Repository navigation
onnx: bench_npu_serve.py can measure a container whose chat route is disabled - #1140
Conversation
…disabled The harness that reproduces AMD's model_benchmark layout drove /v1/chat/completions only, so a container with no ChatML tokens -- which the chat route refuses by design (#963) -- had no AMD-unit number at all. --endpoint completions sends the prompt to /v1/completions, which renders no template (#938) and reports the same usage/timings. Default stays chat, so earlier rows stand. Also: count a chunk's `text` in stream mode (the completions chunk shape), and report a refusing server's body instead of raising HTTPError, since that body is what names the route to use. closes #1125
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY (one nit, one note about a deliberate deviation from the issue's suggested shape)
I drove the harness against a stand-in server I wrote (not yours), so the wiring is checked by what it actually put on the wire, in all three combinations:
=== chat default (json) rc=0 path=/v1/chat/completions
keys=[max_tokens, messages, model, stream, temperature] messages=True prompt=False
=== completions (json) rc=0 path=/v1/completions
keys=[max_tokens, model, prompt, stream, temperature] messages=False prompt=True
Number of Tokens: 69 <- from usage.prompt_tokens, not from the prompt text
=== completions (stream) rc=0 path=/v1/completions stream_options={include_usage:true}
Token generation: … n: 7 * 1 token(s) <- so `choices[0].text` is counted; without the new line this fails
=== chat (stream) rc=0 path=/v1/chat/completions, one delta per token, unchanged
The default really is unchanged: for chat the body is the same mapping in the same order ({"model": …, "messages": …, "max_tokens": …, …}) and the URL is untouched — I diffed the request the stub received, not the source.
The 400 path is better than the issue asked for, and I measured the truncation rather than eyeballing it: the real refusal body is 292 bytes, the cut is at 300, and send /v1/completions starts at byte 201 of it — so the actionable half survives, and rc=1 with no traceback:
HTTP 400 from http://127.0.0.1:18183/v1/chat/completions: {"error": {"message": "bad request: this container's
tokenizer has no <|im_start|> / <|im_end|>, … send /v1/completions with prompt as token ids (#938) …"}}
The engine side matches the three shapes the harness now relies on, read at this head: /v1/completions takes a string prompt (app/forward_serve.cpp:186), the non-stream reply carries choices[0].text (:529) with usage (:531) and timings (:532), and the stream chunk for the non-chat route is {"choices":[{"index":0,"text":…}]} (:572) with usage in the tail (:611) — which is exactly the choice.get("text") the counter now accepts. py_compile clean, tools/copyright.py --check rc 0, no new file.
Nit — the new switch is not reachable from the wrapper that operators actually run. onnx/bench_npu.sh forwards a whitelist of bench flags and rejects everything else before it touches the device:
$ onnx/bench_npu.sh --endpoint completions
bench_npu.sh: unknown option --endpoint (exit 2, from the `*)` arm at :62)
so a chat-disabled container measured through the wrapper still gets the 400 — the fix is reachable only by calling the python directly. One word in the --lens|--gen|-w|--warmup|-r|--repeat|--mode arm (plus the row in the script's own usage block sed -n '2,30p') keeps the two entry points aligned. It fails loudly rather than silently, so it is a nit and not a blocker.
Note, for the record rather than as a complaint: #1125's suggested shape sends the prompt as token ids, and this sends text. The reason is argued in the body and I think it is the right call for this harness — it carries no tokenizer, the route tokenizes with the container's own, the count comes back in usage (the same rule the chat path already followed), and the ids form would need a tokenizer the tool does not have. What it does not give you is #938's parity property (ids skip tokenization, so two engines compare the forward); anyone wanting a parities row still has to run the ids form from the gate-(c) scripts. Worth one line in the --endpoint help so nobody reads text-mode rows as #938-parity rows.
Not run by me: your leg 2 (the Llama-3.2 container under forward-serve in host-GEMM mode). It needs your build, and I would not start a serve on this box for a plumbing check — the two legs above are enough to prove the change, and the row's rate is explicitly not a speed claim.
CI at this head: Analyze (actions/python/javascript-typescript) success, Analyze (c-cpp), Analyze (rust) and build still in progress, hw_gate skipped, pr_agent queued — so BLOCKED here is checks-not-finished, not a red.
…s not a #938 parity row Review nit fixed where it bites: bench_npu.sh whitelists bench flags and rejected --endpoint before it touched the device (exit 2, '"*)' arm), so the new switch was reachable only by calling the python directly. The usage block gains the example. Also records in --endpoint's help the reviewer's note: text is tokenized server-side, so a completions row is not #938 parity -- that needs ids, which the gate (c) scripts send and this harness cannot without a tokenizer.
|
Nit fixed at Your note is now in the |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 5959fa1a — both nits closed, and the forwarding is proven by running the wrapper, not by reading the case arm
Nit 1 (wrapper): --endpoint is now in the forward arm, and I drove the whole wrapper to see it arrive at the harness. A stub engine binary that answers /v1/health and /v1/models, a python3 earlier on PATH that records its argv:
$ ONEBIT_BIN=<stub> ONEBIT_DX_KERNELS=<kern> ONEBIT_MODEL=<model> onnx/bench_npu.sh --endpoint completions --lens 64 --gen 8
INVOKED: -u onnx/bench_npu_serve.py --host 127.0.0.1:52625 --model --endpoint completions --lens 64 --gen 8
So the container this PR exists for is now measurable through the wrapper, not only by calling the python directly. Two things I checked around it, because they are what a whitelist edit can break: --endpointx is still refused (bench_npu.sh: unknown option --endpointx, exit 2 — the arm is precise, not a wildcard), and bash -n + shellcheck -S warning are clean. The empty --model above is my stub's /v1/models parser being captured by the same fake python3, not the wrapper.
(Side observation, not a finding: the wrapper's "something already answers on port N; refusing to measure it" guard fired at me twice while I built that stub. It is correct and it is the kind of guard that stops a benchmark measuring another lane's server.)
Nit 2 (the parity note): the --endpoint help now carries it, printed by --help, at the point where someone deciding which endpoint to use will read it — "text is tokenized by the server, so a completions row is not a #938 parity row". That was the whole ask, and it is where the wrong conclusion would otherwise be drawn.
Nothing else moved. The python diff is that help string only, so my earlier evidence still describes this head, and I re-ran it to be sure: chat default unchanged (messages, no prompt, /v1/chat/completions), completions sends prompt and no messages to /v1/completions, and stream mode still counts the chunks.
CI at this head: CodeQL + all five Analyze success, build in progress, hw_gate skipped, MERGEABLE/BEHIND.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
onnx/bench_npu_serve.pyis the only thing in the tree that reproduces AMD'smodel_benchmarklayout (promptprocessing / token generation / E2E) from a server's own stream, and it drove
/v1/chat/completionsonly. A containerwhose chat route is deliberately disabled therefore had no number in AMD's units at all — not a slow row, an
unmeasurable one.
Root cause
The chat route refuses, on purpose and correctly, when the tokenizer has no ChatML tokens (#963):
The gap is on the harness side, not in the refusal:
/v1/completionsserves such a container (app/forward_serve.cpprenders nothing on that path, and the reply carries the same
timings.prompt_ms/timings.predicted_msandusage),but the harness had no way to send it there. So the Llama-3.2-1B pack container — the family this engine's docs point at
/v1/completionsfor — could be measured for correctness (gate (a)/(b)) and not for speed in AMD's units.The change
--endpoint {chat,completions}, defaultchat:chat— unchanged body and URL, so every row taken before this switch stays reproducible;completions—{"prompt": <text>, "max_tokens": ...}against/v1/completions, no template rendered. Sent as textrather than token ids because the harness has no tokenizer and needs none: the route tokenizes the prompt with the
container's own tokenizer, and the count used for the rate comes back in
usage(the same rule the chat path follows),so the two endpoints measure the same quantity.
Two lines beyond the switch, both in the same failure path the issue is about:
text, which is the completions chunk shape (forward_serve.cppstreamschoices[0].textthere). Without it,--mode stream --endpoint completionswould count zero tokens and fail with "notokens streamed" instead of reporting a row;
urllibraisesHTTPErroron a 400, and the reason — which isprecisely "send /v1/completions" — lives in the body the traceback discarded. Measured before that line:
Proof
Two legs, neither taking an NPU dispatch.
1. The wiring, against a stand-in server that answers the chat route with the container's own 400 and the completions
route with a
timings+usagereply (throwaway script, no repo file added). Defaultchathits/v1/chat/completionsand reports the refusal;
--endpoint completionshits/v1/completions, sendsprompt(asserted: nomessageskey),and prints the full AMD-layout table with
prompt_tokensread fromusage:2. The container this issue was filed on (
~/ogaload/oga13/ctr-llama-b8, the Llama-3.2-1B pack container inengine#671's gate table),
forward-servein host-GEMM mode on port 18090 — plumbing only, so the rate in this row is nota speed claim (host GEMM on a loaded box; the device row is engine#671's business):
The 69 prompt tokens are the container's own count from
usage(the filler sentence is 13 tokens per repetition), which isthe number the rates are computed from — the same rule the chat path already followed.
python3 -m py_compile onnx/bench_npu_serve.pyclean;tools/copyright.py --checkclean (no new file, the Apache noticeis already on this one); no NPU dispatch, no
:18097, no device lock taken for either leg.closes #1125