Skip to content

qwen38: a checkpoint folder's plan holds its load's least part reads - #898

Merged
juliankang4 merged 6 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fp4l-seat-defaults
Oct 28, 2026
Merged

juliankang4 merged 6 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fp4l-seat-defaults

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8 FP4-Local을 DGX Spark 한 대에서 --parallel 4로 켤 때 로드가 거절되던 문제를 고치고, 서버가 시작 설정을 한 줄로 출력하게 합니다.

What and why

On one DGX Spark, bloomery-serve -m <Qwen3.8-Flash-Next-FP4-Local folder> --parallel 4 with no --ctx-size was refused by the load. The context choice halved the default to 131,072 positions a slot, but its plan did not count the host bytes the load reads ahead of its parts, so the plan passed and the load then refused it. This PR makes the plan count them, so the default halves further until the load fits.

What changes, one item for each commit:

  • placement: an unset context halves on a unified pool when no card share fits. PlacementError::PoolBudget now carries the first refusal's host room and floor, and card_short reads it as a host-short memory. Callers that plan in the pool (the qwen35moe/qwen38, glm5next and deepseek41 plans) halve an unset context where they used to refuse the start. A set --ctx-size that does not fit is still refused.
  • qwen38: a checkpoint folder's plan holds the load's least part reads. Folder::least_reads asks the part source for its least read peak, and the plan is held to its need with that read-ahead, the NVMe tier's arena counted at its floor (ArenaFloor::of), because the load's own check shrinks the arena to make room for the reads. The check runs at the room the plan was made at and names the reading that decided it. On a unified pool the context choice reads that refusal as short; where each card has its own memory the refusal still stops the seat.
  • model-hf: Checkpoint::read_bytes charged every BF16 or F32 part four extra copies for widened values. A BF16 matrix read whole is copied as stored, so its bound is now its stored bytes plus the copy. For the FP4-Local output.weight (1,525,678,080 B stored) the bound drops from 15,256,789,000 B to 9,154,076,680 B.
  • qwen38: the checkpoint folder's MTP draft reuses the header the folder was opened with, instead of opening the folder two more times.
  • qwen38: the server prints one setup line before its address: the draft (mtp, lookup or off), where the draft reads its layer (folder or file), the slots, the context each serves and the settings that change them. docs/serving.md and docs/contrib/dgx-spark.md state the FP4-Local defaults: one slot, the folder's own MTP draft on, and 262,144 positions a slot halved until the plan fits.
  • q8f32: nvfp4_gemv_sel_f32, the expert-select gemv of the checkpoint MTP draft, now owns whole code words per lane, as q8_0_gemv_sel_f32 does, instead of decoding one value at a time. Launch, grid, fault and expert-scale rules are unchanged. Each code is multiplied by its sub-block scale before it meets its activation, so every product is the stored weight's. Activations that are not 16-byte aligned take scalar loads in the same word and value order, so one input gives one sum at either address. The lane's sum order changes, so gate_nvfp4 gains two clauses: routed_f32_finite_scaled_word (code 7 under scale byte 0x01, activations 2^125) holds the row to the f64 reference's f32 bits with no fault, and routed_f32_alignment runs cancelling and overflowing lane sums at an aligned and a four-byte-offset address and expects the same result at both. f32_fold_values takes the weight as a closure so nv_word_dot uses it instead of a second eight-term fold.

The draft default at more than one slot (off) and the single default slot are unchanged.

Release notes: Fixed: Qwen3.8 FP4-Local starts with --parallel 4 and no --ctx-size on one DGX Spark, and the server prints its setup before its address.

Code shape

The review reads these first. A box left unticked needs one line of why.

  • No second copy. The refusal reading lives in PlacementError::card_short; the part-read count is the existing HostNeed::read_ahead term filled from PartsLoad::host_bytes, the one owner of a part source's read peak. nv_word and nv_word_dot are the only NVFP4 f32-activation walk.
  • Model code holds only architecture facts. The shared owners gained no per-model branch, flag or trait method. The folder reads are asked of the Qwen3.8 seat only.
  • Dead code is gone. Nothing is left behind by the change.
  • No silent failure. Every new Result is propagated with ?; the kernel's launch contract and the expert checks are unchanged.
  • Comments state what is true now. I did not run tools/check-comments.sh on this head.
  • No relaxed gate. No band, tolerance or lint moved. tools/unsafe-ratchet.txt re-pins the GPU count for the new unsafe blocks, each with its SAFETY line and a PIN(...) note.
  • cargo fmt and cargo clippy did not run on this head.

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

What I ran

The GPU gates and the serve-rules gate ran on the branch before its last rebase onto upstream main, which moved the placement code into modules and changed no behavior; the placement tests ran after it. The serve and speed runs below used earlier tips, and the kernel path they run is unchanged since.

gate_nvfp4 on an RTX 5090 machine (sm_86 PTX, JIT for compute capability 12.0):

| NVIDIA-SMI 595.99.02              Driver Version: 595.99.02      CUDA Version: 13.2     |
|   0  NVIDIA GeForce RTX 5090        Off |   00000000:01:00.0 Off |                  N/A |
just gate-gpu-nvfp4
nvfp4 device=NVIDIA GeForce RTX 5090
nvfp4 clause=routed_f32_finite_scaled_word got=4.984605e35 want=4.984605e35 no_fault=true PASS
nvfp4 clause=routed_f32_alignment alignment=aligned overflow=false got=0e0 fault_names_f32_product=false PASS
nvfp4 clause=routed_f32_alignment alignment=offset4 overflow=false got=0e0 fault_names_f32_product=false PASS
nvfp4 clause=routed_f32_alignment alignment=aligned overflow=true got=NaN fault_names_f32_product=true PASS
nvfp4 clause=routed_f32_alignment alignment=offset4 overflow=true got=NaN fault_names_f32_product=true PASS
gpu-gate.sh: gate_nvfp4 ran 15 s (exit 0)

All 50 clauses passed, none failed. With the old one-value walk in the unaligned path, the same gate fails on the offset rows:

nvfp4 clause=routed_f32_alignment alignment=offset4 overflow=false got=1e0 fault_names_f32_product=false FAIL
nvfp4 clause=routed_f32_alignment alignment=offset4 overflow=true got=0e0 fault_names_f32_product=false FAIL
gpu-gate.sh: gate_nvfp4 ran 0 s (exit 1)

On a DGX Spark (GB10, sm_121a), with the old one-value walk and the finite-scaled clause, the gate fails on that clause alone:

nvfp4 clause=routed_f32_finite_scaled_word got=NaN want=4.984605e35 no_fault=false FAIL
gpu-gate.sh: gate_nvfp4 ran 18 s (exit 1)

tools/ptx-compare.sh of generate_ds41 (sm_86, JIT for compute capability 12.0) against an earlier build of the same kernel file reports one changed entry, nvfp4_gemv_sel_f32. Registers, blocks per SM and local memory are the same on both sides, and only the unaligned path's instruction counts differ:

  base entries  470
  head entries  470
  added         none
  removed       none
  changed       1: nvfp4_gemv_sel_f32 (fma:49->41 ld.global.scalar:39->15 ptx-scan-md5:cf216dce->e46847d8)
ptx-compare: changed (rc 3)

Host tests, x86_64:

cargo test --release -p bloomery-placement
test result: ok. 208 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.38s
cargo test -p bloomery-model-hf
test result: ok. 64 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 1.13s

read_peaks_cover_the_owned_inputs_and_results pins bf.weight at 4 S + 2 A + 8. With only the pin and the old bound it fails with left: 12296, right: 10248.

just gate-q38-serve-rules on the RTX 5090 machine calls the seat's own Plans::holds on a checkpoint folder's header. A folder's reads hold on the arena's floor, an unset context halves on a unified pool and a set one is refused. The same test fails when the folder check is removed from Plans::holds:

just gate-q38-serve-rules
test qwen38::tests::a_folder_plan_holds_its_reads_on_the_arena_floor ... FAILED
test result: FAILED. 24 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

and the same gate with it in place:

test result: ok. 25 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

On the DGX Spark, an earlier tip of this branch served the FP4-Local checkpoint (b9ce18a6887e18c089fdea8509a33e63429a3300) with bloomery-serve -m <folder> --parallel 4 and no --ctx-size. It started, where the load refused it before:

ctx rule=halved ctx=65536 slots=4 total=262144 limit=262144 (trained) from=262144 host-short need=125270169364 room=123708866560
setup draft=off slots=4 ctx=65536 (BLOOMERY_DRAFT=mtp drafts with the MTP layer; --parallel N sets the slots and --ctx-size N their context)
bloomery-serve-qwen38: place=a ctx=65536 slots=4 slot_ctx=65536 listening on http://127.0.0.1:18733

Speed, one DGX Spark (GB10), 4,096-token prompt, 128 generated tokens, eight windows, three rounds each side, greedy output equal on both sides. fp4l-mtp drafts from the checkpoint folder (base e009acd4); fp4l-off is the draft-off path (base a87b49d9). The comparison ran before the unaligned path was reordered and before the last rebase; the aligned path it runs is unchanged.

Metric Base Head Difference Ranges overlap
fp4l-mtp code decode, tok/s 58.03 58.97 +1.63% (resolution 1.85%) yes
fp4l-mtp prose decode, tok/s 41.76 41.69 -0.17% (resolution 1.52%) yes
fp4l-off code decode, tok/s 30.73 30.71 -0.08% (resolution 0.82%) yes

Prefill and p95 TTFT differ by less than 0.5% on every arm, ranges overlapping. The decode differences are inside the smallest effect the runs resolve, so this PR claims no speed change.

Not run: gate-gpu-qwen38-serve (it needs an RTX 3090, and none was available), gate-placement (the DS41 Q3 model files were not on the RTX 5090 machine), gate-gpu-e2e, tools/check-comments.sh and cargo clippy on this head.

Hardware

DGX Spark with one GB10, driver 595.84, CUDA 13.3, sm_121a build, the FP4-Local checkpoint folder above. The kernel gate and the serve-rules gate also ran on an RTX 5090 machine, driver 595.99.02, CUDA 13.2. Host tests ran on x86_64.

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 gpu The card engine: crates/gpu*, crates/app 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 Oct 28, 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 two new gate clauses copy the same 17-line kernel launch, and no failure path survived in the code itself.

Must fix

1. f32_alignment and finite_scaled_word repeat one launch block (kind B, one owner per fact)

gate_nvfp4.rs:906 and gate_nvfp4.rs:971 both build sel, y and the same Nvfp4Stack and SelArgs. Both call enqueue_nvfp4_gemv_sel_f32, read y[0], then call take_fault. Grep finds no other caller of enqueue_nvfp4_gemv_sel_f32 in gpu-gates, so these two are the only copies, and both are in this diff. The helper replaces about 40 lines in the two clauses with about 25, and removes two sel, two y and two Nvfp4Stack and SelArgs literals.
Fix: add this helper and call it from both clauses.

/// One expert-select launch of a one-row, one-expert NVFP4 stack over `x`:
/// the row's f32 and the fault the launch raised.
fn sel_f32(
    gpu: &Gpu,
    (qs, e, scales): (&DeviceTensor<u32>, &DeviceTensor<u32>, &DeviceTensor<f32>),
    x: &DeviceBuffer<f32>,
) -> Result<(f32, Option<bloomery_gpu::Fault>), GateError> {
    let stream = gpu.stream();
    let sel = DeviceBuffer::from_host(stream, &[0u32])?;
    let mut y = DeviceBuffer::from_host(stream, &[SENT])?;
    gpu.q8f32().enqueue_nvfp4_gemv_sel_f32(
        stream,
        Nvfp4Stack { qs, e, scales },
        &bloomery_gpu::q8f32::SelArgs {
            x,
            sel: &sel,
            n_slots: 1,
            rows_per_expert: 1,
            slots_per_col: 1,
        },
        gpu.unlabelled_sink(),
        &mut y,
    )?;
    Ok((y.to_host_vec(stream)?[0], gpu.take_fault()?))
}

In f32_alignment, replace the sel, y, launch, got and fault lines with let (got, fault) = sel_f32(gpu, (&qs, &e, &scales), x)?;. In finite_scaled_word, use let (got, fault) = sel_f32(gpu, (&qs, &e, &scales), &x)?; let clean = fault.is_none();. Remove the now-unused sel upload in f32_alignment. Adjust the types if the compiler asks.

Non-blocking

⚠ Doc claims a result the PR did not run: docs/contrib/dgx-spark.md:129 says --parallel 2 and --parallel 4 start without a context flag. The PR body shows a run only for --parallel 4, on one GB10 with one checkpoint. Name that run's conditions or drop --parallel 2.

Checked

  • Duplicates: 14 new items checked (functions, types, constants, one variant). One duplicate, the launch block (item 1). dryer: 0 pairs.
  • Complexity: f32_alignment (new, 21) is a gate clause with one loop and one branch per case. Checkpoint::read_bytes 15→20 grows by one bool, widened, and its factor term. routed::run +4 and qwen38::run +2 are even growth. No #[kernel] body was split. nv_word and nv_word_dot are #[inline(always)].
  • Silent failure: 6 sites followed. own_draft uses layer.ok().flatten(), but folder_draft_for (qwen38.rs:992) has already refused or turned off the draft on that Err. ArenaFloor::of(plan)? and least_reads(..)? propagate. pool_short returns None off a unified pool, so a discrete card still stops the seat. A set --ctx-size stays refused through Rule::Set.
  • Numeric order: the scalar fallback maps word w to the same values and quads as the aligned walk (first + off + 4·(off/4) equals quads 2w − w%2 and +2). nv_word_dot matches Nvfp4Values::at (code times ue4m3_half). The sum-order change is gated by the two new clauses.
  • Read bound: modelopt::plain copies raw.bytes.to_vec() for Matrix(Plain::Bf16), so dropping the ×4 for a whole, single-source, unstepped BF16 matrix is right. F32 and stacked tensors keep ×4.
  • Folder check: least_reads passes host_bytes room 0 and folder_holds puts the peak, ring included, in read_ahead. The load puts peak − ring in read_ahead and ring in shadows, so the sum is equal. The arena at its floor matches HostNeed::grant. The plan check is a lower bound of the load's check.
  • Tests (mutation): read_peaks_cover_the_owned_inputs_and_results turns red if the factor goes back to 4. routed_f32_alignment turns red if the fallback sum order differs (FAIL shown in the PR body). routed_f32_finite_scaled_word turns red if the scale moves after the activation multiply (FAIL shown on GB10). a_folder_plan_holds_its_reads_on_the_arena_floor turns red if the folder check is dropped from Plans::holds (shown). The PoolBudget and pool_short tests pin the new Short values. No test only prints.
  • Gates: no band, tolerance or lint moved. The unsafe-ratchet re-pins carry dated PIN lines with the reason.
  • Performance: hot path is the NVFP4 select gemv (decode). The PTX diff in the PR body shows fma 49→41 and scalar loads 39→15, with registers and local memory equal. The timed A/B shows no change within resolution. Headroom: none named.
  • Escape catalog: no pattern matched (no shell script changed).

Notes

  • The PR body leaves cargo fmt, cargo clippy and tools/check-comments.sh unrun on this head. Run them before merge. The diff adds no date, issue number or measured number to a comment under crates/*/src.
  • Evidence on a card: the body has the nvidia-smi line and just gate-gpu-nvfp4 output, but no commit hash of the head that ran. The speed table names only base hashes.

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

The seat holds a folder plan's least part reads beside its host need, with
the NVMe tier arena at its floor (ArenaFloor::of), since the load's own check
(HostNeed::grant) shrinks the arena to make room for them. On a unified pool
that refusal reads as short, so an unset context halves and a set one is
refused; where each card has its own memory the refusal stands.

HostTotals::room keeps the reading that decided the room the plan was held
to, so HostNeed::check_planned refuses at that room and names it: the
reading's own HostRead when its plan room binds, and HostRead::Machine (the
host's usable bytes less the OS reserve, or the unified pool) when a machine
cap does or the plan was made without a room. Plan::violations names its
machine-figure check the same way.

@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 earlier must-fix is fixed, and no new failure path survived in the changed commits.

Since the last review:

  • Must-fix 1 (the repeated launch block): fixed. gate_nvfp4.rs:883 adds sel_f32. f32_alignment (line 930) and finite_scaled_word (line 975) call it. The unused sel upload in f32_alignment is gone.
  • ⚠ The doc claim for --parallel 2: fixed. docs/contrib/dgx-spark.md now names --parallel 4 on one GB10 with the FP4-Local folder, which is the run in the PR body.

Checked

  • Duplicates: the one new item, sel_f32, checked. enqueue_nvfp4_gemv_sel_f32 has no other caller in gpu-gates outside the existing resident_sel_f32 sites, which go through site::. dryer: 0 pairs.
  • Complexity: f32_alignment is now smaller than the 17 crapper reported and is one loop with one branch. The other flagged functions are unchanged since the last review.
  • Silent failure: sel_f32 propagates every Result with ?. It reads fault through take_fault and the caller checks it. Fault is Copy, so fault.is_some_and(..) followed by fault.is_none() compiles.
  • Tests (mutation): the helper keeps the same launch arguments as the two removed blocks (n_slots 1, rows_per_expert 1, slots_per_col 1, sel = [0], y = SENT). The earlier mutants still turn the same clauses red: a changed fallback sum order for routed_f32_alignment, and a scale applied after the activation multiply for routed_f32_finite_scaled_word.
  • Gates: no pin moved by the new commits.
  • Escape catalog: no pattern matched (no shell script changed).

Notes

  • The PR body leaves cargo fmt, cargo clippy and tools/check-comments.sh unrun on this head. Run them before merge, because the helper edit is new on this head.
  • Card evidence: the body has the nvidia-smi line and the gate output, but no commit hash of the head that ran.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_nvfp4.rs, crates/gpu-gates/src/bin/generate_qwen3moe.rs, crates/gpu-gates/src/bin/shared/qwen3moe_place.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 efa54f2 into midagedev:main Oct 28, 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 gpu The card engine: crates/gpu*, crates/app 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant