Skip to content

serve: /metrics splits decode rounds by width, the engine's waits by phase and the draft's counts by depth - #1007

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-service-metrics
Oct 30, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-service-metrics

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

서버 /metrics가 decode round를 동시 slot 수별로 나누고, 엔진이 card와 PLE를 기다린 시간과 draft의 depth별 제안과 수락 수를 함께 내도록 했습니다.

What and why

/metrics showed one decode total, so a reader could not tell how long a round took at each batch width, how much of that time the engine spent waiting for the card or for PLE rows from NVMe, or at which depth a drafter's ids were accepted. This change adds those counters:

  • rounds_total, round_seconds_total, round_card_wait_seconds_total and round_ple_wait_seconds_total, each labelled by width (the slots one round stepped or passed).
  • card_wait_seconds_total and ple_wait_seconds_total, the same waits over every engine call.
  • spec_decode_num_draft_tokens_by_depth_total and spec_decode_num_accepted_tokens_by_depth_total, labelled by source (the drafter kind from /props) and depth. They sum to the existing draft and accepted totals.

The source label is escaped for the Prometheus text format. A wait total that goes down is a named panic instead of a silent zero. docs/serving.md describes the new rows.

Release notes: Added: /metrics splits decode rounds by batch width and reports card and PLE wait time and per-depth draft proposals and acceptances.

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": none.

What I ran

Base fb43427d12d4ad05b11327ad5be8611ebaed2f2c (upstream/main), head 4069f68eaaa88d8e2604de702f0100895065e75f.

Serve gate set (the commands behind gate-serve: the bloomery-serve lib and its ten integration targets), every target 0 failed:

bash tools/gate.sh -p bloomery-serve --lib --test serve --test dsml --test glmxml --test hermes --test qwenxml --test callstream --test limits --test anthropic --test penalty --test sampdraft --test contract -- --include-ignored
test result: ok. 454 passed; 0 failed; ...   (lib)
test result: ok. 111 passed; 0 failed; ...   (serve)

The two tests that cover this change, run on the head. Each of the three mutations below fails its test first, then the restored code passes:

cargo test -p bloomery-serve --lib api::tests::metrics_split_rounds_by_width_waits_by_phase_and_drafts_by_depth -- --exact
cargo test -p bloomery-serve --lib engine::tests::wait_deltas_require_monotonic_totals -- --exact
label escaping removed:          a labelled row                                              1 failed
card delta back to saturating_sub: a decreasing wait total must panic: Waits { card: 0ns, ple: 7ms }   1 failed
PLE delta back to saturating_sub:  a decreasing wait total must panic: Waits { card: 3ms, ple: 0ns }   1 failed
restored code, both tests:       1 passed; 0 failed

GPU gate clauses for the two engine wait counters, in the GPU lib build on the card (BLOOMERY_BOX_LOCAL=1):

bash tools/gate.sh --gpu --oxide -p bloomery-gpu --release --lib -- the_busy_guard_marks_clears_and_bumps a_folder_s_stored_rows_decode_as_the_split_s
test watchdog::tests::the_busy_guard_marks_clears_and_bumps ... ok
test arch::qwen3moe::body38::tests::a_folder_s_stored_rows_decode_as_the_split_s ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 465 filtered out

Real server on the card. Build and start bloomery-serve, then send one sampled request alone and two sampled requests at once (n_predict 128, temperature 0.7):

cargo oxide build --arch sm_121a -- -p bloomery-gpu-gates --features <release features from tools/release/build.sh> --release --bin bloomery-serve
BLOOMERY_RESIDENCY=off BLOOMERY_HOST_ROOM=96G target/release/bloomery-serve -m <Qwen3.8-Flash-Next-FP4-Local b9ce18a6> --host 127.0.0.1 --port 18743 --parallel 2 --ctx-size 16896
curl -s http://127.0.0.1:18743/metrics | grep -E 'round|wait|by_depth|n_decode_total|spec_decode_num'

The drafter is MTP (slots=2 ctx=8448 cache=q8_0). The seven checks on the scrape all pass (CARDRUN PASS):

width="1": 61 rounds, 3.590 s, card wait 3.006 s (83.7 %), PLE wait 0.074 s
width="2": 51 rounds, 4.815 s, card wait 3.898 s (80.9 %), PLE wait 0.089 s
card_wait_seconds_total 7.358   ple_wait_seconds_total 0.183
n_decode_total 115   (112 rounds + 3 prompts)
spec_decode_num_draft_tokens_by_depth_total{source="mtp"}     depth 1/2/3: 150 135 82   (sum 367 = spec_decode_num_draft_tokens_total)
spec_decode_num_accepted_tokens_by_depth_total{source="mtp"}  depth 1/2/3: 111  76 36   (sum 223 = spec_decode_num_accepted_tokens_total)
check a_widths_1_and_2 / b_round_card_wait_within_round / c_card_total_covers_rounds / d_calls_are_rounds_and_prompts / e_depths_under_mtp / f_depth_sums / g_depths_shrink: PASS

The wait counters are not a speed change and no throughput number is claimed.

Hardware (if the change is for a machine)

NVIDIA GB10 (DGX Spark), driver 595.84, CUDA 13.3.1.

AI help

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

@github-actions github-actions Bot added documentation Improvements or additions to documentation 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 30, 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: MUST_FIX: The new metrics test accepts removal of two required metric families.

Must fix

1. Assert that both round-time families exist

crates/serve/src/api.rs:10943.
Kind B: the test never reads round_seconds_total; its PLE all() assertion accepts no rows. Removing either family from labelled_metrics leaves this test green. Pin both required families while adding the metrics contract so later deletions cannot pass this test.
Insert before the PLE assertion:

assert_eq!(rows("round_seconds_total").len(), rounds.len(), "one round-time row per width: {m}");
assert_eq!(rows("round_ple_wait_seconds_total").len(), rounds.len(), "one PLE-wait row per width: {m}");

Non-blocking

⚠ Attach the move-class proof: crates/serve/src/worker.rs:1081.
call_round extracts decode dispatch. AGENTS' move/split/rename class requires identical covering PTX scans; the body supplies gates but no scan comparison.
Attach just narrow fb43427d12d4ad05b11327ad5be8611ebaed2f2c faf091f029b47bc4bb9f885ee9e105b9effbb74b output to establish that proof before merge.

Checked

Duplicates: 43 new definitions checked; no duplicated owner found. The one dryer pair, Waits::add_assign and Depth::add_assign, adds different quantities.

Complexity: crapper reports Worker::call_round at 22. This extracts the existing dispatch branches from step; it adds no dispatch decisions.

Silent failure: 3 new candidates followed. An absent optional draft kind yields the explicit unknown label; both test parse failures reach named panics.

Tests, static mutation review: crates/serve/src/engine.rs:647,651 changed to saturation loses the required panic; crates/serve/src/genloop.rs:284 changed from < to <= breaks the exact depth counts; removing label escaping at crates/serve/src/api.rs:2951 breaks the API test. Removing the additions at crates/gpu/src/watchdog.rs:235 and crates/gpu/src/arch/qwen3moe/body38.rs:746 breaks their wait assertions in isolation. Missing-family mutants pass as described above.

Gates: no existing pin, threshold or test clause was removed or relaxed.

Escape catalog: no C1–C4 pattern matched.

Hot paths: decode/prefill instrumentation adds one atomic add per recorded wait and one extra stats lock per worker-loop iteration; no launch, transfer or reduction-order change.

Adversarial checks: zero-width rounds return before indexing; zero drafts preserve both totals; cache-only actions publish waits before replying. No unsafe block was added.

Notes

Rust tests and GPU gates were not rerun locally. Review used source inspection and the supplied diagnostics.
GPU evidence is incomplete for this head: the body names 4069f68e, while the reviewed head is faf091f0; the build/model commands also contain placeholders.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bind.rs, crates/gpu/src/arch/qwen3moe/body38.rs, crates/gpu/src/host/mod.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)

…phase and the draft's counts by depth

/metrics gains labelled counters. rounds_total, round_seconds_total, round_card_wait_seconds_total and round_ple_wait_seconds_total carry a width label, the slots one decode round stepped or passed: a round's wall time on the engine thread, the part the engine waited for the card's work and the part it waited for PLE table rows, the rest being host time. card_wait_seconds_total and ple_wait_seconds_total count the same waits over every call. spec_decode_num_draft_tokens_by_depth_total and spec_decode_num_accepted_tokens_by_depth_total count a drafted pass's ids by depth under the drafter's kind (source); they sum to the existing draft totals and are booked when a request ends, as those are.

The engine reports its waits through Engine::waits (zero by default). The CUDA engine counts each finished wait of a guarded engine call as card wait, and each wait of a Qwen3.8 fill for PLE table rows read off the NVMe tier as PLE wait; the server reads the totals around each round and counts from its own start.

@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 added assertions close the reported test gap; the interdiff introduces no new defect.

Non-blocking

⚠ Attach the move-class proof: crates/serve/src/worker.rs:1081.
AGENTS requires identical covering PTX scans for the dispatch extraction. The body supplies no comparison.
Attach just narrow fb43427d12d4ad05b11327ad5be8611ebaed2f2c 7b7f61dd0873ccd7e9967fb0d1c8432bcd67ab47 output to verify this before merge.

Checked

Duplicates: 0 new definitions in the interdiff. The dryer pair was read: Waits::add_assign and Depth::add_assign aggregate different quantities.

Complexity: crapper flags Worker::call_round at 22, an extraction of existing dispatch branches. The interdiff changes no dispatch decisions.

Silent failure: 0 new sites; both additions fail explicitly on a missing metric family.

Tests, static mutation review: deleting the family at crates/serve/src/api.rs:2980 or :2992 fails the corresponding new assertion. The positive width-2 round assertion prevents zero-row comparisons from passing. Both comparisons use the same captured scrape.

Gates: two assertions added; no gate relaxed or pin moved.

Escape catalog: no C1–C4 pattern matched.

Notes

Rust tests and GPU gates were not rerun locally; validation was static.
GPU evidence remains incomplete: the body names head 4069f68e, provides no literal nvidia-smi output, and leaves build/model placeholders.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bind.rs, crates/gpu/src/arch/qwen3moe/body38.rs, crates/gpu/src/host/mod.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 b9584f6 into midagedev:main Oct 30, 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 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