TheBloke commited on
Commit
1cf8147
1 Parent(s): 1e5ca15

Initial GPTQ model commit

Browse files
Files changed (1) hide show
  1. README.md +306 -0
README.md ADDED
@@ -0,0 +1,306 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ inference: false
3
+ license: other
4
+ model_creator: SLAM-group
5
+ model_link: https://huggingface.co/SLAM-group/NewHope
6
+ model_name: NewHope
7
+ model_type: llama
8
+ quantized_by: TheBloke
9
+ ---
10
+
11
+ <!-- header start -->
12
+ <div style="width: 100%;">
13
+ <img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
14
+ </div>
15
+ <div style="display: flex; justify-content: space-between; width: 100%;">
16
+ <div style="display: flex; flex-direction: column; align-items: flex-start;">
17
+ <p><a href="https://discord.gg/theblokeai">Chat & support: my new Discord server</a></p>
18
+ </div>
19
+ <div style="display: flex; flex-direction: column; align-items: flex-end;">
20
+ <p><a href="https://www.patreon.com/TheBlokeAI">Want to contribute? TheBloke's Patreon page</a></p>
21
+ </div>
22
+ </div>
23
+ <!-- header end -->
24
+
25
+ # NewHope - GPTQ
26
+ - Model creator: [SLAM-group](https://huggingface.co/SLAM-group)
27
+ - Original model: [NewHope](https://huggingface.co/SLAM-group/NewHope)
28
+
29
+ ## Description
30
+
31
+ This repo contains GPTQ model files for [SLAM-group's NewHope](https://huggingface.co/SLAM-group/NewHope).
32
+
33
+ Multiple GPTQ parameter permutations are provided; see Provided Files below for details of the options provided, their parameters, and the software used to create them.
34
+
35
+ ## Repositories available
36
+
37
+ * [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/NewHope-GPTQ)
38
+ * [2, 3, 4, 5, 6 and 8-bit GGML models for CPU+GPU inference](https://huggingface.co/TheBloke/NewHope-GGML)
39
+ * [SLAM-group's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/SLAM-group/NewHope)
40
+
41
+ ## Prompt template: Alpaca
42
+
43
+ ```
44
+ Below is an instruction that describes a task. Write a response that appropriately completes the request.
45
+
46
+ ### Instruction:
47
+ {prompt}
48
+
49
+ ### Response:
50
+ ```
51
+
52
+ ## Provided files
53
+
54
+ Multiple quantisation parameters are provided, to allow you to choose the best one for your hardware and requirements.
55
+
56
+ Each separate quant is in a different branch. See below for instructions on fetching from different branches.
57
+
58
+ | Branch | Bits | Group Size | Act Order (desc_act) | GPTQ Dataset | Size | ExLlama Compat? | Made With | Desc |
59
+ | ------ | ---- | ---------- | -------------------- | ------------ | ---- | --------------- | --------- | ---- |
60
+ | [main](https://huggingface.co/TheBloke/NewHope-GPTQ/tree/main) | 4 | 128 | No | [Evol Instruct Code](https://huggingface.co/datasets/nickrosh/Evol-Instruct-Code-80k-v1) | 7.26 GB | Yes | AutoGPTQ | Most compatible option. Good inference speed in AutoGPTQ and GPTQ-for-LLaMa. Lower inference quality than other options. |
61
+ | [gptq-4bit-32g-actorder_True](https://huggingface.co/TheBloke/NewHope-GPTQ/tree/gptq-4bit-32g-actorder_True) | 4 | 32 | Yes | [Evol Instruct Code](https://huggingface.co/datasets/nickrosh/Evol-Instruct-Code-80k-v1) | 8.00 GB | Yes | AutoGPTQ | 4-bit, with Act Order and group size 32g. Gives highest possible inference quality, with maximum VRAM usage. Poor AutoGPTQ CUDA speed. |
62
+ | [gptq-4bit-64g-actorder_True](https://huggingface.co/TheBloke/NewHope-GPTQ/tree/gptq-4bit-64g-actorder_True) | 4 | 64 | Yes | [Evol Instruct Code](https://huggingface.co/datasets/nickrosh/Evol-Instruct-Code-80k-v1) | 7.51 GB | Yes | AutoGPTQ | 4-bit, with Act Order and group size 64g. Uses less VRAM than 32g, but with slightly lower accuracy. Poor AutoGPTQ CUDA speed. |
63
+ | [gptq-4bit-128g-actorder_True](https://huggingface.co/TheBloke/NewHope-GPTQ/tree/gptq-4bit-128g-actorder_True) | 4 | 128 | Yes | [Evol Instruct Code](https://huggingface.co/datasets/nickrosh/Evol-Instruct-Code-80k-v1) | 7.26 GB | Yes | AutoGPTQ | 4-bit, with Act Order and group size 128g. Uses even less VRAM than 64g, but with slightly lower accuracy. Poor AutoGPTQ CUDA speed. |
64
+ | [gptq-8bit--1g-actorder_True](https://huggingface.co/TheBloke/NewHope-GPTQ/tree/gptq-8bit--1g-actorder_True) | 8 | None | Yes | [Evol Instruct Code](https://huggingface.co/datasets/nickrosh/Evol-Instruct-Code-80k-v1) | 13.36 GB | No | AutoGPTQ | 8-bit, with Act Order. No group size, to lower VRAM requirements and to improve AutoGPTQ speed. |
65
+ | [gptq-8bit-128g-actorder_True](https://huggingface.co/TheBloke/NewHope-GPTQ/tree/gptq-8bit-128g-actorder_True) | 8 | 128 | Yes | [Evol Instruct Code](https://huggingface.co/datasets/nickrosh/Evol-Instruct-Code-80k-v1) | 13.65 GB | No | AutoGPTQ | 8-bit, with group size 128g for higher inference quality and with Act Order for even higher accuracy. Poor AutoGPTQ CUDA speed. |
66
+
67
+ ## How to download from branches
68
+
69
+ - In text-generation-webui, you can add `:branch` to the end of the download name, eg `TheBloke/NewHope-GPTQ:gptq-4bit-32g-actorder_True`
70
+ - With Git, you can clone a branch with:
71
+ ```
72
+ git clone --branch --single-branch gptq-4bit-32g-actorder_True https://huggingface.co/TheBloke/NewHope-GPTQ
73
+ ```
74
+ - In Python Transformers code, the branch is the `revision` parameter; see below.
75
+
76
+ ## How to easily download and use this model in [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
77
+
78
+ Please make sure you're using the latest version of [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
79
+
80
+ It is strongly recommended to use the text-generation-webui one-click-installers unless you know how to make a manual install.
81
+
82
+ 1. Click the **Model tab**.
83
+ 2. Under **Download custom model or LoRA**, enter `TheBloke/NewHope-GPTQ`.
84
+ - To download from a specific branch, enter for example `TheBloke/NewHope-GPTQ:gptq-4bit-32g-actorder_True`
85
+ - see Provided Files above for the list of branches for each option.
86
+ 3. Click **Download**.
87
+ 4. The model will start downloading. Once it's finished it will say "Done"
88
+ 5. In the top left, click the refresh icon next to **Model**.
89
+ 6. In the **Model** dropdown, choose the model you just downloaded: `NewHope-GPTQ`
90
+ 7. The model will automatically load, and is now ready for use!
91
+ 8. If you want any custom settings, set them and then click **Save settings for this model** followed by **Reload the Model** in the top right.
92
+ * Note that you do not need to set GPTQ parameters any more. These are set automatically from the file `quantize_config.json`.
93
+ 9. Once you're ready, click the **Text Generation tab** and enter a prompt to get started!
94
+
95
+ ## How to use this GPTQ model from Python code
96
+
97
+ First make sure you have [AutoGPTQ](https://github.com/PanQiWei/AutoGPTQ) installed:
98
+
99
+ `GITHUB_ACTIONS=true pip install auto-gptq`
100
+
101
+ Then try the following example code:
102
+
103
+ ```python
104
+ from transformers import AutoTokenizer, pipeline, logging
105
+ from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
106
+
107
+ model_name_or_path = "TheBloke/NewHope-GPTQ"
108
+ model_basename = "gptq_model-4bit-128g"
109
+
110
+ use_triton = False
111
+
112
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
113
+
114
+ model = AutoGPTQForCausalLM.from_quantized(model_name_or_path,
115
+ model_basename=model_basename,
116
+ use_safetensors=True,
117
+ trust_remote_code=False,
118
+ device="cuda:0",
119
+ use_triton=use_triton,
120
+ quantize_config=None)
121
+
122
+ """
123
+ To download from a specific branch, use the revision parameter, as in this example:
124
+
125
+ model = AutoGPTQForCausalLM.from_quantized(model_name_or_path,
126
+ revision="gptq-4bit-32g-actorder_True",
127
+ model_basename=model_basename,
128
+ use_safetensors=True,
129
+ trust_remote_code=False,
130
+ device="cuda:0",
131
+ quantize_config=None)
132
+ """
133
+
134
+ prompt = "Tell me about AI"
135
+ prompt_template=f'''Below is an instruction that describes a task. Write a response that appropriately completes the request.
136
+
137
+ ### Instruction:
138
+ {prompt}
139
+
140
+ ### Response:
141
+ '''
142
+
143
+ print("\n\n*** Generate:")
144
+
145
+ input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids.cuda()
146
+ output = model.generate(inputs=input_ids, temperature=0.7, max_new_tokens=512)
147
+ print(tokenizer.decode(output[0]))
148
+
149
+ # Inference can also be done using transformers' pipeline
150
+
151
+ # Prevent printing spurious transformers error when using pipeline with AutoGPTQ
152
+ logging.set_verbosity(logging.CRITICAL)
153
+
154
+ print("*** Pipeline:")
155
+ pipe = pipeline(
156
+ "text-generation",
157
+ model=model,
158
+ tokenizer=tokenizer,
159
+ max_new_tokens=512,
160
+ temperature=0.7,
161
+ top_p=0.95,
162
+ repetition_penalty=1.15
163
+ )
164
+
165
+ print(pipe(prompt_template)[0]['generated_text'])
166
+ ```
167
+
168
+ ## Compatibility
169
+
170
+ The files provided will work with AutoGPTQ (CUDA and Triton modes), GPTQ-for-LLaMa (only CUDA has been tested), and Occ4m's GPTQ-for-LLaMa fork.
171
+
172
+ ExLlama works with Llama models in 4-bit. Please see the Provided Files table above for per-file compatibility.
173
+
174
+ <!-- footer start -->
175
+ ## Discord
176
+
177
+ For further support, and discussions on these models and AI in general, join us at:
178
+
179
+ [TheBloke AI's Discord server](https://discord.gg/theblokeai)
180
+
181
+ ## Thanks, and how to contribute.
182
+
183
+ Thanks to the [chirper.ai](https://chirper.ai) team!
184
+
185
+ I've had a lot of people ask if they can contribute. I enjoy providing models and helping people, and would love to be able to spend even more time doing it, as well as expanding into new projects like fine tuning/training.
186
+
187
+ If you're able and willing to contribute it will be most gratefully received and will help me to keep providing more models, and to start work on new AI projects.
188
+
189
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
190
+
191
+ * Patreon: https://patreon.com/TheBlokeAI
192
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
193
+
194
+ **Special thanks to**: Luke from CarbonQuill, Aemon Algiz.
195
+
196
+ **Patreon special mentions**: Willem Michiel, Ajan Kanaga, Cory Kujawski, Alps Aficionado, Nikolai Manek, Jonathan Leane, Stanislav Ovsiannikov, Michael Levine, Luke Pendergrass, Sid, K, Gabriel Tamborski, Clay Pascal, Kalila, William Sang, Will Dee, Pieter, Nathan LeClaire, ya boyyy, David Flickinger, vamX, Derek Yates, Fen Risland, Jeffrey Morgan, webtim, Daniel P. Andersen, Chadd, Edmond Seymore, Pyrater, Olusegun Samson, Lone Striker, biorpg, alfie_i, Mano Prime, Chris Smitley, Dave, zynix, Trenton Dambrowitz, Johann-Peter Hartmann, Magnesian, Spencer Kim, John Detwiler, Iucharbius, Gabriel Puliatti, LangChain4j, Luke @flexchar, Vadim, Rishabh Srivastava, Preetika Verma, Ai Maven, Femi Adebogun, WelcomeToTheClub, Leonard Tan, Imad Khwaja, Steven Wood, Stefan Sabev, Sebastain Graf, usrbinkat, Dan Guido, Sam, Eugene Pentland, Mandus, transmissions 11, Slarti, Karl Bernard, Spiking Neurons AB, Artur Olbinski, Joseph William Delisle, ReadyPlayerEmma, Olakabola, Asp the Wyvern, Space Cruiser, Matthew Berman, Randy H, subjectnull, danny, John Villwock, Illia Dulskyi, Rainer Wilmers, theTransient, Pierre Kircher, Alexandros Triantafyllidis, Viktor Bowallius, terasurfer, Deep Realms, SuperWojo, senxiiz, Oscar Rangel, Alex, Stephen Murray, Talal Aujan, Raven Klaugh, Sean Connelly, Raymond Fosdick, Fred von Graf, chris gileta, Junyu Yang, Elle
197
+
198
+
199
+ Thank you to all my generous patrons and donaters!
200
+
201
+ <!-- footer end -->
202
+
203
+ # Original model card: SLAM-group's NewHope
204
+
205
+ # NewHope: Harnessing 99% of GPT-4's Programming Capabilities
206
+
207
+ We introduce NewHope, a fine-tuned chat model based on llama-2-13b, aiming to provide a strong coding capability. NewHope handle different languages including Python, C++, Java, JavaScript, Go, and more. Preliminary evaluation on HumanEval shows that **NewHope possesses 99% of GPT-4's programming capabilities**.
208
+
209
+ **Contact**: SLAM (<ins>S</ins>UFE <ins>L</ins>arge <ins>A</ins>I <ins>M</ins>odel) is a research group at Shanghai University of Finance and Economics.
210
211
+
212
+ **TODO**: We will release more evaluatation results and training details later.
213
+
214
+ # Evaluation Results
215
+
216
+ We evaluated NewHope on [HumanEval](https://github.com/openai/human-eval) using the official evaluation script by OpenAI. We compared the Pass@1 metric of NewHope with other models. The results of other models are from PapersWithCode.
217
+
218
+ | Model | Pass@1 |
219
+ | ----- | ------ |
220
+ | **GPT-4** | **67.0** |
221
+ | **NewHope** | **66.5** |
222
+ | PanGu-Coder2 15B | 61.6 |
223
+ | WizardCoder 15B | 57.3 |
224
+ | phi-1 1.3B | 50.6 |
225
+ | GPT-3.5 | 48.1 |
226
+ | phi-1-small | 45.0 |
227
+ | PaLM-Coder | 36.0 |
228
+ | CodeGeeX2-6B | 35.9 |
229
+
230
+ # Model Weights
231
+
232
+ We have open-sourced the model weights [NewHope](https://huggingface.co/SLAM-group/NewHope).
233
+
234
+ We are uploading the model weights. The weights will be available in a few hours.
235
+
236
+
237
+ # Usage
238
+
239
+ To load the NewHope model using Transformers, use the following code:
240
+ ```
241
+ import torch
242
+ from transformers import LlamaTokenizer, LlamaForCausalLM
243
+
244
+ base_model = "SLAM-group/NewHope"
245
+ tokenizer = LlamaTokenizer.from_pretrained(base_model)
246
+ model = LlamaForCausalLM.from_pretrained(base_model, torch_dtype=torch.float16, device_map="auto")
247
+ # model.config.use_cache is default to `False`. For inference: `model.config.use_cache = True`
248
+ ```
249
+ **Note:** At least Huggingface Transformers **4.31.0** is required to load this model!
250
+
251
+ You can ask NewHope to generate code with instructions. We provide a simple example of how NewHope model generates code with the specific prompt:
252
+ ```
253
+ # Suppose required tokenizer and model have already been loaded
254
+
255
+ instruction = "Write a Python function to tell me what the date is today."
256
+ prompt = f"<s> ### Instruction:\n{instruction}\n\n### Response:\n"
257
+ inputs = tokenizer(prompt, add_special_tokens=False, return_tensors="pt").to("cuda")
258
+ output = model.generate(**inputs, do_sample=True, top_p=0.9, max_new_tokens=2048)[0]
259
+ decoded_output = tokenizer.decode(output, skip_special_tokens=True).split("### Response:\n")[-1].strip()
260
+ print(decoded_output)
261
+ ```
262
+
263
+ You can also interact with NewHope in a dialog manner with the following prompt:
264
+ ```
265
+ <s> ### Instruction:\nQ1\n\n### Response:\nA1</s><s> ### Instruction:\nQ2\n\n### Response:\nA2</s>
266
+ ```
267
+
268
+
269
+ # Evaluation
270
+
271
+ ### Local setup
272
+ 1. Install HumanEval for evaluation. [Details](https://github.com/openai/human-eval)
273
+ 2. Install dependencies
274
+
275
+ ```bash
276
+ pip install -r requirements.txt
277
+ ```
278
+
279
+ ---
280
+ For HumanEval, we use the following prompt:
281
+ ```
282
+ example_input = 'def is_odd(number: int) -> bool:\n """ Check whether the given number is odd\n >>> is_odd(3)\n True\n >>> is_odd(6)\n False\n """\n'
283
+ example_output = 'def is_odd(number: int) -> bool:\n """ Check whether the given number is odd\n >>> is_odd(3)\n True\n >>> is_odd(6)\n False\n """\n return number % 2 == 1'
284
+
285
+ task_in_humaneval = "REPLACE `task_in_humaneval` WITH THE SPECIFIC TASK IN HUMANEVAL DATA"
286
+
287
+ prompt = f"<s> ### Instruction:\nComplete the given function below:\n\n{example_input}\n\n### Response:\n{example_output}</s><s> ### Instruction:\nComplete the given function below:\n\n{task_in_human_eval}\n\n### Response:\n"
288
+ ```
289
+
290
+ To reproduce the results on HumanEval, use the following script:
291
+ ```
292
+ python complete.py --base_model SLAM-group/NewHope --output_dir output --n_gpu 8
293
+ ```
294
+ The above script will generate `samples.jsonl` in `output_dir`, which can be directly evaluated by HumanEval. [Evaluation procedure](https://github.com/openai/human-eval). We conducted the experiment with `fp16` on 8xA800, 80GB GPUs, reaching `66.5%` on Pass@1 (v.s. GPT4 `67.0%`).
295
+
296
+ # Citation
297
+
298
+ ```
299
+ @misc{2023newhope,
300
+ title={NewHope: Harnessing 99% of GPT-4's Programming Capabilities},
301
+ author={Wanyun Cui and Qianle Wang},
302
+ howpublished = https://github.com/SLAM-group/newhope,
303
+ year={2023}
304
+ }
305
+ ```
306
+