Text Generation
Transformers
Safetensors
English
falcon_mamba
Inference Endpoints
4-bit precision
bitsandbytes
ybelkada commited on
Commit
9252de3
·
verified ·
1 Parent(s): 490b75f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +179 -103
README.md CHANGED
@@ -1,199 +1,275 @@
1
  ---
2
- library_name: transformers
3
- tags: []
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
10
 
 
11
 
12
- ## Model Details
13
 
14
- ### Model Description
 
 
 
 
15
 
16
- <!-- Provide a longer summary of what this model is. -->
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
 
20
- - **Developed by:** [More Information Needed]
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
- ### Model Sources [optional]
29
 
30
- <!-- Provide the basic links for the model. -->
 
 
 
 
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
 
36
- ## Uses
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
 
44
- [More Information Needed]
45
 
46
- ### Downstream Use [optional]
 
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
 
49
 
50
- [More Information Needed]
 
51
 
52
- ### Out-of-Scope Use
 
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
 
55
 
56
- [More Information Needed]
57
 
58
- ## Bias, Risks, and Limitations
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
 
61
 
62
- [More Information Needed]
 
 
63
 
64
- ### Recommendations
 
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
 
67
 
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
 
 
69
 
70
- ## How to Get Started with the Model
71
 
72
- Use the code below to get started with the model.
73
 
74
- [More Information Needed]
 
75
 
76
- ## Training Details
 
 
77
 
78
- ### Training Data
 
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
- [More Information Needed]
 
83
 
84
- ### Training Procedure
 
 
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
 
88
- #### Preprocessing [optional]
89
 
90
- [More Information Needed]
91
 
 
92
 
93
- #### Training Hyperparameters
 
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
 
 
 
96
 
97
- #### Speeds, Sizes, Times [optional]
 
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
 
100
 
101
- [More Information Needed]
 
 
102
 
103
- ## Evaluation
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
 
107
- ### Testing Data, Factors & Metrics
 
108
 
109
- #### Testing Data
 
 
110
 
111
- <!-- This should link to a Dataset Card if possible. -->
 
112
 
113
- [More Information Needed]
 
114
 
115
- #### Factors
 
 
116
 
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
 
119
- [More Information Needed]
120
 
121
- #### Metrics
122
 
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
 
125
- [More Information Needed]
126
 
127
- ### Results
 
 
 
128
 
129
- [More Information Needed]
 
130
 
131
- #### Summary
132
 
 
 
133
 
 
134
 
135
- ## Model Examination [optional]
 
 
 
 
 
 
136
 
137
- <!-- Relevant interpretability work for the model goes here -->
138
 
139
- [More Information Needed]
 
 
140
 
141
- ## Environmental Impact
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
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
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
- ## Technical Specifications [optional]
154
 
155
- ### Model Architecture and Objective
156
 
157
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
158
 
159
- ### Compute Infrastructure
160
 
161
- [More Information Needed]
162
 
163
- #### Hardware
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
- [More Information Needed]
166
 
167
- #### Software
168
 
169
- [More Information Needed]
 
 
170
 
171
- ## Citation [optional]
172
 
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
 
175
- **BibTeX:**
176
 
177
- [More Information Needed]
178
 
179
- **APA:**
180
 
181
- [More Information Needed]
182
 
183
- ## Glossary [optional]
184
 
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
 
 
 
 
 
 
186
 
187
- [More Information Needed]
188
 
189
- ## More Information [optional]
190
 
191
- [More Information Needed]
192
 
193
- ## Model Card Authors [optional]
194
 
195
- [More Information Needed]
196
 
197
- ## Model Card Contact
198
 
199
- [More Information Needed]
 
1
  ---
2
+ datasets:
3
+ - tiiuae/falcon-refinedweb
4
+ - HuggingFaceFW/fineweb-edu
5
+ language:
6
+ - en
7
+ license: apache-2.0
8
  ---
9
 
10
+ # Model Card for Falcon-Mamba-7B - 4bit precision version
11
 
12
+ **Make sure to install `bitsandbytes` and have a GPU compatible with `bitsandbytes` to run this model**
13
 
14
+ <img src="./mamba-paper.png" alt="drawing" width="800"/>
15
 
16
+ > Figure 1 from [Mamba: Linear-Time Sequence Modeling with Selective State Spaces](https://arxiv.org/pdf/2312.00752) from Albert Gu and Tri Dao
17
 
18
+ # Table of Contents
19
 
20
+ 0. [TL;DR](#TL;DR)
21
+ 1. [Model Details](#model-details)
22
+ 2. [Usage](#usage)
23
+ 3. [Training Details](#training-details)
24
+ 4. [Evaluation](#evaluation)
25
 
 
26
 
27
+ # TL;DR
28
 
29
+ # Model Details
 
 
 
 
 
 
30
 
31
+ ## Model Description
32
 
33
+ - **Developed by:** [https://www.tii.ae](https://www.tii.ae)
34
+ - **Model type:** Causal decoder-only
35
+ - **Architecture:** Mamba
36
+ - **Language(s) (NLP):** Mainly English
37
+ - **License:** TII Falcon-Mamba License 2.0
38
 
39
+ ### Model Source
 
 
40
 
41
+ - **Paper:** *coming soon*.
42
 
43
+ # Usage
44
 
45
+ 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):
46
 
47
+ ## Using the Pytorch model
48
 
49
+ ### Running the model on a CPU
50
 
51
+ <details>
52
+ <summary> Click to expand </summary>
53
 
54
+ ```python
55
+ from transformers import AutoTokenizer, AutoModelForCausalLM
56
 
57
+ tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-mamba-7b")
58
+ model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-mamba-7b")
59
 
60
+ input_text = "Question: How many hours in one day? Answer: "
61
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids
62
 
63
+ outputs = model.generate(input_ids)
64
+ print(tokenizer.decode(outputs[0]))
65
+ ```
66
 
67
+ </details>
68
 
69
+ ### Running the model on a GPU
70
 
71
+ <details>
72
+ <summary> Click to expand </summary>
73
 
74
+ ```python
75
+ # pip install accelerate
76
+ from transformers import AutoTokenizer, AutoModelForCausalLM
77
 
78
+ tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-mamba-7b")
79
+ model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-mamba-7b", device_map="auto")
80
 
81
+ input_text = "Question: How many hours in one day? Answer: "
82
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda")
83
 
84
+ outputs = model.generate(input_ids)
85
+ print(tokenizer.decode(outputs[0]))
86
+ ```
87
 
88
+ </details>
89
 
90
+ ### Running the model on a GPU using `torch.compile`
91
 
92
+ <details>
93
+ <summary> Click to expand </summary>
94
 
95
+ ```python
96
+ import torch
97
+ from transformers import AutoTokenizer, AutoModelForCausalLM
98
 
99
+ tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-mamba-7b")
100
+ model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-mamba-7b", torch_dtype=torch.bfloat16).to(0)
101
 
102
+ model = torch.compile(model)
103
 
104
+ input_text = "Question: How many hours in one day? Answer: "
105
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda")
106
 
107
+ outputs = model.generate(input_ids)
108
+ print(tokenizer.decode(outputs[0]))
109
+ ```
110
 
111
+ </details>
112
 
 
113
 
114
+ ### Running the model on a GPU using different precisions
115
 
116
+ #### FP16
117
 
118
+ <details>
119
+ <summary> Click to expand </summary>
120
 
121
+ ```python
122
+ # pip install accelerate
123
+ import torch
124
+ from transformers import AutoTokenizer, AutoModelForCausalLM
125
 
126
+ tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-mamba-7b")
127
+ model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-mamba-7b", device_map="auto", torch_dtype=torch.float16)
128
 
129
+ input_text = "Question: How many hours in one day? Answer: "
130
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda")
131
 
132
+ outputs = model.generate(input_ids)
133
+ print(tokenizer.decode(outputs[0]))
134
+ ```
135
 
136
+ </details>
137
 
138
+ #### 4-bit
139
 
140
+ <details>
141
+ <summary> Click to expand </summary>
142
 
143
+ ```python
144
+ # pip install bitsandbytes accelerate
145
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
146
 
147
+ tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-mamba-7b")
148
+ model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-mamba-7b", device_map="auto", quantization_config=BitsAndBytesConfig(load_in_4bit=True))
149
 
150
+ input_text = "Question: How many hours in one day? Answer: "
151
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda")
152
 
153
+ outputs = model.generate(input_ids)
154
+ print(tokenizer.decode(outputs[0]))
155
+ ```
156
 
157
+ </details>
158
 
 
159
 
 
160
 
161
+ # Training Details
162
 
163
+ ## Training Data
164
 
165
+ Falcon-Mamba has been trained with ~ 6,000 GT mainly coming from [Refined-Web](https://huggingface.co/datasets/tiiuae/falcon-refinedweb), a large volume web-only dataset filtered and deduplicated.
166
+ 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 training from 2,048 up to 8,192.
167
+ Note that at inference the context-length is not relevant as the Mamba architecture has no limit on long range dependency.
168
+ At the last training stage, small portion of high-quality curated data was used to further enhance performance.
169
 
170
+ Overall, the data sources included RefinedWeb-English, high quality technical data, code data and conversational data extracted from public sources.
171
+ In particular, we used samples coming from [Fineweb-edu](https://huggingface.co/datasets/HuggingFaceFW/fineweb-edu).
172
 
173
+ The data was tokenized with the Falcon-[7B](https://huggingface.co/tiiuae/falcon-7B)/[11B](https://huggingface.co/tiiuae/falcon-11B) tokenizer.
174
 
175
+ ## Training Procedure
176
+ 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.
177
 
178
+ #### Training Hyperparameters
179
 
180
+ | **Hyperparameter** | **Value** | **Comment** |
181
+ |--------------------|------------|-------------------------------------------|
182
+ | Precision | `bfloat16` | |
183
+ | Optimizer | AdamW | |
184
+ | Max learning rate | 6.4e-4 | Following a WSD (warmup-stable-decay) learning rate schedule |
185
+ | Weight decay | 1e-1 | |
186
+ | Batch size | 2048 | |
187
 
 
188
 
189
+ 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.
190
+ 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.
191
+ 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.
192
 
193
+ #### Speeds, Sizes, Times
194
 
195
+ The model training took roughly two months.
196
 
197
+ # Evaluation
198
 
199
+ ## Benchmarks
 
 
 
 
200
 
201
+ We evaluate our model on all benchmarks of the leaderboard's version 2 using the `lm-evaluation-harness` package, and we evaluate it on the benchmarks of version 1 using `lighteval`.
202
 
 
203
 
204
+ | `model name` |`IFEval`| `BBH` |`MATH LvL5`| `GPQA`| `MUSR`|`MMLU-PRO`|`Average`|
205
+ |:--------------------------|:------:|:-----:|:---------:|:-----:|:-----:|:--------:|:-------:|
206
+ | ***Pure SSM models*** | | | | | | | |
207
+ | `Falcon-Mamba-7B` | 33.36 | 19.88 | 3.63 | 8.05 | 10.86 | 14.47 |**15.04**|
208
+ | `TRI-ML/mamba-7b-rw` | 22.46 | 6.71 | 0.45 | 1.12 | 5.51 | 1.69 | 6.25 |
209
+ |***Hybrid SSM-attention models*** | | | | | | |
210
+ | `Zamba-7B-v1` | 24.06 | 21.12 | 3.32 | 3.03 | 7.74 | 16.02 | 12.55 |
211
+ |`recurrentgemma-9b` | 30.76 | 14.80 | 4.83 | 4.70 | 6.60 | 17.88 | 13.20 |
212
+ |***Transformer models*** | | | | | | | |
213
+ | `Falcon2-11B` | 32.61 | 21.94 | 2.34 | 2.80 | 7.53 | 15.44 | 13.78 |
214
+ | `Meta-Llama-3-8B` | 14.55 | 24.50 | 3.25 | 7.38 | 6.24 | 24.55 | 13.41 |
215
+ | `gemma-7B` | 26.59 | 21.12 | 6.42 | 4.92 | 10.98 | 21.64 |**15.28**|
216
+ | `Mistral-7B-v0.1` | 23.86 | 22.02 | 2.49 | 5.59 | 10.68 | 22.36 | 14.50 |
217
+ | `Mistral-Nemo-Base` | 16.83 | 29.37 | 4.98 | 5.82 | 6.52 | 27.46 | 15.08 |
218
 
 
219
 
 
220
 
221
+ | `model name` |`ARC`|`HellaSwag` |`MMLU` |`Winogrande`|`TruthfulQA`|`GSM8K`|`Average` |
222
+ |:-----------------------------|:------:|:---------:|:-----:|:----------:|:----------:|:-----:|:----------------:|
223
+ | ***Pure SSM models*** | | | | | | | |
224
+ | `Falcon-Mamba-7B` |62.03 | 80.82 | 62.11 | 73.64 | 53.42 | 52.54 | **64.09** |
225
+ | `TRI-ML/mamba-7b-rw` | 46.48 | 80.24 | 57.72 | 76.40 | - | 4.70 | - |
226
+ |***Hybrid SSM-attention models***| | | | | | | |
227
+ | `recurrentgemma-9b` |52.00 | 80.40 | 60.50 | 73.60 | 38.60 | 42.60 | 57.95 |
228
+ | `Zyphra/Zamba-7B-v1` | 46.48 | 80.24 | 57.72 | 76.40 | - | 30.78 | - |
229
+ |***Transformer models*** | | | | | | | |
230
+ | `Falcon2-11B` | 59.73 | 82.91 | 58.37 | 78.30 | 52.56 | 53.83 | **64.28** |
231
+ | `Meta-Llama-3-8B` | 60.24 | 82.23 | 66.70 | 78.45 | 42.93 | 45.19 | 62.62 |
232
+ | `gemma-7B` | 61.09 | 82.20 | 64.56 | 79.01 | 44.79 | 50.87 | 63.75 |
233
+ | `Mistral-7B-v0.1` | 59.98 | 83.31 | 64.16 | 78.37 | 42.15 | 37.83 | 60.97 |
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
 
247
+ # Technical Specifications
248
 
249
+ ## Model Architecture and Objective
250
 
251
+ Falcon-Mamba-7B is a causal decoder-only model trained on a causal language modeling task (i.e., predict the next token).
252
 
253
+ The model is based on the Mamba architecture ([Gu et al., 2023](https://arxiv.org/abs/2312.00752)).
254
 
255
+ | **Hyperparameter** | **Value** | **Comment** |
256
+ |--------------------|-----------|----------------------------------------|
257
+ | Layers | 64 | Number of layers |
258
+ | `d_model` | 4096 | Hidden dimension |
259
+ | `d_state` | 16 | The SSM state dimension |
260
+ | Vocabulary | 65024 | Vocabulary Size |
261
+ | Sequence length | 8192 | During stages 4 and LR Decay stage |
262
 
263
+ ## Compute Infrastructure
264
 
265
+ ### Hardware
266
 
267
+ Falcon-Mamba-7B was trained on AWS SageMaker, using on average 256 H100 80GB GPUs in 32 p5 instances.
268
 
269
+ ### Software
270
 
271
+ Falcon-Mamba-7B was trained an internal distributed training codebase, Gigatron. It uses a 3D parallelism approach combined with ZeRO, high-performance Triton kernels.
272
 
273
+ # Citation
274
 
275
+ *Paper coming soon* 😊.