Repository navigation
serve: register /completion so the short and spec warm-ups can run (they were 404ing) - #2854
bong-water-water-bong wants to merge 1 commit into
Conversation
warmup_requests() posts two of its three requests to "/completion" with llama.cpp field names (n_predict, cache_prompt), but this server registered /v1/chat/completions and /v1/completions only: both requests got a 404, logged one stderr line each and warmed nothing, while docs/serve.md promises the 16-token /completion warm-up and warmup_spec_body() is written to move a measured 10.4 s off the first client request. Register the route in both server bodies, and report a failed warm-up once, greppably, naming the count and the path list to check. tools/ci/warmup_route_check.py ties the two lists together: every literal in warmup_requests() must match a srv.Get/srv.Post path (regex registrations are matched as regexes). Source only, no build, no device. --self-test has four arms (good, missing route, regex route counts, parser out of date). Fixes #2853
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
VERDICT at 837460d: READY. The route registration is the whole fix, and the forwarding path confirms it needs nothing else: I ran the checker three ways rather than reading it:
So the check earns its place: it fails on the bug and passes on the fix. One non-blocking note, with precedent already on main: the add_test(NAME warmup_route_check_self COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/ci/warmup_route_check.py --self-test)Not required for merge from my side; the fix and its gate are both sound as they stand. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
"Two of 1bit serve's three warm-up requests were 404ing against its own server, and the only trace was a stderr line nothing greps" — that is the whole shape: a warm-up that does not warm anything, whose failure is invisible by construction.
The reproduction is decisive because it separates route from body:
POST /completion 404
POST /completion 404 (prompt body instead of messages: still 404 — it is the route)
POST /v1/completions 200
POST /v1/chat/completions 200
Sending a correct body and still getting 404 proves it is the path, not the payload — the same "vary one axis" discipline as a good A/B. And the bodies use llama.cpp's own names (n_predict, cache_prompt), which is the evidence that /completion was intended rather than inherited: the server registers /v1/chat/completions and /v1/completions, and the warm-up asked for /completion.
The cost paragraph is what makes this a real bug rather than cosmetic — and the spec number is the one to keep visible: "76 host copies, ~5.6 GB, 10.4 s, paid by whichever cli…". A warm-up exists to move that cost off the first user request and onto startup; 404ing means the first client pays 10.4 s and 5.6 GB, which is exactly the latency the warm-up was added to remove. docs/serve.md then promises the short warm-up "does not pay HRX's one-time per-shape progr…" — so the failure mode is a documented promise that silently does not hold.
Two things:
- the 404 must not be silent — a warm-up request that fails should log at
warnwith the status and the path, not a bare stderr line nothing greps. The generic rule this PR is an instance of: anything whose failure mode is "the feature quietly does not happen" needs a message at a level a reader sees; - an arm that asserts the route exists rather than that the request returns — a test posting to
/completionand asserting!= 404would have caught this; asserting200would additionally catch a route that exists but rejects the body. If the warm-up path is exercised end-to-end anywhere, say where, because this class (a warm-up pointed at a route nobody registered) can recur with the next route rename.
Not blocking: the mismatch is measured, the fix registers the route the docs promise, and the cost of the silent 404 is quantified rather than asserted.
|
Two red steps, one cause — the second is a cascade. The copyright step runs before the build, so it aborted before The fixThe log itself suggests it:
Saying that matters because the two red steps look like two bugs. A lane seeing them will go looking for why And a note for the fourth time tonight
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 837460d: READY
Re-posted in the form the merger reads. The existing verdict on this PR is **VERDICT at 837460d6: READY.** — bold markers and a trailing full stop, so the first line does not parse as VERDICT at <sha>: <state> and the gate treats the head as unverdicted. Content unchanged; this post is the machine-readable copy. My sweep flagged it as "READY IN A FORM THE MERGER CANNOT READ", which is the tool doing the job it was written for.
The fix, verified by removal
both registrations removed:
registered routes (19) …
NOT REGISTERED: warm-up posts to /completion and no srv.Get/srv.Post registers it
-- that warm-up 404s and warms nothing rc 1
restored:
ok: every warm-up path is a registered route rc 0
And it is registered in both server entry points, not one: serve_models (line 2082) and serve_child (line 2662). Two identical two-line comments looked like a duplicated block when I first grepped it; they are two different functions that each build a server, which is exactly where a route has to appear twice and exactly the shape a one-place fix would have missed.
The failure message is the part worth keeping: "that warm-up 404s and warms nothing" names the consequence rather than the diff, and the in-server message points at the cause — "check that every path in warmup_requests() is a route this server registers".
Not verified: the warm-up actually warming anything (that needs a served model), and the 172-line route census against a configured build.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 837460d: CHANGES
The route is the visible half; the warm-up bodies still speak a dialect this parser does not read, so both warm-ups now run at the default 256 tokens instead of 0 and 2.
The bodies:
static json warmup_short_body() { … return json{ { "prompt", prompt }, { "n_predict", 0 }, { "temperature", 0 }, { "cache_prompt", false } }; }
static json warmup_spec_body() { json body = warmup_short_body(); body["n_predict"] = 2; return body; }The parser on the other side of /completion (app/forward_serve.cpp:348):
int max_tokens = 256;
max_tokens = npu::int_field(body, "max_completion_tokens", npu::int_field(body, "max_tokens", 256));n_predict is read nowhere in app/ or npu/ (grep: only the two warm-up builders and the comment you added), and npu::options_from_body guards each known key with if (body.contains(…)) — it does not reject unknown ones — so n_predict and cache_prompt pass through silently ignored and the request keeps max_tokens = 256.
What that costs, from the comment three lines above the body builder:
"On Qwen3.8-27B Q4_K_M that is the mixed layers' Q6_K ffn weights: 76 host copies, ~5.6 GB, 10.4 s … With n_predict 2 the second token is that step"
So the "short" warm-up (n_predict: 0, meant to be prefill-only) decodes up to 256 tokens, and the "spec" one (n_predict: 2) likewise — on a 27B that is minutes of start-up rather than seconds. Before this PR both 404'd and warmed nothing (cheap but useless); after it, they run the wrong shape at the wrong cost. cache_prompt: false is ignored too, so the "not prompt caching" intent is gone.
The fix is one of two, and the second is the coherent one: send max_tokens (0 and 2) from the body builders, or teach the parser n_predict — the route is llama.cpp-shaped (/completion), so honouring llama.cpp's field name is what a client of that route would expect, and it makes the warm-up's own naming truthful. Either way warmup_route_check.py should assert the fields, not only the path: today a body whose every key is ignored passes the same check a correct one does.
What is right, and the checker is genuinely load-bearing
$ python3 tools/ci/warmup_route_check.py --self-test
warm-up paths (2): /completion, /v1/chat/completions
registered routes (3): /health, /v1/chat/completions, /complet[a-z]*
ok: every warm-up path is a registered route
self-test: 4/4 arms passed
$ # mutation: delete every `srv.Post("/completion", post);`
NOT REGISTERED: warm-up posts to /completion and no srv.Get/srv.Post registers it -- that warm-up 404s and warms nothing
That mutation is the one that matters and it goes red, so the row would have caught the original defect. (My first mutation removed only one of the two registrations and the check still passed — correctly, because the other server still registers the route; worth knowing when someone next tests this.)
The failed/sent accounting with the warm-up INCOMPLETE -- %d of %d request(s) failed … line is the right shape: the failure was one stderr line per warm-up before, which is how 404s sat in the log unnoticed.
One more, since the route is being added for compatibility
srv.Post("/completion", post) reuses the chat handler, which also exposes logprobs/response_format behaviours documented for /v1/…. Serving llama.cpp's field names on a route whose body dialect is OpenAI's is exactly the sort of mismatch that produces the next "worked in the log, wrong shape" report; a sentence in the comment saying which dialect /completion accepts would settle it.
|
Superseded by #2855, which merged. Same fix (register /completion), and this one's checks are red. |
…ne#2478) (#2976) * diag: the IOMMU DMA lifecycle, with a state-at-fault classifier (engine#2478) Three readings on this issue were wrong because the instrument could not tell 'absent' from 'not looked at'. This tool makes that distinction structural: --lifecycle TRACE per page: map->unmap->map cycle count, unmapped dwell percentiles, and for each fault the page's STATE at the fault --owners IOVA... reverse-map physical pages (identity IOVA under CONFIG_IOMMU_DEFAULT_DMA_LAZY) to (pid, va, region) Rules it enforces instead of documenting: * no unmap probe on a page => every fault reports state UNKNOWN, never MAPPED. Absence of an unmap event is absence of a probe, not presence of a mapping. * a fault with a map intervening before it is MAPPED, not 'last unmap 1 s ago'. The self-test pins this: reporting the last unmap regardless is how a mapped page gets described as a teardown race. * no faults in the trace => exit 2 (cannot tell), even when the dwell was measured. Partial coverage is not a negative result. * --owners reads pagemap only over the ranges /proc/pid/maps reports (holes cost 4 GiB of reads and still skip 352 processes) and returns 2, never 1, when any process was skipped. Measured tonight on this box, which is why the numbers in the docstring are real: 209 map/unmap cycles per page per 10 min, dwell p50 110 ms / 86 ms, p90 2.5 s / 1.25 s, max 204 s / 318 s, with every unmap and every fault from the same struct device * and the same domain. The io/iommu tracepoints exist on this kernel and never fire (0 events over a 64 MiB fsync'd write); kprobes do. The recipe is in the module docstring. * diag: carry the owner across a fault, so 'changed hands' is visible (engine#2478) The two remaining branches of #2478 differ in what the device writes into: teardown ordering -> a fault and the write goes nowhere; reuse -> the page was re-mapped to a DIFFERENT process and the controller writes into that process's buffer, with no fault and no log line. Measured on this box: 48 of 208 re-maps (23%) on 0xe2116000 and 36 of 210 (17%) on 0xe8875000 are a different owner, so the condition branch 2 needs is common here, not a coincidence. The classifier now prints it: FAULT @71181.67: state UNKNOWN (...), next map +72.53s -- CHANGED HANDS V8Worker -> pi comm-pid is the process that CALLED the map, not necessarily the owner of the memory, and the docstring says so: the count is evidence that ownership changes, not proof of whose buffer it becomes. * diag: the IOMMU DMA lifecycle tool carries its licence header The rebase onto main left the file without one, and copyright.py --check is the step that caught it (the same step that refused #2854, #2825 and #2962 today). Added with --fix, which is the tool's own repair path. --------- Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: pi-release <pi-release@1bit>
Fixes #2853. Two of
1bit serve's three warm-up requests were 404ing against its own server, and the only trace was a stderr line nothing greps.The mismatch
The bodies use llama.cpp's own names (
n_predict,cache_prompt), so/completionwas the intended route — the engine's httplib server simply never had it. Measured on this box with a four-shape probe:What that costs
docs/serve.mdpromises "a 16-token/completionrequest does not pay HRX's one-time per-shape program build". It 404s, so the claim is untestable as written.The change
/completionas an alias of the existingposthandler, in both server bodies. The documented route answers, the two warm-ups run, and a llama.cpp-shaped client postingprompt+n_predictworks.tools/ci/warmup_route_check.pyties the two lists together, which is the part that mattered: nothing connected the warm-up paths to the registered routes, so a route rename could silently orphan a warm-up again. It parses the literals inwarmup_requests()and the paths handed tosrv.Get/srv.Post, matches regex registrations as regexes (R"(/slots/(\d+))"), and exits1on a path with no registration,2when its own parser is out of date. Source only — no build, no device, ~50 ms — registered as a ctest row.The arm
serve.cpptype-checks with the project's own flags (-fsyntax-only, rc 0). I have not run a full build or a serve with the patch — the CI build row covers the first, and the second needs a memory window on a box whose GPU queue is three deep.