Repository navigation
[Feature] AMD NPU: Q4NX export only on machines with an AMD NPU and FastFlowLM installed - #17522
Conversation
…hosts The converter runs on the CPU and neither /api/export/convert/q4nx nor the export npu_q4nx path checks for an NPU, so a GPU box can build Q4NX for a Ryzen AI PC. Show the export toggle and the convert card regardless of NPU status and say converting works on any machine.
|
@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: 906b712a87
ℹ️ 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".
| ) | ||
|
|
||
|
|
||
| @_shared_settings_router.get("/q4nx-export", response_model = Q4nxExportResponse) |
There was a problem hiding this comment.
Keep the caller account when reading Q4NX settings
When a managed account requests this endpoint on a supported-NPU host, _shared_policy_read binds its context to OWNER before the handler runs. Consequently, the managed_account() check in _q4nx_export_response() is false and the response returns npu_supported: true, exposing hardware information that /api/npu/status deliberately redacts. The new helper-only test bypasses this router dependency and misses the issue. Register this read on _account_settings_router—the setting getter already reads as OWNER—or otherwise preserve the authenticated caller for the redaction.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 87cd314: the read now sits on the account router, so the managed caller's context reaches the redaction; the test goes through the registered route.
…account sees no NPU [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: 87cd3140e0
ℹ️ 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".
| const settings = fromApi(await res.json()); | ||
| useQ4nxExportStore.setState({ settings }); |
There was a problem hiding this comment.
Discard Q4NX reads that predate a successful save
When the Resources panel mounts with cached settings, such as after visiting Export, its initial GET runs while the Q4NX switch is already interactive. If that GET reads the old value but completes after a successful toggle PUT, this unconditional publication overwrites the saved response. On a host without an NPU, enabling Q4NX can therefore leave the switch off and the export controls hidden until another load; disabling it can instead restore controls whose requests now receive 403. Invalidate outstanding reads when saving, or use a request generation so stale GET responses cannot replace newer saved settings.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a1fab1b: a read that started before a save no longer publishes over it; test fails without the guard.
…erwrite it [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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". |
|
@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: dacc2a2d03
ℹ️ 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".
| """Never raises: a failed probe counts as no NPU.""" | ||
| try: | ||
| from core.inference.npu_backend import get_npu_backend | ||
| status = get_npu_backend().status() |
There was a problem hiding this comment.
Preserve managed-account redaction in the Q4NX export gate
For managed-account requests, this reads the real installation status rather than the redacted supported/ready values returned by routes/npu.py:npu_status. The newly gated /api/export/convert/q4nx provides a separate availability probe: an otherwise workspace-valid request with neither GGUF source returns 400 on a supported, ready host but 403 otherwise, revealing the owner's NPU/runtime availability without performing a conversion. Hiding the frontend controls does not prevent this API-level disclosure. Reject managed callers before consulting the raw status, and cover this distinction in a route-level test.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 554530d: the gate now refuses a managed account with the same 403 as a machine without an NPU, so the answer matches the redacted /api/npu/status. Route test covers owner vs managed on a ready NPU.
…atching the redacted NPU status [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
… LoRA and Q4NX into tabs (unslothai#17717) The Export page stacked its flows as cards (Source, Export method, "Export an image LoRA", "Convert a GGUF to Q4NX (AMD NPU)"), so the image LoRA and Q4NX flows sat below the whole LLM form. This puts each flow behind its own tab under the page header. ## What changed - A tab bar under the "Export" title, using the app's existing `Tabs` component (`components/ui/tabs.tsx`): 1. **LLM**: the existing Source + Export method flow and its summary card. 2. **Diffusion LoRA**: the image LoRA export card. 3. **Convert to Q4NX**: main's Q4NX model-picker card, next to its own Export summary card (model, GGUF file, quant, original model, save directory, estimated size, NPU memory, quick guide). No Export button there: the card converts with its own Convert button. The tab only shows when main's gate passes (a supported AMD NPU with FastFlowLM ready); a stale `q4nx` selection falls back to LLM. - Subtitle is now "Export models and adapters for deployment, or convert GGUFs for AMD NPUs". - Card contents are as main has them. Each flow is a real tab panel (`TabsContent`, `forceMount`), hidden while inactive rather than unmounted, so a running export or conversion keeps its state when you switch tabs. - An `?imageLora=` deep link from a finished training run opens on the Diffusion LoRA tab. Starting the guided tour switches to the LLM tab, since the tour only walks that flow. - New `exportTabs` i18n keys in `en.ts` and every overlay (`npm run i18n:check:strict` passes). ## Merge of main Merged main at `d2d8823325` (the NPU phase PRs had landed and the page conflicted). Main's Q4NX picker card (unslothai#17515) and the NPU-and-FastFlowLM gate (unslothai#17522) are kept as is. Main switched one shared summary card between the LLM flow and the Q4NX card by tracking which card you last clicked; with tabs that tracking has nothing to do, so it's dropped and the Q4NX tab renders its own summary from the card's `onSummary`. The loading and error fallback that rendered both extra cards above the LLM form is gone too, since each card now lives in its own tab regardless of checkpoint state. `tests/export-q4nx-npu-gate.test.ts` now counts the gated Q4NX tab trigger and panel instead of two `<Q4nxConvertCard>` sites. ## Tests All at `5b74aa2973`. Codex: "Didn't find any major issues" at this commit on the mirror, LeoBorcherding#886 ([comment](LeoBorcherding#886 (comment))). - `tsc -b`: clean - `tsc -p tsconfig.test.json --noEmit`: clean - `npm run i18n:check:strict`: all overlays pass - `tests/export-page-tabs.test.ts` (tab fallback without an NPU, one trigger and one panel per tab, each card rendered once, image LoRA deep link opens its tab) - Export page tests (`tests/export-*.test.ts`, `image-lora-export-handoff`, `finetune-export-branches`, `reload-snapshot`, `chat-only-full-install`): 123/123 pass - Full frontend suite (`npm test`): 16456 pass, 0 fail, 1 skipped ## Tested on a Strix Halo NPU | | | |---|---| | Machine | AMD DevLab runner `X2-LA03-S04-D04`: Ryzen AI MAX+ 395, Radeon 8060S, XDNA2 NPU, 124 GiB | | OS / kernel | Ubuntu 24.04, `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 (installed by Unsloth Studio) | | Commit | `5b74aa2973`, installed with `install.sh --local` | | Run | [oobabooga/unsloth run 43897124471](https://github.com/oobabooga/unsloth/actions/runs/43897124471) | What ran, headless Chromium at 1440x1000, mint theme, glass on, light mode, no chats: 1. LLM tab with `unsloth/Qwen3-0.6B` picked from the Hugging Face source and GGUF Q4_K_M selected: summary reads Ready, ~343 MB. 2. Diffusion LoRA tab as it shows on a box with no image LoRAs. 3. A real conversion through the Q4NX card: `unsloth/Qwen3-0.6B-GGUF`, file `Qwen3-0.6B-Q4_1.gguf`, original model `Qwen/Qwen3-0.6B`. It finished in under 30 s and wrote `q4nx/Qwen3-0.6B-Q4_1-q4nx` (`model.q4nx`, `tokenizer.json`, `tokenizer_config.json`). 4. The converted `model.q4nx` is byte-identical to FastFlowLM's own published `Qwen3-0.6B-NPU2/model.q4nx` (both sha256 `db8dec4d…53fa667`, 683,820,832 bytes). Unsloth Studio only loads NPU models from FastFlowLM's catalog, so the job copied the converted files into that catalog folder (a no-op, same bytes), loaded `qwen3-0.6b-FLM` on the NPU from Unsloth Studio, and asked one question from the chat page with temperature forced to 0 (the UI's 0.6 rewritten on the request). Reply: "The capital of France is Paris.", 112.6 tok/s. The folder's hash was unchanged after the chat. Not covered here: Q4_0 conversion (still broken on main), Q4_K_M re-quantization, Windows, and the NVIDIA path (the tab is hidden there by main's gate, which the unit test covers). ## Screenshots **LLM**, Hugging Face model picked  **Diffusion LoRA**  **Convert to Q4NX**, nothing picked  **Convert to Q4NX**, Q4_1 picked, convert settings open  **Converting**  **Done**  **The result loaded on the NPU and chatting** (temperature 0)  ## Before / after on a host without an AMD NPU Main at the merge base (`d2d8823325`) vs this PR (`729950ad5f`), two isolated Studio installs, Chromium at 1440x1000. No NPU on this host, so the Q4NX tab and the AMD NPU subtitle clause stay hidden on both sides. LLM flow: the page now opens on the LLM tab, with "LLM" and "Diffusion LoRA" as the only tabs.  Image LoRA flow: stacked under the LLM form before, its own tab after.  --------- Co-authored-by: Daniel Han <[email protected]>
…the NPU model list (unslothai#17636) 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 (unslothai#17521, unslothai#17515, unslothai#17522, unslothai#17533, unslothai#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](https://github.com/oobabooga/unsloth/actions/runs/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 (unslothai#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**  --------- Co-authored-by: Daniel Han <[email protected]>
Q4NX export is an AMD NPU feature, but nothing on the server enforced that: the export page hid the Q4NX controls on machines without an NPU, while
/api/export/ggufwithnpu_q4nxand/api/export/convert-q4nxaccepted the request on any machine and downloaded the converter. The page also showed Q4NX on an NPU machine before FastFlowLM was installed.This makes Q4NX export available only on a machine with a supported AMD Ryzen AI NPU and FastFlowLM installed (
/api/npu/statussupportedandready), and nowhere else, NVIDIA included:utils/q4nx_export_gate.py:q4nx_export_allowed()reads the NPU backend status; a failed probe counts as no NPU.The earlier opt-in for machines without an NPU (Settings > Developer mode) is dropped: NPU features stay off on every machine without an NPU.
Tests
test_export_q4nx_accounts.py: the gate across supported / ready combinations, a failed probe, and a refused request that never authorizes a Hub repo; the existing managed-account workspace tests still pass (33 passed withtest_export_npu_q4nx.py).export-q4nx-npu-gate.test.ts: the page's single gate requires bothsupportedandready.