A GPU cannot hold a long sequence in on-chip memory, so Mamba's kernel scans the sequence chunk by chunk and carries the state across chunk boundaries. Mamba-2 builds its whole algorithm on the same decomposition. Implement it for and make it equal the full scan.
chunked_linear_scan(a, b, T, h0=None)
a and b have the same shape (L, ...); the recurrence runs along axis 0, elementwise over trailing axes. T >= 1 is the chunk size: chunk covers positions to , so the last chunk may be shorter and there are chunks. h0 is the state before position 0 (shape a.shape[1:], default zeros).(h, states): h of shape (L, ...) and states of shape (n_chunks, ...) with states[j] (so states[0] is h0, and states[j] is the true state at position for ). The result must equal the sequential scan for every T. Do not modify the inputs.T, so all chunks can be scanned at once with one loop over the T positions.np.cumprod along the within-chunk axis gives every .L.