Skip to content

gpu: Qwen3.8's step and verify skip the host leg on a layer the host serves nothing, and the hc norm loads a chunk before it uses it - #45

Merged
midagedev merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-decode
Oct 12, 2026
Merged

midagedev merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-decode

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

What and why

Part of #13. On a DGX Spark, all of Qwen3.8-Flash-Next UD-Q4_K_XL fits on the card, and these two commits make its
decode step faster there. Over six rounds against main in one lease, the median step is 1.0458 ± 0.0065 times
main's speed (main_ms / PR_ms of the p50 step), and tok/s(mean) reads 1.0908 ± 0.0289 (PR / main). Every arm
generates the same ids. The sitting ran on main e8e32a38, before the rebase onto b8d1ff06.

  1. The hc norm loads a chunk before it uses it. Each of the norm's two passes walked its stream one value a
    thread at a time: the loads, their use, and in the first pass a store back to the residual, then the next value.
    Now a thread loads 16 values and then uses them in the same order. The sum of squares adds the same terms in the
    same order, so every value keeps its bits. hc_gated_norm_4 (the step, the verify and the pass) and
    hc_gated_norm_4w (the ubatch walk) now share that body, norm_stream, so the wide entry is the capped one's
    body again, as the module doc says.
  2. A layer the host serves nothing runs without the host leg. A layer with every routed expert on the card still
    enqueued the go and the wait (two stream memory-operation batches) and told the host tier that its row was
    enqueued. With the whole plan that is 96 batch_mem_op nodes in each captured step. Now the load decides once
    per layer whether the step and the verify run it without the host leg (Card38::hostless). Three things must
    hold: every routed expert of the layer is on the card, no residency machine runs, and no route trace is recorded.
    A residency machine moves card experts to the host after the load (SwapMachine::layout), and the host service
    is where the route trace is written, so either one keeps every host leg. The trace is attached after the load, so
    the load learns of it from a new HostCfg::route_trace, which Levers::host sets when BLOOMERY_ROUTE_TRACE is
    set, and the lever's doc says so. On a load that runs a layer without its service (HostTier::mark_unserved,
    which the Qwen3.8 load sets), the host tier refuses by name a route trace attached after the load, whose message
    says the load's HostCfg::route_trace was false, and a residency machine started after it
    (HostTier::start_swap), before any slot moves. On such a layer the handoff still writes the row's image and the card's places and stops before
    the go. The back has no wait and no row_enqueued. shared_add takes the host's sum as an Option; None reads
    Card38::zero_sum, a zeroed row a token, which is what the host writes for an empty list. The zero row is
    allocated only when the load has such a layer. The prompt pass is unchanged. walk_launches and
    Body38::step_launches count the two memops only on a layer with a host leg, so generate_qwen3moe's capture
    check still holds the graph to the program, and the captured step goes from 1391 nodes to 1295.
    gate_qwen4exp_e2e's card clauses now derive the memops and the verify's host services they expect from the plan
    they load (Shape::memops_card, hostless). A new clause, card leg whole plan, loads the plan with no card
    budget and holds its steps (graph and eager) and its verify to the same plan loaded with every host leg kept, bit
    for bit, and checks that this load refuses a route trace and a residency machine by name. In the fixture tier
    that plan puts every routed expert on the card, which the clause requires, so its load has no memop and no host
    service. In the real tier the card's memory decides how many layers are whole, and the clause prints the count
    without requiring it; on a card the file does not fit, it compares two loads that both keep every host leg.

The commits are separate because they are separate contracts: the first is a kernel body with no change to its
callers, and the second is the program's shape on one kind of load.

Code shape

  • No second copy. hc_gated_norm_4 and hc_gated_norm_4w had the same body twice; they now call one
    norm_stream. The skip has one owner, Card38::hostless, which the handoff, both backs, the launch counts and
    the host tier's two refusals read.
  • Model code holds only architecture facts. The skip keys on the load (where its slot map put the experts,
    and whether a residency machine or a route trace runs), not on a model or a device. HostCfg::route_trace is
    a fact about the host service; only Qwen3.8's body reads it today.
  • Dead code is gone.
  • No silent failure. Card38::zero_sum is refused by name on a load with no hostless layer, a route trace
    or a residency machine on a load that skips a host leg is refused by name at the host tier, Card38::hostless and
    Shape::memops_card assert their ranges, and the capture check fails a step whose graph does not match the
    program's count (the FAIL-firsts are under "What I ran").
  • Comments state what is true now.
  • No relaxed gate. tools/unsafe-ratchet.txt goes from gpu 1729 192 10 to gpu 1731 193 10, the
    counts tools/check-unsafe.sh reads, with a PIN(2026-10-12): line: norm_stream is the new unsafe fn, its
    loads and stores each have a block and a SAFETY line, and the two entries each lose their copy of the body.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line): crates/gpu/src/hc_gated.rs, the bodies of hc_gated_norm_4 and
hc_gated_norm_4w (removed, now norm_stream). DeepSeek-V4.1's FFN (crates/gpu-deepseek41/src/chain/ffn.rs:1494)
and GLM-5.3's (crates/gpu-glm5next/src/ffn.rs:460) enqueue the go on every layer the same way. I left them alone
because those files need far more than a DGX Spark's 128 GB. I have no plan that puts every routed expert of one of
their layers on the card, so nothing here could test the skip there.

What I ran

The code is 0bd19edc, two commits on main b8d1ff06. The Mac checks ran on that tree. The GPU runs used
binaries built from this branch on main e8e32a38, dd187c1d and b8d1ff06, and the first-step runs under "The
A/B" used earlier builds; "Which binary ran what" at the end gives the trees and hashes.

On a Mac:

just mac-static upstream/main
mac-static: fmt-check rc 0 in 7 s
mac-static: lint rc 0 in 7 s
mac-static: combos rc 0 in 2 s
mac-static: check-arch rc 0 in 11 s
mac-static: check-comments rc 0 in 10 s
mac-static: check-defaults rc 0 in 1 s
mac-static: check-levers rc 0 in 8 s
mac-static: check-loads rc 0 in 62 s
mac-static: check-ptx-names rc 0 in 0 s
mac-static: check-recipes rc 0 in 528 s
mac-static: check-rustflags rc 0 in 0 s
mac-static: check-unsafe rc 0 in 1 s
mac-static: check-waits rc 0 in 0 s
mac-static: ok
just affected upstream/main --no-box
affected: b8d1ff06e..(working tree)

Each mac-static line is cut after its time. The lint step counts 41 warnings, the ratchet's 41, and combos ran 1
shape with 0 red (45 scoped out; its ledger held the others green from earlier runs of this branch). cargo check
for aarch64-unknown-linux-gnu (tools/mac-check.sh check with BLOOMERY_CHECK_TARGET) passes too. just affected names 11 changed files and selects 137 of the 149 gate recipes
(the levers crate is among the changed files) and 1 of the 7 weekly recipes (weekly-gpu-ds41-lost, which
crates/gpu/src/host/mod.rs triggers). cargo test -p bloomery-levers: 37 passed.

ptxas and ptx-scan. On the generate_qwen3moe PTX module of main and of this branch, with the dev container's
ptxas 13.3.73, and tools/ptx-scan.sh with the driver JIT (not --no-jit) on a GB10, the same numbers for
hc_gated_norm_4 and hc_gated_norm_4w:

Build sm_86 registers sm_121 registers Stack frame Spill stores / loads JIT registers / local bytes (GB10)
main 26 28 0 0 / 0 28 / 0
this branch 63 62 0 0 / 0 62 / 0

The two [f32; 16] arrays stay in registers: the PTX has no ld.local or st.local. I did not run just gate-ptx-spill, which checks the 0/0 pins these two entries carry in tools/ref/ptx-shapes.tsv (the
generate_ds41 and gate_e2e rows): its JIT column is an RTX 3090's, so that check is in your box run. On
e8e32a38, a full --no-jit scan of the module lists 229 entries on main and on this branch, and only these two
differ; on each side the two compile to the same PTX as each other (191 lines on main, 854 here). Their static occupancy goes from 6 blocks an SM to 4. That costs hc_gated_norm_4 nothing: its grid is 4
× m blocks with m at most 8, so 32 blocks at most, under one wave on a GB10 (48 SMs), an RTX A6000 (84) or an RTX
3090 (82).
The table is from main dd187c1d and this branch on it; the rebase onto b8d1ff06 changes no kernel.

Gates. On a DGX Spark, in the dev container, run directly from the built binaries:

  • gate_hc_gated: 60 PASS on main and 60 PASS on this branch (on 0bd19edc too), every stage bit for bit, and the wide arm's norm
    the capped entry's bits. FAIL-first (on e8e32a38): the same tree with pass 1 walking each chunk in reverse
    order (not committed) fails stages[xn] (bit_equal=false max_ulps=3) and stages[head].

  • gate_qwen4exp_e2e in the fixture tier passes its two structure clauses on the host plan (graph_nodes=113, 8 of
    them batch_mem_op) and then stops, as on main: the fixture tier opens the Qwen3.8 fixture, which this machine
    has, but it also reads the token ids of the real file's ik set (ref_qwen4exp/MANIFEST.tsv under
    BLOOMERY_DATA), which this machine does not have. So I ran the card clauses from a build of the gate whose
    run() keeps only them (not committed): the card leg's structure and rows on the half-card plan, then the new
    whole-plan clause. On 0bd19edc that build passes 30 checks, 0 FAIL. The half-card plan's verify reads 139 nodes
    with 8 batch_mem_op and 4 host services; the whole plan's reads 131 with 0 and 0, against 8 and 4 with every
    host leg kept, and its graph steps, eager steps and verify equal the kept load's bit for bit. The whole-plan load
    refuses a route trace and a residency machine by name:

    card leg whole plan: a route trace after the load -> HostTier::attach_route_trace: a route trace on a load whose step runs layer 0 without the host service, which writes the trace: the load's HostCfg::route_trace was false (Levers::host sets it from BLOOMERY_ROUTE_TRACE) PASS
    card leg whole plan: a residency machine after the load -> HostTier::start_swap: a residency machine on a load whose step runs layer 0 without the host service, to which the machine moves card experts: the load was made without one (its residency glue had no source) PASS
    

    FAIL-firsts, each a mutant of that build (not committed). On 0bd19edc, with the trace's refusal taken out:
    card leg whole plan: a route trace after the load -> taken FAIL. With the machine's refusal taken out:
    card leg whole plan: a residency machine after the load -> SwapMachine::new: no layer of the map names expert parts: the source holds no stacks the machine could move FAIL (the clause hands the machine a source with no
    parts, so it stops there instead of moving experts). On e8e32a38: the zero row swapped for the card's own sum
    (4 FAIL: the pass against the steps, and the graph steps, the eager steps and the verify against the kept load);
    every host leg kept fails the whole plan's verify structure (batch_mem_op=8 (want 0)) and services (7 FAIL); the
    verify expecting a service on every layer fails the whole plan's three verify cases (3 FAIL).
    The clause's real-tier path ran on no machine here: the count printed and not required, and on a card the file
    does not fit, the line that there is no refusal to check. With no budget, each card plans with its own usable
    bytes (PlanLevers), so that load fits the card.

  • cargo test -p bloomery-gpu-gates --lib q38_fixture (in the container; the crate does not build its tests on
    macOS), from the build on b8d1ff06 before this review's fixes (they change only a comment in that file): 2
    passed, with the new memops_card check.

  • Of the 137 gate recipes just affected selects, I ran only what is above and below. No unit test covers the
    changed step count (body38.rs's one test checks a hash), and the rest need your box.

Same output, and the FAIL-firsts. generate_qwen3moe at main and at this branch, Qwen3.8 UD-Q4_K_XL, one
process a run, -n 64, the same prompt, --mode graph and --mode eager, --logits (the fnv64 of the last logits
row) where the draft is off. In every run below, all 64 ids equal main's, and graph and eager agree.
I ran every case on main dd187c1d and this branch on it, and on this branch on b8d1ff06 before this review's fixes; main e8e32a38 read the
same ids and the same fnv64 in each. At 0bd19edc, the default plan in graph and eager reads the same ids and
55b10727a2f20da1 again.

Run Nodes in the captured step (batch_mem_op), main / this branch Last logits fnv64, main and this branch
Every routed expert on the card (the default plan) 1391 (96) / 1295 (0) 55b10727a2f20da1
--place a, BLOOMERY_CARD_BUDGET=84292M: 49 experts on the host, no layer whole 1391 (96) / 1391 (96) 34cd72db9b0d9f22
BLOOMERY_QWEN38_EXPERTS=host: every expert on the host 1151 (96) / 1151 (96) 8225b759e013a254
The default plan with the MTP draft 1391 (96) / 1295 (0) (no logits with a draft; ids equal)
The default plan, BLOOMERY_RESIDENCY=mid-p500-s1 1391 (96) / 1391 (96) 03a873fe24fa3e4e
The default plan, BLOOMERY_ROUTE_TRACE, --prefill step 1391 (96) / 1391 (96) c81f178744e72544

With the route trace, both builds seal positions=94 complete over all 48 layers, and the trace files
(MANIFEST.tsv, topk-<layer>.u16, slots-<layer>.u8) are byte for byte the same in graph and in eager.
bloomery-serve-qwen38 with BLOOMERY_ROUTE_TRACE on the default plan (tools/ref/route-trace-chat.py, one
request) writes main's trace byte for byte: 101 positions over 48 layers. One budget step above 84292M puts every
expert on the card, so I found no plan that leaves some layers whole and others not; only the fixture's whole-plan
clause and the real file's whole plan cover a hostless layer.

FAIL-firsts on the real file (not committed; on e8e32a38 unless the line says otherwise):

  • This branch before the review fixes, where the skip keyed on the slot map alone: BLOOMERY_RESIDENCY=mid-p500-s1
    stops with rc 1 in graph and in eager at the first decode step (SwapMachine::end_pass: row 0 at layer 0: slots [0..9] of top-10 not noted (1 rows kept)), and BLOOMERY_ROUTE_TRACE generates main's ids and logits but writes
    no positions.
  • This branch with Levers::host leaving route_trace unset, so the trace reaches a hostless load: on 0bd19edc,
    generate_qwen3moe (graph and eager) stops with rc 1 at the attach, HostTier::attach_route_trace: a route trace on a load whose step runs layer 0 without the host service, which writes the trace: the load's HostCfg::route_trace was false (Levers::host sets it from BLOOMERY_ROUTE_TRACE). On e8e32a38, where the
    refusal's text was older, bloomery-serve-qwen38 stopped at the same attach. Before the tier refused it, the
    seat's trace sealed 0 positions.
  • A build of this branch with main's step count (the two memops counted on every layer) failed the whole plan's
    graph run at the capture check, by name.

The A/B. tools/ref/depth-qwen3moe.sh with BLOOMERY_MODEL=qwen4exp, through tools/box.sh's local mode on a
DGX Spark's host, one lease, LC_ALL=C, stock clocks, six rounds with the order rotated each round, n = 160 with 16
warm steps, depth 6, BLOOMERY_DRAFT=off, on main e8e32a38 (before the rebase; of the files these commits change,
the rebase onto b8d1ff06 brought changes only to crates/levers and tools/unsafe-ratchet.txt). Before the
sitting I wrote the card in tools/ref/card.py format (card.py check: ok, h = 0.772 % at 6 rounds) with a
prediction of +4..+15 % for the runner's term, tok/s(mean), and 1.03..1.07 for the p50 step ratio. The arms were
ours (this branch), bin:<main's build> (main) and ours@BLOOMERY_AB_LOAD=arm (the A/A). The sitting began with the 1-minute and
5-minute load averages both under 1.0, no GPU process and no container.

Term Card Read (95 % t interval, 5 df) Per round, r1 to r6
p50 step, main_ms / PR_ms (from the ROW lines) 1.03..1.07 1.0458 ± 0.0065 1.0511 1.0442 1.0546 1.0458 1.0395 1.0394
tok/s(mean), PR / main (the runner's ratio line) +4..+15 % 1.0908 ± 0.0289 1.1260 1.0672 1.1242 1.0877 1.0687 1.0710
A/A p50 step 0.9996 ± 0.0018 1.0005 0.9999 0.9968 1.0018 1.0000 0.9983
A/A tok/s(mean) 0.9996 ± 0.0017 1.0010 0.9994 0.9974 1.0016 1.0000 0.9984
prompt tok/s at p = 6, PR / main 1.0099 ± 0.0263

Both terms read inside the card, so by its decide-in this pull request carries the p50 step first and the mean
beside it. Over the six rounds ours averages 30.88 tok/s with a 32.29 ms p50 step and a 32.39 ms mean step, and
main 28.32 tok/s, 33.77 ms and 35.33 ms. The mean term is larger because main has slow steps that ours does not:
main's mean step sits 2.50, 0.86, 2.34, 1.47, 1.05 and 1.11 ms above its p50 by round, and ours 0.08 to 0.10 ms.
Main's first10_p50 column (33.99, 33.54, 33.63, 33.61, 40.04 and 33.88 ms against a last10_p50 of 33.5 to 33.8
ms, 35.9 in r5) shows slow first steps in r5 only. It is the median of steps 1 to 10, which are all inside the 16 warm
steps, and the p50 and the mean come from the SMOKE line, which counts steps 17 to 159, so slow first steps cost main
nothing in either term. The slow steps the mean does count come later, in runs of a few to a few dozen steps, and they
have the same cause as the slow first steps.

These are diagnostic runs outside the lease runners; no number here decides anything. The sitting's log keeps no
per-step times, so I looked into it in separate runs on the sitting's DGX Spark, with the
same model file and the command of the sitting's bin: arm (--tokens 100000,53606,14808,58936,59336,53416 -n 160 --ctx 256 --time --warm 16, BLOOMERY_DRAFT=off), main e8e32a38 against this branch, under
BLOOMERY_STEP_STATS=1 (one run of each without it), with a 100 ms read of each thread's CPU and context switches
from /proc beside it. This branch's mean sits 0.085 to 0.104 ms above its p50 in all six runs. Main's mean sits 0.9 to 2.3 ms above
its p50 in nine runs of ten (in the tenth more than half the steps were slow and the p50 itself read 39.5 ms), and 88
to 100 % of that excess is in steps more than 1 ms over the p50. Those steps cost 5 to 8 ms each. In their stat step
records straggle_us reads about 11,000 against about 700 in a normal step, parks about 600 against 5, and leg_us
stays near 100 in both. No step past the warm ones takes a page fault, and the kernel does no reclaim while the steps
run.

The cause is the host leg's go wait. On main every hybrid layer of a step runs a service whose wait_go is a pool
job: the 19 workers, pinned to 19 of the 20 cores, and the decode thread, which is not pinned and runs the last chunk,
all spin on the generation word until the go lands, and the card waits at the layer's wait until the service
signals. When the scheduler puts the decode thread on a core that also holds a pinned worker, the two share that core.
The decode thread is then preempted about 1,000 times a second, each of the 48 services ends late, and the step takes
about 40 ms until the scheduler moves the decode thread back to the free core. In the thread samples, steps with the
decode thread on a worker's core averaged 39.5 to 41.7 ms across five runs, against 34.6 to 36.5 ms on the free core.
Three runs of main on another DGX Spark show the same: in the two where the decode thread spent time on a worker's
core, those steps averaged 41.0 and 42.3 ms against 34.1 and 34.2 ms on the free core, and main's mean sat 1.39 to
1.40 ms above its p50 in all three, against 0.07 ms for this branch. On the sitting's machine, the first steps are
slow when decode starts on a worker's core: the decode thread began on one in six runs and step 1 read 40 to 48 ms in all six; it began on a
free core in five runs and steps 1 to 3 read 33 to 35 ms in all five. Waiting 30 s between the load and the first
step (--arm-sync) did not change this, so it is not something left over from the load. Shorter bursts come when
another task takes a worker's core while the decode thread has its own: a wider /proc read that also took every other
process's CPU time, about 10 ms of CPU every 100 ms on one worker's core, added 4 to 8 ms to every third step of main
with the decode thread held on the free core (taskset -c 19; the workers pin themselves). Under the same read this
branch's mean sat 0.10 ms above its p50. On the other DGX Spark, the bursts that remain with the decode thread on its
own core and no sampler came from a monitoring script that reached the box over SSH every 5 s and ran nvidia-smi,
docker ps and a journalctl search. Each time, for about half a second, most cores took a burst of process starts,
page faults and RCU work; the 19 workers together waited 23 to 45 ms per 100 ms for their cores (2 to 3 ms otherwise)
while the decode thread waited under 1 ms per 100 ms, and seven or eight steps of main ran long, up to 69 to 92 ms.
That was 60 to 85 % of main's excess over its p50 in those runs. This branch ran through the same probe: the mean
of its steps in each 100 ms window stayed within 2.1 ms of its p50, and its mean sat 0.105 ms above its p50. Parking is a symptom, not the cause: with BLOOMERY_SPIN=0 the workers park about
640 times a step and the steps stay at 33 to 34 ms while the decode thread has its own core, and with
BLOOMERY_SPIN=2000000 they never park and the bursts still come. This branch runs no host leg in the step on this
plan, so a step runs no pool job and waits for no go, and the slow steps that come from the go wait do not reach
it.

On main the effect could be reduced without this pull request, for example by leaving a core out of the pool
(BLOOMERY_THREADS=19 here: the decode thread found a free core within one or two steps and main's mean sat 0.5 and
0.6 ms above its p50 in two runs) or by pinning the decode thread to a core the pool does not use. I have not changed
either.

How much of the mean term this is, as an estimate: in those runs on the sitting's machine, main's steps outside the
slow runs sit about 0.1 ms above its p50, as this branch's do. With main's mean at its p50 plus 0.1 ms in each round
of the sitting, tok/s(mean) would read 1.0459 ± 0.0065 instead of 1.0908 ± 0.0289. So about half of the mean term's
9.1 points (4.5) comes from main's slow steps, and the rest matches the p50 term (1.0458 ± 0.0065). The runner tags
every main row [cold]; for a bin: arm it counts major faults over the whole process, load included (about
330,000), so the tag does not say whether the timed window faulted. The ours rows (both arms) fault 0 to 3 times in
their timed window, and main's steps faulted 0 times in the runs above.

The 38 witness blocks show no Xid, event reasons 0x0 in every block, the SM clock at 2411 to 2424 MHz (208 MHz in
one, before the first load), and MemAvailable at 116.4 to 116.7 GiB in the 26 blocks taken with no model loaded
(37.2 to 37.3 GiB in the 12 taken while one was). No row was tagged [cpu-busy]. The ids were equal in all six
rounds. resident_bytes reads 83282041996 for ours and 83281960076 for main; the 81,920 bytes between them are
the zero row.

What I ran into

  1. The skip first keyed on the slot map alone. The first version of the second commit decided per layer from the
    load's map, so it also skipped the host leg under a residency machine and under a route trace. Both broke on the
    whole plan (the FAIL-firsts above). The decision now sits in Card38::new. The trace is the awkward one: the
    load cannot see it, so it comes in through HostCfg::route_trace, and a trace attached to the tier without it is
    refused there. If you would rather attach the trace inside the load, or keep the flag off HostCfg, say so and I
    will move it.
  2. A third commit, left out. q5_1_gemv_sel (the Q5_1 expert down kernel, 43 of the 48 layers on this file) can
    walk four rows a warp instead of one. Each lane's terms keep their order, so gate_kquant's Q5_1 clause stays bit
    for bit (max_ulps 0 at every shape). The launcher then refuses an expert size that is not a multiple of four,
    and the gate gains that case, which main accepts (the one FAIL on main). Its card said to include it if the
    sitting read inside +0.5..+1.0 %, and it read 1.0088 ± 0.0021 in tok/s(mean) and 1.0090 ± 0.0024 on the p50 step
    against this pull request's build at the time, both as bin: arms. I still left it out. The card's h (0.193 %)
    rested on the A/A spread of this pull request's first sitting, and the q5_1 sitting's own A/A came out at
    0.9967 ± 0.0111, so that assumption did not hold. AGENTS.md's ruler also cannot read a difference under 1 %
    between two binaries. The commit is on my fork's dgx-spark-q38-q51 branch. A lever that picks one row or four
    rows a warp inside one binary would let a same-binary sitting decide it; I can send that as its own pull request if
    you want it.
  3. gpu: on an integrated device, a decode gemv warp asks L2 for its whole row before the walk #27's prefetch does not reach these kernels. The L2 row prefetch from gpu: on an integrated device, a decode gemv warp asks L2 for its whole row before the walk #27 is on the Qwen3.6 path only. It does
    not reach the Qwen3.8 card leg's kernels or its fused router.
  4. The router's rows a block. sparkrouter in docs/research/sparkdec.md (section 7.1) covers
    qwen35moe_router_norm and leaves _fused out, but Qwen3.8 decode runs qwen35moe_router_fused_512. The same
    regrid (eight rows a block, with gpu: on an integrated device, a decode gemv warp asks L2 for its whole row before the walk #27's prefetch) can go on that kernel, and I have it as a commit on top of gpu: on an integrated device, a decode gemv warp asks L2 for its whole row before the walk #27.
    I can send it separately if you want it.

Docs

I changed no docs. No doc gives the Qwen3.8 step's node count or says that a layer the host serves nothing still
waits for it, so none goes stale here.

Hardware (if the change is for a machine)

Three DGX Sparks: one ran the sitting, the runs on e8e32a38 and 0bd19edc, and most of the first-step runs, one
the runs on dd187c1d and the first ones on b8d1ff06, and one the other first-step runs and the earlier sittings under "What I ran into". On
all three, nvidia-smi --query-gpu=name,driver_version prints NVIDIA GB10, 595.84. CPU: 20 cores (10 Cortex-X925
and 10 Cortex-A725). MemTotal is 127535272 kB, 127535276 kB and 127599376 kB. All three run DGX OS 7.6.0 (the OTA
version in /etc/dgx-release) on Ubuntu 24.04.5 LTS, kernel 6.17.0-1032-nvidia. The model is Qwen3.8-Flash-Next
UD-Q4_K_XL (the four-part GGUF). I built in the project's dev container (CUDA 13.3.1, the pinned nightly) with
cargo oxide build --arch sm_86 -- -p bloomery-gpu-gates --features gpu --release --bin <name> (--features gpu,deepseek41 for bloomery-serve-qwen38), which the PTX JIT compiles on GB10. No local change to the trees on
e8e32a38, dd187c1d and b8d1ff06. The first sitting's trees on aa6df234 had target-cpu=native in place of
znver3 in .cargo/cuda-oxide.toml, because znver3 stops rustc on aarch64.

Which binary ran what (sha256, first 12 digits):

@midagedev

Copy link
Copy Markdown
Owner

Thanks — the per-launch numbers and the same-ids check are clear. This one touches kernels (hc_gated) and Qwen3.8's step, so it needs our box's ptx-scan and the A6000 A/B. It comes after the 0.3.0 tag, after #43; I will post the review here.

@midagedev

Copy link
Copy Markdown
Owner

Review done. The sum order in norm_stream holds on paper (same index order, same mul_add, same block_sum). Thanks for the clear write-up.

It does not apply to main any more: qwen3moe/ moved a lot since aa6df23 (body38.rs:126 and the ratchet line conflict).

Asks:

  1. Rebase onto main (23ee210 or later) and recompute the unsafe-ratchet.txt pin from main's count.
  2. hc_gated.rs: show ptxas spill / local bytes for hc_gated_norm_4 and _4w before and after. They are pinned at 0/0, and the two [f32; 16] arrays can spill if the loop does not fully unroll.
  3. card38.rs: list every trigger of keep_host. The PR checks residency_glue.source(); anything else that moves experts to the host after load must also keep the host leg.
  4. The skipped leg adds + 0.0 instead of the host sum. Please say why a -0.0 row cannot reach it, or keep the sign.
  5. levers: Levers::host() hard-codes route_trace: false and the bin overrides it. One line in the doc, or derive it from the lever.

After the rebase we run the box side: ptx-scan + spill gate, the Qwen3.8 owning gates, and one same-lease A6000 A/B for the skipped legs.

… chunk of 16 values a thread before it uses them, so a pass's loads go out together; the sum of squares keeps its order and every value its bits

Each of the norm's two passes walked its stream one value a thread at a time: a load (of the residual, and of y or gamma), its use, and in the first pass a store back to the residual, then the next value. norm_stream, now the one body of both entries, loads 16 values a thread first and then uses them in the same order, so the sum of squares adds the same terms in the same order and every stored value keeps its bits. gate_hc_gated: 60 PASS, as on main, the wide arm's norm the capped entry's bits; a mutant whose first pass walks each chunk in reverse order fails stages[xn] (max_ulps 3) and stages[head]. tools/unsafe-ratchet.txt pins gpu at 1731 blocks and 193 fns with the count.

ptxas 13.3 gives each entry 63 registers at sm_86 and 62 at sm_121 (26 and 28 on main), with no stack frame and 0 bytes of spill stores and loads, and the driver JIT on a GB10 gives it 0 bytes of local memory. ptx-scan changes only these two entries; the two compile to the same PTX as each other, on main and on this branch.
…the load put every routed expert of it on the card and runs no residency machine and no route trace: no go, no wait, no row_enqueued, and zeros for the host's sum

Such a layer still enqueued the go and the wait, two stream memory-operation batches, and told the host tier the row was enqueued, though the host serves it nothing. With every routed expert on the card (the whole plan on a DGX Spark) that is 96 batch_mem_op nodes in each captured step. The load now decides it once per layer (Card38::hostless, made in Card38::new): every routed expert of the layer is on the card, and keep_host is false. A residency machine moves card experts to the host after the load, and the host service writes the route trace, so either keeps every host leg: the load reads the machine from its residency glue and the trace from HostCfg::route_trace, which Levers::host sets when BLOOMERY_ROUTE_TRACE is set (the trace is attached after the load). On a load that runs a layer without its service (HostTier::mark_unserved, which Body38's load sets), the host tier refuses by name a route trace attached after the load, saying the load's HostCfg::route_trace was false, and a residency machine started after it (HostTier::start_swap), before any slot moves. BLOOMERY_ROUTE_TRACE's lever doc says that on a qwen4exp load it keeps every layer's host leg.

On a hostless layer the handoff writes the row's image and the card's places and stops before the go, the back has no wait and no row_enqueued, and shared_add takes the host's sum as an Option: None reads Card38::zero_sum, a zeroed row a token (PASS_ROWS x HIDDEN f32, 81,920 bytes, counted in Card38::bytes), which is what the host writes for an empty list (out.fill(0.0)), so the sum keeps main's bits; it is allocated only on a load with a hostless layer. The prompt pass is unchanged. walk_launches and Body38::step_launches count the two memops only on a layer with a host leg, so generate_qwen3moe's capture check still holds the graph to the program. gate_qwen4exp_e2e's card clauses expect the memops and the host services of the plan they load (Shape::memops_card, hostless), and a new clause, card leg whole plan, loads the plan with no card budget, holds its step, eager and graph, and its verify to the same plan loaded with every host leg kept, bit for bit, and holds the load to both refusals by name. In the fixture tier that plan puts every routed expert on the card, which the clause requires (no memop, no host service); in the real tier the card's memory decides how many layers are whole, and the clause prints the count without requiring it. A load that fails is a named FAIL.

Same output as main e8e32a3 (ids and the last logits row's fnv64), graph and eager: the whole plan (its captured step goes from 1391 nodes, 96 of them batch_mem_op, to 1295 and 0), a plan with 49 experts on the host, every expert on the host, the whole plan under BLOOMERY_RESIDENCY=mid-p500-s1, and the whole plan with a route trace (the same 94 positions over 48 layers, byte for byte); with the MTP draft the ids. bloomery-serve-qwen38 with a route trace on the whole plan writes main's trace byte for byte (101 positions over 48 layers). A build whose Levers::host leaves route_trace unset now stops both of them at the trace's attach with the tier's refusal, where the trace used to seal 0 positions. gate_qwen4exp_e2e's card clauses and the new one, run in the fixture tier from a build whose run() keeps only them (not committed; the whole run also reads the real file's ik sets), pass; mutants (not committed) fail them by name with the zero row swapped for the card's sum (the steps and the verify leave the kept host legs' bits), with every host leg kept (8 batch_mem_op, want 0), with the verify expecting a service on every layer, and with either refusal taken out. Before the residency and trace terms, the residency run stopped at its first decode pass (SwapMachine::end_pass: slots not noted) and the trace sealed with 0 positions. With main's step count, the whole plan's graph run fails the capture check by name.

With the hc_gated_norm commit before it, Qwen3.8 decode on a DGX Spark reads 1.0458 ± 0.0065 on the p50 step (main_ms / PR_ms) and 1.0908 ± 0.0289 in tok/s(mean) (PR / main) against main e8e32a3, with an A/A of 0.9996 ± 0.0018 and 0.9996 ± 0.0017 (tools/ref/depth-qwen3moe.sh, six rounds in one lease, n = 160, draft off), the ids equal.
@juliankang4

Copy link
Copy Markdown
Collaborator Author

@midagedev Thanks for the review. I rebased the branch onto main b8d1ff06; it is now 0bd19edc.

  1. tools/check-unsafe.sh counts gpu at 1729 blocks and 192 fns on main and 1731 and 193 here, and the PIN line says so.

  2. ptxas 13.3.73 -v on the generate_qwen3moe PTX module, main and this branch (on e8e32a38 and again on dd187c1d), gives the same numbers for hc_gated_norm_4 and hc_gated_norm_4w:

    sm_86 regs sm_121 regs stack frame spill stores / loads JIT regs / local bytes (GB10, driver JIT)
    main 26 28 0 0 / 0 28 / 0
    this branch 63 62 0 0 / 0 62 / 0

    The JIT column is tools/ptx-scan.sh with the driver JIT (not --no-jit) on a GB10. The two arrays stay in registers; the PTX has no ld.local or st.local. I did not run just gate-ptx-spill, which checks the 0/0 pins of these two entries (the generate_ds41 and gate_e2e rows of tools/ref/ptx-shapes.tsv): its JIT column is an RTX 3090's, so that check is in your box run. On e8e32a38, a full --no-jit scan of the module lists 229 entries on main and on this branch, and only these two differ; the two compile to the same PTX as each other on both sides.

  3. keep_host is the one switch, and two things set it: a residency machine (the load's residency glue has a source) and a route trace (HostCfg::route_trace, from BLOOMERY_ROUTE_TRACE). On this body only the residency machine moves an expert between card and host after the load: SlotMap::admit and SlotMap::evict are called only from host/swap.rs and slots.rs's tests, and the glue starts the machine only when it has that source (ResidencyGlue::start). BLOOMERY_XSTREAM's admit and split are refused without a machine (Body38::set_xstream), so they keep the host leg through it. A route trace does not move experts, but the host service writes it, so it keeps the leg too. Both could still be started after the load through hybrid_mut() (attach_route_trace, start_swap), past the load's check. The host tier now refuses both by name on a load that runs a layer without the service (HostTier::mark_unserved, which the Qwen3.8 load sets), start_swap before any slot moves. The trace's refusal says that the load's HostCfg::route_trace was false, which Levers::host sets from BLOOMERY_ROUTE_TRACE. The whole-plan clause of gate_qwen4exp_e2e now checks both refusals by name.

  4. The host writes +0.0 for an empty list. The step's service, HostLayer::experts_into_on, fills its output with 0.0 before it checks for an empty list (crates/model/src/moe.rs:2449 on b8d1ff06), and the verify's union call does the same when no column lists a host expert (serve_planned, moe.rs:1814). The skipped leg reads a buffer made with DeviceBuffer::zeroed, so the same +0.0 bits, into the same shared_add kernel. Whatever the card sum's sign, including -0.0, it meets the same +0.0 it met on main, so the output bits are main's. The whole-plan runs read main's ids and last-logits fnv64 in graph and eager.

  5. Levers::host() now derives route_trace from the lever (self.route_trace().is_some()), and the bins no longer override it. The lever's doc says that on a qwen4exp load it keeps every layer's host leg.

The whole-plan clause also runs in both tiers now. It requires every layer to be whole only in the fixture tier, and a load that fails is a named FAIL instead of an abort.

I also updated the PR body: a paragraph on why main's first steps are slow (under "The A/B"), the binary list, and the FAIL-firsts.

@midagedev

Copy link
Copy Markdown
Owner

Thank you for the rebase and the answers. I will review 0bd19ed after the 0.3.1 tag today. It moves a kernel, so it goes through the box gates and a ptx-scan then.

@midagedev

Copy link
Copy Markdown
Owner

Thank you for the rebase and for answering all five asks. The sum order, the ptxas table and the refusals read right.

You do not need to rebase again. Main will move once more when the 0.3.2 train lands tonight. After that we merge main into this branch ourselves, which resolves the tools/unsafe-ratchet.txt conflict, and we run the box checks:

  • ptx-scan and gate-ptx-spill for the two norm entries;
  • the Qwen3.8 gates in the fixture tier;
  • an A6000 A/B. The A6000 plan puts no layer whole, so that A/B prices the norm commit. Your Spark table stays the evidence for the skipped memops.

Then it lands in the next train. I will post the numbers here.

@midagedev
midagedev merged commit eb1ee79 into midagedev:main Oct 12, 2026
1 check passed
midagedev added a commit that referenced this pull request Oct 12, 2026
…ps on a layer the reference hosts nothing on

The reference load runs a layer whose routed experts are all on the card
without its go and wait (Card38::hostless); the tier load keeps the leg on
every tier layer. The expected tier stage nodes are the reference's less one a
tier layer plus HOST_LEG_NODES (2) a tier layer the reference's plan hosts
nothing on, read per layer from that plan. On the fixture all four tier layers
are unhosted (125 - 4 + 8 = 129); on the real file every layer is hosted and the
clause reads ref - 48 as before. The clause stays exact.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@juliankang4 juliankang4 added gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset labels Oct 13, 2026
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 host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants