Skip to content

gpu, qwen38: the card route's down form is read from the whole slot map, so a load with an expert tier rounds its down rows to BF16 as its union's one-card load does, and the tier join reads the tier's rows rounded with them - #1126

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-fix-twocard-1120
Nov 2, 2026

Conversation

@juliankang4

@juliankang4 juliankang4 commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

두 장 카드 load가 한 장 union load와 같은 BF16 down 형식을 쓰도록 맞춰, 두 장 prompt 결과가 union reference와 어긋나던 문제(#1120)를 고칩니다.

Fixes #1120. On Qwen3.8, a two-card load with an expert tier sums its down rows in F32, while the one-card load of the same experts rounds each down row to BF16 first. The two sums differ in the last bits, so the two-card prompt call no longer matches its union reference.

What and why

The down-row storage form was decided from !tiered && card.all_hostless(), so any load with a tier took F32. This change makes one owner, card_slots::DownStore::of_load, decide it from the whole slot map: when every expert sits on a card (stage or tier) and no host leg is kept, down rows are BF16, otherwise F32. A two-card load and its union as a one-card load see the same map fact (SlotMap::all_on_cards), so they get the same form. The stage down store, the block join and the tier join all read this one value. In the BF16 form the tier join reads the tier's F32 rows rounded to nearest-even, the same rounding the card rows get.

The tier join needs its own kernel entry, q38_card_tier_acc_bf16, because a kernel entry's argument types are fixed and the stage rows are u16 in this form. It shares its body with q38_card_tier_acc through card_tier_acc_at. The one-card path keeps its form: without a tier, all_on_cards holds under the same conditions as before.

Release notes: Fixed: a two-card Qwen3.8 load with an expert tier now rounds its down rows to BF16 like the one-card load of the same experts, so its prompt output matches the one-card reference.

Code shape

  • No second copy. The down-form policy had one copy (wide38.rs); it now lives only in DownStore::of_load, and q38_card_tier_acc and its _bf16 entry share one body.
  • Model code holds only architecture facts. The policy is in the common card_slots owner; wide38.rs and card38.rs read it.
  • Dead code is gone. Nothing left unused; all_hostless is still read by the PLE path.
  • No silent failure. The existing size check in enqueue_card_tier_acc covers both forms.
  • Comments state what is true now. Docs of wide38, tier38, q38, card38 and place.rs now state the BF16 condition.
  • No relaxed gate. No band or tolerance moved; the bit comparison stays. The PTX table gains one pinned row, q38_card_tier_acc_bf16 0 0, and the unsafe ratchet moves with the new blocks.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line): the old !tiered && card.all_hostless() rule in crates/gpu/src/arch/qwen3moe/wide38.rs was the only copy and is replaced by DownStore::of_load (crates/gpu/src/card_slots.rs). The body of q38_card_tier_acc moved to card_tier_acc_at in crates/gpu/src/q38.rs, shared by two entries.

What I ran

Upstream base 97902d2be794e22bf03675fabba987a2681bf543, PR head d9228627ee32505b8dbdb3f88cb0c32ce0698732.

The new gate clause q38_card_tier_join reproduces the two-card join on one card and compares it with the union's BF16 card sum. On the code before this change:

$ just gate-gpu-kquant
q38_card_tier_join[bf16_rows, 3 tier slots] is_union_card_sum=false fault="none" FAIL first_mismatch=slot 0 row 0 got 0x3e01decb want 0x3e01f395
q38_card_tier_join[f32_rows, 3 tier slots] is_union_card_sum=true fault="none" PASS
gate_kquant: FAILED: one or more checks above did not pass

After the change, on a DGX Spark (GB10):

$ nvidia-smi
Mon Nov  2 01:59:42 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   51C    P8              5W /  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
$ bash tools/gate.sh --oxide -p bloomery-gpu --release --lib -- a_tier_loads_down_store_is_its_unions host::slots::
test card_slots::tests::a_tier_loads_down_store_is_its_unions ... ok
test result: ok. 19 passed; 0 failed; 0 ignored; 0 measured; 470 filtered out; finished in 0.00s

$ just gate-gpu-kquant
q38_card_tier_join[bf16_rows, 3 tier slots] is_union_card_sum=true fault="none" PASS
q38_card_tier_join[f32_rows, 3 tier slots] is_union_card_sum=true fault="none" PASS
PASSED: gate_kquant q5k_gemv_sel within 1e-5 of the f64 dequant_row reference at 8 shapes, its probe decoding as the host; slots, duplicate ids, rerun, graph replay and two-token gate·up bit for bit; the m-column walk is the one-column walk at m = 1..8 on 8 K; ids past the stack raise expert_id, HO

The same clause on an RTX 5090 machine:

$ nvidia-smi
Mon Nov  2 10:58:48 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 Off |                  N/A |
|  0%   43C    P8             11W /  400W |       2MiB /  32607MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

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

$ just gate-gpu-kquant
q38_card_tier_join[bf16_rows, 3 tier slots] is_union_card_sum=true fault="none" PASS
q38_card_tier_join[f32_rows, 3 tier slots] is_union_card_sum=true fault="none" PASS
PASSED: gate_kquant q5k_gemv_sel within 1e-5 of the f64 dequant_row reference at 8 shapes, its probe decoding as the host; slots, duplicate ids, rerun, graph replay and two-token gate·up bit for bit; the m-column walk is the one-column walk at m = 1..8 on 8 K; ids past the stack raise expert_id, HO

The real binary on Qwen3.8 FP4-Local, where every routed expert is on the card (the BF16 down form). Model: nvidia/Qwen3.8-Flash-Next-FP4-Local, revision b9ce18a6887e18c089fdea8509a33e63429a3300, $M is its folder. SHA-256 of its files:

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
$ cargo oxide build --arch sm_121a -- -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve
$ ./target/release/bloomery-serve -m "$M" --host 127.0.0.1 --port 18920 --parallel 1 --ctx-size 8192
$ curl -s -X POST http://127.0.0.1:18920/completion -H 'Content-Type: application/json' --data @req.json    # "The capital of France is", then a 729-token prompt; n_predict 32, temperature 0
load arch=qwen4exp resident_bytes=79123580088 ctx=8192 slots=1 slot_ctx=8192 ctx_max=262144 ctx_train=262144 verified=3001 layers=48 mode=graph store_bytes=367527632 prefill=auto ubatch=4096 place=a card_layers=48 in 16.6 s (runtime value)
ANSWER prompt_n 5 predicted_n 32 ' Paris. The capital of Germany is Berlin. The capital of Italy is Rome. The capital of Spain is Madrid. The capital of Portugal is Lisbon. The capital'
ANSWER prompt_n 729 predicted_n 32 '\n\n<think>\nThe user has provided a text that is simply the same sentence repeated many times: "The river runs past the old mill and the stone bridge,'
server exit 0

The one-card whole-program gate in the fixture tier covers both forms (a card plan with a host leg takes F32, a whole plan without it takes BF16):

$ BLOOMERY_TIER=fixture just gate-gpu-qwen4exp-e2e
card leg whole plan: 4 of 4 layers without the host leg (want 4: the fixture fits the card); batch_mem_op 1 (want 1), with every host leg kept 9 (want 9); the verify replay's services, host calls and Cols services [0, 0, 0] (want 0 each), with every host leg kept [4, 4, 4] (want 4 each); host views 
card leg whole plan: the card route runs 3072 tokens a run (the ubatch's 3072: the fixture fits the card), the loaded route Some(3072) (want the plan's) PASS
paths card plan: fx_ref_qwen4exp_d3k by ubatches cut at 2601 vs one ubatch: tokens [27216] vs [27216]; the last logits bit for bit: true; stores differing at layers [], PLE ring differing: false PASS
clauses: 28 ran, 9 left to the real tier

The PTX comparison against the base shows one added entry and an unchanged resource row for the moved one, and the spill check pins all three card-tier entries:

$ bash tools/ptx-compare.sh e635e3fb7b82a656f5b7b9849fb5da79bdf0a980 generate_ds41 --features gpu,deepseek41
  base entries  535
  head entries  536
  added         1: q38_card_tier_acc_bf16
  removed       none
  changed       1: q38_card_tier_acc (ptx-scan-md5:74019933->ff71df89)

$ bash tools/ptx-spill-check.sh tools/ref/ptx-shapes.tsv tools/ref/ptx-shapes/ generate_ds41:q38_card_tier
ptx-spill bin=generate_ds41 table=tools/ref/ptx-shapes/sm_121a-cc12.1.tsv arch=sm_121a jit-cc=12.1
ptx-spill bin=generate_ds41 entries=3 pinned=3 nonzero=none violations=0 PASS

Hardware (if the change is for a machine)

Machine Card Driver CUDA
DGX Spark NVIDIA GB10 (compute capability 12.1) 595.84 13.3
RTX 5090 machine NVIDIA GeForce RTX 5090 (compute capability 12.0) 595.99.02 13.2

AI help

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

@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 tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Nov 2, 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: the new load-policy API exposes three declarations that have no caller outside the GPU crate, contrary to R13.

Must fix

1. Keep the load-policy API crate-private (kind B, R13)

crates/gpu/src/card_slots.rs:714 and crates/gpu/src/host/slots.rs:391: DownStore, DownStore::of_load, and SlotMap::all_on_cards are public. A repository-wide search finds only callers inside bloomery-gpu; the policy test is also inside that crate. R13 permits pub only for cross-crate callers.
Restricting these declarations now avoids adding external API commitments for internal storage policy. Keep the existing attributes and surrounding documentation. Replace the enum, the of_load method, and the all_on_cards method with these definitions:

pub(crate) enum DownStore {
    F32,
    /// BF16 bits, each product rounded to nearest even;
    /// tier rows are read with the same rounding.
    Bf16,
}
pub(crate) fn of_load(map: &SlotMap, keep_host: bool) -> DownStore {
    if !keep_host && map.all_on_cards() {
        DownStore::Bf16
    } else {
        DownStore::F32
    }
}
pub(crate) fn all_on_cards(&self) -> bool {
    self.slots.iter().all(|&e| e != HOST)
}

Non-blocking

⚠ Precision-change evidence: crates/gpu/src/q38.rs:731 adds rounding and widening in the BF16 join for each selected tier slot × 2,560 values per prefill token per tier layer [derived]. Attach the error model, applicable end-to-end count-pin result, and one timed A/B required by AGENTS.md's “float sum order or precision” row. The attached join and spill results do not establish the runtime effect.

Checked

Duplicates: 10 new functions/types checked; no duplicate owner found. dryer reported 0 pairs; GPU code was searched manually. Existing tier sums use different row layouts and weight pitches.

Complexity: check_tier_join is new at 29; its separable jobs are input setup, kernel execution, and result comparison. check_q38_card rises 48→49 with one gate clause; harmless growth.

Silent failure: 5 sites followed: the HOST skip, three invalid-place/rank branches, and BF16 non-finites. Invalid values reach named faults through the join and combine.

Tests: static mutation review: flipping !keep_host at card_slots.rs:731 fails the policy assertions; dropping TierRowsRne at q38.rs:731 fails the join's bit comparison. GPU tests were not rerun here.

Gates: no tolerance or band moved; the unsafe-count increase has a dated reason. The new clause carries FAIL-first output.

Escape catalog: no C1–C4 pattern matched.

Notes

dryer did not scan crates/gpu or crates/gpu-gates; those searches were manual.
The attached runs name base d76d5fb and head 9be1235; this review covers base 97902d2 and head 1229ef1.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_kquant.rs, crates/gpu-gates/src/bin/shared/q38_combine.rs, crates/gpu/src/arch/qwen3moe/card38.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)

Comment thread crates/gpu/src/card_slots.rs Outdated
/// sum over them reads ([`DownRows`]), decided once a load from its whole
/// slot map ([`DownStore::of_load`]).
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DownStore {

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.

R13: this storage-policy type has no caller outside bloomery-gpu.

Suggested change
pub enum DownStore {
pub(crate) enum DownStore {

Comment thread crates/gpu/src/card_slots.rs Outdated
/// card's share, so a load with a tier and the one-card load of its
/// union round the same rows.
#[must_use]
pub fn of_load(map: &SlotMap, keep_host: bool) -> DownStore {

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.

R13: all callers of this load-policy method are inside bloomery-gpu.

Suggested change
pub fn of_load(map: &SlotMap, keep_host: bool) -> DownStore {
pub(crate) fn of_load(map: &SlotMap, keep_host: bool) -> DownStore {

Comment thread crates/gpu/src/host/slots.rs Outdated
/// card: no entry is [`HOST`]. A map with a tier and the map of its union
/// (every tier set joined to the stage card's) hold it alike.
#[must_use]
pub fn all_on_cards(&self) -> bool {

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.

R13: this map query is only called inside bloomery-gpu.

Suggested change
pub fn all_on_cards(&self) -> bool {
pub(crate) fn all_on_cards(&self) -> bool {

@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 2, 2026
…ap, so a load with an expert tier rounds its down rows to BF16 as its union's one-card load does, and the tier join reads the tier's rows rounded with them

@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: The previous must-fix is resolved, and the three visibility edits introduce no blocking defect.

Non-blocking

⚠ Precision-change evidence: crates/gpu/src/q38.rs:731 rounds and widens each selected tier slot × 2,560 values per prefill token per tier layer [derived]. Attach the precision error model, applicable end-to-end count-pin result, and timed A/B required by AGENTS.md's “float sum order or precision” row. The added one-card whole-program gate and server outputs cover execution but do not establish the runtime effect.

Checked

Duplicates: 0 new items in the interdiff; callers of all three edited declarations checked. dryer reports 0 pairs.

Complexity: previously flagged check_tier_join (new→29, setup/execution/comparison) and check_q38_card (48→49, one gate clause) are unchanged in the interdiff.

Silent failure: 0 added sites; the edits change visibility only.

Tests: none changed. Static mutation review: flipping !keep_host fails the policy assertions; dropping TierRowsRne fails the join's bit comparison. GPU gates were not rerun here.

Gates: none changed since the previous review; no pins moved.

Escape catalog: no C1–C4 pattern matched.

Notes

dryer did not scan crates/gpu or crates/gpu-gates; relevant searches were manual. Attached gate evidence now names this review's base and head hashes.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_kquant.rs, crates/gpu-gates/src/bin/shared/q38_combine.rs, crates/gpu/src/arch/qwen3moe/card38.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)

@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 1eb22cd into midagedev:main Nov 2, 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 model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gate-gpu-qwen38-twocard red on main: two-card prompt calls differ

1 participant