For RWKV-7 a composition of document states was proposed
The algebraic rule allows merging cached document states RWKV-7 without rereading their text. At the level of the entire multilayer network the result remains approximate: the inputs of upper layers depend on context.

29 November 2026 year on Habr described an algebraic rule for merging document states in RWKV-7. It allows composing cached processing results of fragments without re-running their text through the model, but for a multilayer network it provides an approximation rather than an exact replacement for a continuous pass.
How composition works
For a single layer document processing is represented as a transition S → S·P + S₀: document transforms the input state S using the transition P and adds the state it created S₀. If pairs are stored for two documents (S₀, P), they can be merged, obtaining a state S_AB = S_A·P_B + S_B and transition P_AB = P_A·P_B. This composition is associative.
Accuracy condition is important: it applies to a single layer with identical inputs. In a real multi‑layer model, the state of the upper layer depends on processing of previous documents. Therefore a separately cached fragment receives at the upper layers an input different from what it would get during sequential reading of the entire context. The algebra remains exact, but the network’s end‑to‑end state diverges from the continuous pass because of this difference.
Full transition is better than simplified variants
In experiments we compared the full transition matrix P, its diagonal approximation and simple addition of states without transition. On an independent test pool for checkpoint 7.2B by metric |Δlogp gold| full P It was closer to the continuous pass than the diagonal variant in all ten evaluated cells. In five multi‑document tests it also outperformed simple state addition.
This advantage does not mean that the composition result is always close to ordinary context processing or better on every metric. On smaller checkpoints and individual datasets the comparison of full and diagonal versions was less uniform. In particular, summing states loses information about how subsequent documents transform the already accumulated result, and it noticeably falls behind as the number of documents increases.
Where the error occurs
The evaluations included synthetic information retrieval as well as SQuAD, HotpotQA, and the Russian SberQuAD. On several checkpoints we observed loss of information from early documents. The behavior of a later document differed: in an independent replication on three new seeds for the 7.2B model, the composition yielded a smaller margin of correct answer than the continuous pass, in three checks of the later target. The authors emphasize that different checkpoints are being compared, not controlled models that differ only in parameter count.
State error decomposition showed a noticeable contribution from the state S of the last document. However, the overall magnitude of state error did not predict answer degradation: in the evaluated cells the correlation between these quantities was close to zero. A short warm‑up before caching is considered a possible way to reduce the divergence, but the results of these experiments were obtained on a single seed and remain exploratory.
What this means for developers
The composition can be seen as a way to reuse precomputed document states when context assembly speed and cache reuse are important. The cache must be built with a given text prefix: a zero prefix usually yields a significantly worse approximation. Also, one cannot assume that individual caches fully reproduce a pass over the combined text, especially for upper layers and tasks where early documents matter.
After building caches, the composition took 0,65–1,55 ms per document on a MacBook M4 Air. Cache building took 1,06–1,19 of the prefill time for a single document, i.e., added about 6–19% to prefill. These numbers are not CUDA measurements for the 7.2B model, so they should be regarded as characteristics of the specific described test, not a universal performance reference.