Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
orchestra-research avatar

Mamba Architecture

  • 395 installs
  • 11.2k repo stars
  • Updated June 16, 2026
  • orchestra-research/ai-research-skills

mamba-architecture is an AI research skill that explains Mamba selective SSM (S6) input-dependent state updates and O(n) sequence modeling for developers implementing or evaluating linear-time alternatives to transformer

About

mamba-architecture is a model-architecture skill from Orchestra-Research/AI-Research-SKILLs (253 lines plus 3 reference files) that teaches Mamba's Selective SSM (S6) layer mechanics. Unlike fixed-matrix SSMs, Mamba makes state-space parameters input-dependent via Linear_B, Linear_C, and Linear_Δ projections, enabling selective state updates with O(n) complexity reportedly 5× faster than Transformers on long sequences. The skill documents discretization, selective state updates, and configuration choices before implementing linear-time sequence models. It is one of 5 skills in the Model Architecture category within a library of 86 production-ready research skills across 22 categories. Developers reach for mamba-architecture when choosing between Mamba, RWKV, or transformer backbones or implementing S6 layers in PyTorch training code.

  • Contrasts fixed-matrix SSMs vs Mamba input-dependent B, C, and Δ (S6) selection
  • Explains O(n) recurrent updates vs O(n²) attention with constant state dimension
  • Documents typical d_model, d_state=16, and d_conv configuration knobs
  • Covers content-based remember/forget behavior for long sequences
  • Includes Python-oriented Mamba API setup references from mamba_ssm

Mamba Architecture by the numbers

  • 395 all-time installs (skills.sh)
  • +36 installs in the week ending Jul 18, 2026 (Skillselion tracking)
  • Ranked #510 of 2,066 Data Science & ML skills by installs in the Skillselion catalog
  • Security screen: MEDIUM risk (skills.sh audit)
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
npx skills add https://github.com/orchestra-research/ai-research-skills --skill mamba-architecture

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs395
repo stars11.2k
Security audit2 / 3 scanners passed
Last updatedJune 16, 2026
Repositoryorchestra-research/ai-research-skills

How does Mamba selective SSM architecture work?

Understand Mamba selective SSM (S6) mechanics and configs before choosing or implementing linear-time sequence models.

Who is it for?

ML engineers and researchers implementing or evaluating Mamba state-space models as transformer alternatives for long-sequence workloads.

Skip if: Developers who only need standard transformer fine-tuning without state-space model architecture decisions.

When should I use this skill?

User asks about Mamba architecture, selective SSM, S6 layers, or linear-time sequence models versus transformers.

What you get

S6 layer implementation guidance, discretization formulas, and architecture comparison notes for linear-time sequence models.

  • Architecture implementation notes
  • S6 layer design guidance

By the numbers

  • 253 lines plus 3 reference files in Orchestra-Research library
  • O(n) complexity with 5× faster than Transformers per skill documentation
  • One of 5 skills in Model Architecture category across 86 total skills

Files

SKILL.mdMarkdownGitHub ↗

Mamba - Selective State Space Models

Quick start

Mamba is a state-space model architecture achieving O(n) linear complexity for sequence modeling.

Installation:

# Install causal-conv1d (optional, for efficiency)
pip install causal-conv1d>=1.4.0

# Install Mamba
pip install mamba-ssm
# Or both together
pip install mamba-ssm[causal-conv1d]

Prerequisites: Linux, NVIDIA GPU, PyTorch 1.12+, CUDA 11.6+

Basic usage (Mamba block):

import torch
from mamba_ssm import Mamba

batch, length, dim = 2, 64, 16
x = torch.randn(batch, length, dim).to("cuda")

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")

y = model(x)  # O(n) complexity!
assert y.shape == x.shape

Common workflows

Workflow 1: Language model with Mamba-2

Complete LM with generation:

from mamba_ssm.models.mixer_seq_simple import MambaLMHeadModel
from mamba_ssm.models.config_mamba import MambaConfig
import torch

# Configure Mamba-2 LM
config = MambaConfig(
    d_model=1024,           # Hidden dimension
    n_layer=24,             # Number of layers
    vocab_size=50277,       # Vocabulary size
    ssm_cfg=dict(
        layer="Mamba2",     # Use Mamba-2
        d_state=128,        # Larger state for Mamba-2
        headdim=64,         # Head dimension
        ngroups=1           # Number of groups
    )
)

model = MambaLMHeadModel(config, device="cuda", dtype=torch.float16)

# Generate text
input_ids = torch.randint(0, 1000, (1, 20), device="cuda", dtype=torch.long)
output = model.generate(
    input_ids=input_ids,
    max_length=100,
    temperature=0.7,
    top_p=0.9
)

Workflow 2: Use pretrained Mamba models

Load from HuggingFace:

from transformers import AutoTokenizer
from mamba_ssm.models.mixer_seq_simple import MambaLMHeadModel

# Load pretrained model
model_name = "state-spaces/mamba-2.8b"
tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")  # Use compatible tokenizer
model = MambaLMHeadModel.from_pretrained(model_name, device="cuda", dtype=torch.float16)

# Generate
prompt = "The future of AI is"
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to("cuda")
output_ids = model.generate(
    input_ids=input_ids,
    max_length=200,
    temperature=0.7,
    top_p=0.9,
    repetition_penalty=1.2
)
generated_text = tokenizer.decode(output_ids[0])
print(generated_text)

Available models:

  • state-spaces/mamba-130m
  • state-spaces/mamba-370m
  • state-spaces/mamba-790m
  • state-spaces/mamba-1.4b
  • state-spaces/mamba-2.8b

Workflow 3: Mamba-1 vs Mamba-2

Mamba-1 (smaller state):

from mamba_ssm import Mamba

model = Mamba(
    d_model=256,
    d_state=16,      # Smaller state dimension
    d_conv=4,
    expand=2
).to("cuda")

Mamba-2 (multi-head, larger state):

from mamba_ssm import Mamba2

model = Mamba2(
    d_model=256,
    d_state=128,     # Larger state dimension
    d_conv=4,
    expand=2,
    headdim=64,      # Head dimension for multi-head
    ngroups=1        # Parallel groups
).to("cuda")

Key differences:

  • State size: Mamba-1 (d_state=16) vs Mamba-2 (d_state=128)
  • Architecture: Mamba-2 has multi-head structure
  • Normalization: Mamba-2 uses RMSNorm
  • Distributed: Mamba-2 supports tensor parallelism

Workflow 4: Benchmark vs Transformers

Generation speed comparison:

# Benchmark Mamba
python benchmarks/benchmark_generation_mamba_simple.py \
  --model-name "state-spaces/mamba-2.8b" \
  --prompt "The future of machine learning is" \
  --topp 0.9 --temperature 0.7 --repetition-penalty 1.2

# Benchmark Transformer
python benchmarks/benchmark_generation_mamba_simple.py \
  --model-name "EleutherAI/pythia-2.8b" \
  --prompt "The future of machine learning is" \
  --topp 0.9 --temperature 0.7 --repetition-penalty 1.2

Expected results:

  • Mamba: 5× faster inference
  • Memory: No KV cache needed
  • Scaling: Linear with sequence length

When to use vs alternatives

Use Mamba when:

  • Need long sequences (100K+ tokens)
  • Want faster inference than Transformers
  • Memory-constrained (no KV cache)
  • Building streaming applications
  • Linear scaling important

Advantages:

  • O(n) complexity: Linear vs quadratic
  • 5× faster inference: No attention overhead
  • No KV cache: Lower memory usage
  • Million-token sequences: Hardware-efficient
  • Streaming: Constant memory per token

Use alternatives instead:

  • Transformers: Need best-in-class performance, have compute
  • RWKV: Want RNN+Transformer hybrid
  • RetNet: Need retention-based architecture
  • Hyena: Want convolution-based approach

Common issues

Issue: CUDA out of memory

Reduce batch size or use gradient checkpointing:

model = MambaLMHeadModel(config, device="cuda", dtype=torch.float16)
model.gradient_checkpointing_enable()  # Enable checkpointing

Issue: Slow installation

Install binary wheels (not source):

pip install mamba-ssm --no-build-isolation

Issue: Missing causal-conv1d

Install separately:

pip install causal-conv1d>=1.4.0

Issue: Model not loading from HuggingFace

Use MambaLMHeadModel.from_pretrained (not AutoModel):

from mamba_ssm.models.mixer_seq_simple import MambaLMHeadModel
model = MambaLMHeadModel.from_pretrained("state-spaces/mamba-2.8b")

Advanced topics

Selective SSM: See references/selective-ssm.md for mathematical formulation, state-space equations, and how selectivity enables O(n) complexity.

Mamba-2 architecture: See references/mamba2-details.md for multi-head structure, tensor parallelism, and distributed training setup.

Performance optimization: See references/performance.md for hardware-aware design, CUDA kernels, and memory efficiency techniques.

Hardware requirements

  • GPU: NVIDIA with CUDA 11.6+
  • VRAM:
  • 130M model: 2GB
  • 370M model: 4GB
  • 790M model: 8GB
  • 1.4B model: 14GB
  • 2.8B model: 28GB (FP16)
  • Inference: 5× faster than Transformers
  • Memory: No KV cache (lower than Transformers)

Performance (vs Transformers):

  • Speed: 5× faster inference
  • Memory: 50% less (no KV cache)
  • Scaling: Linear vs quadratic

Resources

  • Paper (Mamba-1): https://arxiv.org/abs/2312.00752 (Dec 2023)
  • Paper (Mamba-2): https://arxiv.org/abs/2405.21060 (May 2024)
  • GitHub: https://github.com/state-spaces/mamba ⭐ 13,000+
  • Models: https://huggingface.co/state-spaces
  • Docs: Repository README and wiki

Related skills

How it compares

Pick mamba-architecture for selective SSM linear-time models; use rwkv-architecture from the same repo for WKV recurrence-based RNN-transformer hybrids.

FAQ

What makes Mamba's SSM selective?

Mamba's Selective SSM (S6) makes state-space parameters input-dependent: B(t), C(t), and delta(t) are projected from each input x(t), unlike fixed-matrix SSMs where A, B, C stay constant.

How large is the mamba-architecture skill?

mamba-architecture ships as 253 lines plus 3 reference files in Orchestra-Research/AI-Research-SKILLs Model Architecture category, one of 5 architecture skills in the 86-skill library.

Is Mamba Architecture safe to install?

skills.sh reports 2 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.