---
license: apache-2.0
---
## Model Details
# Model Card for Bamba 9B
We introduce Bamba-9B, 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 200 billion tokens, leveraging a carefully curated blend of high-quality data to further refine its performance and enhance output quality.
| Model | Params | # Layers | Hidden Dim. | Attention Heads | GQA | KV Heads | Context Length | Tied Embeddings |
|-------------------|--------------|----------|-------------|-----------------|-----|----------|----------------|------------------|
| Bamba | 9B (9.78B) | 32 | 4096 | 32 | Yes | 8 | 4096 | False |
The current release includes the following models:
| **Stage** | **Bamba 9B** | **Quantized** | **Note** |
|----------------------|----------------------------------------------------------------------|-------------------------------------------------------------------------|-------------------------------------------------------------------|
| **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 |
| **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 |
| **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 |
| **SFT** | coming soon | coming soon | to be released in the next drop |
| **DPO** | coming soon | coming soon | to be released in the next drop |
## Installation
Besides [PyTorch](https://pytorch.org/), you would need a few [extra dependencies](https://github.com/state-spaces/mamba?tab=readme-ov-file#installation) for
Mamba models.
We found some of these dependencies picky on PyTorch versions when doing pip install, so
the best way is to build from source for all Mamba dependencies if you hit dependency
issue with your env:
```bash
git clone https://github.com/Dao-AILab/causal-conv1d.git
cd causal-conv1d && pip install . && cd ..
git clone https://github.com/state-spaces/mamba.git
cd mamba && pip install . && cd ..
git clone https://github.com/Dao-AILab/flash-attention.git
cd flash-attention && pip install . && cd ..
```
## Inference
You can utilize our newly contributed HF integration to run inference on our Bamba models:
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("ibm-fms/Bamba-9B")
tokenizer = AutoTokenizer.from_pretrained("ibm-fms/Bamba-9B")
message = ["Mamba is a snake with following properties "]
inputs = tokenizer(message, return_tensors='pt', return_token_type_ids=False)
response = model.generate(**inputs, max_new_tokens=64)
print(tokenizer.batch_decode(response, skip_special_tokens=True)[0])
```
## Training
We trained our Bamba model with FSDP using our training repo [here](https://github.com/foundation-model-stack/fms-fsdp/tree/mamba-new).
Note that this training effort was started before FSDP2 and also long before we contributed
`Mamba2-Hybrid` to HF, so we were doing FSDP1 training with [official Mamba implementation](https://github.com/state-spaces/mamba).
For users trying to reproduce the training you now have much more options with our newly
contributed [HF-version of Mamba2-Hybrid]() (TODO: add link once live).
## Benchmark scores
### Base pretrained models
| Category | Benchmark | Setting | Metric | Bamba 9B (2.2T) |
| General | MMLU | 5-shot | Accuracy | 60.77 |
| ARC-C | 25-shot | Accuracy normalized | 63.23 | |
| GSM8K | 5-shot | exact match | 36.77 | |
| Hellaswag | 10-shot | Accuracy normalized | 81.8 | |
| OpenbookQA | 5-shot | Accuracy normalized | 47.6 | |
| Piqa | 5-shot | Accuracy normalized | 82.26 | |
| TruthfulQA | 0-shot | Accuracy | 49.21 | |
| Winogrande | 5-shot | Accuracy | 76.87 | |
| HF LLM- V2 | MMLU-PRO | 5-shot | Accuracy | 17.53 |
| BBH | 3-shot | Accuracy normalized | 17.4 | |
| GPQA | 0-shot | Accuracy normalized | 4.14 | |
| IFEval | 0-shot | inst_level_strict_acc + prompt_level_strict_acc | 15.16 | |
| MATH Lvl 5 | 4-shot | Exact match | 1.66 | |
| MuSR | 0-shot | Accuracy normalized | 9.59 | |
| Safety Tasks | PopQA | 5-shot, generation | Accuracy | 20.5 |
| Toxigen | 5-shot, logits | Accuracy | 57.4 | |
| BBQ | 5-shot, generation | Accuracy | 44.2 | |
| Crows-pairs_english | 5-shot, generation | pct_stereotype (lower is better) | 70.78 |