Skip to content

qwen38: load the checkpoint folder MTP draft in its stored formats - #682

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fp4local-mtp
Oct 22, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fp4local-mtp

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8 FP4-Local 체크포인트 폴더에 들어 있는 MTP draft를 저장된 형식 그대로 읽어 켜는 작업이고, 코드 입력에서 decode가 최대 71.84% 빨라집니다.

What and why

Part of #565. This closes the line in its section 4: "MTP draft from the FP4-Local checkpoint: W4A16_NVFP4 experts and BF16 dense parts".

nvidia/Qwen3.8-Flash-Next-FP4-Local ships its MTP layer inside the checkpoint folder: BF16 dense matrices, W4A16_NVFP4 routed experts with their tensor-scale companions, and F32 injects. The folder path refused a draft, so MTP on this checkpoint needed a separate GGUF draft. Now both serving entry points find the folder's draft and run it without a prepare step.

What the PR changes:

  • The Qwen mapper shares one target and draft layer mapping, places the MTP layer after the trunk, joins fc_embedding before fc_hidden along the input columns, and applies the existing zero-centered norm transform.
  • The folder exposes a synthetic MTP header and one shared part source. Each load filters that source to its own plan with model::part::Filtered, so the target plan never sees MTP tensors and the draft plan never sees trunk tensors. Strict OnCard placement checks are unchanged.
  • MTP planning accepts stored BF16 dense matrices, routed NVFP4 and FP8_B128 experts, direct F32 injects, and the routed tensor-scale companions, which are not counted as experts.
  • The resident selected-row site gains NVFP4 rows read with unquantized F32 activations. It reuses RowValues, the E2M1 table, the E4M3 decoder, the lane accumulation and the existing fault owner. The new kernel entry has its PTX shape pins.
  • An explicit GGUF draft override still works. The folder's residency refusal is unchanged.

Existing paths: a GGUF draft and a folder served with draft off load through the same code as on main. There are no TP protocol changes, and draft limits for several ranks are unchanged.

Release notes: Added: MTP draft served directly from the Qwen3.8 FP4-Local checkpoint folder, with decode up to 71.84% faster on code at one request.

Code shape

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

  • No second copy. Target and draft planning share one mapping and one source callback. The new selected-row entry reuses RowValues, the E2M1 table, the E4M3 decoder and f32_lane_partial_1col.
  • Model code holds only architecture facts. The Qwen files hold the MTP layer's tensor names and shapes. Source selection lives in model::part.
  • Dead code is gone. The folder's old draft refusal is replaced by the feature.
  • No silent failure. An expert id out of range or a non-finite input makes the selected-row output NaN with a named fault. An F32 product overflow is named too.
  • Comments state what is true now.
  • No relaxed gate. No band or tolerance moves. The new PTX pin rows carry a PIN(2026-10-23): line with the measured values.
  • 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":

  • crates/gpu/src/q8f32.rs:2274 against q8f32.rs:1815 (Q8_0 rows): different. The new entry reads NVFP4 code and scale planes and one tensor scale per selected expert; Q8_0 reads packed blocks. Both call f32_lane_partial_1col.
  • crates/gpu/src/q8f32.rs:2274 against q8f32.rs:1923 (MXFP8): different. MXFP8 reads E4M3 values with E8M0 block scales; NVFP4 reads E2M1 values with E4M3 scales. The traversal and decode helpers are shared.
  • crates/model-hf/src/arch/qwen35moe/folder.rs:244 against crates/model/src/fixture/plan.rs:208: different. draft_header builds a header from a copy of the target's metadata array; the fixture only borrows its array.

What I ran

Decode, draft off against native MTP

One DGX Spark, one slot, nvidia/Qwen3.8-Flash-Next-FP4-Local at b9ce18a6, C@1. Each request processes 4096 prompt ids with no cache hit and generates 128 ids, on four corpora. There are two alternating rounds with one request per corpus per round, so eight matched windows per mode. The table gives the median decode tok/s of the two rounds, and the draft ids accepted over drafted, summed over both rounds.

Corpus Draft off tok/s Native MTP tok/s Decode delta Accepted / drafted
code-fn 29.77 45.03 +51.24% 160/248 (64.5%)
code-js 29.79 51.19 +71.84% 171/215 (79.5%)
prose-en 29.86 31.44 +5.28% 109/325 (33.5%)
prose-ko 29.76 37.98 +27.63% 122/194 (62.9%)

Decode delta per corpus: code-fn +51.24%; code-js +71.84%; prose-en +5.28%; prose-ko +27.63%.

All 1024 generated token ids per mode (8 windows of 128) equal the draft-off ids, with 0 mismatches and 0 errors. Two rounds make this a short comparison: the numbers are decode-rate gains at one request, not a long-run confidence claim.

The decode gain does not carry over to the whole request on every corpus. Median full-request time, draft off against native MTP, is 12328 against 11105 ms on code-fn, 12333 against 10777 ms on code-js, 12206 against 12285 ms on prose-en and 12250 against 11646 ms on prose-ko. Median time to first token rises from about 7.9 to 8.0 s with draft off to about 8.2 to 8.3 s with MTP.

The plain-read ceiling on the node was 239.3 GB/s before the sitting and 240.3 GB/s after.

Oracle and gates

Reference Result
Target-only greedy decode of the same binary on the same checkpoint PASS

The MTP gate on a GB10, with the FP4-Local folder as the reference model: the folder draft loads, eager, graph and replay agree on a poisoned scratch at rows 1 to 4, and the greedy oracle matches.

BLOOMERY_DRAFT=mtp BLOOMERY_REF_MODEL=<FP4-Local folder> BLOOMERY_BOX_LOCAL=1 just gate-gpu-qwen4exp-nvfp4
(l) folder MTP draft_resident_bytes=1596321792 arena_bytes=53526700 PASS
(mtp-g) rows=1 poisoned scratch: eager = graph = replay PASS
(mtp-g) rows=2 poisoned scratch: eager = graph = replay PASS
(mtp-g) rows=3 poisoned scratch: eager = graph = replay PASS
(mtp-g) rows=4 poisoned scratch: eager = graph = replay PASS
(mtp-v) greedy target oracle: 32 tokens plain = verified PASS
gpu-gate.sh: gate_qwen4exp_nvfp4 ran 263 s (exit 0)

The NVFP4 gate on a GB10: the three routed F32 clauses pass against their bands, the id and non-finite refusals name their cause, and an F32 product overflow is detected.

BLOOMERY_BOX_LOCAL=1 just gate-gpu-nvfp4
nvfp4 clause=routed_f32 part=0 rows=640 k=2560 normalized_error=0.000000047 band=0.000020742 PASS
nvfp4 clause=routed_f32 part=1 rows=640 k=2560 normalized_error=0.000000053 band=0.000020742 PASS
nvfp4 clause=routed_f32 part=2 rows=2560 k=640 normalized_error=0.000000071 band=0.000006437 PASS
nvfp4 clause=routed_f32_refusal input=id named=true rows_nan=true PASS
nvfp4 clause=routed_f32_refusal input=nonfinite named=true rows_nan=true PASS
nvfp4 clause=routed_overflow fault_names_f32_product=true rows_nan=true PASS
gpu-gate.sh: gate_nvfp4 ran 10 s (exit 0)
  • Two regression tests fail on their defect. Writing the draft header's compression-ratio array unsigned fails the header serialization test, and dropping the per-plan source filter fails the two-component selection test.
  • just contrib-check --tier t0 on this head: DONE tier=t0 total=107 red=0 wall=484s.

The numeric runtime code on this head is the code the gates and the comparison ran on. Since then only a test fixture and the new entry's PTX pin rows changed.

What I ran into

None of this blocks the PR.

  • The sm_86 PTX pin rows for the new entry hold ptxas values measured on a GB10 (regs=40, spill=0, no depot, no local loads or stores, reqntid=256). The cc 8.6 driver JIT was not measured, and the pin says so.
  • English prose accepts 33.5% of its drafted ids, against 79.5% on code-js, so its decode gain is 5.28% and its full-request time does not improve.
  • The stored draft head is about 0.36 GiB read per proposal, against about 0.17 GiB of dense weights and 0.026 GiB of selected routed weights (derived from the checkpoint shapes).

Hardware (if the change is for a machine)

The change is for DGX Spark. The gates ran on a GB10 with these lines from nvidia-smi:

| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |

The C@1 comparison ran on a second DGX Spark with the default clock policy, with the server built by cargo oxide build --arch sm_121 -- -p bloomery-gpu-gates --features glm5next,clef,mimo2,solar2,minimaxm3,gemma-embedding2,checkpoint --release --bin bloomery-serve.

AI help

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

@github-actions github-actions Bot added documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 22, 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: No must-fix defect was found in the changed code.

Non-blocking

⚠ Pin native draft numerics: crates/gpu-gates/src/bin/gate_qwen4exp_nvfp4.rs:515.
Eager, graph and replay compare the same loaded draft. The mapper test at crates/model-hf/src/arch/qwen35moe.rs:1435 asserts PlusOne for enorm and hnorm, but omitting only the head norm's transform while retaining F32 is not covered by its assertions. The greedy oracle checks target-verified output. Compare one native draft hidden or logit row against an independent checkpoint forward.

⚠ Complete the measurement evidence: docs/cards/q38-fp4local-mtp.card:12.
The PR body supplies hardware lines and gate output, but omits the measured commit hashes and the A/B commands with their output. Attach those witnesses under CONTRIBUTING's evidence rule; identify both arms by SHA even when they use the same binary. This remains a non-blocking request for reproducible measurement evidence.

Checked

Duplicates: supplied dryer diagnostics report zero pairs; GPU crates were excluded from that scan.
Complexity: diagnostics report new gate::mtp (24), extracted planned_tensors (16), and branch growth in mapping, planning, loading and gate functions. Complexity alone establishes no defect.
Silent failure: draft mapping rejects an incomplete projection join and an extra draft layer with named errors.
Tests: inspected mapping assertions, join-order coverage, MTP execution-mode comparisons and the verified-token oracle.
Gates: the cited gate compares token, probability and hidden-state bits across eager, graph and replay. Neither retained concern matches escape catalog C1–C4. The ledger has no lessons in force.

Notes

Validation was static; runtime gates and compiled tests were not run.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/bloomery_serve_qwen38.rs, crates/gpu-gates/src/bin/gate_nvfp4.rs, crates/gpu-gates/src/bin/gate_qwen4exp_mtp.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.

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

Labels

documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant