Skip to content

serve, app, gates: a drafted pass whose pick reads only a row's best logits takes each verified row from the card's best read - #1067

Merged
juliankang4 merged 4 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-next-sampler-accept
Nov 1, 2026
Merged

juliankang4 merged 4 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-next-sampler-accept

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

확률이나 structured output을 요청한 요청도 MTP draft pass를 타게 하고, 샘플링 pass는 행마다 카드에서 읽은 best 64개 logit만 받게 합니다.

What and why

A request that asks for probabilities, or for structured output (json_schema, json_object, a forced tool call), stepped one token at a time even when the MTP draft was on. Both now ride the draft pass. The request's own pick (sampler, bias, program walk, probability collector) is lent to the pass, and each kept row feeds it exactly once, so ids and probability values match the one-token path. A program's walk moves only through kept ids, so nothing needs rolling back.

A sampled pass also read every verified row in full (248,320 f32 logits, 993,280 B per row for Qwen3.8). When the request's pick reads only each row's best logits (top_k up to 64, a penalty that only lowers, a bias that only lowers, greedy), the card now returns 64 best logits and ids per row plus the row's first NaN, 516 B per row, in two launches (crates/gpu/src/best.rs). The pass hands the sampler a row with everything outside those 64 set to -inf. Requests that need the whole row (probabilities, top_k 0, a penalty or bias that can raise a logit) still read it.

The best read and the drafting live in the shared owners: GpuModel (both head layouts), the slots round, serve and the common seat code. Model files only pass the best-read count through.

Release notes: Added: requests that ask for probabilities or structured output now use the MTP draft pass, and sampled MTP passes read each row's 64 best logits from the card instead of the whole row.

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 to make a check pass; 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): crates/gpu/src/dspark/selector.rs carried its own top-16 warp tournament (warp_top16). It is removed; the selector's three calls now use warp_best<PER, K> in crates/gpu/src/best.rs, which takes the list length as a parameter. The selector hardware tests pass on the shared version (below).

What I ran

All runs used the repository's own gate and check commands on an NVIDIA GB10 and an RTX 5090. The card and driver lines are in Hardware.

Kernel test on GB10 and RTX 5090. The card's best lists equal the host's lists bit for bit (V = 248,320 x 8 rows, 151,936 x 5 rows, a short vocab, NaN rows, equal values, +-0, +-inf):

$ BLOOMERY_BOX_LOCAL=1 ./tools/box.sh 'bash tools/gate.sh --gpu --oxide -p bloomery-gpu --release --lib -- --include-ignored best:: --nocapture'
test best::tests::hw_best_lists_are_the_host_lists ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 473 filtered out

PTX spill gate. The two new kernels, best_part and best_merge, spill nothing, and every pinned entry passes:

$ BLOOMERY_BOX_LOCAL=1 just gate-ptx-spill
ptx-spill bin=generate_ds41 table=tools/ref/ptx-shapes/sm_121a-cc12.1.tsv ... entries=505 pinned=505 ... violations=0 PASS    (GB10)
ptx-spill bin=generate_ds41 table=tools/ref/ptx-shapes/sm_120a-cc12.0.tsv ... entries=505 pinned=505 ... violations=0 PASS    (RTX 5090)
ptx-spill bin=gate_qwen3vl_tower ... entries=26 pinned=26 nonzero=none violations=0 PASS

Selector and best-read tests on GB10, after the selector moved onto the shared tournament:

$ bash tools/gate.sh --gpu --oxide -p bloomery-gpu --release --lib -- --include-ignored best:: dspark::selector:: --nocapture
test dspark::selector::tests::hw_selector_faults_by_name ... ok
test dspark::selector::tests::hw_selector_head_returns_the_host_walk ... ok
test dspark::selector::tests::hw_selector_candidates_and_scores_are_the_host_twins ... ok
test best::tests::hw_best_lists_are_the_host_lists ... ok
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 470 filtered out
test tests::a_best_row_holds_its_own_list ... ok
test drafted::tests::a_draw_reads_best_up_to_the_cards_list ... ok

$ just ptx-compare 08fe86386 generate_ds41 --features gpu,deepseek41
  base entries  503
  head entries  505
  added         2: best_merge best_part
  removed       none
  changed       2: sel_topk_merge (ptx-scan-md5:eaabbac1->2739a81a) | sel_topk_part (regs:78->79 jit_regs:78->79 ptx-scan-md5:374011f7->9bf8f86c)

Real server on GB10. bloomery-serve built in release with the release feature set, Qwen3.8-Flash-Next-FP4-Local, MTP draft on by default:

$ BLOOMERY_RESIDENCY=off BLOOMERY_STEP_STATS=1 BLOOMERY_HOST_ROOM=96G target/release/bloomery-serve --host 127.0.0.1 --port 18741 --parallel 2 --ctx-size 16896
load draft=mtp ...
check a_default_load_drafts: PASS
check b_best_together_ids_are_alone: PASS
check b_best_drafts: PASS [(115, 77), (122, 74), (84, 52), (77, 55)]
check b_best_rounds_pass: PASS 72 pass rows=2 of 72 records
check c_whole_rows_ids_are_best_rows_ids: PASS
check d_asking_drafts: PASS [(96, 64), (48, 37)]
check d_asking_one_entry_a_token: PASS 96
check d_asking_together_is_alone: PASS
check e_json_valid: PASS
check e_json_drafts: PASS [(9, 6), (10, 7), (12, 5)]
check e_json_together_is_alone: PASS
CARDRUN PASS

The requests go to /completion with temperature 0.7, top_k 20 and a fixed seed (b, c); a request that asks for probabilities (d); and a json_schema request (e). The pairs are (drafted tokens, accepted). Each request gives the same ids and probability values alone and next to another slot. Check c adds a +1e-30 bias so the same request reads the whole row, and the ids equal the best-read ids. The asking request returned 96 tokens, 64 of them accepted from draft passes. The schema request returned {"name": "user", "year": 2024, "kind": "book", "ok": true, "note": "ok"} with 6 of 9 drafted tokens accepted.

Two-slot decode, base against head on GB10, same model, fp4l-mtp-c2s arm (two slots, temperature 0.7, seed 42, top_k unset so the default 40 takes the best-read path), a warm-up and then 3 rounds each. Base is 27533de28, head is 3be1cbff:

Metric Base Head Difference Ranges overlap
code-fn decode tok/s 31.70 32.04 +1.08% yes
code-fn total tok/s 46.22 47.02 +1.73% yes
prose-en decode tok/s 26.57 26.98 +1.53% yes
prose-en total tok/s 42.46 42.98 +1.22% yes

Prefill and TTFT p95 are within 0.4% on both prompts. The change makes no speed claim; this shows no decode regression on the path it touches.

Clippy on the touched crates, no warning in a changed file:

$ cargo clippy -p bloomery-gpu -p bloomery-app -p bloomery-gpu-gates --all-targets
clippy-rc=0

Hardware (if the change is for a machine)

Machine Card Driver CUDA
DGX Spark NVIDIA GB10, sm_121a 595.84 13.3
RTX 5090 machine NVIDIA GeForce RTX 5090, sm_120a 595.99.02 13.3

AI help

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

…alue read from its verified row by the request's own pick
…through the kept ids it picks from their verified rows
…with each row's first NaN, in place of the whole rows

The warp tournament takes its list length as a parameter, and the selector
head's top-k launches take their lists by it in place of warp_top16. A
retired entry now drops its id too, so a warp with fewer finite entries than
the list ends it with -inf slots that name no id twice.
…logits takes each verified row from the card's best read
@github-actions github-actions Bot added documentation Improvements or additions to documentation 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 serve The HTTP server: crates/serve tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 31, 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 reachable behavior failure or proven quality defect survived review.

Non-blocking

⚠ Complete the performance evidence: crates/gpu/src/model.rs:1549 adds two launches per row read under PerRow, versus two per pass under One [derived].
The launch-count/geometry class needs the owning gates and timed A/B evidence. Attach the runner commands and output for the current head, including the PerRow path; the supplied Qwen3.8 table names an earlier head. This establishes a reproducible baseline now.

⚠ Show FAIL-first for the new gate: crates/gpu/src/best.rs:549 has green output but no failing run in the PR body.
Plant a wrong-id or reversed-tie mutant in warp_best, show the list assertion fail, then restore it and show green. This confirms the regression guard before later kernel changes.

Optimization headroom

  • E. Less work: crates/gpu/src/best.rs:482 copies all eight output rows even when only m were written. Limit the existing readback to the valid prefix: 516 × (8 − m) fewer bytes per read; at m=1, 3,612 fewer bytes per row read on PerRow [derived].

Checked

Duplicates: 75 new named declarations searched; no proven duplicate. Both dryer pairs read: the builders set different facts. The selector reuses the shared tournament.
Complexity: pass_best is new at 16, combining validation, scratch initialization and layout-specific readback. pass_slots and Gen::pump each grow by two through existing state decisions; no defect established.
Silent failure: six sites followed through their consumers; unsupported best reads use full rows, and invalid rows or picks reach named errors.
Tests: static mutation analysis only. crates/gpu/src/best.rs:125 retirement removal breaks list equality; crates/app/src/lib.rs:424 reset removal breaks stale-row equality; crates/gpu-gates/src/bin/shared/serve_seats/drafted.rs:77 changing <= to < breaks the boundary assertion; crates/serve/src/sampling.rs:118 removing zero equality breaks the zero test.
Tests: crates/serve/src/genloop.rs:2282 bypassing the pick breaks drafted walk/schema and probability assertions; crates/serve/src/engine.rs:1328 dropping the penalty-window allowance breaks best/plain sampling equivalence; crates/serve/src/genloop.rs:2273 disabling asking passes breaks the asking-pass count assertions.
Gates: no tolerance moved; the unsafe ratchet increase has a dated PIN and reason. New spill entries retain zero allowances.
Escape catalog: C1–C4 match no changed executable code. Boundary sizes, NaN propagation, mixed full/best reads and held-program handoff checked.

Notes

Gates were not rerun. The PR supplies a hardware table but no nvidia-smi output; GPU evidence is recorded as false.

Card check: needs-gpu. This pull request changes crates/app/src/lib.rs, crates/app/src/mtp.rs, crates/gpu-gates/src/bin/shared/serve_seats/drafted.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 6791d57 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

documentation Improvements or additions to documentation 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 serve The HTTP server: crates/serve tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant