TheBloke commited on
Commit
bc9c7f4
1 Parent(s): ca190a6

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +722 -0
README.md ADDED
@@ -0,0 +1,722 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Yukang/LongAlpaca-70B
3
+ inference: false
4
+ license: llama2
5
+ model_creator: YukangChen
6
+ model_name: LongAlpaca 70B
7
+ model_type: llama
8
+ prompt_template: 'Below is an instruction that describes a task. Write a response
9
+ that appropriately completes the request.
10
+
11
+
12
+ ### Instruction:
13
+
14
+ {prompt}
15
+
16
+
17
+ ### Response:
18
+
19
+ '
20
+ quantized_by: TheBloke
21
+ ---
22
+
23
+ <!-- header start -->
24
+ <!-- 200823 -->
25
+ <div style="width: auto; margin-left: auto; margin-right: auto">
26
+ <img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
27
+ </div>
28
+ <div style="display: flex; justify-content: space-between; width: 100%;">
29
+ <div style="display: flex; flex-direction: column; align-items: flex-start;">
30
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://discord.gg/theblokeai">Chat & support: TheBloke's Discord server</a></p>
31
+ </div>
32
+ <div style="display: flex; flex-direction: column; align-items: flex-end;">
33
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://www.patreon.com/TheBlokeAI">Want to contribute? TheBloke's Patreon page</a></p>
34
+ </div>
35
+ </div>
36
+ <div style="text-align:center; margin-top: 0em; margin-bottom: 0em"><p style="margin-top: 0.25em; margin-bottom: 0em;">TheBloke's LLM work is generously supported by a grant from <a href="https://a16z.com">andreessen horowitz (a16z)</a></p></div>
37
+ <hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
38
+ <!-- header end -->
39
+
40
+ # LongAlpaca 70B - GPTQ
41
+ - Model creator: [YukangChen](https://huggingface.co/Yukang)
42
+ - Original model: [LongAlpaca 70B](https://huggingface.co/Yukang/LongAlpaca-70B)
43
+
44
+ <!-- description start -->
45
+ ## Description
46
+
47
+ This repo contains GPTQ model files for [YukangChen's LongAlpaca 70B](https://huggingface.co/Yukang/LongAlpaca-70B).
48
+
49
+ 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.
50
+
51
+ <!-- description end -->
52
+ <!-- repositories-available start -->
53
+ ## Repositories available
54
+
55
+ * [AWQ model(s) for GPU inference.](https://huggingface.co/TheBloke/LongAlpaca-70B-AWQ)
56
+ * [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/LongAlpaca-70B-GPTQ)
57
+ * [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/LongAlpaca-70B-GGUF)
58
+ * [YukangChen's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/Yukang/LongAlpaca-70B)
59
+ <!-- repositories-available end -->
60
+
61
+ <!-- prompt-template start -->
62
+ ## Prompt template: Alpaca
63
+
64
+ ```
65
+ Below is an instruction that describes a task. Write a response that appropriately completes the request.
66
+
67
+ ### Instruction:
68
+ {prompt}
69
+
70
+ ### Response:
71
+
72
+ ```
73
+
74
+ <!-- prompt-template end -->
75
+
76
+
77
+ <!-- README_GPTQ.md-provided-files start -->
78
+ ## Provided files, and GPTQ parameters
79
+
80
+ Multiple quantisation parameters are provided, to allow you to choose the best one for your hardware and requirements.
81
+
82
+ Each separate quant is in a different branch. See below for instructions on fetching from different branches.
83
+
84
+ Most GPTQ files are made with AutoGPTQ. Mistral models are currently made with Transformers.
85
+
86
+ <details>
87
+ <summary>Explanation of GPTQ parameters</summary>
88
+
89
+ - Bits: The bit size of the quantised model.
90
+ - GS: GPTQ group size. Higher numbers use less VRAM, but have lower quantisation accuracy. "None" is the lowest possible value.
91
+ - Act Order: True or False. Also known as `desc_act`. True results in better quantisation accuracy. Some GPTQ clients have had issues with models that use Act Order plus Group Size, but this is generally resolved now.
92
+ - Damp %: A GPTQ parameter that affects how samples are processed for quantisation. 0.01 is default, but 0.1 results in slightly better accuracy.
93
+ - GPTQ dataset: The calibration dataset used during quantisation. Using a dataset more appropriate to the model's training can improve quantisation accuracy. Note that the GPTQ calibration dataset is not the same as the dataset used to train the model - please refer to the original model repo for details of the training dataset(s).
94
+ - Sequence Length: The length of the dataset sequences used for quantisation. Ideally this is the same as the model sequence length. For some very long sequence models (16+K), a lower sequence length may have to be used. Note that a lower sequence length does not limit the sequence length of the quantised model. It only impacts the quantisation accuracy on longer inference sequences.
95
+ - ExLlama Compatibility: Whether this file can be loaded with ExLlama, which currently only supports Llama models in 4-bit.
96
+
97
+ </details>
98
+
99
+ | Branch | Bits | GS | Act Order | Damp % | GPTQ Dataset | Seq Len | Size | ExLlama | Desc |
100
+ | ------ | ---- | -- | --------- | ------ | ------------ | ------- | ---- | ------- | ---- |
101
+ | [main](https://huggingface.co/TheBloke/LongAlpaca-70B-GPTQ/tree/main) | 4 | None | Yes | 0.1 | [c4](https://huggingface.co/datasets/allenai/c4) | 16384 | 35.33 GB | Yes | 4-bit, with Act Order. No group size, to lower VRAM requirements. |
102
+ | [gptq-4bit-128g-actorder_True](https://huggingface.co/TheBloke/LongAlpaca-70B-GPTQ/tree/gptq-4bit-128g-actorder_True) | 4 | 128 | Yes | 0.1 | [c4](https://huggingface.co/datasets/allenai/c4) | 16384 | 36.65 GB | Yes | 4-bit, with Act Order and group size 128g. Uses even less VRAM than 64g, but with slightly lower accuracy. |
103
+ | [gptq-4bit-32g-actorder_True](https://huggingface.co/TheBloke/LongAlpaca-70B-GPTQ/tree/gptq-4bit-32g-actorder_True) | 4 | 32 | Yes | 0.1 | [c4](https://huggingface.co/datasets/allenai/c4) | 16384 | 40.66 GB | Yes | 4-bit, with Act Order and group size 32g. Gives highest possible inference quality, with maximum VRAM usage. |
104
+ | [gptq-3bit-128g-actorder_True](https://huggingface.co/TheBloke/LongAlpaca-70B-GPTQ/tree/gptq-3bit-128g-actorder_True) | 3 | 128 | Yes | 0.1 | [c4](https://huggingface.co/datasets/allenai/c4) | 16384 | 28.03 GB | No | 3-bit, with group size 128g and act-order. Higher quality than 128g-False. |
105
+
106
+ <!-- README_GPTQ.md-provided-files end -->
107
+
108
+ <!-- README_GPTQ.md-download-from-branches start -->
109
+ ## How to download, including from branches
110
+
111
+ ### In text-generation-webui
112
+
113
+ To download from the `main` branch, enter `TheBloke/LongAlpaca-70B-GPTQ` in the "Download model" box.
114
+
115
+ To download from another branch, add `:branchname` to the end of the download name, eg `TheBloke/LongAlpaca-70B-GPTQ:gptq-4bit-128g-actorder_True`
116
+
117
+ ### From the command line
118
+
119
+ I recommend using the `huggingface-hub` Python library:
120
+
121
+ ```shell
122
+ pip3 install huggingface-hub
123
+ ```
124
+
125
+ To download the `main` branch to a folder called `LongAlpaca-70B-GPTQ`:
126
+
127
+ ```shell
128
+ mkdir LongAlpaca-70B-GPTQ
129
+ huggingface-cli download TheBloke/LongAlpaca-70B-GPTQ --local-dir LongAlpaca-70B-GPTQ --local-dir-use-symlinks False
130
+ ```
131
+
132
+ To download from a different branch, add the `--revision` parameter:
133
+
134
+ ```shell
135
+ mkdir LongAlpaca-70B-GPTQ
136
+ huggingface-cli download TheBloke/LongAlpaca-70B-GPTQ --revision gptq-4bit-128g-actorder_True --local-dir LongAlpaca-70B-GPTQ --local-dir-use-symlinks False
137
+ ```
138
+
139
+ <details>
140
+ <summary>More advanced huggingface-cli download usage</summary>
141
+
142
+ If you remove the `--local-dir-use-symlinks False` parameter, the files will instead be stored in the central Huggingface cache directory (default location on Linux is: `~/.cache/huggingface`), and symlinks will be added to the specified `--local-dir`, pointing to their real location in the cache. This allows for interrupted downloads to be resumed, and allows you to quickly clone the repo to multiple places on disk without triggering a download again. The downside, and the reason why I don't list that as the default option, is that the files are then hidden away in a cache folder and it's harder to know where your disk space is being used, and to clear it up if/when you want to remove a download model.
143
+
144
+ The cache location can be changed with the `HF_HOME` environment variable, and/or the `--cache-dir` parameter to `huggingface-cli`.
145
+
146
+ For more documentation on downloading with `huggingface-cli`, please see: [HF -> Hub Python Library -> Download files -> Download from the CLI](https://huggingface.co/docs/huggingface_hub/guides/download#download-from-the-cli).
147
+
148
+ To accelerate downloads on fast connections (1Gbit/s or higher), install `hf_transfer`:
149
+
150
+ ```shell
151
+ pip3 install hf_transfer
152
+ ```
153
+
154
+ And set environment variable `HF_HUB_ENABLE_HF_TRANSFER` to `1`:
155
+
156
+ ```shell
157
+ mkdir LongAlpaca-70B-GPTQ
158
+ HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download TheBloke/LongAlpaca-70B-GPTQ --local-dir LongAlpaca-70B-GPTQ --local-dir-use-symlinks False
159
+ ```
160
+
161
+ Windows Command Line users: You can set the environment variable by running `set HF_HUB_ENABLE_HF_TRANSFER=1` before the download command.
162
+ </details>
163
+
164
+ ### With `git` (**not** recommended)
165
+
166
+ To clone a specific branch with `git`, use a command like this:
167
+
168
+ ```shell
169
+ git clone --single-branch --branch gptq-4bit-128g-actorder_True https://huggingface.co/TheBloke/LongAlpaca-70B-GPTQ
170
+ ```
171
+
172
+ Note that using Git with HF repos is strongly discouraged. It will be much slower than using `huggingface-hub`, and will use twice as much disk space as it has to store the model files twice (it stores every byte both in the intended target folder, and again in the `.git` folder as a blob.)
173
+
174
+ <!-- README_GPTQ.md-download-from-branches end -->
175
+ <!-- README_GPTQ.md-text-generation-webui start -->
176
+ ## How to easily download and use this model in [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
177
+
178
+ Please make sure you're using the latest version of [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
179
+
180
+ It is strongly recommended to use the text-generation-webui one-click-installers unless you're sure you know how to make a manual install.
181
+
182
+ 1. Click the **Model tab**.
183
+ 2. Under **Download custom model or LoRA**, enter `TheBloke/LongAlpaca-70B-GPTQ`.
184
+ - To download from a specific branch, enter for example `TheBloke/LongAlpaca-70B-GPTQ:gptq-4bit-128g-actorder_True`
185
+ - see Provided Files above for the list of branches for each option.
186
+ 3. Click **Download**.
187
+ 4. The model will start downloading. Once it's finished it will say "Done".
188
+ 5. In the top left, click the refresh icon next to **Model**.
189
+ 6. In the **Model** dropdown, choose the model you just downloaded: `LongAlpaca-70B-GPTQ`
190
+ 7. The model will automatically load, and is now ready for use!
191
+ 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.
192
+ * Note that you do not need to and should not set manual GPTQ parameters any more. These are set automatically from the file `quantize_config.json`.
193
+ 9. Once you're ready, click the **Text Generation tab** and enter a prompt to get started!
194
+
195
+ <!-- README_GPTQ.md-text-generation-webui end -->
196
+
197
+ <!-- README_GPTQ.md-use-from-tgi start -->
198
+ ## Serving this model from Text Generation Inference (TGI)
199
+
200
+ It's recommended to use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
201
+
202
+ Example Docker parameters:
203
+
204
+ ```shell
205
+ --model-id TheBloke/LongAlpaca-70B-GPTQ --port 3000 --quantize awq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
206
+ ```
207
+
208
+ Example Python code for interfacing with TGI (requires huggingface-hub 0.17.0 or later):
209
+
210
+ ```shell
211
+ pip3 install huggingface-hub
212
+ ```
213
+
214
+ ```python
215
+ from huggingface_hub import InferenceClient
216
+
217
+ endpoint_url = "https://your-endpoint-url-here"
218
+
219
+ prompt = "Tell me about AI"
220
+ prompt_template=f'''Below is an instruction that describes a task. Write a response that appropriately completes the request.
221
+
222
+ ### Instruction:
223
+ {prompt}
224
+
225
+ ### Response:
226
+ '''
227
+
228
+ client = InferenceClient(endpoint_url)
229
+ response = client.text_generation(prompt,
230
+ max_new_tokens=128,
231
+ do_sample=True,
232
+ temperature=0.7,
233
+ top_p=0.95,
234
+ top_k=40,
235
+ repetition_penalty=1.1)
236
+
237
+ print(f"Model output: {response}")
238
+ ```
239
+ <!-- README_GPTQ.md-use-from-tgi end -->
240
+ <!-- README_GPTQ.md-use-from-python start -->
241
+ ## How to use this GPTQ model from Python code
242
+
243
+ ### Install the necessary packages
244
+
245
+ Requires: Transformers 4.33.0 or later, Optimum 1.12.0 or later, and AutoGPTQ 0.4.2 or later.
246
+
247
+ ```shell
248
+ pip3 install transformers optimum
249
+ pip3 install auto-gptq --extra-index-url https://huggingface.github.io/autogptq-index/whl/cu118/ # Use cu117 if on CUDA 11.7
250
+ ```
251
+
252
+ If you have problems installing AutoGPTQ using the pre-built wheels, install it from source instead:
253
+
254
+ ```shell
255
+ pip3 uninstall -y auto-gptq
256
+ git clone https://github.com/PanQiWei/AutoGPTQ
257
+ cd AutoGPTQ
258
+ git checkout v0.4.2
259
+ pip3 install .
260
+ ```
261
+
262
+ ### You can then use the following code
263
+
264
+ ```python
265
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
266
+
267
+ model_name_or_path = "TheBloke/LongAlpaca-70B-GPTQ"
268
+ # To use a different branch, change revision
269
+ # For example: revision="gptq-4bit-128g-actorder_True"
270
+ model = AutoModelForCausalLM.from_pretrained(model_name_or_path,
271
+ device_map="auto",
272
+ trust_remote_code=False,
273
+ revision="main")
274
+
275
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
276
+
277
+ prompt = "Tell me about AI"
278
+ prompt_template=f'''Below is an instruction that describes a task. Write a response that appropriately completes the request.
279
+
280
+ ### Instruction:
281
+ {prompt}
282
+
283
+ ### Response:
284
+ '''
285
+
286
+ print("\n\n*** Generate:")
287
+
288
+ input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids.cuda()
289
+ output = model.generate(inputs=input_ids, temperature=0.7, do_sample=True, top_p=0.95, top_k=40, max_new_tokens=512)
290
+ print(tokenizer.decode(output[0]))
291
+
292
+ # Inference can also be done using transformers' pipeline
293
+
294
+ print("*** Pipeline:")
295
+ pipe = pipeline(
296
+ "text-generation",
297
+ model=model,
298
+ tokenizer=tokenizer,
299
+ max_new_tokens=512,
300
+ do_sample=True,
301
+ temperature=0.7,
302
+ top_p=0.95,
303
+ top_k=40,
304
+ repetition_penalty=1.1
305
+ )
306
+
307
+ print(pipe(prompt_template)[0]['generated_text'])
308
+ ```
309
+ <!-- README_GPTQ.md-use-from-python end -->
310
+
311
+ <!-- README_GPTQ.md-compatibility start -->
312
+ ## Compatibility
313
+
314
+ The files provided are tested to work with AutoGPTQ, both via Transformers and using AutoGPTQ directly. They should also work with [Occ4m's GPTQ-for-LLaMa fork](https://github.com/0cc4m/KoboldAI).
315
+
316
+ [ExLlama](https://github.com/turboderp/exllama) is compatible with Llama and Mistral models in 4-bit. Please see the Provided Files table above for per-file compatibility.
317
+
318
+ [Huggingface Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference) is compatible with all GPTQ models.
319
+ <!-- README_GPTQ.md-compatibility end -->
320
+
321
+ <!-- footer start -->
322
+ <!-- 200823 -->
323
+ ## Discord
324
+
325
+ For further support, and discussions on these models and AI in general, join us at:
326
+
327
+ [TheBloke AI's Discord server](https://discord.gg/theblokeai)
328
+
329
+ ## Thanks, and how to contribute
330
+
331
+ Thanks to the [chirper.ai](https://chirper.ai) team!
332
+
333
+ Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
334
+
335
+ 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.
336
+
337
+ 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.
338
+
339
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
340
+
341
+ * Patreon: https://patreon.com/TheBlokeAI
342
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
343
+
344
+ **Special thanks to**: Aemon Algiz.
345
+
346
+ **Patreon special mentions**: Pierre Kircher, Stanislav Ovsiannikov, Michael Levine, Eugene Pentland, Andrey, 준교 김, Randy H, Fred von Graf, Artur Olbinski, Caitlyn Gatomon, terasurfer, Jeff Scroggin, James Bentley, Vadim, Gabriel Puliatti, Harry Royden McLaughlin, Sean Connelly, Dan Guido, Edmond Seymore, Alicia Loh, subjectnull, AzureBlack, Manuel Alberto Morcote, Thomas Belote, Lone Striker, Chris Smitley, Vitor Caleffi, Johann-Peter Hartmann, Clay Pascal, biorpg, Brandon Frisco, sidney chen, transmissions 11, Pedro Madruga, jinyuan sun, Ajan Kanaga, Emad Mostaque, Trenton Dambrowitz, Jonathan Leane, Iucharbius, usrbinkat, vamX, George Stoitzev, Luke Pendergrass, theTransient, Olakabola, Swaroop Kallakuri, Cap'n Zoog, Brandon Phillips, Michael Dempsey, Nikolai Manek, danny, Matthew Berman, Gabriel Tamborski, alfie_i, Raymond Fosdick, Tom X Nguyen, Raven Klaugh, LangChain4j, Magnesian, Illia Dulskyi, David Ziegler, Mano Prime, Luis Javier Navarrete Lozano, Erik Bjäreholt, 阿明, Nathan Dryer, Alex, Rainer Wilmers, zynix, TL, Joseph William Delisle, John Villwock, Nathan LeClaire, Willem Michiel, Joguhyik, GodLy, OG, Alps Aficionado, Jeffrey Morgan, ReadyPlayerEmma, Tiffany J. Kim, Sebastain Graf, Spencer Kim, Michael Davis, webtim, Talal Aujan, knownsqashed, John Detwiler, Imad Khwaja, Deo Leter, Jerry Meng, Elijah Stavena, Rooh Singh, Pieter, SuperWojo, Alexandros Triantafyllidis, Stephen Murray, Ai Maven, ya boyyy, Enrico Ros, Ken Nordquist, Deep Realms, Nicholas, Spiking Neurons AB, Elle, Will Dee, Jack West, RoA, Luke @flexchar, Viktor Bowallius, Derek Yates, Subspace Studios, jjj, Toran Billups, Asp the Wyvern, Fen Risland, Ilya, NimbleBox.ai, Chadd, Nitin Borwankar, Emre, Mandus, Leonard Tan, Kalila, K, Trailburnt, S_X, Cory Kujawski
347
+
348
+
349
+ Thank you to all my generous patrons and donaters!
350
+
351
+ And thank you again to a16z for their generous grant.
352
+
353
+ <!-- footer end -->
354
+
355
+ # Original model card: YukangChen's LongAlpaca 70B
356
+
357
+ # LongLoRA and LongAlpaca for Long-context LLMs
358
+
359
+
360
+ [![Huggingface Models](https://img.shields.io/badge/Models-Huggingface%20Models-bron)](https://huggingface.co/Yukang)
361
+ [![Github](https://img.shields.io/badge/Github-Repo-cyan)](https://github.com/dvlab-research/LongLoRA)
362
+ [![Data](https://img.shields.io/badge/Data-LongAlpaca%2012k-light)](https://huggingface.co/datasets/Yukang/LongAlpaca-12k)
363
+ [![Paper](https://img.shields.io/badge/Paper-Arvix-blue)](https://arxiv.org/abs/2309.12307)
364
+
365
+ [![Code License](https://img.shields.io/badge/Code%20License-Apache_2.0-yellow.svg)](https://github.com/dvlab-research/LongLoRA/blob/main/LICENSE)
366
+ [![Data License](https://img.shields.io/badge/Data%20License-CC%20By%20NC%204.0-orange.svg)](https://github.com/dvlab-research/LongLoRA/blob/main/DATA_LICENSE)
367
+ [![Weight License](https://img.shields.io/badge/Weight%20License-CC%20By%20NC%204.0-red)](https://github.com/dvlab-research/LongLoRA/blob/main/WEIGHT_LICENSE)
368
+
369
+ For detailed usage and codes, please visit the [Github project](https://github.com/dvlab-research/LongLoRA).
370
+ ## TABLE OF CONTENTS
371
+ 1. [News](#news)
372
+ 2. [Examples](#examples)
373
+ 3. [Highlights](#highlights)
374
+ 4. [How to contribute](#how-to-contribute)
375
+ 5. [Requirements](#usage-requirements)
376
+ 6. [Installation and quick guide](#installation-and-quick-guide)
377
+ 7. [LongAlpaca Data](#longalpaca-data)
378
+ 8. [Models](#models)
379
+ 9. [Training](#training)
380
+ 10. [Evaluation](#evaluation)
381
+ 11. [Demo](#demo)
382
+ 12. [Data Generation via Pdf2Text](#data-generation-via-pdf2text)
383
+ 13. [Citation](#citation)
384
+ 14. [Acknowledgement](#acknowledgement)
385
+ 15. [License](#license)
386
+
387
+ ## News
388
+ - [x] [2023.10.8] **We release the long instruction-following dataset**, [LongAlpaca-12k](https://huggingface.co/datasets/Yukang/LongAlpaca-12k) and **the corresponding models**, [LongAlpaca-7B](https://huggingface.co/Yukang/LongAlpaca-7B), [LongAlpaca-13B](https://huggingface.co/Yukang/LongAlpaca-13B), and [LongAlpaca-70B](https://huggingface.co/Yukang/LongAlpaca-70B).
389
+ - (*The previous sft models*, [Llama-2-13b-chat-longlora-32k-sft](https://huggingface.co/Yukang/Llama-2-13b-chat-longlora-32k-sft) and [Llama-2-70b-chat-longlora-32k-sft](https://huggingface.co/Yukang/Llama-2-70b-chat-longlora-32k-sft), *have been depreciated*.)
390
+ - [x] [2023.10.3] We add support GPTNeoX models. Please refer to this [PR](https://github.com/dvlab-research/LongLoRA/pull/32) for usage. Thanks for @naubull2 for this contribution.
391
+ - [x] [2023.9.22] We release all our fine-tuned [models](https://huggingface.co/Yukang), including **70B-32k models**, [LLaMA2-LongLoRA-70B-32k](https://huggingface.co/Yukang/Llama-2-70b-longlora-32k), [LLaMA2-LongLoRA-7B-100k](https://huggingface.co/Yukang/Llama-2-7b-longlora-100k-ft). Welcome to check them out!
392
+ - [x] [2023.9.22] We release [Paper](http://arxiv.org/abs/2309.12307) and this GitHub repo, including training and evaluation code.
393
+
394
+ **LongLoRA: Efficient Fine-tuning of Long-Context Large Language Models [[Paper](http://arxiv.org/abs/2309.12307)]** <br />
395
+ [Yukang Chen](https://scholar.google.com/citations?user=6p0ygKUAAAAJ&hl=en),
396
+ [Shengju Qian](https://scholar.google.com/citations?user=QNnWmasAAAAJ),
397
+ [Haotian Tang](https://scholar.google.com/citations?user=WxL13BAAAAAJ&hl),
398
+ [Xin Lai](https://scholar.google.com/citations?user=tqNDPA4AAAAJ&hl=zh-CN),
399
+ [Zhijian Liu](https://scholar.google.com/citations?user=3coYSTUAAAAJ&hl=en),
400
+ [Song Han](https://scholar.google.com/citations?user=E0iCaa4AAAAJ&hl=zh-CN),
401
+ [Jiaya Jia](https://scholar.google.com/citations?user=XPAkzTEAAAAJ&hl=en)<br />
402
+
403
+ ## Highlights
404
+ 1. In LongLoRA approach, The proposed shifted short attention is easy to implement, compatible with Flash-Attention, and is not required during inference.
405
+ 2. We released all our models, including models from 7B to 70B, context length from 8k to 100k, including [LLaMA2-LongLoRA-7B-100k](https://huggingface.co/Yukang/Llama-2-7b-longlora-100k-ft), [LLaMA2-LongLoRA-13B-64k](https://huggingface.co/Yukang/Llama-2-13b-longlora-64k), and [LLaMA2-LongLoRA-70B-32k](https://huggingface.co/Yukang/Llama-2-70b-longlora-32k).
406
+ 3. We built up a long-context instruction-following dataset, [LongAlpaca-12k](#longalpaca-data). We released the corresponding [LongAlpaca-7B](https://huggingface.co/Yukang/LongAlpaca-7B), [LongAlpaca-13B](https://huggingface.co/Yukang/LongAlpaca-13B) and [LongAlpaca-70B](https://huggingface.co/Yukang/LongAlpaca-70B) models. To our best knowledge, this is the first open-sourced long-context 70B model.
407
+
408
+ ## How to Contribute
409
+ - Make sure to have git installed.
410
+ - Create your own [fork](https://github.com/dvlab-research/LongLoRA/fork) of the project.
411
+ - Clone the repository on your local machine, using git clone and pasting the url of this project.
412
+ - Read both the `Requirements` and `Installation and Quick Guide` sections below.
413
+ - Commit and push your changes.
414
+ - Make a pull request when finished modifying the project.
415
+
416
+
417
+ ## Usage Requirements
418
+ To download and use the [pre-trained weights](#pre-trained-weights) you will need:
419
+ 1. Hugging Face (HF) account with valid email. Note, the email used for HF must alse be used for the license agreement.
420
+ 2. Accept the Meta [license and acceptable use policy](https://ai.meta.com/resources/models-and-libraries/llama-downloads/)
421
+
422
+
423
+ ## Installation and Quick Guide
424
+ To install and run the application:
425
+ 1. [Fork this repo](https://github.com/dvlab-research/LongLoRA/fork) on github
426
+ 2. Clone the repository on your local machine, using git clone and pasting the url of this project.
427
+ 3. Run the following code:
428
+ ```
429
+ pip install -r requirements.txt
430
+ pip install flash-attn --no-build-isolation
431
+ ```
432
+ 4. Use either a [Released model](#released-models) or [Fine tune](#fine-tuning) a model to fit your preferences.
433
+ 5. Test your model by chat.
434
+ 6. Deploy your own demo.
435
+
436
+ ## LongAlpaca Data
437
+
438
+ LongAlpaca-12k contains 9k long QA data that we collected and 3k short QA sampled from the original [Alpaca data](https://github.com/tatsu-lab/stanford_alpaca/blob/main/alpaca_data.json). This is to avoid the case that the model might degrade at short instruction following. The data we collect contains various types and amounts as the following figure.
439
+
440
+ | Data | Short QA | Long QA | Total | Download |
441
+ |:---------------|----------|----------|----------|----------|
442
+ | LongAlpaca-12k | 3k | 9k | 12k | [Link](https://huggingface.co/datasets/Yukang/LongAlpaca-12k) |
443
+
444
+ Following the original Alpaca format, our Long QA data uses the following prompts for fine-tuning:
445
+ - `instruction`: `str`, describes the task the model should perform. For example, to answer a question after reading a book section or paper. We vary the contents and questions to make instructions diverse.
446
+ - `output`: `str`, the answer to the instruction.
447
+
448
+ We did not use the `input` format in the Alpaca format for simplicity.
449
+
450
+ ## Models
451
+
452
+ ### Models with supervised fine-tuning
453
+ | Model | Size | Context | Train | Link |
454
+ |:---------------|------|---------|---------|-----------------------------------------------------------------------------------------------------------------------|
455
+ | LongAlpaca-7B | 7B | 32768 | Full FT | [Model](https://huggingface.co/Yukang/LongAlpaca-7B) |
456
+ | LongAlpaca-13B | 13B | 32768 | Full FT | [Model](https://huggingface.co/Yukang/LongAlpaca-13B) |
457
+ | LongAlpaca-70B | 70B | 32768 | LoRA+ | [Model](https://huggingface.co/Yukang/LongAlpaca-70B) [(LoRA-weight)](https://huggingface.co/Yukang/LongAlpaca-70B-lora) |
458
+
459
+
460
+ ### Models with context extension via fully fine-tuning
461
+ | Model | Size | Context | Train | Link |
462
+ |:----------------------------|------|---------|-------|-------------------------------------------------------------------|
463
+ | Llama-2-7b-longlora-8k-ft | 7B | 8192 | Full FT | [Model](https://huggingface.co/Yukang/Llama-2-7b-longlora-8k-ft) |
464
+ | Llama-2-7b-longlora-16k-ft | 7B | 16384 | Full FT | [Model](https://huggingface.co/Yukang/Llama-2-7b-longlora-16k-ft) |
465
+ | Llama-2-7b-longlora-32k-ft | 7B | 32768 | Full FT | [Model](https://huggingface.co/Yukang/Llama-2-7b-longlora-32k-ft) |
466
+ | Llama-2-7b-longlora-100k-ft | 7B | 100000 | Full FT | [Model](https://huggingface.co/Yukang/Llama-2-7b-longlora-100k-ft) |
467
+ | Llama-2-13b-longlora-8k-ft | 13B | 8192 | Full FT | [Model](https://huggingface.co/Yukang/Llama-2-13b-longlora-8k-ft) |
468
+ | Llama-2-13b-longlora-16k-ft | 13B | 16384 | Full FT | [Model](https://huggingface.co/Yukang/Llama-2-13b-longlora-16k-ft) |
469
+ | Llama-2-13b-longlora-32k-ft | 13B | 32768 | Full FT | [Model](https://huggingface.co/Yukang/Llama-2-13b-longlora-32k-ft) |
470
+
471
+ ### Models with context extension via improved LoRA fine-tuning
472
+ | Model | Size | Context | Train | Link |
473
+ |:----------------------------|------|---------|-------|---------------------------------------------------------------------|
474
+ | Llama-2-7b-longlora-8k | 7B | 8192 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-7b-longlora-8k) |
475
+ | Llama-2-7b-longlora-16k | 7B | 16384 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-7b-longlora-16k) |
476
+ | Llama-2-7b-longlora-32k | 7B | 32768 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-7b-longlora-32k) |
477
+ | Llama-2-13b-longlora-8k | 13B | 8192 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-13b-longlora-8k) |
478
+ | Llama-2-13b-longlora-16k | 13B | 16384 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-13b-longlora-16k) |
479
+ | Llama-2-13b-longlora-32k | 13B | 32768 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-13b-longlora-32k) |
480
+ | Llama-2-13b-longlora-64k | 13B | 65536 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-13b-longlora-64k) |
481
+ | Llama-2-70b-longlora-32k | 70B | 32768 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-70b-longlora-32k) |
482
+ | Llama-2-70b-chat-longlora-32k | 70B | 32768 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-70b-chat-longlora-32k) |
483
+
484
+ ## Training
485
+ ### Pre-trained weights
486
+ We use LLaMA2 models as the pre-trained weights and fine-tune them to long context window sizes. Download based on your choices.
487
+
488
+ | Pre-trained weights |
489
+ |:-------------------------------------------------------------------------------------|
490
+ | [Llama-2-7b-hf](https://huggingface.co/meta-llama/Llama-2-7b-hf) |
491
+ |[Llama-2-13b-hf](https://huggingface.co/meta-llama/Llama-2-13b-hf) |
492
+ | [Llama-2-70b-hf](https://huggingface.co/meta-llama/Llama-2-70b-hf) |
493
+ | [Llama-2-7b-chat-hf](https://huggingface.co/meta-llama/Llama-2-7b-chat-hf) |
494
+ | [Llama-2-13b-chat-hf](https://huggingface.co/meta-llama/Llama-2-13b-chat-hf) |
495
+ | [Llama-2-70b-chat-hf](https://huggingface.co/meta-llama/Llama-2-70b-chat-hf) |
496
+
497
+ This project also supports GPTNeoX models as the base model architecture. Some candidate pre-trained weights may include [GPT-NeoX-20B](https://huggingface.co/EleutherAI/gpt-neox-20b), [Polyglot-ko-12.8B](https://huggingface.co/EleutherAI/polyglot-ko-12.8b) and other variants.
498
+
499
+ ### Fine-tuning
500
+ ```
501
+ torchrun --nproc_per_node=8 fine-tune.py \
502
+ --model_name_or_path path_to/Llama-2-7b-hf \
503
+ --bf16 True \
504
+ --output_dir path_to_saving_checkpoints \
505
+ --cache_dir path_to_cache \
506
+ --model_max_length 8192 \
507
+ --use_flash_attn True \
508
+ --low_rank_training False \
509
+ --num_train_epochs 1 \
510
+ --per_device_train_batch_size 1 \
511
+ --per_device_eval_batch_size 2 \
512
+ --gradient_accumulation_steps 8 \
513
+ --evaluation_strategy "no" \
514
+ --save_strategy "steps" \
515
+ --save_steps 1000 \
516
+ --save_total_limit 2 \
517
+ --learning_rate 2e-5 \
518
+ --weight_decay 0.0 \
519
+ --warmup_steps 20 \
520
+ --lr_scheduler_type "constant_with_warmup" \
521
+ --logging_steps 1 \
522
+ --deepspeed "ds_configs/stage2.json" \
523
+ --tf32 True \
524
+ --max_steps 1000
525
+ ```
526
+
527
+ - Please remember to change `path_to/Llama-2-7b-hf`, `path_to_saving_checkpoints`, `path_to_cache` to your own directory.
528
+ - Note that you can change `model_max_length` to other values.
529
+ - You could change `ds_configs/stage2.json` to `ds_configs/stage3.json` if you want.
530
+ - Please set `use_flash_attn` as `False` if you use V100 machines or do not install flash attention.
531
+ - You can set `low_rank_training` as `False` if you want to use fully fine-tuning. It will cost more GPU memory and slower, but the performance will be a bit better.
532
+ - When training is finished, to get the full model weight:
533
+ ```
534
+ cd path_to_saving_checkpoints && python zero_to_fp32.py . pytorch_model.bin
535
+ ```
536
+
537
+ ### Supervised Fine-tuning
538
+ ```
539
+ torchrun --nproc_per_node=8 supervised-fine-tune.py \
540
+ --model_name_or_path path_to_Llama2_chat_models \
541
+ --bf16 True \
542
+ --output_dir path_to_saving_checkpoints \
543
+ --model_max_length 32768 \
544
+ --use_flash_attn True \
545
+ --data_path LongAlpaca-12k.json \
546
+ --low_rank_training True \
547
+ --num_train_epochs 3 \
548
+ --per_device_train_batch_size 1 \
549
+ --per_device_eval_batch_size 2 \
550
+ --gradient_accumulation_steps 1 \
551
+ --evaluation_strategy "no" \
552
+ --save_strategy "steps" \
553
+ --save_steps 1000 \
554
+ --save_total_limit 2 \
555
+ --learning_rate 2e-5 \
556
+ --weight_decay 0.0 \
557
+ --warmup_steps 20 \
558
+ --lr_scheduler_type "constant_with_warmup" \
559
+ --logging_steps 1 \
560
+ --deepspeed "ds_configs/stage2.json" \
561
+ --tf32 True
562
+ ```
563
+ - There is no need to make supervised fine-tuning upon the fine-tuned context extended models. It is all right to directly use base model as Llama2-chat models, as the amount of long instruction following data is enough for SFT.
564
+ - Our long instruction following data can be found in [LongAlpaca-12k.json](https://huggingface.co/datasets/Yukang/LongAlpaca-12k).
565
+
566
+
567
+ ### Get trainable weights in low-rank training
568
+ In low-rank training, we set embedding and normalization layers as trainable. Please use the following line to extract the trainable weights `trainable_params.bin` from `pytorch_model.bin`
569
+ ```
570
+ python3 get_trainable_weights.py --checkpoint_path path_to_saving_checkpoints --trainable_params "embed,norm"
571
+ ```
572
+
573
+ ### Merge LoRA Weight
574
+ Merge the LoRA weights of `pytorch_model.bin` and trainable parameters `trainable_params.bin`, save the resulting model into your desired path in the Hugging Face format:
575
+ ```
576
+ python3 merge_lora_weights_and_save_hf_model.py \
577
+ --base_model path_to/Llama-2-7b-hf \
578
+ --peft_model path_to_saving_checkpoints \
579
+ --context_size 8192 \
580
+ --save_path path_to_saving_merged_model
581
+ ```
582
+ For example,
583
+ ```
584
+ python3 merge_lora_weights_and_save_hf_model.py \
585
+ --base_model /dataset/pretrained-models/Llama-2-7b-hf \
586
+ --peft_model /dataset/yukangchen/hf_models/lora-models/Llama-2-7b-longlora-8k \
587
+ --context_size 8192 \
588
+ --save_path /dataset/yukangchen/models/Llama-2-7b-longlora-8k-merged
589
+ ```
590
+
591
+
592
+ ## Evaluation
593
+ ### Perplexity Validation
594
+ To evaluate a model that is trained in the low-rank setting, please set both `base_model` and `peft_model`. `base_model` is the pre-trained weight. `peft_model` is the path to the saved checkpoint, which should contain `trainable_params.bin`, `adapter_model.bin` and `adapter_config.json`. For example,
595
+ ```
596
+ python3 eval.py --seq_len 8192 --context_size 8192 --batch_size 1 --base_model path_to/Llama-2-7b-hf --peft_model path_to_saving_checkpoints --data_path pg19/test.bin
597
+ ```
598
+
599
+ To evaluate a model that is fully fine-tuned, you only need to set `base_model` as the path to the saved checkpoint, which should contain `pytorch_model.bin` and `config.json`. `peft_model` should be ignored.
600
+ ```
601
+ python3 eval.py --seq_len 8192 --context_size 8192 --batch_size 1 --base_model path_to_saving_checkpoints --data_path pg19/test.bin
602
+ ```
603
+
604
+ - Note that `--seq_len` is to set the sequence length for evaluation. `--context_size` is to set the context length of the model during fine-tuning. `--seq_len` should not be larger than `--context_size`.
605
+
606
+ - We have already tokenized the validation and test splits of PG19 and proof-pile dataset into `pg19/validation.bin`, `pg19/test.bin`, and `proof-pile/test_sampled_data.bin`, with the tokenizer of LLaMA. `proof-pile/test_sampled_data.bin` contains 128 documents that are randomly sampled from the total proof-pile test split. For each document, it has at least 32768 tokens. We also release the sampled ids in [proof-pile/test_sampled_ids.bin](https://drive.google.com/file/d/1cnzWODLRQYAd7HeugzLCIhaqzaLZv7J5/view?usp=share_link). You can download them from the links below.
607
+
608
+ | Dataset | Split | Link |
609
+ |:-----------|------------|--------------------------------------------------------------------------------------------------------------|
610
+ | PG19 | validation | [pg19/validation.bin](https://drive.google.com/file/d/1rbJvb0qRIf2mQoN2ON7S93TbTzMnlrN6/view?usp=share_link) |
611
+ | PG19 | test | [pg19/test.bin](https://drive.google.com/file/d/1QANDMdctpacPAYgS04adDXqByGEq-Ret/view?usp=share_link) |
612
+ | Proof-pile | test | [proof-pile/test_sampled_data.bin](https://drive.google.com/file/d/1bUI5lPDvrqzY_XXJJ2sSuvZx0Y9AZClE/view?usp=share_link) |
613
+
614
+
615
+ ### Passkey Retrieval
616
+ We provide a manner to test the passkey retrieval accuracy. For example,
617
+ ```
618
+ python3 passkey_retrivial.py \
619
+ --context_size 32768 \
620
+ --base_model path_to/Llama-2-7b-longlora-32k \
621
+ --max_tokens 32768 \
622
+ --interval 1000
623
+ ```
624
+ - Note that the `context_size` is the context length during fine-tuning.
625
+ - `max_tokens` is maximum length for the document in passkey retrieval evaluation.
626
+ - `interval` is the interval during the document length increasing. It is a rough number because the document increases by sentences.
627
+
628
+ ## Demo
629
+ ### Local Inference
630
+ To chat with [Llama-2-13b-chat-longlora-32k-sft](https://huggingface.co/Yukang/Llama-2-13b-chat-longlora-32k-sft) or [Llama-2-70b-chat-longlora-32k-sft](https://huggingface.co/Yukang/Llama-2-70b-chat-longlora-32k-sft), you need to run `merge_lora_weights_and_save_hf_model.py` first, and then:
631
+ ```
632
+ python3 inference.py \
633
+ --base_model path_to_model \
634
+ --question $question \
635
+ --context_size $context_length \
636
+ --max_gen_len $max_gen_len \
637
+ --flash_attn True \
638
+ --material $material_content \
639
+ --material_type $material_type \
640
+ --material_title $material_title
641
+ ```
642
+ To ask a question related to a book:
643
+ ```
644
+ python3 inference.py \
645
+ --base_model /data/models/Llama-2-13b-chat-longlora-32k-sft \
646
+ --question "Why doesn't Professor Snape seem to like Harry?" \
647
+ --context_size 32768 \
648
+ --max_gen_len 512 \
649
+ --flash_attn True \
650
+ --material "materials/Harry Potter and the Philosophers Stone_section2.txt" \
651
+ --material_type "book" \
652
+ --material_title "Harry Potter and the Philosophers Stone"
653
+ ```
654
+ Note that you can ignore `material_type` or `material_title`.
655
+
656
+ To ask a question related to a paper:
657
+ ```
658
+ python3 inference.py \
659
+ --base_model /data/models/Llama-2-13b-chat-longlora-32k-sft \
660
+ --question "What are the main contributions and novelties of this work?" \
661
+ --context_size 32768 \
662
+ --max_gen_len 512 \
663
+ --flash_attn True \
664
+ --material "materials/paper1.txt" \
665
+ --material_type "paper"
666
+ ```
667
+
668
+ ### Online Demo
669
+ To deploy your own demo run
670
+ ```
671
+ python3 demo.py \
672
+ --base_model path_to_model \
673
+ --context_size $context_size \
674
+ --max_gen_len $max_gen_len \
675
+ --flash_attn True
676
+ ```
677
+ Example
678
+ ```
679
+ python3 demo.py \
680
+ --base_model /data/models/Llama-2-13b-chat-longlora-32k-sft \
681
+ --context_size 32768 \
682
+ --max_gen_len 512 \
683
+ --flash_attn True
684
+ ```
685
+ - Note that `flash_attn=True` will make the generation slow but save much GPU memory.
686
+
687
+ ## Data Generation via Pdf2text
688
+ During our dataset collection, we convert paper and books from pdf to text. The conversion quality has a large influence on the final model quality. We think that this step is non-trivial. We release the tool for the pdf2txt conversion, in the folder `pdf2txt`. It is built upon `pdf2image`, `easyocr`, `ditod` and `detectron2`. Please refer to the [README.md](pdf2txt/README.md) in `pdf2txt` for more details.
689
+
690
+ ## Citation
691
+ If you find this project useful in your research, please consider citing:
692
+
693
+ ```
694
+ @article{longlora,
695
+ title={LongLoRA: Efficient Fine-tuning of Long-Context Large Language Models},
696
+ author={Yukang Chen and Shengju Qian and Haotian Tang and Xin Lai and Zhijian Liu and Song Han and Jiaya Jia},
697
+ journal={arXiv:2309.12307},
698
+ year={2023}
699
+ }
700
+ ```
701
+
702
+
703
+ ```
704
+ @misc{long-alpaca,
705
+ author = {Yukang Chen and Shaozuo Yu and Shengju Qian and Haotian Tang and Xin Lai and Zhijian Liu and Song Han and Jiaya Jia},
706
+ title = {Long Alpaca: Long-context Instruction-following models},
707
+ year = {2023},
708
+ publisher = {GitHub},
709
+ journal = {GitHub repository},
710
+ howpublished = {\url{https://github.com/dvlab-research/LongLoRA}},
711
+ }
712
+ ```
713
+ ## Acknowledgement
714
+ - This work is built upon the [LLaMA2](https://ai.meta.com/llama) as the pre-trained models.
715
+ - This work can also be built upon the [GPTNeoX-HF](https://huggingface.co/docs/transformers/model_doc/gpt_neox) which is based upon [EleutherAI/GPTNeoX](https://github.com/EleutherAI/gpt-neox) as the pre-trained model architecture.
716
+ - This work is based on [DeepSpeed](https://github.com/microsoft/DeepSpeed), [peft](https://github.com/huggingface/peft), and [Flash-Attention2](https://github.com/Dao-AILab/flash-attention) for acceleration.
717
+ - Some evaluation code is modified upon [Landmark Attention](https://github.com/epfml/landmark-attention).
718
+ - We use [LongChat](https://github.com/DachengLi1/LongChat) for the retrieval evaluation.
719
+
720
+ ## License
721
+ - LongLoRA is licensed under the Apache License 2.0. This means that it requires the preservation of copyright and license notices.
722
+ - Data and weights are under CC-BY-NC 4.0 License. They are licensed for research use only, and allowed only non-commercial. Models trained using the dataset should not be used outside of research purposes.