mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1916] [CLOSED] OpenAI logprobs on /v1/chat/completions for the CUDA/HIP engine #3757
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#3757
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/1916
Author: @gt50
Created: 10/11/2026
Status: ❌ Closed
Base:
main← Head:logprobs📝 Commits (3)
92ebad2OpenAI logprobs on /v1/chat/completions for the CUDA/HIP engine7e1a00dserve: logprobs with "parallel" (batch slots) for one-token decisions; 400 for longer replies4098d58serve: the logprobs 400 with "parallel" only for real batch slots, not for replicas without them📊 Changes
5 files changed (+638 additions, -16 deletions)
View changed files
📝
docs/DETAILS.md(+17 -0)📝
serve/server.py(+216 -16)➕
serve/test_logprobs.py(+271 -0)➕
serve/test_logprobs_parallel.py(+101 -0)📝
src/program/generate.cpp(+33 -0)📄 Description
Title
OpenAI logprobs on /v1/chat/completions for the CUDA/HIP engine
Summary
"logprobs": true(with"top_logprobs": 0..20) on/v1/chat/completionsnow returnschoices[0].logprobs.content, as OpenAI and llama-server do. Until now only the SYCL port had it (835d30b); the CUDA/HIP engine andserve/accepted the field and returned nothing. A client that marks values the model was unsure of (the weakest token of a value under 50%) needs it.What changed
src/program/generate.cpp): the GEN keylogprobs=KwritesLP <logprob> [id:logprob ...]after eachT <id>, from the verify window's head logits (Verifier::copy_logits), before penalties, temperature and sampling. It is the SYCL port's code, placed at both token outputs (the plain and the pipelined path). Without the key, no LP lines and nothing else changes.serve/server.py:sampling_keyssendslogprobs=Konly when the request asks; an engine without LP lines ignores the key and the reply has nologprobs.StrataEngine.generatereads a token's LP line before it yields the token (the engine writes both in the same flush), so the logprobs belong to the right text chunk. When nothing follows a token within 0.5 s, it is yielded without one. A line read this way is handed to the early-stop drain, so aDONEread after the last token is not waited for again (tested).tokenis the text the token completes (an incremental UTF-8 decode, as the reply's text is made): a character split across tokens is in the token that finishes it, so the tokens, joined, spell the reply.bytesare the token's own bytes. Tokens that make no text (</think>and the newlines after it) and the stop token are left out.openai_collectmerges them intochoices[0].logprobs(content,refusal, andreasoning_contentwith thinking on).response_formatjson_schema: withlogprobs, the answer is returned as the model wrote it (validated as before, the same value) when its tokens spell it, including the JSON inside a```jsonfence; otherwise the canonical JSON withoutlogprobs. Withoutlogprobs, the canonical JSON as before.docs/DETAILS.md: a "Logprobs" paragraph after the sampling one.serve/test_logprobs.py: the request keys, the engine line pairing (with and without LP lines, not asked, early stop), the API streamed and not (multi-byte characters,top_logprobs, the stop token), thinking,json_schemawith a fenced answer, and the span helper.Extra Notes
logprobssends the same GEN line, reads the same lines and returns the same reply (tested). The engine prints LP lines only when asked.--spec 4 --mtp), this branch built withtools/hip/build_windows.bat(gfx1151, engine 0.1.42):logprobs, 38.5 and 38.1 tok/s; 254 entries (the stop token left out).{"rent": "$1,250", "quote": "Rent is $1,250 a month."}from a two-fieldjson_schemaat temperature 0: 26 tokens that spell the content.contentandreasoning_contenteach spelled by their tokens. A streamedjson_objectanswer and a sentence withcafé,東京and€5: spelled too.--parallelbatch slots (theirBTlines get no LP lines). The legacy completions form"logprobs": Nis taken astop_logprobsN.servetest files pass onmain61b3fb5d(704 tests).🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.