mamba-architecture

Implements and benchmarks Mamba state-space models for linear-complexity sequence modeling.

Updated Mar 23, 2026
One-click install
npx skills add https://github.com/hanasho744/codex --skill mamba-architecture-hanasho744
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mamba-architecture
Source: https://github.com/hanasho744/codex/tree/main/.agents/skills/mamba
Command: npx skills add https://github.com/hanasho744/codex --skill mamba-architecture-hanasho744

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Transformer models suffer from O(n²) attention complexity and growing KV cache memory, making long-sequence inference slow and expensive. This Skill provides working code and guidance for Mamba, a selective state-space architecture with O(n) linear complexity, no KV cache, and up to 5× faster inference. ## Core Features & Use Cases - Mamba Block & LM Construction: Build Mamba-1 and Mamba-2 blocks or full language models with MambaLMHeadModel, configuring d_state, d_conv, expand, and multi-head parameters. - Pretrained Model Inference: Load HuggingFace checkpoints (130M to 2.8B parameters) and generate text with temperature, top-p, and repetition penalty controls. - Benchmarking & Training: Compare generation speed against Transformers, train from scratch with DDP, mixed precision, and gradient checkpointing. - Use Case: You need to serve a language model over 100K-token genomic sequences on limited GPU memory. Use this Skill to configure a Mamba-2 model that processes the sequence with constant memory per token instead of an exploding KV cache. ## Quick Start Install mamba-ssm with pip and ask the AI to create a Mamba language model that loads the state-spaces/mamba-2.8b checkpoint and generates text from a prompt.

Frequently Asked Questions about mamba-architecture

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

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

Load pretrained Mamba models with MambaLMHeadModel.from_pretrained, passing a checkpoint like state-spaces/mamba-2.8b, then call model.generate with input_ids, temperature, and top_p. Use the EleutherAI/gpt-neox-20b tokenizer, since AutoModel does not support Mamba checkpoints.

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

Mamba-1 uses a state dimension of 16, while Mamba-2 uses d_state=128 with a multi-head structure, RMSNorm normalization, and tensor parallelism support. Mamba-2 is configured through the Mamba2 class with headdim and ngroups parameters.

Mamba vs Transformer: when should I use each?▼

Use Mamba for sequences over 100K tokens, streaming applications, or memory-constrained inference, since it has O(n) complexity and no KV cache. Use Transformers when you need best-in-class task performance and have sufficient compute.

What hardware do I need to run Mamba models?▼

Mamba requires Linux, an NVIDIA GPU with CUDA 11.6+, and PyTorch 1.12+. VRAM needs range from 2GB for the 130M model to 28GB for the 2.8B model in FP16.

Why does Mamba installation fail or run slowly?▼

Installation issues usually come from building from source; install binary wheels with pip install mamba-ssm --no-build-isolation. Also install causal-conv1d>=1.4.0 separately, since missing kernels cause slow fallback execution.

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

Reduce the per-GPU batch size, shorten the sequence length, or enable gradient checkpointing with model.gradient_checkpointing_enable(). Gradient checkpointing saves roughly 30-40% memory with minimal speed impact.