Skip to content

gpu: select native FP4 prompt builds on GB10 - #758

Merged
juliankang4 merged 7 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-routed-w4a4
Oct 24, 2026
Merged

juliankang4 merged 7 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-routed-w4a4

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

GB10에서 빌드가 기본으로 sm_121a를 골라, NVFP4와 FP4-Local routed prompt가 이미 있는 네이티브 FP4 경로로 돌게 해 prefill과 첫 토큰 시간을 줄이는 속도 PR입니다.

Part of #565. Tracked in #699.

What and why

On a GB10 the recipes built for sm_86 unless BLOOMERY_ARCH was set, so the routed prompt GEMM for NVFP4 and FP4-Local weights never used the FP4 tensor-core path that the tree already has for sm_121a. A user had to know the target and give it by hand.

This PR makes the build target selection live in one place, tools/arch.sh, and lets the justfile and every tool that inspects a build read it:

  • With BLOOMERY_ARCH unset, arch.sh reads the compute capability from nvidia-smi. One card at capability 12.1, or several cards that all report 12.1, select sm_121a. Any other card, a mixed set, or a machine without nvidia-smi keeps sm_86. An nvidia-smi query that errors is itself an error that asks for an explicit BLOOMERY_ARCH. An explicit value is kept as given, and an empty or malformed one is refused by name.
  • The justfile takes arch from bash tools/arch.sh and exports it, so recipes build with --arch {{arch}} and the gate, LDS, SASS and PTX scanners see the same target the build used.
  • tools/check-recipes.sh holds the new owner shape (one arch definition, one export, no second default) and runs the selection against a fake nvidia-smi for card sets, overrides and refusals, through the script and through the sourced function.
  • tools/lds-scan.sh and tools/ptx-spill-check.sh fix their fixture target to sm_86 so their self-tests do not depend on the visible card. lds-scan.sh also gets a case for an LDS entry-count read that errors, which the scanner already refused but no test covered.
  • tools/box.sh reads whether the caller set BLOOMERY_ARCH before it runs the selection, so a remote command exports the target once, and its refusal names the tools/arch.sh selection as the default. The tools/gpu-gate.sh self-test clears BLOOMERY_ARCH for its stub tree, as the card tests already do.
  • tools/ptx-compare.sh refuses a BLOOMERY_ARCH other than sm_86, the target its scan builds at, with a named error (rc 64), as tools/ptx-scan.sh and tools/narrow-scan.sh already do; on a GB10 the comparison runs with BLOOMERY_ARCH=sm_86 set explicitly.
  • tools/batch-replay.sh copies tools/arch.sh into each snapshot and fixes the snapshot's arch to its evaluated value before it builds the command table, so the replay runs recipes and matches their keys as before. A base without an arch variable keeps its own commands. tools/nightly/selftest.sh checks both cases.
  • Once the default follows the card, tests that expected sm_86 and let the host driver answer depend on the machine they run on. The fixtures now supply their own card (results under Tests and FAIL-first). The card tests' box and gate fixtures put a stub nvidia-smi that reports capability 8.6 on their private PATH, so they expect sm_86 on any machine, and the replay self-test runs its freeze check with an explicit BLOOMERY_ARCH=sm_86. The ptx-compare self-test's concurrent children clear BLOOMERY_ARCH like its other cases.
  • The card tests gain a case for an sd override that overflows to infinity: card.py check refuses it as malformed (rc 65).
  • docs/contrib/dgx-spark.md shows the sm_121a build command and describes the default.

With this change a GB10 build runs the routed prompt GEMM for NVFP4 and FP4-Local with both weights and activations in FP4. Other routed formats keep their activation format, and decode is unchanged. The kernels are not touched. The change reaches the rank count only through the build target, which does not depend on it.

Release notes: Changed: GB10 builds select sm_121a by default, which speeds up NVFP4 and FP4-Local prompt processing.

Code shape

  • No second copy. The target is chosen by bloomery_arch in tools/arch.sh, and the justfile, the recipes and the scanners read that one function. The old default in the justfile is gone, and check-recipes.sh rejects a second definition.
  • Model code holds only architecture facts. No model file or common Rust owner changed.
  • Dead code is gone. The justfile's own sm_86 default and the document text that described it are removed.
  • No silent failure. A card query that errors, an empty BLOOMERY_ARCH and a malformed one are named errors.
  • Comments state what is true now. The new comments describe the current selection rules.
  • No relaxed gate. No band, tolerance or lint moved. The architecture-owner check in check-recipes.sh was rewritten for the new owner shape and carries a dated PIN, with a case that rejects the old per-recipe default.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up. No Rust file changed.

Duplication found or removed (path:line), or "none": none.

What I ran

Hardware: one DGX Spark (GB10) for the timed run and the gate.

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

The build container reports CUDA 13.3 for the toolchain; the line above is the driver's.

Speed

Both trees were built on the same machine, main for sm_121 and the head for sm_121a. Models are the FP4-Local folder nvidia/Qwen3.8-Flash-Next-FP4-Local at revision b9ce18a6887e18c089fdea8509a33e63429a3300 and the NVFP4 folder nvidia/Qwen3.8-Flash-Next-NVFP4 at revision fc694b54fb0174e0913e6adf86691ef85a4ead47. Each arm loaded the server once with the draft off, then ran three rounds of two greedy requests with 4,096 prompt tokens and 128 output tokens, one request at a time. Main and head alternated in one lease, and the order was reversed between the two checkpoints. Each checkpoint's first warm load was discarded, and load time is kept out of the numbers. A cell is the median of the three rounds, and TTFT is the p95 over each round's two requests. The GPU clock cap was lifted for each arm and restored after it.

Checkpoint Metric main head Change
FP4-Local Prefill tok/s 1307.778 1365.672 +4.43%
FP4-Local TTFT p95 ms 3162.330 3038.784 -3.91%
FP4-Local Decode tok/s 30.343 30.474 +0.43%
NVFP4 Prefill tok/s 1309.562 1379.693 +5.36%
NVFP4 TTFT p95 ms 3168.799 2986.812 -5.74%
NVFP4 Decode tok/s 22.496 22.665 +0.75%

FP4-Local: Prefill +4.43%, TTFT -3.91%, Decode +0.43%; NVFP4: Prefill +5.36%, TTFT -5.74%, Decode +0.75%

Each head round beats every main round on prefill and TTFT for both checkpoints (FP4-Local prefill: main rounds 1306.6 to 1309.5, head rounds 1331.4 to 1368.5; NVFP4 prefill: main rounds 1286.6 to 1326.3, head rounds 1373.7 to 1381.3; FP4-Local TTFT: main rounds 3160.6 to 3164.1, head rounds 3026.7 to 3136.7; NVFP4 TTFT: main rounds 3104.1 to 3221.9, head rounds 2983.5 to 3002.9). That is three rounds per arm, not a significance test. The decode differences are inside the rounds' own spread (FP4-Local decode: main rounds 30.14 to 30.43, head rounds 30.31 to 30.70), and I do not claim a decode gain. The prompt path is the one the change affects.

A kernel profile of one extra 4,096-token request with two output tokens on FP4-Local, taken in the third round and left out of the medians, shows the routed GEMM switching from gemm_nvfp4p to gemm_nvfp4_mma:

Routed GEMM main head
Kernel gemm_nvfp4p gemm_nvfp4_mma
Calls 144 144
Total ms 884.253120 739.128640

That is 16.41% less routed GEMM GPU time on the same request. I did not profile the NVFP4 checkpoint.

The read probe of each arm stayed between 232.872 and 238.990 GB/s, against a 236.625 GB/s read ceiling measured at the end of the same session, and no arm's decode rate stands out from its tree.

The timed head had the same justfile, tools/arch.sh and documentation change as this PR's head; the commits after it change only tool scripts and their self-tests, which the build and the server do not run. The timings were taken on upstream main 501db04f and are not a fresh measurement of the current main.

Output parity

All 24 regular requests returned 128 tokens with no error. Both checkpoints were run on two windows of the corpus, three rounds each. On the first window the head's 128 greedy tokens equal main's in all three rounds on both checkpoints. On the second window they differ in all three rounds, first at token 22 (counting from 0) for FP4-Local and at token 102 for NVFP4, with the same text in every round of a tree. The tokens continue Python code in both trees. FP4-Local's head continues with super().__instancecheck__(instance) where main continues with _abc_instancecheck(cls, instance). I saw no nonsense tokens, endless repetition or device fault, but I did not judge the code's correctness against an oracle. The difference is expected: the routed prompt now rounds its activations to FP4. A user who wants more activation precision can set BLOOMERY_ARCH to the old target or pick a higher precision checkpoint format. KL was not measured, because the client does not collect log probabilities.

Tests and FAIL-first

The native FP4 GEMM gate, built on each tree, on the card above:

just gate-gpu-gemm --case nvfp4_native (built arch=sm_121)
gate_gemm: nvfp4_native requires the native FP4 build
gpu-gate.sh: gate_gemm ran 1 s (exit 1)
just gate-gpu-gemm --case nvfp4_native (built arch=sm_121a)
gpu-gate.sh: gate_gemm ran 13 s (exit 0)

On main's sm_121 build the native case refuses to run by name. On the head the same case succeeds, including the two refused-alignment checks and the product cases with wrong=0 and eager_graph_eq=true. No gate band, tolerance or eager/graph contract changed.

The selection is checked by bash tools/check-recipes.sh --block archowner (15 ownership fixtures and 22 selection cases), bash tools/lds-scan.sh --self-test (11 cases) and bash tools/ptx-spill-check.sh --self-test, which all pass. FAIL-first: the archowner fixtures include the old per-recipe default (env_var_or_default) and fail on it, and the LDS case fails when the entry-count guard is removed from lds-scan.sh.

FAIL-first for the fixtures: on a GB10 (card, driver and CUDA lines above), env -u BLOOMERY_ARCH just check-recipes on the tree before the fixture fixes failed with card-tests: 903 tests, 5 failed. The five failures are the box.sh unset-target refusal, its accepted default entry, its two export assertions and the gate.sh default build target, which built for sm_121a where the test expected sm_86. The ptx-compare self-test also failed (slow rc 64, fast rc 64): its two concurrent children call the script directly and inherited the caller's target, which the new refusal rejects. The self-test now clears the caller's target once at entry, which covers every child.

After the fixes, on the same GB10, env -u BLOOMERY_ARCH just check-recipes and BLOOMERY_ARCH=sm_121a just check-recipes both end with card-tests: 903 tests, 0 failed, ptx-compare: self-test ok (37 cases, 0 failed) and check-recipes: 145 blocks ran, 0 skipped by a green input key.

The replay self-test did not fail on its own before the change: BLOOMERY_ARCH=sm_121a bash tools/nightly/selftest.sh --self-test --output-only passed (28/28) on the earlier tree. Its freeze check now selects sm_86 explicitly so that it does not depend on the caller's target.

just check-recipes passes on this head on an x86 Linux machine and on a GB10, there both with BLOOMERY_ARCH unset and with BLOOMERY_ARCH=sm_121a, each with card-tests: 903 tests, 0 failed, gpu-gate self-test: 169 of 169 ok and ptx-compare: self-test ok (37 cases, 0 failed). The new ptx-compare refusal case fails when the refusal is removed. FAIL-first for the new card case: with the finite check in card.py removed, the same card is accepted as under margin (rc 71) instead of refused.

just gate-gpu-qwen38-serve and the other model gates were not run: they need the maintainers' workstation.

Reproduction

bash tools/check-recipes.sh --block archowner
bash tools/lds-scan.sh --self-test
bash tools/ptx-spill-check.sh --self-test
just gate-gpu-gemm --case nvfp4_native

For the timing, build the head and upstream main from their own trees, with BLOOMERY_ARCH unset on the head (sm_121a) and sm_121 on main, serve each checkpoint with BLOOMERY_DRAFT=off, and send greedy requests with 4,096 prompt tokens and 128 output tokens on fresh corpus windows.

What I ran into

This does not block the PR.

  • An explicit BLOOMERY_ARCH=sm_121 from an outer launcher overrides the new default. To get the native FP4 path, leave it unset or name sm_121a.
  • Not measured: KL, a profile of the NVFP4 checkpoint, and speed at prompt lengths other than 4,096.

AI help

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

@github-actions github-actions Bot added dgx-spark The DGX Spark (aarch64, GB10) port documentation Improvements or additions to documentation tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 24, 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: GB10 target selection makes the static test suites fail.

Must fix

1. Give the card fixtures a synthetic compute capability

tools/ref/card-tests/run.sh:895 expects the unset target to be sm_86, but box() clears BLOOMERY_ARCH and exposes the real nvidia-smi. On GB10 the selector returns sm_121a: this diagnostic differs, and the accepted sm_86 case at line 898 returns 64. The gate.sh fixture at line 1354 likewise clears the target and expects sm_86.
These failures prevent contributors on the target card from completing just check-recipes. Fixing the fixtures with the selector change keeps the static checks usable.

After creating $tmp/stub at line 734, add:

printf '%s\n' '#!/bin/sh' 'printf "%s\n" 8.6' > "$tmp/stub/nvidia-smi"
chmod +x "$tmp/stub/nvidia-smi"

After creating $GS/stub at line 1347, reuse that fixture:

cp "$tmp/stub/nvidia-smi" "$GS/stub/"

2. Change the target explicitly when checking the freeze mutant

tools/nightly/selftest.sh:179 inherits the caller's environment, while snapshot evaluation at line 168 forces sm_121a. With BLOOMERY_ARCH=sm_121a, the arch-freeze mutant still produces the expected commands. valid remains true, so line 184 fails a healthy tree. An unset target on GB10 has the same result.
Set a different target for the execution phase now so the mutation test checks freezing on every machine.

Replace line 179 with:

                actual = subprocess.run(["env", "BLOOMERY_ARCH=sm_86", "just", "gate-probe"], cwd=work / arm, capture_output=True, text=True)

Non-blocking

⚠ Complete the timing evidence: justfile:13 changes the default used by the speed comparison. The body gives summaries and an upstream base hash, but no tested head hash or exact timing commands with their output. Add those so the measurements meet CONTRIBUTING.md's evidence contract.

Checked

Complexity: no Rust functions changed.
Silent failure: the architecture-query error returns 64, and the box and gate callers propagate it.
Tests: in-memory checks reproduced the GB10 box refusals and gate target mismatch. The replay freeze mutant was traced through snapshot selection, execution and the final assertion. The inline suggestion replaces an added line and parses as Python.
Gates: the ownership rewrite has PIN(2026-10-24); no numeric pins moved.
Escape catalog: neither finding matches C1–C4. No ledger lessons are in force.

Notes

Full suites were not rerun: just is unavailable. The timing-evidence question remains non-blocking under the review contract.

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

Comment thread tools/nightly/selftest.sh Outdated
box = work / arm / "tools/box.sh"
box.write_text('#!/bin/sh\nprintf "%s\\n" "$*"\n')
box.chmod(0o755)
actual = subprocess.run(["just", "gate-probe"], cwd=work / arm, capture_output=True, text=True)

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.

Use a target different from snapshot evaluation so the freeze mutant is rejected when the caller selects sm_121a.

Suggested change
actual = subprocess.run(["just", "gate-probe"], cwd=work / arm, capture_output=True, text=True)
actual = subprocess.run(["env", "BLOOMERY_ARCH=sm_86", "just", "gate-probe"], cwd=work / arm, capture_output=True, text=True)

@juliankang4
juliankang4 force-pushed the dgx-spark-q38-routed-w4a4 branch from 857af62 to ff85f25 Compare October 24, 2026 02:21

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

Since the last review:

Verdict: CLEAN: Both earlier blocking defects are fixed; no must-fix finding remains.

Non-blocking

⚠ Complete the timing evidence: justfile:13 changes the default used by the comparison. The body still omits the tested head hash and exact timing commands with their output. Add these to meet CONTRIBUTING.md's evidence list. This evidence request is non-blocking under the review rules.

Checked

Duplicates: no new functions, types or constants in the interdiff; the gate fixture reuses the synthetic card.
Complexity: no Rust functions changed.
Silent failure: the selector's query failure returns 64; the interdiff adds no fallback or discarded result.
Tests: static tracing confirms that execution at sm_86 differs from snapshot selection at sm_121a when the freeze at tools/batch-replay.sh:92 is removed. The PTX self-test clears the caller's target before its child processes run.
Gates: no pins or tolerances moved in the interdiff.
Escape catalog: no C1–C4 match. No ledger lessons are in force.

Notes

No Rust file changed; dryer and crapper did not run.
Validation used static inspection; test suites were not rerun.

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

@juliankang4
juliankang4 merged commit 100c224 into midagedev:main Oct 24, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dgx-spark The DGX Spark (aarch64, GB10) port documentation Improvements or additions to documentation 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