Skip to content

Prompt cache: a cancelled prompt keeps the prefix it already read, in eleven families - #4420

Open
ashhart wants to merge 32 commits into
mainfrom
lead/gap-s1-prefill
Open

ashhart wants to merge 32 commits into
mainfrom
lead/gap-s1-prefill

Conversation

@ashhart

@ashhart ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

What this changes

Prompt cache: a cancelled prompt on Gemma 4, Nemotron, Llama, Spark2.5, Dory, MiniMax-M3, GLM, Muse Spark, LFM2-MoE, dots.mocr and Kimi keeps the part it had already read, so the next request with the same start resumes there instead of reading it again.

Commits in this series (32):

  • sessions: roll back slot when restore cannot queue
  • kimi: reject invalid full attention layer indices
  • glm: stop prefill at prompt cache marks
  • hip: skip consumed marks on resumed prefill
  • glm dsa: publish restored prefill progress
  • step5: yield between native prefill chunks
  • kimi: retain prefill state on cancellation
  • replay: restore prepared seed for explicit null
  • deepseek: plan text TBO beside image replay
  • cache: isolate decoded-row extension namespaces
  • gemma4: retain cancelled CUDA prefill prefixes
  • nemotron: retain cancelled HIP prefill prefixes
  • llama: retain cancelled prompt chunks
  • spark25: retain cancelled prompt chunks
  • dory: retain cancelled prompt chunks
  • minimax m3: retain cancelled prompt chunks
  • nemotron parse: retain cancelled prompt prefixes
  • uocr: stop cancelled image and decoder prefill
  • lfm3 xpu: clear stale carry on snapshot restore
  • glm: retain cancelled prefill prefixes
  • glm dsa: retain cancelled prefill prefixes
  • muse spark: retain cancelled prefill prefixes
  • lfm2 moe: retain cancelled prefill state
  • dots mocr: retain cancelled prefill snapshots
  • lfm2 moe: split cancellation regression fixture
  • minimax_m3: reserve draft state before cache admission
  • prompt cache: fix RAM rollback fault count
  • docs: scope Gemma and XPU qualification evidence
  • HIP: share Flash Next prefixes through LaneHost
  • CUDA: preserve planned proposal routing through LaneHost
  • adapt: keep Gemma CUDA backend and CUDA host within 600 lines
  • adapt: keep LFM2-MoE CUDA backend and CUDA host within 600 lines

Checks on this head

  • The series applies in order on main c51efc1 and reproduces its tree; every changed code file is at or under 600 lines at the series tip; no new lean findings.
  • test-host (Linux only) and test-server-cpu (it needs loopback) were not run where this was prepared; both run in this PR's train.

Not run yet

  • Device checks: the train's device cells, plus the cancel-and-resume and prefix-reuse checks listed in the stack notes where a series touches those paths. This PR stays out of the landing queue until they pass.

Moves the greedy-pick test to its own file and restores the one-line backend literal. No runtime change.
@ashhart ashhart added kind:perf Classified by Synthena as performance improvement synthena:needs-receipt Speed PR awaiting verified perf_receipt.py hash run labels Dec 3, 2026
@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner Author

Synthena Initial Review — Performance receipt required (kind:perf)

Adds cancelled-prompt prefix retention across eleven model families so resumed requests reuse already-read prompt rows, plus supporting changes to prompt-cache policy, session store rollback, replay seed handling, and build test wiring.

  • Branch currently has merge conflicts against base.
  • Performance claim detected without a verified tf-receipt-v1 receipt.

Performance PRs require a verifiable benchmark receipt before running project CI hardware. See CONTRIBUTING.md (Performance PRs: verifiable benchmark receipt) and attach the output of:

python3 tools/perf_receipt.py run --base-bin /path/to/base-tf --head-bin /path/to/head-tf --model /path/to/model.tfold --out receipt.json

Findings:

  • [BLOCKER] zig/src/families/lfm3/xpu_model.zig: snapRestore now zeroes seq.win_start/win_rows on every restore, but the diff shows no corresponding change to snapSave or Snap, so a snapshot taken mid-window will silently drop the window state on restore. Suggested fix: Persist win_start/win_rows in Snap (or assert they are always zero at save time) so restore does not discard live window state.
  • [BLOCKER] zig/src/sessions/store.zig: The errdefer runs only if a failure occurs after slot.ensure, but catch unreachable on truncate turns a truncate failure into a crash; also slot.over = over restores the reservation count without releasing any quota the failed ensure may have consumed. Suggested fix: Handle truncate failure explicitly (log and continue) and verify quota accounting matches pool.reserved expectations, as asserted in store_failure_test.zig.
  • [WARNING] zig/src/families/kimi_k3/config.zig: The bound check uses c.layers, but full_attn is a StaticBitSet(128) and the function later rejects c.layers > 128; a config with layers <= 128 is fine, yet indices equal to c.layers are accepted while the bitset is indexed at v-1, so this is correct only if layers <= 128 is enforced before this loop runs. Suggested fix: Confirm ordering: the TooManyLayers check happens after this loop, so move it before parsing full_attn_layers or clamp against 128 explicitly.
  • [WARNING] zig/src/core/prompt_cache_policy.zig: The new extends() adds a decode_spans equality requirement to prefix linking, but the diff does not show cache_modes.equal or how decode_spans are populated for cancelled-prefix entries, so resumed entries may fail to link as extensions of their prefixes. Suggested fix: Add a test showing a cancelled-then-resumed entry links to its prefix entry, or document why decode_spans equality holds for retained prefixes.
  • [WARNING] tools/replay_request.py: The old check was 'seed' not in body; the new one also injects a prepared seed when the client explicitly sent seed: null, which changes replay semantics for clients that intentionally pass null to request a fresh draw. Suggested fix: Confirm this is intended (the new test asserts it is); if so, document in the replay tool help that seed:null replays the journaled draw rather than requesting a new one.
  • Synthena

@ashhart ashhart added synthena:needs-device Initial diff review passed; waiting for device and slowdown check before READY and removed synthena:needs-receipt Speed PR awaiting verified perf_receipt.py hash run labels Dec 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:perf Classified by Synthena as performance improvement synthena:needs-device Initial diff review passed; waiting for device and slowdown check before READY

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant