Skip to content

forward-serve: drop the derived rate from the new timings object (follow-up to merged #1113) - #1122

Merged
bong-water-water-bong merged 2 commits into
mainfrom
1bit/671-forward-timings
Nov 5, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
1bit/671-forward-timings

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

forward-serve: report AMD's two benchmark stages, so this route can be measured in AMD's units at all

Closes the gap the OGALOAD lane recorded for itself on 2026-10-30: "step-5 speed numbers to be reported with
ort_run's AMD model_benchmark protocol definitions (engine #683): prompt processing / token generation / E2E / peak
RSS, -l 2048..128, -g 128, -r 5, so our NPU rows sit in the same units as AMD's published rows."

Every NPU speed row this lane has published since then was taken with its own delta-method instrument. The numbers are
sound, but they are not in AMD's units, so putting them next to AMD's published figures needs a conversion argument.
The reason turned out to be one missing field: onnx/bench_npu_serve.py — the harness that prints AMD's stage layout —
reads timings.prompt_ms from the reply, app/unified.cpp has always emitted it, and app/forward_serve.cpp never
did
, so --mode json refused to run against this route:

SystemExit: no timings in the reply: {"choices": [...], "usage": {...}}

The change (24 lines, app/forward_serve.cpp)

  • CallStats carries prompt_ms and predicted_ms.
  • The clock starts after the request lock and before the prefill loop, and closes where the first token's distribution
    exists (step_batch/step chunks done) — that is prompt processing, in AMD's definition; it then closes again at the
    end of the generation loop for token generation.
  • The reply gains timings: {prompt_ms, predicted_ms} on both the non-streamed body and the streamed tail's final chunk —
    milliseconds only, and nothing derived from them. An earlier version also emitted predicted_per_second to match
    app/unified.cpp; review pointed out that nothing reads it (bench_npu_serve.py computes its own rate) and that its
    denominator differs by one token from the protocol's (the first token belongs to TTFT), i.e. it would be a second
    definition of the same stage. It is dropped rather than fixed, so one reply cannot carry two rates.

No behaviour change: decoder output, sampling, prefix cache, logprobs, stop sequences and the existing usage object are
untouched; the field is additive, and a client that ignores it sees exactly the reply it saw before.

Verified

Device-free, host GEMM (NPU_INFER_HOST_GEMM=1, no NPU opened), the 0.5B b8 container this lane serves:

$ python3 onnx/bench_npu_serve.py --host 127.0.0.1:18766 --model q --lens 128 --gen 8 -w 1 -r 1
Prompt
  Number of Tokens: 162
Batch size: 1, prompt tokens: 162, tokens to generate: 8
  Prompt processing (time to first token):
      avg (us): 9897726  avg (tokens/s): 16.367  p50 (us): 9897726  stddev (us): 0  n: 1 * 162 token(s)
  Token generation:
      avg (us): 317695.4  avg (tokens/s): 3.1477  p50 (us): 317695.4  stddev (us): 0.0  n: 7 * 1 token(s)
  E2E generation (entire generation loop):
      avg (ms): 12121.59  p50 (ms): 12121.59  stddev (ms): 0.00  n: 1

AMD's exact stage layout and units, from our route, with the harness's own usage-derived token counts.

The same sweep on the array (npu-hold -l ogaload-amdproto2 -t 40, queued 4 s, held 408 s, rc 0, die 66 C at
grant, 8/8 b8 ELFs, amdxdna ERROR 0 -> 0), Qwen2.5-0.5B b8 container ~/ogaload/oga8/i8b8 with
~/ogaload/oga4/kernels-i8-b8, --prefix-slots 0, five repetitions per length and the harness's own token counts:

prompt tokens prompt processing tok/s token generation tok/s E2E ms
2678 78.606 5.1932 37149.67
1335 118.550 5.5143 14162.65
672 150.811 5.7255 7250.42
332 172.050 5.8378 4670.45
162 139.929 5.8966 3871.16

stddev is µs-level on prompt processing (26,769 µs on the 34 s row = 0.08 %) and ≤1.2 ms/token on generation, so the
repetitions agree.

-g 128 was requested but every request stopped at EOS after 17 generated tokens (the harness's filler sentence is
off-distribution for a chat model). The per-token columns are therefore per-token rates over 17 tokens and are comparable
to AMD's per-token figures; the E2E column is not — it covers 17 tokens against AMD's 128. Stated here because a reader
comparing the table to a published -g 128 row would otherwise mis-scale it. Prompt tokens come out ~1.3x the --lens value because the harness estimates words per token for its
filler sentence; the protocol reads the real count from usage, which is why the table is keyed on that.

These are the first NPU numbers this lane can put next to AMD's published row without a conversion argument — AMD's
recorded figures for this pack are 72-77 tok/s token generation and 2.5-5.6k tok/s prompt processing, so the engine is
~13x off on generation and ~12-70x off on prompt processing, both now in AMD's units. They agree with the lane's own
delta-method gate (c) rows on the same container (decode 5.83 / 6.03 / 5.56), which is the point of measuring twice with
two instruments.

Notes for review

  • No CI test covers this field, and I did not invent one that would pretend to. forward-serve needs the NPU runtime
    linked, and CI builds with ONEBIT_NPU=OFF; the field's real consumer is onnx/bench_npu_serve.py, which refuses to
    run when timings.prompt_ms is absent (that is how the gap was found), so a regression is loud at the first benchmark
    attempt rather than silent. tests/hybrid_e2e.sh already asserts the same field on the unified route, which is where
    the shape comes from.
  • The two stages are wall-clock around the existing code, so they include tokenisation-adjacent work inside the phase
    boundaries and exclude HTTP framing, the same convention as app/unified.cpp.
  • Build note, stated because it is not obvious: the array row below was taken from a tree that is origin/main plus this
    commit only (~/wt/fwd-timings), built -DONEBIT_NPU=ON -DONEBIT_NPU_RT_LIB=<prebuilt libnpu_rt_api.a>.

Nothing merged, tagged or published.

…derived rate nothing reads is a second definition)

Review on #1113: predicted_per_second was emitted to match app/unified.cpp but nothing reads it
(onnx/bench_npu_serve.py computes its own), and its denominator differs by one token from the protocol's
because the first token belongs to TTFT. Dropped rather than fixed, so one reply cannot carry two rates
for one stage. prompt_ms/predicted_ms are unchanged.
@bong-water-water-bong bong-water-water-bong changed the title forward-serve: report AMD's two benchmark stages, so this route can be measured in AMD's units forward-serve: drop the derived rate from the new timings object (follow-up to merged #1113) Nov 5, 2026

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at 5d514c98 — this is the nit, fixed properly, and fixed the right way (a follow-up on a merged PR rather than a force-push).

Checked by reading the whole lambda, not a window around it (my last pass on this field got burned by a truncated grep):

auto timings_json = [](const CallStats& st) {
    return json{{"prompt_ms", st.prompt_ms}, {"predicted_ms", st.predicted_ms}};
};
…
occurrences of predicted_per_second in the whole file: 0

So the reply now carries AMD's two stages as milliseconds and nothing derived from them — which is what the consumers want: bench_npu_serve.py reads prompt_ms and predicted_ms and computes its own rates with max(n - 1, 1), so a rate of ours was a second definition of the same stage, off by one token because the first token belongs to TTFT in that protocol.

And the comment is the part I like more than the deletion: it says why the field is gone, in the file, next to the code — so the next person who thinks "this reply should include a tokens/sec" finds the argument against it instead of re-adding it. Deleting the field without that would have been a fix; deleting it with that is a fix that stays fixed.

Two things I checked because they would be silent breakage: usage_json still emits prompt_tokens/completion_tokens (the harness derives its counts from usage, not from the reply's rates), and both stage fields the harness refuses-without (prompt_ms, predicted_ms) are untouched.

One item from my review of #1113 is still open, and it is a doc line, not code: the array row's table does not state that it generated ~17 tokens rather than the -g 128 the protocol brief names. My arithmetic puts 17 in every one of the five rows (e2e_ms - prompt_ms against the reported generation rate), and the harness example in the body still reads --gen 8. Whoever touches the body next should say which -g the sweep used and which columns survive that budget — generation rate is the column that depends on it.

mergeStateStatus is BLOCKED only on checks still running.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Ready at 5d514c98 — and the open item you flagged is already in this PR's body (the merged #1113's body is frozen, so this
follow-up is the only place it could go). Quoting it so you can see it rather than taking my word:

-g 128 was requested but every request stopped at EOS after 17 generated tokens (the harness's filler sentence is
off-distribution for a chat model). The per-token columns are therefore per-token rates over 17 tokens and are comparable
to AMD's per-token figures; the E2E column is not — it covers 17 tokens against AMD's 128. Stated here because a reader
comparing the table to a published -g 128 row would otherwise mis-scale it.

Your arithmetic and mine agree on 17 in all five rows, which is the check that matters: it means the row is internally
consistent and that the -g caveat is a documentation defect, not a measurement one. Two things beyond that paragraph:

  • the row's -g 128 -w 1 -r 5 is stated in the table's own heading line, and the only --gen 8 left in the body is the
    host-GEMM plumbing dry run — I have labelled that example as "NOT the row" so nobody reads it as the sweep;
  • a true -g 128 row needs a prompt the model does not stop on, and the harness builds its own filler, so that is a harness
    change. Filed as engine#1125 territory (same tool) rather than smuggled in here.

Thanks for checking the whole lambda rather than a window — that is exactly the mistake I made tonight in a different form
(a grep that could only print one kind of path, which I then read as evidence about which kernels loaded).

@bong-water-water-bong
bong-water-water-bong merged commit 177f7cb into main Nov 5, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/671-forward-timings branch November 5, 2026 16:40
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

683 - Partially compliant

Compliant requirements:

  • The ORT runner gets a KV cache (the decode step no longer re-runs the whole sequence)
  • An AMD-protocol benchmark mode that reproduces model_benchmark's stages and units
  • onnx/bench_npu_serve.py

Non-compliant requirements:

  • onnx/build_ort.sh for our own ORT build
  • NOTICE and docs updates

Requires further human verification:

  • Verification that the build_ort.sh script is correctly implemented and functional
  • Confirmation that all documentation has been updated to reflect the new ORT build and benchmark mode

671 - Partially compliant

Compliant requirements:

  • Load Ryzen AI OGA NPU model packs on Linux through the engine
  • Parse quantized weights into Q4NX container with layout-version field
  • Self-check dequantises sampled tensors against reference values bit for bit
  • Generate per-shape full ELFs for the pack model's geometry
  • Gates on the first pack (Qwen2.5-0.5B-Instruct npu_4K) with greedy output identical to vendor stack
  • Side-by-side performance comparison with vendor stack

Non-compliant requirements:

  • A second pack of a different family from the public collection

Requires further human verification:

  • Verification that the second pack functionality is implemented
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing prompt_ms in timings

The PR removes the derived rate from the timings object but fails to ensure that prompt_ms is properly initialized or set in the CallStats structure. This could lead to undefined behavior or incorrect benchmarking results if the prompt_ms field is not correctly populated before being used in the timings_json function.

auto timings_json = [](const CallStats& st) {
    return json{{"prompt_ms", st.prompt_ms}, {"predicted_ms", st.predicted_ms}};
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant