mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
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#4471
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/3138
Author: @ctr-137
Created: 10/19/2026
Status: ❌ Closed
Base:
main← Head:serve-n-predict-2980📝 Commits (1)
6dd1fefserve: read llama.cpp's n_predict, including the prompt-only 0 (#2980)📊 Changes
3 files changed (+162 additions, -2 deletions)
View changed files
📝
docs/DETAILS.md(+6 -0)📝
serve/server.py(+55 -2)➕
serve/test_n_predict.py(+101 -0)📄 Description
Issue: #2980
Summary
/v1/chat/completionsread onlymax_tokens/max_completion_tokens. llama.cpp's web UI sends a follow-up withn_predict: 0after every reply to evaluate the prompt into the conversation cache; Strata treated 0 as "the rest ofthe context" and generated a second full answer (~20k tokens, 4-5 minutes of GPU on the reporter's R9700). Because
Strata serves one request at a time, every other client waited behind it, and the next user message re-read the whole
conversation because the prompt-only call never completed. llama.cpp's server README defines the field this way:
"When 0, no tokens will be generated but the prompt is evaluated into the cache."
What changed
n_predictis honoured on/v1/chat/completionswhen the request has neithermax_tokensnormax_completion_tokens:0evaluates the prompt through the normal generation path and generates nothing. The answer is empty withfinish_reason: "length"- the shape llama.cpp returns for this - andusage.completion_tokensis 0. Streamingand non-streaming.
N > 0is the output cap.-1(or absent) leaves the rest of the context, as before.An OpenAI
max_tokens/max_completion_tokensin the same request wins overn_predict, so an existing clientkeeps exactly the behaviour it had. A non-integer
n_predict("0",true,1.5) is a 400 before inference.One engine note:
GENneedsmax_new >= 1, so the prompt-only call samples and drops one token. The prompt is readthrough the normal generation path, which is what the client's follow-up wanted. The engine's own totals count that
one token; the API response reports 0 completion tokens, matching llama.cpp.
docs/DETAILS.mdhas one bullet under the API section.Validation
python -m unittest serve.test_n_predict- 6 tests, OK:n_predict: 0finish_reason: "length", empty content, the prompt reached the enginen_predict: 0,stream: truelengthand usage 0,[DONE], no contentn_predict: 3lengthmax_tokens: 2+n_predict: 7n_predict: -1finish_reason: "stop""0"/true/1.5/[0]The full
servesuite: 854 tests; the only error istest_winjob.TestWinJob(a Windowstasklistcall returningNonehere), the same one as on unmodifiedmain(848 tests).test_keepawakeis timing-flaky under the full runand passes alone; neither is related to this change. No new skips.
What I left alone
/v1/messagesand/v1/responses. The report is llama.cpp's chat client, Anthropic requiresmax_tokens, and theResponses API has
max_output_tokens.GEN 0that samples nothing would be a C++ change; this stays a server-side fix withone sampled token.
n_predictfield in/propswas already reported; it is unchanged.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.