Skip to content

placement, gpu: a routed MXFP4 down off the 256-value super-block reads the 32-value form, MXFP8 planes take ceil(K/128) scale words, and V4.1's FFN holds only the forms its downs read - #1154

Merged
midagedev merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-tp4-pr1b
Nov 3, 2026

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

MXFP4 down 행렬의 K가 256으로 나누어떨어지지 않아도, MXFP8 가중치의 K가 128로 나누어떨어지지 않아도 카드에서 거부되지 않고 돌아가도록 고쳤습니다.

What and why

A routed MXFP4 down projection whose K is not a multiple of 256, and an MXFP8 weight whose K is not a multiple of 128, were refused on the card. This PR lets both run. The down projection reads the 32-value activation form when K is off the 256-value super-block (kernels::down_act), the MXFP8 planes hold ceil(K/128) scale words per row, and V4.1's FFN allocates only the activation buffers its layers read, so a rank whose FFN width is 576 or 1,152 loads. The grouped MXFP8 wo_a and the Engram MXFP8 table rows get arms over the existing kernels.

Release notes: Fixed: routed MXFP4 downs and MXFP8 weights with a K off 256 and 128 now run on the card instead of being refused, and V4.1's FFN buffers follow the forms each layer reads.

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": crates/gpu-deepseek41/src/chain/glue.rs:611 resembles :534 and :572. The MXFP8 table-row kernel has its own entry like the Q8_0 and IQ4_NL ones; they share a ten-line thread-to-value map, and each body calls its own decode with its own block bytes. Folding them would put a runtime format switch into the two existing kernels. The first version of the 32-value MXFP4 down kernel was a copy of mxfp4_gemv_sel; it is now that one kernel with a scale shift.

What I ran

Base c7f21a7d28087a95abfc7d7cb1c69dea37781090, PR head 8dddfab7f2ca0218498c1b84ec60445b05345288. Card: RTX 5090 (see Hardware). Model: the V4.1 fixture GGUF v41-fixture-00001-of-00004.gguf.

Lint, on a DGX Spark, the PR head:

cargo clippy --workspace --all-targets --features gpu,bloomery-metal/pipeline-scan,bloomery-metal/encode-trace,bloomery-gpu-gates/deepseek41,bloomery-gpu-gates/vision,bloomery-gpu-gates/glm5next,bloomery-gpu-gates/mimo2,bloomery-gpu-gates/solar2,bloomery-gpu-gates/minimaxm3,bloomery-gpu-gates/flint,bloomery-gpu-gates/gemma-embedding2,bloomery-gpu-gates/gemma4a,bloomery-gpu-gates/mistrallarge4,bloomery-gpu-gates/clef,bloomery-gpu-gates/hf,bloomery-gpu-gates/glm5next-hf,bloomery-gpu-glm5next/hf,bloomery-decision/safetensors
lint rc 0 (^warning: 0, the ratchet 0 in tools/lint-ratchet.txt)

Each fix has a test that detects its absence. For the PR head, the BF16 to MXFP8 conversion's scale row stride was set to row * (k / 128) (the old rule), then restored (git checkout, git diff --exit-code):

./tools/box.sh "bash tools/gate.sh --gpu --oxide -p bloomery-gpu --release --lib -- --include-ignored q8f32::tests::bf16_head_encoding_refuses_bad_shapes_and_non_finite_values"
test q8f32::tests::bf16_head_encoding_refuses_bad_shapes_and_non_finite_values ... FAILED
  left: [1852664939, 1920036975, 1987409011, 2054781047, 2155839103, 2223211137, 2290583173, 2357955209, 36493, 0]
 right: [1852664939, 1920036975, 1987409011, 2054781047, 31867, 2155839101, 2223211137, 2290583173, 2357955209, 36493]
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 491 filtered out; finished in 0.00s

./tools/box.sh "bash tools/gate.sh --gpu --oxide -p bloomery-gpu --release --lib -- --include-ignored q8f32::tests::bf16_head_encoding_refuses_bad_shapes_and_non_finite_values mxfp4_sel::tests::hw_card_k_units_are_the_layouts_own"
test q8f32::tests::bf16_head_encoding_refuses_bad_shapes_and_non_finite_values ... ok
test mxfp4_sel::tests::hw_card_k_units_are_the_layouts_own ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 490 filtered out; finished in 20.37s

hw_card_k_units_are_the_layouts_own runs the MXFP4 down at K 576 over the 32-value form and compares bit for bit with the host rule; the id past the stack faults.

V4.1 and MXFP8 gates. The mutants were the MXFP8 row decode without its undefined-byte check, and mxfp8_gemv's block diagonal reading window 0 for every group; both were restored afterwards:

./tools/box.sh "bash tools/gate.sh --gpu --oxide -p bloomery-gpu-deepseek41 --release --lib -- --include-ignored hw_glue_rows_decode_as_the_file_decodes_them hw_mxfp8_dense_is_the_byte_rule_at_a_k_tail"
test dense::tests::hw_mxfp8_dense_is_the_byte_rule_at_a_k_tail ... FAILED
test chain::glue::tests::hw_glue_rows_decode_as_the_file_decodes_them ... FAILED
MXFP8 scale: value 5 decoded to inf
MXFP8 scale: raised None
MXFP8 value: value 5 decoded to 480
MXFP8 value: raised None
MXFP8 product: value 5 decoded to inf
MXFP8 product: raised None
test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 44 filtered out; finished in 22.22s

just gate-gpu-ds41-lib
test result: ok. 46 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 22.14s

./tools/box.sh "bash tools/gate.sh --gpu --oxide -p bloomery-gpu --release --lib -- --include-ignored q8f32::"
test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 485 filtered out; finished in 0.00s

just gate-gpu-mxfp8
mxfp8 clause=plane-shape case=k-tail-wide tile=Err(Shape { what: "Gemm32Kernels::enqueue_e4m3_tile", detail: "E4M3 planes of k=576: this entry reads whole 128-value records" }) mma=Err(Shape { what: "Gemm32Kernels::enqueue_e4m3_mma", detail: "E4M3 planes of k=576: this entry reads whole 128-value records" }) PASS
mxfp8 clause=head.bits rows=19 k=128 m=1 equal=19/19 PASS
mxfp8 clause=head.bits rows=19 k=128 m=3 equal=57/57 PASS
gpu-gate.sh: gate_mxfp8 ran 29 s (exit 0)

just gate-ptx-spill
ptx-spill bin=gate_qwen3vl_tower entries=28 pinned=28 nonzero=none violations=0 PASS

The prompt batch and the expert tier follow the same rule (each makes only the buffers its layers read). A mutant that made the batch's shared q8_1 scratch for every file is caught by its test; with the mutant restored the V4.1 lib runs:

./tools/box.sh "bash tools/gate.sh --gpu --oxide -p bloomery-gpu-deepseek41 --release --lib -- --include-ignored hw_a_ranks_ff_makes_only_the_forms_its_downs_read"
test chain::ffn::batch::tests::hw_a_ranks_ff_makes_only_the_forms_its_downs_read ... FAILED
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 46 filtered out; finished in 21.99s

just gate-gpu-ds41-lib
test result: ok. 47 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.29s

Real binary, bloomery-serve on the V4.1 fixture on the one card ($FIXTURE_MODEL is the fixture GGUF above, from tools/ref/ref-paths.sh), then one completion of 16 tokens:

BLOOMERY_MODEL=deepseek41 BLOOMERY_TIER=fixture target/release/bloomery-serve -m "$FIXTURE_MODEL" --port 18473 --ctx-size 4096
load resident_bytes=6396974908 ctx=4096 layers=9 top_k=512 shadow=host 37748736 unified_addressing=1 cards=[NVIDIA_GeForce_RTX_5090] prefill=batch mode=graph place=a pin_main=on pinned=true in 3.1 s (runtime value)
bloomery-serve-ds41: place=a ctx=4096 listening on http://127.0.0.1:18473
POST /completion {"prompt": "The capital of France is", "n_predict": 16, "temperature": 0, "cache_prompt": false}
prompt_n 5 predicted_n 16 content '水箱 је diferente反正 conscience THREE感染のではない惊奇 Appalach得益 resisting hurtsnten亲情拎'

The fixture has random weights, so the text is noise; the run shows that the load, the prompt batch and 16 decode steps complete.

Hardware (if the change is for a machine)

RTX 5090 for the gates and the bloomery-serve run above; a DGX Spark for the clippy run. nvidia-smi on the RTX 5090, PR head run:

$ nvidia-smi
Tue Nov  3 21:09:39 2026       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 595.99.02              Driver Version: 595.99.02      CUDA Version: 13.2     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 5090        Off |   00000000:01:00.0  On |                  N/A |
|  0%   42C    P8             15W /  400W |      34MiB /  32607MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+

$ nvidia-smi --query-gpu=name,driver_version --format=csv,noheader
NVIDIA GeForce RTX 5090, 595.99.02

AI help

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

…ds the 32-value form, MXFP8 planes take ceil(K/128) scale words, and V4.1's FFN holds only the forms its downs read

A tensor-parallel rank's part of V4.1's 2,304-wide experts is 1,152 or 576 values, no whole number of the q8_1 super-block.

- placement: `kernels::down_act(ty, k)` picks a down's activation form by its K (its entry's at whole 256-value super-blocks, else the 32-value `Q8Blocks32`); `card_k_unit` gives 32 to the downs that read that form, MXFP4 among them, and lets MXFP8 planes take their 32-value block. Every card leg's buffers and launch take the form from there (`LegStacks::down_act`).
- gpu: `mxfp4_gemv_sel32`, the MXFP4 down `_sel` over a `Q8Blocks32` (`lane_partial_file` at one scale a block), as the leg's arm for that form.
- gpu: MXFP8 planes hold `ceil(K/128)` scale words a row, the last padded with zero; the splitter, the upload, the joined rows, the size budget and the gemv read that one contract, and the wide tiles refuse a K off 128 by name. A K of whole 128-value records keeps its bytes.
- gpu-deepseek41: `FfnRow` allocates the q8_1 columns only where a layer reads them; the `ff % 256` refusal becomes each down's own K unit. `Dense` runs an MXFP8 projection on the common E4M3 gemv, and an engram table of MXFP8 rows decodes on the card (`ds41_glue_engram_rows_mxfp8`).
@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 tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Nov 3, 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 reachable behavior defect or actionable quality defect survived review.

Non-blocking

⚠ Supply the dispatch-path timing proof: crates/gpu/src/q8f32.rs:2350.
The shared MXFP8 kernel adds a row division, group guard and input offset; ordinary one-column GEMV still calls it at crates/gpu/src/q8f32.rs:3496. AGENTS.md's Measuring section requires a same-lease A/B for dispatch changes. The body reports functional gates and spill checks, but no A/B. Attach decode and prefill results on the contributor's card, with both commits, model, commands and output.

Checked

  • Duplicates: 39 new functions, types and constants checked by search, including test constants; no actionable duplicate. The Engram kernels share indexing shape but decode different formats. No dryer pairs were available.
  • Complexity: crapper supplied no results. FFN host branches select required scratch; kernel growth changes scale strides and group indexing. No kernel split is needed.
  • Silent failure: four new defaults/error conversions followed to consumers; malformed layouts are refused. Invalid MXFP8 bytes and expert IDs raise named device faults.
  • Tests: static mutation checks cover old scale strides, type-only down forms, unconditional scratch, dropped byte checks, a dropped group offset and equal division of resident bytes. Assertions detect these mutations. GPU tests were not rerun here.
  • Gates: changed shape refusals and ratchets carry dated PIN reasons. No numeric tolerance was relaxed.
  • Escape catalog: no C1–C4 pattern matched. Boundary scenarios checked MXFP8 scale tails, MXFP4 partial windows, invalid IDs and a rank pool one byte short.

Notes

Dryer and crapper did not run because their Python modules were missing.
The reported RTX 5090 gate evidence names head 8dddfab7, while this review covers 031d1a74; refresh the evidence for the reviewed head.

Card check: gpu-evidence. This pull request changes crates/gpu-deepseek41/src/body/prefill.rs, crates/gpu-deepseek41/src/chain/attn.rs, crates/gpu-deepseek41/src/chain/ffn.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 Nov 3, 2026
@midagedev
midagedev merged commit 6490d03 into midagedev:main Nov 3, 2026
7 checks passed
@midagedev

Copy link
Copy Markdown
Owner

@juliankang4 Merged, thank you. On sm_86 the one red was gate-ptx-spill: mxfp8_gemv_ids in generate_ds41 now spills 16 B and uses 8 B of jit local, below its pins of 60 and 24. We lowered the pins in 691109b. The rest of the fixture batch runs next.

(Written by an AI coding agent.)

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 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.

2 participants