Skip to content

model-hf, qwen3moe: a Qwen3.8 NVFP4 folder's routed stacks stay where the folder stores them - #1034

Merged
juliankang4 merged 5 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-offload-shared-layer
Oct 31, 2026
Merged

juliankang4 merged 5 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-offload-shared-layer

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8 NVFP4를 체크포인트 폴더와 GGUF 모두에서 카드와 호스트로 나눠 serve할 수 있게 고쳤습니다.

What and why

A Qwen3.8 NVFP4 model could not be served split between the card and the host. The checkpoint folder was refused at load (parts::load: blk.0.ffn_down_exps.weight is placed on Card(0) and Host: a load from a part source holds every tensor whole on card 0 ...), and the shipped GGUF (type 40) was refused by the placement rule.

Part of #1022. This is the shared layer for the offload work: a routed stack's experts go to the host only where a host kernel runs them (kernels::host_stack, used by both the plan and the load check); host::swap carries an NVFP4 plane's source form and target length; a part source reads an NVFP4 stack's whole experts past the page cache; a located stack's runs may each lie in their own shard (144 stacks in the folder's index, 21 of them span more than one shard); and a folder load keeps a plain NVFP4 stack where the folder stores it instead of rebuilding it (Keep::InPlace). No kernel file changes, so an all-card load is bit for bit the one before.

The folder split serves with BLOOMERY_RESIDENCY=off. The GGUF split serves at the defaults.

Release notes: Fixed: a Qwen3.8 NVFP4 model, as a checkpoint folder or the shipped GGUF, now serves split between the card and the host instead of being refused at load.

Code shape

  • No second copy. The host-capability rule has one owner, kernels::host_stack, which the plan and the load check both call; the NVFP4 plane conversion extends host::swap's Transform instead of adding a second path.
  • Model code holds only architecture facts. Qwen3.8's stacks are declared as NVFP4 rows in planes; no common owner gained a per-model branch.
  • Dead code is gone.
  • No silent failure. A split the host kernels cannot run is a named PlacementError::NoHostKernel; a plan that pages a located stack from the NVMe tier stops with a named error.
  • Comments state what is true now.
  • No relaxed gate. Two refusal clauses are removed with their reasons in PIN(...) lines (crates/placement/src/placement/tests/bounds.rs, crates/model-hf/src/folder.rs); no band or tolerance moved.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

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

What I ran

Head 292c1328f on upstream main 294f8d6b4, on a DGX Spark (hardware below). The gate bundle printed:

just gate-gpu-swap
gate_swap: PASS
just gate-gpu-xstream
gate_xstream: PASS
BLOOMERY_CARD_ALL_EXPERTS=1 BLOOMERY_REF_MODEL=<nvidia Qwen3.8-Flash-Next-NVFP4 folder> just gate-gpu-qwen4exp-nvfp4
(l) plan card=GB10 ctx_max=3072 ubatch=3072 host_experts=0 card_experts=24576 layers short of 512 card experts: [] PASS
(p) the batch set by one pass: last argmax ours=11751 oracle=11751 logits_rel=5.037e-2 kld=0.008083050 (printed) PASS
(g) the batch set by one ubatch: last argmax ours=11751 oracle=11751 logits_rel=8.703e-2 kld=0.015801894 (printed) PASS
(s) plan card_budget=73734243024 host_experts=3066 card_experts=21510 layers split between the card and the host: 48
(s) the split load: the plan splits true, the oracle's band held true; last argmax 11751 the all-card run's 11751, logits_rel to it 5.542e-2 (printed) PASS
(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

The library tests of the changed modules, and the NVMe tier's paged read of a GGUF stack on the card:

bash tools/gate.sh --gpu --oxide -p bloomery-gpu --release --lib -- --include-ignored --skip hw_ host::nvtier:: host::tier_cpu:: arch::qwen3moe::swap arch::qwen3moe::card38 folder:: parts:: host::node host::swap host::lane host::xstream planes::
test result: ok. 112 passed; 0 failed; 0 ignored; 0 measured; 360 filtered out
RUST_TEST_THREADS=1 bash tools/gate.sh --gpu --oxide -p bloomery-gpu --release --lib -- --include-ignored --exact host::tier_cpu::tests::hw_held_node_nvme_host_run_keeps_eager_and_captured_rows
test host::tier_cpu::tests::hw_held_node_nvme_host_run_keeps_eager_and_captured_rows ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 471 filtered out

Before and after, serving the checkpoint folder under a 60G card budget (bloomery-serve-qwen38 --place a --ctx-size 4096, BLOOMERY_CARD_BUDGET=60G, BLOOMERY_DRAFT=off, a 128 token greedy /completion). On 13d469be1, the base at the time:

bloomery-serve-qwen38: parts::load: blk.0.ffn_down_exps.weight is placed on Card(0) and Host: a load from a part source holds every tensor whole on card 0, and reads a row-gathered table from the NVMe tier

On the head, with BLOOMERY_RESIDENCY=off:

plan place=a card=GB10 experts=card ctx_max=4096 host_experts=6759 card_experts=17817 ...
load host_tier type=nvfp4_rows k=2560 path=planes
load arch=qwen4exp resident_bytes=61601187448 ... in 9.9 s (runtime value)
tokens 128 stop limit

The shipped GGUF split under the same budget, at the defaults:

plan place=a card=GB10 experts=card ctx_max=4096 host_experts=6868 card_experts=17708 ...
load arch=qwen4exp resident_bytes=61473083692 ... in 34.5 s (runtime value)
tokens 128 stop limit

The folder all-card serve on the base and on the head give the same 128 ids and the same probabilities:

match base-folder-card.json vs folder-card.json: greedy ids equal for 128 of 128/128; ids identical=True; probabilities identical=True

Each split against its own format's all-card serve, on the head (128 tokens, each id's top two requested):

match folder-card vs folder-split-off: greedy ids equal for 64 of 128/128
match gguf-card vs gguf-split: greedy ids equal for 92 of 128/128

Both splits differ from all-card at a position where the top two candidates are within 0.3 nats (folder at 64: gaps 0.0703 and 0.1523; GGUF at 92: gaps 0.2659 and 0.0022), and agree with it before that.

Hardware (if the change is for a machine)

DGX Spark: nvidia-smi --query-gpu=name,driver_version,compute_cap prints NVIDIA GB10, 595.84, 12.1. The gates ran in the project's dev container (CUDA 13.3.1) built with --arch sm_121.

AI help

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

…kernel runs them

The plan put any routed stack the card rule left over on the host as its
file bytes, whatever the host could compute: a BF16 or F16 stack, which no
host kernel reads, planned and fit by its bytes and was refused only at load
by the host tier's check. The split's one owner (routed_row_on_as) now asks
the host's executor rule, kernels::host_stack: a fused qdot kernel for the
type on this machine and a row width of whole units, the rule
model::ops::host_stack_runs now delegates to. A host segment of a stack it
refuses is PlacementError::NoHostKernel, naming the tensor, the type, the
width and the experts the host would hold.

The node scale tests' one-layer model held I8 stacks no host kernel runs;
it holds MXFP4 rows of the same bytes, which the host runs and no card rule
there reads.
The plan refused an NVFP4 routed stack with some experts on a card and the
rest on the host: the card holds the stack as planes, and a residency swap
copied the file's blocks into a card slot. The host's NVFP4 dot reads the
file's blocks, so the plan now splits such a stack as it splits any other,
and every reader of a split stack takes it:

- Transform::Nvfp4Codes and Ue4m3Scales name their source form (Nvfp4From):
  a folder's plane, or GGUF's NVFP4 blocks, whose one run holds both planes
  interleaved. A slot part is Transform::target_len of its source, so the
  lane and the expert stream check and stage a part of another length than
  its source; planes::split_plane moves one plane of the blocks, checked as
  the load's split_rows checks a row.
- FileSwap stages a GGUF NVFP4 expert's three planes from its one run
  (through the NVMe arena when it serves the id, which holds the run whole),
  reads its tensor scales from the stack's .scale, and holds NVFP4 planes
  for either NVFP4 file type. card_bytes gives a plane as the static load
  uploads it.
- A Qwen3.8 load whose card route reads NVFP4 planes refuses
  BLOOMERY_XSTREAM=split by name (XSTREAM_FORM): its ring pass reads words.
  Unset, the rule then takes admit, as it does for a ring with no room.
- The residency's unset word turns off beside the NVMe tier only for NVFP4
  rows a folder locates.

gate_qwen4exp_nvfp4 gains (s): the all-card plan under a card budget 8 GiB
short, whose eager steps hold (c)'s band against the oracle.
…e page cache

A card's share of a split stack (its experts along the stack or by a
list) was normalized through the shard mapping: page faults on the
reading thread, the page cache filled with the experts' bytes. It now
takes the bounded direct reads a whole NVFP4 stack takes
(`read_nvfp4`), over the sources the part reads whole
(`whole_sources`, which `read_from` and `release` share), and its read
bytes count that batch and the part's own output. A part that cuts
rows still reads them through the mapping.
…their own

A checkpoint folder keeps a stack's experts wherever its shards fall:
of Qwen3.8-Flash-Next-NVFP4's 144 routed stacks, 21 cross a shard
boundary, and 5 matrices keep their block scales in the next shard
from their codes. A located stack held one shard, so the folder refused
such a stack by name ("not the stack's file", "the one matrix a stack of
planes holds").

gguf::Place::Stack names the shard of every run (codes_in, scales_in
beside codes_at, scales_at); the first matrix's codes shard lists the
stack in its table. Split::located checks each run inside its own file,
and overlap only between runs of one file; Split::matrix reads each run
from its shard. The host's StackRuns carries the same shards and reads
them through the split's files (ops::Files), and host_lock's expert
runs and page walks name each run's file. stack_in_place records each
plane's file instead of refusing a second one.
… the folder stores them

A Qwen3.8 checkpoint folder made every tensor for the card, so its header
located no file: the host could hold no routed expert, a plan that split
the experts was refused by the load, and no residency machine ran. The
qwen35moe map now keeps the routed stacks in place as NVFP4 rows planes,
as the minimax-m3 and nemotron maps do, so a load reads them where the
folder stores them and the plan splits them between the card and the host
as a GGUF's.

- folder::Keep says where a plan reads a tensor its map keeps in place:
  where the folder stores it (open), or nowhere (read, which prepare
  writes, and a draft), so prepare's split still holds made NVFP4 stacks.
- A stack is kept only where its stored format is the rows type it is
  declared as; FP4-Local's stacks, whose csf block scales the host does not
  read, are made for the card as before.
- The card holds NVFP4 rows as NVFP4's planes, so card38's leg types read
  them as NVFP4 (the same upload and kernels as before).
- gate_qwen4exp_nvfp4 takes a folder whose routed gate is NVFP4 rows.
- The NVMe expert tier reads a paged stack from its file run
  (gguf::Split::run), so a plan that pages a folder's located stacks is
  refused by name where it read a header offset no file holds.
- The qwen38 seat, Folder38, serving.md, dgx-spark.md and the README say
  the NVFP4 folder's experts split; FP4-Local's stay on the card.
@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 host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset 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 placement Placement planning: crates/placement tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 31, 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: No reachable behavior defect or mechanical quality defect was proved.

Non-blocking

⚠ Verify live NVFP4 residency: crates/gpu-gates/src/bin/gate_qwen4exp_nvfp4.rs:632 forces residency off. This catches the load refusal but does not exercise the new staging path during an admission or eviction. Exercise migrations for the NVFP4 folder and GGUF, checking all plane parts, migration counts and eager/captured outputs. The existing residency gate needs adaptation: it opens GGUF directly and checks only three parts per expert.

⚠ Supply the host dispatch performance proof: crates/model/src/ops.rs:1385 builds shard maps through host_resident → expert_runs → stack_runs. For a full resident expert check over three located stacks of 512 experts, the change adds six shard-vector clones (24,576 bytes on a 64-bit host), at least six map allocations and at least three metadata-vector allocations per check, multiplied by checks per token [derived]. Read the existing split placement directly for one expert, or provide a same-lease A/B with live migrations. The move/split proof also needs identical PTX and unchanged host dispatch structural counts.

Checked

Duplicates: 28 new functions, types and constants checked. No qualifying duplicate found. Dryer reported zero pairs; GPU owners were searched manually.
Complexity: split is new (18), combining plan/load/run checks. Place::check (+5) adds shard validation; tensor_scales (+5) adds the GGUF source. Growth in planned_tensors, xstream_rule, assemble, host_pages, gate run and NvTier::of_paged adds origin, fallback, shard or refusal cases. Complexity alone produced no finding.
Silent failure: 10 default/conversion sites followed. Invalid runs, unsupported host rows and invalid scales reach named errors. Validated made tensors and optional streaming paths account for the remaining defaults.
Tests: static mutation checks only. Force the first shard in reads or page ranges → cross-shard assertions fail; omit scale validation → refusal/sentinel assertions fail; keep NVFP4_ROWS as the card leg type → type assertion fails; disable in-place origins → origin assertions fail; reverse listed experts → byte assertions fail; reject GGUF planes → part-count assertions fail; restore the split refusal or remove the host-capability check → placement/gate assertions fail. Other test edits adapt fixtures to the host-capability contract.
Gates: no band or tolerance moved. Removed refusal clauses have dated PIN reasons and replacement assertions.
Escape catalog: C1–C4 did not match.
Adversarial: checked cross-shard offsets, invalid scales, CSF fallback, located stacks on the NVMe tier and staging destination lengths. Existing guards blocked the constructed failures.

Notes

No builds or hardware tests were run here. Reported GB10 gate evidence names head 292c1328f; the reviewed head is 838061905.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_qwen4exp_e2e.rs, crates/gpu-gates/src/bin/gate_qwen4exp_nvfp4.rs, crates/gpu-gates/src/bin/shared/qwen38_open.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 Oct 31, 2026
@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

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 gpu-evidence Verified on the author's card: the pull request carries the gate run and its output host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja 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