In packed mode, the chunks of all documents are laid end to end. The smoothing EMA must restart at each document: a chunk must never blend with the last chunk of the previous document. Implement it without branching on document boundaries inside the recursion.
packed_probs(P, cu_seqlens)
P float (T,), cu_seqlens long (K+1,) with cu_seqlens[0] == 0 and cu_seqlens[K] == T. Document i occupies [cu_seqlens[i], cu_seqlens[i+1]).P except that it is exactly 1.0 at each document's first position. Do not modify P. Gradients must still flow to the other entries.packed_ema(z, P, cu_seqlens, block=64)
z float (T, D). Return zbar (T, D), equal to running separately on each document, from a zero start.packed_probs first: since , setting P to one at a document start wipes the previous state with no branch.T in blocks of length block (the last may be shorter). Inside a block, compute the outputs with lower-triangular matrix weights and no Python loop over time positions; between blocks, carry one state vector. Result must not depend on block. Gradients must flow to z and P.