Skip to content

qwen38: the plan counts a native FP4 card route by the bytes it holds - #1033

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-opt-native-input-storage
Oct 31, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-opt-native-input-storage

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

native FP4로만 읽는 routed 입력이 Q8 buffer를 더는 잡지 않고, placement도 실제 할당 바이트대로 세게 합니다.

What and why

On the Qwen3.8 native FP4 card route, the gate and up input is read only in its native FP4 form. It still allocated the Q8 planes and the plan still counted the old f32 row scratch for it.

GemmAct32::new_native_input now holds the native form only, and CardRoute38::new uses it for the fused route. A launch that writes Q8 planes refuses a scratch that has none, by name. On the plan side, RouteForm { Rows, Native } makes the card route scratch follow the file's form: Native when the build is native FP4 and every routed stack in the file's layers is NVFP4, otherwise Rows as before. Load, the shared open, the serve seat and the two gate binaries read the same form, so the reserve the plan widens is the reserve the load checks.

Speed is unchanged (the base and head ranges overlap, see below). The change moves the planned card bytes, so more of a card's memory is left for the KV cache.

Release notes: Changed: the Qwen3.8 native FP4 card route no longer allocates Q8 planes for its input, and the plan counts the route by the bytes it holds.

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 or tolerance moved, and this PR adds no pin.
  • 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": native_input_only in crates/gpu/src/gemm/act32.rs is removed; new_native_input replaces it.

What I ran

A/B of the built server binary on a DGX Spark, base b4e02387 against head 49400131, one A/B per model (Qwen3.8-Flash-Next-FP4-Local and Qwen3.8-Flash-Next-NVFP4). The load uses a 4,096-id prompt and 128 generated tokens, 8 windows, three timed rounds per revision, temperature 0.

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
BLOOMERY_DRAFT=off BLOOMERY_HOST_ROOM=96G bloomery-serve -m <model> --host 127.0.0.1 --port 18731 --parallel 1 --ctx-size 16896

Bytes the plan and the load hold, from the server log of one load per revision:

Model Metric Base Head Difference
FP4-Local need bytes 82139315280 81915558992 -223756288
FP4-Local resident_bytes 77583386892 77570500876 -12886016
FP4-Local mem_left 20939899824 21163656112 +223756288
NVFP4 need bytes 84490222672 84266466384 -223756288
NVFP4 resident_bytes 80408047884 80395161868 -12886016
NVFP4 mem_left 18588992432 18812748720 +223756288

The planned reduction is the same for both models.

Speed, medians of three rounds (tok/s):

Model Metric Base Head Difference Ranges overlap
FP4-Local decode 31.26 31.39 +0.41% yes
FP4-Local prefill 2836.72 2836.49 -0.01% yes
NVFP4 decode 22.66 22.63 -0.13% yes
NVFP4 prefill 2540.71 2541.39 +0.03% yes

Every metric's ranges overlap, and greedy_equal: True (the greedy output is identical).

Tests and gates on commit be0d8765 (BLOOMERY_BOX_LOCAL=1, DGX Spark):

bash tools/gate.sh --release -p bloomery-model --lib -- arch::qwen35moe
test result: ok. 112 passed; 0 failed; 0 ignored; 0 measured; 493 filtered out
bash tools/gate.sh --release -p bloomery-model --test qwen4exp_mtp_reserve
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
bash tools/gate.sh --gpu --oxide -p bloomery-gpu --release --lib -- --include-ignored nvfp4mma:: act32
test gemm::nvfp4mma::tests::hw_native_activation_planes ... ok
just gate-gpu-nvfp4
gpu-gate.sh: gate_nvfp4 ran 21 s (exit 0)
BLOOMERY_CARD_ALL_EXPERTS=1 BLOOMERY_REF_MODEL=<model folder> just gate-gpu-qwen4exp-nvfp4
(rt) the load for a route trace: host views 0 (want 0), trace positions Some(5) (want 5), every slot on the card true, logits the plain load's bit for bit true PASS
gpu-gate.sh: gate_qwen4exp_nvfp4 ran 58 s (exit 0)

The last gate ran on both model folders; both exit 0. The NVFP4 folder prints the same PASS lines, ending with gpu-gate.sh: gate_qwen4exp_nvfp4 ran 54 s (exit 0).

New tests fail without the change. On 49400131, removing the layer filter in route_form fails a_card_route_is_counted_in_its_files_form with left: (Rows, Rows) and right: (Native, Rows), and removing the build condition fails it with left: (Native, Native) and right: (Native, Rows). With the native input allocating its Q8 planes, hw_native_activation_planes fails with left: 840 and right: 280. With the Q8 refusal removed it fails at nvfp4mma.rs:2574.

Hardware (if the change is for a machine)

  • Card and driver: NVIDIA GB10, 595.84
  • CUDA: 13.3

AI help

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

…planes

Qwen3.8's card route reads its run's normed rows in the native FP4 form
alone when one native launch runs the gate, the up and the SwiGLU (every
card layer NVFP4 on a native FP4 build). Its input scratch still allocated
the 32-value Q8 planes, which the input quantizer then skipped and no reader
took: 3,200 B a column at K = 2,560, 6,553,600 B at a run of 2,048 tokens.

GemmAct32::new_native_input makes that scratch with the native form and
empty Q8 planes (GemmAct32::new's scratch on a build without the native
products or at K not a multiple of 64). Every launch that stores the Q8
planes takes its shape from GemmAct32::quant_launch, which now refuses such
a scratch by name; the input quantizer, which stores them only where the
scratch holds them, takes the same shape without that check.
A card-experts machine counted the ubatch walk's card route at 170,360 B a
run token, the q8_1 input form and the gate and up f32 rows. A load whose
card layers run the gate, the up and the SwiGLU as one native FP4 launch
holds neither: its input is the native FP4 form alone (1,444 B a column at
K = 2,560) and it writes no gate or up rows, so the plan held back 54,628 B
a run token that no buffer took (111,878,144 B at a run of 2,048 tokens),
and the card's experts, cache and slots could not use them.

place::RouteForm names the two forms, and PlanInputs::route_form reads a
load's from the file and the build: Native where every routed stack of the
file's layers is NVFP4 on a build with the native FP4 products, which every
card layer then runs fused. place::machine_for_route counts the card route
in that form (115,732 B a run token in Native; machine_for_experts keeps
Rows), and widen_card_route and card_route_run size and check the
whole-ubatch run's reserve in it. The Qwen3.8 seat, generate_qwen3moe, the
gates' shared open and the load itself read the form the same way, so the
reserve a plan widens by is the one the load reads back.
@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 labels Oct 30, 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: The changed allocation and placement paths agree, and invalid Q8 consumers receive named errors.

Non-blocking

⚠ Complete the verification evidence: crates/gpu/src/gemm/act32.rs:301. The unchanged-speed claim uses model placeholders and revisions other than the reviewed base/head. Supply the exact model files, the card/driver nvidia-smi line, and commands with output tied to both revisions. This makes the measurements reproducible.

Checked

  • Duplicates: 9 new named items checked; no duplicate owner found. Dryer reported 0 pairs.
  • Complexity: CardRoute38::new grew from 27 to 28 through one allocation-selection branch; no separate responsibility was added.
  • Silent failure: 3 paths followed. Q8-writing quantizers, Q8 readers, and invalid route reserves return named errors.
  • Tests, source-level mutation check: hw_native_activation_planes protects crates/gpu/src/gemm/act32.rs:301 and crates/gpu/src/gemm/act32.rs:396; restoring Q8 allocation or deleting refusal makes assertions fail.
  • Tests, source-level mutation check: a_card_route_is_counted_in_its_files_form protects crates/model/src/arch/qwen35moe/place.rs:556; dropping the layer filter or native-build condition makes assertions fail.
  • Tests, source-level mutation check: the_card_route_runs_the_whole_ubatch_where_nothing_moves_for_it protects crates/model/src/arch/qwen35moe/place.rs:1453; using the Rows rate for Native fails the reserve assertions.
  • Gates: no tolerance or existing pin moved. Reported FAIL-first results cover the allocation, refusal, and format-selection changes.
  • Adversarial checks: mixed formats, non-native builds, empty Q8 planes, and ubatches around 2,048 are blocked by format checks or named errors. The final bounds check found constructor validation for zero columns and invalid K.
  • Performance: allocation changes occur at load time; launch counts and float reduction order are unchanged.
  • Escape catalog: no C1–C4 pattern matched.

Notes

Static review only; builds and card gates were not rerun.
Dryer did not scan crates/gpu or crates/gpu-gates; these changes were checked by grep.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_qwen38_serve.rs, crates/gpu-gates/src/bin/generate_qwen3moe.rs, crates/gpu-gates/src/bin/shared/qwen38_open.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)

@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 c8cc354 into midagedev:main Oct 31, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant