Repository navigation
vision: restore the prefix cache and per-chunk encode for every tower - #303
Conversation
The generic walker restarted each chunk at the linear position and at item 0, so a prefill starting after a cached image would have positioned the rest from its own first token. Walk the prompt from position 0 and slice the processed range, as the Qwen3-VL arm does. GLM-5 had lost its walker: `build_glm5` has no caller on main, so a GLM video took the generic walk, which does not know its per-frame markers and timestamp text. Its arm is back. A run a walker pushes past the range is sliced off; a walk shorter than the range is request-local. Ported from Enntity/atlas 4b30eb8 and bd3eca1 (AGPL-3.0-only). Co-Authored-By: Claude Opus 5.5 <[email protected]>
- `items_in_range` selects an item only for a placeholder in [max(from, computed_from), to). It selected an item the cache covers wholly but whose pads end inside a later chunk: the window started one item early while the splice skipped that item's rows, and every later image read the previous image's rows. A chunk wholly in the cache encodes nothing. - `vision_splice_plan` places only the placeholders the prefill computes. A cached head of a straddling item still advances the row index, and a computed placeholder with no row is an error, never a raw token embedding. - A chunk's rows are checked against the window on every rank before the drain, the encode and any collective. A single rank used to overrun `buf_out`. - The head is told by rank. A head without pixels fails through the agreement instead of splicing whatever `buf_out` held. - A worker takes the agreement's rank-0 word as an idle receive, so a long encode does not mark the communicator unhealthy. - `prepare_vision_embed_for_chunked` moves the pixels onto the sequence: the sequence holds the request's only copy and the permits it carries. - `ATLAS_VISION_CHECK_ROWS=1` re-encodes each item of the window alone and compares its rows (diagnostic, slow). `embed_chunk_sim_tests` drives the real selection, window and plan over random prompts, caches and chunkings. Ported from Enntity/atlas ca929ec, 8746056, da94c7a and d85c88d (AGPL-3.0-only). Co-Authored-By: Claude Opus 5.5 <[email protected]>
`vision_prefix_cache_ok` was `is_some_and(|_| false)`, so no vision prompt was ever looked up or inserted: a repeated image re-prefilled in full. The key is content hashes over the placeholder runs, and every walker now positions a prefill that starts after a cached image from the whole prompt, so nothing about it is tower-specific. qwen4_exp's in-pass checkpoints register under the same key, or skip a prompt the key does not cover. Ported from Enntity/atlas a946481 (AGPL-3.0-only). Co-Authored-By: Claude Opus 5.5 <[email protected]>
A vision sequence is never cached when it finishes, so the radix references it holds are its prompt's. Releasing over the reply would drop references it never took from a node another request's prompt put on the same key. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
I also measured vision TTFT on main before and after this PR (
Cold requests are unchanged, and repeats of the same image or video are faster, the video about 4.6×. Before this PR, nothing in either phase was cached. |
|
Merged after the KL logit-drift and bench gate on reiner + spark2, against main KL logit drift. For each position I compute KL(main ‖ this PR) from the two engines' top-20 logprob distributions:
Bench (sq_bench, spark config, interleaved boots, n=4–6 per cell; main, then this PR):
TTFT at 2K, 8K, 16K and 28K is equal. Every cell is inside main's run-to-run range. rc16: greedy C1 and C8 8/8 identical to main, tools 21/21. On your question about the gate: I closed it in #286, not deliberately. That port dropped the GLM vision tower, so |
|
Post-merge GB10 confirmation is queued. #305 carries this PR's commits unchanged on main 8c2b672, and its sparky gate runs an FP4-Local vision prefix-cache probe:
|
|
Post-merge GB10 vision probe (sparky, Flash-Next FP4-Local, single GB10). Setup:
Requests:
Observed under this fingerprint, one run per arm:
No quality judgement either way: I haven't scored these texts. Before relying on the default-on cache for qwen4_exp, I'd suggest:
Artifacts on sparky: |
|
@AzeezIsh thanks for the probe, and sorry this sat. Your three findings, in order:
On the default: I'd keep vision caching on. Text prompts already behave this way by default, and caching an image differently from the text around it would be its own inconsistency. What I owe is cold == warm for vision under Our Sparks are all busy right now; I'll post the run here once I get one. |
Summary
On main, no vision prompt reaches the prefix cache on any tower:
vision_prefix_cache_okisis_some_and(|_| false), so a repeated image or video re-prefills in full. SparkQwen 0.4.0 and SparkGLM 0.2.0 both cache them. Turning the gate back on alone is not safe, because the prefill and MRoPE paths also need to handle a chunk that starts after a cached image. This PR ports those fixes and then restores the gate for every tower.build_glm5has no caller on main; its arm is back.ATLAS_VISION_PREFIX_CACHE=0turns it off. qwen4_exp in-pass checkpoints register under the same content key, or skip a prompt the key does not cover.The four commits port Enntity/atlas 4b30eb8, bd3eca1, ca929ec, 8746056, da94c7a, d85c88d and a946481. Each commit message says which.
Part of #220.
Test plan
cargo fmt --all -- --checkATLAS_SKIP_BUILD=1 cargo clippy --locked --workspace --tests -- -Dwarnings, CI's env. Not--all-features, which stops onobjc2on Linux.python3 scripts/check_spdx.py, which is what CI runs.scripts/check-license-headers.shneeds Docker and did not run in my container. All four new files carry the header.typos: not run, not installed here.spark-modelwith the filtersvision mrope pc_policy finish_leaf: 158 passed, 3 ignored. The workspace suite was not run at this tip.embed_chunk_sim_tests, which drives the real selection, window and plan over random prompts, caches and chunkings, andvision_cache_stream_tests.SparkQwen, this tip (
cecf6539e) vs SparkQwen 0.4.0. Qwen3.8-Flash-Next, Spark and Strict modes,8x32kprofile. Four image and video prompts plus one image and video pair sent together, 14 responses at temperature 0 withreasoning_effort: low.4x1mprofile.Spark mode, preliminary, one run, three requests each:
Cached repeats run a few ms slower than 0.4.0 here, and the same shows in Strict. I have not found why.
SparkGLM, not this tip. Main has no GLM tower path yet, so these commits were tested merged into our SparkGLM tree (Enntity/atlas
a76faa010), against SparkGLM 0.2.0 in Spark mode.glm5_vision_native_encoder_oracle_dumpandmxfp8_real_tensors_match_bf16_per_tp2_rankdid not run, because they need a checkpoint env var we had not set.These comparisons are against the reference products, not against main in the same run, so they do not isolate this PR's speed effect. Main was not measured with this probe, so "main re-prefills in full" comes from reading the gate, not from a before number.
Notes for reviewers
switch_on()invision_cache.rsis a one-line change.|v| v.is_glm5_nextto|_| false. I do not know why. If it was covering a problem these commits do not address, please say.ATLAS_VISION_CHECK_ROWS=1is a new slow diagnostic that re-encodes each item of the window alone and compares its rows.9b25f57596d1):out_row()andout_hidden_size()accessors, and the Qwen3-VL arm. The tower dequantizingVitWeightat run time,output_rows()asp_maxandVisionCapacityErrorare main's and stay.ep_min_u32gather fast path, and the verify-split and native MTP trait additions. The GLM multi-rank cap invision_row_boundsbelongs with the GLM stack.stack/dflash-warm-ctx.Authorship
AI-authored (Claude Code). No human-written code.
🤖 Generated with Claude Code