Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,278 @@
|
|
1 |
---
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
|
7 |
|
8 |
-
|
9 |
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
-
|
13 |
|
14 |
-
|
15 |
|
16 |
-
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
- **Funded by [optional]:** [More Information Needed]
|
22 |
-
- **Shared by [optional]:** [More Information Needed]
|
23 |
-
- **Model type:** [More Information Needed]
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
-
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
|
28 |
-
|
29 |
|
30 |
-
|
31 |
|
32 |
-
|
33 |
-
- **Paper [optional]:** [More Information Needed]
|
34 |
-
- **Demo [optional]:** [More Information Needed]
|
35 |
|
36 |
-
|
37 |
|
38 |
-
|
|
|
39 |
|
40 |
-
|
|
|
41 |
|
42 |
-
|
|
|
43 |
|
44 |
-
|
|
|
45 |
|
46 |
-
|
|
|
|
|
47 |
|
48 |
-
|
49 |
|
50 |
-
|
51 |
|
52 |
-
|
|
|
53 |
|
54 |
-
|
|
|
|
|
55 |
|
56 |
-
|
|
|
57 |
|
58 |
-
|
|
|
59 |
|
60 |
-
|
|
|
|
|
61 |
|
62 |
-
|
63 |
|
64 |
-
###
|
65 |
|
66 |
-
|
|
|
67 |
|
68 |
-
|
|
|
|
|
69 |
|
70 |
-
|
|
|
71 |
|
72 |
-
|
73 |
|
74 |
-
|
|
|
75 |
|
76 |
-
|
|
|
|
|
77 |
|
78 |
-
|
79 |
|
80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
81 |
|
82 |
-
|
83 |
|
84 |
-
|
85 |
|
86 |
-
|
|
|
87 |
|
88 |
-
|
|
|
|
|
|
|
89 |
|
90 |
-
|
|
|
91 |
|
|
|
|
|
92 |
|
93 |
-
|
|
|
|
|
94 |
|
95 |
-
|
96 |
|
97 |
-
####
|
98 |
|
99 |
-
|
|
|
100 |
|
101 |
-
|
|
|
|
|
102 |
|
103 |
-
|
|
|
104 |
|
105 |
-
|
|
|
106 |
|
107 |
-
|
|
|
|
|
108 |
|
109 |
-
|
110 |
|
111 |
-
|
112 |
|
113 |
-
|
114 |
|
115 |
-
|
116 |
|
117 |
-
|
|
|
|
|
|
|
|
|
118 |
|
119 |
-
|
|
|
120 |
|
121 |
-
|
122 |
|
123 |
-
|
|
|
124 |
|
125 |
-
|
126 |
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
-
[More Information Needed]
|
130 |
|
131 |
-
|
|
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
|
135 |
-
|
136 |
|
137 |
-
|
138 |
|
139 |
-
|
140 |
|
141 |
-
|
142 |
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
|
153 |
-
|
154 |
|
155 |
-
### Model Architecture and Objective
|
156 |
|
157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
|
159 |
-
|
160 |
|
161 |
-
|
162 |
|
163 |
-
|
164 |
|
165 |
-
|
|
|
|
|
166 |
|
167 |
-
|
168 |
|
169 |
-
[More Information Needed]
|
170 |
|
171 |
-
|
172 |
|
173 |
-
|
174 |
|
175 |
-
|
176 |
|
177 |
-
|
178 |
|
179 |
-
|
180 |
|
181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
-
##
|
184 |
|
185 |
-
|
186 |
|
187 |
-
|
188 |
|
189 |
-
|
190 |
|
191 |
-
|
192 |
|
193 |
-
|
194 |
|
195 |
-
|
196 |
|
197 |
-
|
198 |
-
|
199 |
-
[More Information Needed]
|
|
|
1 |
---
|
2 |
+
datasets:
|
3 |
+
- tiiuae/falcon-refinedweb
|
4 |
+
- HuggingFaceFW/fineweb-edu
|
5 |
+
language:
|
6 |
+
- en
|
7 |
---
|
8 |
|
9 |
+
<img src="https://huggingface.co/datasets/tiiuae/documentation-images/resolve/main/falcon_mamba/thumbnail.png" alt="drawing" width="800"/>
|
10 |
|
11 |
+
# Table of Contents
|
12 |
|
13 |
+
0. [TL;DR](#TL;DR)
|
14 |
+
1. [Model Details](#model-details)
|
15 |
+
2. [Usage](#usage)
|
16 |
+
3. [Training Details](#training-details)
|
17 |
+
4. [Evaluation](#evaluation)
|
18 |
|
19 |
|
20 |
+
# TL;DR
|
21 |
|
22 |
+
# Model Details
|
23 |
|
24 |
+
## Model Description
|
25 |
|
26 |
+
- **Developed by:** [https://www.tii.ae](https://www.tii.ae)
|
27 |
+
- **Model type:** Causal decoder-only
|
28 |
+
- **Architecture:** Mamba
|
29 |
+
- **Language(s) (NLP):** Mainly English
|
30 |
+
- **License:** TII Falcon-Mamba License 2.0
|
31 |
|
32 |
+
<br>
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
# Usage
|
35 |
|
36 |
+
Find below some example scripts on how to use the model in `transformers` (Make sure to have the latest transformers, or the one built from source):
|
37 |
|
38 |
+
## Using the Pytorch model
|
|
|
|
|
39 |
|
40 |
+
### Running the model on a CPU
|
41 |
|
42 |
+
<details>
|
43 |
+
<summary> Click to expand </summary>
|
44 |
|
45 |
+
```python
|
46 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
47 |
|
48 |
+
tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-mamba-7b")
|
49 |
+
model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-mamba-7b")
|
50 |
|
51 |
+
input_text = "Question: How many hours in one day? Answer: "
|
52 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids
|
53 |
|
54 |
+
outputs = model.generate(input_ids)
|
55 |
+
print(tokenizer.decode(outputs[0]))
|
56 |
+
```
|
57 |
|
58 |
+
</details>
|
59 |
|
60 |
+
### Running the model on a GPU
|
61 |
|
62 |
+
<details>
|
63 |
+
<summary> Click to expand </summary>
|
64 |
|
65 |
+
```python
|
66 |
+
# pip install accelerate
|
67 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
68 |
|
69 |
+
tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-mamba-7b")
|
70 |
+
model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-mamba-7b", device_map="auto")
|
71 |
|
72 |
+
input_text = "Question: How many hours in one day? Answer: "
|
73 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda")
|
74 |
|
75 |
+
outputs = model.generate(input_ids)
|
76 |
+
print(tokenizer.decode(outputs[0]))
|
77 |
+
```
|
78 |
|
79 |
+
</details>
|
80 |
|
81 |
+
### Running the model on a GPU using `torch.compile`
|
82 |
|
83 |
+
<details>
|
84 |
+
<summary> Click to expand </summary>
|
85 |
|
86 |
+
```python
|
87 |
+
import torch
|
88 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
89 |
|
90 |
+
tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-mamba-7b")
|
91 |
+
model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-mamba-7b", torch_dtype=torch.bfloat16).to(0)
|
92 |
|
93 |
+
model = torch.compile(model)
|
94 |
|
95 |
+
input_text = "Question: How many hours in one day? Answer: "
|
96 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda")
|
97 |
|
98 |
+
outputs = model.generate(input_ids)
|
99 |
+
print(tokenizer.decode(outputs[0]))
|
100 |
+
```
|
101 |
|
102 |
+
</details>
|
103 |
|
|
|
104 |
|
105 |
+
### Running the model on a GPU using different precisions
|
106 |
|
107 |
+
#### FP16
|
108 |
|
109 |
+
<details>
|
110 |
+
<summary> Click to expand </summary>
|
111 |
|
112 |
+
```python
|
113 |
+
# pip install accelerate
|
114 |
+
import torch
|
115 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
116 |
|
117 |
+
tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-mamba-7b")
|
118 |
+
model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-mamba-7b", device_map="auto", torch_dtype=torch.float16)
|
119 |
|
120 |
+
input_text = "Question: How many hours in one day? Answer: "
|
121 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda")
|
122 |
|
123 |
+
outputs = model.generate(input_ids)
|
124 |
+
print(tokenizer.decode(outputs[0]))
|
125 |
+
```
|
126 |
|
127 |
+
</details>
|
128 |
|
129 |
+
#### 4-bit
|
130 |
|
131 |
+
<details>
|
132 |
+
<summary> Click to expand </summary>
|
133 |
|
134 |
+
```python
|
135 |
+
# pip install bitsandbytes accelerate
|
136 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
137 |
|
138 |
+
tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-mamba-7b")
|
139 |
+
model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-mamba-7b", device_map="auto", quantization_config=BitsAndBytesConfig(load_in_4bit=True))
|
140 |
|
141 |
+
input_text = "Question: How many hours in one day? Answer: "
|
142 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda")
|
143 |
|
144 |
+
outputs = model.generate(input_ids)
|
145 |
+
print(tokenizer.decode(outputs[0]))
|
146 |
+
```
|
147 |
|
148 |
+
</details>
|
149 |
|
150 |
+
<br>
|
151 |
|
152 |
+
# Training Details
|
153 |
|
154 |
+
## Training Data
|
155 |
|
156 |
+
Falcon-Mamba has been trained with ~ 5,500 GT mainly coming from [Refined-Web](https://huggingface.co/datasets/tiiuae/falcon-refinedweb), a large volume web-only dataset filtered and deduplicated.
|
157 |
+
Similar to the others [Falcon](https://huggingface.co/tiiuae/falcon-11B) suite models, Falcon-Mamba has been trained leveraging a multi-stage training strategy to increase the context-length from 2,048 to 8,192.
|
158 |
+
Moreover, inspired by the concept of Curriculum Learning, we carefully selected data mixtures throughout the training stages, considering both data diversity and complexity.
|
159 |
+
Note that at inference the context-length is not relevant as the Mamba architecture has no limit on long range dependency.
|
160 |
+
At the last training stage, small portion of high-quality curated data was used to further enhance performance.
|
161 |
|
162 |
+
Overall, the data sources included RefinedWeb-English, high quality technical data, code data and math data extracted from public sources.
|
163 |
+
In particular, we used samples coming from [Fineweb-edu](https://huggingface.co/datasets/HuggingFaceFW/fineweb-edu) during our last training stage.
|
164 |
|
165 |
+
The data was tokenized with the Falcon-[7B](https://huggingface.co/tiiuae/falcon-7B)/[11B](https://huggingface.co/tiiuae/falcon-11B) tokenizer.
|
166 |
|
167 |
+
## Training Procedure
|
168 |
+
Falcon-Mamba-7B was trained on 256 H100 80GB GPUs for the majority of the training, using a 3D parallelism strategy (TP=1, PP=1, DP=256) combined with ZeRO.
|
169 |
|
170 |
+
### Training Hyperparameters
|
171 |
|
172 |
+
| **Hyperparameter** | **Value** | **Comment** |
|
173 |
+
|--------------------|------------|-------------------------------------------|
|
174 |
+
| Precision | `bfloat16` | |
|
175 |
+
| Optimizer | AdamW | |
|
176 |
+
| Max learning rate | 6.4e-4 | Following a WSD (warmup-stable-decay) learning rate schedule |
|
177 |
+
| Weight decay | 1e-1 | |
|
178 |
+
| Batch size | 2048 | |
|
179 |
|
|
|
180 |
|
181 |
+
The model was trained AdamW optimizer, WSD (warmup-stable-decay) learning rate schedule, and a batch size rampup from \\(b_{\mathrm{min}}=128\\) to \\(b_{\mathrm{max}}=2048\\) during first 50 GT of training.
|
182 |
+
In the stable phase we used maximal learning rate \\(\eta_{\mathrm{max}}=6.4 \times 10^{-4}\\), and decayed it to the minimal value \\(\eta_{\mathrm{min}}=\frac{\eta_{\mathrm{max}}}{256}\\) with exponential schedule over 500 GT.
|
183 |
+
Also, we applied *BatchScaling* during the rampup — rescaling learning rate \\(\eta\\) so that the Adam noise temperature \\(T_{\mathrm{noise}}\equiv\frac{\eta}{\sqrt{b}}\\) is kept constant.
|
184 |
|
185 |
+
### Speeds, Sizes, Times
|
186 |
|
187 |
+
The model training took roughly two months.
|
188 |
|
189 |
+
<br>
|
190 |
|
191 |
+
# Evaluation
|
192 |
|
193 |
+
## Benchmarks
|
194 |
|
195 |
+
We evaluate our model on all benchmarks of the new leaderboard's version using the `lm-evaluation-harness` package, and then normalize the evaluation results with HuggingFace score normalization.
|
196 |
|
|
|
197 |
|
198 |
+
| `model name` |`IFEval`| `BBH` |`MATH LvL5`| `GPQA`| `MUSR`|`MMLU-PRO`|`Average`|
|
199 |
+
|:--------------------------|:------:|:-----:|:---------:|:-----:|:-----:|:--------:|:-------:|
|
200 |
+
| ***Pure SSM models*** | | | | | | | |
|
201 |
+
| `FalconMamba-7B` | 33.36 | 19.88 | 3.63 |8.05 |10.86 | 14.47 |**15.04**|
|
202 |
+
| `TRI-ML/mamba-7b-rw`<sup>*</sup>| 22.46 | 6.71 | 0.45 | 1.12 | 5.51 | 1.69 | 6.25 |
|
203 |
+
|***Hybrid SSM-attention models*** | | | | | | |
|
204 |
+
|`recurrentgemma-9b` | 30.76 | 14.80 | 4.83 | 4.70 | 6.60 | 17.88 | 13.20 |
|
205 |
+
| `Zyphra/Zamba-7B-v1`<sup>*</sup> | 24.06 | 21.12 | 3.32 | 3.03 | 7.74 | 16.02 | 12.55 |
|
206 |
+
|***Transformer models*** | | | | | | | |
|
207 |
+
| `Falcon2-11B` | 32.61 | 21.94 | 2.34 | 2.80 | 7.53 | 15.44 | 13.78 |
|
208 |
+
| `Meta-Llama-3-8B` | 14.55 | 24.50 | 3.25 | 7.38 | 6.24 | 24.55 | 13.41 |
|
209 |
+
| `Meta-Llama-3.1-8B` | 12.70 | 25.29 | 4.61 | 6.15 | 8.98 | 24.95 | 13.78 |
|
210 |
+
| `Mistral-7B-v0.1` | 23.86 | 22.02 | 2.49 | 5.59 | 10.68 | 22.36 | 14.50 |
|
211 |
+
| `Mistral-Nemo-Base-2407 (12B)` | 16.83 | 29.37 | 4.98 | 5.82 | 6.52 | 27.46 | 15.08 |
|
212 |
+
| `gemma-7B` | 26.59 | 21.12 | 6.42 | 4.92 | 10.98 | 21.64 |**15.28**|
|
213 |
|
|
|
|
|
|
|
|
|
|
|
214 |
|
215 |
+
Also, we evaluate our model on the benchmarks of the first leaderboard using `lighteval`.
|
216 |
|
|
|
217 |
|
218 |
+
| `model name` |`ARC`|`HellaSwag` |`MMLU` |`Winogrande`|`TruthfulQA`|`GSM8K`|`Average` |
|
219 |
+
|:-----------------------------|:------:|:---------:|:-----:|:----------:|:----------:|:-----:|:----------------:|
|
220 |
+
| ***Pure SSM models*** | | | | | | | |
|
221 |
+
| `FalconMamba-7B`<sup>*</sup> | 62.03 | 80.82 | 62.11 | 73.64 | 53.42 | 52.54 | **64.09** |
|
222 |
+
| `TRI-ML/mamba-7b-rw`<sup>*</sup> | 51.25 | 80.85 | 33.41 | 71.11 | 32.08 | 4.70 | 45.52 |
|
223 |
+
|***Hybrid SSM-attention models***| | | | | | | |
|
224 |
+
| `recurrentgemma-9b`<sup>**</sup> |52.00 | 80.40 | 60.50 | 73.60 | 38.60 | 42.60 | 57.95 |
|
225 |
+
| `Zyphra/Zamba-7B-v1`<sup>*</sup> | 56.14 | 82.23 | 58.11 | 79.87 | 52.88 | 30.78 | 60.00 |
|
226 |
+
|***Transformer models*** | | | | | | | |
|
227 |
+
| `Falcon2-11B` | 59.73 | 82.91 | 58.37 | 78.30 | 52.56 | 53.83 | **64.28** |
|
228 |
+
| `Meta-Llama-3-8B` | 60.24 | 82.23 | 66.70 | 78.45 | 42.93 | 45.19 | 62.62 |
|
229 |
+
| `Meta-Llama-3.1-8B` | 58.53 | 82.13 | 66.43 | 74.35 | 44.29 | 47.92 | 62.28 |
|
230 |
+
| `Mistral-7B-v0.1` | 59.98 | 83.31 | 64.16 | 78.37 | 42.15 | 37.83 | 60.97 |
|
231 |
+
| `gemma-7B` | 61.09 | 82.20 | 64.56 | 79.01 | 44.79 | 50.87 | 63.75 |
|
232 |
|
233 |
+
Mostly, we took evaluation results from both leaderboards. For the models marked by *star* we evaluated the tasks internally, while for the models marked by two *stars* the results were taken from paper or model card.
|
234 |
|
235 |
+
## Throughput
|
236 |
|
237 |
+
This model can achieve comparable throughput and performance compared to other transformer based models that use optimized kernels such as Flash Attention 2. Make sure to install the optimized Mamba kernels with the following commands:
|
238 |
|
239 |
+
```bash
|
240 |
+
pip install "causal-conv1d>=1.4.0" mamba-ssm
|
241 |
+
```
|
242 |
|
243 |
+
Refer to our technical report for more details about performance evaluation.
|
244 |
|
|
|
245 |
|
246 |
+
<br>
|
247 |
|
248 |
+
# Technical Specifications
|
249 |
|
250 |
+
## Model Architecture and Objective
|
251 |
|
252 |
+
Falcon-Mamba-7B is a causal decoder-only model trained on a causal language modeling task (i.e., predict the next token).
|
253 |
|
254 |
+
The model is based on the Mamba architecture ([Gu et al., 2023](https://arxiv.org/abs/2312.00752)).
|
255 |
|
256 |
+
| **Hyperparameter** | **Value** | **Comment** |
|
257 |
+
|--------------------|-----------|----------------------------------------|
|
258 |
+
| Layers | 64 | Number of layers |
|
259 |
+
| `d_model` | 4096 | Hidden dimension |
|
260 |
+
| `d_state` | 16 | The SSM state dimension |
|
261 |
+
| Vocabulary | 65024 | Vocabulary Size |
|
262 |
+
| Sequence length | 8192 | During the last training stages |
|
263 |
|
264 |
+
## Compute Infrastructure
|
265 |
|
266 |
+
### Hardware
|
267 |
|
268 |
+
Falcon-Mamba-7B was trained on AWS SageMaker, using on average 256 H100 80GB GPUs in 32 p5 instances.
|
269 |
|
270 |
+
### Software
|
271 |
|
272 |
+
Falcon-Mamba-7B was trained on an internal distributed training codebase, Gigatron. It uses a 3D parallelism approach combined with ZeRO, high-performance Triton kernels.
|
273 |
|
274 |
+
<br>
|
275 |
|
276 |
+
# Citation
|
277 |
|
278 |
+
*Paper coming soon* 😊.
|
|
|
|