Skip to content

gpu, model, refset: Qwen3.8 served from the NVIDIA NVFP4 checkpoint on one card, every routed expert on the card, against its pinned oracle - #561

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-nvfp4
Oct 20, 2026
Merged

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

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8-Flash-Next의 NVIDIA NVFP4 체크포인트를 DGX Spark(GB10) 한 장에서 실행하고, 체크포인트 자체의 순전파 결과와 맞는지 확인하는 게이트를 추가합니다.

Part of #493.

This PR lets bloomery run Qwen3.8-Flash-Next from NVIDIA's NVFP4 checkpoint (nvidia/Qwen3.8-Flash-Next-NVFP4) on a DGX Spark (GB10), with all 24,576 routed experts on the card. On main, loading the GGUF split that prepare writes from this checkpoint stops at 144 tensors have no role. With this PR the same split generates text, and a new gate, gate_qwen4exp_nvfp4, passes against a pinned oracle computed from the checkpoint itself.

What and why

Running the checkpoint needed four contracts. Each lives in a common owner, so the next NVFP4 model, Qwen3.8 FP4-Local included, at most adds a type to its leg's arm.

Contract Owner What it does What the next model does
Expert .scale role crates/model/src/arch/classify.rs, tensor_scale_role inside the common classify_with A <stem>.scale beside a <stem>.weight whose type reads a scale (GgmlType::reads_scale) is unread and belongs to that tensor's layer. Any other .scale stays unclassified and the file is refused by name. The per-layer embedding scale row in qwen35moe/roles.rs is gone because the common rule now covers it. Nothing.
Card admission crates/placement/src/accepts.rs, leg_card_format One answer to how a card leg loads a routed stack of a given type: NVFP4 as planes, every other type as the file's blocks. Every leg arm (Qwen3.5, Qwen3.8, the common leg, V4.1, the latent MoE body), the Qwen3.8 card check in qwen35moe/place.rs and card_routed in place_hybrid.rs call it instead of naming CardFormat::KQuant themselves. The Qwen3.8 arm gains NVFP4 gate-up and down entries. Adds the type to its leg's arm.
Prompt route crates/gpu/src/card_leg.rs, StackW::route(ty) Picks the route GEMM for a resident stack from the placement table kernels::gemm: K-quant and i-quant words go through the grouped GEMM; Q8_0, Q5_1 and IQ4_NL blocks and NVFP4 planes go through the 32-value GEMM. StackW::route builds the grouped format through GemmWeight::from_ggml. The ubatch route in wide38.rs and the block route in tier38.rs call only this, and their own Qwen3.8 type lists are gone. Nothing for these types.
Host load when every layer is on the card main's crate::model::host_run body38.rs passes host_run only the layers that have a host leg, and qwen35moe::host::layers and routed_layers take a layer set instead of a range. A layer without a host leg downloads nothing and adds a zero sum (Card38::zero_sum in the pass, hsum.zero_async in the walk). Nothing.

The calls that go with these contracts:

  • card38.rs reads an NVFP4 stack through Weights::nvfp4_stack. At load, one_gate_up_form decides one input form for every card layer from StackW::route (the q8_1 rows or the 32-value rows) and refuses a load that mixes the two, naming both layers. The ubatch route in wide38.rs (RouteX) then holds only that one form, so the plan's existing per-token bound, CARD_ROUTE_RUN_TOKEN_BYTES in qwen35moe/place.rs, covers it. Its comment now says so. A GGUF load allocates the same input rows as on main.
  • gate_qwen4exp_nvfp4 is new, with the recipe just gate-gpu-qwen4exp-nvfp4. It reads the refset family hf-qwen4exp-nvfp4 (crates/refset/src/arch/qwen4exp/nvfp4.rs), which just dump-ref-qwen4exp-nvfp4 writes with tools/ref/qwen4exp-nvfp4-oracle.py: an f32 CPU forward of the checkpoint at revision fc694b54fb0174e0913e6adf86691ef85a4ead47, on the weights the prepared split holds. The writer emits each int row twice, flat and logical, in lowercase i32, the form crates/refset already reads.
  • The oracle writer's --resume continues only from state with the same writer md5, checkpoint path and config, transformers model code hash, torch version, arm names, token ids and tap format. Missing or different identity is refused by name before any model computation. The prose input is exactly 3,001 in-vocabulary integers, and its digest comes from the bytes the computation used.
  • qwen4exp::check_inputs (crates/refset/src/arch/qwen4exp/mod.rs) checks the positions of the batch, step4, D1K and D3K sets. gate_qwen4exp_nvfp4 calls it for its four manifests before the GPU load, and gate_qwen4exp_e2e calls it at its manifest and step entry points.
  • The new gate and gate_qwen4exp_e2e read reference routing and collect route flips through one file, crates/gpu-gates/src/bin/shared/q38_oracle.rs. The bands and their PINs moved there unchanged.

Release notes: Added: Qwen3.8-Flash-Next runs from the NVIDIA NVFP4 checkpoint on one card with every routed expert on the card, and just gate-gpu-qwen4exp-nvfp4 checks it against an f32 forward of the checkpoint.

Code shape

  • No second copy. The four contracts above each have one owner. The leg arms, the Qwen3.8 card check and card_routed now call leg_card_format, the reference routing reader has one home in q38_oracle.rs, the position check has one owner in check_inputs, and the grouped format conversion in card_leg.rs calls GemmWeight::from_ggml where six local copies stood.
  • Model code holds only architecture facts. The Qwen3.8 files gain no type list. They ask StackW::route and leg_card_format.
  • Dead code is gone. The per-family scale row, the Qwen3.8 route type lists and the writer's unused files counter are removed.
  • No silent failure. A .scale beside a type that reads no scale, a stack type the GEMM table does not name, a load that mixes the two input forms, and an oracle --resume or input set that does not match its identity or positions are each refused by name.
  • Comments state what is true now.
  • No relaxed gate. The bands moved to q38_oracle.rs with the same values and PINs.
  • 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-gates/src/bin/gate_qwen4exp_e2e.rs loses its own reference routing reader and its two flip loops, which now live in crates/gpu-gates/src/bin/shared/q38_oracle.rs. CardFormat::KQuant written in each leg arm is replaced by leg_card_format (crates/placement/src/accepts.rs:186). The six grouped-format conversions in StackW::route become one call to GemmWeight::from_ggml (crates/gpu/src/gemm/grouped.rs:179).

What I ran

The PR head is 50d934b6 over upstream e3ce40fd. Runs used a DGX Spark (GB10) except the CPU mutants. The accuracy gate, its scale mutant and the route device test ran on b5562dea; the later commit changes only the oracle writer's completion handling, its harness identity and a CPU test, with no device code. The build, the card tests, the card38 mutants, the short generation, the UD-Q4_K_XL comparison and the speed record ran on bf5238fd, and each of those sections names that head. Since then card_leg.rs gained the GemmWeight::from_ggml conversion, which the gate and the route test below ran with.

Build and device tests

On bf5238fd, the build of generate_qwen3moe, gate_qwen4exp_nvfp4 and gate_qwen4exp_e2e at sm_121: build rc=0, with no warning in a file this PR changes.

The card leg's device tests and card38's tests (card_leg::tests::hw_ and card38::tests::): test result: ok. 11 passed; 0 failed. They include hw_a_stack_routes_by_the_tables_gemm_entry for the route and a_load_reads_its_card_gate_up_in_one_form for the one input form.

The route device test on b5562dea: card_leg::tests::hw_a_stack_routes_by_the_tables_gemm_entry gives test result: ok. 1 passed; 0 failed.

Mutants that must fail

On bf5238fd, two mutants planted in card38.rs each made a_load_reads_its_card_gate_up_in_one_form fail, and the test passes without them:

  • a load that mixes the two forms taken as the 32-value form: test result: FAILED. 0 passed; 1 failed, rc=101
  • the two layers in the refusal message swapped: test result: FAILED. 0 passed; 1 failed, rc=101
  • the file restored: test result: ok. 1 passed; 0 failed, rc=0

On 308c579c, cargo test -p bloomery-refset arch::qwen4exp::nvfp4 --lib passes with test result: ok. 2 passed; 0 failed. Seventeen mutants of the oracle input checks (3 position and unknown-set checks, and 14 set-name guards each skipped) each make the test fail, test result: FAILED. 1 passed; 1 failed, rc=101. With the file restored it passes again, rc=0.

On b5562dea, a mutant in weights.rs uploads every NVFP4 expert scale as zero. The accuracy clauses fail: the free walk (worst l_out_rel 5.140e-1 at layer 0 position 2), (p) and (g) with argmax 279 against oracle 11751, and (t) with argmax 279 against 423. With the file restored, the same gate passes (next section). Removing the check_inputs call from the gate makes the input-refusal check fail.

Accuracy gate against the checkpoint

The recipe and its output summary, on b5562dea, with the local refset directory shortened to the family name:

just gate-gpu-qwen4exp-nvfp4
(l) plan card=GB10 ctx_max=3072 ubatch=3072 host_experts=0 card_experts=24576 layers short of 512 card experts: [] PASS
free hf-qwen4exp-nvfp4/hf_qwen4exp_nvfp4: 5 tokens, 0 route taps not the top 10 of their own logits, 36 flips (36 allowed), 112 outputs on a flip's path; worst l_out_rel off every flip's path 7.219e-3 at layer 19 position 4 (band 0.10); last argmax ours=11751 oracle=11751 logits_rel=8.401e-2 (printed) PASS
(p) the batch set by one pass: last argmax ours=11751 oracle=11751 logits_rel=8.401e-2 (printed) PASS
(g) the batch set by one ubatch: last argmax ours=11751 oracle=11751 logits_rel=9.377e-2 (printed) PASS
(t) hf-qwen4exp-nvfp4/hf_qwen4exp_nvfp4_d3k: position 3000 after 3000 ids by ubatches (2.9 s, runtime value); argmax ours=423 oracle=423 (its runner-up 11222, margin 1.6376, our distance at the two 0.2279); logits_rel 1.070e-1; worst l_out_rel 1.784e-1 (printed) PASS
gpu-gate.sh: gate_qwen4exp_nvfp4 ran 106 s (exit 0)

Clause (l) checks that every layer holds all 512 experts on the card. The free walk (5 tokens), clause (p) (one pass) and clause (g) (one ubatch) compare each layer and the logits with the oracle. Clause (t) compares position 3,000 of a 3,001-id prompt.

Writing the reference set again with this writer, in three sittings that resumed under one identity, gives 1,546 data files byte-identical to the first set. sha256sum -c over the family passes.

Clause Our argmax Oracle argmax Result
(p) the 5-id batch set by one pass 11751 11751 PASS
(g) the 5-id batch set by one ubatch 11751 11751 PASS
(t) position 3000 after 3000 ids 423 423 PASS

Our argmax token equals the oracle's in the one-pass, one-ubatch and 3,000-id clauses.

Short generation, main and this branch

On bf5238fd: generate_qwen3moe --prompt "The capital of France is" -n 64 --ctx 4096 --time on the NVFP4 split:

  • main: generate_qwen3moe: 144 tensors have no role: blk.0.ffn_down_exps.scale, ..., exit 1 (SHORT-RC main 1)
  • this branch: SHORT-RC head 0, 64 tokens, text " Paris. The capital of Germany is Berlin. The capital of Italy is Rome. ...", decode p50_ms=32.6501

The existing UD-Q4_K_XL path is unchanged

On bf5238fd, generate_qwen3moe built from main and from this branch, greedy, 64 tokens each, on the UD-Q4_K_XL GGUF. On GB10 that file also puts every routed expert on the card, so it goes through the new host-load path.

  • the 5-id batch set by one pass: IDS-EQUAL batch, PLAN-EQUAL batch
  • prose-en, 2,048 ids by one ubatch walk: IDS-EQUAL prose2k, PLAN-EQUAL prose2k, and a second run of each binary gives the same ids (IDS-REPEAT-EQUAL prose2k)

The only records that differ are main's four load host_tier type=... path=fused lines (q4_K, q5_1, q5_K, q8_0). This branch builds no host view for layers that have no host leg.

Speed (recorded, not a verdict)

bloomery-serve from this branch at bf5238fd, one server per file in one lease, prose-en prompts, greedy, draft off, 512 generated tokens. Each cell is one request without repeats, so the table is a record of this run only.

Arm NVFP4 split UD-Q4_K_XL
decode tok/s, 4,096-token prompt 30.26 28.32
decode tok/s, 16,384-token prompt 30.33 28.22
prefill tok/s, 4,096-token prompt 1,028.8 935.7
prefill tok/s, 16,384-token prompt 959.3 887.9
TTFT ms, 4,096-token prompt 4,088 4,393
TTFT ms, 16,384-token prompt 17,195 18,470
resident bytes 78,052,135,308 87,133,065,612

Hardware

A DGX Spark (GB10). The builds, the gate and the generate_qwen3moe runs used the CUDA 13.3.1 container. nvidia-smi in the gate job:

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

GPU: NVIDIA GB10, driver 595.84, CUDA 13.3

Models:

  • nvidia/Qwen3.8-Flash-Next-NVFP4 at revision fc694b54fb0174e0913e6adf86691ef85a4ead47, split by prepare into four GGUF shards; first shard sha256 513302fc64c400279d1ba3d5a86211a0dbe65dddc8c5e16c3516a0970d9a09b3.
  • Qwen3.8-Flash-Next UD-Q4_K_XL GGUF at revision 766911a6b7369840a91dbcd95f9f997acaab6cd6; first shard sha256 4448186216b3af4cc558bbce2c3213f01608f8f8b2e5267a9767971dd3ec8082.

What I ran into

None of this blocks the PR.

  • nvidia/Qwen3.8-Flash-Next-FP4-Local (revision b9ce18a6), generate_qwen3moe -n 16:
    • The split with Q8_0 dense weights and NVFP4 routed experts stops on main at 144 tensors have no role. With this branch it generates 16 tokens: [11751, 13, 561, 6511, 314, 9564, 369, 19241, 13, 561, 6511, 314, 14898, 369, 21047, 13], the same as the first 16 of the NVFP4 split.
    • The split that keeps the checkpoint's MXFP8 dense weights also stops on main at 144 tensors have no role. With this branch it gets through classification and the plan (host_experts=0 card_experts=24576), then Body38 refuses it: mxfp8 attention matrices (the body reads q8_0). Body38 reads MXFP8 dense weights in a later PR.
  • The site path (site::gemm, site::gated) still refuses NVFP4. A later PR extends StackW::route and the table kernels::gemm to it. The points it changes:
    • crates/gpu/src/site.rs:796: site::gemm returns no_wide_gemm for SiteTy::Nvfp4
    • crates/gpu/src/site.rs:929: Gated::check refuses NVFP4
    • crates/gpu/src/site.rs:168: SiteTy::reads, one input form per type
    • crates/gpu/src/site.rs:256: site::site knows DevWeight::Nvfp4 but not DevWeight::Nvfp4Stack
    • crates/placement/src/kernels.rs:265: SiteEntry::reads
    • callers in crates/gpu/src/arch/qwen3moe/wide.rs:1398 (slots_gemm) and :1442 (slot_site)
  • gate_qwen4exp_e2e was built but not run here, because its reference set and fixture are not on this machine. The reference routing code it now shares runs in gate_qwen4exp_nvfp4 above.

AI help

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

…n one card, every routed expert on the card, against its pinned oracle

The split prepare writes from nvidia/Qwen3.8-Flash-Next-NVFP4 holds its routed stacks in NVFP4 with one
tensor scale an expert. Every card leg loads such a stack in its planes (placement's leg_card_format,
which every leg's arm and the hybrid plan's card rule read) and Qwen3.8's leg admits it; the card's step
leg reads it through the NVFP4 `_sel` entries main already has. The prompt route reads every card stack
by the GEMM entry the kernel table names for its type (card_leg's StackW::route), so Qwen3.8's ubatch
route and its tier card's block route keep no type list of their own, and NVFP4's planes go through the
32-value GEMM over 32-value rows, which the ubatch route holds in place of the q8_1 rows the plan counts
(one input form a load). A layer whose experts all sit on the card has no host leg in the pass or the
ubatch walk either, and the host run holds no view of it (model::host_run over the other layers), so its
stacks need no host kernel; the expert ring and the tier card's block route refuse NVFP4 by name. A
format's tensor scale, `<stem>.scale` beside a `<stem>.weight` whose type reads one, takes its tensor's
layer in the shared classifier, so no family lists it.

gate_qwen4exp_nvfp4 holds the load, the batch set's steps, its pass and its ubatch walk, and D3K's step
to the checkpoint's own forward (refset hf-qwen4exp-nvfp4, tools/ref/qwen4exp-nvfp4-oracle.py, whose
route ids carry ik's logical twins) by the e2e gate's bands and its reading of the reference's routing,
which both gates now take from one file.
…old its positions, reuse the grouped mapping
@github-actions github-actions Bot added 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 placement Placement planning: crates/placement tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 20, 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 remaining dispatch-evidence request is non-blocking.

Non-blocking

⚠ Complete the dispatch proof: crates/gpu/src/arch/qwen3moe/wide38.rs:1164. The prompt route changes format dispatch. The grouped path retains one input quantization per run; each expert batch retains two gate/up GEMMs, one SwiGLU quantization and one down GEMM. Supply the move-class PTX comparison for the existing GGUF path and a same-lease base/head UD-Q4_K_XL A/B under R20. The speed table compares two formats at one head. Establish the regression baseline before another format uses this dispatch.

Checked

Duplicates: Dryer reported zero pairs in model, placement and refset. GPU and GPU-gates were outside its search.

Complexity: Diagnostics report CardRoute38::enqueue rising from 30 to 38. Its changed code adds format dispatch and ring refusals; complexity alone is not a finding.

Dispatch: Compared the cited hunk and enqueue_gemm_batch at base and head. The grouped path preserves the quantization and GEMM call sequence described above. Landing and ring batches can invoke the GEMM sequence more than once per run.

Error paths: CardRoute38::enqueue refuses incompatible route/input forms and unsupported ring combinations before entering the run loop.

Gates: FREE_BAND remains 0.10 and FLIP_ERR_CAP remains 2.0 in shared/q38_oracle.rs, with their existing dated PINs.

Classification: The review rules classify missing change-class performance evidence as a non-blocking request. No escape pattern or ledger lesson changes that classification.

Notes

Validation used source and diff inspection. GPU results are the PR's reported GB10 runs. The PR states that gate_qwen4exp_e2e was built but not run.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/Cargo.toml, crates/gpu-gates/src/bin/gate_qwen4exp_e2e.rs, crates/gpu-gates/src/bin/gate_qwen4exp_nvfp4.rs … and carries a gate run on the author's card, which counts as verified.

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

@github-actions github-actions Bot added gpu-evidence Verified on the author's card: the pull request carries the gate run and its output and removed needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 20, 2026
@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

gpu The card engine: crates/gpu*, crates/app gpu-evidence Verified on the author's card: the pull request carries the gate run and its output 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 placement Placement planning: crates/placement 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