Skip to content

q8f32: an MXFP8 gemv of five to eight columns runs the staged walk over an eight-column stage - #1106

Merged
juliankang4 merged 4 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-next-pass-cols
Nov 1, 2026
Merged

juliankang4 merged 4 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-next-pass-cols

Conversation

@juliankang4

@juliankang4 juliankang4 commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Qwen3.8의 MTP 검증과 2요청 디코드에서 쓰는 여러 열 GEMV 세 가지가 가중치를 한 번만 읽도록 바꿔 처리량을 조금 높였습니다.

What and why

Three kernels that multi-column decode steps use (an MTP verify, or two parallel requests) now load each weight unit once for every row or column that needs it:

  • hc_gated: the up projection mixes each column as soon as its four partial sums are reduced.
  • nvfp4_gemv_sel32_cols (the multi-token NVFP4 routed down): a warp takes four rows of a slot and reads each column unit once for them. Per row, the lane assignment, unit order and reduction match the single-token entry, so results are bit for bit the same.
  • mxfp8_gemv_mcol_staged_wide (new entry): an MXFP8 gemv of five to eight columns runs the existing staged walk over an eight-column stage. The four-column entry is unchanged.

Release notes: Changed: Qwen3.8 NVFP4 and MXFP8 multi-column decode steps read each weight once per step, which raises two-request decode throughput on a DGX Spark.

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 two MXFP8 staged entries share one body, blocks_gemv_mcol_staged in crates/gpu/src/q8f32.rs.

What I ran

Upstream base 55e23f17be68bcfddf090d37046c5f80503842f3, PR head 92eb943d153ff2076cf026816eeaac1efa494769. The runs below are on GB10 DGX Spark machines, see Hardware.

Card:

$ nvidia-smi
Sun Nov  1 18:14:53 2026       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
+-----------------------------------------+------------------------+----------------------+
| 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 GB10                    On  |   0000000F:01:00.0 Off |                  N/A |
| N/A   55C    P8              4W /  N/A  | Not Supported          |      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 GB10, 595.84

Gates for the changed kernels (BLOOMERY_ARCH=sm_121a BLOOMERY_BOX_LOCAL=1 just <gate>):

GATE gate-gpu-nvfp4 rc=0 PASSLINES 92 FAILLINES 0
GATE gate-gpu-mxfp8 rc=0 PASSLINES 484 FAILLINES 0
GATE gate-gpu-hc-gated rc=0 PASSLINES 231 FAILLINES 0
GATE gate-gpu-bf16 rc=0 PASSLINES 307 FAILLINES 0
GATE gate-gpu-ple rc=0 PASSLINES 49 FAILLINES 0

The new 5 to 8 column MXFP8 path and the four-row NVFP4 down are bit-checked against the one-column walk:

nvfp4 clause=routed_down bits equal=12800/12800 PASS
mxfp8 clause=gemv.bits shape=blk.3.attn_q_b rows=16384 k=1536 m=6 equal=98304/98304 PASS
mxfp8 clause=gemv.bits shape=tail.r9 rows=9 k=512 m=7 equal=63/63 PASS

PTX spill check (just gate-ptx-spill) on the generate binary:

ptx-spill bin=generate_ds41 entries=527 pinned=527 ... violations=0 PASS
SPILL rc=0

MTP draft gate, fixture tier (env BLOOMERY_ARCH=sm_121a BLOOMERY_BOX_CARD=local BLOOMERY_TIER=fixture just gate-gpu-qwen4exp-mtp):

clauses: 28 ran, 4 left to the real tier
gpu-gate.sh: gate_qwen4exp_mtp ran 364 s (exit 0)

Model: nvidia/Qwen3.8-Flash-Next-FP4-Local, revision b9ce18a6887e18c089fdea8509a33e63429a3300. MODEL_FP4L below is the folder holding these files (SHA-256, then path):

b0ad2a8a314ca96618e21e40d50c0af6e181e6060f9cdd1996c7074d19284c1a  README.md
c3cf9e34abf4f9e36c2d72165aa9c132d3e2a725b6c2586aaa3a8af9d7a81041  chat_template.jinja
b50dbc52a0c83b0cd2a44a372c1fb6b5e0e6827d22f2611c97d4d030f92f6b28  config.json
e70c136c1b78ddc1fb0905bac8e733a4dc448d4f852a5dd75143fffc70be550e  generation_config.json
a9d356d7bdf1ef4949e3e748e95b8e10ad9d4e2e838eddc38a0a7b6b94d1db8d  merges.txt
5fa166bbb1cf25adda455117563efa72a2072272001f459eedece131ffc913e1  model.safetensors.index.json
27225450ac9c6529872ee1924fcb0962ff5634834f817040f444118116f4e516  preprocessor_config.json
ebf3648c5f4cd1f24e79789e7803498dc4e74cb52515cc515b2d22cf8161953b  tensors/model-00001-of-00021.safetensors
79a643fc5c024089cecd32ca27dc43e671cbec70ff3628b728909b7656ac43ec  tensors/model-00002-of-00021.safetensors
c45f942203db4c7f5a1071700b93b908495cc790271acddfff39091c2b953923  tensors/model-00003-of-00021.safetensors
071ab9cf963ca0f1a6a194b4cec485f5de18ef9804da915b2e6abd0eb0c707af  tensors/model-00004-of-00021.safetensors
f80d17870eb1d36917257494770984953476583c57737f61fdbd341c957b9715  tensors/model-00005-of-00021.safetensors
3e9183d4ebb267fa92429184d5132d302cb1a98fd049149e5d01dccd4ca65795  tensors/model-00006-of-00021.safetensors
aa1ad959c4d62e0bc4600fd0b57cc2939b463e9fb53dc01020e188552b52ce5a  tensors/model-00007-of-00021.safetensors
0b18844027be74b84b240f23bf3a744bc29b35de0bd384f41c40cd85e6339326  tensors/model-00008-of-00021.safetensors
2d0b6c66790c17f8b1fdcf442f541778c8f0a381aca26c11b9d7cfcf7c96f2f0  tensors/model-00009-of-00021.safetensors
3ed9bd73745aebf6dc136f437b67d6b9fc3d38d25ad84300b399164bc87a72b7  tensors/model-00010-of-00021.safetensors
4936ff28c6cc8b66653ddb9cae28bc284569a1a2f7116819a017dc1a0e517ed8  tensors/model-00011-of-00021.safetensors
dd7df5a6ff73e9960412243f744eab9ec35f4be40da5bb158dc4ba8796b33742  tensors/model-00012-of-00021.safetensors
28a455c8ea4ebaa847fb4cbed2bc1de9eff0b501dd3f848a3a3cfc38778e8500  tensors/model-00013-of-00021.safetensors
6941676e685abf9817d9c48a17fdeda20b2b72d16217555252aa4c602b7f98b8  tensors/model-00014-of-00021.safetensors
2a1129b5acfc24a45bf402aa63dcef08b531aedfdaf5233c65fd3d12dc303fdd  tensors/model-00015-of-00021.safetensors
635e97fbad78fa988647d407e2b58e55d551ef94d798c9b6fb5550de25e86429  tensors/model-00016-of-00021.safetensors
bf60d564d89a805b67f8be5f2847a1b1567a70dbc23d19754395c127568474ad  tensors/model-00017-of-00021.safetensors
c5bde22f9364e82eb25973456795592fdcb4b158bc2095898979a2566bf4c562  tensors/model-00018-of-00021.safetensors
da3dc3b4f428f5b9dd53362691043d0242f48d03adca9b7b553bd9f3a1e96350  tensors/model-00019-of-00021.safetensors
4978bb6b8480cfc02d3c8bc84ba86202889f5f10d090bb17c21fee663cea7683  tensors/model-00020-of-00021.safetensors
48203838f2c76921bddbf1cc51d20a23858c128821a21add55fa1778e5e25283  tensors/model-00021-of-00021.safetensors
0997f410c57a1f4e53b09e4be8f4a172d90edd9564368fb0847030937229b9f3  tokenizer.json
b11349aafa7cdc6a320767cf7ceb29ed82f7eda5d65e8e0819e76f0ce947bf27  tokenizer_config.json
7768af27c1fafa9cc9011c1dc20067e03f8915e03b63504550e11d5066986d13  video_preprocessor_config.json
ce99b4cb2983d118806ce0a8b777a35b093e2000a503ebde25853284c9dfa003  vocab.json

Speed A/B on the real server, base build against head build, same shipped feature set. Build, then serve and one timed client round for the two-request, no-draft arm (the base run uses ./base/target/release/bloomery-serve):

(cd head && cargo oxide build --arch "$(bash tools/arch.sh)" -- -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve)
env BLOOMERY_DRAFT=off BLOOMERY_HOST_ROOM=96G ./head/target/release/bloomery-serve -m "${MODEL_FP4L}" --host 127.0.0.1 --port 18731 --parallel 2 --ctx-size 16896 & server_pid=$!
client.py load --port 18731 --ids "${CODE_IDS}" --prompt-len 4096 --n-predict 128 --count 2 --conc 2 --offset 0 --bound 0 --label fp4l-off-c2s-1 --temperature 0.7 --out fp4l-off-c2s-1-timed-code-fn-client.jsonl --seed 42 --window-plan sitting-windows.json --eos-shift 1024

The MTP arms start the server with BLOOMERY_DRAFT=mtp BLOOMERY_MTP_WIDTH=cost (with env -u BLOOMERY_MTP_DRAFT). The one-request arms use --parallel 1, --count 1 --conc 1 and --temperature 0 without --seed. Prompt length 4096, 128 new tokens, eight windows of the corpus, medians of three rounds per side. ${CODE_IDS} is the code corpus; the prose arms use the prose corpus.

Arm Base Head Difference Ranges overlap
1 request, no draft, code, decode tok/s 31.70 31.83 +0.43% yes
1 request, MTP, code, decode tok/s 59.00 60.46 +2.49% no
1 request, MTP, prose, decode tok/s 41.24 41.79 +1.35% yes
2 requests, no draft, code, decode tok/s 21.96 22.08 +0.58% no
2 requests, no draft, code, total tok/s 38.14 38.44 +0.79% no
2 requests, MTP, code, decode tok/s 33.59 34.83 +3.67% yes
2 requests, MTP, code, total tok/s 47.74 51.24 +7.34% yes
2 requests, MTP, prose, decode tok/s 26.38 27.04 +2.50% yes
2 requests, MTP, prose, total tok/s 40.66 43.29 +6.46% yes

Every difference above is positive. The total tok/s of the two-request, no-draft arm is the one result whose range does not overlap the base's and that lies above the run-to-run resolution (0.72%). The other differences are inside the resolution of their runs.

Hardware (if the change is for a machine)

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

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 tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Nov 1, 2026
…ms are reduced

up_mix_value and up_mix_value_bf16 kept every column's four reduced sums
in a [STREAMS][MAX_COLS] array until lane 0 mixed them all at the end, so
the m-column entries held 32 sums beside the row's weights and took a
block of 512 threads a SM. Lane 0 now mixes column c (mix_col) right after
its sums are reduced; the sums, their order and the stores are the same.
…reads each column unit once for them

nvfp4_gemv_sel32_cols ran one row a warp, so every warp of a verify's
slots paid the id read, the first-slot check and the ballot walk for one
row of 20 units (K 640), and a duplicate slot's warp paid them to return.
A warp now takes four rows of its slot: those costs and the duplicate
warps fall by four, and each column unit is read once for the four rows.
Each row keeps its lanes, its unit order and the butterfly, so it is
nvfp4_gemv_sel32's bit for bit.
…er an eight-column stage

The staged walk read each step's activations once a block into shared
memory only at four columns; five to eight columns (two sequences'
verify rows) ran the unstaged walk, which reads them once a row. The
walk now takes its stage width as a parameter: the four-column entry
keeps its stage, and mxfp8_gemv_mcol_staged_wide runs five to eight
columns over a stage of eight with the columns past the launch's idle.
Column c stays the one-column walk's bit for bit. gate_mxfp8 adds six
columns at attn_q_b and seven at the nine-row tail.
@juliankang4
juliankang4 force-pushed the dgx-spark-q38-next-pass-cols branch from 8ac2641 to 92eb943 Compare November 1, 2026 22:33

@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 findings are non-blocking evidence requests and optimization advice.

Non-blocking

⚠ Supply the geometry proof: crates/gpu/src/q8f32.rs:2482.
For m=5..8 with aligned activations and k a multiple of 512, staging adds 8,192 shared bytes per block [derived: 2 × 8 × 128 × 4].
The body includes a timed A/B and spill totals. Attach before/after PTX resource rows and the occupancy calculation from registers, shared memory, threads and SM count required by the occupancy/geometry class.

⚠ Show the added cases failing on a mutant: crates/gpu-gates/src/bin/gate_mxfp8.rs:159.
The added six-column and seven-column cases reject omitted col!(5) and col!(6) dots through their host-bit comparisons.
Attach a FAIL-first run with those omissions; the body contains only passing output.

Optimization headroom

  • D. More at once: crates/gpu/src/mxfp4_sel.rs:1694. Each matching slot reloads the same weight units. Reuse decoded units across matching slots to remove 20(h−1) requested plane bytes per row per 32-value unit for h matching slots [derived: 16 code bytes + 4 scale-word bytes per load].

Checked

Duplicates: the staged entries share one body. Dryer reported 0 candidate pairs.
Complexity: nvfp4_gemv_sel32_cols 10→15 adds row reuse inside a kernel; enqueue_e4m3_gemv 26→30 adds staged dispatch guards.
Silent failure: the NVFP4 tail minimum selects live rows; staged dispatch checks activation alignment and k before the vector view.
Tests: the added m=6 and m=7 cases compare every output with the host rule. Omitting q8f32.rs:1683 or :1684 leaves the corresponding column's accumulator zero.
Gates: no accuracy band relaxed; added spill pins and the unsafe-count increase carry dated reasons.
Escape catalog: no C1–C4 pattern matched.

Notes

Dryer did not scan gpu-gates; its changed cases were read manually. GPU gates were not rerun here.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_mxfp8.rs, crates/gpu/src/hc_gated.rs, crates/gpu/src/mxfp4_sel.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 1, 2026
@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 f3791a2 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 gpu-evidence Verified on the author's card: the pull request carries the gate run and its output 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