Safetensors
llama
princeton-nlp commited on
Commit
1003c5f
1 Parent(s): a8b0ca1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +271 -3
README.md CHANGED
@@ -1,3 +1,271 @@
1
- ---
2
- license: llama3
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: llama3
3
+ ---
4
+
5
+ # princeton_nlp/Llama-3-8B-ProLong-512k-Instruct
6
+
7
+ Contributors: Tianyu Gao*, Alexander Wettig* (*equal contribution), Howard Yen, Danqi Chen
8
+
9
+ Contact: `{tianyug, awettig}@princeton.edu`
10
+
11
+ 💡 ProLong stands for **Pr**incet**o**n **Long**-Context!
12
+
13
+ ## The ProLong Models
14
+
15
+ - [princeton_nlp/Llama-3-8B-ProLong-64k-Base](https://huggingface.co/princeton-nlp/Llama-3-8B-ProLong-64k-Base)
16
+ - [princeton_nlp/Llama-3-8B-ProLong-64k-Instruct](https://huggingface.co/princeton-nlp/Llama-3-8B-ProLong-64k-Instruct)
17
+ - [princeton_nlp/Llama-3-8B-ProLong-512k-Base](https://huggingface.co/princeton-nlp/Llama-3-8B-ProLong-512k-Base)
18
+ - [princeton_nlp/Llama-3-8B-ProLong-512k-Instruct](https://huggingface.co/princeton-nlp/Llama-3-8B-ProLong-512k-Instruct) ← you are here!
19
+
20
+ ## Features
21
+
22
+
23
+ - Based on [meta-llama/Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct) (original max length: 8K), we produce a long-context instruction-tuned model that can stably handle up to 64K tokens. We also have a version that can process up to 512K tokens.
24
+ - This model is trained on
25
+ - 20B carefully curated data mixture of short and long data (max length 64K). You can find our base model [here](https://huggingface.co/princeton-nlp/Llama-3-8B-ProLong-64k-Base).
26
+ - For the 512K version, we continue training the base model for 20B more tokens, with a mixture of short, long (64K), and ultra long (512K) data. You can find the corresponding base model [here](https://huggingface.co/princeton-nlp/Llama-3-8B-ProLong-512k-Base).
27
+ - Then we fine-tuned them on [UltraChat](https://huggingface.co/datasets/stingning/ultrachat) to regain chat ability.
28
+ - On a range of long-context tasks, our ProLong models achieve the better/comparable performance among models of similar sizes, including Llama 3.1 (128K context window), which was trained on 20x more long-context data (800B vs. 40B).
29
+ - ProLong is also the first open-source model to effectively support a 512K context window.
30
+ - We conduct extensive ablations in our preliminary experiments, looking for the most effective way to extend LMs’ context length. We will include more details in our technique report (coming soon).
31
+
32
+
33
+ ## Benchmarking results
34
+
35
+
36
+
37
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/607f846419a5af0183d7bfb9/PPSuEMsUWIyrmrOV_88Xf.png)
38
+
39
+
40
+ You can find results for more tasks and models in this [spreadsheet](https://docs.google.com/spreadsheets/d/1qGzimBE8F896p1m7_yWHnjyGX7kpEAeyaT1h2iTbNzE/edit?usp=sharing). In this detailed results, we show that our model can retain the original Llama-3's general LM performance (on tasks selected by the [HF Open LLM Leaderboard v1](https://huggingface.co/spaces/open-llm-leaderboard-old/open_llm_leaderboard)). This is non-trivial in long-context fine-tuning and requires a careful selection of the fine-tuning data mixture and the training configurations.
41
+
42
+
43
+ Understanding long-context performance is tricky, as there is no consensus on what’s effective long-context evaluation or how well those existing benchmarks reflect real-world use case. In this work, we curate a combination of existing and new tasks across both synthetic and natural datasets to demonstrate the strength of our model.
44
+
45
+ We divide the tasks into the following categories:
46
+
47
+ - **Recall**: we use synthetic Json key-value retrieval task (lost-in-the-middle, [Liu et al., 2023](https://arxiv.org/pdf/2307.03172); ∞BENCH, [Zhang et al., 2024](https://arxiv.org/pdf/2402.13718)) to test the model’s ability to retrieve arbitrary information from the context. This is a more comprehensive and reliable version of [needle-in-a-haystack](https://github.com/gkamradt/LLMTest_NeedleInAHaystack).
48
+ - **Retrieval-augmented generation (RAG)**: we use existing open-domain question answering datasets in a multi-document QA format ([Liu et al., 2023](https://arxiv.org/pdf/2307.03172)). Datasets we select include NaturalQuestion ([Kwiatkowski et al., 2019](https://aclanthology.org/Q19-1026.pdf)), HotpotQA (Y[ang et al., 2018](https://arxiv.org/pdf/1809.09600)), and PopQA ([Mallen et al., 2023](https://arxiv.org/pdf/2212.10511)). The gold document is put to different positions to test “lost-in-the-middle”.
49
+ - **In-context learning (ICL)**: ICL tasks have been established to evaluate long-context abilities ([Li et al., 2024](https://arxiv.org/pdf/2404.02060); [Bertsch et al., 2024](https://arxiv.org/pdf/2405.00200)). We follow [Bertsch et al., 2024](https://arxiv.org/pdf/2405.00200) and use the following five tasks: TREC, TREC-fine ([Hovy et al., 2001](https://aclanthology.org/H01-1069.pdf)), NLU ([Liu et al., 2019](https://arxiv.org/pdf/1903.05566)), Banking-77 ([Casanueva et al., 2020](https://aclanthology.org/2020.nlp4convai-1.5.pdf)), Clinc-150 ([Larson et al., 2019](https://aclanthology.org/2020.nlp4convai-1.5.pdf)).
50
+ - **Reranking**: Given a query and a number of retrieved passages (by an off-the-shelf model), reranking requires the model to generate the IDs of the top-10 passages. This has been shown to be a realistic application ([Sun et al., 2023](https://arxiv.org/pdf/2304.09542)) and is also challenging, as it requires reasoning/comparison across documents. We use MSMARCO ([Bajaj et al., 2018](https://arxiv.org/pdf/1611.09268)) for this task.
51
+ - **Long-document QA/summarization**: These are the most straightforward applications. We selected some of the public tasks that have the longest documents, including NarrativeQA ([Kočiský et al., 2017](https://arxiv.org/pdf/1712.07040)), Qasper ([Dasigi et al., 2021](https://arxiv.org/pdf/2105.03011)), QMSum ([Zhong et al., 2021](https://arxiv.org/pdf/2104.05938)), and Multi-LexSum ([Shen et al., 2022](https://arxiv.org/pdf/2206.10883)). As traditional evaluation metrics like rouge or F1 do not reflect the performance well, we use GPT-4o to score the model output given the gold output and the question.
52
+
53
+ <details><summary>Find details about our GPT-4o rubrics for the long-document QA/summarization tasks.</summary>
54
+
55
+ We use the following prompt to evaluate NarrativeQA and Qasper:
56
+
57
+ ```
58
+ Please act as an impartial judge and evaluate the quality of the provided answer which attempts to answer the provided question based on a provided context.
59
+ Although you are not given the context, you will be given a set of correct answers that achieves full scores on all metrics, and you need to assess the provided answers using the correct answers.
60
+
61
+ Below is your grading rubric:
62
+
63
+ Fluency:
64
+ - Score 0 (incoherent, repetitive, or incomplete): Incoherent sentences, repetitive sentences (even if not by exact words), incomplete answers, or gibberish. Note that even if the answer is coherent, if it is repetitive or incomplete, it should be given a score of 0.
65
+ - Score 1 (coherent, non-repetitive answer): Coherent, non-repetitive, fluent, grammatically correct answers.
66
+
67
+ Correctness:
68
+ - Score 0 (Incorrect): The answer does not agree with the provided correct answers at all.
69
+ - Score 1 (partly correct): Partly agree with one of the provided correct answers (for example, the question asks for a date and a person; the answer gets the date right but the person wrong).
70
+ - Score 2 (correct but not fully relevant): Fully agrees with one of the provided correct answers but mentions other completely irrelevant information. Note that extra details provided in the answer, even if not mentioned in the correct answers, should NOT be seen as irrelevant as long as they are relevant to the question to a reasonable extend.
71
+ - Score 3 (correct and relevant): Fully agrees with one of the provided correct answers and only provides information relevant to the question. Note that if the answer is longer than the correct answer, as long as everything in the answer is relevant to the question, it should still be given score 3. For example, if the correct answer is "the North Pole" and the answer is "They are headed for the North Pole", it should still be given a score of 3.
72
+
73
+ Now, read the following question, answer, and correct answers. First think step-by-step and provide your reasoning and assessment on the answer. Then output your score in the following json format: {{"fluency": 0, "correctness": 1}}.
74
+
75
+ Question: {question}
76
+ Correct answers: {correct_answers}
77
+ Answer: {output}
78
+ ```
79
+
80
+ For QMSum:
81
+
82
+ ```
83
+ Please act as an impartial judge and evaluate the quality of the provided summary with respect to a summarization inquiry based on a meeting transcript.
84
+ Although you are not given the transcript, you will be given a reference summary that achieves full scores on all metrics, and you need to assess the provided summary using the reference one.
85
+
86
+ Below is your grading rubric:
87
+
88
+ Fluency:
89
+ - Score 0 (incoherent, repetitive, or incomplete): Incoherent sentences, repetitive sentences (even if not by exact words), incomplete sentences, or gibberish. Note that even if the answer is coherent, if it is repetitive or incomplete, it should be given a score of 0.
90
+ - Score 1 (coherent, non-repetitive answer): Coherent, non-repetitive, fluent, grammatically correct summaries.
91
+
92
+ Correctness:
93
+ - Score 0 (Incorrect): The summary does not agree (have overlap) with the reference summary at all.
94
+ - Score 1 (<=30% correct): Covers less than 30% of the reference summary.
95
+ - Score 2 (<=80% correct): Covers 30%-80% of the reference summary.
96
+ - Score 3 (>80% correct, but not fully relevant): Covers more than 80% of the reference summary, but mentions other completely irrelevant information. Note that extra details provided in the summary, even if not mentioned in the reference summary, should NOT be seen as irrelevant as long as they are relevant to the query to a reasonable extend.
97
+ - Score 4 (>80% correct and relevant): Almost fully agrees with the reference and only provides information relevant to the question.
98
+
99
+ Now, read the following question, reference summary, and provided summary. First think step-by-step and provide your reasoning and assessment on the answer. Then output your score in the following json format: {{"fluency": 0, "correctness": 1}}.
100
+
101
+ Question: {question}
102
+ Reference summary: {correct_answers}
103
+ Provided summary: {output}
104
+ ```
105
+
106
+ Multi-LexSum
107
+
108
+ ```
109
+ Please act as an impartial judge and evaluate the quality of the provided summary of a civil lawsuit. The summary is based on a set of legal documents, and it should contain a short description of the background, parties invovled, and the outcomes of the case.
110
+ You are not given the entirety of the legal documents, but you will be given with expert-written summaries to help you evaluate the quality of the provided summary. The expert-written summaries come in two forms: the short expert summary contains all the relevant information that the provided summary should contain, and the long expert summary contains other relevant information that the provided summary may or may not contain.
111
+
112
+ Below is your grading rubric:
113
+
114
+ Fluency:
115
+ - Score 0 (incoherent, repetitive, or incomplete): Incoherent sentences, repetitive sentences (even if not by exact words), incomplete answers, or gibberish. Note that even if the answer is coherent, if it is repetitive or incomplete, it should be given a score of 0.
116
+ - Score 1 (coherent, non-repetitive answer): Coherent, non-repetitive, fluent, grammatically correct answers.
117
+
118
+ Correctness:
119
+ - Score 0 (Incorrect): The summary does not agree with the information provided in the expert summaries at all. The summary either does not contain any information or only contains irrelevant or incorrect information.
120
+ - Examples:
121
+ - Expert short summary: "This case is about an apprenticeship test that had a disparate impact on Black apprenticeship applicants."
122
+ - Provided summary: "This case is about a lawsuit filed by the EEOC against a company for discrimination against Asian employees."
123
+ - Score 1 (<=30% correct): Covers less than 30% of the expert short summary.
124
+ - Score 2 (<=80% correct): Covers 30%-80% of the expert short summary.
125
+ - Score 3 (>80% correct, but irrelevant or incorrect information found): Covers more than 80% of the expert short summary, but mentions other completely irrelevant information or incorrect information.
126
+ - Irrelevant information is those that are not relelvant to the case and are not found in the expert short/long summaries.
127
+ - Incorrect information is those that are factually incorrect or in conflict with the expert summaries.
128
+ - Score 4 (>80% correct and relevant): The provided summary contains almost all major points found in the expert short summary and does not contain any irrelevant information.
129
+
130
+ Now, read the provided summary and expert summaries, and evaluate the summary using the rubric. First think step-by-step and provide your reasoning and assessment on the answer. Then output your score in the following json format: {{"fluency": 0, "correctness": 1}}.
131
+
132
+ Expert long summary: {long_expert_summary}
133
+
134
+ Export short summary: {short_expert_summary}
135
+
136
+ Provided summary: {output}
137
+ ```
138
+
139
+ We get both a fluency score (0/1) and a correctness score (0-3 for QA and 0-4 for summarization). The final score is fluency * correctness (think fluency as a “prerequisite”), normalized to 0-100.
140
+ </details>
141
+
142
+
143
+ Note that we are still actively developing our evaluation and the results/tasks are subject to change. We plan to include a more systematic evaluation in our technical report. The evaluation code will be available [here](https://github.com/princeton-nlp/ProLong).
144
+
145
+ <details>
146
+ <summary>Some more details about the evaluation.</summary>
147
+
148
+ - All the evaluation context length is determined by the llama-2 tokenizer to accommodate models with smaller vocabularies.
149
+ - For Json KV and RAG, we randomly sample positions of the target key-value pairs or the passages to test “lost-in-the-middle”.
150
+ - For ICL, we use abstract labels (0,1,2,3…) instead of natural language labels ([Pan et al., 2023](https://arxiv.org/pdf/2305.09731)) to evaluate models’ ability to learn new tasks.
151
+ - We use greedy decoding for all models/tasks.
152
+
153
+ </details>
154
+
155
+
156
+ ## Efficient training techniques
157
+
158
+ We integrate several pieces of efficient training techniques in producing our models:
159
+
160
+ - We use [FlashAttention-2 (Dao et al., 2023)](https://github.com/Dao-AILab/flash-attention)’s variable length attention and stop the attention across document boundaries. We combine variable length attention with smart batching (batching sequences with similar lengths in one step) and achieve significant speedup.
161
+ - To handle Llama-3’s large vocabulary and avoid the memory overhead from materializing a huge logit matrix, we computing the cross entropy loss in chunks of 8192 tokens.
162
+ - For training the 512K model, we adapt [DeepSpeed-Ulysses (Jacobs et al., 2023)](https://www.deepspeed.ai/tutorials/ds-sequence/) for sequence parallelism.
163
+
164
+ ## Stage 1: long-context training (64K)
165
+
166
+ We used the following data mixture and traind [meta-llama/Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct) for 20B tokens. Notably, we use 40% high-quality short-context data, 30% 64K book data and 30% 64K code data.
167
+
168
+ <div style="display: flex;">
169
+
170
+ <div style="flex: 3; margin-right: 5px;">
171
+
172
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/607f846419a5af0183d7bfb9/JMKoID3e6Xd7MfJtfM5Nm.png)
173
+
174
+ </div>
175
+ <div style="flex: 1;">
176
+
177
+
178
+ | Data sources |
179
+ |:----- |
180
+ | [Books](https://huggingface.co/datasets/cerebras/SlimPajama-627B) Only 64k tokens |
181
+ | [Textbooks](https://arxiv.org/pdf/2402.11111) Chapters concat. by book and topic |
182
+ | [The Stack V1](https://huggingface.co/datasets/bigcode/the-stack) Source files concat. by repo; only 64K tokens |
183
+ | [StackExchange](https://huggingface.co/datasets/cerebras/SlimPajama-627B) |
184
+ | [Tulu-v2](https://huggingface.co/datasets/allenai/tulu-v2-sft-mixture) |
185
+ | [Wikipedia](https://allenai.github.io/dolma/) |
186
+ | [Arxiv](https://huggingface.co/datasets/cerebras/SlimPajama-627B) |
187
+ | [OpenWebMath](https://huggingface.co/datasets/open-web-math/open-web-math) |
188
+ | [FineWeb](https://huggingface.co/spaces/HuggingFaceFW/blogpost-fineweb-v1) |
189
+ | [FineWeb-EDU](https://huggingface.co/spaces/HuggingFaceFW/blogpost-fineweb-v1) |
190
+ </div>
191
+ </div>
192
+
193
+
194
+
195
+ For the stack v1, we concatenate all the files from the same repo (a strategy introduced by [DeepSeek Coder; Guo et al., 2024](https://github.com/deepseek-ai/DeepSeek-Coder)). For the stack v1 and books, we only keep documents that are longer than 64K.
196
+
197
+ We use the following hyperparameters:
198
+
199
+ | Name | Hyperparameter |
200
+ |:------- |:------- |
201
+ | Batch size | 4M tokens |
202
+ | Peak learning rate | 1e-5 |
203
+ | Scheduling | 5% warmup, cosine decay till 10% peak learning rate |
204
+ | Total #tokens | 20B |
205
+ | Rope theta | 8M |
206
+
207
+ In our preliminary experiments, we found that
208
+
209
+ - One of the challenges in long-context training is to preserve the general LM performance.
210
+ - At the beginning of training, the general LM performance degrades potentially due to optimizer state warmup, data mixture mismatch, and the length extension.
211
+ - We found that the right rope theta + the right data mixture + longer training + low LR help alleviate this problem.
212
+ - Using variable length attention and stopping attention across document boundaries helps preserve the general LM performance.
213
+ - Other warmup schemes like progressively increasing the length (similar to [LWM; Liu et al., 2024](https://arxiv.org/pdf/2402.08268)) do not seem to provide more benefit in our experiments.
214
+
215
+ We will release more details of our ablations in our technical report!
216
+
217
+ ## Stage 2: long-context training (512K)
218
+
219
+ For our 512K model, we continued training the previous model for another 20B tokens. The data mixture is similar -- 40% short data and 60% long data. Among the long data, we use 15% 64K code, 15% 512K code, 25% 64K book, and 5% 512K book -- the ratio largely correlates with code/book's natural distribution.
220
+
221
+ <div style="display: flex;">
222
+
223
+ <div style="flex: 3; margin-right: 5px;">
224
+
225
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/607f846419a5af0183d7bfb9/eeX2optF1oa4l5N9To_y8.png)
226
+
227
+ </div>
228
+ <div style="flex: 1;">
229
+
230
+
231
+ | Data sources |
232
+ |:----- |
233
+ | [Books](https://huggingface.co/datasets/cerebras/SlimPajama-627B) Only 64k tokens |
234
+ | [Textbooks](https://arxiv.org/pdf/2402.11111) Chapters concat. by book and topic |
235
+ | [The Stack V1](https://huggingface.co/datasets/bigcode/the-stack) Source files concat. by repo; only 64K tokens |
236
+ | [StackExchange](https://huggingface.co/datasets/cerebras/SlimPajama-627B) |
237
+ | [Tulu-v2](https://huggingface.co/datasets/allenai/tulu-v2-sft-mixture) |
238
+ | [Wikipedia](https://allenai.github.io/dolma/) |
239
+ | [Arxiv](https://huggingface.co/datasets/cerebras/SlimPajama-627B) |
240
+ | [OpenWebMath](https://huggingface.co/datasets/open-web-math/open-web-math) |
241
+ | [FineWeb](https://huggingface.co/spaces/HuggingFaceFW/blogpost-fineweb-v1) |
242
+ | [FineWeb-EDU](https://huggingface.co/spaces/HuggingFaceFW/blogpost-fineweb-v1) |
243
+ </div>
244
+ </div>
245
+
246
+
247
+
248
+ ## Stage 3: instruction tuning
249
+
250
+ We conduct supervised fine-tuning (SFT) on our base long-context model. In our preliminary experiments, we found that using [UltraChat (Ding et al., 2023)](https://huggingface.co/datasets/stingning/ultrachat) leads to the best long-context results (among [UltraChat](https://huggingface.co/datasets/stingning/ultrachat), [Tulu (Wang et al., 2023)](https://huggingface.co/datasets/allenai/tulu-v2-sft-mixture), and [ShareGPT](https://sharegpt.com/)). Note that this only reflects the performance on our benchmark, not representing the overall quality of those datasets. The hyperparameters we used for SFT are as follows:
251
+
252
+ | Name | Hyperparameter |
253
+ |:------- |:------- |
254
+ | Batch size | 4M tokens |
255
+ | Peak learning rate | 2e-5 |
256
+ | Scheduling | 5% warmup, cosine decay till 10% peak learning rate |
257
+ | Total #tokens | 1B |
258
+
259
+ - Synthetic data: we also experiment with several strategies to generate long, synthetic chat data, but they have not yet helped to improve upon our UltraChat-fine-tuned chat models. The synthetic data strategies we tried include (1) using a paragraph of a long book/repo to generate question-answer pairs; (2) using hierarchical methods to summarize a long book; (3) turning the previous synthetic long QA data into a RAG format.
260
+
261
+ ## Citation
262
+
263
+ If you find our model useful, please cite by
264
+ ```bibtex
265
+ @misc{gao2024prolong,
266
+ title={ProLong Long-Context Language Model Series},
267
+ author={Gao, Tianyu and Wettig, Alexander and Yen, Howard and Chen, Danqi},
268
+ year={2024},
269
+ url="https://huggingface.co/princeton-nlp/Llama-3-8B-ProLong-64k-Instruct"
270
+ }
271
+ ```