Skip to content

[Feature] Unsloth Studio / Desktop: the API accepts the NPU model name the app shows - #18147

Merged
danielhanchen merged 5 commits into
unslothai:mainfrom
LeoBorcherding:studio/api-npu-display-names
Nov 17, 2026
Merged

danielhanchen merged 5 commits into
unslothai:mainfrom
LeoBorcherding:studio/api-npu-display-names

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

The OpenAI-compatible API now takes the NPU model name Unsloth Studio shows (Qwen3.6-35B-A3B-NPU2), or its FastFlowLM/ repo, wherever it takes a model id. Before, it only took the Lemonade id (lemonade:qwen3.6-moe-35b-a3b-FLM).

Since #17610 the app labels NPU models with FastFlowLM's Hugging Face repo names. Someone who copies that name into an app like Open WebUI, or into a curl, gets a 404 as soon as it matters: when the model isn't loaded yet, or when they look it up.

Example

curl $BASE/v1/chat/completions -H "Authorization: Bearer $KEY" -d '{
  "model": "Qwen3.6-35B-A3B-NPU2",
  "messages": [{"role": "user", "content": "What is the capital of France?"}]
}'

That now loads and answers from lemonade:qwen3.6-moe-35b-a3b-FLM. FastFlowLM/Qwen3.6-35B-A3B-NPU2, any casing, and the old lemonade: id work too. The response's model field stays the Lemonade id.

Before and after

AMD DevLab Strix Halo runner (Ryzen AI MAX+ 395, Ubuntu 24.04, kernel 7.0.0-43, amdxdna 2.25, FastFlowLM 1.0.12, Lemonade 2026.44.1), qwen3-0.6b-FLM, both legs in one job. Run 44089863791: main 3384411 vs 062f2e7. The first run, 44023985957 on ee35baa, gave the same codes in every row but the last.

request main this PR
chat, Qwen3-0.6B-NPU2, model loaded 200 200
chat, fastflowlm/qwen3-0.6b-npu2, model loaded 200 200
/v1/responses, Qwen3-0.6B-NPU2 200 200
GET /v1/models/Qwen3-0.6B-NPU2 404 "does not exist" 200, the loaded NPU model
GET /v1/models id only adds "display_name": "Qwen3-0.6B-NPU2"
chat, display name, nothing loaded, auto-switch off 400 "No model loaded" 404 naming the NPU model and the setting that loads it
chat, display name, auto-switch on 404 "not downloaded on this server" 200, loads lemonade:qwen3-0.6b-FLM and answers
chat, Qwen3-9B-Nope-NPU2 (no such model), NPU model loaded on this PR's leg 404 "not downloaded on this server" 404 "No NPU model is named 'Qwen3-9B-Nope-NPU2'"

On main a display name only "works" while that model is already loaded, because chat answers from whatever is loaded. Loading by name and looking up by name both fail.

The last row is why there's a second commit. At ee35baa a made-up -NPU2 name got the loaded model's answer with a 200. At 062f2e7 it's a 404 "No NPU model is named 'Qwen3-9B-Nope-NPU2'", with the NPU model loaded, so a typo never quietly gets another model's reply. A host that can't run the NPU still passes such a name on unchanged.

main 3384411

this PR 062f2e7

How it works

  • npu_backend.py: NpuModel.display_name and answers_to() match on the hf_repo the app's names come from. model_path_for_name() resolves a name to lemonade:<id>, checking the loaded model first, then the catalog. A name two catalog rows share (FastFlowLM's flash builds reuse the base repo) gets a 400 listing both. A catalog it can't read raises rather than matching nothing, so a runtime that won't start is never mistaken for an unknown name.
  • routes/inference.py: _maybe_auto_switch_model resolves the name first; a host without a supported NPU passes it on untouched. Reading the catalog can start the NPU runtime, so only /v1/chat/completions (the one route an NPU model serves) on a request that's allowed to load starts it: auto-switch on, a credential whose load policy lets it load, not a managed account, not a held-back keyless caller. Other routes (/v1/messages, count_tokens, /v1/responses, TTS, music, separation) never start it and only resolve the model already loaded. A managed account only ever reaches the model already loaded.
  • The public preview passes an NPU name on untouched and serves its pinned checkpoint, as it does for any other name.
  • A runtime that can't be read is a 503 "The NPU runtime is not available: ", not a 404 "No NPU model is named".
  • /v1/models lists display_name, and /v1/models/{id} matches on it or its FastFlowLM/ repo, in any case.
  • Anything that isn't shaped like an NPU name (FastFlowLM/<name> or *-NPU<n>) passes through unchanged, so GGUF and other ids aren't touched.

Tests

New cases in studio/backend/tests/test_npu_backend.py and test_npu_chat_route.py: name and repo matching in any case, the shared-repo refusal, the managed-account and auto-switch-off paths, the refusal of an unknown name on an NPU host, the 503 for a runtime that won't start, a non-chat route that never starts the runtime but still finds the loaded model, and the preview passing an NPU name on.

Not covered: one model (qwen3-0.6b-FLM) on one Linux Strix Halo. No Windows NPU run.

The CLI side of the same change is #18048.

/v1/chat/completions, /v1/responses and the other routes that resolve
lemonade: ids now take the Hugging Face repo name Unsloth Studio shows
for an NPU model (Qwen3-0.6B-NPU2, or FastFlowLM/Qwen3-0.6B-NPU2, any
case) and route it as its lemonade:<id>. The loaded model answers
without I/O; others resolve through the catalog, which may start the
runtime only for a request that could load. /v1/models adds a
display_name field to the NPU entry.
… the NPU

With the runtime stopped and switching off, a display name used to fall
through and be answered by whatever model was loaded, where its
lemonade: id gets the not-loaded 404. On a host with a supported NPU and
the runtime installed, an NPU name that resolves to nothing now gets
that 404, or 'No NPU model is named' when the request could load.
@LeoBorcherding
LeoBorcherding marked this pull request as ready for review November 17, 2026 13:26
@danielhanchen danielhanchen self-assigned this Nov 17, 2026
@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 17, 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-17T17:26:34.793327Z ee084e7 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: b6150bdd13

ℹ️ 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 thread studio/backend/routes/inference.py Outdated
Comment on lines +38518 to +38521
if isinstance(eid, str) and model_id.lower() in (
eid.lower(),
str(entry.get("display_name") or "").lower(),
):

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 Resolve full FastFlowLM repo names in model retrieval

With lemonade:qwen3-0.6b-FLM loaded, GET /v1/models/FastFlowLM/Qwen3-0.6B-NPU2 still returns 404: this branch compares only the canonical ID and bare display name, and the subsequent catalog loop also compares only IDs. Chat accepts the full repo name through NpuModel.answers_to(), so a client that retrieves its configured model before generating cannot use this newly supported identifier. Match retrieval requests against the NPU model's full repo name as well, while preserving the existing alias precedence.

Useful? React with 👍 / 👎.

Comment thread studio/backend/routes/inference.py Outdated
gguf_requires_vision = (
(require_audio_input or require_video) if tool_images_only else require_vision
)
requested_model = await _npu_path_for_display_name(requested_model, fastapi_request)

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 Check endpoint support before allowing NPU runtime startup

With auto-switch enabled and the NPU runtime stopped, an otherwise valid /v1/completions request naming Qwen3-0.6B-NPU2 reaches model_path_for_name() and catalog() before the endpoint's NPU capability is checked. This starts Lemonade; after a runtime pin update, _ensure_running() can even invoke enable() to download and validate the replacement runtime, only for _refuse_unservable_npu_switch() to reject the request because completions cannot serve NPU models. The equivalent canonical lemonade: request is rejected before that catalog I/O. Gate runtime startup on the endpoint's NPU capability so an unsupported request cannot trigger this potentially lengthy setup.

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 ee084e7: _maybe_auto_switch_model passes serves_npu to the display-name step, and only an endpoint that serves the NPU may start its runtime. Test: test_an_endpoint_that_cannot_serve_the_npu_never_starts_the_runtime.

…a credential that may load starts the runtime

[skip ci]
@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. Swish!

Reviewed commit: ee084e786e

ℹ️ 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
danielhanchen merged commit 971ab32 into unslothai:main Nov 17, 2026
danielhanchen added a commit that referenced this pull request Nov 17, 2026
…-r red since #18147) (#18197)

Two Studio tests fail on main since #18147 (`m-r` shard, seen on the
staging run of #18188, a computer-use change):

```
tests/test_multi_model_serving.py::test_a_resident_npu_model_keeps_to_the_primarys_seat
routes/inference.py:10720: in _loaded_satisfies
E   AttributeError: 'types.SimpleNamespace' object has no attribute 'answers_to'
tests/test_multi_model_serving.py::test_the_loaded_models_list_names_the_npu_model_once
E   AttributeError: 'types.SimpleNamespace' object has no attribute 'display_name'
```

## Cause

#18147 lets the API accept the NPU model name the app shows: `NpuModel`
gained `display_name` and `answers_to()`, and the routing /
loaded-models code now calls them. That is correct for the real class.
These tests stand in for the resident NPU model with a `SimpleNamespace`
carrying only the fields the code used before, so the new calls fail.

## Fix

A `_npu_model()` helper builds the real `npu_backend.NpuModel` (frozen
dataclass, `model_path` derived from `id`), and the four NPU stubs in
the file use it. The surrounding backend stubs (`is_loaded`, `resident`)
are unchanged. With the real class, a later method on `NpuModel` reaches
these tests automatically instead of breaking them.

## Verification

- main: 2 failed, 108 passed.
- this branch: `tests/test_multi_model_serving.py` 110 passed.
@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

Pushed 53135c9. When the NPU runtime couldn't start, model_path_for_name swallowed the error and returned no match, so a chat request for a real NPU model got a 404 "No NPU model is named ..." that pointed at the name instead of the runtime. It now raises, and the route answers 503 "The NPU runtime is not available: ". A name two catalog rows share has its own error type and stays a 400.

The public preview also refused an NPU-shaped name with a 404 when that model wasn't loaded, before it reached the code that serves the preview's pinned checkpoint whatever model the caller names. The resolver now passes the name on untouched for a preview request, the same as for any other name. Starting the runtime only on the chat route is ee084e7; this commit adds a test that a non-chat route still finds the NPU model already loaded.

Tests added. Codex is clean on this commit on the mirror (LeoBorcherding#947 (comment)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants