Repository navigation
[Feature] AMD NPU: load Q4NX models converted in Unsloth Studio from the NPU model list - #17636
Conversation
…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.
…size in the entry
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.
…port has no geometry gate
…ts FastFlowLM reads
…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
…s, named by its save folder
# 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
…icker and every NPU display name
|
@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: 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".
| if "model.q4nx" in files: | ||
| dirs[:] = [] |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
…ng lemond under it
…re a GPU model is unloaded [skip ci]
…; bulk delete finds staged copies in any catalog layout [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: 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".
| except OSError: | ||
| shutil.copy2(source, target) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
…copying the weights on every load [skip ci]
…ily when deleting
|
@codex review |
1 similar comment
|
@codex review |
|
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". |
…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:  On this branch it resolves to `qwen3.6-moe-35b-a3b-FLM`, downloads 20.6 GB, loads on the NPU and serves:  (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:   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]>
…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`.  ## 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]>
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 amodel_list.jsonentry (throughFLM_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
7.0.0-43-genericamdxdna2.25.260102.56, NPU firmware 1.1.2.658f5c293fb5: this PR's headd2256204plus the review fixes from the fork mirror (LeoBorcherding#876, to380ee036c4), merged with mainb66e8f498a, 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)What ran, in the real UI with headless Chromium (mint theme, glass on, light mode, no chats):
unsloth/Qwen3-0.6B-GGUF, fileQwen3-0.6B-Q4_1.gguf, original modelQwen/Qwen3-0.6B. Converted in 23 s toq4nx/Qwen3-0.6B-Q4_1-q4nx.Qwen3-0.6B-Q4_1-q4nx("Converted on the Export page").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

Convert settings, Q4_1

Converting

Done

The converted model in the NPU section of the chat picker

Loaded, temperature 0

Chat on the NPU

Reply stats
