Skip to content

nemotron hip: prompt-cache states key the token the MTP head absorbed (#4999) - #5003

Open
BlivionIaG wants to merge 1 commit into
ashhart:mainfrom
BlivionIaG:fix/nemotron-hip-mtp-resume-page
Open

BlivionIaG wants to merge 1 commit into
ashhart:mainfrom
BlivionIaG:fix/nemotron-hip-mtp-resume-page

Conversation

@BlivionIaG

Copy link
Copy Markdown
Contributor

What this changes

Before: with the MTP head loaded, a prompt matching a kept Nemotron HIP state through the cut, but not at the token after it, resumed at the cut. It then re-absorbed the head's row at cut - 1 with its own token, writing into the last adopted page. That page is shared with the prompt cache and with other streams.

After: with the head loaded, the cache rules take a one-token lookahead, as GLM and Flash Next do. A state resumes only when the token after it repeats, and the head's rows are already complete at the resume point (mtp_len = from). The resumed absorb, its resumed flag and the hidden row that each snapshot kept for it are removed. Without the head, the rules and resumes are unchanged.

Checks on this head

  • Head commit: e6f48fa395 (one commit on d1ff890729)
  • Lean checker, python3 tools/zig/lean_check.py: 165 on the base and 165 on this head, 0 new. All 165 are inherited. tools/pr_check.py --base d1ff890729: 0 errors and 1 advisory warning (no PR number yet).
  • Tests run, Linux x86_64 host, -Dhip=true:
    • zig build test-nemotron-hip-resume-host: 5/5 pass. Fails on main with expected 612, found 9512. That run used the test with main's begin lines and prefix.init signature.
    • test-nemotron-hip-faults-host: 6/6.
    • test-hip-followers-host: 12/12.
    • check-native-hip-host: builds.
    • The whole HIP Nemotron host module, before the rebase: 67 pass, 1 skip.
    • zig fmt --check build.zig zig and git diff --check: clean.
  • On the GPU: tf-nemotron-hip-test invariance passes. A served prompt-cache resume at 128/193 plus 4 decode steps matches a fresh prefill bit for bit (Mamba state, final row, model K/V and logits). This test called prefix.begin without the salt and kept nothing, because the seed lane had no key; both are fixed here.
  • CI: not yet run on this head.
  • Not run, and why: zig build test test-golden in full, because the shared workstation's build lock was busy; I ran the named steps above instead. Metal and CUDA are not reached by this change.

Receipt

  • Main against branch: AMD Radeon PRO V620 (gfx1030), ROCm 7.14, Zig 0.17.0, NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit with its MTP head; --mtp-drafts 3 --parallel 1 --context 4096 --prompt-cache-gib 2, greedy. There were four token-id /v1/completions requests:

    • A1: A[0:520].
    • A2: A[0:1100].
    • B: A[0:512] plus 8 other tokens.
    • A3: A2 again.

    A throwaway read-back (not in this diff) hashed the head's K and V at position 511:

    main branch
    B resumes at 512 and writes page 7 (2 holders), K dbe9a117… → 6411494c… no hit, writes its own page
    A3 (resumes at 1088) reads B's row reads A's row dbe9a117…
  • Boxes it reaches: Nemotron on HIP with --mtp-drafts, single rank and rank 0 of TP. Followers hold no head and keep their cache rules unchanged.

  • New switch? None.

  • Environment: above. Base d1ff890729; the GPU cells ran on 4c79cfe346 plus this change, and nothing between those two commits touches the Nemotron, hip_serve or radix code.

  • Paths and platforms: the Nemotron HIP prompt cache and the MTP absorb. Ran on gfx1030. Not run on gfx1100, gfx1151, gfx1201 or TP > 1.

  • Exactness: token_sha matches across main and branch, with and without B: A1 3e6ce2279a7d, A2 749be1c472e9, B be6a63a683cf, A3 c31385f7d0a9.

  • Draft acceptance: A3 accepted 161 of 208 drafts on main with and without B, and on the branch with and without B. The wrong row changed nothing measurable in this run.

  • Decode speed: not measured with tools/bench_openai.py. The decode path is unchanged; one absorb row less per resume.

  • Prompt speed: a prompt that differs from a kept one exactly at the token after a kept state now resumes from an earlier state. In the run above, B went from 512 cached tokens to 0. Other resumes are unchanged.

  • Licence of new weights or drafter: n/a.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. A resume matches fresh (invariance) and tokens are unchanged; "draft": false and concurrent runs were not run.
  • No precision traded for speed.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted. Not benchmarked; see Prompt speed.

…ashhart#4999)

A non-final prompt chunk absorbs its last row into the MTP head with the
token after it, but the cache keyed a state at a cut by the tokens before
it only. A prompt that matched through the cut and differed at the next
token resumed there and re-absorbed that row with its own token, writing
the head's K/V in the last adopted page, which the cache and other
streams hold.

With the head loaded the cache rules take a lookahead of one token, as
GLM and Flash Next do: a state resumes only where its next token repeats,
the head's rows are complete at the resume point, and the resumed absorb,
its flag and the hidden row kept in each snapshot for it go. Without the
head the rules and resumes are unchanged.

The host test resumes two prompts that share 512 tokens and differ at
token 512 through the real cache, page swaps and prompt chunks, and checks
the first stream's head rows. The GPU invariance check calls the cache
with its salt and the seed lane's key again.
@AIFlowML

Copy link
Copy Markdown
Contributor

I independently trial-merged e6f48fa395 into d1ff890729 on the M5 Max. The merge was clean. The HIP host gates passed 23/23 and the native adapter compiled for aarch64 Linux. The resume cases include the no-MTP behavior as well as the MTP cache rule.

zig build test-nemotron-hip-resume-host test-nemotron-hip-faults-host test-hip-followers-host check-native-hip-host -Dhip=true -Dfixed-cpu -j2 --summary all
zig build test-prompt-cache-host test-prompt-cache-miss-host test-cache-agent-host -Dhip=true -Dfixed-cpu -j2 --summary all

The shared-cache targets passed 804/804. This was a host and cross-compile check. The served HIP result remains the AMD device evidence.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks, @BlivionIaG. The lookahead key now covers the token already absorbed by the head, and resume no longer rewrites that shared row. The focused regression and no-head control support the fix; the posted readback shows why it matters even though those token hashes stayed equal. The source is ready to land, with changelog integration on our side. The unrun concurrency, draft-off and TP cells remain separate qualification limits.

  • Synthena

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nemotron hip: a resumed prompt's MTP absorb rewrites a row in a shared prefix-cache page

3 participants