Papers · Architectures and attention · 2023

Mamba: Linear-Time Sequence Modeling with Selective State Spaces

Albert Gu, Tri Dao

The notation of the Mamba paper, explained: its 12 displayed equations, then every symbol it uses, grouped by category and shown the way the paper writes it.

Read the paper on arXiv

Reading this paper

Mamba: a sequence model built on state-space models whose parameters depend on the input, giving a recurrent model that rivals Transformers on language.

The bars do not mean averages: Aˉ\bar{A} and Bˉ\bar{B} are the discretized versions of the continuous parameters AA and BB, computed with the step size Δ\Delta (for example Aˉ=exp⁡(ΔA)\bar{A} = \exp(\Delta A)). hth_t is the hidden state, xtx_t the input and yty_t the output. "Selective" means BB, CC and Δ\Delta are computed from xtx_t rather than fixed.

Read from arXiv's HTML version: 12 displayed equations and 264 pieces of inline math. 36 symbols and constructs from the catalog.

The paper's displayed equations

Open any of them in the decoder for a symbol-by-symbol reading.

  1. (1a)
    h′(t)=Ah(t)+Bx(t)h^{\prime}(t) =\bm{A}h(t)+\bm{B}x(t)
    Decode →
  2. (1b)
    y(t)=Ch(t)y(t) =\bm{C}h(t)
    Decode →
  3. (2a)
    ht=A‾ht−1+B‾xth_{t} =\overline{\bm{A}}h_{t-1}+\overline{\bm{B}}x_{t}
    Decode →
  4. (2b)
    yt=Chty_{t} =\bm{C}h_{t}
    Decode →
  5. (3a)
    K‾=(CB‾,CA‾B‾,…,CA‾kB‾,… )\bm{\overline{K}} =(\bm{C}\bm{\overline{B}},\bm{C}\bm{\overline{A}}\bm{\overline{B}},\dots,\bm{C}\bm{\overline{A}}^{k}\bm{\overline{B}},\dots)
    Decode →
  6. (3b)
    y=x∗K‾y =x\ast\bm{\overline{K}}
    Decode →
  7. (4)
    A‾=exp⁡(ΔA)B‾=(ΔA)−1(exp⁡(ΔA)−I)⋅ΔB\overline{\bm{A}}=\exp(\Delta\bm{A})\qquad\overline{\bm{B}}=(\Delta\bm{A})^{-1}(\exp(\Delta\bm{A})-\bm{I})\cdot\Delta\bm{B}
    Decode →
  8. (5)
    gt=σ(Linear(xt))ht=(1−gt)ht−1+gtxt.\begin{gathered}g_{t} =\sigma(\mathsf{Linear}(x_{t})) \\ h_{t} =(1-g_{t})h_{t-1}+g_{t}x_{t}.\end{gathered}
    Decode →
  9. h(t)=−h(t)+x(t)h(t)=-h(t)+x(t)
    Decode →
  10. Δt=τΔ(Parameter+sΔ(xt))=softplus(Parameter+Linear(xt))=softplus(Linear(xt))\begin{gathered}\Delta_{t} =\tau_{\Delta}(\mathsf{Parameter}+s_{\Delta}(x_{t})) \\ =\mathsf{softplus}(\mathsf{Parameter}+\mathsf{Linear}(x_{t})) \\ =\mathsf{softplus}(\mathsf{Linear}(x_{t}))\end{gathered}
    Decode →
  11. A‾t=exp⁡(ΔA)=11+exp⁡(Linear(xt))=σ(−Linear(xt))=1−σ(Linear(xt))B‾t=(ΔA)−1(exp⁡(ΔA)−I)⋅ΔB=−(exp⁡(ΔA)−I)=1−A‾=σ(Linear(xt)).\begin{gathered}\overline{\bm{A}}_{t} =\exp(\Delta\bm{A})=\frac{1}{1+\exp(\mathsf{Linear}(x_{t}))}=\sigma(-\mathsf{Linear}(x_{t})) \\ =1-\sigma(\mathsf{Linear}(x_{t})) \\ \overline{\bm{B}}_{t} =(\Delta\bm{A})^{-1}(\exp(\Delta\bm{A})-\bm{I})\cdot\Delta\bm{B}=-(\exp(\Delta\bm{A})-\bm{I})=1-\overline{\bm{A}} \\ =\sigma(\mathsf{Linear}(x_{t})).\end{gathered}
    Decode →
  12. gt=σ(Linear(xt))ht=(1−gt)ht−1+gtxt\begin{gathered}g_{t} =\sigma(\mathsf{Linear}(x_{t})) \\ h_{t} =(1-g_{t})h_{t-1}+g_{t}x_{t}\end{gathered}
    Decode →

Famous equations in this paper

Symbols, by category

Most used first. The examples are written as the paper writes them.

Notation conventions

  1. hh, tt, xx

    Italic letters (variables) 296 uses

    A plain italic letter is a variable; conventions say what kind (x input, y target, W weights…).

  2. A‾k\bm{\overline{A}}^{k}, D2D^{2}, 262^{6}

    Superscript (power or label) 95 uses

    Usually a power (x² = x·x), but a capital or a word up there is often just a label (W^Q).

  3. hth_{t}, ht−1h_{t-1}, xtx_{t}

    Subscript (index or label) 81 uses

    A subscript picks an element (xᵢ), a time step (h_t), a named copy (W_q), or the parameters (p_θ).

  4. A‾\overline{\bm{A}}, B‾\overline{\bm{B}}, K‾\overline{K}

    Bar (mean) 47 uses

    A bar usually marks an average: x̄ is the mean of the x values.

  5. …\dots

    Dots (ellipsis) 2 uses

    “And so on”: continue the pattern.

  6. ∗\ast

    Star (optimal) 1 use

    As a superscript, the optimal value: θ* is the best θ. Between two terms, convolution.

Greek letters

  1. Δ\Delta

    Delta (capital) 75 uses

    A change or update: ΔW is the change to the weights W.

  2. τ\tau

    Tau 9 uses

    A temperature that sharpens or flattens a softmax; in RL, a trajectory.

  3. σ\sigma

    Sigma (lowercase) 8 uses

    Either the sigmoid function σ(z) = 1/(1+e⁻ᶻ) or a standard deviation. The context decides.

  4. β\beta

    Beta 5 uses

    Usually a decay rate (Adam’s β₁, β₂), a shift parameter in normalization, or a weight on a loss term.

Vectors and matrices

  1. A\bm{A}, B\bm{B}, C\bm{C}

    Bold uppercase (matrix) 153 uses

    A bold capital letter is a matrix (or a higher-order tensor).

  2. ×\times

    Times (cross) 44 uses

    Usually the “by” in a shape (n × d); also plain multiplication or a cross product.

  3. KK

    Q, K, V (query, key, value) 11 uses

    In attention: queries Q, keys K and values V, each a matrix with one row per token.

  4. (ΔA)−1(\Delta\bm{A})^{-1}, τΔ−1\tau_{\Delta}^{-1}

    Inverse 3 uses

    The matrix inverse, A⁻¹A = I; for a function, its inverse function; for a number, 1/x.

  5. I\bm{I}

    Identity matrix 3 uses

    The matrix with 1s on the diagonal and 0s elsewhere; multiplying by it changes nothing.

  6. ⋅\cdot

    Centre dot 3 uses

    A dot product between vectors, plain multiplication between numbers, or an empty slot f(·).

Calculus and gradients

  1. ∞\infty

    Infinity 2 uses

    Infinity; as a norm subscript, ‖x‖_∞ is the largest absolute entry.

  2. h′h^{\prime}

    Prime 1 use

    Either a derivative, f′(x), or simply "another one": x′ is a second sample, s′ the next state.

Probability and statistics

  1. exp⁡\exp

    Exponential 10 uses

    The exponential function eˣ, with e ≈ 2.718. Always positive.

  2. log⁡\log

    Logarithm 3 uses

    A logarithm, almost always the natural log (base e) in ML papers.

  3. pp

    Probability p(x) 2 uses

    A probability or probability density; p is usually the true or model distribution, q an approximation.

  4. Uniform\mathsf{Uniform}

    Uniform distribution 1 use

    𝒰(a, b) is the uniform distribution: every value between a and b is equally likely.

  5. ∼\sim

    Distributed as (tilde) 1 use

    “Is drawn from” or “is distributed as”: x ~ p means x is a sample from the distribution p.

  6. N\mathcal{N}

    Normal distribution 1 use

    The normal (Gaussian) distribution with the given mean and variance.

Functions and operators

  1. ↦\mapsto, ::, →\to

    Arrow (maps to) 23 uses

    Maps to (f: X → Y), tends to (x → 0), or implies (⇒).

  2. ←\leftarrow

    Assignment arrow 12 uses

    Assignment in an algorithm: replace the variable on the left with the value on the right.

  3. OO

    Big-O notation 11 uses

    How a cost grows with size, ignoring constants: O(n²) means at most proportional to n² for large n.

  4. softplus\mathsf{softplus}

    Softplus 5 uses

    log(1 + eˣ): a smooth ReLU whose output is always positive.

  5. 11+exp⁡(Linear(xt))\frac{1}{1+\exp(\mathsf{Linear}(x_{t}))}, 12\frac{1}{2}, 217L\frac{2^{17}}{L}

    Fraction 3 uses

    Division: the top divided by the bottom.

  6. ∘\circ

    Composition (circle) 1 use

    Function composition: (f ∘ g)(x) = f(g(x)). Some papers use it for elementwise products.

Sets, shapes and definitions

  1. ≈\approx

    Approximately equal 18 uses

    Approximately equal: often a Monte Carlo estimate or a Taylor approximation.

  2. ∈\in

    Element of 6 uses

    “Is in” or “belongs to”: x ∈ S says x is a member of the set S.

  3. >>, <<

    Inequalities 4 uses

    Less than / greater than (or equal). ≪ means “much smaller than”.

  4. RN\mathbb{R}^{N}, RN×N\mathbb{R}^{N\times N}, RN×1\mathbb{R}^{N\times 1}

    Tensor shapes 4 uses

    ℝ with a superscript of sizes joined by × declares an array’s shape: ℝ^{B×T×d} is a 3-axis tensor.

  5. {1e−3,2e−3,4e−3,8e−3}\{1e-3,2e-3,4e-3,8e-3\}, {1e−5,2e−5,4e−5,1e−4,2e−4}\{1e-5,2e-5,4e-5,1e-4,2e-4\}

    Set braces 4 uses

    A set: a collection of items. {x | condition} is every x that satisfies the condition.

  6. R\mathbb{R}

    Real numbers (ℝ) and shapes 2 uses

    The real numbers. ℝⁿˣᵈ is the set of n × d arrays of reals: it states a shape.

23 things the catalog has no entry for yet
  • Linear\mathsf{Linear} Linear 17
  • ↑\uparrow \uparrow 11
  • Parameter\mathsf{Parameter} Parameter 8
  • ↓\downarrow \downarrow 8
  • (B,L,D)\mathtt{(B,L,D)} (B,L,D) 7
  • (D,N)\mathtt{(D,N)} (D,N) 5
  • ▹\triangleright \triangleright 4
  • SSM\mathsf{SSM} SSM 3
  • (B,L,D,N)\mathtt{(B,L,D,N)} (B,L,D,N) 3
  • Broadcast\mathsf{Broadcast} Broadcast 2
  • discretize\mathsf{discretize} discretize 2
  • (B,L,N)\mathtt{(B,L,N)} (B,L,N) 2
  • (D)\mathtt{(D)} (D) 1
  • B,L,D\mathtt{B,L,D} B,L,D 1
  • n_layers\mathtt{n\_layers} n\_layers 1
  • d_model\mathtt{d\_model} d\_model 1
  • n_heads\mathtt{n\_heads} n\_heads 1
  • d_head\mathtt{d\_head} d\_head 1
  • conv\mathsf{conv} conv 1
  • batch_size\mathtt{batch\_size} batch\_size 1
  • sequence_length\mathtt{sequence\_length} sequence\_length 1
  • 4e−5\mathtt{4e-5} 4e-5 1
  • 1e−4\mathtt{1e-4} 1e-4 1

Formulas from arXiv's HTML version of the paper, © their authors; the explanations are this site's. Title and authors as arXiv lists them.

More architectures and attention papers