惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
V
V2EX
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
罗磊的独立博客
H
Help Net Security
月光博客
月光博客
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
GbyAI
GbyAI
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Mamba/SSM Basics
Sirajuddin Shaik · 2026-05-31 · via DEV Community

Sirajuddin Shaik

State Space Models offer linear-time sequence modeling with content-aware selective filtering, challenging Transformers for long-context inference.

Why This Matters

State Space Models (SSMs) provide a principled alternative to Transformers for long-sequence modeling. In production systems handling long contexts (e.g., code generation, genomic analysis), Transformer attention's quadratic cost becomes a bottleneck. Mamba achieves linear-time inference with constant-memory state, making it viable for million-token contexts where attention-based models are prohibitively expensive.

Core Idea

SSMs originate from continuous-time control theory: a latent state evolves over time driven by input, and observations are linear projections of that state. Mamba's key innovation is making the SSM parameters input-selective — the model learns to gate which information enters and exits the state, mimicking attention's ability to focus on relevant tokens without the O(n2)O(n^2) cost.

Technical Details

The continuous-time SSM is defined as:

x(t)=Ax(t)+Bu(t),y(t)=Cx(t)+Du(t) x'(t) = Ax(t) + Bu(t), \quad y(t) = Cx(t) + Du(t)

where x(t)RNx(t) \in \mathbb{R}^N is latent state, u(t)u(t) is input, and ARN×NA \in \mathbb{R}^{N \times N} , BRN×1B \in \mathbb{R}^{N \times 1} , CR1×NC \in \mathbb{R}^{1 \times N} . Using zero-order hold discretization with step Δ\Delta :

Aˉ=exp(ΔA),Bˉ=(ΔA)1(exp(ΔA)I)ΔB \bar{A} = \exp(\Delta A), \quad \bar{B} = (\Delta A)^{-1}(\exp(\Delta A) - I) \cdot \Delta B

The recurrent update becomes:

xk=Aˉxk1+Bˉuk,yk=Cxk x_k = \bar{A}x_{k-1} + \bar{B}u_k, \quad y_k = Cx_k

Mamba's selective mechanism makes BB , CC , and Δ\Delta input-dependent:

Bk=LinearB(xk),Ck=LinearC(xk),Δk=softplus(LinearΔ(xk)) B_k = \text{Linear}B(x_k), \quad C_k = \text{Linear}_C(x_k), \quad \Delta_k = \text{softplus}(\text{Linear}\Delta(x_k))

The parallel scan algorithm computes this recurrence in O(nlogn)O(n \log n) during training. Inference is O(1)O(1) O(1) per token with fixed state size N NN , yielding constant-memory decoding regardless of sequence length.

How It Works

  1. Project input: Map token uku_k to expanded dimension DND \cdot N .
  2. Generate selective parameters: Compute input-dependent BkB_k , CkC_k , Δk\Delta_k from uku_k .
  3. Discretize: Convert continuous (A,B)(A, B) to discrete (Aˉk,Bˉk)(\bar{A}_k, \bar{B}_k) using Δk\Delta_k .
  4. Recurrent scan: Apply parallel scan (training) or sequential update (inference) to compute hidden states xkx_k .
  5. Output projection: Compute yk=Ckxky_k = C_k x_k , then project through gating (SiLU) to output dimension.

Key Insights

  • Selectivity is essential: Non-selective SSMs (S4) cannot do in-context retrieval; making B,C,ΔB, C, \Delta input-dependent enables content-aware filtering.
  • Diagonal + low-rank structure on AA enables O(n)O(n) recurrence; Mamba uses diagonal AA matrices exclusively.
  • Hardware-aware design: The scan kernel is IO-bound, not compute-bound — Mamba's CUDA kernel fuses discretization, scan, and output projection to minimize memory reads.
  • Linear decoding cost: Unlike KV-cache which grows linearly, SSM state is fixed-size O(ND)O(ND) , making generation memory-constant.

Sources