6.1.11 · HinglishScaling & Efficient Architectures

State-space models (Mamba, S4)

2,720 words12 min readRead in English

6.1.11 · AI-ML › Scaling & Efficient Architectures

The State-Space Foundation

CONTINUOUS KYUN? Bhalein hum discrete tokens process karte hain, continuous formulation hamein control theory aur signal processing ke powerful tools deta hai. Hum ise carefully discretize karenge.

From Continuous to Discrete: The Key Step

Neural networks ke liye jo discrete sequences process karti hain, hume continuous dynamics ko discretize karna hoga. Zero-order hold assumption ka use karke (input timesteps ke beech constant hota hai), exact solution hai:

YE SPECIFIC DISCRETIZATION KYUN? Matrix exponential constant input ke liye ODE ka exact solution hai. Simple methods use karne se (jaise Euler) lambi sequences par errors accumulate ho jaati hain.

KAISE COMPUTE KARO? General matrices ke liye ye costly hai, lekin S4 structured matrices use karta hai (agla section) jahan ye efficient ho jaata hai.

S4: Structured State Spaces

Original SSM approach ek wall se takra gayi: state dimension bada (thousands) hona chahiye taaki sufficient memory capacity ho, lekin isse matrix huge aur expensive ho jaati hai.

The Convolution View

Yahan ek crucial dual perspective hai: SSM ko ya to dekha ja sakta hai:

  1. Recurrent: (generation ke liye)
  2. Convolutional: (training ke liye)

SSM convolution kernel hai:

CONVOLUTIONAL VIEW KYUN? Convolutions FFT use karke mein compute ho sakti hain, aur ye sequence ke across perfectly parallelize hoti hain (recurrent form ke unlike). Training convolution use karti hai, inference recurrence use karta hai.

DPLR STRUCTURE KAISE HELP KARTA HAI? Diagonal-plus-low-rank ke saath, powers aur kernel Cauchy kernel trick aur FFT ka use karke efficiently compute ho sakte hain. Details mein complex analysis hai, lekin result hai computation per layer.

Mamba: Selective State Spaces

S4 ek breakthrough tha lekin iska ek key limitation tha: matrices input-independent hain. Har token par same filter apply hota hai.

SELECTIVE KYUN? Socho ek document process kar rahe ho: model shayad pehle sentence mein mention kiya gaya naam poori sequence ke liye yaad rakhna chahta hai, lekin filler words ko turant bhoolna chahta hai. Fixed SSMs ye choice nahi kar sakte—Mamba kar sakta hai.

YE EFFICIENTLY KAISE COMPUTE HOTA HAI? Ye convolution view tod deta hai (kernel ab input-dependent hai), isliye FFT use nahi kar sakte. Mamba specialized hardware-aware kernels use karta hai jo recurrent computation ko careful memory management ke saath fuse karte hain, aur FFT-based S4 se comparable speed achieve karte hain bawajood recurrent hone ke.

The Mamba Architecture Block

Ek full Mamba block selective SSM ko gating aur projections ke saath combine karta hai:

Training vs Inference Modes

Connections to Other Models

  • Transformers: SSMs attention ka ek alternative hain, flexibility ko efficiency ke saath trade-off karte hain
  • RNNs and LSTMs: SSMs "spiritual successor" hain better long-term memory aur parallelization ke saath
  • Convolutional Neural Networks: Convolution view SSMs ko time-series convolutions se link karta hai
  • Linear Attention: Kuch linear attention variants mathematically kuch SSM configurations ke equivalent hain
  • Mixture of Experts: Mamba ko MoE ke saath combine karke aur greater efficiency hasil ki ja sakti hai
Recall Ek 12-saal ke bacche ko explain karo

Socho tum ek lamba gaana sun rahe ho aur use yaad karne ki koshish kar rahe ho. Tumhara dimaag har ek awaaz ko equally yaad nahi karta—kuch parts (chorus, melody) tum zyada yaad rakhte ho, jabki kuch parts (ek dheemi drum beat) tum jaldi bhool jaate ho.

Ek Transformer mein tumhare dimaag ki tarah hota hai jaise ek bade kaagaz par har ek awaaz likh do aur baar baar poora kaagaz dekho. Agar gaana bahut lamba hai (jaise 100,000 notes!), to tumhara kaagaz dev ho jaata hai aur sab check karne mein bahut time lagta hai.

Ek State-Space Model (SSM) ek choti notebook ki tarah hai jahan tum summary notes rakhte ho. Jab tum koi nayi awaaz suno, to tum apni notebook ko purane notes aur nayi awaaz ke basis par update karte ho. Teri notebook choti rehti hai chahe gaana kitna bhi lamba ho!

S4 ne notebook ko super organized (structured) banaya taaki tum use bahut tezi se dekh sako. Mamba ne ise aur bhi smarter banaya: jab koi important awaaz aaye (jaise singer kahe "I love you"), notebook kehti hai "Ise pen mein likho!" taaki ye wahan lamba rahe. Jab boring awaazein aayein, ye kehti hai "Pencil mein likho" taaki ye jaldi fade ho jaayein.

Isliye SSMs bahut bahut lambi sequences handle kar sakte hain (jaise poori Harry Potter book ek saath padho!) jabki Transformers beech mein hi thak jaate.


Flashcards

#flashcards/ai-ml

Ek continuous state-space model define karne wale do key equations kya hain? :: (state evolution) aur (observation)

Sequence length ke liye SSMs ki time complexity Transformers se kaise compare hoti hai?
SSMs ya hain, jabki Transformers hain attention matrix ki wajah se
Neural networks ke liye ek continuous SSM ko hum kaise discretize karte hain?
aur define karo, phir recurrence use karo
S4 matrix par kya structural constraint lagata hai?
S4 diagonal-plus-low-rank (DPLR) structure use karta hai: , jo FFT ke zariye efficient computation enable karta hai
Ek SSM ke do computational views kya hain?
Recurrent view (inference ke liye): , aur Convolutional view (training ke liye):
SSM convolution kernel kya hai?
—system ka impulse response
S4 par Mamba ka key innovation kya hai?
Mamba SSM parameters ko input-dependent (selective) banata hai: input token par depend karte hain, jisse model choose kar sakta hai kya yaad rakhna hai
Mamba ka selectivity mechanism kaise kaam karta hai?
Timestep parameter ek learned linear layer ke zariye per-token compute hota hai; bada slow decay deta hai (long memory), chota fast decay deta hai (quick forgetting)
Mamba S4 ka FFT-based convolution trick kyun use nahi kar sakta?
Kyunki kernel ab input-dependent hai (har sequence ke liye alag), jo FFT convolution ke liye zaroori time-invariance tod deta hai
SSM inference vs Transformer inference mein per-token computational cost kya hai?
SSMs: (sirf fixed-size state update karo). Transformers: (saare previous tokens attend karo)
Kaun si initialization strategy SSMs ko long-term memory maintain karne mein help karti hai?
HiPPO initialization, jo ke eigenvalues ko specific values par set karta hai jo stable memory channels banate hain
Kis sequence length par SSMs typically Transformers se faster ho jaate hain?
Hardware aur implementation details ke hisaab se around 4K-8K tokens par; <2K tokens ke liye, optimized Transformers (FlashAttention) aksar faster hote hain

Concept Map

motivates

achieves

enables

models as

state evolves via

needs

uses

gives exact

yields

large N is costly

makes efficient

extended by

Transformers O n squared

State-Space Models

Linear Time O n

Very Long Sequences 100K+

Continuous Dynamical System

h prime = A h + B x

Discretization

Zero-Order Hold

Matrix Exponential e^ A delta

Discrete Recurrence h_k = A_bar h + B_bar x

S4 Structured Matrices

Mamba Selective SSM