Expand description
§Physical-frame moments with a custom, memory-efficient backward
The forward is the same serial chunkwise computation as
Mamba3MomentsInput::state_moments_phys,
but routed through the Mamba3MomentsBackendExt trait so Autodiff
backends substitute a custom recompute backward (see
super::backward): the node saves only its five leaf inputs and the tiny
(m2, m1) outputs; backprop re-materialises one chunk of states at a time
— the full per-token state trajectory that plain autodiff would retain is
never kept alive. This is the at-scale execution model.
The default body (every plain backend) runs the identical math on B’s
primitives via the rank-tagged F wrapper. The rotation is passed as a
rank-erased primitive plus a quaternion flag ([b, s, h, a] cumulative
angles, or [b, s, h, J, 4] cumulative unit quaternions), so a single
trait method covers both algebras.
Enums§
- RotPrim 🔒
- The per-token cumulative rotation on
B’s primitives — the rank-tagged counterpart ofRotationSeq.
Traits§
- Mamba3
Moments Backend Ext - Extends the backend with the physical-frame state-moments computation.
Functions§
- chunk_
cos_ 🔒sin - The rotation’s per-pair
cos/sinfor one chunk, expanded overper_head_dim:[b, h, l, p, a]each.transposenegates the angle —falseapplies the de-rotationR(−θ)(cache → physical),trueits transposeR(+θ)(used on cotangents). - chunk_
decay 🔒 - Chunk-local decay:
dₜ = exp(a_cum[t])([b, h, l]) and the 1-semiseparable maskL[t, j] = exp(a_cum[t] − a_cum[j])([b, h, l, l], zero strictly above the diagonal). - chunk_
mask 🔒 - Float validity mask
[1, 1, l, 1, 1]for a chunk starting atstart(1for global positions< valid_len,0for pads). - chunk_
states 🔒 - One chunk of cache-frame states
h̃[t] = dₜ·h₋ + Σ_{j≤t,c} L[t,j]·x̂[j,c] ⊗ b̂[j,c]— the channel axis is folded into the write index for one batched GEMM. - chunk_
writes 🔒 - The per-token write
W_j = Σ_c x̂[j,c] ⊗ b̂[j,c]([b, h, j, p, r]) — used by the backward’sdagradient. - moments_
phys_ 🔒fwd - The serial chunkwise forward on primitives — the exact math of
Mamba3MomentsInput::state_moments_phys. - quat_
conj_ 🔒prim - Quaternion conjugate on the packed trailing axis.
- quat_
mul_ 🔒prim - Quaternion Hamilton product on the packed trailing
(w, x, y, z)axis (primitive port ofrotation::quat_mul). - rotate_
chunk 🔒 - Rotate the
state_rankaxis of one chunk of states by the per-token cumulative rotation.transpose = falseis the de-rotation to the physical frame (R(−θ)/ left-multiply byQ);transpose = trueis its transpose (R(+θ)/ left-multiply byconj(Q)), the map cotangents take back to the cache frame.