When the sliding-window state at a cache boundary is missing, the exact way to rebuild it is to run the last window of tokens through the window layers with their full attention history. Bounded replay instead restarts attention at the replay start s and lets each replayed query see only keys at or after s: the cost no longer depends on the context, at the price of an approximation in the first positions. Implement both and measure the gap.
swa_attention(x, Wq, Wk, Wv, window)
x is (T, d_model); Wq, Wk, Wv are (d_model, d_head). Position attends to keys with , scores , softmax over those keys, output the weighted sum of values. Return (T, d_head).bounded_replay(x, Wq, Wk, Wv, window, s)
(T - s, d_head).replay_error(x, Wq, Wk, Wv, window, s)
"max_abs_error", a list over the replayed positions of the largest absolute difference between the bounded and exact outputs (rounded to 6 decimals), and "exact_from", the first replayed position (absolute index) whose bounded window equals its exact window, i.e. s + window - 1.window - 1 after s see exactly the same keys in both computations, so their error must come out as zero.