Skip to content

Restrict prompt retention to shared arenas - #1079

Merged
juliankang4 merged 6 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fix-nvfp4-c2-greedy
Nov 1, 2026
Merged

juliankang4 merged 6 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fix-nvfp4-c2-greedy

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

NVFP4 모델에서 요청 두 개를 동시에 처리하고 MTP 초안을 켰을 때 greedy 결과가 달라지던 문제를 고쳤습니다.

What and why

With the MTP draft on and two requests running at once, the Qwen3.8 seat served a prompt differently from a single request. Another slot's step or prompt could overwrite the shared prompt arena before the draft read the waiting hidden row, so the seat stepped the prompt's last id by a different path. That path rounds the last row differently, and a greedy id can differ.

The fix keeps that row. When a drafted prompt ends in a shared arena, the common MTP policy copies the final hidden row into the sequence's own step arena together with its position record. The Qwen3.8 and GLM NextN adapters only map the source, the destination and the position record to one device copy (gpu::draft::retain_hidden_row). The retain step refuses an arena the sequence already owns, by name. The seat's MTP-only branch (drafts_slots) and its prompt-quantum exception are removed, so the MTP draft uses the same prompt path as the plain run on any slot count. No kernel, flag or constant is added.

Release notes: Fixed: with the MTP draft on, two parallel requests on an NVFP4 Qwen3.8 model return the greedy ids of the serial and no-draft runs.

Code shape

The review reads these first. A box left unticked needs one line of why.

  • No second copy. Logic two models (or two call sites) share has one common owner; I lifted it there instead of
    copying it (AGENTS.md "Common code first", docs/rust-quality.md R14). Where I found an existing copy, I
    named it below.
  • Model code holds only architecture facts. A model's own files carry only what its architecture forces
    (tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
  • Dead code is gone. Nothing I made unused is left behind (functions, flags, gate clauses, docs).
  • No silent failure. Undefined input is a named error or panic, never a defined-looking output.
  • Comments state what is true now. No dates, issue numbers or how a bug was found (tools/check-comments.sh).
  • No relaxed gate. No band, tolerance or lint moved to make a check pass; a re-pin carries PIN(YYYY-MM-DD):
    and its reason.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": none. The row copy lives in crates/gpu/src/draft.rs (retain_hidden_row) and both models call it; the policy side is crates/app/src/mtp/policy.rs and MtpDraft::retain_prompt in crates/app/src/mtp.rs.

What I ran

Each fix check was first run with the fix removed, then with it in place. The GPU runs are on a DGX Spark (GB10), see Hardware below.

Policy unit test, CPU:

cargo test --release -p bloomery-app --lib retain_prompt

Without the fix (the retained row's last_unit is not cleared):

assertion failed: rig.p.last_unit.is_none()
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 31 filtered out; finished in 0.00s

With the fix:

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 31 filtered out; finished in 0.00s

Qwen3.8 MTP close gate:

bash tools/gate.sh --gpu --oxide -p bloomery-gpu-gates --release --features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --bin gate_qwen4exp_mtp -- --ignored hw_close_fold --nocapture --test-threads 1

Without the row copy and the shared-arena refusal:

(cl) close then another slot's prompt: retained_row_bits=false draft_active=true refused_owned_arenas=false greedy_equal=true FAIL
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 3 filtered out; finished in 46.15s

With the fix:

(cl) close then another slot's prompt: retained_row_bits=true draft_active=true refused_owned_arenas=true greedy_equal=true PASS
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 3 filtered out; finished in 46.19s
GATE-PASS Qwen close fold and shared-arena refusal

GLM NextN two-slot gate ((z) now also finishes both prompts before either slot's first step), on the GLM fixture model glm53-fixture-00001-of-00003.gguf:

BLOOMERY_TIER=fixture BLOOMERY_MODEL=glm5next BLOOMERY_BOX_LOCAL=1 bash tools/box.sh 'cargo oxide build --arch sm_121a -- -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --release --bin gate_glm5next_mtp && BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_glm5next_mtp'
(z) two slots in one pass: 8 rounds, each window's draft its own and its proposal capped at the seat's depth 1 (a pass of 4 rows), kept slot 0 [1, 1, 1, 1, 1, 1, 1, 1], slot 1 [1, 1, 1, 1, 1, 1, 1, 1]: each window's ids, kept rounds, draft store and position its alone run's; 16 slot rounds kept fewer rows than they ran, 0 rounds kept different counts on the two slots PASS
gpu-gate.sh: gate_glm5next_mtp ran 21 s (exit 0)
GATE-PASS GLM full gate without selector

Real server, NVFP4 Qwen3.8-Flash-Next-NVFP4, built with the shipped feature set (cargo oxide build --arch sm_121a -- -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve). Server and client for the four arms (draft off and MTP, two parallel requests and the same two in series):

BLOOMERY_DRAFT=off|mtp BLOOMERY_HOST_ROOM=96G [BLOOMERY_MTP_WIDTH=cost] target/release/bloomery-serve --host 127.0.0.1 --port 18731 --parallel 2 --ctx-size 16896
client.py load --port 18731 --ids corpus-code-fn.ids --prompt-len 4096 --n-predict 128 --count 2 --conc 2|1 --offset 0 --bound 0 --temperature 0 --out <arm>.jsonl

Prompt length 4096, 128 greedy tokens, temperature 0, offsets 0 and 4096. The four arms' ids compared pairwise:

GREEDY off-parallel vs off-serial request=0 first=None equal=128/128
GREEDY off-parallel vs off-serial request=1 first=None equal=128/128
GREEDY mtp-parallel vs mtp-serial request=0 first=None equal=128/128
GREEDY mtp-parallel vs mtp-serial request=1 first=None equal=128/128
GREEDY off-parallel vs mtp-parallel request=0 first=None equal=128/128
GREEDY off-parallel vs mtp-parallel request=1 first=None equal=128/128
GREEDY off-serial vs mtp-serial request=0 first=None equal=128/128
GREEDY off-serial vs mtp-serial request=1 first=None equal=128/128
GREEDY-PASS all comparisons 128/128

The same server with MTP on two parallel requests at the final head (--n-predict 4):

SERVER-PASS MTP C2 P4096 K4 requests=2

No speed change is claimed.

Hardware (if the change is for a machine)

Card NVIDIA GB10 (DGX Spark), driver 595.84, CUDA 13.3.

The unit test ran on a Linux CPU host.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card labels Nov 1, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: The shared prompt row is validated, copied into sequence-owned storage, and preserved across slot changes.

Non-blocking

⚠ Cover the server retention hook: crates/gpu-gates/src/bin/shared/serve_seats/drafted.rs:800. Both changed GPU regressions call retain_prompt directly, so removing this server call leaves those checks unchanged. Exercise SlotDrafts::prompt_close or prefill_only in a two-slot regression and assert that the draft stays active after a slot switch.

Checked

Duplicates: the model adapters share gpu::draft::retain_hidden_row; the common policy owns the retention transition.

Complexity: hw_close_fold adds retention, refusal and slot-switch test stages. slots_pass separates both prompts from their first steps.

Silent failure: three no-copy states followed: skipped draft, sequence-owned arena, and no waiting row. Copy failures propagate to the caller. The placeholder token is replaced before a draft walk.

Tests: static mutation review only. Removing policy.rs:491 fails the new unit test's cleared-anchor assertion. Qwen's gate asserts retained row bits and refusal of sequence-owned arenas. GLM's clause (z) compares each slot's ids, kept rounds, draft store and position with its isolated run.

Gates: no band, threshold or pin moved; no gate clause removed.

Performance: at most one asynchronous hidden-row copy per retention call; no added copy per steady decode token.

Adversarial checks: source validation, replacement of the placeholder token, and park/unpark of the retained anchor were read.

Escape catalog: C1–C4 do not match.

Notes

Tests and card gates were not run in this review environment. The PR reports card runs but omits the tested commit hashes and nvidia-smi output required for complete GPU evidence.

Card check: needs-gpu. This pull request changes crates/app/src/arch/glm5next/mtp.rs, crates/app/src/arch/qwen3moe/mtp.rs, crates/app/src/arch/qwen3moe/mtp35.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit b84b552 into midagedev:main Nov 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant