Repository navigation
[Bug] AMD NPU: non-streaming chat completions return no usage - #18577
Merged
danielhanchen merged 1 commit intoNov 20, 2026
Merged
Conversation
Member
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Non-streaming
/v1/chat/completionson an AMD NPU model never returnsusage, so the OpenAI SDK readsusage=None. Streaming withstream_options.include_usagedoes return it.Cause.
_npu_chat_completionsalways streams from FastFlowLM and collects the stream for a JSON caller. FastFlowLM sends usage in its own empty-choices chunk, and_proxy_to_external_providerdrops that chunk unless the payload opts in (_is_openai_usage_only_sse). The non-streaming payload never opts in, so_NpuStreamRelaynever sees usage and the collected body has none.Fix. When the caller didn't ask for a stream, set
stream_options.include_usageon the upstream copy of the payload. Streaming requests are unchanged.Test.
test_non_streaming_reply_keeps_a_separate_usage_chunkmakes the fake FastFlowLM send usage the way the real one does: a separate chunk, only oninclude_usage. It fails on main withKeyError: 'usage'and passes here. The existing fake put usage inline on the finish chunk, which the proxy never drops, so the existing test passed on main. All 657 NPU backend tests pass (2 skipped).Before and after on a Strix Halo NPU
Both legs in one job, run 44657898339, each a fresh
install.sh --localin its own home,unsloth run --model LFM3-1.7B-NPU2 --context-length 4096, then the same requests.39429427fa1666stream: falseusagekeyusagewith prompt 17, completion 200, total 217, plus FastFlowLM's KV fieldsstream: false,enable_tools: falseusagekeyusagepresentchat.completions.createusage=NoneCompletionUsage(completion_tokens=109, prompt_tokens=17, total_tokens=126, ...)stream: truewithinclude_usagestream: true, nostream_optionsThe same
usage=Noneshows on the v0.1.920-beta release install (tag2f2490c) with Qwen3.6-35B-A3B-NPU2 in runs 44644638040 and 44654204267.7fa1666vs3942942Not run: Windows (the route is OS-independent, but nobody ran the Windows NPU path), Strix Point / Krackan / Gorgon Point NPUs, and FastFlowLM 1.0.13 from #18553. The change is in Unsloth Studio's route only, so it doesn't depend on the NPU part.