ohallstrom commited on
Commit
e62657d
1 Parent(s): 2258609

Add model card

Browse files
README.md ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ thumbnail: images/alfred-40b-1023.png
4
+ datasets:
5
+ - OpenAssistant/oasst1
6
+ - ehartford/dolphin
7
+ - tau/sled
8
+ - tiiuae/falcon-refinedweb
9
+ language:
10
+ - en
11
+ - fr
12
+ - de
13
+ - es
14
+ - it
15
+ tags:
16
+ - falcon-40b
17
+ - long-context
18
+ - falcon
19
+ - NTK-YaRN
20
+ ---
21
+ # Model Card for Alfred-40B-1023
22
+
23
+ ![a witty and elegant butler with a falcon on his shoulder, smile, flat illustration, simple shapes, colorful, lo-fi aesthetics](images/alfred-40b-1023.png)
24
+
25
+ `Alfred-40B-1023` is a finetuned version of [Falcon-40B](https://huggingface.co/tiiuae/falcon-40b), with an **extended context length of 8192 tokens**.
26
+ Finetuning was performed in October 2023. `Alfred-40B-1023` is made available under the Apache 2.0 License.
27
+
28
+ ## Model Details
29
+
30
+ ### Model Description
31
+
32
+ - **Developed by:** [LightOn](https://www.lighton.ai/)
33
+ * [Oskar Hallström](https://huggingface.co/ohallstrom) (project lead, training & modeling, internal long context data, evaluation)
34
+ * [Amélie Chatelain](https://huggingface.co/ameliechatelain) (internal data & long context data, data generation)
35
+ * [Clément Thiriet](https://huggingface.co/cthiriet) (data infrastructure, data generation, evaluation)
36
+ * [Julien Séailles](https://huggingface.co/Jseailleslighton) (data generation)
37
+ * [Adrien Cavaillès](https://huggingface.co/adcavail) (data generation)
38
+ * [Axel Marmet](https://huggingface.co/WeightsnWizardry)* (training 2K baseline)
39
+
40
+ `*` work done while at LightOn
41
+ - **Model type:** Causal decoder-only;
42
+ - **Language(s) (NLP):** English, German, Spanish, French (and limited capabilities in Italian, Portuguese, Polish, Dutch, Romanian, Czech, Swedish);
43
+ - **License:** Apache 2.0 license.
44
+ - **Finetuned from model:** [Falcon-40B](https://huggingface.co/tiiuae/falcon-40b)
45
+ - **Training date:** October 2023 (`1023`).
46
+
47
+ ## Uses
48
+
49
+ ### Direct Use
50
+
51
+ `Alfred-40B-1023` can be used as a chat model or as an instruct model.
52
+
53
+ For both instruct and chat mode, the model has been trained with chat tokens `<start_system>`, `<start_user>`, `<start_assistant>`, and `<end_message>`. These can be integrated into the prompt in the follwoing way:
54
+ ```
55
+ <start_system>You are Alfred, a helpful assistant trained by LightOn. Knowledge cutoff: November 2022. Current date: 16 November, 2023<end_message><start_user>{user query}<end_message><start_assistant>
56
+ ```
57
+
58
+ The stop word `<end_message>` should be used.
59
+
60
+ ### Out-of-Scope Use
61
+
62
+ Production use without adequate assessment of risks and mitigation; any use cases which may be considered irresponsible or harmful.
63
+
64
+ ## Bias, Risks, and Limitations
65
+
66
+ `Alfred-40B-1023` is a finetune of Falcon-40B. As such, it is trained mostly on English, German, Spanish, French, with limited capabilities also in Italian, Portuguese, Polish, Dutch, Romanian, Czech, Swedish. It will not generalize appropriately to other languages. Furthermore, as it is trained on a large-scale corpora representative of the web, it will carry the stereotypes and biases commonly encountered online.
67
+
68
+ ### Recommendations
69
+
70
+ We recommend users of `Alfred-40B-1023` to implement appropriate guardrails and precautions in any production use.
71
+
72
+ ## How to Get Started with the Model
73
+
74
+ Use the code below to get started with the model.
75
+
76
+ ```
77
+ from transformers import AutoTokenizer, AutoModelForCausalLM
78
+ import transformers
79
+ import torch
80
+
81
+ model = "lightonai/alfred-40b-1023"
82
+ tokenizer = AutoTokenizer.from_pretrained("lightonai/alfred-0923-tokenizer")
83
+
84
+ pipeline = transformers.pipeline(
85
+ "text-generation",
86
+ model=model,
87
+ tokenizer=tokenizer,
88
+ torch_dtype=torch.bfloat16,
89
+ trust_remote_code=True,
90
+ device_map="auto",
91
+ )
92
+
93
+ sequences = pipeline(
94
+ "<start_system>You are Alfred, a helpful assistant trained by LightOn. Knowledge cutoff: November 2022. Current date: 16 November, 2023<end_message><start_user>Write me an email to my boss, explaining how the company could benefit by using LightOns platform for Large Language Models, Paradigm.<end_message><start_assistant>",
95
+ max_length=1000,
96
+ do_sample=True,
97
+ top_k=3,
98
+ num_return_sequences=1,
99
+ eos_token_id=tokenizer.eos_token_id,
100
+ )
101
+ for seq in sequences:
102
+ print(f"Result: {seq['generated_text']}")
103
+ ```
104
+
105
+ ## Training Details
106
+
107
+ ### Training Data
108
+
109
+ Alfred-40B-1023 was trained on a mixture of publicly available and in-house curated datasets. The training data is composed of 50 % short context tasks, 45 % long context tasks and 5 % RefinedWeb.
110
+
111
+ | **Short context sources** |
112
+ |--------------------|
113
+ | [oasst1](https://huggingface.co/datasets/OpenAssistant/oasst1) |
114
+ | [dolphin](https://huggingface.co/ehartford/dolphin) |
115
+ | [openai-critiques](https://openaipublic.blob.core.windows.net/critiques/README.md) |
116
+ | internal |
117
+ `internal` is a collection of synthetic and human-generated datasets created by Ligthon, tailored towards the use cases of our clients.
118
+
119
+ | **Long context sources** |
120
+ |--------------------|
121
+ | [sled](https://huggingface.co/datasets/tau/sled) |
122
+ | internal-long-context |
123
+
124
+ `internal-long-context` is a collection of synthetic datasets generated by LightOn, tailored towards the use cases of our clients.
125
+
126
+ During training, we apply regular language modeling loss for a partition of the prompts in the long context data.
127
+
128
+ | **Pretraining objective source** |
129
+ |--------------------|
130
+ | [RefinedWeb](https://huggingface.co/datasets/tiiuae/falcon-refinedweb) |
131
+
132
+ ### Training Procedure
133
+
134
+ `Alfred-40B-1023` was trained on 128 A100 40GB GPUs, using a 3D parallelism strategy (TP=8, PP=2, DP=8) combined with ZeRO. Alfred has been trained through supervised finetuning on 100 megatokens, with a learning rate decayed with a cosine schedule.
135
+
136
+ #### Preprocessing
137
+
138
+ All datasets have been filtered, up or downsampled, and adapted to our chat token format.
139
+
140
+ #### Context length extension
141
+
142
+ We extend the context length to 8K with a custom method that we name NTK-YaRN. As guessable from its name, our extension method draws inspiration from NTK-aware interpolation and YaRN.
143
+
144
+ During our context length extension efforts, we experimented with various methods suitable for RoPE embeddings. These include vanilla [positional interpolation](https://arxiv.org/abs/2306.15595), [NTK-aware interpolation](https://www.reddit.com/r/LocalLLaMA/comments/14lz7j5/ntkaware_scaled_rope_allows_llama_models_to_have/), [NTK-by-parts](https://github.com/jquesnelle/scaled-rope/pull/1), and lastly [YaRN](https://arxiv.org/abs/2309.00071).
145
+
146
+ YaRN looked very promising when applied at test-time, however finetuning with YaRN was not successful in our experiments. When extending the context length at training-time, NTK-aware interpolation was the most successful out of the already existing methods. Some of our results from trying different long context extension methods are shared in the Evaluation section below. We acknowledge that the same parameter values as proposed in the YaRN-paper have been used in our YaRN experiments, and that these potentially could have other optimal values for our particular setup.
147
+
148
+ ##### NTK-YaRN
149
+
150
+ Similarly to NTK-aware interpolation (`NTK`), NTK-YaRN involves increasing the base of the RoPE embeddings. In the original implementation of NTK-aware interpolation the new base `b'` is adapted according to the following formula:
151
+
152
+ $$ b' = b \times s^{\frac{|D|}{|D|-2}} $$
153
+
154
+ where `b` is the original base, `s` the scaling factor of the context length, and `|D|` the model's head dimension.
155
+
156
+ However, we find (similar to other actors) that increasing the base slightly more is even better. The value of `b'` could probably be optimized even further, but for these experiments we have settled with the following value:
157
+
158
+ $$ b' = b \times (s+1)^{\frac{|D|}{|D|-2}} $$
159
+
160
+ In the following parts of this model card, context length extension with this extended scaling of the base is referred to as `NTK-Margin`. For `NTK-YaRN`, the extended scaling of the base is combined with the modification of the computation of the attention weights made in YaRN, where the query and key matrices are scaled by the factor `m`.
161
+
162
+ $$ m = 1 + 0.1 \times \log(s) $$
163
+
164
+ Scaling the query and key matrices this way substantially reduces the initial grad norm when applying a context length extension method in our training runs.
165
+
166
+ To cite NTK-YaRN, please refer to the model bibtex in the bottom of this model card.
167
+
168
+ ## Evaluation
169
+
170
+ ### Context length extension strategies
171
+ #### Training losses
172
+
173
+ After experimenting on a 7B scale, we finally run a selected partition of the extension methods on a 40B scale. In the figure below, we display the resulting training losses when training a 40B model with the different extension methods, ceteris paribus.
174
+
175
+ ![Training loss curves for extension methods](images/training-loss-curves.png "Training loss curves for extension methods")
176
+
177
+ Initially, YaRN has the lowest training loss, which can be seen as a reflection of the fact that YaRN was the most successful extension method at test time. However all the other methods surpasse YaRN in terms of training loss already after a handful of megatokens. Comparing NTK-Margin vs NTK-YaRN, we can note that the scaling of Q and K matrices makes the training loss lower in the beginning, however NTK-YaRN's advantage over NTK-Margin decreases as the training goes on. Comparing NTK-Margin with NTK in turn, it seems like the larger value of the base in NTK-Margin gives an initial boost in training loss, however this advantage decreases as training goes on.
178
+
179
+ #### Performance on Long Context Benchmarks
180
+ We evaluate the context length extension methods on an own benchmark, consisting of four tasks.
181
+
182
+ * [Key-value retrieval UUID](https://arxiv.org/pdf/2307.03172.pdf)
183
+ * [Coarse-grained Topic Retrieval](https://lmsys.org/blog/2023-06-29-longchat/)
184
+ * [Fine-grained Line Retrieval](https://lmsys.org/blog/2023-06-29-longchat/)
185
+ * [Multi document retrieval data](https://nlp.stanford.edu/data/nfliu/lost-in-the-middle/nq-open-contriever-msmarco-retrieved-documents.jsonl.gz)
186
+
187
+ For each task, we have created 3 subtasks - one for each of the three context lengths 2K, 4K and 8K. In total, we thus have 12 subtasks.
188
+
189
+ In order to get an aggregated score that values each subtask equally, we normalize the scores for each subtask and then calculate the mean of the normalized scores for each extension method.
190
+
191
+ ![Aggregated scores on long context benchmarks](images/lc_benchmarks.png "Aggregated scores on long context benchmarks")
192
+
193
+ On these benchmarks, YaRN clearly lags behind. NTK-YaRN is the winning method, however NTK-Margin is so close that more extensive research is needed to verify that NTK-YaRN really is superior to NTK-Margin, especially when trained for longer.
194
+
195
+ ### Comparison to 2K baseline
196
+
197
+ In order to track any potential degradation on 2K context tasks due to the context length extension, we compare our 8K model against a 2K model trained in a similar setup for 100 megatokens. When training the 2K baseline, we don't include any long context data.
198
+
199
+ We conduct the comparison by evaluating the models on a selection of tasks from EleutherAI harness, as well as ranking model outputs internally.
200
+
201
+ ![Evaluation of 2K vs 8K version of alfred-40b-2023](images/2k_vs_8k.png "Evaluation of 2K vs 8K version of alfred-40b-2023")
202
+
203
+ Notably, our 8K model not only performs on par with our 2K model on most of our EleutherAI harness tasks, in fact it outperforms the 2K model on a majority of the tasks. Reading comprehension is the only subcategory for which our 8K model is outperformed by the 2K model.
204
+
205
+ We recognize that there is a discrepancy between performance on classical NLP benchmarks and how humans perceive the model quality. When model outputs (limited to 2K context lengths) are ranked by LightOn employees internally, the 2K and 8K have strikingly similar performance. However, a few rare failure modes have been noted for the 8K version, which are not seen when using the 2K model. These failure modes are likely to be fixable with better composition of the long context data.
206
+
207
+
208
+ ## Compute Infrastructure
209
+
210
+ ### Hardware
211
+
212
+ Alfred-40B-1023 was trained on AWS SageMaker, on 128 A100 40GB GPUs in P4d instances.
213
+
214
+ ### Software
215
+
216
+ Alfred-40B-1023 was trained with a custom codebase. Training leverages a 3D parallelism approach combined with ZeRO, as well as high-performance kernels such as FlashAttention.
217
+
218
+ ## Model Card Contact
219
+
220
+ Please open a Community Discussion for any support request related to using Alfred with HuggingFace transformers.
221
+
222
+ For any other inquiry: [email protected]
223
+
224
+ ## Citation
225
+
226
+ If you find the model useful in your work, please use the following bibtex when citing.
227
+ ```
228
+ @article{alfred-40b-1023,
229
+ title={Alfred-40B-1023},
230
+ author={Hallström, Oskar and Chatelain, Amélie and Thiriet, Clément and Séailles, Julien and Cavaillès, Adrien and Marmet, Axel},
231
+ year={2023}
232
+ }
233
+ ```
images/2k_vs_8k.png ADDED
images/alfred-40b-1023.png ADDED
images/lc_benchmarks.png ADDED
images/training-loss-curves.png ADDED