abhinavkulkarni commited on
Commit
a43cc08
1 Parent(s): 84fa1ba

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +135 -0
README.md ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: llama2
3
+ language:
4
+ - code
5
+ tags:
6
+ - llama2
7
+ - AWQ
8
+ inference: false
9
+ ---
10
+ # **Code Llama**
11
+ Code Llama is a collection of pretrained and fine-tuned generative text models ranging in scale from 7 billion to 34 billion parameters.
12
+
13
+ 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).
14
+
15
+ ## Model Date
16
+
17
+ August 31, 2023
18
+
19
+ ## Model License
20
+
21
+ Please refer to the original Code Llama model license ([link](https://huggingface.co/codellama/CodeLlama-7b-Python-hf)).
22
+
23
+ Please refer to the AWQ quantization license ([link](https://github.com/llm-awq/blob/main/LICENSE)).
24
+
25
+ Version
26
+
27
+ 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.
28
+
29
+ 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.
30
+
31
+ ## How to Use
32
+
33
+ ```bash
34
+ git clone https://github.com/mit-han-lab/llm-awq \
35
+ && cd llm-awq \
36
+ && git checkout ce4a6bb1c238c014a06672cb74f6865573494d66 \
37
+ && pip install -e . \
38
+ && cd awq/kernels \
39
+ && python setup.py install
40
+ ```
41
+
42
+ ```python
43
+ import time
44
+ import torch
45
+ from awq.quantize.quantizer import real_quantize_model_weight
46
+ from transformers import AutoModelForCausalLM, AutoConfig, AutoTokenizer, TextStreamer
47
+ from accelerate import init_empty_weights, load_checkpoint_and_dispatch
48
+ from huggingface_hub import snapshot_download
49
+
50
+ model_name = "abhinavkulkarni/codellama-CodeLlama-7b-Python-hf-w4-g128-awq"
51
+
52
+ # Config
53
+ config = AutoConfig.from_pretrained(model_name, trust_remote_code=True)
54
+
55
+ # Tokenizer
56
+ try:
57
+ tokenizer = AutoTokenizer.from_pretrained(config.tokenizer_name, trust_remote_code=True)
58
+ except:
59
+ tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False, trust_remote_code=True)
60
+ streamer = TextStreamer(tokenizer, skip_special_tokens=True)
61
+
62
+ # Model
63
+ w_bit = 4
64
+ q_config = {
65
+ "zero_point": True,
66
+ "q_group_size": 128,
67
+ }
68
+
69
+ load_quant = snapshot_download(model_name)
70
+
71
+ with init_empty_weights():
72
+ model = AutoModelForCausalLM.from_config(config=config,
73
+ torch_dtype=torch.float16, trust_remote_code=True)
74
+
75
+ real_quantize_model_weight(model, w_bit=w_bit, q_config=q_config, init_only=True)
76
+ model.tie_weights()
77
+
78
+ model = load_checkpoint_and_dispatch(model, load_quant, device_map="balanced")
79
+
80
+ # Inference
81
+ prompt = f"import socket\n\ndef ping_exponential_backoff(host: str):"
82
+
83
+ input_ids = tokenizer(prompt, return_tensors='pt').input_ids.cuda()
84
+ output = model.generate(
85
+ inputs=input_ids,
86
+ temperature=0.7,
87
+ max_new_tokens=512,
88
+ top_p=0.15,
89
+ top_k=0,
90
+ repetition_penalty=1.1,
91
+ eos_token_id=tokenizer.eos_token_id,
92
+ streamer=streamer)
93
+ ```
94
+
95
+ ## Evaluation
96
+
97
+ This evaluation was done using OpenAI [HumanEval](https://github.com/openai/human-eval)
98
+
99
+ [CodeLlama-7b-Python-hf](https://huggingface.co/codellama/CodeLlama-7b-Python-hf)
100
+
101
+ | Task |Version| Metric | Value | |Stderr|
102
+ |---------|------:|---------------|--------:|---|------|
103
+ |HumanEval| 1|pass@1 |36.5853% | | |
104
+
105
+ [CodeLlama-7b-Python-hf (4-bit 128-group AWQ)](https://huggingface.co/abhinavkulkarni/codellama-CodeLlama-7b-Python-hf-w4-g128-awq)
106
+
107
+ | Task |Version| Metric | Value | |Stderr|
108
+ |---------|------:|---------------|--------:|---|------|
109
+ |HumanEval| 1|pass@1 |34.1463% | | |
110
+
111
+ ## Acknowledgements
112
+
113
+ You can cite codellama paper as follows:
114
+
115
+ ```
116
+ @misc{rozière2023code,
117
+ title={Code Llama: Open Foundation Models for Code},
118
+ author={Baptiste Rozière and Jonas Gehring and Fabian Gloeckle and Sten Sootla and Itai Gat and Xiaoqing Ellen Tan and Yossi Adi and Jingyu Liu and Tal Remez and Jérémy Rapin and Artyom Kozhevnikov and Ivan Evtimov and Joanna Bitton and Manish Bhatt and Cristian Canton Ferrer and Aaron Grattafiori and Wenhan Xiong and Alexandre Défossez and Jade Copet and Faisal Azhar and Hugo Touvron and Louis Martin and Nicolas Usunier and Thomas Scialom and Gabriel Synnaeve},
119
+ year={2023},
120
+ eprint={2308.12950},
121
+ archivePrefix={arXiv},
122
+ primaryClass={cs.CL}
123
+ }
124
+ ```
125
+
126
+ The model was quantized with AWQ technique. If you find AWQ useful or relevant to your research, please kindly cite the paper:
127
+
128
+ ```
129
+ @article{lin2023awq,
130
+ title={AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration},
131
+ author={Lin, Ji and Tang, Jiaming and Tang, Haotian and Yang, Shang and Dang, Xingyu and Han, Song},
132
+ journal={arXiv},
133
+ year={2023}
134
+ }
135
+ ```