mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2254] [CLOSED] [Engine] OpenAI logprobs / top_logprobs / allowed_token_ids for the CUDA/HIP engine #3951
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3951
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2254
Author: @xiezhipeng-git
Created: 10/13/2026
Status: ❌ Closed
Base:
main← Head:feat/openai-logprobs📝 Commits (1)
8049478OpenAI logprobs / top_logprobs / allowed_token_ids for the CUDA/HIP engine📊 Changes
3 files changed (+570 additions, -8 deletions)
View changed files
📝
serve/server.py(+240 -8)➕
serve/test_logprobs.py(+270 -0)📝
src/program/generate.cpp(+60 -0)📄 Description
Problem and result.
/v1/chat/completionson the CUDA/HIP engine acceptedlogprobs/top_logprobsand returned HTTP 200, butchoices[0].logprobs.contentwas always[]. A client that ranks candidate tokens from the model's own distribution — constrained decoding, candidate scoring, tool-choice re-ranking — silently got nothing: the request succeeds, the content is correct, only the field is missing, so the failure is invisible unless the caller asserts on the field. After this change,logprobs: truewithtop_logprobs0..20 (the legacy completions formlogprobs: Nis also accepted) returns one entry per token with its top alternatives, andallowed_token_idsreturns a distribution renormalised over exactly the ids the caller named.Related discussion. #1916 proposed the same feature for CUDA/HIP and is closed. This implementation follows the protocol the SYCL port already speaks (
835d30b1) and the Metal port (31f26683), so one server-side reader serves all three backends.Approach.
src/program/generate.cpp:logprobs=Kandallowed=a,b,care two extra keys on the--serveGEN line (an engine that predates them skips them as unknown), and oneLP <logprob> [id:logprob ...]line is written after eachT <id>in the same flush. The value comes from the verify window's head logits before sampling, penalties and temperature, so it is the model's distribution rather than the sampler's. Off by default: a request withoutlogprobsproduces the previous output byte for byte, and the per-token cost is one integer compare.serve/server.py:sampling_keysappends the two keys only when asked;generatereads each token'sLPline before yielding the token (a held line is consumed before the next read, so an engine without LP lines loses no lines, and aDONEread while looking for one still ends the request);LogprobEntriesdecodes token bytes incrementally so the entries joined spell the reply;allowed_token_idskeeps the named ids and renormalises over them;structured_chunksre-aligns the entries whenresponse_format: json_schemarewrites the content and returns no logprobs rather than a set that does not match.Validation.
Rebased onto
upstream/maine88ee39d(which containsv0.2.0-betab73dbce3); head104becfd. The diff is 3 files, +570/−8, unchanged by the rebase.Passed:
104becfd:cmake --build build-lp --target strata— Release,CMAKE_CUDA_ARCHITECTURES=89, CUDA 13.3 (V13.3.73), MSVC 14.41, Windows 11, RTX 4090.[154/154] Linking CXX executable strata.exe, exit 0.python -m unittest serve.test_logprobs— 17 tests, OK, on104becfd.strata.exebuilt from it, model Swift-1.5 IQ3_XXS,--spec 4 --spec-min-p 0.5 --kv int8 --kv-resident 32768),max_tokens: 1,temperature: 0,chat_template_kwargs.enable_thinking: false:top_logprobs: 20→logprobs.contentlength 1,top_logprobswidth 20; entry tokenAat -0.1028 withB -3.121,C -3.201,D -5.1109.toolsandtool_choice: "auto"→ entries present, width 20, labelsA/D/C/B.stream: true→ the delta carrieslogprobs.content(1 entry, tokenA, -0.0801, top width 20).80494788); the endpoint behaviour it depends on is the same code path exercised above.Failed: none observed.
Not run:
src/program/generate.cppis shared by the CUDA and HIP builds; only the CUDA configuration was built here (no AMD GPU or toolchain on this machine).install_logprobsinsycl/serve/server_intel.py) and this change does not touch it; no Intel GPU or toolchain here.--batchmode: see Limits.Limits.
--batchdoes not return logprobs.generate_batchednever readsLPlines; only the solo/serial path (generate) does, so a server started with--batchanswerslogprobs.content: []. Giving the batched path the same read-before-yield step is the remaining work if that combination is wanted.response_format: json_schemathe returned content may not be spelled by the tokens; in that case no logprobs are returned, by design.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.