abhinavkulkarni commited on
Commit
aad5bcc
1 Parent(s): 9ba682d

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +124 -0
README.md ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # **Llama 2** (4-bit 128g AWQ Quantized)
14
+ 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 7B pretrained model, converted for the Hugging Face Transformers format.
15
+
16
+ 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).
17
+
18
+ ## Model Date
19
+
20
+ July 19, 2023
21
+
22
+ ## Model License
23
+
24
+ Please refer to the original LLaMA 2 model license ([link](https://huggingface.co/meta-llama/Llama-2-7b-hf)).
25
+
26
+ Please refer to the AWQ quantization license ([link](https://github.com/llm-awq/blob/main/LICENSE)).
27
+
28
+ ## CUDA Version
29
+
30
+ 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.
31
+
32
+ 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.
33
+
34
+ ## How to Use
35
+
36
+ ```bash
37
+ git clone https://github.com/abhinavkulkarni/llm-awq \
38
+ && cd llm-awq \
39
+ && git checkout e977c5a570c5048b67a45b1eb823b81de02d0d60 \
40
+ && pip install -e . \
41
+ && cd awq/kernels \
42
+ && python setup.py install
43
+ ```
44
+
45
+ ```python
46
+ import torch
47
+ from awq.quantize.quantizer import real_quantize_model_weight
48
+ from transformers import AutoModelForCausalLM, AutoConfig, AutoTokenizer
49
+ from accelerate import init_empty_weights, load_checkpoint_and_dispatch
50
+ from huggingface_hub import snapshot_download
51
+
52
+ model_name = "abhinavkulkarni/meta-llama-Llama-2-7b-chat-hf-w4-g128-awq"
53
+
54
+ # Config
55
+ config = AutoConfig.from_pretrained(model_name, trust_remote_code=True)
56
+
57
+ # Tokenizer
58
+ tokenizer = AutoTokenizer.from_pretrained(config.tokenizer_name)
59
+
60
+ # Model
61
+ w_bit = 4
62
+ q_config = {
63
+ "zero_point": True,
64
+ "q_group_size": 128,
65
+ }
66
+
67
+ load_quant = snapshot_download(model_name)
68
+
69
+ with init_empty_weights():
70
+ model = AutoModelForCausalLM.from_config(config=config,
71
+ torch_dtype=torch.float16, trust_remote_code=True)
72
+
73
+ real_quantize_model_weight(model, w_bit=w_bit, q_config=q_config, init_only=True)
74
+
75
+ model = load_checkpoint_and_dispatch(model, load_quant, device_map="balanced")
76
+
77
+ # Inference
78
+ prompt = f'''What is the difference between nuclear fusion and fission?
79
+ ###Response:'''
80
+
81
+ input_ids = tokenizer(prompt, return_tensors='pt').input_ids.cuda()
82
+ output = model.generate(
83
+ inputs=input_ids,
84
+ temperature=0.7,
85
+ max_new_tokens=512,
86
+ top_p=0.15,
87
+ top_k=0,
88
+ repetition_penalty=1.1,
89
+ eos_token_id=tokenizer.eos_token_id
90
+ )
91
+ ```
92
+
93
+ ## Evaluation
94
+
95
+ This evaluation was done using [LM-Eval](https://github.com/EleutherAI/lm-evaluation-harness).
96
+
97
+ [Llama-2-7b-chat](https://huggingface.co/meta-llama/Llama-2-7b-chat-hf)
98
+
99
+ | Task |Version| Metric | Value | |Stderr|
100
+ |--------|------:|---------------|------:|---|------|
101
+ |wikitext| 1|word_perplexity|12.1967| | |
102
+ | | |byte_perplexity| 1.5964| | |
103
+ | | |bits_per_byte | 0.6748| | |
104
+
105
+ [Llama-2-7b-chat (4-bit 128-group AWQ)](https://huggingface.co/abhinavkulkarni/meta-llama-Llama-2-7b-chat-hf-w4-g128-awq)
106
+
107
+ | Task |Version| Metric | Value | |Stderr|
108
+ |--------|------:|---------------|------:|---|------|
109
+ |wikitext| 1|word_perplexity|12.5962| | |
110
+ | | |byte_perplexity| 1.6060| | |
111
+ | | |bits_per_byte | 0.6835| | |
112
+
113
+ ## Acknowledgements
114
+
115
+ The model was quantized with AWQ technique. If you find AWQ useful or relevant to your research, please kindly cite the paper:
116
+
117
+ ```
118
+ @article{lin2023awq,
119
+ title={AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration},
120
+ author={Lin, Ji and Tang, Jiaming and Tang, Haotian and Yang, Shang and Dang, Xingyu and Han, Song},
121
+ journal={arXiv},
122
+ year={2023}
123
+ }
124
+ ```