abhinavkulkarni
commited on
Commit
•
ecc86ee
1
Parent(s):
d7c1f39
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
pipeline_tag: text-generation
|
5 |
+
inference: false
|
6 |
+
tags:
|
7 |
+
- facebook
|
8 |
+
- meta
|
9 |
+
- pytorch
|
10 |
+
- llama
|
11 |
+
- llama-2
|
12 |
+
---
|
13 |
+
|
14 |
+
# **Llama 2** (4-bit 128g AWQ Quantized)
|
15 |
+
Llama 2 is a collection of pretrained and fine-tuned generative text models ranging in scale from 7 billion to 70 billion parameters. This is the repository for the 13B pretrained model, converted for the Hugging Face Transformers format.
|
16 |
+
|
17 |
+
This model is a 4-bit 128 group size AWQ quantized model. For more information about AWQ quantization, please click [here](https://github.com/mit-han-lab/llm-awq).
|
18 |
+
|
19 |
+
## Model Date
|
20 |
+
|
21 |
+
July 19, 2023
|
22 |
+
|
23 |
+
## Model License
|
24 |
+
|
25 |
+
Please refer to the original LLaMA 2 model license ([link](https://huggingface.co/meta-llama/Llama-2-13b-hf)).
|
26 |
+
|
27 |
+
Please refer to the AWQ quantization license ([link](https://github.com/llm-awq/blob/main/LICENSE)).
|
28 |
+
|
29 |
+
## CUDA Version
|
30 |
+
|
31 |
+
This model was successfully tested on CUDA driver v530.30.02 and runtime v11.7 with Python v3.10.11. Please note that AWQ requires NVIDIA GPUs with compute capability of `8.0` or higher.
|
32 |
+
|
33 |
+
For Docker users, the `nvcr.io/nvidia/pytorch:23.06-py3` image is runtime v12.1 but otherwise the same as the configuration above and has also been verified to work.
|
34 |
+
|
35 |
+
## How to Use
|
36 |
+
|
37 |
+
```bash
|
38 |
+
git clone https://github.com/abhinavkulkarni/llm-awq \
|
39 |
+
&& cd llm-awq \
|
40 |
+
&& git checkout e977c5a570c5048b67a45b1eb823b81de02d0d60 \
|
41 |
+
&& pip install -e . \
|
42 |
+
&& cd awq/kernels \
|
43 |
+
&& python setup.py install
|
44 |
+
```
|
45 |
+
|
46 |
+
```python
|
47 |
+
import torch
|
48 |
+
from awq.quantize.quantizer import real_quantize_model_weight
|
49 |
+
from transformers import AutoModelForCausalLM, AutoConfig, AutoTokenizer
|
50 |
+
from accelerate import init_empty_weights, load_checkpoint_and_dispatch
|
51 |
+
from huggingface_hub import snapshot_download
|
52 |
+
|
53 |
+
model_name = "abhinavkulkarni/meta-llama-Llama-2-13b-chat-hf-w4-g128-awq"
|
54 |
+
|
55 |
+
# Config
|
56 |
+
config = AutoConfig.from_pretrained(model_name, trust_remote_code=True)
|
57 |
+
|
58 |
+
# Tokenizer
|
59 |
+
tokenizer = AutoTokenizer.from_pretrained(config.tokenizer_name)
|
60 |
+
|
61 |
+
# Model
|
62 |
+
w_bit = 4
|
63 |
+
q_config = {
|
64 |
+
"zero_point": True,
|
65 |
+
"q_group_size": 128,
|
66 |
+
}
|
67 |
+
|
68 |
+
load_quant = snapshot_download(model_name)
|
69 |
+
|
70 |
+
with init_empty_weights():
|
71 |
+
model = AutoModelForCausalLM.from_config(config=config,
|
72 |
+
torch_dtype=torch.float16, trust_remote_code=True)
|
73 |
+
|
74 |
+
real_quantize_model_weight(model, w_bit=w_bit, q_config=q_config, init_only=True)
|
75 |
+
|
76 |
+
model = load_checkpoint_and_dispatch(model, load_quant, device_map="balanced")
|
77 |
+
|
78 |
+
# Inference
|
79 |
+
prompt = f'''What is the difference between nuclear fusion and fission?
|
80 |
+
###Response:'''
|
81 |
+
|
82 |
+
input_ids = tokenizer(prompt, return_tensors='pt').input_ids.cuda()
|
83 |
+
output = model.generate(
|
84 |
+
inputs=input_ids,
|
85 |
+
temperature=0.7,
|
86 |
+
max_new_tokens=512,
|
87 |
+
top_p=0.15,
|
88 |
+
top_k=0,
|
89 |
+
repetition_penalty=1.1,
|
90 |
+
eos_token_id=tokenizer.eos_token_id
|
91 |
+
)
|
92 |
+
```
|
93 |
+
|
94 |
+
## Evaluation
|
95 |
+
|
96 |
+
This evaluation was done using [LM-Eval](https://github.com/EleutherAI/lm-evaluation-harness).
|
97 |
+
|
98 |
+
[Llama-2-13b-chat](https://huggingface.co/meta-llama/Llama-2-13b-chat-hf)
|
99 |
+
|
100 |
+
| Task |Version| Metric | Value | |Stderr|
|
101 |
+
|--------|------:|---------------|------:|---|------|
|
102 |
+
|wikitext| 1|word_perplexity|10.7231| | |
|
103 |
+
| | |byte_perplexity| 1.5584| | |
|
104 |
+
| | |bits_per_byte | 0.6401| | |
|
105 |
+
|
106 |
+
[Llama-2-13b-chat (4-bit 128-group AWQ)](https://huggingface.co/abhinavkulkarni/meta-llama-Llama-2-13b-chat-hf-w4-g128-awq)
|
107 |
+
|
108 |
+
| Task |Version| Metric | Value | |Stderr|
|
109 |
+
|--------|------:|---------------|------:|---|------|
|
110 |
+
|wikitext| 1|word_perplexity|10.9812| | |
|
111 |
+
| | |byte_perplexity| 1.5653| | |
|
112 |
+
| | |bits_per_byte | 0.6465| | |
|
113 |
+
|
114 |
+
## Acknowledgements
|
115 |
+
|
116 |
+
The model was quantized with AWQ technique. If you find AWQ useful or relevant to your research, please kindly cite the paper:
|
117 |
+
|
118 |
+
```
|
119 |
+
@article{lin2023awq,
|
120 |
+
title={AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration},
|
121 |
+
author={Lin, Ji and Tang, Jiaming and Tang, Haotian and Yang, Shang and Dang, Xingyu and Han, Song},
|
122 |
+
journal={arXiv},
|
123 |
+
year={2023}
|
124 |
+
}
|
125 |
+
```
|