What problem does it solve?
Mamba helps users address the complexity and efficiency issues in long-sequence sequence modeling, offering a more efficient alternative to Transformer models.
Core Features & Use Cases
- State-Space Modeling: Mamba employs state-space models for efficient sequence modeling with O(n) complexity.
- Model Choice: Offers Mamba-1 and Mamba-2 for different use cases and performance needs.
- Inference Speed: Achieves up to 5x faster inference compared to Transformers.
- Memory Efficiency: No KV cache required, suitable for memory-constrained environments.
Quick Start
To start using Mamba, first install the mamba-ssm library:
pip install mamba-ssm
Then, use the Mamba model in your code as follows:
import torch
from mamba_ssm import Mamba
model = Mamba(
d_model=dim, # Model dimension
d_state=16, # SSM state dimension
d_conv=4, # Conv1d kernel size
expand=2 # Expansion factor
).to("cuda")
x = torch.randn(batch, length, dim).to("cuda")
y = model(x)