Skip to content

qwen38: a prompt call runs one cut across its checkpoints and reads its PLE rows under the layers - #724

Merged
juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-prompt-waste
Oct 23, 2026
Merged

juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-prompt-waste

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8 프롬프트 처리에서 아무도 읽지 않는 일(체크포인트마다 반복되는 head 계산, 카드가 쉬는 동안 하던 PLE 행 디코드)을 없애 첫 토큰까지의 시간(TTFT)을 줄이는 속도 PR입니다.

Part of #565.

What and why

The Qwen3.8 prompt call did two kinds of work that no later step reads, and one read that stalled the card.

  1. With checkpoints on (the serve default), feed_marked cut a prompt call into runs between the checkpoint marks and ran each run as its own call. Every run started its own PLE read-ahead, so the first ubatch after a mark read its own rows with the card idle on a load whose PLE table lives on the NVMe tier (the FP4-Local folder). Every run also ended with the final combine, the head and the argmax readback, although only the call's last unit has a reader for them.
  2. A ubatch walk with no host leg decoded its PLE rows and uploaded them in one step before the first launch. On the profile that ranked the prompt pass, that was a host-only gap before the first kernel and then one 41.9 MB copy, 313 ms of a 4,095-row prompt (7% of TTFT). The walk first needs the rows at the PLE site in layer 1, so the decode can run while the card computes layer 0.

This PR changes both, in crates/gpu/src/arch/qwen3moe/body38.rs and wide38.rs:

  • call_units(from, n, width, marks) is the one cut of a prompt call: each run up to the next mark is cut the way ubatch_cut cuts it, and the unit before each mark is marked. feed_marked computes marks only when checkpoints are on and calls feed38 once for the whole call. feed38 starts one PleHost::prompt_start for the call's units (now given the cut instead of a row width), runs the head on the last unit only, and on a marked unit before it still runs the last layer's combine when the MTP draft or a tap reads the rows, and reads the fault word before mark_here takes the checkpoint.
  • PleRead::read is split into start and finish, and PleHost::fill_spanned into name_spanned (names the rows, makes every refusal, starts the NVMe read) and decode. PleHost::upload copies the decoded rows into the arena's e through WindowMut::of_mut, which replaces three unsafe f32_view copies (the prompt, ubatch and verify plans).
  • Body38::ple_late is set by stage_gemm on a walk with no expert tier where every layer is Card38::hostless (FP4-Local on GB10 loads this way). walk_gemm then hands the walk a rows_in closure (decode and upload), WideParts::ple_rows carries it, and the front's PLE-site branch calls it before combine. A walk that reaches its PLE site without the rows copied in is refused by name. A walk with a host leg keeps the early fill, because there the step thread serves the host between launches.
  • tools/unsafe-ratchet.txt: the gpu block count goes from 2268 to 2265.

The change is in Body38's own prompt path, above any rank split, so the rank count is not involved.

Release notes: Changed: long Qwen3.8 prompts reach their first token sooner on GB10.

Code shape

  • No second copy. call_units is the one cut that the walk and the read-ahead both use, and it replaces the per-run cut. PleHost::upload replaces three copies of the same copy. Searches for call_units, PleRowsIn, name_spanned, upload, mark_here, feed_steps and ple_late find no second definition.
  • Model code holds only architecture facts. The PLE table and its reader exist only in Qwen3.8. No common owner gained a per-model branch.
  • Dead code is gone. The per-run cut and the separate hostless walk entry are removed, and no parameter or mode is left unused.
  • No silent failure. A walk that reaches its PLE site without its rows is a named refusal. The fault word is read before an intermediate checkpoint is taken. Every new Result is propagated.
  • Comments state what is true now. tools/check-comments.sh is ok.
  • No relaxed gate. No band, tolerance or lint level moved. The unsafe ratchet went down, with its line.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up. cargo fmt --check and cargo check are clean on this head. Clippy has not been run on this head.

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

What I ran

Hardware: one DGX Spark (GB10) for the timed run and the unit tests.

| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.2     |
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |

The build container reports CUDA 13.3 for the toolchain; the host line above is the driver's.

Speed

Measured on one DGX Spark (NVIDIA GB10, driver 595.84), the head against main c681eb07d, each built from its own tree, FP4-Local folder nvidia__Qwen3.8-Flash-Next-FP4-Local/b9ce18a6887e18c089fdea8509a33e63429a3300. --parallel 1 --ctx-size 16896, BLOOMERY_DRAFT=off, checkpoints on, /completion greedy with n_predict 32, one request at a time. The arms ran in the order main1, head1, main2, head2 in one lease, with one server load per arm and three requests per prompt length, each on its own window of the corpus; a cell is the arm's median. Load time is reported apart. The GPU clock cap was lifted from each arm's ready to its done and restored after it.

arm prompt runs TTFT ms prompt ms prefill tok/s decode tok/s load s
main1 (cold) 4096 3 4477.3 4470.4 916.3 27.02 207.8
main1 (cold) 8192 3 9469.3 9432.2 868.5 26.76 207.8
head1 4096 3 3503.0 3486.0 1175.0 30.63 221.3
head1 8192 3 7186.3 7155.9 1144.8 30.75 221.3
main2 4096 3 3556.6 3540.1 1157.0 30.86 204.8
main2 8192 3 7313.6 7282.9 1124.8 30.72 204.8
head2 4096 3 3506.6 3489.7 1173.7 31.43 205.2
head2 8192 3 7172.6 7141.4 1147.1 31.23 205.2

4096 ids: TTFT -51.8 ms (-1.46%), prefill +1.50%, decode +0.54%; 8192 ids: TTFT -134.1 ms (-1.83%), prefill +1.88%, decode +0.87%

The deltas compare the two head arms with main2, the warm main arm. Main1 is the first server after the builds, so its page cache was cold and it paid for the PLE rows its later arms found already read; it is in the table and left out of the deltas. That leaves one warm main arm, so this is one alternating pair and not a significance claim. At 8K every head request (7,160 to 7,220 ms) is below every main2 request (7,278 to 7,320 ms). At 4K the head requests (3,478 to 3,523 ms) and main2's (3,521 to 3,577 ms) overlap slightly, and the 4K gain is small enough that I would not call it separated from the run-to-run spread. The decode difference is not something this change aims at, and I do not claim it.

Which change acts where: a 4K request prefills 4,095 ids (prompt_whole steps the last id), which is one unit whose only mark is the call's end, so at 4K only the late PLE fill acts. An 8K request prefills 8,191 ids as two units with a checkpoint after the first, so the late PLE fill acts on both units, and the one-cut call also drops the first unit's head and reads the second unit's PLE rows ahead. At 4,095 rows, the head and readback that an intermediate checkpoint unit no longer runs cost 10.96 ms by the profile, and six launches and one blocking readback are gone per such unit.

The same lease measured the machine's read ceiling at 206.6 GB/s (read_probe).

The timed head has the same crates/ code as the head of this PR. The rebase onto current main changes only tools/unsafe-ratchet.txt (the recounted gpu block count: 2268 to 2265 on this base, 2256 to 2253 on the measured base), and upstream between the measured base and this PR's base changed neither body38.rs nor wide38.rs.

Output parity

Greedy ids (32 a request) are equal across all four arms in all six windows, both prompt lengths, with checkpoints on.

Tests and FAIL-first

bash tools/gate.sh --oxide -p bloomery-gpu --release --lib -- arch::qwen3moe::body38:: arch::qwen3moe::wide38:: on the head, then on two planted mutants of the code, restoring the file after each:

  • Mutant 1 restores the old read-ahead order (a new prompt_start for each run between marks). The NVMe PLE test stops at its read-ahead assertion.
  • Mutant 2 marks every unit of a marked run. a_call_cuts_its_units_at_its_marks stops at its marks assertion.
test result: ok. 11 passed; 0 failed; 1 ignored; 0 measured; 372 filtered out; finished in 0.01s
assertion `left == right` failed: unit 1: the next unit read ahead
assertion `left == right` failed: 10 ids from 0, 8 wide, marks [10]
FAILFIRST real=0 m1_readahead=101 m2_marks=101 restored_clean=0

The ignored test, hw_a_unit_window_gives_back_its_context_handle, needs a CUDA device and runs under just gate-gpu-lib. a_call_cuts_its_units_at_its_marks is new, and the NVMe PLE test now reads ahead across a mark.

just gate-gpu-qwen38-serve not run: the gate needs the maintainers' workstation.

just gate-gpu-qwen4exp-e2e and just gate-gpu-qwen4exp-mtp not run: they load the plan of the maintainers' workstation.

Reproduction

bash tools/gate.sh --oxide -p bloomery-gpu --release --lib -- arch::qwen3moe::body38:: arch::qwen3moe::wide38::
BLOOMERY_DRAFT=off bloomery-serve -m <FP4-Local folder> --parallel 1 --ctx-size 16896

Send greedy /completion requests with n_predict 32 and prompts of 4,096 and 8,192 ids on fresh corpus windows, and compare TTFT against main after one warm-up load on each tree.

What I ran into

This does not block the PR.

  • The first server after a build pays for cold PLE pages. In the run above main1 took 4,477.3 ms at 4K against 3,556.6 ms for main2, and decoded at 27.02 tok/s against 30.86. The head had no cold arm, so I cannot say how much of that penalty this change moves.
  • The late PLE fill applies only on walks with no host leg. A load with an expert tier or a host leg keeps its early fill, and I did not time such a load.
  • Not run: t0, clippy and the other static checks.

AI help

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

…nd the exposed PLE read once

A prompt call with cache checkpoints inside it (a serve prompt past 4,096
ids) ran each run between two marks as a call of its own: the vocabulary
head and its blocking argmax readback at the end of every run, and a new
PLE read-ahead for each run, so the first ubatch after each mark read its
own rows from the NVMe tier with the card idle.

The call now cuts its units once (call_units: each run between its marks
cut as the ubatch cut cuts it) and walks them in one loop. The PLE reader
reads every later unit ahead across the marks, and the head runs on the
call's last unit only. A marked unit before it still runs the last
layer's combine when the MTP draft reads the point row or a tap reads the
rows, and reads the fault word before its checkpoint is taken. The units,
their order and the last unit's head are the ones the runs walked, so
every store, checkpoint and logit keeps its bits.
…ayers before the PLE site

A ubatch walk's PLE rows were read, decoded and copied to the card before
its first launch, so the card sat idle for the whole fill: on a 4K
FP4-Local prompt on GB10, 313 ms of host-only time before the first
kernel, then the 41.9 MB upload.

On a walk with no expert tier whose every layer serves no host leg, the
plan now names the rows and starts their read; the walk decodes and
copies them when it reaches the first PLE site, after the layers before
it are enqueued, so the fill runs while the card computes them. A walk
with a host leg keeps the fill before the walk, since its step thread
serves the host between launches. The rows' copy goes through a safe
window of the arena buffer, which removes three unsafe views.
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 23, 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 behavior defect or blocking quality defect was found.

Non-blocking

⚠ Cover the production read-ahead boundary: crates/gpu/src/arch/qwen3moe/body38.rs:6183.
The NVMe test calls prompt_start directly and never calls feed38. Restoring per-mark read-ahead in the production caller leaves this test green.
Extend an existing prompt gate to observe prefetch across an internal checkpoint. This closes the caller's regression coverage while its scheduling changes.

⚠ Verify draft recovery at an internal checkpoint: crates/gpu/src/arch/qwen3moe/body38.rs:4169.
The timed run disables the draft, and the owning checkpoint/MTP gates were not run. Neither changed unit test exercises this final-combine decision.
Run a prompt across an internal mark, restore that checkpoint, and compare its hidden row and draft logits with a fresh prefix. Force finals = false to verify that the assertion fails.

Optimization headroom

  • E. Less work: crates/gpu/src/arch/qwen3moe/body38.rs:4169. With a draft and no sink, a checkpoint reads only the last hidden row, but finals combines every row. Restrict that combine to the last row using existing windows: save 81,920 × (m − 1) B of residual reads/writes per marked unit [derived: four streams, 2,560 f32 values, one read and write].

Checked

Duplicates: 10 new functions/types checked; no proven duplicate. Common call_batches balances batches; this cut retains full-width units. Dryer reported 0 pairs.
Complexity: stage_gemm 11→16 adds deferred-fill branches; feed38 27→30 merges pass/GEMM orchestration; front 30→32 adds optional callback dispatch. These are existing host functions.
Silent failure: 6 optional/fallback sites followed; read, decode, copy and intermediate device-fault errors propagate.
Tests: by inspection, marking every unit or dropping the next prefetch submission fails the new assertions. The production restart mutant remains uncovered.
Gates: no tolerance relaxed; unsafe-block pin tightens 2266→2263.
Adversarial checks: empty/context-boundary prompts are refused; marks come from the sorted common owner; hostless guards prevent a deferred-copy host wait; standalone and head combines use the same FMA.
Performance: Qwen3.8 prefill; the launch-count class needs its owning gate, requested above.
Escape catalog: no matching patterns.

Notes

Static review only; no build or GPU gate run here. The PR lacks the exact timed-head hash and a completed owning GPU gate with output, so GPU evidence is false.

Card check: needs-gpu. This pull request changes crates/gpu/src/arch/qwen3moe/body38.rs, crates/gpu/src/arch/qwen3moe/wide38.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 f8f3635 into midagedev:main Oct 23, 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 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