Repository navigation
olmo_core_vlm: cached decoding for Kimi Delta Attention blocks - #574
Merged
Merged
Conversation
OLMo 3.5 document-layout checkpoints decoded without a cache because their Kimi Delta Attention blocks have no KV cache: every generated token re-ran the language model over the whole sequence. - KDA blocks now keep their recurrent state and the last inputs of their q/k/v convolutions between decode steps (left-padded rows; pad positions are inert in the prefill). - Attention blocks with Scalable-Softmax count a query's visible tokens from the cache, and models without RoPE get no position tables. - At load, one KDA block is decoded from state on random input and compared with its own full forward; if they disagree the model decodes without a cache. olmOCR-Bench 22 h -> 2 h 06 min, CC-OCR 9 h -> 1 h 10 min, SA-Co Gold 4k 16.5 h -> 5.5 h on one 8-GPU job each, with scores within 0.25 of the uncached decode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it does
OLMo 3.5 document-layout checkpoints mix Kimi Delta Attention (KDA) blocks with a few softmax-attention blocks.
enable_kv_cachecould not cover the KDA blocks, so these checkpoints decoded without a cache: every generatedtoken re-ran the language model over the whole sequence. With this change they decode from kept state:
kernel_size - 1inputs of the q/k/v convolutions(
CachedKimiDeltaAttention). The prefill runs the usual chunked kernel over the left-padded prompt with the padpositions made inert; decode steps continue from the kept state.
position inside the current forward (
CachedAttention), and models without RoPE get no position tables.KimiDeltaAttention.forward, so before it istrusted one block is decoded from state on random input and compared with its own full forward. A build whose
forward has changed fails the check and the model decodes without a cache, with a warning.
Nothing changes for models the cache already covered.
-o provider.use_cache=falsekeeps the uncached decode.Recommended setting for SA-Co Gold 4k: batch 256, passed as
-o provider.batch_size=256 -o batching.chunk_size=256after
--harness(the harness chunks requests at 64 before the provider sees them). It runs in 2 h 38 min instead of5.5 h at the same score. The other evals are fine at 64.
Results
Same checkpoint (
c20b-r44hr-seed0, step 1200), 8 crops, one 8-GPU job per eval on holmes (B300, torch 2.10 image):A second checkpoint and a 24-crop run, cached from this branch on local B300s (torch 2.13) against the uncached
holmes jobs (torch 2.10):
c20b-r44hrocr-seed0, 8 crops, 2,000 imagesc20b-r44hr-seed0: PixMo-Count (192)Paired per image on the 2,000 CC-OCR images: 1,575 outputs are identical; word F1 per image is 60.69 cached against
60.54 uncached (difference +0.15 +- 0.22 SE; 159 images better, 164 worse).
On one real checkpoint the load-time check measures a deviation of 0.2-0.3% on each of the 14 KDA blocks (tolerance
5%), and four pages decoded for 48 tokens are identical to the uncached decode.
The cached and uncached decodes agree to rounding, not bitwise: the chunked KDA kernel groups tokens in blocks of
64 from the padded start, and a decode step's convolution runs through
F.conv1d. Measured with forced tokens(3 pages x 700 tokens), the largest logit difference per position is 0.37-0.45 on a scale of ~30, flat along the
sequence; the same uncached forward with 500 extra right pads moves the logits by 0.31-0.33. The top token flips
1-4 times in 700, always at margins <= 0.06.
Open points
shows no systematic shift, so this reads as run-to-run noise, but only CC-OCR was paired.
max_tokensholds the batch (SA-Co Gold4k). Larger batches help (
-o provider.batch_size=256 -o batching.chunk_size=256after--harness: 2.7 items/sagainst 1.4-1.5 at 64); dropping finished rows from the state is a possible follow-up.
grouped_mmloop on Blackwell; a cached step costs ~0.28 s thereand ~0.1 s on torch 2.13.
tywas not run locally (not installed in the environment used here).Tests
tests/providers/test_olmo_core_provider.py::TestCachedDecodeState: the convolution tail against the full causalconvolution; cached Scalable-Softmax against a full forward with left padding; the load-time check on a toy
recurrent mixer (kept state passes, lost state and a raising forward fail, the module's class is restored); and,
with OLMo-core, flash-linear-attention and a GPU, a real
KimiDeltaAttentiondecoded from state against its fullforward. Provider tests: 352 passed, 1 skipped (no
openaipackage locally).🤖 Generated with Claude Code
https://claude.ai/code/session_0159PTUsp2w3YTANVDZ4BUss