YuxinJiang commited on
Commit
0c5c41b
1 Parent(s): 63620f5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +4 -250
README.md CHANGED
@@ -2,258 +2,12 @@
2
  license: mit
3
  ---
4
 
5
- # Note: To comply with the LLaMA model license, we release Lion weights as _delta weights_.
6
 
7
- # Lion: Adversarial Distillation of Closed-Source Large Language Model
8
- <p align="center" width="100%">
9
- <a ><img src="https://github.com/YJiangcm/Lion/raw/master/pics/Lion.jpg" alt="Lion" style="width: 20%; min-width: 200px; display: block; margin: auto;"></a>
10
- </p>
11
- <p align="center">
12
- <a href="https://arxiv.org/abs/2305.12870">[📄 Paper]</a> |
13
- <a href="https://github.com/YJiangcm/Lion">[⌨ Github]</a> |
14
- <a href="https://67cd0230230f39d7.gradio.app/">[💻 Demo]</a>
15
- </p>
16
 
17
- ### Tuned on 70k instruction-following data, Lion (7B) can achieve 95% capability of ChatGPT!
18
- <p align="center">
19
- <img width="500" height="250" src="https://github.com/YJiangcm/Lion/raw/master/pics/relative_quality_overall.jpg">
20
- </p>
21
 
22
- ## News
23
- - **[May 26, 2023]** We released the model weights. Check out the [7B](https://huggingface.co/YuxinJiang/Lion) model!
24
- - **[May 25, 2023]** We released an [online demo](https://67cd0230230f39d7.gradio.app/), try our model here!
25
- - **[May 23, 2023]** We released the code for training and inference.
26
 
27
- <!-- :pray: Since our team members are perparing for the PhD Qualifying Exam, we apologize for any possible delay in responding to your questions. We warmly welcome all inquiries and appreciate your constructive feedback :) -->
28
 
29
- ## Contents
30
-
31
- 1. [Overview](#overview)
32
-
33
- 2. [Online Demo](#online-demo)
34
-
35
- 3. [Recovering Lion weights](#recovering-lion-weights)
36
-
37
- 4. [Inference](#inference)
38
-
39
- 5. [Training Process](#training-process)
40
-
41
- 6. [Evaluation](#evaluation)
42
-
43
- 7. [Citation](#citation)
44
-
45
- 8. [Disclaimer](#disclaimer)
46
-
47
-
48
- ## Overview
49
- <p align="center">
50
- <img width="700" height="320" src="https://github.com/YJiangcm/Lion/raw/master/pics/overview.jpg">
51
- </p>
52
-
53
- The high-level overview of our adversarial distillation framework, where we craft a compact Student LLM based on a superior closed-source LLM that serves three roles: the **Teacher**, the **Referee**, and the **Generator**. From left to right, there are three stages in an iteration:
54
- 1) an _imitation_ stage to align the student’s response with the teacher’s response;
55
- 2) a _discrimination_ stage to identify hard samples;
56
- 3) a _generation_ stage to produce new hard samples for escalating the challenges presented to the student model.
57
-
58
-
59
- ## Online Demo
60
- We will provide our latest models for you to try for as long as possible. You may ask some questions to Lion and we are happy to hear your feedback!
61
-
62
- [**Demo Link**](https://67cd0230230f39d7.gradio.app/) (the UI interface is shown below)
63
-
64
- <p align="center">
65
- <img width="800" height="350" src="https://github.com/YJiangcm/Lion/raw/master/pics/english_case2.png">
66
- </p>
67
-
68
- Since the training data are English instruction-following examples, You'd better ask questions in English. However, we found Lion can also understand instructions in other languages to some extent. See the following case:
69
-
70
- <p align="center">
71
- <img width="800" height="350" src="https://github.com/YJiangcm/Lion/raw/master/pics/chinese_case.png">
72
- </p>
73
-
74
-
75
- ## Recovering Lion weights
76
- We release Lion weights as delta weights to comply with the LLaMA model license.
77
-
78
- - [Lion-7B (delta weights)](https://huggingface.co/YuxinJiang/Lion)
79
-
80
- You can add our delta to the original LLaMA weights to obtain the Lion weights. Instructions:
81
- 1. Get the original LLaMA weights in the huggingface format by following the instructions [here](https://huggingface.co/docs/transformers/main/model_doc/llama)
82
- 2. Please download our delta model from [Hugging Face](https://huggingface.co/YuxinJiang/Lion)
83
- 3. Use the following scripts to get Lion weights by applying our delta:
84
- ```bash
85
- python src/weight_diff.py recover --path_raw huggyllama/llama-7b --path_diff YuxinJiang/Lion --path_tuned <path_to_store_recovered_weights>
86
- ```
87
-
88
- ## Inference
89
- For inference and training of Lion, please first install the requirements:
90
- ```bash
91
- pip install -r requirements.txt
92
- ```
93
-
94
- We provide the decoding script for Lion, which reads a input file and generates corresponding responses for each sample, and finally consolidates them into an output file.
95
- ```bash
96
- python src/lion_inference.py \
97
- --model_dir <path_to_hf_converted_lion_ckpt_and_tokenizer> \
98
- --data_dir <path_to_input_json_file> \
99
- --output_dir <path_to_output_json_file> \
100
- --num_gpus 8
101
- ```
102
-
103
-
104
- ## Training Process
105
- Below shows one iteration of our adversarial distillation framework.
106
- ### 1. Imitation Stage
107
- #### 1.1 Acquire the teacher's response on the Train Pool
108
-
109
- ```bash
110
- python src/chatgpt_inference.py \
111
- -q <path_to_json_file_for_the_Train_Pool> \
112
- -o <path_to_chatgpt_inference_for_the_Train_Pool> \
113
- --api_key <your_openai_api_key>
114
- ```
115
-
116
- #### 1.2 Instruction-tuning the student based on the teacher’s response on the Train Pool
117
-
118
- Fine-tuning was conducted on on a machine with 8 A100 80G GPUs.
119
-
120
- ```bash
121
- torchrun --nproc_per_node=8 --master_port=<your_random_port> src/train.py \
122
- --model_name_or_path <path_to_hf_converted_ckpt_and_tokenizer> \
123
- --data_path <path_to_chatgpt_inference_for_the_Train_Pool> \
124
- --bf16 True \
125
- --output_dir result \
126
- --num_train_epochs 3 \
127
- --model_max_length 1024 \
128
- --per_device_train_batch_size 1 \
129
- --per_device_eval_batch_size 1 \
130
- --gradient_accumulation_steps 8 \
131
- --evaluation_strategy "no" \
132
- --save_strategy "steps" \
133
- --save_steps 500 \
134
- --save_total_limit 1 \
135
- --learning_rate 2e-5 \
136
- --weight_decay 0. \
137
- --warmup_ratio 0.03 \
138
- --lr_scheduler_type "cosine" \
139
- --logging_steps 1 \
140
- --fsdp "full_shard auto_wrap" \
141
- --fsdp_transformer_layer_cls_to_wrap 'LlamaDecoderLayer' \
142
- --tf32 True
143
- ```
144
-
145
- ### 2. Discrimination Stage
146
- #### 2.1 Acquire the teacher's response on the Cache Pool
147
-
148
- ```bash
149
- python src/chatgpt_inference.py \
150
- -q <path_to_json_file_for_the_Cache_Pool> \
151
- -o <path_to_chatgpt_inference_for_the_Cache_Pool> \
152
- --api_key <your_openai_api_key>
153
- ```
154
-
155
- #### 2.2 Acquire the student's response on the Cache Pool
156
-
157
- ```bash
158
- python src/lion_inference.py \
159
- --model_dir <path_to_hf_converted_lion_ckpt_and_tokenizer> \
160
- --data_dir <path_to_json_file_for_the_Cache_Pool> \
161
- --output_dir <path_to_lion_inference_for_the_Cache_Pool> \
162
- --num_gpus 8
163
- ```
164
-
165
- #### 2.3 Ask the referee to output two scores according to the respose quality of the teacher and the student
166
-
167
- ```bash
168
- python src/chatgpt_referee.py \
169
- -a <path_to_chatgpt_inference_for_the_Cache_Pool> <path_to_lion_inference_for_the_Cache_Pool> \
170
- -o <path_to_output_review_file> \
171
- --api_key <your_openai_api_key>
172
- ```
173
-
174
- #### 2.4 Discriminate hard instructions and easy instructions
175
-
176
- ```bash
177
- python src/discrimination.py \
178
- --review_path <path_to_output_review_file> \
179
- --chatgpt_inference_path <path_to_chatgpt_inference_for_the_Cache_Pool> \
180
- --lion_inference_path path_to_lion_inference_for_the_Cache_Pool \
181
- --hard_save_path <path_to_identified_hard_instructions> \
182
- --easy_save_path <path_to_identified_easy_instructions>
183
- ```
184
-
185
- ### 3. Generation Stage
186
- Fill the `openai.api_key = "<you_openai_api_key>"` in [src/utils.py](https://github.com/YJiangcm/Lion/raw/master/src/utils.py).
187
- #### 3.1 Generate new hard instructions
188
-
189
- ```bash
190
- python -m src/generate_hard_instruction generate_instruction_following_data \
191
- --seed_tasks_path <path_to_identified_hard_instructions> \
192
- --output_dir <path_to_generated_hard_instructions> \
193
- --num_instructions_to_generate 3000
194
- ```
195
- #### 3.2 Generate new easy instructions
196
- ```bash
197
- python -m src/generate_easy_instruction generate_instruction_following_data \
198
- --seed_tasks_path <path_to_identified_easy_instructions> \
199
- --output_dir <path_to_generated_easy_instructions> \
200
- --num_instructions_to_generate 3000
201
- ```
202
-
203
- ## Evaluation
204
-
205
- ### Automatic Evaluation with GPT-4
206
- we leverage GPT-4 to automatically rate the response quality (with scores from 1 to 10) between two models on 80 unseen [Vicuna-Instructions](https://github.com/lm-sys/FastChat/blob/main/fastchat/eval/table/question.jsonl).
207
- ChatGPT has been chosen as the reference model to estimate the relative capability of diverse LLMs against it. The relative score is reported in percentage, computed as the ratio of the sum of scores.
208
-
209
- **Relative Overall Response Quality**:
210
-
211
- <p align="center">
212
- <img width="500" height="250" src="https://github.com/YJiangcm/Lion/raw/master/pics/relative_quality_overall.jpg">
213
- </p>
214
-
215
- **Relative Response Quality of Diverse Task Categories**:
216
-
217
- <p align="center">
218
- <img width="700" height="330" src="https://github.com/YJiangcm/Lion/raw/master/pics/relative_quality_category.jpg">
219
- </p>
220
-
221
- ### Human Evaluation with Alignment Criteria
222
- We employ the alignment criteria proposed by Askell et al. (2021), which define that an assistant is considered aligned if it is characterized by being helpful, honest, and
223
- harmless (HHH). We performed a human evaluation on 252 [UserOriented-Instructions](https://github.com/yizhongw/self-instruct/blob/main/human_eval/user_oriented_instructions.jsonl). To estimate the won rate, we compare the frequency of won, tie, and lost between each pair
224
- of models below.
225
-
226
- <p align="center">
227
- <img width="500" height="300" src="https://github.com/YJiangcm/Lion/raw/master/pics/252task_win.jpg">
228
- </p>
229
-
230
-
231
- ## Citation
232
- Please cite our paper if you use the code in this repo.
233
-
234
- ```
235
- @article{DBLP:journals/corr/abs-2305-12870,
236
- author = {Yuxin Jiang and
237
- Chunkit Chan and
238
- Mingyang Chen and
239
- Wei Wang},
240
- title = {Lion: Adversarial Distillation of Closed-Source Large Language Model},
241
- journal = {CoRR},
242
- volume = {abs/2305.12870},
243
- year = {2023},
244
- url = {https://doi.org/10.48550/arXiv.2305.12870},
245
- doi = {10.48550/arXiv.2305.12870},
246
- eprinttype = {arXiv},
247
- eprint = {2305.12870},
248
- biburl = {https://dblp.org/rec/journals/corr/abs-2305-12870.bib},
249
- bibsource = {dblp computer science bibliography, https://dblp.org}
250
- }
251
- ```
252
-
253
-
254
-
255
-
256
- ## Disclaimer
257
- ⚠️ Lion is intended and licensed for **research use ONLY**. Commercial use is **strictly prohibited**.
258
- The content produced by any version of Lion is influenced by uncontrollable variables such as randomness, and therefore, the accuracy of the output cannot be guaranteed by this project.
259
- This project does not accept any legal liability for the content of the model output, nor does it assume responsibility for any losses incurred due to the use of associated resources and output results.
 
2
  license: mit
3
  ---
4
 
 
5
 
 
 
 
 
 
 
 
 
 
6
 
7
+ # Lion: Adversarial Distillation of Proprietary Large Language Models (EMNLP 2023)
 
 
 
8
 
9
+ arXiv link: https://arxiv.org/abs/2305.12870
10
+ Github: https://github.com/YJiangcm/Lion
 
 
11
 
 
12
 
13
+ **Note: To comply with the LLaMA model license, we release Lion weights as _delta weights_.**