Skip to content

[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

Merged
danielhanchen merged 4 commits into
unslothai:mainfrom
LeoBorcherding:studio/npu-tools-off-by-default
Nov 14, 2026

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

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: pillDefault turns Search and Code on for any model with tools, applied through resolveToolsEnabledOnLoad (:1912).
  • npu_backend.py:95: NPU models report tool support from Lemonade's tool-calling label.
  • chat-adapter.ts:7013: sends enable_tools: true, and providers.py:532 (studio_tools: True) lets the tool loop run for lemonade.
  • FastFlowLM chat_grammar.cpp:615: tool_choice auto with a non-empty tools list builds a grammar. modeling_qwen3_8mtp.cpp:480 turns speculation off under any constraint.
  • API callers hit a side path. tool_choice: "none" clears the tools (routes/inference.py:30465), but external_provider.py:1991 still forwards it. FastFlowLM turns it into a token-ban constraint (chat_constraint.cpp:109), so speculation is off there too.

Fix:

  • NPU models load with Search and Code off unless the open chat or a saved click says otherwise. The user can still turn them on. This covers every NPU model, not only qwen3.8: the frontend can't tell which Lemonade models speculate, and a grammar constraint costs decode speed on all of them.
  • The lemonade proxy no longer forwards 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_tools now also checks that tool_choice never 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 1 ac3e06e. This PR's head ae8871f is part of ac3e06e. 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.
17530

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-FLM at 8192 context. Base fcae458 and 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.

no tools tools sent tools + tool_choice: none fresh profile: Search composer sends
main 2.61 tok/s 0.28 tok/s 0.28 tok/s (459-461 s) on enable_tools: true, 5 tools
this PR 2.61 tok/s 0.28 tok/s 2.61 tok/s (49 s) off enable_tools: false

With 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:
npu tools before after

…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.
@NilayYadav

Copy link
Copy Markdown
Collaborator

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 /v1/chat/completions.

Request qwen3.8-dflash2-27b qwen3.8-mtp-27b
No tools, 16 tokens out 4.58 tok/s 2.28 tok/s
No tools, 128 tokens out 2.57 tok/s 2.36 tok/s
No tools, 128 tokens out, temperature 0 2.57 tok/s 2.36 tok/s
Tools sent, 32 tokens out 0.29 tok/s 0.29 tok/s
Tools sent + tool_choice: none, 32 tokens out 4.56 tok/s 4.07 tok/s
  • A tool catalog drops both variants to 0.29 tok/s (32 tokens took 115 s), matching the number in this PR. Without tools it is 8 to 16x faster.
  • tool_choice: none runs at full speed: the request reaches FastFlowLM with 70 prompt tokens, same as no tools.
  • Without tools, speed depends on reply length: dflash2 does ~4.6 tok/s for the first 16 to 32 tokens, 2.57 over 128 and 2.2 over 256. So "3-5 tok/s" holds for short replies only.
  • The drafter loads: DFlash2 drafter loaded ... (5 layers, block 8, taps 5).

Lemonade lines:

tools sent:       Inference completed: model=qwen3.8-dflash2:27b, tokens=353 (in=321, out=32), ttft=4.484s, tps=0.29
no tools:         Inference completed: model=qwen3.8-dflash2:27b, tokens=198 (in=70, out=128), ttft=3.730s, tps=2.57
tool_choice none: Inference completed: model=qwen3.8-dflash2:27b, tokens=102 (in=70, out=32), ttft=3.761s, tps=4.56

Full Lemonade and server logs are the qwen38-logs artifact on https://github.com/oobabooga/unsloth/actions/runs/43279437474

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

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 92c2fbb, temperature 0, 256-token replies. Numbers are medians of 2 to 3 identical reps from Lemonade's telemetry, in oobabooga/unsloth run 43276227073.

Model Tools sent (before) No tools (this PR)
Qwen3.8-27B-DFlash2-NPU2 0.28 tok/s, 4.6 s first token 2.17 tok/s, 3.7 s 7.7x faster replies
Qwen3.6-35B-A3B-NPU2 17.2 tok/s, 7.2 s first token 17.2 tok/s, 3.1 s 2.3x sooner first token
Qwen3.5-9B-NPU2 9.5 tok/s, 1.3 s first token 9.6 tok/s, 1.1 s 1.2x sooner first token

tools

"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 (modeling_qwen3_8mtp.cpp:480), leaving 0.28 tok/s plain decode. With it on, the model runs 7 to 10x faster:

27B

With #17532 and #17510 measured alongside, the whole gain is this PR (both bars measured directly, not summed):

stack

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.

@danielhanchen danielhanchen self-assigned this Nov 13, 2026
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]
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T17:01:08.865180Z 816ac95 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +941 to +942
for (const key of ["toolsEnabled", "codeToolsEnabled"] as const) {
out[key] = loadOptionalBool(MIRRORED_SETTINGS[key].storageKey) ?? pillDefault(key);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

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".

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 13, 2026
@danielhanchen
danielhanchen merged commit 48c220b into unslothai:main Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants