Skip to content

gpu, hf: Nemotron-H ModelOpt body sites (NVFP4 GEMM/GEMV/head, FP8→Q8_0 at load) - #928

Merged
midagedev merged 3 commits into
mainfrom
nvhr2-land
Oct 28, 2026
Merged

midagedev merged 3 commits into
mainfrom
nvhr2-land

Conversation

@midagedev

Copy link
Copy Markdown
Owner

What and why

Second step for NVIDIA's Nemotron-H ModelOpt folders (after #921). The body now runs the sites the folder brings: NVFP4 in the wide GEMM (site::gemm), NVFP4 at any K through the sel32 GEMV, an NVFP4 head, and FP8/BF16 weights re-quantized once to Q8_0 at load (Use::Q8_0). An FP8 scale past F16's range is refused by name.

Release notes: internal — the folder does not open end to end yet (the relu² NVFP4 expert leg and the folder seat are the next steps).

Code shape

  • No second copy. NVFP4 joins the existing site::gemm table and HeadEntry; FP8→Q8_0 is one Use kind in crates/hf.
  • Model code holds only architecture facts. nemotron_h.rs only routes its tensors to the shared kinds.
  • Dead code is gone.
  • No silent failure. An FP8 row scale F16 cannot hold is a named refusal (test an_fp8_weight_read_as_q8_0_is_its_exact_values_quantized_once).
  • Comments state what is true now.
  • No relaxed gate. New clauses: nvfp4_site_k64_through_sel32 (gate-gpu-nvfp4), nvfp4_head_k2688 (gate-gpu-head).
  • cargo fmt and cargo clippy are clean on what I touched.

Duplication found or removed: none.

What I ran

  • tools/narrow-scan.sh: the four --no-jit ptx-scans equal to the base; 152 gates selected.
  • tools/gate-batch.sh --tier fixture --ledger, 176 items: red 3. Two (gate-gpu-glm5next-e2e@iq4xs, gate-gpu-qwen4exp-e2e) were cannot read the binary containing the CUDA artifact anchor (a parallel rebuild); alone they ran DONE total=2 red=0. The third, gate-gpu-qwen38-serve (slots_default_residency_*), is red on main too and is fixed separately.
  • gate-hf: 116 passed; clippy 0 warnings.

Hardware

The maintainer's box: RTX 3090 and RTX A6000 (sm_86). The NVFP4 sites here are the sm_86 path; the native sm_120a/sm_121a block-scaled path is #925/#926.

🤖 Generated with Claude Code

midagedev and others added 2 commits October 29, 2026 00:55
…mm, NVFP4 at any K by sel32, an NVFP4 head, FP8/BF16 re-quantized to Q8_0 at load

- `Use::Q8_0` (crates/hf/src/modelopt.rs) is a new kind: a quantized or BF16 source quantized again to Q8_0 at load.
  An FP8 block's value (e4m3 times its block scale) is decoded exactly, then quantized by gguf's Q8_0 rule. The
  Nemotron-H map routes the embedding, the attention and the FP8 mamba in/out projections through it, so every card
  runs them on one INT8 path.
- The NVFP4 wide GEMM moves from nemotron_h_moe's prefill into `site::gemm`'s NVFP4 row: one owner, which
  Qwen3.8-27B NVFP4 will use as well.
- An NVFP4 dense site whose K is not a multiple of 256 (Lightning: 2688, 3712) runs the one-expert sel32 GEMV on
  Q8 blocks of 32 (`SiteEntry::reads_at(k)`, `card_k_unit_at`). Today's kgemv keeps every multiple of 256.
- `HeadEntry::Nvfp4` / `OutW::Nvfp4` with the same split by K.
- New gate clauses: `gate-gpu-nvfp4` `nvfp4_site_k64_through_sel32` and `gate-gpu-head` `nvfp4_head_k2688`.
- R1's "opened as stored" pin moves to Q8_0 (PIN line).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and a scale past it is refused by name

The fixture's row scales reached 2^15, so row 26's Q8_0 block scale left F16 and the conversion refused it, as it
must; the scales now run from 2^-15 to under 1, and a separate case pins that refusal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app 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 labels Oct 28, 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: MUST_FIX: card_k_unit_at is dead code, and its test repeats the test in site.rs.

Must fix

1. Remove the unused card_k_unit_at and its duplicate test

crates/placement/src/kernels.rs:414 is a new pub fn. Grep over the whole PR tree finds it only in kernels.rs: its definition and the test a_dense_nvfp4_site_reads_by_its_width (kernels.rs:891). No card code, planner or body calls it, so the K unit it computes changes nothing. The test's reads_at half pins what an_nvfp4_site_reads_the_form_its_width_takes (site.rs:2137) already pins, with the same FAIL-first mutant. The rest of the test only guards the dead function.
Cost: an unused pub function reads as a contract. The next author will assume the planner uses it. Wire it in when the folder seat needs it.
Fix: delete card_k_unit_at (from kernels.rs:409, including its doc comment) and the test a_dense_nvfp4_site_reads_by_its_width. Keep the PIN(2026-10-28) line above head_admits_exactly_the_pinned_pairs.

Non-blocking

⚠ The new sel32 route is unreachable from the Nemotron-H body: body.rs:197 refuse_widths still reads s.ty.reads(). For an NVFP4 site of width 2688 it answers Q8x128 and refuses the load: "a form of 256 values takes a width that is a positive multiple of 256". The decode branch in project_rows (prefill.rs:695) would also fail at width 2688 ("no q8_1 run form"). The refusal is by name, and the PR body says the folder does not open yet. Still, refuse_widths should use s.reads() in the same step as the route, or the next PR should name it as its first item. Only the gate binaries exercise sel32 today.

⚠ A comment in gate_head_gpu.rs:261 (the NVFP4_BAND doc) says "a block's largest value a value", which is garbled. Rewrite it so the 3 % band's derivation can be checked. 0.4 % is quoted without conditions; mark it [derived].

Checked

  • Duplicates: 9 new items checked (reads_at ×3 layers, card_k_unit_at, nvfp4_sel32_gemv, fp8_q8_0, TokenRows, not_gated, Nvfp4Head). Hit: card_k_unit_at (dead). dryer: 0 pairs. crates/gpu and crates/gpu-gates were not searched by dryer, so I Grepped them by hand.
  • reads_at appears at three layers (gguf, gpu site, placement). The gguf and gpu ones are used, and the placement one is the dead card_k_unit_at.
  • Complexity: Head::enqueue_over 29→42 and Head::with_gain 26→32 are branch growth from one more OutW arm, and the arm holds one owner's call sequence. site::gemm 41→45 is a new match arm (even growth). nvfp4_head::run (26) and sel32_case (21) are gate bodies, so no split is needed. normalize 17→18 is one arm.
  • Silent failure: 7 sites followed (fp8_q8_0 scale refusal, Nvfp4Head missing-kernels states, act32 missing form, nvfp4_sel32_gemv type, weight and column refusals, kept_file role check). All raise a named error. The Role::Rows checks in folder.rs keep the old refusal.
  • Hot path: the decode head. No new allocation per step: TokenRows is built at load, and the new arm only launches. The sel32 gemv's sum order is its own gate's (bits_equal). No ptx-scan proof is needed beyond the one in the PR body.
  • Tests: an_fp8_weight_read_as_q8_0_is_its_exact_values_quantized_once: protects the scale and rounding in fp8_q8_0. Mutant "scale not applied" or "one-block scale for all blocks" turns the exact-bytes assert red. Mutant "no refusal on a scale past F16" turns the unrepresentable scale assert red. nvfp4_head_k2688: mutant "the head skips the tensor scale" scales every logit by 1/0.3719, far outside the 3 % band, so in_band turns red. Mutant "no token-major copy" differs from the one-row heads in the three-row clause, so rows_equal turns red. I did not run either.
  • Gates: one pin moved (modelopt open-as-stored types, PIN(2026-10-28) with reason and FAIL-first). One head-entry pin added with a date. No band loosened.
  • Escape catalog: no match (no shell changes).

Notes

  • Speed claims: none made. Hardware evidence in the PR body names cards in words only, with no nvidia-smi line, commit hashes or gate output, so gpu.json carries evidence: false.

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

…hecks a site's width by the form it reads at that width

`card_k_unit_at` had no caller and its test repeated the site test's
`reads_at` pin. `refuse_widths` now reads `Site::reads`, so an NVFP4 site at a
width that is not whole 256-value blocks is checked against the 32-value form
the sel32 route reads. The NVFP4 head band's comment says what bounds the
rounding.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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 new commits delete the dead card_k_unit_at and its test, route refuse_widths through Site::reads, and fix the band comment. No kind A or B defect is left in them.

Non-blocking

⚠ Load and prompt path disagree for NVFP4 at a width that is no multiple of 256: body.rs:198 now admits it (s.reads() answers Q8Blocks32) and decode runs it (hybrid.rs:517). The prompt path does not: PassSizes pushes every NVFP4 width into run_k (prefill.rs:240), and Q8Act::with_k refuses a width that is no multiple of 256 (tensor.rs:807). So a width of 2688 loads, then the first prompt pass ends on a named shape error, where the load used to refuse it. project_rows (prefill.rs:695) has the same gap. The error is named and the folder does not open yet, so this is not a must-fix. Next PR's first item: run_k takes only Form::Q8x128 widths, and the NVFP4 arm of project_rows calls site::nvfp4_sel32_gemv for the others.

Checked

  • Duplicates: 0 new items (the new commits only delete and re-point). No reference to card_k_unit_at remains. dryer: 0 pairs.
  • Complexity: no flagged function changed in the new commits.
  • Silent failure: 1 site followed (refuse_widths); its result is the named error above, not a wrong output.
  • Tests: an_nvfp4_site_reads_the_form_its_width_takes (site.rs:2137) still pins reads_at at 2688 and 4096.
  • Gates: no pin moved. The NVFP4_BAND comment now says [derived].
  • Escape catalog: no match (no shell changes).

Notes

  • Since the last review: must-fix 1 (card_k_unit_at) is fixed. ⚠ 1 (refuse_widths read s.ty.reads()) is fixed in body.rs, but the prompt path is still open (above). ⚠ 2 (band comment) is fixed.
  • The PR body carries no nvidia-smi line, commit hashes or gate output, so gpu.json has evidence: false.

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

@midagedev
midagedev merged commit 645c6af into main Oct 28, 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 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant