mamba-architecture

Implement and train Mamba selective state-space models with linear-complexity sequence modeling.

13.0k|930|Updated Nov 3, 2025
One-click install
npx skills add https://github.com/Orchestra-Research/AI-research-SKILLs --skill mamba-architecture-orchestra-research
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mamba-architecture
Source: https://github.com/Orchestra-Research/AI-research-SKILLs/tree/main/01-model-architecture/mamba
Command: npx skills add https://github.com/Orchestra-Research/AI-research-SKILLs --skill mamba-architecture-orchestra-research

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires mamba-ssm, torch, transformers, causal-conv1d, and includes references (resource) components.

What problem does it solve? Transformer attention scales quadratically with sequence length, causing high memory usage from KV caches and slow inference on long contexts. This Skill provides guidance for building, training, and deploying Mamba state-space models that achieve O(n) linear complexity with no KV cache. ## Core Features & Use Cases - Mamba Block Implementation: Configure Mamba and Mamba-2 layers with d_model, d_state, d_conv, and expand parameters using the mamba-ssm library. - Pretrained Model Usage: Load HuggingFace models from state-spaces/mamba-130m up to mamba-2.8b and generate text with temperature and top-p sampling. - Training & Benchmarking: Distributed training with DDP, mixed precision, gradient checkpointing, and generation speed benchmarks against Transformers. - Use Case: You need to process million-token DNA sequences or long documents where a Transformer runs out of memory. Use this Skill to configure a Mamba-2 language model that scales linearly and runs inference 5× faster. ## Quick Start Use the mamba skill to build a Mamba-2 language model with 24 layers and generate text from a prompt on my CUDA GPU.

Frequently Asked Questions about mamba-architecture

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use pretrained Mamba models from HuggingFace?▼

Load pretrained Mamba models with MambaLMHeadModel.from_pretrained using model names like state-spaces/mamba-2.8b, paired with the EleutherAI/gpt-neox-20b tokenizer. Available sizes range from 130M to 2.8B parameters, and generation uses standard temperature and top-p sampling.

What is the difference between Mamba-1 and Mamba-2?▼

Mamba-1 uses d_state=16 with a single-head structure, while Mamba-2 uses d_state=128 with multi-head structure, RMSNorm, and tensor parallelism support. Mamba-2 offers larger state capacity and better distributed training options.

Does Mamba require a GPU to run?▼

Yes, Mamba requires Linux with an NVIDIA GPU, PyTorch 1.12+, and CUDA 11.6 or higher. The mamba-ssm library relies on custom CUDA kernels for its hardware-aware parallel scan implementation.

Why does Mamba installation fail or run slowly?▼

Slow installs usually come from building from source; use pip install mamba-ssm --no-build-isolation for binary wheels. If causal-conv1d is missing, install it separately with pip install causal-conv1d>=1.4.0.

When should I use Mamba instead of a Transformer?▼

Use Mamba for sequences over 100K tokens, memory-constrained inference without KV cache, or streaming applications needing constant per-token memory. Choose Transformers when you need best-in-class task performance and have sufficient compute.

How do I fix CUDA out of memory errors when training Mamba?▼

Reduce per-GPU batch size, enable gradient checkpointing on the model, or shorten the sequence length. Mamba memory grows linearly with sequence length, so these adjustments scale predictably.