The H-Net paper uses Mamba-2 layers for every encoder and decoder. Their core is State Space Duality (SSD; Dao and Gu, 2024), a linear recurrence with one scalar decay per head that can be computed by chunks of matrix multiplications. For H heads of size P and state size N, with x (B, L, H, P), dt (B, L, H), A (H,) negative, and B_t, C_t of shape (B, L, N) shared by all heads:
Here each head's state S_t has shape (P, N), and the full state is (B, H, P, N).
segment_decay(a)
a is float (..., T). Return (..., T, T) with entry [l, s] equal to for s <= l (so the diagonal is 1) and 0.0 above the diagonal.ssd_sequential(x, dt, A, B, C)
L. Return (y, final_state), with y (B, L, H, P) and final_state (B, H, P, N).ssd_chunked(x, dt, A, B, C, chunk)
chunk (the last may be shorter). For each chunk, call segment_decay exactly once, on the per-head decays a = A * dt for that chunk. Compute the chunk's outputs with no Python loop over time positions, and carry the state from one chunk to the next.class SSDMixer(nn.Module)
__init__(self, d_model, d_state, head_dim, expand=2, chunk=16): d_inner = expand * d_model must divide by head_dim, and H = d_inner // head_dim. Create self.in_proj = nn.Linear(d_model, 2 * d_inner + 2 * d_state + H, bias=False), self.out_proj = nn.Linear(d_inner, d_model, bias=False), and parameters self.A_log (H zeros), self.dt_bias (H zeros), self.D (H ones).forward(self, u): u is (B, L, d_model). Split in_proj(u) in the order z, x, B, C, dt. Set dt = softplus(dt + dt_bias) and A = -exp(A_log). Run ssd_chunked on x reshaped to (B, L, H, head_dim). Add the skip term x * D per head, flatten back, multiply by silu(z), and apply out_proj. Return (B, L, d_model). The full Mamba-2 block also has a causal convolution and a gated norm, left out here.