Repository navigation
[Bug] AMD NPU: Unsloth Studio sends a tool catalog on every NPU chat, which turns FastFlowLM speculative decoding off and drops qwen3.8 decode to ~0.3 tok/s - #17530
Conversation
…nstraint path FastFlowLM builds a decoding constraint for a tools list under auto and for a forwarded tool_choice none, and a constraint turns speculative decoding off on the NPU (ROCm/FastFlowLM#1016). NPU models now load with Search and Code off unless the chat or a saved click says otherwise, and the lemonade proxy drops tool_choice none once the tools are cleared.
|
Tested on a real Strix Halo NPU (AMD DevLab, Lemonade 2026.44.1, FastFlowLM 1.0.12, phase 5 branch). Same prompt each time, straight to
Lemonade lines: Full Lemonade and server logs are the |
|
Measured on a real NPU: AMD Strix Halo (DevLab runner, Linux), amdxdna 2.25, NPU firmware 1.1.2.65, FastFlowLM 1.0.12, Lemonade 2026.44.1, Unsloth Studio fork phase 5
"Tools sent" puts two tool definitions (web_search, python) in the request, the way Unsloth Studio did with Search and Code on. They add 311 prompt tokens, so part of the first-token gap is reading those tokens, not only the grammar build. On the 27B the gap comes from speculation: FastFlowLM 1.0.12 turns it off whenever a tool grammar is attached ( With #17532 and #17510 measured alongside, the whole gain is this PR (both bars measured directly, not summed): Not covered: the 27B MTP build with tools, any temperature above 0, and FastFlowLM main. ROCm/FastFlowLM#1029 keeps speculation on under a tool grammar for greedy requests. ROCm/FastFlowLM#1031 limits Qwen3.8-MTP speculation to greedy requests. A run covering both is in progress. |
A chat opened under a GPU model captured the Search-on default, and a new chat after loading an NPU model fell back to it, so the tool catalog was sent again. New chats on NPU models now take the same default as a fresh load: a saved click, else off. [skip ci]
|
@codex review |
1 similar comment
|
@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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba73f18c54
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| // A key the snapshot omits falls back to the defaults, not to the outgoing chat's value. | ||
| const value = firstSetThreadScopedValue( | ||
| stored?.[key], | ||
| npuPillDefault(state.params.checkpoint, key), |
There was a problem hiding this comment.
Keep NPU defaults out of the shared installation snapshot
If the first chat in a session is opened on an NPU with no saved Search/Code preferences, applyThreadScopedSettings captures the newly disabled pills into globalThreadScopedDefaults. Loading a tool-capable GPU model while that chat is open and then starting a new chat leaves both pills off: npuPillDefault returns undefined for the GPU, so the fallback restores the captured NPU values and persists them onto the new GPU chat. The same sequence leaves both pills on in the parent commit. Keep the shared installation defaults independent of the NPU override, or resolve the destination model's defaults when restoring a new chat.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 816ac95: new-chat defaults are captured from the saved choice, else the GPU default, not from the NPU's forced-off pills. Covered by a new test in npu-tools-new-chat.test.ts, which fails on the previous head.
A first chat opened under an NPU model captured Search and Code off as the installation defaults, so a new chat on a GPU model loaded later came up with both off. Capture the saved choice, else the GPU default, instead. [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 816ac95bf5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| for (const key of ["toolsEnabled", "codeToolsEnabled"] as const) { | ||
| out[key] = loadOptionalBool(MIRRORED_SETTINGS[key].storageKey) ?? pillDefault(key); |
There was a problem hiding this comment.
Apply the NPU fallback when snapshotting during a reload
For an older chat whose snapshot omits the pill keys, with no saved global choices, editing an unrelated thread setting during an NPU reload now persists both pills as true. While modelLoading, readThreadScopedValue defers to pillOnRecord, which still falls back to these GPU-defaulted installation values rather than the NPU default. buildThreadScopedSnapshot then promotes them to explicit chat overrides, so resolveToolsEnabledOnLoad re-enables Search, Code, and the expensive tool catalog after reload without a tool opt-in. Apply the same NPU-aware fallback when snapshotting missing pill values.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not fixing here: this needs a chat saved before the pill keys existed plus an unrelated setting edited during the seconds an NPU model is loading, and the result (Search on for that one chat) is what every NPU chat got before this PR. Fresh loads, new chats and chats with stored pills are all covered.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |



On AMD NPU models (
lemonade:*), Unsloth Studio turns Search and Code on by default and sends a tool catalog with every chat, even when the user never asked for tools. FastFlowLM builds a decoding constraint for that catalog, and a constraint turns speculative decoding off. On qwen3.8, decode drops from ~3-5 tok/s to ~0.29 tok/s (ROCm/FastFlowLM#1016).How it happens:
chat-runtime-store.ts:1072:pillDefaultturns Search and Code on for any model with tools, applied throughresolveToolsEnabledOnLoad(:1912).npu_backend.py:95: NPU models report tool support from Lemonade'stool-callinglabel.chat-adapter.ts:7013: sendsenable_tools: true, andproviders.py:532(studio_tools: True) lets the tool loop run forlemonade.chat_grammar.cpp:615: tool_choice auto with a non-empty tools list builds a grammar.modeling_qwen3_8mtp.cpp:480turns speculation off under any constraint.tool_choice: "none"clears the tools (routes/inference.py:30465), butexternal_provider.py:1991still forwards it. FastFlowLM turns it into a token-ban constraint (chat_constraint.cpp:109), so speculation is off there too.Fix:
tool_choice: "none"once the tools are cleared.New chats are covered too: a chat opened under a GPU model used to capture the Search-on default, and a new chat started after loading an NPU model fell back to it. New chats on an NPU model now take the same default as a fresh load (a saved click, else off).
Tests
frontend/tests/npu-tools-default.test.ts: an NPU load comes up with the pills off, a GPU load still comes up with them on, and a saved "on" is kept on NPU. The first case fails on main.frontend/tests/npu-tools-new-chat.test.ts: a chat opened under a GPU model, then an NPU load, then a new chat: Search and Code come up off and are stored off on the new chat; a GPU model still comes up on; a saved "on" is kept. The NPU cases fail on the previous head.backend/tests/test_npu_chat_route.py::test_tool_choice_none_withholds_the_toolsnow also checks thattool_choicenever reaches FastFlowLM. It fails on main.Tested on Windows 11, Ryzen 9 9950X + 2x R9700, no NPU: frontend typecheck plus 247 store tests, 907 backend NPU route and external provider tests. Not run on a Ryzen AI NPU, so the tok/s figures are the ones reported in ROCm/FastFlowLM#1016, not measured here.
Screenshots
NPU spoofed: fake Lemonade/FastFlowLM on a Windows 11 PC with no NPU; no speed numbers. Before | after: fork phase stack, phase-0 base
5d5c138| phase 1ac3e06e. This PR's headae8871fis part ofac3e06e. Light mode, mint theme, glass on, same on both sides.Before | after: with qwen3.6-moe-35b-a3b-FLM loaded, Search and Tools start off instead of on.

Measured on a real Ryzen AI NPU
AMD Strix Halo NPU (XDNA2, amdxdna 2.25, firmware 1.1.2.65), Lemonade 2026.44.1, FastFlowLM 1.0.12,
qwen3.8-dflash2-27b-FLMat 8192 context. Basefcae458and this PR's head were run on the same Studio install, the same runner and the same downloaded model. Each chat used temperature 0 and 128 output tokens, two reps per cell. tok/s is 128 divided by wall time.tool_choice: noneenable_tools: true, 5 toolsenable_tools: falseWith
tool_choice: "none", main still forwards the field. FastFlowLM turns it into a constraint and decodes at the tool-catalog speed. This PR decodes at the no-tools speed. Sending tools on purpose is unchanged (0.28 tok/s on both).Before | after on the real NPU, same model loaded, fresh browser profile:
