JunHowie commited on
Commit
fcc8f70
·
verified ·
1 Parent(s): eb08e77

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +193 -0
README.md ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ license: apache-2.0
4
+ license_link: https://huggingface.co/Qwen/Qwen2-7B-Instruct/blob/main/LICENSE
5
+ pipeline_tag: text-generation
6
+ tags:
7
+ - Qwen2
8
+ - GPTQ
9
+ - Int8
10
+ - 量化修复
11
+ - vLLM
12
+ base_model:
13
+ - Qwen/Qwen2-7B-Instruct
14
+ base_model_relation: quantized
15
+ ---
16
+ # Qwen2-7B-Instruct-GPTQ-Int8
17
+ Base model: [Qwen/Qwen2-7B-Instruct](https://huggingface.co/Qwen/Qwen2-7B-Instruct)
18
+
19
+ <i>This model is quantized to 8-bit with a group size of 128.</i>
20
+
21
+ ```
22
+ vllm serve JunHowie/Qwen2-7B-Instruct-GPTQ-Int8
23
+ ```
24
+
25
+ ### 【Dependencies】
26
+ ```
27
+ vllm>=0.4.3
28
+ ```
29
+
30
+ ### 【Model Download】
31
+
32
+ ```python
33
+ from huggingface_hub import snapshot_download
34
+ snapshot_download('JunHowie/Qwen2-7B-Instruct-GPTQ-Int8', cache_dir="your_local_path")
35
+ ```
36
+
37
+ ### 【Overview】
38
+ # Qwen2-7B-Instruct
39
+
40
+ ## Introduction
41
+
42
+ Qwen2 is the new series of Qwen large language models. For Qwen2, we release a number of base language models and instruction-tuned language models ranging from 0.5 to 72 billion parameters, including a Mixture-of-Experts model. This repo contains the instruction-tuned 7B Qwen2 model.
43
+
44
+ Compared with the state-of-the-art opensource language models, including the previous released Qwen1.5, Qwen2 has generally surpassed most opensource models and demonstrated competitiveness against proprietary models across a series of benchmarks targeting for language understanding, language generation, multilingual capability, coding, mathematics, reasoning, etc.
45
+
46
+ Qwen2-7B-Instruct supports a context length of up to 131,072 tokens, enabling the processing of extensive inputs. Please refer to [this section](#processing-long-texts) for detailed instructions on how to deploy Qwen2 for handling long texts.
47
+
48
+ For more details, please refer to our [blog](https://qwenlm.github.io/blog/qwen2/), [GitHub](https://github.com/QwenLM/Qwen2), and [Documentation](https://qwen.readthedocs.io/en/latest/).
49
+ <br>
50
+
51
+ ## Model Details
52
+ Qwen2 is a language model series including decoder language models of different model sizes. For each size, we release the base language model and the aligned chat model. It is based on the Transformer architecture with SwiGLU activation, attention QKV bias, group query attention, etc. Additionally, we have an improved tokenizer adaptive to multiple natural languages and codes.
53
+
54
+ ## Training details
55
+ We pretrained the models with a large amount of data, and we post-trained the models with both supervised finetuning and direct preference optimization.
56
+
57
+
58
+ ## Requirements
59
+ The code of Qwen2 has been in the latest Hugging face transformers and we advise you to install `transformers>=4.37.0`, or you might encounter the following error:
60
+ ```
61
+ KeyError: 'qwen2'
62
+ ```
63
+
64
+ ## Quickstart
65
+
66
+ Here provides a code snippet with `apply_chat_template` to show you how to load the tokenizer and model and how to generate contents.
67
+
68
+ ```python
69
+ from transformers import AutoModelForCausalLM, AutoTokenizer
70
+ device = "cuda" # the device to load the model onto
71
+
72
+ model = AutoModelForCausalLM.from_pretrained(
73
+ "Qwen/Qwen2-7B-Instruct",
74
+ torch_dtype="auto",
75
+ device_map="auto"
76
+ )
77
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2-7B-Instruct")
78
+
79
+ prompt = "Give me a short introduction to large language model."
80
+ messages = [
81
+ {"role": "system", "content": "You are a helpful assistant."},
82
+ {"role": "user", "content": prompt}
83
+ ]
84
+ text = tokenizer.apply_chat_template(
85
+ messages,
86
+ tokenize=False,
87
+ add_generation_prompt=True
88
+ )
89
+ model_inputs = tokenizer([text], return_tensors="pt").to(device)
90
+
91
+ generated_ids = model.generate(
92
+ model_inputs.input_ids,
93
+ max_new_tokens=512
94
+ )
95
+ generated_ids = [
96
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
97
+ ]
98
+
99
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
100
+ ```
101
+
102
+ ### Processing Long Texts
103
+
104
+ To handle extensive inputs exceeding 32,768 tokens, we utilize [YARN](https://arxiv.org/abs/2309.00071), a technique for enhancing model length extrapolation, ensuring optimal performance on lengthy texts.
105
+
106
+ For deployment, we recommend using vLLM. You can enable the long-context capabilities by following these steps:
107
+
108
+ 1. **Install vLLM**: You can install vLLM by running the following command.
109
+
110
+ ```bash
111
+ pip install "vllm>=0.4.3"
112
+ ```
113
+
114
+ Or you can install vLLM from [source](https://github.com/vllm-project/vllm/).
115
+
116
+ 2. **Configure Model Settings**: After downloading the model weights, modify the `config.json` file by including the below snippet:
117
+ ```json
118
+ {
119
+ "architectures": [
120
+ "Qwen2ForCausalLM"
121
+ ],
122
+ // ...
123
+ "vocab_size": 152064,
124
+
125
+ // adding the following snippets
126
+ "rope_scaling": {
127
+ "factor": 4.0,
128
+ "original_max_position_embeddings": 32768,
129
+ "type": "yarn"
130
+ }
131
+ }
132
+ ```
133
+ This snippet enable YARN to support longer contexts.
134
+
135
+ 3. **Model Deployment**: Utilize vLLM to deploy your model. For instance, you can set up an openAI-like server using the command:
136
+
137
+ ```bash
138
+ python -m vllm.entrypoints.openai.api_server --served-model-name Qwen2-7B-Instruct --model path/to/weights
139
+ ```
140
+
141
+ Then you can access the Chat API by:
142
+
143
+ ```bash
144
+ curl http://localhost:8000/v1/chat/completions \
145
+ -H "Content-Type: application/json" \
146
+ -d '{
147
+ "model": "Qwen2-7B-Instruct",
148
+ "messages": [
149
+ {"role": "system", "content": "You are a helpful assistant."},
150
+ {"role": "user", "content": "Your Long Input Here."}
151
+ ]
152
+ }'
153
+ ```
154
+
155
+ For further usage instructions of vLLM, please refer to our [Github](https://github.com/QwenLM/Qwen2).
156
+
157
+ **Note**: Presently, vLLM only supports static YARN, which means the scaling factor remains constant regardless of input length, **potentially impacting performance on shorter texts**. We advise adding the `rope_scaling` configuration only when processing long contexts is required.
158
+
159
+ ## Evaluation
160
+
161
+ We briefly compare Qwen2-7B-Instruct with similar-sized instruction-tuned LLMs, including Qwen1.5-7B-Chat. The results are shown below:
162
+
163
+ | Datasets | Llama-3-8B-Instruct | Yi-1.5-9B-Chat | GLM-4-9B-Chat | Qwen1.5-7B-Chat | Qwen2-7B-Instruct |
164
+ | :--- | :---: | :---: | :---: | :---: | :---: |
165
+ | _**English**_ | | | | | |
166
+ | MMLU | 68.4 | 69.5 | **72.4** | 59.5 | 70.5 |
167
+ | MMLU-Pro | 41.0 | - | - | 29.1 | **44.1** |
168
+ | GPQA | **34.2** | - | **-** | 27.8 | 25.3 |
169
+ | TheroemQA | 23.0 | - | - | 14.1 | **25.3** |
170
+ | MT-Bench | 8.05 | 8.20 | 8.35 | 7.60 | **8.41** |
171
+ | _**Coding**_ | | | | | |
172
+ | Humaneval | 62.2 | 66.5 | 71.8 | 46.3 | **79.9** |
173
+ | MBPP | **67.9** | - | - | 48.9 | 67.2 |
174
+ | MultiPL-E | 48.5 | - | - | 27.2 | **59.1** |
175
+ | Evalplus | 60.9 | - | - | 44.8 | **70.3** |
176
+ | LiveCodeBench | 17.3 | - | - | 6.0 | **26.6** |
177
+ | _**Mathematics**_ | | | | | |
178
+ | GSM8K | 79.6 | **84.8** | 79.6 | 60.3 | 82.3 |
179
+ | MATH | 30.0 | 47.7 | **50.6** | 23.2 | 49.6 |
180
+ | _**Chinese**_ | | | | | |
181
+ | C-Eval | 45.9 | - | 75.6 | 67.3 | **77.2** |
182
+ | AlignBench | 6.20 | 6.90 | 7.01 | 6.20 | **7.21** |
183
+
184
+ ## Citation
185
+
186
+ If you find our work helpful, feel free to give us a cite.
187
+
188
+ ```
189
+ @article{qwen2,
190
+ title={Qwen2 Technical Report},
191
+ year={2024}
192
+ }
193
+ ```