Yukang commited on
Commit
c40fcb9
1 Parent(s): 61b6540

Upload README-hf.md

Browse files
Files changed (1) hide show
  1. README-hf.md +364 -0
README-hf.md ADDED
@@ -0,0 +1,364 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LongLoRA and LongAlpaca - A Toolbox for Long-context LLMs
2
+
3
+
4
+ [![Gradio](https://img.shields.io/badge/Gradio-Online%20Demo-green)](https://1841bb028d32e8619c.gradio.live)
5
+ [![Huggingface Models](https://img.shields.io/badge/Models-Huggingface%20Models-bron)](https://huggingface.co/Yukang)
6
+ [![Paper](https://img.shields.io/badge/Paper-Arvix%20Link-blue)](https://arxiv.org/abs/2309.12307)
7
+ [![Github](https://img.shields.io/badge/Github-Repo-cyan)](https://github.com/dvlab-research/LongLoRA)
8
+
9
+
10
+ [![Code License](https://img.shields.io/badge/Code%20License-Apache_2.0-yellow.svg)](https://github.com/dvlab-research/LongLoRA/blob/main/LICENSE)
11
+ [![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)
12
+ [![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)
13
+
14
+ For detailed usage and codes, please visit the [Github project](https://github.com/dvlab-research/LongLoRA).
15
+ ## TABLE OF CONTENTS
16
+ 1. [News](#news)
17
+ 2. [Examples](#examples)
18
+ 3. [Highlights](#highlights)
19
+ 4. [How to contribute](#how-to-contribute)
20
+ 5. [Requirements](#usage-requirements)
21
+ 6. [Installation and quick guide](#installation-and-quick-guide)
22
+ 7. [LongAlpaca Data](#longalpaca-data)
23
+ 8. [Models](#models)
24
+ 9. [Training](#training)
25
+ 10. [Evaluation](#evaluation)
26
+ 11. [Demo](#demo)
27
+ 12. [Data Generation via Pdf2Text](#data-generation-via-pdf2text)
28
+ 13. [Citation](#citation)
29
+ 14. [Acknowledgement](#acknowledgement)
30
+ 15. [License](#license)
31
+
32
+ ## News
33
+ - [x] [2023.10.8] We release the long instruction-following dataset, [LongAlpaca-12k](https://drive.google.com/file/d/1JVC1p_Ht-1h61tKitOCW0blnCHf-552U/view?usp=share_link) 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).
34
+ - (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.)
35
+ - [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.
36
+ - [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!
37
+ - [x] [2023.9.22] We release [Paper](http://arxiv.org/abs/2309.12307) and this GitHub repo, including training and evaluation code.
38
+
39
+ **LongLoRA: Efficient Fine-tuning of Long-Context Large Language Models [[Paper](http://arxiv.org/abs/2309.12307)]** <br />
40
+ [Yukang Chen](https://scholar.google.com/citations?user=6p0ygKUAAAAJ&hl=en),
41
+ [Shengju Qian](https://scholar.google.com/citations?user=QNnWmasAAAAJ),
42
+ [Haotian Tang](https://scholar.google.com/citations?user=WxL13BAAAAAJ&hl),
43
+ [Xin Lai](https://scholar.google.com/citations?user=tqNDPA4AAAAJ&hl=zh-CN),
44
+ [Zhijian Liu](https://scholar.google.com/citations?user=3coYSTUAAAAJ&hl=en),
45
+ [Song Han](https://scholar.google.com/citations?user=E0iCaa4AAAAJ&hl=zh-CN),
46
+ [Jiaya Jia](https://scholar.google.com/citations?user=XPAkzTEAAAAJ&hl=en)<br />
47
+
48
+ ## Highlights
49
+ 1. In LongLoRA approach, The proposed shifted short attention is easy to implement, compatible with Flash-Attention, and is not required during inference.
50
+ 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).
51
+ 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.
52
+
53
+ ## How to Contribute
54
+ - Make sure to have git installed.
55
+ - Create your own [fork](https://github.com/dvlab-research/LongLoRA/fork) of the project.
56
+ - Clone the repository on your local machine, using git clone and pasting the url of this project.
57
+ - Read both the `Requirements` and `Installation and Quick Guide` sections below.
58
+ - Commit and push your changes.
59
+ - Make a pull request when finished modifying the project.
60
+
61
+
62
+ ## Usage Requirements
63
+ To download and use the [pre-trained weights](#pre-trained-weights) you will need:
64
+ 1. Hugging Face (HF) account with valid email. Note, the email used for HF must alse be used for the license agreement.
65
+ 2. Accept the Meta [license and acceptable use policy](https://ai.meta.com/resources/models-and-libraries/llama-downloads/)
66
+
67
+
68
+ ## Installation and Quick Guide
69
+ To install and run the application:
70
+ 1. [Fork this repo](https://github.com/dvlab-research/LongLoRA/fork) on github
71
+ 2. Clone the repository on your local machine, using git clone and pasting the url of this project.
72
+ 3. Run the following code:
73
+ ```
74
+ pip install -r requirements.txt
75
+ pip install flash-attn --no-build-isolation
76
+ ```
77
+ 4. Use either a [Released model](#released-models) or [Fine tune](#fine-tuning) a model to fit your preferences.
78
+ 5. Test your model by chat.
79
+ 6. Deploy your own demo.
80
+
81
+ ## LongAlpaca Data
82
+
83
+ 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.
84
+
85
+ | Data | Short QA | Long QA | Total | Download |
86
+ |:---------------|----------|----------|----------|----------|
87
+ | LongAlpaca-12k | 3k | 9k | 12k | [Link](https://drive.google.com/file/d/1JVC1p_Ht-1h61tKitOCW0blnCHf-552U/view?usp=share_link) |
88
+
89
+ Following the original Alpaca format, our Long QA data uses the following prompts for fine-tuning:
90
+ - `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.
91
+ - `output`: `str`, the answer to the instruction.
92
+
93
+ We did not use the `input` format in the Alpaca format for simplicity.
94
+
95
+ ## Models
96
+
97
+ ### Models with supervised fine-tuning
98
+ | Model | Size | Context | Train | Link |
99
+ |:---------------|------|---------|---------|--------------------------------------------------------------------------------------------------------------------------|
100
+ | LongAlpaca-7B | 7B | 32768 | Full FT | [Model](https://huggingface.co/Yukang/LongAlpaca-7B) |
101
+ | LongAlpaca-13B | 13B | 32768 | Full FT | [Model](https://huggingface.co/Yukang/LongAlpaca-13B) |
102
+ | LongAlpaca-70B | 70B | 32768 | LoRA+ | [Model](https://huggingface.co/Yukang/LongAlpaca-70B) [(LoRA-weight)](https://huggingface.co/Yukang/LongAlpaca-70B-lora) |
103
+
104
+
105
+ ### Models with context extension via fully fine-tuning
106
+ | Model | Size | Context | Train | Link |
107
+ |:----------------------------|------|---------|-------|-------------------------------------------------------------------|
108
+ | Llama-2-7b-longlora-8k-ft | 7B | 8192 | Full FT | [Model](https://huggingface.co/Yukang/Llama-2-7b-longlora-8k-ft) |
109
+ | Llama-2-7b-longlora-16k-ft | 7B | 16384 | Full FT | [Model](https://huggingface.co/Yukang/Llama-2-7b-longlora-16k-ft) |
110
+ | Llama-2-7b-longlora-32k-ft | 7B | 32768 | Full FT | [Model](https://huggingface.co/Yukang/Llama-2-7b-longlora-32k-ft) |
111
+ | Llama-2-7b-longlora-100k-ft | 7B | 100000 | Full FT | [Model](https://huggingface.co/Yukang/Llama-2-7b-longlora-100k-ft) |
112
+ | Llama-2-13b-longlora-8k-ft | 13B | 8192 | Full FT | [Model](https://huggingface.co/Yukang/Llama-2-13b-longlora-8k-ft) |
113
+ | Llama-2-13b-longlora-16k-ft | 13B | 16384 | Full FT | [Model](https://huggingface.co/Yukang/Llama-2-13b-longlora-16k-ft) |
114
+ | Llama-2-13b-longlora-32k-ft | 13B | 32768 | Full FT | [Model](https://huggingface.co/Yukang/Llama-2-13b-longlora-32k-ft) |
115
+
116
+ ### Models with context extension via improved LoRA fine-tuning
117
+ | Model | Size | Context | Train | Link |
118
+ |:----------------------------|------|---------|-------|---------------------------------------------------------------------|
119
+ | Llama-2-7b-longlora-8k | 7B | 8192 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-7b-longlora-8k) |
120
+ | Llama-2-7b-longlora-16k | 7B | 16384 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-7b-longlora-16k) |
121
+ | Llama-2-7b-longlora-32k | 7B | 32768 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-7b-longlora-32k) |
122
+ | Llama-2-13b-longlora-8k | 13B | 8192 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-13b-longlora-8k) |
123
+ | Llama-2-13b-longlora-16k | 13B | 16384 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-13b-longlora-16k) |
124
+ | Llama-2-13b-longlora-32k | 13B | 32768 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-13b-longlora-32k) |
125
+ | Llama-2-13b-longlora-64k | 13B | 65536 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-13b-longlora-64k) |
126
+ | Llama-2-70b-longlora-32k | 70B | 32768 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-70b-longlora-32k) |
127
+ | Llama-2-70b-chat-longlora-32k | 70B | 32768 | LoRA+ | [LoRA-weight](https://huggingface.co/Yukang/Llama-2-70b-chat-longlora-32k) |
128
+
129
+ ## Training
130
+ ### Pre-trained weights
131
+ We use LLaMA2 models as the pre-trained weights and fine-tune them to long context window sizes. Download based on your choices.
132
+
133
+ | Pre-trained weights |
134
+ |:-------------------------------------------------------------------------------------|
135
+ | [Llama-2-7b-hf](https://huggingface.co/meta-llama/Llama-2-7b-hf) |
136
+ |[Llama-2-13b-hf](https://huggingface.co/meta-llama/Llama-2-13b-hf) |
137
+ | [Llama-2-70b-hf](https://huggingface.co/meta-llama/Llama-2-70b-hf) |
138
+
139
+ 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.
140
+
141
+ ### Fine-tuning
142
+ ```
143
+ torchrun --nproc_per_node=8 fine-tune.py \
144
+ --model_name_or_path path_to/Llama-2-7b-hf \
145
+ --bf16 True \
146
+ --output_dir path_to_saving_checkpoints \
147
+ --cache_dir path_to_cache \
148
+ --model_max_length 8192 \
149
+ --use_flash_attn True \
150
+ --low_rank_training False \
151
+ --num_train_epochs 1 \
152
+ --per_device_train_batch_size 1 \
153
+ --per_device_eval_batch_size 2 \
154
+ --gradient_accumulation_steps 8 \
155
+ --evaluation_strategy "no" \
156
+ --save_strategy "steps" \
157
+ --save_steps 1000 \
158
+ --save_total_limit 2 \
159
+ --learning_rate 2e-5 \
160
+ --weight_decay 0.0 \
161
+ --warmup_steps 20 \
162
+ --lr_scheduler_type "constant_with_warmup" \
163
+ --logging_steps 1 \
164
+ --deepspeed "ds_configs/stage2.json" \
165
+ --tf32 True \
166
+ --max_steps 1000
167
+ ```
168
+
169
+ - Please remember to change `path_to/Llama-2-7b-hf`, `path_to_saving_checkpoints`, `path_to_cache` to your own directory.
170
+ - Note that you can change `model_max_length` to other values.
171
+ - You could change `ds_configs/stage2.json` to `ds_configs/stage3.json` if you want.
172
+ - Please set `use_flash_attn` as `False` if you use V100 machines or do not install flash attention.
173
+ - 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.
174
+ - When training is finished, to get the full model weight:
175
+ ```
176
+ cd path_to_saving_checkpoints && python zero_to_fp32.py . pytorch_model.bin
177
+ ```
178
+
179
+ ### Supervised Fine-tuning
180
+ ```
181
+ torchrun --nproc_per_node=8 supervised-fine-tune.py \
182
+ --model_name_or_path path_to_finetuned_models \
183
+ --bf16 True \
184
+ --output_dir path_to_saving_checkpoints \
185
+ --model_max_length 32768 \
186
+ --use_flash_attn True \
187
+ --data_path LongQA.json \
188
+ --low_rank_training True \
189
+ --num_train_epochs 3 \
190
+ --per_device_train_batch_size 1 \
191
+ --per_device_eval_batch_size 2 \
192
+ --gradient_accumulation_steps 1 \
193
+ --evaluation_strategy "no" \
194
+ --save_strategy "steps" \
195
+ --save_steps 1000 \
196
+ --save_total_limit 2 \
197
+ --learning_rate 2e-5 \
198
+ --weight_decay 0.0 \
199
+ --warmup_steps 20 \
200
+ --lr_scheduler_type "constant_with_warmup" \
201
+ --logging_steps 1 \
202
+ --deepspeed "ds_configs/stage2.json" \
203
+ --tf32 True
204
+ ```
205
+ - We typically make supervised fine-tuning upon the fine-tuned context extended models, `path_to_finetuned_models`, like `Llama-2-13b-longlora-32k` or `Llama-2-13b-longlora-32k-ft`.
206
+ - During our dataset collection, it is hard for us to collect many high-quality QA that are larger than 32768. Thus, if you use our `LongQA.json`, please also set `model_max_length` as 32768.
207
+
208
+
209
+ ### Get trainable weights in low-rank training
210
+ 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`
211
+ ```
212
+ python3 get_trainable_weights.py --checkpoint_path path_to_saving_checkpoints --trainable_params "embed,norm"
213
+ ```
214
+
215
+ ### Merge LoRA Weight
216
+ 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:
217
+ ```
218
+ python3 merge_lora_weights_and_save_hf_model.py \
219
+ --base_model path_to/Llama-2-7b-hf \
220
+ --peft_model path_to_saving_checkpoints \
221
+ --context_size 8192 \
222
+ --save_path path_to_saving_merged_model
223
+ ```
224
+ For example,
225
+ ```
226
+ python3 merge_lora_weights_and_save_hf_model.py \
227
+ --base_model /dataset/pretrained-models/Llama-2-7b-hf \
228
+ --peft_model /dataset/yukangchen/hf_models/lora-models/Llama-2-7b-longlora-8k \
229
+ --context_size 8192 \
230
+ --save_path /dataset/yukangchen/models/Llama-2-7b-longlora-8k-merged
231
+ ```
232
+
233
+
234
+ ## Evaluation
235
+ ### Perplexity Validation
236
+ 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,
237
+ ```
238
+ 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
239
+ ```
240
+
241
+ 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.
242
+ ```
243
+ python3 eval.py --seq_len 8192 --context_size 8192 --batch_size 1 --base_model path_to_saving_checkpoints --data_path pg19/test.bin
244
+ ```
245
+
246
+ - 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`.
247
+
248
+ - 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.
249
+
250
+ | Dataset | Split | Link |
251
+ |:-----------|------------|--------------------------------------------------------------------------------------------------------------|
252
+ | PG19 | validation | [pg19/validation.bin](https://drive.google.com/file/d/1rbJvb0qRIf2mQoN2ON7S93TbTzMnlrN6/view?usp=share_link) |
253
+ | PG19 | test | [pg19/test.bin](https://drive.google.com/file/d/1QANDMdctpacPAYgS04adDXqByGEq-Ret/view?usp=share_link) |
254
+ | Proof-pile | test | [proof-pile/test_sampled_data.bin](https://drive.google.com/file/d/1bUI5lPDvrqzY_XXJJ2sSuvZx0Y9AZClE/view?usp=share_link) |
255
+
256
+
257
+ ### Passkey Retrieval
258
+ We provide a manner to test the passkey retrieval accuracy. For example,
259
+ ```
260
+ python3 passkey_retrivial.py \
261
+ --context_size 32768 \
262
+ --base_model path_to/Llama-2-7b-longlora-32k \
263
+ --max_tokens 32768 \
264
+ --interval 1000
265
+ ```
266
+ - Note that the `context_size` is the context length during fine-tuning.
267
+ - `max_tokens` is maximum length for the document in passkey retrieval evaluation.
268
+ - `interval` is the interval during the document length increasing. It is a rough number because the document increases by sentences.
269
+
270
+ ## Demo
271
+ ### Local Inference
272
+ 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:
273
+ ```
274
+ python3 inference.py \
275
+ --base_model path_to_model \
276
+ --question $question \
277
+ --context_size $context_length \
278
+ --max_gen_len $max_gen_len \
279
+ --flash_attn True \
280
+ --material $material_content \
281
+ --material_type $material_type \
282
+ --material_title $material_title
283
+ ```
284
+ To ask a question related to a book:
285
+ ```
286
+ python3 inference.py \
287
+ --base_model /data/models/Llama-2-13b-chat-longlora-32k-sft \
288
+ --question "Why doesn't Professor Snape seem to like Harry?" \
289
+ --context_size 32768 \
290
+ --max_gen_len 512 \
291
+ --flash_attn True \
292
+ --material "materials/Harry Potter and the Philosophers Stone_section2.txt" \
293
+ --material_type "book" \
294
+ --material_title "Harry Potter and the Philosophers Stone"
295
+ ```
296
+ Note that you can ignore `material_type` or `material_title`.
297
+
298
+ To ask a question related to a paper:
299
+ ```
300
+ python3 inference.py \
301
+ --base_model /data/models/Llama-2-13b-chat-longlora-32k-sft \
302
+ --question "What are the main contributions and novelties of this work?" \
303
+ --context_size 32768 \
304
+ --max_gen_len 512 \
305
+ --flash_attn True \
306
+ --material "materials/paper1.txt" \
307
+ --material_type "paper"
308
+ ```
309
+
310
+ ### Online Demo
311
+ To deploy your own demo run
312
+ ```
313
+ python3 demo.py \
314
+ --base_model path_to_model \
315
+ --context_size $context_size \
316
+ --max_gen_len $max_gen_len \
317
+ --flash_attn True
318
+ ```
319
+ Example
320
+ ```
321
+ python3 demo.py \
322
+ --base_model /data/models/Llama-2-13b-chat-longlora-32k-sft \
323
+ --context_size 32768 \
324
+ --max_gen_len 512 \
325
+ --flash_attn True
326
+ ```
327
+ - Note that `flash_attn=True` will make the generation slow but save much GPU memory.
328
+
329
+ ## Data Generation via Pdf2text
330
+ 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.
331
+
332
+ ## Citation
333
+ If you find this project useful in your research, please consider citing:
334
+
335
+ ```
336
+ @article{longlora,
337
+ title={LongLoRA: Efficient Fine-tuning of Long-Context Large Language Models},
338
+ author={Yukang Chen and Shengju Qian and Haotian Tang and Xin Lai and Zhijian Liu and Song Han and Jiaya Jia},
339
+ journal={arXiv:2309.12307},
340
+ year={2023}
341
+ }
342
+ ```
343
+
344
+
345
+ ```
346
+ @misc{long-alpaca,
347
+ author = {Yukang Chen and Shaozuo Yu and Shengju Qian and Haotian Tang and Xin Lai and Zhijian Liu and Song Han and Jiaya Jia},
348
+ title = {Long Alpaca: Long-context Instruction-following models},
349
+ year = {2023},
350
+ publisher = {GitHub},
351
+ journal = {GitHub repository},
352
+ howpublished = {\url{https://github.com/dvlab-research/LongLoRA}},
353
+ }
354
+ ```
355
+ ## Acknowledgement
356
+ - This work is built upon the [LLaMA2](https://ai.meta.com/llama) as the pre-trained models.
357
+ - 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.
358
+ - 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.
359
+ - Some evaluation code is modified upon [Landmark Attention](https://github.com/epfml/landmark-attention).
360
+ - We use [LongChat](https://github.com/DachengLi1/LongChat) for the retrieval evaluation.
361
+
362
+ ## License
363
+ - LongLoRA is licensed under the Apache License 2.0. This means that it requires the preservation of copyright and license notices.
364
+ - Data and weights are under CC-BY-NC 4.0 License.