Upload folder using huggingface_hub
Browse files- README.md +207 -3
- adapter_config.json +37 -0
- adapter_model.safetensors +3 -0
- checkpoint-3/README.md +207 -0
- checkpoint-3/adapter_config.json +37 -0
- checkpoint-3/adapter_model.safetensors +3 -0
- checkpoint-3/optimizer.pt +3 -0
- checkpoint-3/rng_state.pth +3 -0
- checkpoint-3/scaler.pt +3 -0
- checkpoint-3/scheduler.pt +3 -0
- checkpoint-3/trainer_state.json +55 -0
- checkpoint-3/training_args.bin +3 -0
- inference.py +48 -0
- list_modules.py +22 -0
- qwen.tiktoken +0 -0
- special_tokens_map.json +1 -0
- tokenization_qwen.py +276 -0
- tokenizer_config.json +13 -0
- train_lora.py +119 -0
- upload.py +15 -0
README.md
CHANGED
@@ -1,3 +1,207 @@
|
|
1 |
-
---
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
base_model: Qwen/Qwen-7B-Chat
|
3 |
+
library_name: peft
|
4 |
+
pipeline_tag: text-generation
|
5 |
+
tags:
|
6 |
+
- base_model:adapter:/home/yq238/project_pi_aaa247/yq238/qwen_training/models/Qwen-7B-Chat
|
7 |
+
- lora
|
8 |
+
- transformers
|
9 |
+
---
|
10 |
+
|
11 |
+
# Model Card for Model ID
|
12 |
+
|
13 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
## Model Details
|
18 |
+
|
19 |
+
### Model Description
|
20 |
+
|
21 |
+
<!-- Provide a longer summary of what this model is. -->
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
- **Developed by:** [More Information Needed]
|
26 |
+
- **Funded by [optional]:** [More Information Needed]
|
27 |
+
- **Shared by [optional]:** [More Information Needed]
|
28 |
+
- **Model type:** [More Information Needed]
|
29 |
+
- **Language(s) (NLP):** [More Information Needed]
|
30 |
+
- **License:** [More Information Needed]
|
31 |
+
- **Finetuned from model [optional]:** [More Information Needed]
|
32 |
+
|
33 |
+
### Model Sources [optional]
|
34 |
+
|
35 |
+
<!-- Provide the basic links for the model. -->
|
36 |
+
|
37 |
+
- **Repository:** [More Information Needed]
|
38 |
+
- **Paper [optional]:** [More Information Needed]
|
39 |
+
- **Demo [optional]:** [More Information Needed]
|
40 |
+
|
41 |
+
## Uses
|
42 |
+
|
43 |
+
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
44 |
+
|
45 |
+
### Direct Use
|
46 |
+
|
47 |
+
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
48 |
+
|
49 |
+
[More Information Needed]
|
50 |
+
|
51 |
+
### Downstream Use [optional]
|
52 |
+
|
53 |
+
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
54 |
+
|
55 |
+
[More Information Needed]
|
56 |
+
|
57 |
+
### Out-of-Scope Use
|
58 |
+
|
59 |
+
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
60 |
+
|
61 |
+
[More Information Needed]
|
62 |
+
|
63 |
+
## Bias, Risks, and Limitations
|
64 |
+
|
65 |
+
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
66 |
+
|
67 |
+
[More Information Needed]
|
68 |
+
|
69 |
+
### Recommendations
|
70 |
+
|
71 |
+
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
72 |
+
|
73 |
+
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
74 |
+
|
75 |
+
## How to Get Started with the Model
|
76 |
+
|
77 |
+
Use the code below to get started with the model.
|
78 |
+
|
79 |
+
[More Information Needed]
|
80 |
+
|
81 |
+
## Training Details
|
82 |
+
|
83 |
+
### Training Data
|
84 |
+
|
85 |
+
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
86 |
+
|
87 |
+
[More Information Needed]
|
88 |
+
|
89 |
+
### Training Procedure
|
90 |
+
|
91 |
+
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
92 |
+
|
93 |
+
#### Preprocessing [optional]
|
94 |
+
|
95 |
+
[More Information Needed]
|
96 |
+
|
97 |
+
|
98 |
+
#### Training Hyperparameters
|
99 |
+
|
100 |
+
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
101 |
+
|
102 |
+
#### Speeds, Sizes, Times [optional]
|
103 |
+
|
104 |
+
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
105 |
+
|
106 |
+
[More Information Needed]
|
107 |
+
|
108 |
+
## Evaluation
|
109 |
+
|
110 |
+
<!-- This section describes the evaluation protocols and provides the results. -->
|
111 |
+
|
112 |
+
### Testing Data, Factors & Metrics
|
113 |
+
|
114 |
+
#### Testing Data
|
115 |
+
|
116 |
+
<!-- This should link to a Dataset Card if possible. -->
|
117 |
+
|
118 |
+
[More Information Needed]
|
119 |
+
|
120 |
+
#### Factors
|
121 |
+
|
122 |
+
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
123 |
+
|
124 |
+
[More Information Needed]
|
125 |
+
|
126 |
+
#### Metrics
|
127 |
+
|
128 |
+
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
129 |
+
|
130 |
+
[More Information Needed]
|
131 |
+
|
132 |
+
### Results
|
133 |
+
|
134 |
+
[More Information Needed]
|
135 |
+
|
136 |
+
#### Summary
|
137 |
+
|
138 |
+
|
139 |
+
|
140 |
+
## Model Examination [optional]
|
141 |
+
|
142 |
+
<!-- Relevant interpretability work for the model goes here -->
|
143 |
+
|
144 |
+
[More Information Needed]
|
145 |
+
|
146 |
+
## Environmental Impact
|
147 |
+
|
148 |
+
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
149 |
+
|
150 |
+
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
151 |
+
|
152 |
+
- **Hardware Type:** [More Information Needed]
|
153 |
+
- **Hours used:** [More Information Needed]
|
154 |
+
- **Cloud Provider:** [More Information Needed]
|
155 |
+
- **Compute Region:** [More Information Needed]
|
156 |
+
- **Carbon Emitted:** [More Information Needed]
|
157 |
+
|
158 |
+
## Technical Specifications [optional]
|
159 |
+
|
160 |
+
### Model Architecture and Objective
|
161 |
+
|
162 |
+
[More Information Needed]
|
163 |
+
|
164 |
+
### Compute Infrastructure
|
165 |
+
|
166 |
+
[More Information Needed]
|
167 |
+
|
168 |
+
#### Hardware
|
169 |
+
|
170 |
+
[More Information Needed]
|
171 |
+
|
172 |
+
#### Software
|
173 |
+
|
174 |
+
[More Information Needed]
|
175 |
+
|
176 |
+
## Citation [optional]
|
177 |
+
|
178 |
+
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
179 |
+
|
180 |
+
**BibTeX:**
|
181 |
+
|
182 |
+
[More Information Needed]
|
183 |
+
|
184 |
+
**APA:**
|
185 |
+
|
186 |
+
[More Information Needed]
|
187 |
+
|
188 |
+
## Glossary [optional]
|
189 |
+
|
190 |
+
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
191 |
+
|
192 |
+
[More Information Needed]
|
193 |
+
|
194 |
+
## More Information [optional]
|
195 |
+
|
196 |
+
[More Information Needed]
|
197 |
+
|
198 |
+
## Model Card Authors [optional]
|
199 |
+
|
200 |
+
[More Information Needed]
|
201 |
+
|
202 |
+
## Model Card Contact
|
203 |
+
|
204 |
+
[More Information Needed]
|
205 |
+
### Framework versions
|
206 |
+
|
207 |
+
- PEFT 0.17.1
|
adapter_config.json
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"alpha_pattern": {},
|
3 |
+
"auto_mapping": null,
|
4 |
+
"base_model_name_or_path": "Qwen/Qwen-7B-Chat",
|
5 |
+
"bias": "none",
|
6 |
+
"corda_config": null,
|
7 |
+
"eva_config": null,
|
8 |
+
"exclude_modules": null,
|
9 |
+
"fan_in_fan_out": false,
|
10 |
+
"inference_mode": true,
|
11 |
+
"init_lora_weights": true,
|
12 |
+
"layer_replication": null,
|
13 |
+
"layers_pattern": null,
|
14 |
+
"layers_to_transform": null,
|
15 |
+
"loftq_config": {},
|
16 |
+
"lora_alpha": 128,
|
17 |
+
"lora_bias": false,
|
18 |
+
"lora_dropout": 0.05,
|
19 |
+
"megatron_config": null,
|
20 |
+
"megatron_core": "megatron.core",
|
21 |
+
"modules_to_save": null,
|
22 |
+
"peft_type": "LORA",
|
23 |
+
"qalora_group_size": 16,
|
24 |
+
"r": 64,
|
25 |
+
"rank_pattern": {},
|
26 |
+
"revision": null,
|
27 |
+
"target_modules": [
|
28 |
+
"mlp.c_proj",
|
29 |
+
"attn.c_proj"
|
30 |
+
],
|
31 |
+
"target_parameters": null,
|
32 |
+
"task_type": "CAUSAL_LM",
|
33 |
+
"trainable_token_indices": null,
|
34 |
+
"use_dora": false,
|
35 |
+
"use_qalora": false,
|
36 |
+
"use_rslora": false
|
37 |
+
}
|
adapter_model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9c0dc9c55df566416bb43b03b5445c30fbacbef4c095d0e1e583f0fcf4c30c4b
|
3 |
+
size 190857672
|
checkpoint-3/README.md
ADDED
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
base_model: /home/yq238/project_pi_aaa247/yq238/qwen_training/models/Qwen-7B-Chat
|
3 |
+
library_name: peft
|
4 |
+
pipeline_tag: text-generation
|
5 |
+
tags:
|
6 |
+
- base_model:adapter:/home/yq238/project_pi_aaa247/yq238/qwen_training/models/Qwen-7B-Chat
|
7 |
+
- lora
|
8 |
+
- transformers
|
9 |
+
---
|
10 |
+
|
11 |
+
# Model Card for Model ID
|
12 |
+
|
13 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
## Model Details
|
18 |
+
|
19 |
+
### Model Description
|
20 |
+
|
21 |
+
<!-- Provide a longer summary of what this model is. -->
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
- **Developed by:** [More Information Needed]
|
26 |
+
- **Funded by [optional]:** [More Information Needed]
|
27 |
+
- **Shared by [optional]:** [More Information Needed]
|
28 |
+
- **Model type:** [More Information Needed]
|
29 |
+
- **Language(s) (NLP):** [More Information Needed]
|
30 |
+
- **License:** [More Information Needed]
|
31 |
+
- **Finetuned from model [optional]:** [More Information Needed]
|
32 |
+
|
33 |
+
### Model Sources [optional]
|
34 |
+
|
35 |
+
<!-- Provide the basic links for the model. -->
|
36 |
+
|
37 |
+
- **Repository:** [More Information Needed]
|
38 |
+
- **Paper [optional]:** [More Information Needed]
|
39 |
+
- **Demo [optional]:** [More Information Needed]
|
40 |
+
|
41 |
+
## Uses
|
42 |
+
|
43 |
+
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
44 |
+
|
45 |
+
### Direct Use
|
46 |
+
|
47 |
+
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
48 |
+
|
49 |
+
[More Information Needed]
|
50 |
+
|
51 |
+
### Downstream Use [optional]
|
52 |
+
|
53 |
+
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
54 |
+
|
55 |
+
[More Information Needed]
|
56 |
+
|
57 |
+
### Out-of-Scope Use
|
58 |
+
|
59 |
+
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
60 |
+
|
61 |
+
[More Information Needed]
|
62 |
+
|
63 |
+
## Bias, Risks, and Limitations
|
64 |
+
|
65 |
+
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
66 |
+
|
67 |
+
[More Information Needed]
|
68 |
+
|
69 |
+
### Recommendations
|
70 |
+
|
71 |
+
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
72 |
+
|
73 |
+
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
74 |
+
|
75 |
+
## How to Get Started with the Model
|
76 |
+
|
77 |
+
Use the code below to get started with the model.
|
78 |
+
|
79 |
+
[More Information Needed]
|
80 |
+
|
81 |
+
## Training Details
|
82 |
+
|
83 |
+
### Training Data
|
84 |
+
|
85 |
+
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
86 |
+
|
87 |
+
[More Information Needed]
|
88 |
+
|
89 |
+
### Training Procedure
|
90 |
+
|
91 |
+
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
92 |
+
|
93 |
+
#### Preprocessing [optional]
|
94 |
+
|
95 |
+
[More Information Needed]
|
96 |
+
|
97 |
+
|
98 |
+
#### Training Hyperparameters
|
99 |
+
|
100 |
+
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
101 |
+
|
102 |
+
#### Speeds, Sizes, Times [optional]
|
103 |
+
|
104 |
+
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
105 |
+
|
106 |
+
[More Information Needed]
|
107 |
+
|
108 |
+
## Evaluation
|
109 |
+
|
110 |
+
<!-- This section describes the evaluation protocols and provides the results. -->
|
111 |
+
|
112 |
+
### Testing Data, Factors & Metrics
|
113 |
+
|
114 |
+
#### Testing Data
|
115 |
+
|
116 |
+
<!-- This should link to a Dataset Card if possible. -->
|
117 |
+
|
118 |
+
[More Information Needed]
|
119 |
+
|
120 |
+
#### Factors
|
121 |
+
|
122 |
+
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
123 |
+
|
124 |
+
[More Information Needed]
|
125 |
+
|
126 |
+
#### Metrics
|
127 |
+
|
128 |
+
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
129 |
+
|
130 |
+
[More Information Needed]
|
131 |
+
|
132 |
+
### Results
|
133 |
+
|
134 |
+
[More Information Needed]
|
135 |
+
|
136 |
+
#### Summary
|
137 |
+
|
138 |
+
|
139 |
+
|
140 |
+
## Model Examination [optional]
|
141 |
+
|
142 |
+
<!-- Relevant interpretability work for the model goes here -->
|
143 |
+
|
144 |
+
[More Information Needed]
|
145 |
+
|
146 |
+
## Environmental Impact
|
147 |
+
|
148 |
+
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
149 |
+
|
150 |
+
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
151 |
+
|
152 |
+
- **Hardware Type:** [More Information Needed]
|
153 |
+
- **Hours used:** [More Information Needed]
|
154 |
+
- **Cloud Provider:** [More Information Needed]
|
155 |
+
- **Compute Region:** [More Information Needed]
|
156 |
+
- **Carbon Emitted:** [More Information Needed]
|
157 |
+
|
158 |
+
## Technical Specifications [optional]
|
159 |
+
|
160 |
+
### Model Architecture and Objective
|
161 |
+
|
162 |
+
[More Information Needed]
|
163 |
+
|
164 |
+
### Compute Infrastructure
|
165 |
+
|
166 |
+
[More Information Needed]
|
167 |
+
|
168 |
+
#### Hardware
|
169 |
+
|
170 |
+
[More Information Needed]
|
171 |
+
|
172 |
+
#### Software
|
173 |
+
|
174 |
+
[More Information Needed]
|
175 |
+
|
176 |
+
## Citation [optional]
|
177 |
+
|
178 |
+
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
179 |
+
|
180 |
+
**BibTeX:**
|
181 |
+
|
182 |
+
[More Information Needed]
|
183 |
+
|
184 |
+
**APA:**
|
185 |
+
|
186 |
+
[More Information Needed]
|
187 |
+
|
188 |
+
## Glossary [optional]
|
189 |
+
|
190 |
+
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
191 |
+
|
192 |
+
[More Information Needed]
|
193 |
+
|
194 |
+
## More Information [optional]
|
195 |
+
|
196 |
+
[More Information Needed]
|
197 |
+
|
198 |
+
## Model Card Authors [optional]
|
199 |
+
|
200 |
+
[More Information Needed]
|
201 |
+
|
202 |
+
## Model Card Contact
|
203 |
+
|
204 |
+
[More Information Needed]
|
205 |
+
### Framework versions
|
206 |
+
|
207 |
+
- PEFT 0.17.1
|
checkpoint-3/adapter_config.json
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"alpha_pattern": {},
|
3 |
+
"auto_mapping": null,
|
4 |
+
"base_model_name_or_path": "/home/yq238/project_pi_aaa247/yq238/qwen_training/models/Qwen-7B-Chat",
|
5 |
+
"bias": "none",
|
6 |
+
"corda_config": null,
|
7 |
+
"eva_config": null,
|
8 |
+
"exclude_modules": null,
|
9 |
+
"fan_in_fan_out": false,
|
10 |
+
"inference_mode": true,
|
11 |
+
"init_lora_weights": true,
|
12 |
+
"layer_replication": null,
|
13 |
+
"layers_pattern": null,
|
14 |
+
"layers_to_transform": null,
|
15 |
+
"loftq_config": {},
|
16 |
+
"lora_alpha": 128,
|
17 |
+
"lora_bias": false,
|
18 |
+
"lora_dropout": 0.05,
|
19 |
+
"megatron_config": null,
|
20 |
+
"megatron_core": "megatron.core",
|
21 |
+
"modules_to_save": null,
|
22 |
+
"peft_type": "LORA",
|
23 |
+
"qalora_group_size": 16,
|
24 |
+
"r": 64,
|
25 |
+
"rank_pattern": {},
|
26 |
+
"revision": null,
|
27 |
+
"target_modules": [
|
28 |
+
"mlp.c_proj",
|
29 |
+
"attn.c_proj"
|
30 |
+
],
|
31 |
+
"target_parameters": null,
|
32 |
+
"task_type": "CAUSAL_LM",
|
33 |
+
"trainable_token_indices": null,
|
34 |
+
"use_dora": false,
|
35 |
+
"use_qalora": false,
|
36 |
+
"use_rslora": false
|
37 |
+
}
|
checkpoint-3/adapter_model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9c0dc9c55df566416bb43b03b5445c30fbacbef4c095d0e1e583f0fcf4c30c4b
|
3 |
+
size 190857672
|
checkpoint-3/optimizer.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a4cbbbad499faeb0863966293e2081589f89941eb765e6d2142e4ab967834440
|
3 |
+
size 381790283
|
checkpoint-3/rng_state.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:02a9e263816dc1cd5c720e052d6fa2f988ef1066d76dcbccaf5efd05c6e352f7
|
3 |
+
size 14645
|
checkpoint-3/scaler.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5be4c65680a9815ca3fc0738d3db6d8ea3a0d6246656b7e251a9b34a942fa7e0
|
3 |
+
size 1383
|
checkpoint-3/scheduler.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e9cd46075d1b3ae3c4c3ba017fb54771530839917f6158b9f49498cd4c5ca744
|
3 |
+
size 1465
|
checkpoint-3/trainer_state.json
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"best_global_step": null,
|
3 |
+
"best_metric": null,
|
4 |
+
"best_model_checkpoint": null,
|
5 |
+
"epoch": 3.0,
|
6 |
+
"eval_steps": 500,
|
7 |
+
"global_step": 3,
|
8 |
+
"is_hyper_param_search": false,
|
9 |
+
"is_local_process_zero": true,
|
10 |
+
"is_world_process_zero": true,
|
11 |
+
"log_history": [
|
12 |
+
{
|
13 |
+
"epoch": 1.0,
|
14 |
+
"grad_norm": 8.896397590637207,
|
15 |
+
"learning_rate": 0.0,
|
16 |
+
"loss": 17.321,
|
17 |
+
"step": 1
|
18 |
+
},
|
19 |
+
{
|
20 |
+
"epoch": 2.0,
|
21 |
+
"grad_norm": 9.058915138244629,
|
22 |
+
"learning_rate": 0.0002,
|
23 |
+
"loss": 17.321,
|
24 |
+
"step": 2
|
25 |
+
},
|
26 |
+
{
|
27 |
+
"epoch": 3.0,
|
28 |
+
"grad_norm": 8.789560317993164,
|
29 |
+
"learning_rate": 0.0001,
|
30 |
+
"loss": 14.1843,
|
31 |
+
"step": 3
|
32 |
+
}
|
33 |
+
],
|
34 |
+
"logging_steps": 1,
|
35 |
+
"max_steps": 3,
|
36 |
+
"num_input_tokens_seen": 0,
|
37 |
+
"num_train_epochs": 3,
|
38 |
+
"save_steps": 10,
|
39 |
+
"stateful_callbacks": {
|
40 |
+
"TrainerControl": {
|
41 |
+
"args": {
|
42 |
+
"should_epoch_stop": false,
|
43 |
+
"should_evaluate": false,
|
44 |
+
"should_log": false,
|
45 |
+
"should_save": true,
|
46 |
+
"should_training_stop": true
|
47 |
+
},
|
48 |
+
"attributes": {}
|
49 |
+
}
|
50 |
+
},
|
51 |
+
"total_flos": 32932016160768.0,
|
52 |
+
"train_batch_size": 1,
|
53 |
+
"trial_name": null,
|
54 |
+
"trial_params": null
|
55 |
+
}
|
checkpoint-3/training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a385ce4651aa513088b8a4ce4fbba860d2ff5637f9dba2b0685add0989093c7c
|
3 |
+
size 5841
|
inference.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# inference.py
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
from peft import PeftModel
|
4 |
+
import torch
|
5 |
+
|
6 |
+
# --- 模型路径 ---
|
7 |
+
base_model_path = "/home/yq238/project_pi_aaa247/yq238/qwen_training/models/Qwen-7B-Chat"
|
8 |
+
lora_path = "/home/yq238/project_pi_aaa247/yq238/qwen_training/training/test1"
|
9 |
+
|
10 |
+
# --- 加载 tokenizer ---
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_path, trust_remote_code=True)
|
12 |
+
|
13 |
+
# --- 加载模型 ---
|
14 |
+
model = AutoModelForCausalLM.from_pretrained(
|
15 |
+
base_model_path,
|
16 |
+
device_map="auto",
|
17 |
+
trust_remote_code=True,
|
18 |
+
torch_dtype=torch.float16,
|
19 |
+
)
|
20 |
+
model = PeftModel.from_pretrained(model, lora_path)
|
21 |
+
|
22 |
+
# --- 推理 ---
|
23 |
+
instruction = "生成分析输入表格。生成的表格应包括 SampleID,fastq_P1,fastq_P2,..."
|
24 |
+
user_input = "/gpfs/gibbs/pi/augert/Collaboration/guangxiao/batch6_2/01Sam/merge_data\n├── PU1_WT_D7_R1_P1.fastq.gz\n..."
|
25 |
+
|
26 |
+
prompt = f"你是一个自动化助手。\n\n用户:{instruction}\n{user_input}\n\n助手:"
|
27 |
+
|
28 |
+
# ✅ 关键修复:只提取 input_ids 和 attention_mask
|
29 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
30 |
+
inputs = {
|
31 |
+
"input_ids": inputs["input_ids"].to("cuda"),
|
32 |
+
"attention_mask": inputs["attention_mask"].to("cuda"),
|
33 |
+
# ✅ 显式排除 token_type_ids
|
34 |
+
}
|
35 |
+
|
36 |
+
# ✅ 关键修复:禁用缓存(避免 past_key_values 问题)
|
37 |
+
outputs = model.generate(
|
38 |
+
**inputs,
|
39 |
+
max_new_tokens=1024,
|
40 |
+
do_sample=True,
|
41 |
+
temperature=0.7,
|
42 |
+
top_p=0.9,
|
43 |
+
use_cache=False, # ✅ 关键:禁用缓存,避免 past_key_values 问题
|
44 |
+
)
|
45 |
+
|
46 |
+
# 解码输出
|
47 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
48 |
+
print(response)
|
list_modules.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# list_modules.py
|
2 |
+
from transformers import AutoModelForCausalLM
|
3 |
+
|
4 |
+
# 修改为你的模型路径
|
5 |
+
model_path = "/home/yq238/project_pi_aaa247/yq238/qwen_training/models/Qwen-7B-Chat"
|
6 |
+
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(
|
8 |
+
model_path,
|
9 |
+
device_map="auto",
|
10 |
+
trust_remote_code=True,
|
11 |
+
torch_dtype="auto"
|
12 |
+
)
|
13 |
+
|
14 |
+
print("🔍 模型中包含 'proj' 的模块名:")
|
15 |
+
for name, module in model.named_modules():
|
16 |
+
if 'proj' in name.lower():
|
17 |
+
print(name)
|
18 |
+
|
19 |
+
print("\n🔍 模型中包含 'attn' 的模块名(可能包含注意力层):")
|
20 |
+
for name, module in model.named_modules():
|
21 |
+
if 'attn' in name.lower() and any(x in name for x in ['q_', 'k_', 'v_', 'o_']):
|
22 |
+
print(name)
|
qwen.tiktoken
ADDED
The diff for this file is too large to render.
See raw diff
|
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{}
|
tokenization_qwen.py
ADDED
@@ -0,0 +1,276 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (c) Alibaba Cloud.
|
2 |
+
#
|
3 |
+
# This source code is licensed under the license found in the
|
4 |
+
# LICENSE file in the root directory of this source tree.
|
5 |
+
|
6 |
+
"""Tokenization classes for QWen."""
|
7 |
+
|
8 |
+
import base64
|
9 |
+
import logging
|
10 |
+
import os
|
11 |
+
import unicodedata
|
12 |
+
from typing import Collection, Dict, List, Set, Tuple, Union
|
13 |
+
|
14 |
+
import tiktoken
|
15 |
+
from transformers import PreTrainedTokenizer, AddedToken
|
16 |
+
|
17 |
+
logger = logging.getLogger(__name__)
|
18 |
+
|
19 |
+
|
20 |
+
VOCAB_FILES_NAMES = {"vocab_file": "qwen.tiktoken"}
|
21 |
+
|
22 |
+
PAT_STR = r"""(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+"""
|
23 |
+
ENDOFTEXT = "<|endoftext|>"
|
24 |
+
IMSTART = "<|im_start|>"
|
25 |
+
IMEND = "<|im_end|>"
|
26 |
+
# as the default behavior is changed to allow special tokens in
|
27 |
+
# regular texts, the surface forms of special tokens need to be
|
28 |
+
# as different as possible to minimize the impact
|
29 |
+
EXTRAS = tuple((f"<|extra_{i}|>" for i in range(205)))
|
30 |
+
# changed to use actual index to avoid misconfiguration with vocabulary expansion
|
31 |
+
SPECIAL_START_ID = 151643
|
32 |
+
SPECIAL_TOKENS = tuple(
|
33 |
+
enumerate(
|
34 |
+
(
|
35 |
+
(
|
36 |
+
ENDOFTEXT,
|
37 |
+
IMSTART,
|
38 |
+
IMEND,
|
39 |
+
)
|
40 |
+
+ EXTRAS
|
41 |
+
),
|
42 |
+
start=SPECIAL_START_ID,
|
43 |
+
)
|
44 |
+
)
|
45 |
+
SPECIAL_TOKENS_SET = set(t for i, t in SPECIAL_TOKENS)
|
46 |
+
|
47 |
+
|
48 |
+
def _load_tiktoken_bpe(tiktoken_bpe_file: str) -> Dict[bytes, int]:
|
49 |
+
with open(tiktoken_bpe_file, "rb") as f:
|
50 |
+
contents = f.read()
|
51 |
+
return {
|
52 |
+
base64.b64decode(token): int(rank)
|
53 |
+
for token, rank in (line.split() for line in contents.splitlines() if line)
|
54 |
+
}
|
55 |
+
|
56 |
+
|
57 |
+
class QWenTokenizer(PreTrainedTokenizer):
|
58 |
+
"""QWen tokenizer."""
|
59 |
+
|
60 |
+
vocab_files_names = VOCAB_FILES_NAMES
|
61 |
+
|
62 |
+
def __init__(
|
63 |
+
self,
|
64 |
+
vocab_file,
|
65 |
+
errors="replace",
|
66 |
+
extra_vocab_file=None,
|
67 |
+
**kwargs,
|
68 |
+
):
|
69 |
+
super().__init__(**kwargs)
|
70 |
+
|
71 |
+
# how to handle errors in decoding UTF-8 byte sequences
|
72 |
+
# use ignore if you are in streaming inference
|
73 |
+
self.errors = errors
|
74 |
+
|
75 |
+
self.mergeable_ranks = _load_tiktoken_bpe(vocab_file) # type: Dict[bytes, int]
|
76 |
+
self.special_tokens = {
|
77 |
+
token: index
|
78 |
+
for index, token in SPECIAL_TOKENS
|
79 |
+
}
|
80 |
+
|
81 |
+
# try load extra vocab from file
|
82 |
+
if extra_vocab_file is not None:
|
83 |
+
used_ids = set(self.mergeable_ranks.values()) | set(self.special_tokens.values())
|
84 |
+
extra_mergeable_ranks = _load_tiktoken_bpe(extra_vocab_file)
|
85 |
+
for token, index in extra_mergeable_ranks.items():
|
86 |
+
if token in self.mergeable_ranks:
|
87 |
+
logger.info(f"extra token {token} exists, skipping")
|
88 |
+
continue
|
89 |
+
if index in used_ids:
|
90 |
+
logger.info(f'the index {index} for extra token {token} exists, skipping')
|
91 |
+
continue
|
92 |
+
self.mergeable_ranks[token] = index
|
93 |
+
# the index may be sparse after this, but don't worry tiktoken.Encoding will handle this
|
94 |
+
|
95 |
+
enc = tiktoken.Encoding(
|
96 |
+
"Qwen",
|
97 |
+
pat_str=PAT_STR,
|
98 |
+
mergeable_ranks=self.mergeable_ranks,
|
99 |
+
special_tokens=self.special_tokens,
|
100 |
+
)
|
101 |
+
assert (
|
102 |
+
len(self.mergeable_ranks) + len(self.special_tokens) == enc.n_vocab
|
103 |
+
), f"{len(self.mergeable_ranks) + len(self.special_tokens)} != {enc.n_vocab} in encoding"
|
104 |
+
|
105 |
+
self.decoder = {
|
106 |
+
v: k for k, v in self.mergeable_ranks.items()
|
107 |
+
} # type: dict[int, bytes|str]
|
108 |
+
self.decoder.update({v: k for k, v in self.special_tokens.items()})
|
109 |
+
|
110 |
+
self.tokenizer = enc # type: tiktoken.Encoding
|
111 |
+
|
112 |
+
self.eod_id = self.tokenizer.eot_token
|
113 |
+
self.im_start_id = self.special_tokens[IMSTART]
|
114 |
+
self.im_end_id = self.special_tokens[IMEND]
|
115 |
+
|
116 |
+
def __getstate__(self):
|
117 |
+
# for pickle lovers
|
118 |
+
state = self.__dict__.copy()
|
119 |
+
del state["tokenizer"]
|
120 |
+
return state
|
121 |
+
|
122 |
+
def __setstate__(self, state):
|
123 |
+
# tokenizer is not python native; don't pass it; rebuild it
|
124 |
+
self.__dict__.update(state)
|
125 |
+
enc = tiktoken.Encoding(
|
126 |
+
"Qwen",
|
127 |
+
pat_str=PAT_STR,
|
128 |
+
mergeable_ranks=self.mergeable_ranks,
|
129 |
+
special_tokens=self.special_tokens,
|
130 |
+
)
|
131 |
+
self.tokenizer = enc
|
132 |
+
|
133 |
+
def __len__(self) -> int:
|
134 |
+
return self.tokenizer.n_vocab
|
135 |
+
|
136 |
+
def get_vocab(self) -> Dict[bytes, int]:
|
137 |
+
return self.mergeable_ranks
|
138 |
+
|
139 |
+
def convert_tokens_to_ids(
|
140 |
+
self, tokens: Union[bytes, str, List[Union[bytes, str]]]
|
141 |
+
) -> List[int]:
|
142 |
+
ids = []
|
143 |
+
if isinstance(tokens, (str, bytes)):
|
144 |
+
if tokens in self.special_tokens:
|
145 |
+
return self.special_tokens[tokens]
|
146 |
+
else:
|
147 |
+
return self.mergeable_ranks.get(tokens)
|
148 |
+
for token in tokens:
|
149 |
+
if token in self.special_tokens:
|
150 |
+
ids.append(self.special_tokens[token])
|
151 |
+
else:
|
152 |
+
ids.append(self.mergeable_ranks.get(token))
|
153 |
+
return ids
|
154 |
+
|
155 |
+
def _add_tokens(
|
156 |
+
self,
|
157 |
+
new_tokens: Union[List[str], List[AddedToken]],
|
158 |
+
special_tokens: bool = False,
|
159 |
+
) -> int:
|
160 |
+
if not special_tokens and new_tokens:
|
161 |
+
raise ValueError("Adding regular tokens is not supported")
|
162 |
+
for token in new_tokens:
|
163 |
+
surface_form = token.content if isinstance(token, AddedToken) else token
|
164 |
+
if surface_form not in SPECIAL_TOKENS_SET:
|
165 |
+
raise ValueError("Adding unknown special tokens is not supported")
|
166 |
+
return 0
|
167 |
+
|
168 |
+
def save_vocabulary(self, save_directory: str, **kwargs) -> Tuple[str]:
|
169 |
+
"""
|
170 |
+
Save only the vocabulary of the tokenizer (vocabulary).
|
171 |
+
|
172 |
+
Returns:
|
173 |
+
`Tuple(str)`: Paths to the files saved.
|
174 |
+
"""
|
175 |
+
file_path = os.path.join(save_directory, "qwen.tiktoken")
|
176 |
+
with open(file_path, "w", encoding="utf8") as w:
|
177 |
+
for k, v in self.mergeable_ranks.items():
|
178 |
+
line = base64.b64encode(k).decode("utf8") + " " + str(v) + "\n"
|
179 |
+
w.write(line)
|
180 |
+
return (file_path,)
|
181 |
+
|
182 |
+
def tokenize(
|
183 |
+
self,
|
184 |
+
text: str,
|
185 |
+
allowed_special: Union[Set, str] = "all",
|
186 |
+
disallowed_special: Union[Collection, str] = (),
|
187 |
+
**kwargs,
|
188 |
+
) -> List[Union[bytes, str]]:
|
189 |
+
"""
|
190 |
+
Converts a string in a sequence of tokens.
|
191 |
+
|
192 |
+
Args:
|
193 |
+
text (`str`):
|
194 |
+
The sequence to be encoded.
|
195 |
+
allowed_special (`Literal["all"]` or `set`):
|
196 |
+
The surface forms of the tokens to be encoded as special tokens in regular texts.
|
197 |
+
Default to "all".
|
198 |
+
disallowed_special (`Literal["all"]` or `Collection`):
|
199 |
+
The surface forms of the tokens that should not be in regular texts and trigger errors.
|
200 |
+
Default to an empty tuple.
|
201 |
+
|
202 |
+
kwargs (additional keyword arguments, *optional*):
|
203 |
+
Will be passed to the underlying model specific encode method.
|
204 |
+
|
205 |
+
Returns:
|
206 |
+
`List[bytes|str]`: The list of tokens.
|
207 |
+
"""
|
208 |
+
tokens = []
|
209 |
+
text = unicodedata.normalize("NFC", text)
|
210 |
+
|
211 |
+
# this implementation takes a detour: text -> token id -> token surface forms
|
212 |
+
for t in self.tokenizer.encode(
|
213 |
+
text, allowed_special=allowed_special, disallowed_special=disallowed_special
|
214 |
+
):
|
215 |
+
tokens.append(self.decoder[t])
|
216 |
+
return tokens
|
217 |
+
|
218 |
+
def convert_tokens_to_string(self, tokens: List[Union[bytes, str]]) -> str:
|
219 |
+
"""
|
220 |
+
Converts a sequence of tokens in a single string.
|
221 |
+
"""
|
222 |
+
text = ""
|
223 |
+
temp = b""
|
224 |
+
for t in tokens:
|
225 |
+
if isinstance(t, str):
|
226 |
+
if temp:
|
227 |
+
text += temp.decode("utf-8", errors=self.errors)
|
228 |
+
temp = b""
|
229 |
+
text += t
|
230 |
+
elif isinstance(t, bytes):
|
231 |
+
temp += t
|
232 |
+
else:
|
233 |
+
raise TypeError("token should only be of type types or str")
|
234 |
+
if temp:
|
235 |
+
text += temp.decode("utf-8", errors=self.errors)
|
236 |
+
return text
|
237 |
+
|
238 |
+
@property
|
239 |
+
def vocab_size(self):
|
240 |
+
return self.tokenizer.n_vocab
|
241 |
+
|
242 |
+
def _convert_id_to_token(self, index: int) -> Union[bytes, str]:
|
243 |
+
"""Converts an id to a token, special tokens included"""
|
244 |
+
if index in self.decoder:
|
245 |
+
return self.decoder[index]
|
246 |
+
raise ValueError("unknown ids")
|
247 |
+
|
248 |
+
def _convert_token_to_id(self, token: Union[bytes, str]) -> int:
|
249 |
+
"""Converts a token to an id using the vocab, special tokens included"""
|
250 |
+
if token in self.special_tokens:
|
251 |
+
return self.special_tokens[token]
|
252 |
+
if token in self.mergeable_ranks:
|
253 |
+
return self.mergeable_ranks[token]
|
254 |
+
raise ValueError("unknown token")
|
255 |
+
|
256 |
+
def _tokenize(self, text: str, **kwargs):
|
257 |
+
"""
|
258 |
+
Converts a string in a sequence of tokens (string), using the tokenizer. Split in words for word-based
|
259 |
+
vocabulary or sub-words for sub-word-based vocabularies (BPE/SentencePieces/WordPieces).
|
260 |
+
|
261 |
+
Do NOT take care of added tokens.
|
262 |
+
"""
|
263 |
+
raise NotImplementedError
|
264 |
+
|
265 |
+
def _decode(
|
266 |
+
self,
|
267 |
+
token_ids: Union[int, List[int]],
|
268 |
+
skip_special_tokens: bool = False,
|
269 |
+
errors: str = None,
|
270 |
+
**kwargs,
|
271 |
+
) -> str:
|
272 |
+
if isinstance(token_ids, int):
|
273 |
+
token_ids = [token_ids]
|
274 |
+
if skip_special_tokens:
|
275 |
+
token_ids = [i for i in token_ids if i < self.eod_id]
|
276 |
+
return self.tokenizer.decode(token_ids, errors=errors or self.errors)
|
tokenizer_config.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"added_tokens_decoder": {},
|
3 |
+
"auto_map": {
|
4 |
+
"AutoTokenizer": [
|
5 |
+
"tokenization_qwen.QWenTokenizer",
|
6 |
+
null
|
7 |
+
]
|
8 |
+
},
|
9 |
+
"clean_up_tokenization_spaces": false,
|
10 |
+
"extra_special_tokens": {},
|
11 |
+
"model_max_length": 32768,
|
12 |
+
"tokenizer_class": "QWenTokenizer"
|
13 |
+
}
|
train_lora.py
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# train_lora.py
|
2 |
+
# Qwen-7B-Chat 微调脚本(真正最终版)
|
3 |
+
# 核心:添加 labels,让 Trainer 能计算 loss
|
4 |
+
|
5 |
+
import os
|
6 |
+
import torch
|
7 |
+
from transformers import (
|
8 |
+
AutoModelForCausalLM,
|
9 |
+
AutoTokenizer,
|
10 |
+
TrainingArguments,
|
11 |
+
Trainer
|
12 |
+
)
|
13 |
+
from peft import get_peft_model, LoraConfig, TaskType
|
14 |
+
from datasets import load_dataset
|
15 |
+
|
16 |
+
# --- 配置 ---
|
17 |
+
model_path = "/home/yq238/project_pi_aaa247/yq238/qwen_training/models/Qwen-7B-Chat"
|
18 |
+
data_path = "/home/yq238/project_pi_aaa247/yq238/qwen_training/data/training1.jsonl"
|
19 |
+
output_dir = "/home/yq238/project_pi_aaa247/yq238/qwen_training/training/test1"
|
20 |
+
|
21 |
+
os.makedirs(output_dir, exist_ok=True)
|
22 |
+
|
23 |
+
# --- 1. 加载 tokenizer ---
|
24 |
+
print("🔧 加载 tokenizer...")
|
25 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
26 |
+
|
27 |
+
# --- 2. 加载模型 ---
|
28 |
+
print("🔧 加载模型...")
|
29 |
+
model = AutoModelForCausalLM.from_pretrained(
|
30 |
+
model_path,
|
31 |
+
device_map="auto",
|
32 |
+
trust_remote_code=True,
|
33 |
+
torch_dtype=torch.float16,
|
34 |
+
)
|
35 |
+
|
36 |
+
# ✅ 启用梯度检查点,节省显存
|
37 |
+
model.gradient_checkpointing_enable()
|
38 |
+
|
39 |
+
# --- 3. LoRA 配置 ---
|
40 |
+
print("🔧 配置 LoRA...")
|
41 |
+
peft_config = LoraConfig(
|
42 |
+
task_type=TaskType.CAUSAL_LM,
|
43 |
+
r=64,
|
44 |
+
lora_alpha=128,
|
45 |
+
target_modules=["attn.c_proj", "mlp.c_proj"],
|
46 |
+
lora_dropout=0.05,
|
47 |
+
bias="none",
|
48 |
+
)
|
49 |
+
model = get_peft_model(model, peft_config)
|
50 |
+
model.print_trainable_parameters()
|
51 |
+
|
52 |
+
# --- 4. 数据处理:添加 labels ---
|
53 |
+
print("🔧 加载并处理数据...")
|
54 |
+
def tokenize_fn(examples):
|
55 |
+
instructions = examples["instruction"]
|
56 |
+
inputs = examples["input"]
|
57 |
+
outputs = examples["output"]
|
58 |
+
texts = [
|
59 |
+
f"你是一个自动化助手。\n\n用户:{i}\n{s}\n\n助手:{o}"
|
60 |
+
for i, s, o in zip(instructions, inputs, outputs)
|
61 |
+
]
|
62 |
+
# ✅ tokenize
|
63 |
+
batch = tokenizer(texts, truncation=True, max_length=256, padding=False)
|
64 |
+
# ✅ 添加 labels
|
65 |
+
batch["labels"] = [
|
66 |
+
tokenizer(o, truncation=True, max_length=256, padding=False)["input_ids"]
|
67 |
+
for o in outputs
|
68 |
+
]
|
69 |
+
return batch
|
70 |
+
|
71 |
+
dataset = load_dataset('json', data_files=data_path, split='train')
|
72 |
+
print(f"✅ 数据集加载完成,共 {len(dataset)} 条样本")
|
73 |
+
|
74 |
+
tokenized_dataset = dataset.map(
|
75 |
+
tokenize_fn,
|
76 |
+
batched=True,
|
77 |
+
remove_columns=dataset.column_names,
|
78 |
+
num_proc=1
|
79 |
+
)
|
80 |
+
print("✅ 数据处理完成")
|
81 |
+
|
82 |
+
# --- 5. 训练参数 ---
|
83 |
+
training_args = TrainingArguments(
|
84 |
+
output_dir=output_dir,
|
85 |
+
per_device_train_batch_size=1,
|
86 |
+
gradient_accumulation_steps=16,
|
87 |
+
num_train_epochs=3,
|
88 |
+
learning_rate=2e-4,
|
89 |
+
logging_steps=1,
|
90 |
+
save_steps=10,
|
91 |
+
save_total_limit=2,
|
92 |
+
fp16=True,
|
93 |
+
bf16=False,
|
94 |
+
remove_unused_columns=True,
|
95 |
+
report_to="none",
|
96 |
+
warmup_ratio=0.1,
|
97 |
+
weight_decay=0.01,
|
98 |
+
dataloader_num_workers=1,
|
99 |
+
disable_tqdm=False,
|
100 |
+
dataloader_pin_memory=True,
|
101 |
+
max_grad_norm=1.0,
|
102 |
+
)
|
103 |
+
|
104 |
+
# --- 6. Trainer ---
|
105 |
+
trainer = Trainer(
|
106 |
+
model=model,
|
107 |
+
args=training_args,
|
108 |
+
train_dataset=tokenized_dataset,
|
109 |
+
)
|
110 |
+
|
111 |
+
# --- 7. 开始训练 ---
|
112 |
+
print("🚀 开始训练...")
|
113 |
+
trainer.train()
|
114 |
+
|
115 |
+
# --- 8. 保存 ---
|
116 |
+
print("💾 保存 LoRA 权重...")
|
117 |
+
model.save_pretrained(output_dir)
|
118 |
+
tokenizer.save_pretrained(output_dir)
|
119 |
+
print(f"✅ 训练完成!LoRA 权重已保存到: {output_dir}")
|
upload.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# upload.py
|
2 |
+
from huggingface_hub import HfApi
|
3 |
+
|
4 |
+
# 配置
|
5 |
+
repo_id = "qiyongli22/Qwen_test" # 替换为你的用户名和仓库名
|
6 |
+
lora_model_dir = "/home/yq238/project_pi_aaa247/yq238/qwen_training/training/test1"
|
7 |
+
|
8 |
+
# 上传
|
9 |
+
api = HfApi()
|
10 |
+
api.upload_folder(
|
11 |
+
folder_path=lora_model_dir,
|
12 |
+
repo_id=repo_id,
|
13 |
+
repo_type="model",
|
14 |
+
)
|
15 |
+
print(f"✅ 模型已上传!分享链接:https://huggingface.co/{repo_id}")
|