Skip to content

qwen38: read the next step's PLE rows ahead and keep the command receiver awake between steps - #831

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

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

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Qwen3.8 FP4-Local에서 draft를 끈 디코드가 다음 명령과 PLE 행을 한 step 앞서 준비하게 해, DGX Spark의 디코드 속도를 높이는 속도 PR입니다.

What and why

In a plain decode step, each token waits for two thread wake-ups. The engine thread parks on its command channel after every reply, so the server's next call waits for that thread to wake. The PLE rows of the next step are handed to the reader's helper only when the next input is built, so the step waits again for the helper.

This PR removes both waits for Qwen3.8 decode without a draft.

  • receive_command in crates/gpu-gates/src/bind.rs polls the command channel for up to RECEIVE_SPIN (1 ms) after a call, then parks as before. Commands sent before the server drops its end are still all received before the end is reported. The engine loop and the test fake of the engine thread both receive through it.
  • Body38::prefetch_input (crates/gpu/src/arch/qwen3moe/body38.rs) starts the next step's PLE read as soon as a plain step has picked its id. Q38::read_ahead in the Qwen3.8 seat issues it only when the answer is one id and Seat::pass_rows() == 1 (no draft, or the slot's draft off). The read ahead moves no history and no device buffer. The next fill takes the rows when its position and row ids match and drains them otherwise.
  • History::clone_from in crates/engram/src/hash/ngram.rs copies into the target's storage, so the read ahead allocates nothing per step.
  • tools/spawn-allow.txt allows one more spawn in bind.rs, for the new receiver test.

Greedy output is identical on every request. With the draft on, the changed paths are the receiver only, and the measurement below shows no change beyond the run-to-run spread.

Release notes: Changed: Qwen3.8 decode without a draft reads the next step's PLE rows ahead and keeps the command receiver awake between steps, which raises decode speed on a DGX Spark.

Code shape

  • No second copy. The receiver is one function used by the engine loop and the test fake. The read ahead reuses PleRead, the History storage and Seat::pass_rows.
  • Model code holds only architecture facts. Body38::prefetch_input is an inherent method of the one body that has a PLE reader, and Q38::read_ahead sits in the Qwen3.8 seat. The shared SlotDrafts and ChainBody gained no method or branch.
  • Dead code is gone. Nothing was left unused.
  • No silent failure. prefetch_input and read_ahead return their errors with ?. A row id the hash rejects clears the hint, and the fill of that id rejects it by name.
  • Comments state what is true now.
  • No relaxed gate. No band, tolerance or lint moved.
  • 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 needs CUDA and did not run on the machine I used.

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

What I ran

The tests below ran on an RTX 5090 machine on revisions of this branch with the same product code as this head (crates/ has no difference; the head differs by the one-line tools/spawn-allow.txt change).

NVIDIA GeForce RTX 5090, 595.99.02
bash tools/gate.sh --oxide -p bloomery-gpu --release --lib a_folder_s_stored_rows_decode_as_the_split_s
bash tools/gate.sh -p bloomery-engram --lib history_shifts_oldest_first
bash tools/gate.sh --oxide -p bloomery-gpu-gates --release --features glm5next,clef,vision,mimo2,solar2,minimaxm3,gemma-embedding2,hf,checkpoint --lib bind::tests::
bash tools/gate.sh --oxide -p bloomery-gpu-gates --release --features glm5next,clef,vision,mimo2,solar2,minimaxm3,gemma-embedding2,hf,checkpoint --bin bloomery-serve a_table_of_no_draft_passes_one_row_on_every_slot
  • The body test passes: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 424 filtered out
  • The history test passes: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 22 filtered out
  • The 36 bind::tests:: tests pass, including the new receiver test: test result: ok. 36 passed; 0 failed; 0 ignored; 0 measured; 240 filtered out
  • The no-draft table test passes: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 9 filtered out

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

  • Accepting a read-ahead batch of other row ids fails the body test: RESULT 101 expected nonzero
  • Dropping the recycled row-id storage fails the body test: RESULT 101 expected nonzero
  • Replacing clone_from with a fresh clone fails the history test: RESULT 101 expected nonzero
  • A read ahead that walks the live history fails the body test: RESULT 101 expected nonzero
  • A read ahead that never starts fails the body test: RESULT 101 expected nonzero
  • A receiver that polls a thousand times longer fails the receiver test: RESULT 101 expected nonzero
  • An empty poll read as the end fails the receiver test: RESULT 101 expected nonzero
  • A disconnect read as a command fails the receiver test: RESULT 101 expected nonzero
  • A pass-row count of the speculative table for no draft fails the no-draft table test: RESULT 101 expected nonzero

cargo check --workspace --all-targets with all features passes on the same machine (BLOOMERY_BOX_LOCAL=1 just check): Finished dev profile [unoptimized + debuginfo] target(s) in 43.74s

  • just gate-gpu-qwen38-serve not run: it needs the maintainers' workstation and the full Qwen3.8 checkpoint set, so a maintainer runs the recipes just affected selects.

Speed

The timed model is nvidia/Qwen3.8-Flash-Next-FP4-Local at revision b9ce18a6887e18c089fdea8509a33e63429a3300, with the Q8_0 MTP draft 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 895b32d4a5998bdb53fad6e50d76d64ae0c538e5. Base and head are built from their own trees and run alternately. Each cell is the median of three rounds. The head's crates/ content is identical to the tree that was timed. Greedy output is identical on every request.

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

Arm Metric main head Change Ranges
Draft off, code-fn Decode tok/s 30.3198 30.7026 +1.263% separate
Draft off, code-fn Prefill tok/s 2157.04 2154.81 -0.104% overlap
Draft off, code-fn TTFT p95 ms 1905.85 1907.11 -0.066% overlap
Draft on, code-fn Decode tok/s 56.0007 55.9271 -0.131% overlap
Draft on, code-fn Prefill tok/s 2072.68 2068.55 -0.199% overlap
Draft on, code-fn TTFT p95 ms 1983.39 1986.27 -0.145% overlap
Draft on, prose-en Decode tok/s 40.4911 40.2809 -0.519% overlap
Draft on, prose-en Prefill tok/s 2114.71 2112.9 -0.086% overlap
Draft on, prose-en TTFT p95 ms 1943.38 1945.06 -0.086% overlap

draft-off code-fn decode +1.263% (resolved above 0.500%); draft-on decode changes -0.131% (code-fn) and -0.519% (prose-en), both inside the 2.937% and 1.076% the run can resolve

Only the draft-off decode change is 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.

Reproduction

git checkout 895b32d4a5998bdb53fad6e50d76d64ae0c538e5   # main
cargo oxide build --arch "$(bash tools/arch.sh)" -- -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve
env BLOOMERY_DRAFT=off BLOOMERY_HOST_ROOM=96G ./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-on arms set BLOOMERY_DRAFT=mtp, BLOOMERY_MTP_DRAFT to the MTP draft file and BLOOMERY_MTP_WIDTH=cost.

Hardware

One DGX Spark for the timed runs, and an RTX 5090 machine for the tests above. 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 초안 리뷰는 제가 직접 했습니다.

The engine thread parked on its command channel after every reply, so
each decode step's next command waited for that thread's wake-up after
the server sent it. The receiver now polls the channel for up to 1 ms
after the call, which covers a step's reply and the server's next call,
and then parks as before. Commands sent before the server drops its end
are still received before the end is reported.

The test fake of the engine thread receives through the same function,
and a new test checks that the receiver takes a command sent long after
its poll ended, stays parked meanwhile, and takes every queued command
before it reports the end.
A plain decode step's PLE rows were submitted to the reader's helper
only when the next step's input was built, so the step thread waited
for the helper to wake and copy them after the server's next call
arrived. The Qwen3.8 seat now starts that read as soon as a plain step
has picked its id (Body38::prefetch_input), so it runs while the
answer goes to the server and back.

The read ahead moves no history and no device buffer. The next fill
takes the rows when its position and row ids match and drains them
otherwise. It is issued only where the body's next call is the same
slot's one-row step: no draft or the slot's draft off, on a load of one
slot or one whose rounds run as one pass. The row-id storage and the
history walked ahead are kept from call to call (History::clone_from),
so the read ahead allocates nothing per step.
@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 26, 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: Read-ahead mismatches drain before use, and command reception preserves queued work on disconnect.

Non-blocking

⚠ Complete the timing evidence: crates/gpu-gates/src/bind.rs:1647. The shared receiver now polls for up to 1 ms per command before parking. Supply the timed head SHA and the exact benchmark request commands with output for the GB10 A/B. The body names the timed base but leaves the head revision unnamed. Recording them now makes the speed claim reproducible.

Checked

Duplicates: 11 new functions/constants checked; none duplicated. Dryer reported 0 pairs; its excluded gpu-gates paths were searched by hand.
Complexity: crapper flagged no function. The added control flow handles reception and optional read-ahead; no kernel body changed.
Silent failure: 5 sites followed, including receiver loop termination, the test receiver's .ok(), and rejected/overflowing hash hints. Disconnect ends reception; rejected hints leave actual fills subject to named validation errors.
Tests: static mutation checks identify assertions for ngram.rs:182 (fresh clone fails storage identity), body38.rs:611 (accept mismatched ids fails decoded-row comparison), :944 (walk live history fails history equality), :976 (omit submission fails flight assertion), drafted.rs:871 (return speculative rows fails count), and bind.rs:1653/1656 (empty-as-end or prolonged polling fails reception/CPU assertions). The body also checks recycled id storage. The PR reports FAIL-first runs; these were not rerun here.
Gates: no existing pin, tolerance, test clause, or lint level moved.
Escape catalog: C1–C4 matched no changed code.
Adversarial paths: changed token, replaced hint, slot/history switch, reset, invalid token, context boundary, and queued commands at disconnect are blocked by row matching, drains, named guards, or channel semantics.

Notes

The selected serving gate was not run; GPU evidence is incomplete under CONTRIBUTING.md. Runtime tests were not rerun in this static review.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/shared/serve_seats/drafted.rs, crates/gpu-gates/src/bin/shared/serve_seats/qwen38.rs, crates/gpu-gates/src/bind.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 3331d2f into midagedev:main Oct 26, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant