What turns S4 into Mamba's S6 is that the step size and the matrices and are computed from the input. Implement the projections of the reference block, a numerically stable softplus, and the inverse softplus used to initialise the step-size bias.
softplus(z)
softplus(-50) must be about .inv_softplus(y)
y > 0, return the z with softplus(z) == y elementwise, accurate for small y (around 1e-3) and without overflow for large y (such as 800).s6_projections(x, W_x, W_dt, b_dt)
x has shape (B, L, ED). W_x has shape (ED, R + 2N) (no bias), W_dt has shape (R, ED), b_dt has shape (ED,). Infer R from W_dt and N from W_x.R columns are dt, the next N are B, the last N are C.(delta, B, C) with shapes (B, L, ED), (B, L, N), (B, L, N).np.where evaluates both branches, so a thresholded formula still overflows inside the branch it discards.np.expm1 computes without cancellation.