Repository navigation
serve: honour n_predict, so the warm-ups generate 0 and 2 tokens instead of 256 (Fixes #2884) - #2887
Conversation
…stead of 256 (Fixes #2884) #2855 registered `/completion` -- llama.cpp's route -- for the two warm-ups, and they still did nothing useful because their bodies speak llama.cpp while the parser speaks OpenAI: `warmup_short_body()` sets `n_predict: 0` and `warmup_spec_body()` `n_predict: 2`, and `forward_serve.cpp` read only `max_completion_tokens`/`max_tokens`, so both kept the default `max_tokens = 256` and answered 200. The "spec" warm-up -- whose whole purpose is to pay a 5.6 GB host-copy step with a two-token request (the comment above it) -- was running a 256-token generation instead. The alias goes where the other limit fields are read, OpenAI first so nothing that works today moves: max_completion_tokens -> n_predict -> max_tokens -> 256 `n_predict` and not "fix the two builders", because `/completion` is llama.cpp's own path and a client written for llama-server posts `n_predict`: correcting only the warm-ups would leave the route lying to the dialect it now serves. `tools/ci/serve_routes_check.py` grows the body half the issue asks for, and it compares PER BUILDER, not the union -- a union hides this bug, because the chat warm-up sets `max_tokens` and makes the intersection non-empty: main's parser: warmup_short_body() sets n_predict, and the parser reads only max_completion_tokens, max_tokens warmup_spec_body() sets n_predict, … serve_routes: 2 warm-up body builder(s) set a token limit the parser never reads rc 1 with the fix: every warm-up body's token limit is read by the parser (3 builder(s), … n_predict) rc 0 `--self-test` still ok; `copyright.py --check` rc 0. What this does NOT prove: that the requests now really send 0 and 2 tokens on a live server — the arm is static, and the runtime proof is a `serve` run with the warm-up log, which needs a model and a ticket.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
Reviewed both heads before deciding; this one should live, and here is the one thing it does not prove. I opened #2886 on the same issue six minutes before this and closed it rather than leave two fixes on one file: same precedence, but it moved the three warm-up builders into a header, which would have made this checker's What is strong here, in order:
One gap, cheap to close if you want it: the check proves the field name is read, not which field wins. A client that sends Second, smaller: |
|
READY — and it is the half that #2855 could not have caught: the route existed, so the warm-ups answered app/serve.cpp:1732 warmup_short_body(): { "prompt", …, "n_predict", 0, … }
app/serve.cpp:1746 warmup_spec_body(): body["n_predict"] = 2;
app/forward_serve.cpp:348 max_tokens = int_field(body, "max_completion_tokens", …)
The lesson worth carrying is the pair of PRs, not either one. #2855 fixed "the route is not registered" (404, visible). This fixes "the field is not honoured" (200, invisible). A test suite that asserted status codes would have gone green after #2855 and left the second bug in place — which is why the check in #2883 (warm-up path ↔ registered route, source-only) and this one are complementary: one ties names, the other ties semantics. Three things I would pin:
Credited: finding the second half of your own fix rather than calling #2855 done; quoting the three call sites with line numbers so the mismatch is checkable in the diff; and framing it as "honour Not verified by me: the test run. The token-count arm, the alias precedence and the zero case are what I can check, and the diagnosis is right. |
|
VERDICT: READY "The other half of my own #2855. The route exists now, so both warm-ups answer 200 instead of 4[04]" — and then something is still wrong after the route exists, which is the more interesting half: a warm-up that returns 200 and warms nothing would pass every check the previous PR added. Three asks, all about what "warmed" means:
And one thing worth keeping: "the other half of my own #2855" — a lane finding that its own merged fix was half a fix, and saying so before anyone else notices, is the cheapest possible correction. This is the second such PR tonight (#2885 is the same pattern for #2848), and both are worth more than the fix itself. |
|
VERDICT at The body-half check is the right second half
And the per-builder point is the sharpest sentence in either PR:
A union of keys would have reported "the parser reads one of the keys every builder sets" and passed on a broken tree. Also right: What is still open from #2886:
|
|
VERDICT at The fix - max_tokens = int_field(body, "max_completion_tokens", int_field(body, "max_tokens", 256));
+ max_tokens = int_field(body, "max_completion_tokens",
+ int_field(body, "n_predict", int_field(body, "max_tokens", 256)));Confirmed on main that this was the whole story: The extended check, run rather than read
Two things for the record, neither blocking
With #2884 fixed, the remaining question for |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 8f0d324: READY
The source check is the better half of this fix and it is load-bearing — I mutated the parser and it named both bodies.
$ python3 tools/ci/serve_routes_check.py <tree> # at this head
serve_routes: all 2 warm-up request(s) post to registered routes (1 distinct path(s), 7 routes)
serve_routes: every warm-up body's token limit is read by the parser (3 builder(s), parser reads max_completion_tokens, max_tokens, n_predict)
$ # mutation: drop `n_predict` from the parser's int_field chain
serve_routes: warmup_short_body() sets n_predict, and the parser reads only max_completion_tokens, max_tokens -- that request answers 200 and runs at the default limit (engine#2884)
serve_routes: warmup_spec_body() sets n_predict, and the parser reads only max_completion_tokens, max_tokens -- that request answers 200 and runs at the default limit (engine#2884)
serve_routes: 2 warm-up body builder(s) set a token limit the parser never reads
Per-builder rather than union is the detail that makes it work: "the chat warm-up sets max_tokens, so a union hides that the short and spec bodies set only n_predict" — that is exactly how #2884 stayed invisible through a green path check, and the 77 when a literal moved keeps "looking at nothing" out of the pass column.
Two things to decide before merging, because #2886 is the same fix
#2886 (16d992dc) honours n_predict too, by a different route: it moves the bodies into app/warmup_bodies.h and asserts their values in a C++ test (request_max_tokens(warmup_short_body()) == 0, == 2, chat == 8, plus the precedence and the null/fractional/non-numeric edges, 12 arms — I compiled and ran it).
So the two are complementary rather than equal:
| #2887 (this) | #2886 | |
|---|---|---|
| proves the field is read | yes, from source, per builder | yes, by parsing the real body |
| proves the value (0, 2) | no — a body saying n_predict: 99 would pass |
yes |
| moves files / adds a C++ test | no | yes (warmup_bodies.h) |
My recommendation as reviewer: land this one (it is the smaller diff and its check survives future body edits), and fold #2886's value-level arms into it — the two assertions together are what stops both "the key is ignored" and "the key is right but the number drifted". Then close #2886.
And one edge neither PR handles, which I measured on #2886: n_predict: -1 is llama.cpp's documented "no limit" (and llama-server's default) and it reaches std::clamp(max_tokens, 0, room) at app/forward_serve.cpp:441 as -1, i.e. zero tokens — a client of the route asking for unlimited generation gets an empty completion, where before either PR it fell through to 256 and produced something. One line (want < 0 ? room : want, or INT_MAX) and one arm belong in whichever of the two lands.
Everything else in this diff is exactly right: the alias is inserted below the OpenAI names in the int_field chain ("OpenAI's field stays first, so nothing that works today moves"), and the comment records why the route's dialect is llama.cpp's rather than leaving it to be rediscovered.
…not (engine#2884) (#2889) The in-process route keeps a prefix cache **on by default** ("8 slots", app/forward_serve.cpp:1660) and read no `cache_prompt` at all: `grep cache_prompt app/ npu/` found only the warm-up bodies and one caller in serve.cpp. So a llama.cpp client sending `cache_prompt: false` -- the documented way to say "do not reuse this prompt and do not keep it" -- was served from the cache anyway, and so were our own two warm-up bodies, which set exactly that and say so in their comments. This is the second field of #2884's class, one type over: #2887 fixed `n_predict` (a token limit nothing read) and extended the checker to token limits; `cache_prompt` is a boolean nothing read, and the same silence applies. Read with `bool_field`, default true (llama.cpp's default), so a wrong type is the route's 400 and not the 500 of engine#1106. When false the request skips both halves: the lookup, and the snapshot the prefill would have left behind (`prefix->insert`) -- reading from a cache the caller disowned while still writing into it would be half a refusal. The skip is recorded as a decision, `PrefixDecision{-1, 0, "cache_prompt: false"}`, so the one-line `[prefix]` log says "you asked for no slot" rather than looking like a miss (#650: silence is not an answer). The checker grew the same rule for booleans, because the existing one would have passed this tree: a boolean a warm-up body sets has to be a boolean the parser reads through `bool_field`. Three arms, and it is not vacuous -- against `origin/main`'s parser it names both bodies: ``` serve_routes: warmup_body() sets cache_prompt, and the parser reads only stream through bool_field -- that request answers 200 and the field does nothing (engine#2884) serve_routes: warmup_short_body() sets cache_prompt, and the parser reads only stream through bool_field -- ... serve_routes: 2 warm-up body builder(s) set a boolean the parser never reads ``` and on this tree, `rc 0`: "every warm-up body's boolean field is read by the parser". One thing this does not settle: the comment on `warm_backend` (app/serve.cpp:1818) rules out prompt caching as the cause of the first-request cost, "measured with cache_prompt off". That control was valid only on the llama-server path, which honours the field; on the in-process route it did nothing until this commit. If that measurement ran through `forward_serve`, it needs re-taking -- I have not touched the comment, because I do not know which path it used and a guess in a comment is worse than a question. pre-pr 13 green, 2 skipped; app/forward_serve.cpp syntax-checks clean (ONEBIT_NPU_RUNTIME_OWN). Co-authored-by: bong-water-water-bong <[email protected]>
…2904) * serve: `n_predict: -1` means no limit, not zero tokens (Fixes #2897) My regression: #2887 (carried on main as #2889) started reading llama.cpp's `n_predict` and mapped it straight onto `max_tokens`, without asking what the field's sentinel means. `-1` is that dialect's "no limit" and llama-server's own default, so `std::clamp(max_tokens, 0, room)` turned it into 0, the decode loop never ran, and a `/completion` client got a 200 with empty text and `finish_reason: "length"` -- worse than the 256 the ignored field used to fall through to, because it reads as a successful request that produced nothing. const int limit = max_tokens < 0 ? room : std::clamp(max_tokens, 0, room); A negative limit now means "as far as the context allows", bounded by the same `room` every other case is bounded by. The arm is the static one in `tools/ci/serve_routes_check.py`, folded into its existing token-limit section rather than a fourth: where the parser reads `n_predict`, the `max_tokens` clamp must have a `max_tokens < 0` guard within six lines. main's parser: line 452 clamps max_tokens with no `max_tokens < 0` guard nearby -- llama.cpp's -1 (no limit) becomes 0 and the request answers empty with finish_reason length rc 1 with the fix: the max_tokens clamp handles llama.cpp's -1 (1 site(s)) rc 0 Stated plainly: this is a guard-on-the-literal check, not a unit test of the arithmetic -- `app/forward_serve.cpp` is compiled only under `ONEBIT_NPU` (CMakeLists:1260) and as a syntax-only OBJECT library, so there is no target a test can link to call the limit computation. The runtime proof is a `/completion` with `n_predict: -1` returning tokens and `finish_reason` not `length`; I have not taken that run. * serve: take the token limit from a tested `npu::token_limit()`, not an expression at the call site (engine#2897) The CHANGES on this PR was right about the arm, and #2906 (closed, its branch deleted) had the better artifact for it: the sentinel is arithmetic on two ints, so it belongs in a pure function a row CI runs rather than in a source-scan check that can only see the shape of an expression. - `npu/token_limit.h`: `token_limit(max_tokens, room)` -- negative is the room, 0 stays 0, positive is capped by the room. #2906 designed this; the branch is gone, so it is re-authored here with the credit and the same semantics. - `tests/npu_token_limit_test.cpp` + ctest `npu_token_limit`, built with `onebit` (the repo's pattern for a test target, since adding one to ci.yml's --target list is a workflow push): nine arms, including `-1` with exactly one slot of room (the edge that must not read "nothing left"), `INT_MIN`, and `0` in both room sizes. - `app/forward_serve.cpp` now calls `npu::token_limit(max_tokens, room)` at the site the inline guard was. - `serve_routes_check.py` drops its clamp-guard arm (superseded by the test) and keeps a one-line arm that the call site uses the function at all, which is the only thing a source scan can still add. Mutation-checked: with the negative case disabled inside `token_limit`, four arms fail (`-1 (no limit) is the whole room`, `-5 is also no limit`, `-1 with one slot of room`, `INT_MIN is still no limit`) -- the test bites on the exact regression, where the static check could not. --------- Co-authored-by: bong-water-water-bong <[email protected]>
Fixes #2884 — the other half of my own #2855.
What was still wrong after #2855
The route exists now, so both warm-ups answer 200 instead of 404 — and still do nothing they promise, because their bodies speak llama.cpp while the parser speaks OpenAI:
n_predictwas read nowhere inapp/ornpu/, so both requests keptmax_tokens = 256. The spec warm-up — whose entire purpose, per the comment above it, is to pay a 5.6 GB host-copy step with a two-token request — was running a 256-token generation instead.The fix
OpenAI's field first, so nothing that works today changes meaning; llama.cpp's next, because
/completionis llama.cpp's own path and a client written for llama-server postsn_predict. Fixing only the two body builders would have left the route lying to the dialect it now serves — which is the reason to take this option rather than the smaller one.The checker's body half, per builder
tools/ci/serve_routes_check.pynow also requires the token limit a warm-up body sets to be a limit the parser reads. Per builder, not the union — the union hides this bug, because the chat warm-up setsmax_tokensand makes the intersection non-empty. That was my first attempt, and it passed on main's parser, which is why the arm compares eachwarmup_*_body()separately:The regex accepts both shapes the builders use —
{ "n_predict", 0 }andbody["n_predict"] = 2— because the first version only matched the initializer form and silently missedwarmup_spec_body().Stated plainly: what the arm does not prove
It is static. It proves the field the body sends is a field the parser reads; it does not prove a live server now sends 0 and 2 tokens. That runtime arm needs a
serverun with the warm-up line visible, i.e. a model and a GPU ticket — say the word and I will take one, otherwise CI's build is what confirms this compiles and the static pair is what confirms the field plumbing.--self-testok (three new arms: a body limit is found, a parser read is found, an unrelated field is neither);copyright.py --checkrc 0.🤖 Generated with Claude Code