TheBloke commited on
Commit
64991ef
1 Parent(s): 75b6993

Initial GPTQ model commit

Browse files
Files changed (1) hide show
  1. README.md +284 -0
README.md ADDED
@@ -0,0 +1,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ inference: false
3
+ license: other
4
+ ---
5
+
6
+ <!-- header start -->
7
+ <div style="width: 100%;">
8
+ <img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
9
+ </div>
10
+ <div style="display: flex; justify-content: space-between; width: 100%;">
11
+ <div style="display: flex; flex-direction: column; align-items: flex-start;">
12
+ <p><a href="https://discord.gg/Jq4vkcDakD">Chat & support: my new Discord server</a></p>
13
+ </div>
14
+ <div style="display: flex; flex-direction: column; align-items: flex-end;">
15
+ <p><a href="https://www.patreon.com/TheBlokeAI">Want to contribute? TheBloke's Patreon page</a></p>
16
+ </div>
17
+ </div>
18
+ <!-- header end -->
19
+
20
+ # Bavest's Fin Llama 33B GPTQ
21
+
22
+ These files are GPTQ 4bit model files for [Bavest's Fin Llama 33B](https://huggingface.co/bavest/fin-llama-33b-merged).
23
+
24
+ It is the result of quantising to 4bit using [AutoGPTQ](https://github.com/PanQiWei/AutoGPTQ).
25
+
26
+ ## Repositories available
27
+
28
+ * [4-bit GPTQ models for GPU inference](https://huggingface.co/TheBloke/fin-llama-33B-GPTQ)
29
+ * [2, 3, 4, 5, 6 and 8-bit GGML models for CPU+GPU inference](https://huggingface.co/TheBloke/fin-llama-33B-GGML)
30
+ * [Unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/bavest/fin-llama-33b-merged)
31
+
32
+ ## How to easily download and use this model in text-generation-webui
33
+
34
+ Please make sure you're using the latest version of text-generation-webui
35
+
36
+ 1. Click the **Model tab**.
37
+ 2. Under **Download custom model or LoRA**, enter `TheBloke/fin-llama-33B-GPTQ`.
38
+ 3. Click **Download**.
39
+ 4. The model will start downloading. Once it's finished it will say "Done"
40
+ 5. In the top left, click the refresh icon next to **Model**.
41
+ 6. In the **Model** dropdown, choose the model you just downloaded: `fin-llama-33B-GPTQ`
42
+ 7. The model will automatically load, and is now ready for use!
43
+ 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.
44
+ * Note that you do not need to set GPTQ parameters any more. These are set automatically from the file `quantize_config.json`.
45
+ 9. Once you're ready, click the **Text Generation tab** and enter a prompt to get started!
46
+
47
+ ## How to use this GPTQ model from Python code
48
+
49
+ First make sure you have [AutoGPTQ](https://github.com/PanQiWei/AutoGPTQ) installed:
50
+
51
+ `pip install auto-gptq`
52
+
53
+ Then try the following example code:
54
+
55
+ ```python
56
+ from transformers import AutoTokenizer, pipeline, logging
57
+ from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
58
+ import argparse
59
+
60
+ model_name_or_path = "TheBloke/fin-llama-33B-GPTQ"
61
+ model_basename = "fin-llama-33b-GPTQ-4bit--1g.act.order"
62
+
63
+ use_triton = False
64
+
65
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
66
+
67
+ model = AutoGPTQForCausalLM.from_quantized(model_name_or_path,
68
+ model_basename=model_basename,
69
+ use_safetensors=True,
70
+ trust_remote_code=False,
71
+ device="cuda:0",
72
+ use_triton=use_triton,
73
+ quantize_config=None)
74
+
75
+ prompt = "Tell me about AI"
76
+ prompt_template=f'''### Human: {prompt}
77
+ ### Assistant:'''
78
+
79
+ print("\n\n*** Generate:")
80
+
81
+ input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids.cuda()
82
+ output = model.generate(inputs=input_ids, temperature=0.7, max_new_tokens=512)
83
+ print(tokenizer.decode(output[0]))
84
+
85
+ # Inference can also be done using transformers' pipeline
86
+
87
+ # Prevent printing spurious transformers error when using pipeline with AutoGPTQ
88
+ logging.set_verbosity(logging.CRITICAL)
89
+
90
+ print("*** Pipeline:")
91
+ pipe = pipeline(
92
+ "text-generation",
93
+ model=model,
94
+ tokenizer=tokenizer,
95
+ max_new_tokens=512,
96
+ temperature=0.7,
97
+ top_p=0.95,
98
+ repetition_penalty=1.15
99
+ )
100
+
101
+ print(pipe(prompt_template)[0]['generated_text'])
102
+ ```
103
+
104
+ ## Provided files
105
+
106
+ **fin-llama-33b-GPTQ-4bit--1g.act.order.safetensors**
107
+
108
+ This will work with AutoGPTQ and CUDA versions of GPTQ-for-LLaMa. There are reports of issues with Triton mode of recent GPTQ-for-LLaMa. If you have issues, please use AutoGPTQ instead.
109
+
110
+ It was created without group_size to lower VRAM requirements, and with --act-order (desc_act) to boost inference accuracy as much as possible.
111
+
112
+ * `fin-llama-33b-GPTQ-4bit--1g.act.order.safetensors`
113
+ * Works with AutoGPTQ in CUDA or Triton modes.
114
+ * Works with GPTQ-for-LLaMa in CUDA mode. May have issues with GPTQ-for-LLaMa Triton mode.
115
+ * Works with text-generation-webui, including one-click-installers.
116
+ * Parameters: Groupsize = -1. Act Order / desc_act = True.
117
+
118
+ <!-- footer start -->
119
+ ## Discord
120
+
121
+ For further support, and discussions on these models and AI in general, join us at:
122
+
123
+ [TheBloke AI's Discord server](https://discord.gg/Jq4vkcDakD)
124
+
125
+ ## Thanks, and how to contribute.
126
+
127
+ Thanks to the [chirper.ai](https://chirper.ai) team!
128
+
129
+ 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.
130
+
131
+ 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.
132
+
133
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
134
+
135
+ * Patreon: https://patreon.com/TheBlokeAI
136
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
137
+
138
+ **Special thanks to**: Luke from CarbonQuill, Aemon Algiz, Dmitriy Samsonov.
139
+
140
+ **Patreon special mentions**: Oscar Rangel, Eugene Pentland, Talal Aujan, Cory Kujawski, Luke, Asp the Wyvern, Ai Maven, Pyrater, Alps Aficionado, senxiiz, Willem Michiel, Junyu Yang, trip7s trip, Sebastain Graf, Joseph William Delisle, Lone Striker, Jonathan Leane, Johann-Peter Hartmann, David Flickinger, Spiking Neurons AB, Kevin Schuppel, Mano Prime, Dmitriy Samsonov, Sean Connelly, Nathan LeClaire, Alain Rossmann, Fen Risland, Derek Yates, Luke Pendergrass, Nikolai Manek, Khalefa Al-Ahmad, Artur Olbinski, John Detwiler, Ajan Kanaga, Imad Khwaja, Trenton Dambrowitz, Kalila, vamX, webtim, Illia Dulskyi.
141
+
142
+ Thank you to all my generous patrons and donaters!
143
+
144
+ <!-- footer end -->
145
+
146
+ # Original model card: Bavest's Fin Llama 33B
147
+
148
+
149
+
150
+ # FIN-LLAMA
151
+
152
+ > Efficient Finetuning of Quantized LLMs for Finance
153
+
154
+ [Adapter Weights](https://huggingface.co/bavest/fin-llama-33b-merged)
155
+ | [Dataset](https://huggingface.co/datasets/bavest/fin-llama-dataset)
156
+
157
+ ## Installation
158
+
159
+ To load models in 4bits with transformers and bitsandbytes, you have to install accelerate and transformers from source
160
+ and make sure you have the latest version of the bitsandbytes library (0.39.0).
161
+
162
+ ```bash
163
+ pip3 install -r requirements.txt
164
+ ```
165
+
166
+ ### Other dependencies
167
+
168
+ If you want to finetune the model on a new instance. You could run
169
+ the `setup.sh` to install the python and cuda package.
170
+
171
+ ```bash
172
+ bash scripts/setup.sh
173
+ ```
174
+
175
+ ## Finetuning
176
+
177
+ ```bash
178
+ bash script/finetune.sh
179
+ ```
180
+
181
+ ## Usage
182
+
183
+ Quantization parameters are controlled from the `BitsandbytesConfig`
184
+
185
+ - Loading in 4 bits is activated through `load_in_4bit`
186
+ - The datatype used for the linear layer computations with `bnb_4bit_compute_dtype`
187
+ - Nested quantization is activated through `bnb_4bit_use_double_quant`
188
+ - The datatype used for qunatization is specified with `bnb_4bit_quant_type`. Note that there are two supported
189
+ quantization datatypes `fp4` (four bit float) and `nf4` (normal four bit float). The latter is theoretically optimal
190
+ for normally distributed weights and we recommend using `nf4`.
191
+
192
+
193
+ ```python
194
+ import torch
195
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
196
+
197
+ pretrained_model_name_or_path = "bavest/fin-llama-33b-merge"
198
+ model = AutoModelForCausalLM.from_pretrained(
199
+ pretrained_model_name_or_path=pretrained_model_name_or_path,
200
+ load_in_4bit=True,
201
+ device_map='auto',
202
+ torch_dtype=torch.bfloat16,
203
+ quantization_config=BitsAndBytesConfig(
204
+ load_in_4bit=True,
205
+ bnb_4bit_compute_dtype=torch.bfloat16,
206
+ bnb_4bit_use_double_quant=True,
207
+ bnb_4bit_quant_type='nf4'
208
+ ),
209
+ )
210
+
211
+ tokenizer = AutoTokenizer.from_pretrained(pretrained_model_name_or_path)
212
+
213
+ question = "What is the market cap of apple?"
214
+ input = "" # context if needed
215
+
216
+ prompt = f"""
217
+ A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's question.
218
+ '### Instruction:\n{question}\n\n### Input:{input}\n""\n\n### Response:
219
+ """
220
+
221
+ input_ids = tokenizer.encode(prompt, return_tensors="pt").to('cuda:0')
222
+
223
+ with torch.no_grad():
224
+ generated_ids = model.generate(
225
+ input_ids,
226
+ do_sample=True,
227
+ top_p=0.9,
228
+ temperature=0.8,
229
+ max_length=128
230
+ )
231
+
232
+ generated_text = tokenizer.decode(
233
+ [el.item() for el in generated_ids[0]], skip_special_tokens=True
234
+ )
235
+ ```
236
+
237
+
238
+ ## Dataset for FIN-LLAMA
239
+
240
+ The dataset is released under bigscience-openrail-m.
241
+ You can find the dataset used to train FIN-LLAMA models on HF
242
+ at [bavest/fin-llama-dataset](https://huggingface.co/datasets/bavest/fin-llama-dataset).
243
+
244
+ ## Known Issues and Limitations
245
+
246
+ Here a list of known issues and bugs. If your issue is not reported here, please open a new issue and describe the
247
+ problem.
248
+ See [QLORA](https://github.com/artidoro/qlora) for any other limitations.
249
+
250
+ 1. 4-bit inference is slow. Currently, our 4-bit inference implementation is not yet integrated with the 4-bit matrix
251
+ multiplication
252
+ 2. Currently, using `bnb_4bit_compute_type='fp16'` can lead to instabilities.
253
+ 3. Make sure that `tokenizer.bos_token_id = 1` to avoid generation issues.
254
+
255
+ ## Acknowledgements
256
+
257
+ We also thank Meta for releasing the LLaMA models without which this work would not have been possible.
258
+
259
+ This repo builds on the [Stanford Alpaca](https://github.com/tatsu-lab/stanford_alpaca)
260
+ , [QLORA](https://github.com/artidoro/qlora), [Chinese-Guanaco](https://github.com/jianzhnie/Chinese-Guanaco/tree/main)
261
+ and [LMSYS FastChat](https://github.com/lm-sys/FastChat) repos.
262
+
263
+ ## License and Intended Use
264
+ We release the resources associated with QLoRA finetuning in this repository under GLP3 license. In addition, we release the FIN-LLAMA model family for base LLaMA model sizes of 7B, 13B, 33B, and 65B. These models are intended for purposes in line with the LLaMA license and require access to the LLaMA models.
265
+
266
+ ## Prompts
267
+ ### Act as an Accountant
268
+ > I want you to act as an accountant and come up with creative ways to manage finances. You'll need to consider budgeting, investment strategies and risk management when creating a financial plan for your client. In some cases, you may also need to provide advice on taxation laws and regulations in order to help them maximize their profits. My first suggestion request is “Create a financial plan for a small business that focuses on cost savings and long-term investments".
269
+
270
+ ## Paged Optimizer
271
+ You can access the paged optimizer with the argument --optim paged_adamw_32bit
272
+
273
+ ## Cite
274
+
275
+ ```tex
276
+ @misc{Fin-LLAMA,
277
+ author = {William Todt, Ramtin Babaei, Pedram Babaei},
278
+ title = {Fin-LLAMA: Efficient Finetuning of Quantized LLMs for Finance},
279
+ year = {2023},
280
+ publisher = {GitHub},
281
+ journal = {GitHub repository},
282
+ howpublished = {\url{https://github.com/Bavest/fin-llama}},
283
+ }
284
+ ```