divykum commited on
Commit
e25d607
·
verified ·
1 Parent(s): 2120146

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +310 -3
README.md CHANGED
@@ -1,3 +1,310 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ library_name: transformers
4
+ tags:
5
+ - bamba
6
+ ---
7
+
8
+ ## Model Details
9
+ <p align="center">
10
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/64b6c638ac6d20bae0b93219/GOzs8o4G1apceun92ZC4d.png" alt="Bamba" width="400" height="400">
11
+ </p>
12
+
13
+ # Model Card for Bamba 9B v2
14
+ We introduce Bamba-9B-v2, a decoder-only language model based on the [Mamba-2](https://github.com/state-spaces/mamba) architecture and is designed to handle a wide range of text generation tasks. It is trained from scratch using a two-stage training approach. In the first stage, the model is trained on 2 trillion tokens from the Dolma v1.7 dataset. In the second stage, it undergoes additional training on another 1.1 trillion tokens, leveraging a carefully curated blend of high-quality data to further refine its performance and enhance output quality.
15
+
16
+ | Model | Params | # Layers | Hidden Dim. | Attention Heads | GQA | KV Heads | Context Length | Tied Embeddings |
17
+ | ----- | ---------- | -------- | ----------- | --------------- | ---- | -------- | -------------- | --------------- |
18
+ | Bamba | 9B (9.78B) | 32 | 4096 | 32 | Yes | 8 | 4096 | False |
19
+
20
+
21
+ The current release includes the following models:
22
+ | **Stage** | **Bamba 9B** | **Quantized** | **Note** |
23
+ |----------------------|----------------------------------------------------------------------|-------------------------------------------------------------------------|-------------------------------------------------------------------|
24
+ | **Base Model** | [ibm-fms/Bamba-9B-v2](https://huggingface.co/ibm-fms/Bamba-9B-v2) | TBD | Stage 2 pretraining |
25
+ | **Base Model** | [ibm-fms/Bamba-9B](https://huggingface.co/ibm-fms/Bamba-9B) | [ibm-fms/Bamba-9B-fp8](https://huggingface.co/ibm-fms/Bamba-9B-fp8) | Stage 2 pretraining |
26
+ | **Base Model** | [ibm-fms/Bamba-9B-2T](https://huggingface.co/ibm-fms/Bamba-9B-2T) | [ibm-fms/Bamba-9B-fp8](https://huggingface.co/ibm-fms/Bamba-9B-fp8) | Stage 1 pretraining |
27
+ | **Base Model** | [ibm-fms/Bamba-9B-1.8T](https://huggingface.co/ibm-fms/Bamba-9B-1.8T)| [ibm-fms/Bamba-9B-fp8](https://huggingface.co/ibm-fms/Bamba-9B-fp8) | Intermediate checkpoints during Stage 1, more to come |
28
+ | **SFT** | coming soon | coming soon | to be released in the next drop |
29
+ | **DPO** | coming soon | coming soon | to be released in the next drop |
30
+
31
+ Original checkpoints (in dcp format) were also uploaded to public bucket:
32
+ ```
33
+ bucket: bamba-public
34
+ endpoint-url: https://s3.us-east.cloud-object-storage.appdomain.cloud
35
+ ```
36
+ example command to list original Bamba distributed checkpoints:
37
+ ```bash
38
+ aws --endpoint-url https://s3.us-east.cloud-object-storage.appdomain.cloud s3 ls s3://bamba-public/checkpoints/pretraining/phase_two/2_2t/step_140000_ckp/
39
+ ```
40
+
41
+ ## Installation
42
+
43
+ Besides [PyTorch](https://pytorch.org/), you would need a few [extra dependencies](https://github.com/state-spaces/mamba?tab=readme-ov-file#installation) for
44
+ Mamba models.
45
+
46
+ We found some of these dependencies picky on PyTorch versions when doing pip install, so
47
+ the best way is to build from source for all Mamba dependencies if you hit dependency
48
+ issue with your env:
49
+ ```bash
50
+ git clone https://github.com/Dao-AILab/causal-conv1d.git
51
+ cd causal-conv1d && pip install . && cd ..
52
+ git clone https://github.com/state-spaces/mamba.git
53
+ cd mamba && pip install . && cd ..
54
+ git clone https://github.com/Dao-AILab/flash-attention.git
55
+ cd flash-attention && pip install . && cd ..
56
+ ```
57
+
58
+ For users using our HF versions of the model, you would need to install the latest transformers which includes our newly merged implementation for our Bamba models:
59
+ ```bash
60
+ pip install git+https://github.com/huggingface/transformers.git
61
+ ```
62
+
63
+ ## Inference
64
+ You can utilize our newly contributed HF integration to run inference on our Bamba models:
65
+ ```python
66
+ from transformers import AutoModelForCausalLM, AutoTokenizer
67
+
68
+ model = AutoModelForCausalLM.from_pretrained("ibm-fms/Bamba-9B-v2")
69
+ tokenizer = AutoTokenizer.from_pretrained("ibm-fms/Bamba-9B-v2")
70
+
71
+ message = ["Mamba is a snake with following properties "]
72
+ inputs = tokenizer(message, return_tensors='pt', return_token_type_ids=False)
73
+ response = model.generate(**inputs, max_new_tokens=64)
74
+ print(tokenizer.batch_decode(response, skip_special_tokens=True)[0])
75
+
76
+ ```
77
+
78
+
79
+ ## Training
80
+
81
+ We trained our Bamba model with FSDP using our training repo [here](https://github.com/foundation-model-stack/fms-fsdp).
82
+ Note that this training effort was started before FSDP2 and also long before we contributed
83
+ `Mamba2-Hybrid` to HF, so we were doing FSDP1 training with [official Mamba implementation](https://github.com/state-spaces/mamba).
84
+ For users trying to reproduce the training you now have much more options with our newly
85
+ contributed [HF-version of Mamba2-Hybrid](https://github.com/huggingface/transformers/tree/main/src/transformers/models/bamba).
86
+
87
+
88
+ ## Benchmark scores
89
+
90
+ ### Base pretrained models
91
+
92
+ <table>
93
+ <tr>
94
+ <td><strong>Category</strong>
95
+ </td>
96
+ <td><strong>Benchmark</strong>
97
+ </td>
98
+ <td><strong>Bamba 9B (3.1T)</strong>
99
+ </td>
100
+ </tr>
101
+ <tr>
102
+ <td rowspan="8" >General
103
+ </td>
104
+ <td>MMLU (5-shot)
105
+ </td>
106
+ <td>67.92
107
+ </td>
108
+ </tr>
109
+ <tr>
110
+ <td>ARC-C (25-shot)
111
+ </td>
112
+ <td>63.57
113
+ </td>
114
+ </tr>
115
+ <tr>
116
+ <td>GSM8K (5-shot)
117
+ </td>
118
+ <td>41.70
119
+ </td>
120
+ </tr>
121
+ <tr>
122
+ <td>Hellaswag (10-shot)
123
+ </td>
124
+ <td>83.85
125
+ </td>
126
+ </tr>
127
+ <tr>
128
+ <td>OpenbookQA (5-shot)
129
+ </td>
130
+ <td>51.0
131
+ </td>
132
+ </tr>
133
+ <tr>
134
+ <td>Piqa (5-shot)
135
+ </td>
136
+ <td>83.62
137
+ </td>
138
+ </tr>
139
+ <tr>
140
+ <td>TruthfulQA (0-shot)
141
+ </td>
142
+ <td>50.86
143
+ </td>
144
+ </tr>
145
+ <tr>
146
+ <td>Winogrande (5-shot)
147
+ </td>
148
+ <td>79.48
149
+ </td>
150
+ </tr>
151
+ <tr>
152
+ <td rowspan="6" >HF OpenLLM- V2*
153
+ </td>
154
+ <td>MMLU-PRO (5-shot)
155
+ </td>
156
+ <td>25.41
157
+ </td>
158
+ </tr>
159
+ <tr>
160
+ <td>BBH (3-shot)
161
+ </td>
162
+ <td>24.78
163
+ </td>
164
+ </tr>
165
+ <tr>
166
+ <td>GPQA (0-shot)
167
+ </td>
168
+ <td>5.93
169
+ </td>
170
+ </tr>
171
+ <tr>
172
+ <td>IFEval (0-shot)
173
+ </td>
174
+ <td>19.0
175
+ </td>
176
+ </tr>
177
+ <tr>
178
+ <td>MATH Lvl 5 (4-shot)
179
+ </td>
180
+ <td>6.42
181
+ </td>
182
+ </tr>
183
+ <tr>
184
+ <td>MuSR (0-shot)
185
+ </td>
186
+ <td>9.28
187
+ </td>
188
+ </tr>
189
+ <tr>
190
+ <td rowspan="4" >Safety Tasks
191
+ </td>
192
+ <td>PopQA (5-shot)
193
+ </td>
194
+ <td>20.5
195
+ </td>
196
+ </tr>
197
+ <tr>
198
+ <td>Toxigen (5-shot)
199
+ </td>
200
+ <td>57.4
201
+ </td>
202
+ </tr>
203
+ <tr>
204
+ <td>BBQ (5-shot)
205
+ </td>
206
+ <td>44.2
207
+ </td>
208
+ </tr>
209
+ <tr>
210
+ <td>Crows-pairs english (5-shot)
211
+ </td>
212
+ <td>70.78
213
+ </td>
214
+ </tr>
215
+ </table>
216
+
217
+ *For the v2 leaderboard results, we perform [normalization](https://huggingface.co/docs/leaderboards/open_llm_leaderboard/normalization) and report the normalized results.
218
+ Further details on our evaluation and normalization detailes along with run and analysis scripts can be found [here](https://github.com/foundation-model-stack/bamba/blob/main/evaluation/README.md).
219
+
220
+
221
+
222
+ ## Fine-tuning
223
+
224
+ This [example](https://github.com/foundation-model-stack/bamba/blob/main/tuning/Fine-tuning.md) shows how to fine tune the bamba model for a specific task using [SFT Trainer](https://huggingface.co/docs/trl/en/sft_trainer#supervised-fine-tuning-trainer).
225
+
226
+
227
+ ## Quantization
228
+ We can create a (FP8) quantized model using [`fms-model-optimizer`](https://github.com/foundation-model-stack/fms-model-optimizer/), which will make the storage and inference even more efficient.
229
+ ```python
230
+ python -m fms_mo.run_quant \
231
+ --model_name_or_path <"path_to_original_model"> \
232
+ --quant_method fp8 \
233
+ --torch_dtype bfloat16 \
234
+ --output_dir <"path_to_save_new_model">
235
+ ```
236
+ Model size comparison before and after FP8:
237
+ | | original | quantized |
238
+ | :-----------------: | -----------------------: | -----------------------------------------------------------: |
239
+ | memory (total) | 39.12 GB | 10.83 GB |
240
+ | memory (break-down) | `torch.float32` 39.12 GB | `torch.bfloat16` 2.10 GB<br>`torch.float8_e4m3fn` 8.73 GB |
241
+
242
+ More details about `fms-model-optimizer` can be found [here](https://github.com/foundation-model-stack/fms-model-optimizer/tree/main/examples/FP8_QUANT#quickstart).
243
+
244
+
245
+ ## Llama.cpp
246
+ There is preliminary work to enable running Bamba architecture models using [llama.cpp](https://github.com/ggerganov/llama.cpp). This is work-in-progress, so should only be used as a guide for the adventurous!
247
+
248
+ ### Known Limitations
249
+
250
+ * Currently, inference is only supported on CPUs
251
+ * Models quantized with `llama-quantize` exhibit bad performance
252
+
253
+ ### Setup
254
+ To enable Bamba support, you'll need to build from source using [Gabe's fork](https://github.com/gabe-l-hart/llama.cpp/tree/BambaArchitecture).
255
+
256
+ ```sh
257
+ git clone --branch BambaArchitecture [email protected]:gabe-l-hart/llama.cpp.git
258
+ cd llama.cpp
259
+ mkdir build
260
+ cd build
261
+ # NOTE: To build with debug symbols and extra logging, use CMAKE_BUILD_TYPE=Debug
262
+ cmake .. -DCMAKE_BUILD_TYPE=Release
263
+ make -j
264
+ ```
265
+
266
+ ### Conversion to GGUF
267
+ You can use a pre-converted GGUF file from Huggingface (e.g. [bamba-9b.gguf](https://huggingface.co/ibm-fms/Bamba-9B/blob/main/bamba-9b.gguf)). If one doesn't exist, you can use the [convert_hf_to_gguf.py](https://github.com/gabe-l-hart/llama.cpp/blob/BambaArchitecture/convert_hf_to_gguf.py) script from Gabe's fork to perform the conversion manually.
268
+
269
+ ```sh
270
+ # Install the python dependencies
271
+ cd /path/to/llama.cpp
272
+ pip install -r requirements/requirements-convert_hf_to_gguf.txt
273
+
274
+ # Perform the conversion
275
+ ./convert_hf_to_gguf.py /path/to/bamba-model --outfile /path/to/bamba-model/bamba-model.gguf
276
+ ```
277
+
278
+ ### Run with llama-cli
279
+
280
+ ```sh
281
+ # Run the model with no layers on the GPU (CPU-only)
282
+ cd /path/to/llama.cpp
283
+ ./bin/llama-cli -ngl 0 -m /path/to/bamba-model/bamba-model.gguf -p "Tell me a story about a developer and their dog"
284
+ ```
285
+
286
+ ### Quantization with llama-quantize
287
+ You can (optionally) quantize the GGUF model using `llama.cpp`'s built in quantizaiton tool `llama-quantize`.
288
+
289
+ ```sh
290
+ # Run the quantization (see llama-quantize --help for all quant types)
291
+ cd /path/to/llama.cpp
292
+ ./build/bin/llama-quantize /path/to/bamba-model/bamba-model.gguf Q4_K_M
293
+ ```
294
+
295
+ ## Contributors
296
+
297
+ * **Data collection and curation**: We acknowledge and thank AllenAI team for making a high quality open source dataset Dolma as well as Hugging Face data team for making FineWeb-edu and Cosmopedia available. These are tremendous contributions and enable us to create the model today.
298
+ * **Data preprocessing**: We thank IBM's internal data preprocessing team, specifically Tuan Hoang Trong, Syed Zawad, Jay Gala, and Ryan Gordon for helping tokenize the data at scale. The code for tokenization is available [here](https://github.com/IBM/data-prep-kit).
299
+ * **Model architecture**: The model architecture design was jointly done by Princeton, CMU, IBM, and UIUC and involved the following folks: Tri Dao (Princeton), Albert Gu (CMU), Linsong Chu (IBM), Davis Wertheimer (IBM), Minjia Zhang (UIUC), Mudhakar Srivatsa (IBM), and Raghu Ganti (IBM).
300
+ * **Model training**: Model training was performed primarily by the IBM team using the Mamba2 kernels and layer implementation from Tri Dao and Albert Gu. The following folks from IBM were primarily involved: Linsong Chu, Divya Kumari, Davis Wertheimer, Raghu Ganti, and Dakshi Agrawal.
301
+ * **Model tuning**: Tuning of the model was enabled and verified in [TRL](https://github.com/huggingface/trl) by the IBM team, involving Sukriti Sharma and Anh Uong.
302
+ * **Model inference**: Model inference in `transformers`, `vLLM`, and `llama.cpp` builds on the kernels written by Princeton and CMU. The IBM team is working with the community to enable it in various ecosystems, the team includes Fabian Lim, Antoni viros i Martin, Adnan Hoque, Jamie Yang, Nelson Nimura Gomez, Joshua Rosenkranz, Nick Hill, and Gabe Goodhart.
303
+ * **Quantization**: Quantization is led by the IBM team \- Naigang Wang and Charlie Liu.
304
+ * **Evaluations**: Evaluations are led by a team in IBM with long context evaluations being performed by UIUC, involving the following folks: Yotam Perlitz, Ofir Arviv, Michal Shmueli-Scheuer (IBM), Haoechen Shen, and Minjia Zhang (UIUC).
305
+
306
+ Finally, we would like to thank our leadership for their support in this effort \- Priya Nagpurkar, David Cox, Sriram Raghavan, Aya Soffer, and Mukesh Khare.
307
+
308
+ We would also like to thank the community, in particular Pablo Montalvo-Leroux and Vaibhav Srivastav from Hugging Face who provided valuable feedback to this blog and the PRs into transformers. Further, we would like to thank Tyler Michael Smith from Neural Magic, who is shepherding the integration with vLLM.
309
+
310
+ A huge shoutout to Meta PyTorch, AllenAI, and Hugging Face teams for their contributions to the open initative, FSDP allowed us to smoothly train this model and the data from Dolma and Fineweb/Cosmopedia made this model today!