Skip to content

prefill: two-phase full cache hit emits from the snapshot's stashed hidden (latent wrong first token) - #208

Merged
AzeezIsh merged 1 commit into
mainfrom
fix/twophase-full-hit-hidden
Oct 27, 2026
Merged

AzeezIsh merged 1 commit into
mainfrom
fix/twophase-full-hit-hidden

Conversation

@AzeezIsh

Copy link
Copy Markdown
Contributor

Problem

prefill_twophase_dispatch takes the proc_count == 0 branch when an SSM snapshot covers the whole prompt. prefill_d.rs::prefill_full_cache_hit then:

  • re-embeds the last token;
  • runs final_norm_rows + lm_head on that embedding, which went through no layers.

So the first token comes from embedding logits. The path is not gated by ATLAS_MARCONI_EXACT, and it never uses the snapshot's stashed post-norm hidden, which finalize_last's exact-hit fixup does use.

Reachability

Two-phase runs only above max_prefill_tokens, and the monolithic arm needs the whole prompt in the arena (max_batch_tokens). With the default arena (max_prefill + 1, e.g. 8193 for the FP4-Local recipe), that is a single prompt length. So this is latent: zero Two-phase prefill lines in the recipe or bare-metal serve logs. It becomes reachable on any config with max_batch_tokens well above max_prefill_tokens.

Change

Pass the effective snapshot into prefill_full_cache_hit, and copy its stashed hidden into normed before lm_head (restore_hidden, as finalize_last does). Warn when the snapshot has none.

Verified

cargo fmt --check, cargo clippy -p spark-runtime -p spark-model -D warnings and the release build are clean on sparky (GB10), built together with the shallower-snapshot fallback branch. The path itself was not exercised live; that needs a config with max_batch_tokens > len > max_prefill_tokens.

🤖 Generated with Claude Code

…idden

prefill_twophase_dispatch takes the proc_count == 0 path when an SSM
snapshot covers the whole prompt. prefill_full_cache_hit then re-embeds the
last token and ran final_norm + lm_head on that embedding, which went
through no layers: the first token came from embedding logits. Not gated
by ATLAS_MARCONI_EXACT. Use the snapshot's stashed last-token hidden, as
finalize_last's exact-hit fixup does; warn when the snapshot has none.

Reachable only when max_prefill_tokens < prompt <= max_batch_tokens
(two-phase runs above max_prefill_tokens, the monolithic arm needs the
whole prompt in the arena); with the defaults (arena = max_prefill + 1)
that is a single prompt length, so this was latent rather than observed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Riding integration train #212 (integ/train-2026-10-27, merged --no-ff at this PR's current head). It's being gated on sparky (GB10) now: control vs main, then agentic-webserver 50 + BFCL ST-995 on FP4-Local. The plan is to merge the train once both legs pass and CI shows only the repo-wide reds, which merges this PR. Results will land on #212 and in the campaign log (#211).

AzeezIsh added a commit that referenced this pull request Oct 27, 2026
Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@AzeezIsh
AzeezIsh merged commit e21fc2b into main Oct 27, 2026
20 of 23 checks passed
AzeezIsh added a commit that referenced this pull request Oct 27, 2026
AzeezIsh added a commit that referenced this pull request Oct 27, 2026
Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
AzeezIsh added a commit that referenced this pull request Oct 27, 2026
Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Live-repro attempt notes (sparky GB10, FP4-Local). This merged in train #212 on compile, tests and the train gate (BFCL ST-995 87.44 / 87.32 identical to main, agentic 50/50). I tried to drive prefill_full_cache_hit live with main d2d114c vs the train binary. The path was not reached in three tries, so there's no A/B signal either way:

  1. Serve with MAX_PREFILL=4096 ATLAS_MAX_BATCH_TOKENS=8192 ATLAS_HOLO_ALWAYS_MIXED=1; cold block-aligned 5,536-token prompt sent beside a decoy decode (forces the chunked path, which stashes the hidden at the full length); identical warm prompt alone. The warm request restored the 5,504 intermediate snapshot and replayed 32 tokens. The default exact bypass (marconi_restorable: snap_tok == matched == total && !marconi_exact()) declined the 5,536 snapshot.
  2. Same plus ATLAS_MARCONI_EXACT=1. The warm request logged Chunked prefill start: 5536 prompt tokens, chunk_size=5536 → Prefix cache hit: 5536 tokens (346 blocks) but no SSM snapshot — recomputing all KV → Prefilled (single chunk). So it went single-chunk, not two-phase, and the index lookup returned no snapshot, although the cold request had saved one at 5,536.

Both arms behaved identically each time. In practice the two-phase full-hit path needs a two-phase dispatch (len > the effective chunk size with nothing decoding) AND a restorable snapshot at exactly the prompt length. On the FP4-Local recipe profile that combination didn't occur in any serve log. That matches the original reachability note (only a prompt of exactly 8,193 tokens on the recipe). Unexplained: why the 5,536 [chunk] snapshot isn't returned to the exact lookup with ATLAS_MARCONI_EXACT=1. It's noted for whoever next touches prefix_lookup. Logs: sparky ~/code/nightq/logs/{19,21b}-twophase-208.log and nq-tp208{b,c}-*.serve.log.

data-angel pushed a commit to Enntity/atlas that referenced this pull request Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant