Skip to content

[Feature] AMD NPU: load Q4NX models converted in Unsloth Studio from the NPU model list - #17636

Merged
danielhanchen merged 39 commits into
unslothai:mainfrom
LeoBorcherding:studio/npu-local-q4nx-models
Nov 17, 2026
Merged

danielhanchen merged 39 commits into
unslothai:mainfrom
LeoBorcherding:studio/npu-local-q4nx-models

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Q4NX folders converted on the Export page now show in the NPU section of the model picker as "Converted" rows, and load on the AMD NPU. Before, a converted model could only be run by hand outside Unsloth Studio.

Loading links the folder's files into FastFlowLM's model folder next to the base model's config.json, and adds a model_list.json entry (through FLM_CONFIG_PATH) that runs on the base model's kernels. Removing a converted model drops only that registration, never the export folder.

Converted models are text-only: the Export page converts the language weights, not the vision tower.

Builds on the Q4NX export PRs (#17521, #17515, #17522, #17533, #17534).

Tested on a Strix Halo NPU

Machine AMD DevLab runner: Ryzen AI MAX+ 395, Radeon 8060S, XDNA2 NPU, 124 GiB
OS / kernel Ubuntu 24.04.5, 7.0.0-43-generic
NPU driver amdxdna 2.25.260102.56, NPU firmware 1.1.2.65
Runtime FastFlowLM 1.0.12, Lemonade 2026.44.1
Commit that ran 8f5c293fb5: this PR's head d2256204 plus the review fixes from the fork mirror (LeoBorcherding#876, to 380ee036c4), merged with main b66e8f498a, plus two follow-ups (a test stub kept on main's memory tag, and converted rows named by folder in main's new composer model picker)
Run oobabooga/unsloth run 43900756899

What ran, in the real UI with headless Chromium (mint theme, glass on, light mode, no chats):

  1. Export page Q4NX card: unsloth/Qwen3-0.6B-GGUF, file Qwen3-0.6B-Q4_1.gguf, original model Qwen/Qwen3-0.6B. Converted in 23 s to q4nx/Qwen3-0.6B-Q4_1-q4nx.
  2. The chat model picker lists it under NPU as Qwen3-0.6B-Q4_1-q4nx ("Converted on the Export page").
  3. Loaded on the NPU in 8 s and chatted at temperature 0 (Run settings field). "Name the three primary colors in one short sentence." got "The three primary colors are red, blue, and yellow." at 119.5 tok/s (17 tokens, first token 631 ms, prompt 42.1 tok/s).

Not covered: Q4_0 sources (they convert but decode as noise on FastFlowLM, a separate converter issue), Q4_K_M sources, vision models, Windows. The temperature is the Run settings value; the request body wasn't captured.

Known issue on main, not changed here: the composer model picker lists FastFlowLM catalog models by internal id in backend order (#17517). Converted rows from this PR show their folder name.

Pushed as f39b6f687d (merge with main included; Codex clean at that commit on the mirror, LeoBorcherding#876). It has three review fixes on top of what ran, not rerun on the NPU:

  • be91ed7b51: Auto context sizes a converted model from its staged folder (the run above loaded at 8192 because the plan had no config).
  • b0281fe807: converted rows get the memory-fit fields, so the "May not fit NPU memory" tag and the Hub warning show for them.
  • f39b6f687d: a GGUF export with Q4NX saved four or more levels deep under exports registers its save folder, so the conversion is listed.

Screenshots

Export page, Q4NX card: GGUF file list
Q4NX files

Convert settings, Q4_1
Q4NX settings

Converting
Converting

Done
Done

The converted model in the NPU section of the chat picker
Picker

Loaded, temperature 0
Run settings

Chat on the NPU
Chat

Reply stats
Stats

…e NPU picker

Converted folders under the account's exports show in the NPU list as
Converted rows. Loading one links its files into FastFlowLM's model folder
beside the base model's config.json and registers a model_list.json entry
(FLM_CONFIG_PATH) that runs on the base model's kernels. Deleting drops the
registration only; the export folder is never written to. The converter now
records the source GGUF's architecture and size so the base can be matched.
A linked model.q4nx could point at another account's export and get hard-linked or copied into FastFlowLM staging. Each file must be a plain file inside the acting account, checked when listed and again when staged.
The desktop shell calls itself Unsloth, and the branding contract test refuses Unsloth Studio in frontend sources.
…base

The base map keyed Nanbeige only under llama. A test now holds every shape the export accepts to a base the picker loads.
…in the NPU picker

A conversion saved to an absolute folder outside the exports root, or more than four folders deep inside it, converted fine but never showed in the picker. Deep ones are now registered as scan folders like absolute ones already were, and the picker also lists registered folders that hold a model.q4nx, inside the acting account only.
…re 3.12

os.path.isjunction is 3.12+, so on Windows 3.9-3.11 the walk descended junctions out of the exports root. It now reads the reparse tag, through cache_inventory's helper.
…them; each conversion writes a fresh source record
…ull path, and list an unreadable source record as unloadable
# Conflicts:
#	studio/backend/core/export/q4nx.py
#	studio/backend/core/inference/lemonade_server.py
#	studio/backend/core/inference/npu_backend.py
#	studio/backend/tests/test_export_q4nx_accounts.py
#	studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx
#	studio/frontend/src/features/npu/api.ts
#	studio/frontend/src/features/npu/index.ts
…row test; keep the memory warning in NPU row details
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot 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 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: 2afc899c5c

ℹ️ 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 +224 to +225
if "model.q4nx" in files:
dirs[:] = []

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 Discover conversions nested under an existing Q4NX folder

If the Export page saves a conversion inside an existing converted folder, such as exports/q4nx/first-q4nx/second-q4nx, finding the parent's model.q4nx clears dirs, so the valid child conversion is never discovered. hidden_in_exports() only checks depth and dot directories, so this depth-three path is not registered by either export route and never appears in the NPU picker despite conversion succeeding. Continue scanning children within the depth limit, or explicitly register these otherwise-hidden descendants.

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 changing this: it needs a conversion saved inside another conversion's output folder, which the Export page never proposes; a folder holding model.q4nx is treated as one model, and nesting another under it is outside normal use.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…; bulk delete finds staged copies in any catalog layout

[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: f4019e832f

ℹ️ 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 +328 to +329
except OSError:
shutil.copy2(source, target)

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 Honor load cancellation while copying weights across volumes

When a conversion is saved on a different volume from Studio’s runtime, hard-linking falls back to this non-cancellable copy. The config download now honors cancellation, but this separate staging phase never observes _load_cancelled: cancel_load() reports success while load() continues copying the weights under self._lock. For multi-GB models on a slow external drive, subsequent loads and deletes remain blocked until the copy finishes. Pass the load cancellation event into link_files() and check it during a chunked copy, propagating cancellation as NpuLoadCancelled.

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 changing this: the copy fallback runs only when the export and FastFlowLM's folder sit on different volumes, once per conversion, and the load checks the cancel right after it; a cancel is delayed by that one copy, never lost, and nothing is left half-registered.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 17, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 17, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 17, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 4013afefa8

ℹ️ 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 152ca70 into unslothai:main Nov 17, 2026
danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 18, 2026
…ce name Unsloth Studio shows for NPU models (unslothai#18048)

`unsloth run --model` and `unsloth chat` only knew an NPU model by its
Lemonade id (`qwen3.6-moe-35b-a3b-FLM`) or `lemonade:<id>`. Since unslothai#17610
the app names NPU models by their Hugging Face repo
(`Qwen3.6-35B-A3B-NPU2`), so typing the name you see in Unsloth Studio,
or its repo id `FastFlowLM/Qwen3.6-35B-A3B-NPU2`, went down the GGUF
path and failed with an AutoConfig error on
`unsloth/Qwen3.6-35B-A3B-NPU2`.

### The fix
- `npu_model_path` (`unsloth_cli/_npu.py`) also routes names ending in
`-NPU<n>` and `FastFlowLM/<name>` repo ids to the NPU, case-insensitive.
Anything else with a slash is still a Hugging Face repo.
- `prepare_npu_model` resolves the name against `/api/npu/models`,
matching each row's id, `hf_repo` and repo name. `hf_repo` is the field
the app's display names come from (`npu_backend.catalog`, read from
FastFlowLM's `model_list.json`), so there's no second name table. It
returns the `lemonade:<id>` that `unsloth run` and
`connect_studio_server` then load.
- A near miss gets the closest names (`No NPU model named
Qwen3-0.6B-NPU3. Did you mean: Qwen3-0.6B-NPU2, Qwen3.5-0.8B-NPU2,
Qwen3-1.7B-NPU2?`). A name two catalog rows share (FastFlowLM's flash
builds reuse the base build's repo, e.g. `Qwen3.5-2B-NPU2`) asks for the
id instead of guessing.
- `unsloth/Qwen3-0.6B-GGUF` still loads as a GGUF, although FastFlowLM's
`qwen3-core:0.6b` downloads from that same repo.

### Tests
`unsloth_cli/tests/test_npu_cli.py`: display name, repo id and lowercase
forms resolve to the id; a resolved name downloads by its id; near
misses suggest; a shared repo asks for an id; `unsloth/Qwen3-0.6B-GGUF`
stays GGUF; `connect_studio_server` loads the resolved id. 15 of the new
cases fail on main. Full `unsloth_cli/tests`: 2679 passed, 4 failed in
`test_doctor_mcp.py`, which fail the same on main.

### Hardware
| machine | kernel | amdxdna / NPU fw | FLM / Lemonade | commit |
|---|---|---|---|---|
| AMD DevLab Strix Halo (Ryzen AI MAX+ 395, Radeon 8060S, NPU Strix
Halo), Ubuntu 24.04.5, run
[43971387783](https://github.com/oobabooga/unsloth/actions/runs/43971387783)
| 7.0.0-43-generic | 2.25.260102.56 / 1.1.2.65 | 1.0.12 / 2026.44.1 |
main e73b085 vs branch 1dc36f4, same job |
| same pool, run
[43974562934](https://github.com/oobabooga/unsloth/actions/runs/43974562934)
(Qwen3.6 35B) | 7.0.0-43-generic | 2.25.260102.56 / 1.1.2.65 | 1.0.12 /
2026.44.1 | main e73b085 vs branch 1dc36f4, same job |

Both legs installed Unsloth Studio with `install.sh --local` into
separate homes on the same runner.

### Before and after

`unsloth run --model Qwen3.6-35B-A3B-NPU2` on main:

![main: unsloth run --model
Qwen3.6-35B-A3B-NPU2](https://raw.githubusercontent.com/LeoBorcherding/unsloth/94ee41b2e097144715d3c64b9654be07150149d8/npu-cli-names/43974562934/01-main-run-qwen3.6-35b-a3b-npu2.png)

On this branch it resolves to `qwen3.6-moe-35b-a3b-FLM`, downloads 20.6
GB, loads on the NPU and serves:

![branch: unsloth run --model
Qwen3.6-35B-A3B-NPU2](https://raw.githubusercontent.com/LeoBorcherding/unsloth/94ee41b2e097144715d3c64b9654be07150149d8/npu-cli-names/43974562934/02-branch-run-qwen3.6-35b-a3b-npu2.png)

(The 64-token cap ran out inside Qwen3.6's reasoning, so `content` is
null; `/no_think` didn't turn it off. The point here is the load and the
200.)

`unsloth chat` with piped stdin, main then branch:

![main: unsloth chat
Qwen3-0.6B-NPU2](https://raw.githubusercontent.com/LeoBorcherding/unsloth/94ee41b2e097144715d3c64b9654be07150149d8/npu-cli-names/43974562934/04-main-chat-display-name.png)

![branch: unsloth chat with the display name, lowercase, and a wrong
name](https://raw.githubusercontent.com/LeoBorcherding/unsloth/94ee41b2e097144715d3c64b9654be07150149d8/npu-cli-names/43974562934/03-branch-chat-display-name.png)

Every case from run 43971387783, `unsloth run --model <name>`
(Qwen3-0.6B, so it runs quickly):

| name | main e73b085 | branch 1dc36f4 |
|---|---|---|
| `Qwen3-0.6B-NPU2` | AutoConfig error: `unsloth/Qwen3-0.6B-NPU2 is not
a local folder and is not a valid model identifier` | `Model loaded:
lemonade:qwen3-0.6b-FLM`, `/v1/chat/completions` replies `hello` |
| `FastFlowLM/Qwen3-0.6B-NPU2` | `Download for
'FastFlowLM/Qwen3-0.6B-NPU2' returned an incomplete snapshot` | `Model
loaded: lemonade:qwen3-0.6b-FLM`, replies `hello` |
| `qwen3-0.6b-npu2` | AutoConfig error on `unsloth/qwen3-0.6b-npu2` |
`Model loaded: lemonade:qwen3-0.6b-FLM`, replies `hello` |
| `unsloth/Qwen3-0.6B-GGUF` | `Model loaded: unsloth/Qwen3-0.6B-GGUF`,
replies `hello` | same, still GGUF |
| `Qwen3-0.6B-NPU3` | AutoConfig error on `unsloth/Qwen3-0.6B-NPU3` |
`Error: No NPU model named Qwen3-0.6B-NPU3. Did you mean:
Qwen3-0.6B-NPU2, Qwen3.5-0.8B-NPU2, Qwen3-1.7B-NPU2?` |

`unsloth chat <name>` against a running Unsloth Studio gave the same
split for the four non-GGUF names. Raw logs:
[npu-cli-names/43971387783](https://github.com/LeoBorcherding/unsloth/tree/94ee41b2e097144715d3c64b9654be07150149d8/npu-cli-names/43971387783).

### Not covered
- Windows (Ryzen AI laptops): the name resolution is plain string
matching against the same `/api/npu/models` response, but no Windows NPU
box ran it.
- A name that isn't NPU-shaped (no `-NPU<n>`, no `FastFlowLM/`, no
`-FLM`) can't be recognised before Unsloth Studio is up, so a typo like
`Qwen3-0.6B` still goes to the GGUF path. FastFlowLM names every build
`-NPU2` today; if that changes, the suffix rule needs it.
- Q4NX models converted on the Export page (unslothai#17636) have no `hf_repo`,
so they resolve by id only.
- `unsloth inference` and `unsloth start` share `npu_model_path`, so
they see the new names too; only `run` and `chat` were driven on
hardware.

---------

Co-authored-by: Daniel Han <[email protected]>
rhsCZ pushed a commit to rhsCZ/unsloth that referenced this pull request Nov 20, 2026
…nslothai#18528)

**Problem:** When the NPU model list fails, the chat model picker hides
the whole NPU section and shows no message. A user with a working NPU
just sees no NPU models. This happened on a Windows laptop where Smart
App Control blocked `lemond.exe`.

**Change:** The picker keeps the NPU section and shows why the list
failed. The backend no longer answers a bare "Internal Server Error" for
three failures. When `lemond` cannot start or stops answering, it
returns a readable error. An unreadable folder of converted models is
skipped, and the list loads.

**Status:** Tested live on the AMD DevLab Strix Halo runners, Linux and
Windows, against `main`.

![Before and
after](https://raw.githubusercontent.com/oobabooga/unsloth/pr-media/pr/npu-list-error/before-after-127033317109.png)

## Why it happens

When `GET /api/npu/models` fails, the error is stored in `listError`.
The Hub shows it, but the composer picker only draws the NPU notice
before the runtime is ready. With no rows, the NPU section is dropped.

Three backend failures also reached the route as unhandled exceptions
(HTTP 500):

- **`lemond` cannot be spawned:** `Popen` raises `OSError`, for example
when Smart App Control refuses `lemond.exe`.
- **`lemond` stops answering after it started:**
`LemonadeServer.request` raises `LemonadeUnavailable`.
- **A folder of converted Q4NX models cannot be read** (unslothai#17636): the
permission checks raise `PermissionError` and fail the whole list.

## Fix

- `composer-model-picker.tsx`, `npu-rows.ts`: Discover shows the NPU
notice when the runtime is not ready or the list failed
(`npuNoticeShown`). The notice already renders `listError`.
- `npu_backend.py`: both `lemond` failures become `NpuError`, so the
route answers 409 with the message. A Windows code integrity refusal
gets the existing `code_integrity_user_message` that `llama-server`
uses, which names Smart App Control. An exit status of 0xC0000602 alone
is reported as a crash, since an ordinary crash can also exit with it.
- `lemonade_server.py`: keeps the exit status of a `lemond` that died
during startup, read before Studio's own kill. One still running at the
deadline is reported as a health check timeout.
- `npu_local_models.py`: an unreadable folder is skipped with a warning.
Files are checked with `lstat()`, so on Python 3.14 a denied file is not
mistaken for a missing one.

## Not changed

- The On Device tab still shows no NPU notice when the list fails.
- Smart App Control still blocks `lemond.exe`. This PR shows the block
and names the fix.

## Testing

Live on DevLab Strix Halo: `main` and `main` plus this PR side by side,
NPU enabled on both.

| Case | `main` | PR |
|---|---|---|
| Healthy list (Linux, Windows) | 50 models | 50 models |
| Unreadable scan folder (Linux) | HTTP 500 | 50 models |
| `lemond` cannot be spawned (Linux, Windows) | HTTP 500 | HTTP 409,
"Lemonade could not start (...): Permission denied / Access is denied" |
| `lemond` killed, list requested while it exits (Linux) | HTTP 500 |
HTTP 409, "Listing NPU models failed: ... Connection refused" |

The DevLab Windows runner has Smart App Control off, so the real refusal
(`winerror` 4551, exit status 0xC0E90002) is covered by unit tests only.

New unit tests in `test_npu_backend.py`, `test_npu_local_models.py` and
`composer-npu-rows.test.ts` cover each case above, the code integrity
messages and the startup timeout. The backend tests fail on `main`. NPU
backend tests: 554 passed, 1 skipped on Python 3.13; the two changed
test files also pass on Python 3.14. Frontend typecheck and picker tests
pass.

---------

Co-authored-by: Daniel Han <[email protected]>
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.

2 participants