Repository navigation
server : fix usage.completion_tokens undercount with n > 1 - #29486
Conversation
Assisted-by: Copilot
|
Hi @unbug, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
DONE. |
|
/bot review |
Automated code reviewReview of PR #29486 (server: fix usage.completion_tokens undercount with n > 1). Checklists run: scope/quick-reject, security, general, server, tests (changes under Scope gate: clean. Single-purpose fix, linked issue #29451, minimal diff, AI disclosure filled in. No security concerns: the summed values are server-computed token counts, not client-controlled input, and each element of The non-streaming fix itself is correct. I verified that Findings:
Style is fine: comments are concise and explain the non-obvious intent, ASCII only, alignment matches surrounding code. No blocking issues on the code as written; point 1 is the only substantive item and can be addressed either in this PR or as a follow-up. This review was generated automatically by pi coding agent using |
…29486) Assisted-by: Copilot
…29486) Assisted-by: Copilot
Overview
Fix incorrect usage reporting for OpenAI requests with
n > 1.Fixes #29451.
When multiple choices are requested, the server only keeps the usage from the first result. This causes
completion_tokensandtotal_tokensto be undercounted.Sum
completion_tokensacross all choices and recalculatetotal_tokens, while countingprompt_tokensonce.Additional information
The issue can be reproduced with the script provided in #29451. With
n=4, for example, four completions are returned butcompletion_tokensonly reports the tokens from one choice.Requirements
I have read and agree with the [contributing guidelines](https://github.com/ggml-org/llama.cpp/blob/master/CONTRIBUTING.md)
AI usage disclosure: YES — AI was used to help review the code and run the test.