[PR #4056] [Other] serve: logprobs on /v1/completions (stacks #3332) #4894

Open
opened 2026-11-07 16:31:09 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4056
Author: @gdevenyi
Created: 10/25/2026
Status: 🔄 Open

Base: main ← Head: anyjev-completions-logprobs


📝 Commits (6)

  • e04fe08 serve: add the legacy /v1/completions endpoint
  • 7e08755 fix(serve): restore structured SSE errors and avoid duplicate completion text
  • b6132c9 Merge branch 'pr-3332-v3' into v2-on-main
  • c56ee93 [Engine] serve: logprobs on legacy /v1/completions (vLLM's shape), token-id prompts
  • 78a130b [Docs] DETAILS: logprobs on /v1/completions
  • d032be9 [Other] serve: /v1/completions takes logprobs: false as not asked; a two-request ownership test

📊 Changes

7 files changed (+544 additions, -28 deletions)

View changed files

📝 docs/DETAILS.md (+10 -0)
📝 serve/frontend.py (+12 -0)
📝 serve/server.py (+260 -25)
📝 serve/test_logprobs.py (+111 -0)
📝 serve/test_monitor.py (+17 -0)
📝 serve/test_server.py (+122 -0)
📝 serve/test_structured.py (+12 -3)

📄 Description

Problem and result

Decision clients such as AnyJev render their own chat prompt and read the label tokens' log-probabilities from vllm serve's legacy /v1/completions. Strata 0.2.7 has logprobs on /v1/chat/completions (#3200, landed as 9ea04496), and #3332 adds /v1/completions but refuses logprobs. So a client can have its own prompt or the logprobs, but not both.

This PR puts the 0.2.7 logprobs on #3332's route. /v1/completions takes logprobs: N (or true with top_logprobs), allowed_token_ids and return_tokens_as_token_ids, and the prompt can be a list of token ids. It returns vLLM's legacy logprobs object.

 POST /v1/completions                         (#3332)
   prompt: str
+  prompt: [token ids]                         # vLLM form; one prompt per request
-  logprobs → 400 "logprobs are not supported"
+  logprobs: N | true + top_logprobs           # GEN … logprobs=K, as chat
+  allowed_token_ids: [ids]                    # full-vocabulary values, not renormalised
+  return_tokens_as_token_ids: true            # keys "token_id:<id>"
 → choices[0].logprobs
+    {tokens, token_logprobs, top_logprobs: [{tok: lp}], text_offset}
  • Clients: nokia-applied-research/AnyJev#20 (StrataBackend, which reads this route with allowed_token_ids and return_tokens_as_token_ids) and nokia-applied-research/AnyJev#21 (its HTTP decision gateway, anyjev.serve --backend strata, one gateway per Strata server). The scope discussion on the AnyJev side is nokia-applied-research/AnyJev#22.
  • Depends on #3332 only. This branch is main (46c152a1, after 0.2.7.1) + #3332 merged unchanged (clean merge) + three commits, b6132c9a..d032be99 (+216/−20 in serve/server.py, serve/test_logprobs.py, docs/DETAILS.md). When #3332 lands, it is just these commits.
  • #3200 shipped in 0.2.7, so the stacking on it is gone. This branch was rebased onto main instead of re-merging #3200's branch.
  • Originating request: #675. Related: #3743 (a scored typed-decision endpoint; this PR gives existing vLLM-style decision clients the field they already read). Repeatability: #4059.

Approach

  • The same rules as chat, in one place. check_logprobs(req, svc, max_req) holds 0.2.7's two checks, now shared by both routes:
    • --parallel refuses logprobs unless max_tokens is 1.
    • A named id outside the vocabulary is a 400.
    • Like 0.2.7, there is no length cap of its own (@xiezhipeng-git's point on #3200: one way, said in the text). The earlier 1..4096 bound is gone from this branch.
  • CompletionLogprobs. It reads only the LP lines tagged with this request's cancel Event, the ownership rule 0.2.7's LogprobEntries uses. That includes the lines a batch admission keeps on the Event (_strata_lp_lines). It lists every generated token, the stop token too, so a one-token read whose top token is <|im_end|> still has its row.
  • No renormalising. allowed_token_ids reports the named ids' full-vocabulary values. For those ids these are the numbers vLLM's default raw_logprobs gives. A decision client checks how much of the mass its labels hold, and renormalised values always sum to 1. Chat keeps 0.2.7's renormalised shape. Both are documented in docs/DETAILS.md.
  • One limit of this route: logprobs with stream: true are refused (400) to keep the change small.
  • Compatibility. No engine change. Requests that don't ask for logprobs are unchanged.

Validation

d032be99, engine 0.1.53 built from this branch, with Qwen3.8-Flash-Next IQ3_S and the args strata launch writes (--expert-cache auto --prefill auto --spec 4 --spec-min-p 0.5 --mtp … --kv int8 --ple-io ram --kv-resident 32768, no --vision). Two machines:

epic monster
GPU RTX 5080 16 GB, sm_120 GTX 1080 Ti 11 GB, sm_61
Build CUDA 13.4 CUDA 12.9, -DSTRATA_EXPERIMENTAL_SM60=ON, g++-14
OS Linux Linux (CachyOS)

Passed:

  • python -m unittest discover -s serve -p 'test_*.py' (as CI runs it): 1,234 tests, 2 failures.
    • GpuChoice.test_hip_ordinal fails on main here too.
    • LiveRate.test_the_live_number_is_a_rate failed once while the machine was under memory pressure; it passes 3/3 on this branch and on main when re-run.
  • serve.test_logprobs: 41 OK. That is main's tests plus 11 for completions:
    • the legacy shape, the chat form of the field, echo offsets;
    • un-renormalised allowed_token_ids, token-id keys, token-id prompts;
    • logprobs: false, no length cap, the refusals;
    • two overlapping requests that each read only their own LP lines.
  • Hardware, 12 checks on both machines:
    • chat logprobs, streamed and not, with no max_tokens and with a json_schema;
    • completions shape, allowed_token_ids raw values equal to the top-K read, token-id prompt, max_tokens: 0, logprobs: false;
    • the stream refusal.
    • With --adapt-swaps 0 and STRATA_PREFILL_CPU_SHARE=0.5: 12/12 on both. Chat, text-prompt completions and token-id completions give the same values to 6 decimals (epic B −0.027356, monster −0.035613).
    • With the launch defaults: 11/12 on both. The one miss is that chat-vs-completions value comparison, because reads drift between requests there (#4059), not because the routes differ.
  • --parallel 2 on epic: completions max_tokens: 1 with allowed_token_ids → 200 with both ids. max_tokens: 2 → 400 naming --parallel. Two overlapping one-token reads (fruit/vegetable) each returned their own answer (B, A) through batch admission.
  • AnyJev's StrataBackend (nokia-applied-research/AnyJev#20), on epic with --adapt-swaps 0 and STRATA_PREFILL_CPU_SHARE=0.5: engine smoke test 7/7. Its parity check (named-id read vs the server's own top-20) gives max_abs_diff 0.000000 in two runs, and the Decider at L0 decides 5 states × 3 questions in 14 s.

Failed:

  • None beyond the pre-existing test_hip_ordinal.

Not run:

  • HIP, SYCL and Metal builds. No C++ changes here, but this route ran on CUDA only.
  • --parallel on monster (11 GB).
  • The full suite on Windows.

Limits

  • Repeatability is the engine's (#4059). With the launch defaults, identical requests drift by a few hundredths of a nat. --adapt-swaps 0 --pcie-frac 0 with STRATA_PREFILL_CPU_SHARE=0.5 makes them identical, the first run after a start included. Without --pcie-frac 0 that first run still differs. The recipe costs about 38% of decode speed on an RTX 5080 (none for one-token reads); the measurements are on #4059.
  • One prompt per request (no batched prompt: [[…], […]]). AnyJev's Tacit(engine="server") client batches, so it still needs its own path; its Decider backend (nokia-applied-research/AnyJev#20) sends one prompt per request.
  • Logprobs are not streamed on this route.

Merge danger

Door: two-way. It is server-only Python behind an opt-in request field.

Blast radius: small. Callers of /v1/completions that send logprobs used to get a 400 and now get logprobs. Chat logprobs go through the moved, otherwise unchanged checks.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Cix1XJhNhNNuKXi26KvXnU


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4056 **Author:** [@gdevenyi](https://github.com/gdevenyi) **Created:** 10/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `anyjev-completions-logprobs` --- ### 📝 Commits (6) - [`e04fe08`](https://github.com/Niko1221/Strata/commit/e04fe08b681f160e82e252c875b065c0fb6f44ef) serve: add the legacy /v1/completions endpoint - [`7e08755`](https://github.com/Niko1221/Strata/commit/7e08755f0f0239b7db7305b1fad7cc137a454f24) fix(serve): restore structured SSE errors and avoid duplicate completion text - [`b6132c9`](https://github.com/Niko1221/Strata/commit/b6132c9a4beec0218530ffbd146c1a982eeef6cd) Merge branch 'pr-3332-v3' into v2-on-main - [`c56ee93`](https://github.com/Niko1221/Strata/commit/c56ee93ce74efb64e4d8300f7d03f54bff018084) [Engine] serve: logprobs on legacy /v1/completions (vLLM's shape), token-id prompts - [`78a130b`](https://github.com/Niko1221/Strata/commit/78a130b241ecbc902a6381ce6d948c31bd576c74) [Docs] DETAILS: logprobs on /v1/completions - [`d032be9`](https://github.com/Niko1221/Strata/commit/d032be99e2b8cd0c9d34434560c3a613aab26e32) [Other] serve: /v1/completions takes logprobs: false as not asked; a two-request ownership test ### 📊 Changes **7 files changed** (+544 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+10 -0) 📝 `serve/frontend.py` (+12 -0) 📝 `serve/server.py` (+260 -25) 📝 `serve/test_logprobs.py` (+111 -0) 📝 `serve/test_monitor.py` (+17 -0) 📝 `serve/test_server.py` (+122 -0) 📝 `serve/test_structured.py` (+12 -3) </details> ### 📄 Description ## Problem and result Decision clients such as AnyJev render their own chat prompt and read the label tokens' log-probabilities from `vllm serve`'s legacy `/v1/completions`. Strata 0.2.7 has logprobs on `/v1/chat/completions` (#3200, landed as `9ea04496`), and #3332 adds `/v1/completions` but refuses `logprobs`. So a client can have its own prompt or the logprobs, but not both. This PR puts the 0.2.7 logprobs on #3332's route. `/v1/completions` takes `logprobs: N` (or `true` with `top_logprobs`), `allowed_token_ids` and `return_tokens_as_token_ids`, and the prompt can be a list of token ids. It returns vLLM's legacy `logprobs` object. ```diff POST /v1/completions (#3332) prompt: str + prompt: [token ids] # vLLM form; one prompt per request - logprobs → 400 "logprobs are not supported" + logprobs: N | true + top_logprobs # GEN … logprobs=K, as chat + allowed_token_ids: [ids] # full-vocabulary values, not renormalised + return_tokens_as_token_ids: true # keys "token_id:<id>" → choices[0].logprobs + {tokens, token_logprobs, top_logprobs: [{tok: lp}], text_offset} ``` ## Related discussion - **Clients:** nokia-applied-research/AnyJev#20 (`StrataBackend`, which reads this route with `allowed_token_ids` and `return_tokens_as_token_ids`) and nokia-applied-research/AnyJev#21 (its HTTP decision gateway, `anyjev.serve --backend strata`, one gateway per Strata server). The scope discussion on the AnyJev side is nokia-applied-research/AnyJev#22. - **Depends on #3332 only.** This branch is `main` (`46c152a1`, after 0.2.7.1) + #3332 merged unchanged (clean merge) + three commits, `b6132c9a..d032be99` (+216/−20 in `serve/server.py`, `serve/test_logprobs.py`, `docs/DETAILS.md`). When #3332 lands, it is just these commits. - #3200 shipped in 0.2.7, so the stacking on it is gone. This branch was rebased onto `main` instead of re-merging #3200's branch. - Originating request: #675. Related: #3743 (a scored typed-decision endpoint; this PR gives existing vLLM-style decision clients the field they already read). Repeatability: #4059. ## Approach - **The same rules as chat, in one place.** `check_logprobs(req, svc, max_req)` holds 0.2.7's two checks, now shared by both routes: - `--parallel` refuses logprobs unless `max_tokens` is 1. - A named id outside the vocabulary is a 400. - Like 0.2.7, there is no length cap of its own (@xiezhipeng-git's point on #3200: one way, said in the text). The earlier 1..4096 bound is gone from this branch. - **`CompletionLogprobs`.** It reads only the LP lines tagged with this request's cancel `Event`, the ownership rule 0.2.7's `LogprobEntries` uses. That includes the lines a batch admission keeps on the `Event` (`_strata_lp_lines`). It lists **every** generated token, the stop token too, so a one-token read whose top token is `<|im_end|>` still has its row. - **No renormalising.** `allowed_token_ids` reports the named ids' full-vocabulary values. For those ids these are the numbers vLLM's default `raw_logprobs` gives. A decision client checks how much of the mass its labels hold, and renormalised values always sum to 1. Chat keeps 0.2.7's renormalised shape. Both are documented in `docs/DETAILS.md`. - **One limit of this route:** logprobs with `stream: true` are refused (400) to keep the change small. - **Compatibility.** No engine change. Requests that don't ask for logprobs are unchanged. ## Validation `d032be99`, engine 0.1.53 built from this branch, with Qwen3.8-Flash-Next IQ3_S and the args `strata launch` writes (`--expert-cache auto --prefill auto --spec 4 --spec-min-p 0.5 --mtp … --kv int8 --ple-io ram --kv-resident 32768`, no `--vision`). Two machines: | | epic | monster | |---|---|---| | GPU | RTX 5080 16 GB, sm_120 | GTX 1080 Ti 11 GB, sm_61 | | Build | CUDA 13.4 | CUDA 12.9, `-DSTRATA_EXPERIMENTAL_SM60=ON`, `g++-14` | | OS | Linux | Linux (CachyOS) | **Passed:** - `python -m unittest discover -s serve -p 'test_*.py'` (as CI runs it): 1,234 tests, 2 failures. - `GpuChoice.test_hip_ordinal` fails on `main` here too. - `LiveRate.test_the_live_number_is_a_rate` failed once while the machine was under memory pressure; it passes 3/3 on this branch and on `main` when re-run. - `serve.test_logprobs`: 41 OK. That is main's tests plus 11 for completions: - the legacy shape, the chat form of the field, echo offsets; - un-renormalised `allowed_token_ids`, token-id keys, token-id prompts; - `logprobs: false`, no length cap, the refusals; - two overlapping requests that each read only their own LP lines. - Hardware, 12 checks on both machines: - chat logprobs, streamed and not, with no `max_tokens` and with a `json_schema`; - completions shape, `allowed_token_ids` raw values equal to the top-K read, token-id prompt, `max_tokens: 0`, `logprobs: false`; - the stream refusal. - With `--adapt-swaps 0` and `STRATA_PREFILL_CPU_SHARE=0.5`: 12/12 on both. Chat, text-prompt completions and token-id completions give the same values to 6 decimals (epic `B` −0.027356, monster −0.035613). - With the launch defaults: 11/12 on both. The one miss is that chat-vs-completions value comparison, because reads drift between requests there (#4059), not because the routes differ. - `--parallel 2` on epic: completions `max_tokens: 1` with `allowed_token_ids` → 200 with both ids. `max_tokens: 2` → 400 naming `--parallel`. Two overlapping one-token reads (fruit/vegetable) each returned their own answer (`B`, `A`) through batch admission. - AnyJev's `StrataBackend` (nokia-applied-research/AnyJev#20), on epic with `--adapt-swaps 0` and `STRATA_PREFILL_CPU_SHARE=0.5`: engine smoke test 7/7. Its parity check (named-id read vs the server's own top-20) gives `max_abs_diff 0.000000` in two runs, and the `Decider` at L0 decides 5 states × 3 questions in 14 s. **Failed:** - None beyond the pre-existing `test_hip_ordinal`. **Not run:** - HIP, SYCL and Metal builds. No C++ changes here, but this route ran on CUDA only. - `--parallel` on monster (11 GB). - The full suite on Windows. ## Limits - **Repeatability is the engine's (#4059).** With the launch defaults, identical requests drift by a few hundredths of a nat. `--adapt-swaps 0 --pcie-frac 0` with `STRATA_PREFILL_CPU_SHARE=0.5` makes them identical, the first run after a start included. Without `--pcie-frac 0` that first run still differs. The recipe costs about 38% of decode speed on an RTX 5080 (none for one-token reads); the measurements are on #4059. - **One prompt per request** (no batched `prompt: [[…], […]]`). AnyJev's `Tacit(engine="server")` client batches, so it still needs its own path; its `Decider` backend (nokia-applied-research/AnyJev#20) sends one prompt per request. - **Logprobs are not streamed on this route.** ## Merge danger **Door:** two-way. It is server-only Python behind an opt-in request field. **Blast radius:** small. Callers of `/v1/completions` that send `logprobs` used to get a 400 and now get logprobs. Chat logprobs go through the moved, otherwise unchanged checks. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Cix1XJhNhNNuKXi26KvXnU --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4894
No description provided.