Skip to content

qwen38: launch a verify before its PLE rows arrive - #877

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-r1m1-hostwait
Oct 27, 2026
Merged

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

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Qwen3.8 FP4-Local MTP의 verify step이 PLE 행을 기다리지 않고 graph를 먼저 실행하게 해, DGX Spark의 MTP 디코드 속도를 높이는 속도 PR입니다.

What and why

A verify step used to read its PLE rows, decode them and copy them to the card before it launched the verify graph. The card sat idle for that read and copy. Now the graph is launched first. At the layer with the PLE site the graph waits on a host flag and copies the rows from page-locked staging, and the engine thread reads and delivers the rows after the launch.

A PLE fill that needs its rows at once (draft rows, a pass, slot rows, a step with no read ahead) now reads on the calling thread when the reader would have read the token alone. Neither the reader's helper thread nor the caller has to wake up for it.

  • StagedRows in crates/gpu/src/graph.rs owns a row that the host writes after the launch of the graph that reads it. It holds the page-locked staging and the flag. clear lowers the flag before the launch, deliver writes the row and raises the flag on every path (a failed write included), and enqueue captures the flag wait and one copy of the row into the graph. It has the one new unsafe block, with its SAFETY line.
  • RowsArrival in crates/gpu-deepseek41/src/chain/glue.rs carried the same wait-and-copy code for the engram rows. It now uses StagedRows and keeps only its image layout and 4 byte packing. The wait and the copy are the same. Its raise, which nothing called, is removed.
  • Verify38 takes an optional arrival and enqueues it before the front of the PLE site layer. Body38::plan_verify names the rows (a rejected row hash still fails before the launch), clears the flag, stages and launches. Body38::deliver_ple reads and delivers the rows after the launch. The eager verify delivers before its walk, so eager and graph verifies receive the same rows in the same order. A multi-slot pass still places its rows before the launch.
  • Prefetcher::read_now in crates/engram/src/prefetch.rs reads on the calling thread a token that the helper would read alone. A token that splits into parts goes to the helper and part threads as before. The helper loop and read_now share one read body, read_job. PleHost::fill_spanned reads through PleRead::read_now, and PleRead::take_in is the one rule for taking in a read-ahead batch. The prompt ubatch read ahead is unchanged.
  • Pins moved with the new graph nodes. In gate_qwen4exp_e2e, REAL_NODES_VERIFY goes from 1187 to 1189 and REAL_NODES_VERIFY_CARD from 1427 to 1429, each with a PIN(2026-10-27) line. The verify structure check now requires one more batch memop and one copy node per PLE site. In tools/unsafe-ratchet.txt the gpu crate goes from 2748 to 2749 blocks and gpu-deepseek41 from 397 to 396, each with a PIN line.

Greedy output is identical on every request, and the e2e gate compares each verify row's token and logits bit for bit with the single-step path.

Release notes: Changed: Qwen3.8 verify steps launch their graph before the PLE rows arrive, which raises MTP decode speed on a DGX Spark.

Code shape

  • No second copy. The row arrival that RowsArrival carried now lives in StagedRows, which both the Qwen3.8 verify and the engram rows use. The helper and read_now share read_job.
  • Model code holds only architecture facts. StagedRows is in the shared graph code and has no model branch. Verify38 holds the one arrival the Qwen3.8 PLE layers need.
  • Dead code is gone. RowsArrival::raise had no caller and is removed, along with the imports it needed.
  • No silent failure. A failed read or a value past the staging is a named error, and the flag is still raised so the replay ends.
  • Comments state what is true now.
  • No relaxed gate. The moved counts are re-pinned with PIN(2026-10-27) and the reason.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up. cargo fmt --all -- --check passes, and clippy is clean for bloomery-engram and bloomery-gpu-gates. Clippy for bloomery-gpu and bloomery-gpu-deepseek41 needs CUDA and did not run on the machine I used for it. Both crates build on the DGX Spark.

Duplication found or removed (path:line): the arrival code in crates/gpu-deepseek41/src/chain/glue.rs (RowsArrival) moved into crates/gpu/src/graph.rs (StagedRows).

What I ran

The engram and PLE decode tests ran on an RTX 5090 machine. The graph, e2e and deepseek41 tests ran on a DGX Spark. The gates below ran on the head before its final rebase onto upstream main f0077054b5f9c3e3aca2e62ad9fb33348e490ec6; git range-diff shows both commits unchanged by that rebase (=), and the upstream commits between touch none of the files this PR changes.

NVIDIA GeForce RTX 5090, 595.99.02
NVIDIA GB10, 595.84
bash tools/gate.sh -p bloomery-engram --lib prefetch::tests::
bash tools/gate.sh --oxide -p bloomery-gpu --release --lib a_folder_s_stored_rows_decode_as_the_split_s
./tools/box.sh bash tools/gate.sh --gpu --oxide -p bloomery-gpu --release --lib -- --include-ignored hw_staged_row_arrives_after_the_launch
BLOOMERY_BOX_LOCAL=1 BLOOMERY_TIER=fixture just gate-gpu-qwen4exp-e2e
BLOOMERY_BOX_LOCAL=1 BLOOMERY_TIER=fixture just gate-gpu-qwen4exp-mtp
BLOOMERY_BOX_LOCAL=1 just gate-gpu-ds41-lib
  • The engram prefetch tests pass, including the new read_now test: test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 25 filtered out
  • The PLE row decode test passes: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 435 filtered out
  • The new StagedRows hardware test passes: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 435 filtered out. It captures the arrival for row 1 of two, launches, writes and delivers the row after a 20 ms host sleep, and checks that the buffer holds the late value from the arrival's offset and zero around it, twice. It also checks that a failed write still lets the replay end, that a row or copy past the buffer is refused before it is enqueued, and that the arrival adds two graph nodes.
  • just gate-gpu-qwen4exp-e2e exits 0 with 26 clauses run and 8 left to the real tier: clauses: 26 ran, 8 left to the real tier
  • just gate-gpu-qwen4exp-mtp exits 0 with 28 clauses run and 4 left to the real tier: clauses: 28 ran, 4 left to the real tier
  • The verify structure clause counts one copy node for the PLE rows at T=2, 3 and 4 on the plain, card plan and hostless plans: verify structure T=2: graph_nodes=117 (want 117; the program counts 117) batch_mem_op=9 (want 9) other=1 (want 1: the PLE rows' copy)
  • The deepseek41 lib tests, hardware ones included, pass: test result: ok. 40 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Each new or changed test was made to fail first by breaking the code it covers, and succeeds again after the file was restored (the tree is clean at the end of each run):

  • read_now handing every token to the helper fails the read_now test: RESULT 101 expected nonzero
  • read_now reading a token that splits on the caller fails the read_now test: RESULT 101 expected nonzero
  • A pinned helper that splits a token fails the read_now test: RESULT 101 expected nonzero
  • A fill read now that is not taken fails the PLE row decode test: RESULT 101 expected nonzero
  • An arrival that copies without the flag wait fails the StagedRows test: round 1: 4096 of 4096 values are not what the host delivered after the launch
  • A delivery that raises the flag without writing the row fails the StagedRows test: round 1: 4096 of 4096 values are not what the host delivered after the launch
  • A verify that delivers its rows one position off fails the e2e gate: E2E-V1 rc=1 (want nonzero)

Not run: just gate-gpu-ds41-step, just gate-gpu-ds41-engram and just gate-gpu-ds41-chain-glue. They need the DeepSeek V4.1 model, which none of the machines I used hold. RowsArrival makes the same wait and the same copy as before, and I built the gate_deepseek41_step binary on the DGX Spark instead: DS41-STEP-BUILD rc=0. just affected selects more gates than the ones above, so a maintainer runs the rest on the workstation.

Speed

The timed model is nvidia/Qwen3.8-Flash-Next-FP4-Local at revision b9ce18a6887e18c089fdea8509a33e63429a3300, with the Q8_0 MTP draft file mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf (SHA-256 5ff54097406a905cf3a724c709124ceb0e3e10235ee862298969e91c96fa96e6) for the draft-on arms. Each run uses a 4096-id prompt and 128 greedy tokens, on eight corpus windows 50,000 ids apart, with three rounds after a lead-in. Base is upstream main c21e3b81eb7f3ede965e5ac68f325b8a59cb2e05. The head timed is 2d593cc3ff7894dd974916ffcea33075d89bf418. Base and head are built from their own trees and run alternately. Each cell is the median of three rounds.

Arm Metric main head Change Ranges
Draft on, code-fn Decode tok/s 56.3087 57.4305 +1.992% separate
Draft on, code-fn Prefill tok/s 2106.95 2104.38 -0.122% overlap
Draft on, code-fn TTFT p95 ms 1950.48 1952.81 -0.119% overlap
Draft on, prose-en Decode tok/s 40.081 41.2355 +2.880% separate
Draft on, prose-en Prefill tok/s 2157.24 2164.59 +0.340% overlap
Draft on, prose-en TTFT p95 ms 1905.11 1898.1 +0.368% overlap
Draft off, code-fn Decode tok/s 30.9301 30.8411 -0.288% overlap
Draft off, code-fn Prefill tok/s 2194.94 2197.74 +0.128% overlap
Draft off, code-fn TTFT p95 ms 1876.66 1870.29 +0.340% overlap

Ranges are "separate" when the three head rounds and the three main rounds do not overlap.

draft-on decode +1.992% (code-fn) and +2.880% (prose-en), above the 1.272% and 1.711% the run can resolve; the other rows are inside the spread of repeated runs of the same tree

Only the two draft-on decode changes are resolved. The other rows are inside the spread of repeated runs of the same tree, so they are not evidence of an effect or of none.

The head timed is not this PR's head. After the timing the row-arrival code moved into StagedRows and the branch was rebased onto current main; both changes are host code. The compiled GPU code of this head is the same as main's for every entry (BLOOMERY_ARCH=sm_86 just canon-check 12dee757e1bf9ecd9eae3fe115baca5d3df2fe0a): canon-check: 4 bins, 1668 entries: 1668 identical, 0 reordered-only, 0 differs, 0 only-on-one-side

Reproduction

git checkout c21e3b81eb7f3ede965e5ac68f325b8a59cb2e05   # main
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
env BLOOMERY_DRAFT=mtp BLOOMERY_HOST_ROOM=96G BLOOMERY_MTP_DRAFT="<mtp-folder>" BLOOMERY_MTP_WIDTH=cost ./target/release/bloomery-serve -m "<folder>" --host 127.0.0.1 --port 18731 --parallel 1 --ctx-size 16896

Build the head the same way. Send 4096-id prompts from eight windows of the same corpus with 128 greedy tokens (temperature 0), alternating the two trees, and compare the median server decode rate. For the draft-off arm set BLOOMERY_DRAFT=off and leave out BLOOMERY_MTP_DRAFT and BLOOMERY_MTP_WIDTH.

Hardware

One DGX Spark for the timed runs, the graph, e2e and deepseek41 tests, and an RTX 5090 machine for the engram and PLE decode tests. This section lists only the card and driver lines saved with the runs.

NVIDIA GB10, 595.84
| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |

AI help

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

… on the step thread

Prefetcher::read_now is submit and wait in one call for a caller with
nothing to do until the rows are in. A token the helper would read alone
(one too small to split, every token of a pinned helper) is advised,
filled and copied on the calling thread, so neither the helper nor the
caller has to wake for it; a token that splits still goes to the helper
and its part threads.

Qwen3.8's PLE fills that wait at once (a verify's draft rows, a pass, a
slot's rows, a step with nothing read ahead) take this path. A batch read
ahead (a prompt call's next ubatch, a step's read ahead) is still taken
from the helper, and a walk that takes its rows at its PLE site still
starts the read on the helper.
A verify read its PLE rows, decoded them and copied them to the card
before its graph's launch, so the card sat idle for the read and the
launch. The verify's graph now holds the rows' arrival at its PLE site:
a wait on a host flag, then a copy from a page-locked staging. The host
lowers the flag, launches the graph, then reads and decodes the rows on
its own thread, stages them and raises the flag, while the card runs the
embedding and the layers before the site. The flag is raised on every
path, a failed read included.

The staging, the flag and the arrival's wait and copy are the gpu crate's
StagedRows, which DeepSeek V4.1's engram rows' arrival (RowsArrival) now
uses too: one owner of the clear, deliver, wait and copy and of the
staging's lifetime, the row count, row width and copy offset given by each
caller. RowsArrival keeps its image layout and byte packing; its raise,
which nothing called, is gone.

An eager verify delivers its rows before its walk. A pass of several
slots keeps its rows in the arena before its launch and has no arrival.
The verify's graph holds two nodes more (one batch memory operation and
one copy); the e2e gate's verify pins move from 1187 to 1189 and from
1427 to 1429 under the card plan.
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 27, 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: I built no failure path that the code does not block, and the new items have no duplicate.

Checked

  • Duplicates: 9 new items checked (StagedRows, read_now, read_job, take_back, take_in, read_named, name_rows, deliver_ple, ARRIVAL_NODES), none duplicated. RowsArrival's copy moved into StagedRows, which leaves fewer elements. dryer: 0 pairs.
  • Complexity: plan_verify 14 to 16 (one added call and one branch, harmless); load_placed 76 to 77 (one field, even growth).
  • Failure path built: the verify graph waits on a flag that nobody raises. Blocked: launch_served (model.rs:1891) calls serve_captured right after graph.launch for Body38, serve_chain runs deliver_ple first, and StagedRows::deliver raises the flag on every path. The eager walk delivers before it enqueues. The PLE site is a single layer, so verify_launches and Shape::arrivals agree.
  • Silent failure: 6 sites followed (deliver write error, row past staging, copy past buffer, take_in drain, read_now refusals, finish without start). Each ends as a named error.
  • Tests: the read_now test fails if the caller reads a splitting token, if the helper reads a lone token, or if the pinned case is dropped, because it asserts the copying thread's name. The StagedRows hardware test fails if the wait or the write is dropped (stale values after a 20 ms sleep). The e2e gate compares verify rows bit for bit. The PR body lists the mutants that turned each red.
  • Performance: the hot path is the verify step. No allocation, lock or launch is added per token; the added terms are one flag wait and one H2D copy per verify, in place of the host-side upload before the launch. The staging copy is fixed at VERIFY_ROWS * 2560 f32 at every row count, which is small. The class is a node-count change, and the PR body has the gate (pinned counts) and a timed A/B on a GB10.
  • Gates: REAL_NODES_VERIFY 1187 to 1189 and REAL_NODES_VERIFY_CARD 1427 to 1429, each with a dated PIN and the derivation. The unsafe ratchet moves gpu +1 and gpu-deepseek41 -1, with PINs; the new block has its SAFETY line.
  • Escape catalog: no match.

Notes

  • just gate-gpu-ds41-step, -engram and -chain-glue did not run (no model). RowsArrival keeps the same wait and copy, so I accept the build check as the PR body states.
  • The gates ran before the final rebase; the PR body names the range-diff result.

Card check: gpu-evidence. This pull request changes crates/gpu-deepseek41/src/chain/glue.rs, crates/gpu-gates/src/bin/gate_qwen4exp_e2e.rs, crates/gpu-gates/src/q38_fixture.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 27, 2026
@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 a87b49d into midagedev:main Oct 27, 2026
8 of 9 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 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.

1 participant