Skip to content

runtime, gpu, app, gates: one prompt call plan for every seat: a part before the last runs no head, the last call folds its last id where the body allows it, and the unit cut and its read rows live in the shared owner - #1086

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-cmn-prompt-plan
Nov 1, 2026

Conversation

@juliankang4

@juliankang4 juliankang4 commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Qwen3.8 전용이던 프롬프트 호출 계획(마지막 id 접기, 유닛 자르기, 헤드 없는 앞 부분)을 공용 runtime::prompt로 옮겨 모든 seat이 읽게 했고, 속도 손실은 없습니다.

What and why

Only Qwen3.8 knew how a server prompt call should end. Its seat had its own prefill_only and prefill_next, its body had a set_close toggle, and the unit cut and the fold of the last id were private functions in body38.rs. The shared drafts had three variants of the prompt call (prefill, prompt_close, prefill_only). Every other seat ran the head on every part of a long prompt. A new model would have had to write all of this again.

This PR moves the plan into runtime::prompt and makes the seat, the app and the drafts read it:

  1. How a call ends: CallEnd { Unread, Argmax, Close }; head() says whether the head runs.
  2. The unit cut: call_units and fold_units move out of body38.rs and cut runs with the module's existing chunks. Body38's private ubatch_cut copy is removed.
  3. The seat: Seat::prompt_call(ids, end) replaces prefill_only. The server's parts and the default last call (prefill_then_step) run Unread. The Qwen3.8 seat folds with one prompt_call(.., CallEnd::Close) instead of toggling set_close.
  4. The app and drafts: Prompt::prompt_call has a default, bind::call_token turns a call's result into the server's token and refuses by name a headed call that read none, and SlotDrafts::prompt_call replaces its three variants. MtpBody::prompt_with takes the end; MtpBody::prefill_with, Session::prefill and MtpDraft::prefill are removed.
  5. Each body's facts: Qwen3.5/3.6, GLM-5.3-Flash and DeepSeek V4.1 run a part before the last without a head. Qwen3.5/3.6 and GLM refuse a closing call by name, because a delta or KDA layer keeps no state inside a unit. Only the Qwen3.8 seat folds, as before. The other bodies keep the call less the last id and its step: folding Qwen3-30B's last id in one call took the last position's key and value from the GEMM walk instead of the step and changed its greedy text, so a body opts in only once its gate holds those bits.

A new model now states two facts: whether its body runs a call without a head (Prompt::prompt_call) and, only if it folds the last id, a prefill_next that asks for a closing call. The rest comes from the shared owner.

Release notes: Under the hood: every model's server prompt call follows one shared plan, with no speed loss on Qwen3.8.

Code shape

The review reads these first. A box left unticked needs one line of why.

  • No second copy. Logic two models (or two call sites) share has one common owner; I lifted it there instead of
    copying it (AGENTS.md "Common code first", docs/rust-quality.md R14). Where I found an existing copy, I
    named it below.
  • Model code holds only architecture facts. A model's own files carry only what its architecture forces
    (tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
  • Dead code is gone. Nothing I made unused is left behind (functions, flags, gate clauses, docs).
  • No silent failure. Undefined input is a named error or panic, never a defined-looking output.
  • Comments state what is true now. No dates, issue numbers or how a bug was found (tools/check-comments.sh).
  • No relaxed gate. No band, tolerance or lint moved; a re-pin carries PIN(YYYY-MM-DD):
    and its reason.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": the unit cut and fold in crates/gpu/src/arch/qwen3moe/body38.rs (moved to crates/runtime/src/prompt.rs), and the three prompt variants in crates/gpu-gates/src/bin/shared/serve_seats/drafted.rs (now one).

What I ran

Every GB10 check ran on a DGX Spark. The gate runs print this line from nvidia-smi --query-gpu=name,driver_version,compute_cap --format=csv,noheader:

NVIDIA GB10, 595.84, 12.1

bash tools/arch.sh prints sm_121a, and the toolkit is CUDA 13.3. Base is 52bd46bed, the upstream commit before this change.

Unit tests and device-linked tests:

cargo test -p bloomery-runtime --lib prompt::
cargo test -p bloomery-app --features deepseek41,glm5next --lib
BLOOMERY_BOX_LOCAL=1 ./tools/box.sh 'bash tools/gate.sh --gpu --oxide -p bloomery-gpu-gates --features deepseek41 --release --lib -- prompt_plan'
BLOOMERY_BOX_LOCAL=1 ./tools/box.sh 'bash tools/gate.sh --gpu --oxide -p bloomery-gpu --release --lib -- body38'

The prompt:: tests give 10 passed, the app tests give 31 passed and the body38 tests give 6 passed. On the PR head (81c4bd752), bind::tests::prompt_plan::a_prompt_call_reads_the_plan passes with 1 passed.

GB10 gates:

BLOOMERY_BOX_LOCAL=1 BLOOMERY_TIER=fixture just gate-gpu-qwen4exp-e2e
BLOOMERY_BOX_LOCAL=1 just gate-gpu-qwen4exp-mtp
BLOOMERY_BOX_LOCAL=1 BLOOMERY_TIER=fixture just gate-gpu-glm5next-mtp
BLOOMERY_BOX_LOCAL=1 BLOOMERY_TIER=fixture just gate-gpu-qwen38-serve
BLOOMERY_BOX_LOCAL=1 BLOOMERY_QWEN38_FOLDER=<FP4-Local folder> just gate-gpu-qwen4exp-mtp-input
  • gate-gpu-qwen4exp-e2e: clauses: 27 ran, 9 left to the real tier, exit 0.
  • gate-gpu-qwen4exp-mtp: clauses: 28 ran, 4 left to the real tier, exit 0.
  • gate-gpu-glm5next-mtp: clauses: 14 ran, 7 left to the real tier and (w) Batch: the drafted run's 64 ids = the plain run's PASS, exit 0.
  • gate-gpu-qwen38-serve on the PR head (81c4bd752): every check passes, gate_qwen38_serve ran 220 s (exit 0).
  • gate-gpu-qwen4exp-mtp-input runs the closing-call clauses on the FP4-Local folder with its MTP layer, test result: ok. 3 passed. The folded last id and a drafted run whose prompt call closes:
    • (cl) the last id rides the ubatch walk at 21, 32 and 5 ids from a reset (the seat steps it otherwise): [true, true, false] PASS
    • (cl) a drafted run whose prompt call closes: the draft rejoins at 20 true; greedy ids [22, 23, 24, 25, 33898, 2110, 30, 31, 73307] = the plain run's [22, 23, 24, 25, 33898, 2110, 30, 31] PASS
    • (cl) close then another slot's prompt: retained_row_bits=true draft_active=true refused_owned_arenas=true greedy_equal=true PASS

The user-facing bloomery-serve (release feature set) on Qwen3.8 FP4-Local with its MTP draft, answered a short prompt (' Paris. The capital of Germany is Berlin. ...'), a 4,701-id prompt and that prompt extended with the cache kept, at --parallel 1 and at --parallel 2. The long answers were coherent, and the extended request read 617 new ids after 4,096 cached.

Base against head on an RTX 5090 machine

Base and head return equal greedy text and ids for three requests on each of three models. The RTX 5090 ran at a power limit of 400 W (default 600 W). Base is 52bd46bed.

Each side is built through its own tree's tools/box.sh with the feature set of tools/release/build.sh, the same set as the GB10 build below. Each model is served by base and then by head:

BLOOMERY_BOX_LOCAL=1 ./tools/box.sh "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 -u BLOOMERY_REF_MODEL BLOOMERY_DRAFT=off ./target/release/bloomery-serve -m "$MODEL" --host 127.0.0.1 --port 18741 --parallel 1 --ctx-size 16896

BLOOMERY_DRAFT=mtp replaces off for the UD-Q4_K_M file. Each request is a POST /completion with {"prompt": ..., "n_predict": 48, "temperature": 0, "cache_prompt": true, "return_tokens": true}, sent in this order:

  1. short: "The capital of France is".
  2. long: 160 sentences "Paragraph {i}: the river carries silt to the delta, where farmers plant rice in the wet season and wheat in the dry one." for i from 0 to 159, then "\nSummarize the farming pattern in one sentence:". That is 4,700 ids on Qwen3-30B and 4,701 on Qwen3.6.
  3. longer: the long prompt with " Paragraph 160: the delta floods each spring." before the last line, read with the cache kept.

A request counts as equal when content and tokens match on both sides. The run prints each result with both sides' prompt_ms; the load line shows the MTP draft in use:

# Qwen3.6-35B-A3B Q4_K_M, draft off
equal q36 short True prompt_ms base 9.460557 head 9.206688
equal q36 long True prompt_ms base 333.087734 head 332.816241
equal q36 longer True prompt_ms base 55.075216000000005 head 54.876442
# Qwen3.6-35B-A3B UD-Q4_K_M with its MTP draft
load draft=mtp layer=40 resident=564520960 scratch=2756208 head=full in 2.1 s (runtime value)
equal q36mtp short True prompt_ms base 14.698186999999999 head 14.391447999999999
equal q36mtp long True prompt_ms base 2280.057544 head 2279.872926
equal q36mtp longer True prompt_ms base 62.452373 head 62.215256
# Qwen3-30B-A3B-Instruct-2507 Q4_K_M
equal q3 short True prompt_ms base 8.533882 head 8.530787
equal q3 long True prompt_ms base 245.39610000000002 head 245.56229399999998
equal q3 longer True prompt_ms base 27.567617 head 27.552039

Speed on GB10

Qwen3.8 FP4-Local loses no speed: no row below moves beyond its resolution in the slower direction. The run used TP=1, P=4096 and K=128, head against base 52bd46bed, base and head built and timed in the same run on one GB10, and greedy output was equal. The A/B run prints:

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

Each side is built in its own checkout:

git -C base checkout 52bd46bed829edf367f542d97f116962ee1971e9
git -C head checkout <head revision>
(cd head && 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)

The servers, with MODEL_FP4L set to the FP4-Local folder (Hardware below). The first line is the draft-off arm at C=1. The second is the MTP arm at C=1; the C=2 arm runs it with --parallel 2:

env BLOOMERY_DRAFT=off BLOOMERY_HOST_ROOM=96G ./head/target/release/bloomery-serve -m "${MODEL_FP4L}" --host 127.0.0.1 --port 18731 --parallel 1 --ctx-size 16896
env -u BLOOMERY_MTP_DRAFT BLOOMERY_DRAFT=mtp BLOOMERY_HOST_ROOM=96G BLOOMERY_MTP_WIDTH=cost ./head/target/release/bloomery-serve -m "${MODEL_FP4L}" --host 127.0.0.1 --port 18731 --parallel 1 --ctx-size 16896

Each request is a streamed POST /completion whose prompt is 4,096 token ids from a fixed window of a token-id corpus (code-fn, SHA-256 7520b471436fb307e91ee22640ad8100701d48e63e3da7de9160b705b92915d1; prose-en, d10c7044df8884fdd200304604772d81a4b56a228f802d5f05db724b245ef77a):

{"prompt": [4096 token ids], "n_predict": 128, "cache_prompt": false, "stream": true, "timings_per_token": true, "return_tokens": true, "temperature": 0, "top_k": 1}

Each round starts one server, warms it up on two windows past the timed ones, then times eight loads per corpus at offsets 0, 50000, 100000 and so on up to 350000. A load is one request at C=1 and two requests at once at C=2. Rounds run base, head, head, base, base, head, so each side has three. The draft-off arm uses code-fn only; the MTP arms use code-fn and prose-en. The C=2 arm samples with "temperature": 0.7, seed 42 for the first request of a load and 43 for the second. Prefill and decode tok/s come from the server's timings, and TTFT p95 and total tok/s from the client clock. Each cell is the median of the three rounds with their range in parentheses. A positive change is faster for every metric, TTFT included. The resolution is the smallest change the run's same-revision repeats can resolve.

metric base head change ranges overlap
draft off, C=1, code-fn, prefill tok/s 2883.94 (2818.78 to 2887.20) 2880.02 (2877.63 to 2885.00) -0.136% (resolution 2.373%) yes
draft off, C=1, code-fn, TTFT p95 ms 1425.23 (1424.35 to 1457.39) 1427.49 (1424.48 to 1427.70) -0.159% (resolution 2.319%) yes
draft off, C=1, code-fn, decode tok/s 31.4199 (31.33 to 31.48) 31.3707 (31.33 to 31.52) -0.156% (resolution 0.591%) yes
MTP, C=1, code-fn, prefill tok/s 2703.22 (2700.08 to 2706.84) 2708.8 (2706.22 to 2710.16) 0.206% (resolution 0.500%) yes
MTP, C=1, code-fn, TTFT p95 ms 1520.71 (1519.20 to 1522.43) 1517.41 (1517.39 to 1519.34) 0.217% (resolution 0.500%) yes
MTP, C=1, code-fn, decode tok/s 59.4497 (59.09 to 59.82) 59.5142 (59.49 to 59.53) 0.108% (resolution 1.225%) yes
MTP, C=1, prose-en, prefill tok/s 2749.11 (2746.26 to 2768.41) 2757.92 (2732.03 to 2767.51) 0.321% (resolution 1.286%) yes
MTP, C=1, prose-en, TTFT p95 ms 1495.42 (1485.01 to 1496.48) 1491.13 (1485.41 to 1505.24) 0.287% (resolution 1.330%) yes
MTP, C=1, prose-en, decode tok/s 41.2191 (40.38 to 41.23) 41.3298 (41.11 to 41.40) 0.268% (resolution 2.044%) yes
MTP, C=2 (sampled), code-fn, prefill tok/s 2656.87 (2647.53 to 2658.12) 2654.31 (2644.53 to 2656.35) -0.096% (resolution 0.500%) yes
MTP, C=2 (sampled), code-fn, TTFT p95 ms 3143.84 (3135.45 to 3155.00) 3145.39 (3138.86 to 3155.01) -0.049% (resolution 0.622%) yes
MTP, C=2 (sampled), code-fn, decode tok/s 31.4853 (30.94 to 33.32) 32.6107 (32.39 to 33.33) 3.574% (resolution 7.537%) yes
MTP, C=2 (sampled), code-fn, total tok/s 47.177 (46.38 to 48.93) 49.1542 (47.74 to 52.43) 4.191% (resolution 9.537%) yes
MTP, C=2 (sampled), prose-en, prefill tok/s 2700.49 (2684.02 to 2704.37) 2697.05 (2696.29 to 2699.69) -0.128% (resolution 0.753%) yes
MTP, C=2 (sampled), prose-en, TTFT p95 ms 3084.43 (3072.64 to 3093.11) 3075.86 (3062.07 to 3086.98) 0.278% (resolution 0.810%) yes
MTP, C=2 (sampled), prose-en, decode tok/s 25.9895 (25.63 to 26.46) 26.8827 (26.75 to 27.09) 3.436% (resolution 3.193%) no
MTP, C=2 (sampled), prose-en, total tok/s 41.2022 (40.48 to 42.14) 43.04 (40.96 to 43.73) 4.460% (resolution 6.434%) yes

The MTP C=2 prose decode row moved by 3.436%, above its resolution of 3.193%, with the rounds apart.

Hardware (if the change is for a machine)

NVIDIA GB10 (DGX Spark), driver 595.84, CUDA 13.3, arch sm_121a, for the gates and the speed run. An RTX 5090 machine at a power limit of 400 W (default 600 W) for the base against head equality runs. Models:

repository revision file
nvidia/Qwen3.8-Flash-Next-FP4-Local b9ce18a6887e18c089fdea8509a33e63429a3300 the folder, with its MTP layer
lmstudio-community/Qwen3.6-35B-A3B-GGUF 68a34855558af61cbef0324d31f411be8a506b08 Qwen3.6-35B-A3B-Q4_K_M.gguf (SHA-256 4ac6a06bce551257267f49ad2226f8671a22519ccc1a4dde9d5b433d1f2a410d)
unsloth/Qwen3.6-35B-A3B-MTP-GGUF 5bc3e238d916f48a861bac2f8a1990a0e9b7e98d Qwen3.6-35B-A3B-UD-Q4_K_M.gguf (SHA-256 0b21525e972670ed59e1812e170b27c26355381f0656ecc4e25617ece7dac58b)
unsloth/Qwen3-30B-A3B-Instruct-2507-GGUF eea7b2be5805a5f151f8847ede8e5f9a9284bf77 Qwen3-30B-A3B-Instruct-2507-Q4_K_M.gguf (SHA-256 6c997b8af17debdfb01d890214400ccbab00db6acc0ba8da5de1cc906c4774d0)

AI help

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

@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 Nov 1, 2026
github-actions[bot]
github-actions Bot previously approved these changes Nov 1, 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 proven behavior or quality defect remains in the changed code.

Non-blocking

⚠ Cover the headless fault read: crates/gpu/src/arch/qwen3moe/body35.rs:2552.
Removing this read lets an unread call return success after a device fault. The new dispatch test uses a fake seat and passes with that mutant.
Extend the owning GPU gate with an unread call that raises a body fault. Assert the named fault and poisoned state, and show FAIL-first with this read removed. Pin this behavior while changing its readback path.

⚠ Complete the run evidence: crates/gpu/src/arch/qwen3moe/body38.rs:4678.
The PR reports equality and timing results, but omits the nvidia-smi line, both tested commit hashes, exact model files, and the A/B runner command with output.
Attach those records so the no-speed-loss claim can be reproduced. The supplied evidence does not meet CONTRIBUTING.md's hardware evidence list.

Checked

Duplicates: 37 new items and 3 moved items checked. Both sides of dryer's headed pair read; their family-specific error adapters have no extraction that reduces net elements.
Complexity: feed35 11→17, DeepSeek feed 21→24, and GLM call_groups 19→22 add head-selection and fault/result branches. prefill_hooked 15→16 adds the closing-call refusal. These extend the existing prompt orchestration.
Silent failure: 5 candidate sites followed. The two default adapters retain headed calls; the two zero results are unused prompt tokens; closing-call cleanup uses the infallible body accessor. Errors propagate.
Tests: static mutation review found assertions against bypassed dispatch, a unit-cut off-by-one, and a dropped Close flag. Existing completed-row, closing-call, and checkpoint-cut assertions remain. The headless fault-read gap is above. No tests or GPU gates were run here.
Gates: no thresholds or pins moved. The unit-cut test moved with its cases intact. The new dispatch test has no FAIL-first result in the PR body.
Adversarial checks: empty and one-id calls, faults during unread calls, closing-call cleanup, and another slot overwriting the prompt arena are blocked by guards, fault reads, cleanup, and retained-row handling.
Escape catalog: C1–C4 do not match this diff.

Card check: needs-gpu. This pull request changes crates/app/src/arch/deepseek41/mod.rs, crates/app/src/arch/glm5next/mod.rs, crates/app/src/arch/glm5next/mtp.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)

… before the last runs no head, the last call folds its last id where the body allows it, and the unit cut and its read rows live in the shared owner

@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.

Since the last review:

Verdict: CLEAN: The two context-only interdiff hunks introduce no proven defect in the rebased prompt integration.

Non-blocking

⚠ Cover the headless fault read: crates/gpu/src/arch/qwen3moe/body35.rs:2552.
Removing this read lets an unread call return success after a device fault. The fake-seat dispatch test still passes.
Extend the owning GPU gate with an unread call that raises a body fault. Assert the named fault and poisoned state, and show FAIL-first with the read removed. Pin this boundary while changing its readback path.

⚠ Complete A/B reproduction: crates/gpu/src/arch/qwen3moe/body38.rs:4678.
The timing section supplies server commands, request specifications and results, but omits the exact client runner command.
Attach that command with its output so the no-speed-loss claim can be reproduced.

Checked

Duplicates: 0 new items in the interdiff. Both sides of dryer's headed pair re-read; the unchanged family-specific error adapters require no extraction.
Complexity: feed35, DeepSeek feed and GLM call_groups add head/fault branches; prefill_hooked adds a Close refusal. These full-diff flags have no further growth in the interdiff.
Silent failure: 0 new sites. Prompt-call errors propagate; headed calls require a token.
Tests: no new tests in the interdiff. The dispatch assertions pass with the fault-read mutant above. No builds or GPU gates run here.
Gates: no thresholds, pins or cases changed in the interdiff.
Adversarial: sampled multi-slot rounds forward their draws and retain prompt rows before another slot overwrites them. Both rebased round implementations match the base; the new imports resolve their existing owners.
Escape catalog: C1–C4 do not match.

Notes

The supplied GPU results name pre-rebase head 81c4bd7.

Card check: gpu-evidence. This pull request changes crates/app/src/arch/deepseek41/mod.rs, crates/app/src/arch/glm5next/mod.rs, crates/app/src/arch/glm5next/mtp.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 Nov 1, 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 e7a01d5 into midagedev:main Nov 1, 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 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