alvarobartt HF staff commited on
Commit
cf6dd6c
1 Parent(s): b2e7df7

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +238 -0
README.md ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ language:
4
+ - en
5
+ - de
6
+ - fr
7
+ - it
8
+ - pt
9
+ - hi
10
+ - es
11
+ - th
12
+ library_name: transformers
13
+ pipeline_tag: text-generation
14
+ tags:
15
+ - llama-3.1
16
+ - meta
17
+ - autoawq
18
+ ---
19
+
20
+ > [!NOTE]
21
+ > Note that this is a community driven quantized version of the original model [`meta-llama/Meta-Llama-3.1-405B-Instruct`](https://huggingface.co/meta-llama/Meta-Llama-3.1-405B-Instruct) which is the FP16 half-precision official version released by Meta AI.
22
+
23
+ ## Model Information
24
+
25
+ The Meta Llama 3.1 collection of multilingual large language models (LLMs) is a collection of pretrained and instruction tuned generative models in 8B, 70B and 405B sizes (text in/text out). The Llama 3.1 instruction tuned text only models (8B, 70B, 405B) are optimized for multilingual dialogue use cases and outperform many of the available open source and closed chat models on common industry benchmarks.
26
+
27
+ **Model developer**: Meta
28
+
29
+ **Model Architecture:** Llama 3.1 is an auto-regressive language model that uses an optimized transformer architecture. The tuned versions use supervised fine-tuning (SFT) and reinforcement learning with human feedback (RLHF) to align with human preferences for helpfulness and safety.
30
+
31
+ <table>
32
+ <tr>
33
+ <td>
34
+ </td>
35
+ <td><strong>Training Data</strong>
36
+ </td>
37
+ <td><strong>Params</strong>
38
+ </td>
39
+ <td><strong>Input modalities</strong>
40
+ </td>
41
+ <td><strong>Output modalities</strong>
42
+ </td>
43
+ <td><strong>Context length</strong>
44
+ </td>
45
+ <td><strong>GQA</strong>
46
+ </td>
47
+ <td><strong>Token count</strong>
48
+ </td>
49
+ <td><strong>Knowledge cutoff</strong>
50
+ </td>
51
+ </tr>
52
+ <tr>
53
+ <td rowspan="3" >Llama 3.1 (text only)
54
+ </td>
55
+ <td rowspan="3" >A new mix of publicly available online data.
56
+ </td>
57
+ <td>8B
58
+ </td>
59
+ <td>Multilingual Text
60
+ </td>
61
+ <td>Multilingual Text and code
62
+ </td>
63
+ <td>128k
64
+ </td>
65
+ <td>Yes
66
+ </td>
67
+ <td rowspan="3" >15T+
68
+ </td>
69
+ <td rowspan="3" >December 2023
70
+ </td>
71
+ </tr>
72
+ <tr>
73
+ <td>70B
74
+ </td>
75
+ <td>Multilingual Text
76
+ </td>
77
+ <td>Multilingual Text and code
78
+ </td>
79
+ <td>128k
80
+ </td>
81
+ <td>Yes
82
+ </td>
83
+ </tr>
84
+ <tr>
85
+ <td>405B
86
+ </td>
87
+ <td>Multilingual Text
88
+ </td>
89
+ <td>Multilingual Text and code
90
+ </td>
91
+ <td>128k
92
+ </td>
93
+ <td>Yes
94
+ </td>
95
+ </tr>
96
+ </table>
97
+
98
+ **Supported languages:** English, German, French, Italian, Portuguese, Hindi, Spanish, and Thai.
99
+
100
+ **Llama 3.1 family of models**. Token counts refer to pretraining data only. All model versions use Grouped-Query Attention (GQA) for improved inference scalability.
101
+
102
+ **Model Release Date:** July 23, 2024.
103
+
104
+ **Status:** This is a static model trained on an offline dataset. Future versions of the tuned models will be released as we improve model safety with community feedback.
105
+
106
+ **License:** A custom commercial license, the Llama 3.1 Community License, is available at: [https://github.com/meta-llama/llama-models/blob/main/models/llama3_1/LICENSE](https://github.com/meta-llama/llama-models/blob/main/models/llama3_1/LICENSE)
107
+
108
+ Where to send questions or comments about the model Instructions on how to provide feedback or comments on the model can be found in the model [README](https://github.com/meta-llama/llama3). For more technical information about generation parameters and recipes for how to use Llama 3.1 in applications, please go [here](https://github.com/meta-llama/llama-recipes).
109
+
110
+ For more information please refer to the original model card [`meta-llama/Meta-Llama-3.1-405B-Instruct`](https://huggingface.co/meta-llama/Meta-Llama-3.1-405B-Instruct).
111
+
112
+ ## Quantized Model Information
113
+
114
+ Llama 3.1 405B Instruct has been quantized using [AutoAWQ](https://github.com/casperhansen/AutoAWQ) from FP16 down to INT4 using the GEMM kernels performing zero-point quantization with a group size of 128.
115
+
116
+ In order to quantize Llama 3.1 405B Instruct, we had to first install `torch` and `autoawq` as follows:
117
+
118
+ ```bash
119
+ pip install "torch>=2.2.0,<2.3.0" autoawq --upgrade
120
+ ```
121
+
122
+ Otherwise the quantization may fail, since the AutoAWQ kernels are built with PyTorch 2.2.1, meaning that those will break with PyTorch 2.3.0.
123
+
124
+ Then we install the latest version of `transformers` as follows:
125
+
126
+ ```bash
127
+ pip install "transformers>=4.43.0" --upgrade
128
+ ```
129
+
130
+ And then we can run the following script, adapted from [`AutoAWQ/examples/quantize.py`](https://github.com/casper-hansen/AutoAWQ/blob/main/examples/quantize.py) as follows:
131
+
132
+ ```python
133
+ from awq import AutoAWQForCausalLM
134
+ from transformers import AutoTokenizer
135
+
136
+ model_path = "meta-llama/Meta-Llama-3.1-405B-Instruct"
137
+ quant_path = "hugging-quants/Meta-Llama-3.1-405B-Instruct-AWQ-INT4"
138
+ quant_config = {
139
+ "zero_point": True,
140
+ "q_group_size": 128,
141
+ "w_bit": 4,
142
+ "version": "GEMM",
143
+ }
144
+
145
+ # Load model
146
+ model = AutoAWQForCausalLM.from_pretrained(
147
+ model_path, **{"low_cpu_mem_usage": True, "use_cache": False}
148
+ )
149
+ tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
150
+
151
+ # Quantize
152
+ model.quantize(tokenizer, quant_config=quant_config)
153
+
154
+ # Save quantized model
155
+ model.save_quantized(quant_path)
156
+ tokenizer.save_pretrained(quant_path)
157
+
158
+ print(f'Model is quantized and saved at "{quant_path}"')
159
+ ```
160
+
161
+ ## Quantized Model Usage
162
+
163
+ In order to use the current quantized model, we offer support for different alternatives:
164
+
165
+ ### 🤗 transformers
166
+
167
+ To run the inference on top of Llama 3.1 405B Instruct AWQ in INT4 precision, we can instantiate the AWQ model as any other causal language modeling model via `AutoModelForCausalLM` and run the inference normally.
168
+
169
+ ```python
170
+ import torch
171
+ from transformers import AutoModelForCausalLM, AutoTokenizer
172
+
173
+ model_id = "hugging-quants/Meta-Llama-3.1-405B-Instruct-AWQ-INT4"
174
+ prompt = [
175
+ {"role": "system", "content": "You are a helpful assistant, that responds as a pirate."},
176
+ {"role": "user", "content": "What's Deep Learning?"},
177
+ ]
178
+
179
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
180
+ tokenizer.pad_token_id = tokenizer.eos_token_id
181
+ tokenizer.padding_side = "left"
182
+
183
+ terminators = [
184
+ tokenizer.eos_token_id,
185
+ tokenizer.convert_tokens_to_ids("<|eot_id|>"),
186
+ ]
187
+
188
+ inputs = tokenizer.apply_chat_template(prompt, tokenize=True, add_generation_prompt=True, return_tensors="pt").cuda()
189
+
190
+ model = AutoModelForCausalLM.from_pretrained(
191
+ model_id,
192
+ torch_dtype=torch.float16,
193
+ low_cpu_mem_usage=True,
194
+ device_map="auto",
195
+ )
196
+
197
+ outputs = model.generate(**inputs, do_sample=True, max_new_tokens=256, eos_token_id=terminators)
198
+ print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
199
+ ```
200
+
201
+ ### AutoAWQ
202
+
203
+ Alternatively, one may want to run that via `AutoAWQ` even though it's built on top of 🤗 `transformers`, which is the recommended approach instead as described above.
204
+
205
+ ```python
206
+ import torch
207
+ from autoawq import AutoAWQForCausalLM
208
+ from transformers import AutoModelForCausalLM, AutoTokenizer
209
+
210
+ model_id = "hugging-quants/Meta-Llama-3.1-405B-Instruct-AWQ-INT4"
211
+ prompt = [
212
+ {"role": "system", "content": "You are a helpful assistant, that responds as a pirate."},
213
+ {"role": "user", "content": "What's Deep Learning?"},
214
+ ]
215
+
216
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
217
+ tokenizer.pad_token_id = tokenizer.eos_token_id
218
+ tokenizer.padding_side = "left"
219
+
220
+ inputs = tokenizer.apply_chat_template(prompt, tokenize=True, add_generation_prompt=True, return_tensors="pt").cuda()
221
+
222
+ model = AutoAWQForCausalLM.from_pretrained(
223
+ model_id,
224
+ torch_dtype=torch.float16,
225
+ low_cpu_mem_usage=True,
226
+ device_map="auto",
227
+ fuse_layers=True,
228
+ )
229
+
230
+ outputs = model.generate(**inputs, do_sample=True, max_new_tokens=256)
231
+ print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
232
+ ```
233
+
234
+ The AutoAWQ script has been adapted from [AutoAWQ/examples/generate.py](https://github.com/casper-hansen/AutoAWQ/blob/main/examples/generate.py).
235
+
236
+ ### 🤗 Text Generation Inference (TGI)
237
+
238
+ Coming soon!