Update README.md
Browse files
README.md
CHANGED
@@ -4,197 +4,178 @@ license: apache-2.0
|
|
4 |
basemodel: Qwen/Qwen1.5-7B
|
5 |
---
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
-
|
24 |
-
|
25 |
-
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
## Training Details
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
## Model Examination [optional]
|
137 |
-
|
138 |
-
<!-- Relevant interpretability work for the model goes here -->
|
139 |
-
|
140 |
-
[More Information Needed]
|
141 |
-
|
142 |
-
## Environmental Impact
|
143 |
-
|
144 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
145 |
-
|
146 |
-
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).
|
147 |
-
|
148 |
-
- **Hardware Type:** [More Information Needed]
|
149 |
-
- **Hours used:** [More Information Needed]
|
150 |
-
- **Cloud Provider:** [More Information Needed]
|
151 |
-
- **Compute Region:** [More Information Needed]
|
152 |
-
- **Carbon Emitted:** [More Information Needed]
|
153 |
-
|
154 |
-
## Technical Specifications [optional]
|
155 |
-
|
156 |
-
### Model Architecture and Objective
|
157 |
-
|
158 |
-
[More Information Needed]
|
159 |
-
|
160 |
-
### Compute Infrastructure
|
161 |
-
|
162 |
-
[More Information Needed]
|
163 |
-
|
164 |
-
#### Hardware
|
165 |
-
|
166 |
-
[More Information Needed]
|
167 |
-
|
168 |
-
#### Software
|
169 |
-
|
170 |
-
[More Information Needed]
|
171 |
-
|
172 |
-
## Citation [optional]
|
173 |
-
|
174 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
175 |
-
|
176 |
-
**BibTeX:**
|
177 |
-
|
178 |
-
[More Information Needed]
|
179 |
-
|
180 |
-
**APA:**
|
181 |
-
|
182 |
-
[More Information Needed]
|
183 |
-
|
184 |
-
## Glossary [optional]
|
185 |
-
|
186 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
187 |
-
|
188 |
-
[More Information Needed]
|
189 |
-
|
190 |
-
## More Information [optional]
|
191 |
-
|
192 |
-
[More Information Needed]
|
193 |
-
|
194 |
-
## Model Card Authors [optional]
|
195 |
-
|
196 |
-
[More Information Needed]
|
197 |
-
|
198 |
-
## Model Card Contact
|
199 |
-
|
200 |
-
[More Information Needed]
|
|
|
4 |
basemodel: Qwen/Qwen1.5-7B
|
5 |
---
|
6 |
|
7 |
+
## Unsloth x Qwen2
|
8 |
+
[Unsloth](https://github.com/unslothai/unsloth) can speed up training LLM and reduce memory usage, but currently it only supports Llama3, Mistral, Gemma, ORPR, Phi-3 and TinyLlama.
|
9 |
+
We can't train Qwen2 with Unsloth, even though Qwen2 is popular in community.
|
10 |
+
|
11 |
+
It's exciting that we succeed to make Unsloth support Qwen2, it can speed up training and reduce much memory usage.
|
12 |
+
If you want to train Qwen2 with Unsloth, you can use [our repo](https://github.com/yangjianxin1/unsloth) rather than the official one. And we will commit our code to the [official repo](https://github.com/unslothai/unsloth).
|
13 |
+
|
14 |
+
Install our Unsloth:
|
15 |
+
```bash
|
16 |
+
pip install git+https://github.com/yangjianxin1/unsloth.git
|
17 |
+
```
|
18 |
+
|
19 |
+
[Firefly](https://github.com/yangjianxin1/Firefly) already supports training Qwen2 with Unsloth, and the subsequent models are trained with Firefly, you can try it.
|
20 |
+
|
21 |
+
|
22 |
+
## Model Card for Firefly-Qwen1.5-Unsloth
|
23 |
+
[firefly-qwen1.5-en-7b-unsloth](https://huggingface.co/YeungNLP/firefly-qwen1.5-en-7b-unsloth) and [firefly-qwen1.5-en-7b-dpo-v0.1-unloth](https://huggingface.co/YeungNLP/firefly-qwen1.5-en-7b-dpo-v0.1-unsloth) are trained based on [Qwen1.5-7B](https://huggingface.co/Qwen/Qwen1.5-7B) to act as a helpful and harmless AI assistant.
|
24 |
+
We use [Firefly](https://github.com/yangjianxin1/Firefly) to train our models on **a single V100 GPU** with QLoRA and [Unsloth](https://github.com/yangjianxin1/unsloth).
|
25 |
+
firefly-qwen1.5-en-7b-unsloth is fine-tuned based on Qwen1.5-7B with English instruction data, and firefly-qwen1.5-en-7b-dpo-v0.1-unsloth is trained with [Direct Preference Optimization (DPO)](https://arxiv.org/abs/2305.18290) based on firefly-qwen1.5-en-7b-unsloth.
|
26 |
+
|
27 |
+
Our models outperform official [Qwen1.5-7B-Chat](https://huggingface.co/Qwen/Qwen1.5-7B-Chat), [Gemma-7B-it](https://huggingface.co/google/gemma-7b-it), [Zephyr-7B-Beta](https://huggingface.co/HuggingFaceH4/zephyr-7b-beta) on [Open LLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard).
|
28 |
+
|
29 |
+
Although our models are trained with English data, you can also try to chat with models in Chinese because Qwen1.5 is also good at Chinese. But we have not evaluated
|
30 |
+
the performance in Chinese yet.
|
31 |
+
|
32 |
+
We advise you to install transformers>=4.37.0.
|
33 |
+
|
34 |
+
## Performance
|
35 |
+
We have evaluated the training gain of Qwen1.5-7B, we use QLoRA and Unsloth to train model for 20 steps on a single V100. The result can be listed as follows.
|
36 |
+
**Unsloth can reduce GPU memory by 39.13% and training time by 32.12%, and the training speed can increase by 47.32%.**
|
37 |
+
|
38 |
+
| max_seq_length | per_device_train_batch_size | gradient_accumulation_steps | use_unsloth | rank | GPU | Time |
|
39 |
+
|----------------|----------------------------|-----------------------------|-------------|------|-------------------------|-------------------|
|
40 |
+
| 1024 | 1 | 16 | false | 8 | 13.72GB | 448s |
|
41 |
+
| 1024 | 1 | 16 | true | 8 | **8.43GB**(**-38.56%**) | 308s(**-31.25%**) |
|
42 |
+
| 1024 | 1 | 16 | false | 64 | 16.01GB | 452s |
|
43 |
+
| 1024 | 1 | 16 | true | 64 | 11.07GB(**-30.86%**) | 311s(**-31.19%**) |
|
44 |
+
| 2048 | 1 | 16 | false | 64 | 18.55GB | 840s |
|
45 |
+
| 2048 | 1 | 16 | true | 64 | 12.99GB(**-29.97%**) | 596s(**-29.05%**) |
|
46 |
+
| 1024 | 4 | 4 | false | 64 | 24.70GB | 357s |
|
47 |
+
| 1024 | 4 | 4 | true | 64 | 14.36GB(**-41.86%**) | 253s(**-29.13%**) |
|
48 |
+
| 2048 | 4 | 4 | false | 64 | 32.51GB | 741s |
|
49 |
+
| 2048 | 4 | 4 | true | 64 | 19.79GB(**-39.13%**) | 503s(**-32.12%**) |
|
50 |
+
|
51 |
+
|
52 |
+
We evaluate our sft and dpo models on [Open LLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard), they achieve good performance.
|
53 |
+
|
54 |
+
| Model | Average | ARC | HellaSwag | MMLU | TruthfulQA | Winogrande | GSM8K |
|
55 |
+
|--------------------------------------------|---------|--------|-----------|-------|------------|------------|--------|
|
56 |
+
| firefly-gemma-7b | 62.93 | 62.12 | 79.77 | 61.57 | 49.41 | 75.45 | 49.28 |
|
57 |
+
| **firefly-qwen1.5-en-7b-dpo-v0.1-unsloth** | 62.65 | 56.14 | 75.5 | 60.87 | 58.09 | 70.72 | 54.59 |
|
58 |
+
| zephyr-7b-beta | 61.95 | 62.03 | 84.36 | 61.07 | 57.45 | 77.74 | 29.04 |
|
59 |
+
| **firefly-qwen1.5-en-7b-unsloth** | 61.81 | 54.27 | 76.22 | 61.55 | 50.62 | 70.48 | 57.7 |
|
60 |
+
| vicuna-13b-v1.5 | 55.41 | 57.08 | 81.24 | 56.67 | 51.51 | 74.66 | 11.3 |
|
61 |
+
| Xwin-LM-13B-V0.1 | 55.29 | 62.54 | 82.8 | 56.53 | 45.96 | 74.27 | 9.63 |
|
62 |
+
| Qwen1.5-7B-Chat | 55.15 | 55.89 | 78.56 | 61.65 | 53.54 | 67.72 | 13.57 |
|
63 |
+
| gemma-7b-it | 53.56 | 51.45 | 71.96 | 53.52 | 47.29 | 67.96 | 29.19 |
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
## Usage
|
68 |
+
The chat templates of our chat models are the same as Official Qwen1.5-7B-Chat:
|
69 |
+
```text
|
70 |
+
<|im_start|>system
|
71 |
+
You are a helpful assistant.<|im_end|>
|
72 |
+
<|im_start|>user
|
73 |
+
hello, who are you?<|im_end|>
|
74 |
+
<|im_start|>assistant
|
75 |
+
I am a AI program developed by Firefly<|im_end|>
|
76 |
+
```
|
77 |
+
|
78 |
+
You can use script to inference in [Firefly](https://github.com/yangjianxin1/Firefly/blob/master/script/chat/chat.py).
|
79 |
+
|
80 |
+
You can also use the following code:
|
81 |
+
```python
|
82 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
83 |
+
import torch
|
84 |
+
|
85 |
+
model_name_or_path = "YeungNLP/firefly-qwen1.5-en-7b-unsloth"
|
86 |
+
model = AutoModelForCausalLM.from_pretrained(
|
87 |
+
model_name_or_path,
|
88 |
+
trust_remote_code=True,
|
89 |
+
low_cpu_mem_usage=True,
|
90 |
+
torch_dtype=torch.float16,
|
91 |
+
device_map='auto',
|
92 |
+
)
|
93 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
|
94 |
+
|
95 |
+
prompt = "Compose an engaging travel blog post about a recent trip to Hawaii, highlighting cultural experiences and must-see attractions. "
|
96 |
+
messages = [
|
97 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
98 |
+
{"role": "user", "content": prompt}
|
99 |
+
]
|
100 |
+
text = tokenizer.apply_chat_template(
|
101 |
+
messages,
|
102 |
+
tokenize=False,
|
103 |
+
add_generation_prompt=True
|
104 |
+
)
|
105 |
+
model_inputs = tokenizer([text], return_tensors="pt").to('cuda')
|
106 |
+
|
107 |
+
generated_ids = model.generate(
|
108 |
+
model_inputs.input_ids,
|
109 |
+
max_new_tokens=1500,
|
110 |
+
top_p = 0.9,
|
111 |
+
temperature = 0.35,
|
112 |
+
repetition_penalty = 1.0,
|
113 |
+
eos_token_id=tokenizer.encode('<|im_end|>', add_special_tokens=False)
|
114 |
+
)
|
115 |
+
generated_ids = [
|
116 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
117 |
+
]
|
118 |
+
|
119 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
120 |
+
print(response)
|
121 |
+
```
|
122 |
|
123 |
## Training Details
|
124 |
+
Both in SFT and DPO stages, **We only use a single V100 GPU** with QLoRA and Unsloth, and we use [Firefly](https://github.com/yangjianxin1/Firefly) to train our models.
|
125 |
+
|
126 |
+
### Training Setting
|
127 |
+
The following hyperparameters are used during SFT:
|
128 |
+
- num_epochs: 1
|
129 |
+
- learning_rate: 2e-4
|
130 |
+
- total_train_batch_size: 32
|
131 |
+
- max_seq_length: 2048
|
132 |
+
- optimizer: paged_adamw_32bit
|
133 |
+
- lr_scheduler_type: constant_with_warmup
|
134 |
+
- warmup_steps: 600
|
135 |
+
- lora_rank: 64
|
136 |
+
- lora_alpha: 16
|
137 |
+
- lora_dropout: 0.05
|
138 |
+
- gradient_checkpointing: true
|
139 |
+
- fp16: true
|
140 |
+
|
141 |
+
The following hyperparameters were used during DPO:
|
142 |
+
- num_epochs: 1
|
143 |
+
- learning_rate: 2e-4
|
144 |
+
- total_train_batch_size: 32
|
145 |
+
- max_seq_length: 2048
|
146 |
+
- max_prompt_length: 500
|
147 |
+
- optimizer: paged_adamw_32bit
|
148 |
+
- lr_scheduler_type: constant_with_warmup
|
149 |
+
- warmup_steps: 100
|
150 |
+
- lora_rank: 64
|
151 |
+
- lora_alpha: 16
|
152 |
+
- lora_dropout: 0.05
|
153 |
+
- gradient_checkpointing: true
|
154 |
+
- fp16: true
|
155 |
+
|
156 |
+
|
157 |
+
### Training metrics
|
158 |
+
|
159 |
+
The table below shows the full set of DPO training metrics:
|
160 |
+
|
161 |
+
| Epoch | Step | Loss | Rewards/accuracies | Rewards/margins | Rewards/chosen | Rewards/rejected | Logits/chosen | Logits/rejected | Logps/chosen | Logps/rejected |
|
162 |
+
|-------|------|--------|--------------------|-----------------|----------------|------------------|---------------|-----------------|--------------|----------------|
|
163 |
+
| 0.05 | 100 | 0.6128 | 0.6572 | 0.3914 | -0.0622 | -0.4537 | 1.107 | 1.1104 | -283.7632 | -264.5925 |
|
164 |
+
| 0.1 | 200 | 0.6066 | 0.6913 | 0.662 | -0.3589 | -1.0209 | 0.9433 | 0.9431 | -279.0002 | -268.6432 |
|
165 |
+
| 0.16 | 300 | 0.5803 | 0.7069 | 0.876 | -0.3849 | -1.2609 | 0.8411 | 0.8537 | -289.9482 | -274.3425 |
|
166 |
+
| 0.21 | 400 | 0.5624 | 0.7169 | 0.9575 | -0.2447 | -1.2022 | 0.7615 | 0.7497 | -293.8072 | -274.4167 |
|
167 |
+
| 0.26 | 500 | 0.5863 | 0.7 | 0.8908 | -0.5283 | -1.4191 | 0.537 | 0.5085 | -284.3388 | -267.9294 |
|
168 |
+
| 0.31 | 600 | 0.5612 | 0.7166 | 1.0791 | -0.592 | -1.6711 | 0.7121 | 0.7219 | -293.2425 | -278.5992 |
|
169 |
+
| 0.37 | 700 | 0.5741 | 0.7234 | 1.0742 | -0.8469 | -1.9211 | 0.6002 | 0.5769 | -300.8099 | -285.9137 |
|
170 |
+
| 0.42 | 800 | 0.582 | 0.7141 | 1.0414 | -1.1658 | -2.2072 | 0.7191 | 0.5934 | -300.458 | -286.1 |
|
171 |
+
| 0.47 | 900 | 0.5694 | 0.7178 | 1.2055 | -1.7372 | -2.9426 | 0.4226 | 0.316 | -305.5303 | -290.7548 |
|
172 |
+
| 0.52 | 1000 | 0.5827 | 0.7134 | 1.1063 | -1.354 | -2.4603 | 0.535 | 0.4022 | -302.7598 | -286.636 |
|
173 |
+
| 0.58 | 1100 | 0.5553 | 0.7306 | 1.3631 | -1.5861 | -2.9492 | 0.7636 | 0.6559 | -312.9375 | -290.3474 |
|
174 |
+
| 0.63 | 1200 | 0.5633 | 0.7341 | 1.2689 | -1.7187 | -2.9876 | 0.6555 | 0.5894 | -315.0179 | -298.2406 |
|
175 |
+
| 0.68 | 1300 | 0.5705 | 0.7284 | 1.3501 | -1.7762 | -3.1263 | 0.7419 | 0.6874 | -310.9056 | -294.2934 |
|
176 |
+
| 0.73 | 1400 | 0.5458 | 0.7347 | 1.4555 | -2.2377 | -3.6932 | 0.7279 | 0.6564 | -309.141 | -299.1613 |
|
177 |
+
| 0.79 | 1500 | 0.5797 | 0.7222 | 1.2937 | -2.4483 | -3.742 | 0.8444 | 0.771 | -321.578 | -298.111 |
|
178 |
+
| 0.84 | 1600 | 0.5572 | 0.7319 | 1.4824 | -2.9344 | -4.4168 | 0.9202 | 0.8605 | -323.4034 | -307.0114 |
|
179 |
+
| 0.89 | 1700 | 0.5518 | 0.7281 | 1.4263 | -2.7301 | -4.1564 | 0.9257 | 0.8785 | -313.694 | -298.1267 |
|
180 |
+
| 0.94 | 1800 | 0.5572 | 0.7272 | 1.5121 | -2.9505 | -4.4627 | 0.7899 | 0.7503 | -314.1552 | -305.9873 |
|
181 |
+
| 0.99 | 1900 | 0.5763 | 0.7241 | 1.4982 | -2.7064 | -4.2047 | 0.7841 | 0.7023 | -310.6677 | -299.5064 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|