Skip to content

app: compare all and selected logits through the same host read boundary - #978

Merged
juliankang4 merged 9 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-sa-q9-serve-host
Oct 29, 2026
Merged

juliankang4 merged 9 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-sa-q9-serve-host

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen 긴 문자열 인자는 새로 온 부분만 파싱해 보내고, 섞인 슬롯 round는 logits가 필요한 슬롯의 행만 host로 읽도록 고쳤습니다.

What and why

Two host-side costs grow with the work they should not scale with.

  1. A streamed Qwen tool-call string argument was re-scanned, re-escaped and re-sent from its start on every fragment, so work grew with the square of the argument length. The parser now keeps a cursor and escapes and streams only the new text. QwenScan::push keeps its public Progress snapshot contract; ChatParser uses an internal path that builds no snapshot.
  2. Session::step_slots_rounds read and NaN-checked the logits of every row in a round. It now takes one request flag per entry and reads and checks only the rows that were asked for, so a greedy slot sharing a round with a sampled slot no longer reads logits it never uses. The shared device staging transfer is unchanged; the saved work is the host copy and the NaN scan of the unrequested rows.

GPU kernels and the greedy ids do not change. The numbers below are host boundaries (the parser, and the copy and NaN check after staging), not end-to-end decode speed.

Release notes: Fixed: long streamed Qwen tool-call string arguments no longer take quadratic host work, and a mixed greedy and sampled round reads only the logits it needs.

Code shape

  • 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), or "none": crates/gpu-gates/src/bin/gate_qwen3_serve.rs:1953 has request wrappers close to gate_qwen38_serve.rs:1888 and :1992. They share the gate's streamed_body; the two gates return different result types (the Qwen3.8 one counts draft tokens), so I left them separate.

What I ran

Parser, before the fix (test added alone on the base), 114,000 byte string sent in 3,000 fragments:

cargo test -p bloomery-serve --test callstream hw_qwen_long_string_stream_is_linear -- --ignored --nocapture
long-string Lines: bytes=114000 allocated=1444056790 host_us=4922400
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 4 filtered out

Parser, after the fix:

cargo test -p bloomery-serve --test callstream --test qwenxml -- --ignored --nocapture
long-string Lines: bytes=114000 allocated=5025621 host_us=14574
long-string Compact: bytes=114000 allocated=5066572 host_us=13299
test result: ok. 5 passed; 0 failed   (callstream)
test result: ok. 20 passed; 0 failed  (qwenxml)
Metric (114,000 byte string, debug build) Base Head Difference
Bytes allocated, Lines framing 1,444,056,790 5,025,621 287 times fewer
Parser host time, Lines framing host_us=4922400 host_us=14574 338 times less

These are single debug-build runs of the same test, a parser boundary and not a decode speed.

Logits host read, 2 slots, vocabulary 151,936, mean of 32 rounds after one warm-up, both arms through the same row function and the same copy and NaN check:

BLOOMERY_BOX_LOCAL=1 bash tools/gate.sh --oxide -p bloomery-app --release --lib -- round_reads_only_requested_logits --nocapture
mixed-logits vocab=151936 rounds=32 all_host_us=112.938 selected_host_us=56.636
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 27 filtered out
Metric Base (all rows) Head (requested row) Difference
Host copy and NaN check per round all_host_us=112.938 selected_host_us=56.636 half the rows read

cargo clippy -p bloomery-serve --lib --no-deps reports no warnings, and the 24 callstream and qwenxml functional tests pass.

Real GPU gate, a greedy slot and a seed 42 sampled slot decoded alone and together on the Qwen3.6 35B-A3B Q4_K_M GGUF through the real bloomery-serve:

bash tools/gpu-gate.sh gate_qwen3_serve --model <Qwen3.6-35B-A3B-Q4_K_M.gguf> --only-mixed --dir target/sa-q9/mixed
check mixed_slots_parallel_line_names_one_pass: PASS
check mixed_slots_together_alone: PASS
check mixed_slots_rounds_run_one_pass: PASS
check mixed_slots_rounds_hold_a_round_of_both: PASS
gpu-gate.sh: gate_qwen3_serve ran 21 s (exit 0)

Real binary, streamed against non-streamed tool call with a 4,864 byte string argument whose schema pins the exact content (bloomery-serve --model qwen38 on the Qwen3.8 Flash Next FP4 checkpoint, BLOOMERY_DRAFT=off, BLOOMERY_SCHEMAJUMP=off, --ctx 8192 --parallel 1):

Qwen real-binary tool-stream PASS utf8_bytes=4864 argument_bytes=5390 fragments=1285 equal=true

The streamed fragments joined equal the non-streamed arguments string byte for byte.

Hardware (if the change is for a machine)

Mixed-slot gate and logits host read:

NVIDIA GeForce RTX 5090, 595.99.02, 32607 MiB

Real-binary tool stream:

NVIDIA GB10, 595.84, [N/A]

The parser tests ran on CPU only.

AI help

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

@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 serve The HTTP server: crates/serve labels Oct 29, 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 regression or new quality defect was established in the changed code.

Non-blocking

⚠ Make the logits timing reproducible: crates/app/src/lib.rs:1127 exercises a three-float buffer and prints no mixed-logits timings. The PR attributes the vocabulary-sized, 32-round benchmark output to this test. Supply the actual benchmark source and command, with both measured commit hashes. This makes the claimed host-copy saving reproducible.

Checked

Duplicates: 20 new functions, types, constants and statics checked; no new duplicate owner. Dryer reported zero pairs. The gate transport overlap predates this extraction.
Complexity: CallRead::advance is new at 24 (function header, active value, following tag stages); ChatParser::stream 3→9 adds snapshot/advance dispatch; step_slots_rounds 14→19 adds selective reads; gate run 46→51 adds arm dispatch; slots_rounds_run_one_pass 41→42 mostly moves the existing arm body.
Silent failure: 10 added or relocated fallback sites followed. Active cursor state guarantees the function name; invalid typed values reach the complete parser's named errors. Record fallbacks reach checks or diagnostics.
Tests: mutation review only. Removing the skipped-row return or NaN check breaks the new row test; dropping name/index validation or close-state clearing breaks the advance test. Re-sending complete argument prefixes breaks the long-string equality/allocation assertions. Rewinding the non-string search before its value start breaks the empty-boolean chunking case.
Gates: the unsafe-count increase has a dated PIN and reason. The parser allocation gate has reported FAIL-first evidence. No existing tolerance or clause was relaxed.
Adversarial checks: fragmented UTF-8 and delimiters, a cut inside a call, several calls per push, mixed requests across reordered passes, and staging refresh at the first requested row were traced. Device fault readback still rejects invalid head computation before greedy ids return.
Escape catalog: no C1–C4 pattern matched.

Notes

Static review; no build or GPU gate was run here. The posted GPU run lacks both measured commit hashes, so gpu.json records incomplete evidence.

Card check: needs-gpu. This pull request changes crates/app/src/lib.rs, crates/gpu-gates/src/bin/gate_qwen3_serve.rs, crates/gpu-gates/src/bin/shared/serve_seats/rounds.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 63980fe into midagedev:main Oct 29, 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 serve The HTTP server: crates/serve

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant