Repository navigation
[Bug] AMD NPU: models larger than the memory the NPU can map download fully, then fail at load with no warning - #17531
Merged
danielhanchen merged 9 commits intoNov 14, 2026
Conversation
This was referenced Nov 11, 2026
This was referenced Nov 12, 2026
Merged
Merged
…e so Auto context can share them
[skip ci]
danielhanchen
pushed a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Nov 13, 2026
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. |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
LeoBorcherding
added a commit
that referenced
this pull request
Nov 13, 2026
…2 tokens (#17511) NPU models always loaded at 8192 tokens. Auto now sizes the context to free RAM, like GGUF's host-RAM Auto: free RAM less 2 GiB and the weights, priced per token from FastFlowLM's bf16 KV on full-attention layers plus its default prefix cache. Largest multiple of 1024 that fits, capped at 65536 or the model limit, floor 8192. Pins still win, with a warning above the estimate. A reload releases the old model before sampling RAM. Engine caps below the checkpoint limit: Qwen3.8 27B MTP and DFlash2 at 8192 (ROCm/FastFlowLM#1001), Qwen3 0.6B to 8B and LFM2.5 1.2B at 32768 (FastFlowLM 1.0.12 model cards). On a 31.8 GiB Strix Halo with 23.9 GiB free: qwen3.5-9b 65536, qwen3.6-moe-35b-a3b 8192, qwen3.8-mtp-27b 8192. Follow-up, not here: cap Auto at the memory window the NPU can map (about half of RAM on Windows), once #17531's `npu_memory_window_gb` is in. Tested on Windows 11, Ryzen 9 9950X, no NPU: backend and frontend tests only, no NPU load. ## Screenshots Spoofed NPU (fake Lemonade/FastFlowLM, no NPU). Run settings now says Context Length "Auto" instead of a flat 8192.  Also checked by building Unsloth Studio from this PR's merge base (left) and head (right), on the same spoofed AMD NPU: Chat > run settings of qwen3-0.6b-FLM: Context Length defaults to Auto, which fits up to FastFlowLM's 32k card limit, instead of a fixed 8192. On a real XDNA2 NPU the Auto load went from 8192 to 32768 and a 40960 pin was clamped to 32768.  --------- Co-authored-by: oobabooga <[email protected]> Co-authored-by: imagineer99 <[email protected]> Co-authored-by: Daniel Han <[email protected]>
danielhanchen
added a commit
to LeoBorcherding/unsloth
that referenced
this pull request
Nov 14, 2026
…t in the picker and Hub (unslothai#17513) The NPU section of the model picker (and the Hub's NPU list, which shares `npuRowsFor`) showed Lemonade's order: downloaded models first, then alphabetical, so the seven `d3-*` decision models led the list and the newest chat models were buried. NPU models are now ranked by a short curated list: the AMD NPU launch blog's headline models first (Qwen3.6-MoE 35B-A3B, Qwen3.8 MTP 27B and Qwen3.8 DFlash2 27B), then new models that run on a Ryzen AI laptop: Qwen3.5 9B and 4B, Gemma 4 E4B, gpt-oss 20B, LFM3 1.7B, Nemotron 3.5 Bolt E4B, Qwen3-VL 4B, Gemma 4 E2B, Qwen3.5 2B and 0.8B, Phi-4 mini, Llama 3.2 3B. Everything else keeps Lemonade's order after them. The list matches on FastFlowLM checkpoints (`qwen3.5:9b`), so it doesn't depend on Lemonade's id format. The three headline models need about 17 to 22 GB, more than a 32 GB Windows laptop lets the NPU map; unslothai#17531 marks them "May not fit NPU memory" on such machines, so it should land with or before this. Tested: `tests/npu-api.test.ts` (12 pass, ordering test uses real checkpoints) and frontend typecheck on Windows 11, no NPU. ## 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 `221531e` is part of `ac3e06e`. Light mode, mint theme, glass on, same on both sides. Before | after: the picker's NPU list now leads with the launch blog's models, qwen3.6-moe-35b-a3b, qwen3.8-mtp-27b and qwen3.8-dflash2-27b as rows 1 to 3, then the laptop-sized models (qwen3.5-9b, qwen3.5-4b, ...); before, downloaded models sorted first and the d3-* decision models followed. The "May not fit NPU memory" tags elsewhere are unslothai#17531.  Also checked by building Unsloth Studio from this PR's merge base (left) and head (right), on the same spoofed AMD NPU: Model Hub, format NPU: the launch models now lead the NPU list.  --------- Co-authored-by: Daniel Han <[email protected]>
# Conflicts: # studio/backend/core/inference/npu_backend.py # studio/frontend/src/features/hub/catalog/npu-catalog-list.tsx # studio/frontend/src/features/npu/api.ts # studio/frontend/tests/npu-api.test.ts [skip ci]
danielhanchen
added a commit
to LeoBorcherding/unsloth
that referenced
this pull request
Nov 14, 2026
…ead of free-text fields (unslothai#17515) The "Convert a GGUF to Q4NX (AMD NPU)" card on the Export page took the GGUF repo, file and original model as plain text. It now matches the rest of the Export page: - Hugging Face: search GGUF repos (Unsloth first), then pick a file from the repo's .gguf list. Q4_0, Q4_1 and Q4_K_M come first; other quants are listed but marked re-quantized, since the converter dequantizes and rounds them again. - Local file: pick from the on-device GGUF models the app already lists, or type a .gguf path. - The original model fills from the card's `base_model` (the Hub's Base chip) and stays editable. - Hub repos whose GGUF architecture the pinned FLM_Q4NX_Converter doesn't map are hidden; when the architecture is unknown before conversion the card says it may not be supported instead of blocking. The request to `POST /convert/q4nx` and the backend are unchanged. Helpers in `features/export/lib/q4nx-source.ts` are covered by `tests/export-q4nx-source.test.ts`. Tested: typecheck and frontend tests pass on Windows 11. Not yet run in the app. ## Screenshots NPU spoofed: fake Lemonade/FastFlowLM on a Windows 11 PC with no NPU; no speed numbers. After only, built from this PR's head `a21e783` (Unsloth Studio web against the spoof backend, Convert never clicked). Light mode, mint theme, glass on. This branch doesn't have unslothai#17531, so its backend sends no `memory_window_gb`; the captures inject 16.0 GB into `/api/npu/status`, which is what unslothai#17531 reports for the 32 GB of RAM the spoof shows (Windows, half of RAM). Without it the rows show the need with no window. Hugging Face tab: the convert card opens the chat model picker's popover, one row per model with its NPU memory need, "Not convertible" on an unsupported size.  A model expanded to its GGUF files: Q4_0, Q4_1 and Q4_K_M first, the rest tagged re-quantized, each with its NPU memory.  Convert settings page (source quant, original model, save directory) and the export summary describing the conversion.  On Device tab: local GGUFs from the Hugging Face cache.  The chat model picker (left) next to the convert card picker (right): same popover.  ## Before / after (merge base afc8ffb vs head d2f7935) Two isolated Studio installs on Linux, no NPU on the host: `/api/npu/status` is answered as supported with a 16 GB window in the browser so the card renders on both sides. Before: the card takes the GGUF repo, file, original model and save directory as free text. After: a "Select GGUF model" picker; searching "Qwen3-0.6B" lists 35 Hub GGUF repos, each with its NPU memory need (about 1.3 of 16.0 GB), and the export summary describes the conversion.  --------- Co-authored-by: Daniel Han <[email protected]> Co-authored-by: Daniel Han <[email protected]>
# Conflicts: # studio/frontend/src/features/npu/api.ts # studio/frontend/src/features/npu/index.ts # studio/frontend/tests/npu-api.test.ts [skip ci]
# Conflicts: # studio/backend/core/inference/npu_backend.py [skip ci]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Windows the AMD NPU can only map about half of system RAM (lemonade-sdk/lemonade#839; the failure surfaces as ROCm/FastFlowLM#904). Unsloth Studio checked nothing against that: the NPU rows show size only, and download and load go ahead. On a 32 GB Windows laptop, qwen3.8-mtp:27b and qwen3.8-dflash2:27b (about 18 GB) and qwen3.6-moe:35b-a3b (about 22 GB) download fully and then fail at load with a generic error.
The backend now computes an NPU memory window (Windows: half of total RAM; other systems: total RAM minus a 2 GB reserve) and reports it as
memory_window_gbin/api/npu/status. Each catalog model getsmemory_needed_gb(size plus a flat 1 GB for context buffers and the runtime) andfits_memory(nullwhen size or RAM is unknown). The picker row is tagged "May not fit NPU memory", the Hub row shows "Needs about X GB of NPU memory; this PC can give the NPU about Y GB.", and the same text is a warning toast when you download or load such a model. It warns and never blocks: the 50% figure comes from the linked issues, and the 1 GB margin and 2 GB reserve are estimates, none of them measured here.Tests
studio/backend/tests/test_npu_memory_fit.py: with RAM and OS pinned, 32 GB Windows flags all three flagship models, 64 GB Windows flags none, 32 GB Linux uses the reserve rule and flags none, unknown RAM flags nothing, and status reports the window.studio/frontend/tests/npu-api.test.ts: the warning text and tag for a flagged model, and none when the model fits, is unknown, or the backend predates the field.Tested on Windows 11, Ryzen 9 9950X + 2x R9700, no NPU: the backend and frontend unit tests above, with RAM and platform pinned. Not run on a Ryzen AI NPU.
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 1ac3e06e. This PR's head6c8ff92is part ofac3e06e. Light mode, mint theme, glass on, same on both sides.Before | after: the picker tags qwen3.6-moe-35b-a3b and both Qwen3.8 27B models "May not fit NPU memory" (32 GB RAM reported, so about 16 GB for the NPU). The new order on the after side is #17513.

Before | after: Hub rows say what each model needs against what this PC can give the NPU (about 22, 18 and 19 GB against about 16 GB).

Before | after: downloading qwen3.8-dflash2-27b-FLM now warns that it may not load, and still downloads.

Also checked by building Unsloth Studio from this PR's merge base (left) and head (right), on the same spoofed AMD NPU:
Model Hub, format NPU, on a 16 GB machine: models larger than the NPU memory window carry a memory warning.