Skip to content

[Bug] AMD NPU: Q4NX export accepts any model of a supported architecture, so Llama 3.3 70B, Gemma 4 26B-A4B and Qwen3.5-122B convert into files FastFlowLM can't run - #17533

Merged
danielhanchen merged 5 commits into
unslothai:mainfrom
LeoBorcherding:studio/npu-q4nx-geometry-gate
Nov 14, 2026

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

The Q4NX export only looked at a GGUF's general.architecture. FastFlowLM ships NPU kernels per model size, not per architecture, so a llama GGUF of Llama 3.3 70B or a Llama-format phi-4 14B converted into a model.q4nx nothing can run. A gemma4 26B-A4B GGUF failed partway through the converter (its MoE tensors have no name map), and a qwen35moe 122B-A10B GGUF got the 35B-A3B config applied.

Before installing or running the converter, the export now reads the GGUF's layer count, hidden size and expert count and checks them against the models FastFlowLM has AIE2P kernels for (the src/xclbins/*-NPU2 catalog models, geometry from their config.json). An unsupported size is refused with a message naming the nearest sizes that architecture runs, e.g. "FastFlowLM has no AMD NPU kernels for this gemma4 model (30 layers, hidden size 2816, 128 experts). The gemma4 sizes it runs, nearest first: Gemma 4 E4B, Gemma 4 12B, Gemma 4 E2B." Architectures outside the table, and Qwen3.5 Omni, are left to the converter as before.

Tests

test_export_npu_q4nx.py writes real GGUF headers. Six unsupported sizes are refused before the installer runs (Llama 70B, phi-4 14B, Gemma 4 26B-A4B and 31B, Qwen3.5-122B-A10B, Qwen3.5 27B). Seven supported or unlisted ones still convert (Qwen3.5 9B with and without its MTP block, Omni, Qwen3.6 35B-A3B, Llama 3.1 8B, gpt-oss 20B, an unlisted architecture).

Tested on Windows 11, Ryzen 9 9950X + 2x R9700, no NPU: the backend Q4NX tests, plus the gate run on the headers of the Hub GGUFs for Qwen3.5-0.8B, Qwen3.6-35B-A3B, Gemma 4 E2B (accepted) and Gemma 4 26B-A4B (refused). 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 3 3669e68 | phase 4 49a3094. This PR's head f9ebef8 is part of 49a3094. Light mode, mint theme, glass on, same on both sides.

Before | after: unsloth/SmolLM2-135M-Instruct-GGUF Q4_K_M is refused with the reason and the nearest llama sizes FastFlowLM runs; before, it "converted" into a Q4NX the NPU can't run.
17533

danielhanchen added a commit that referenced this pull request Nov 11, 2026
…-transformers pin scan (#17547)

## Summary

`Repo tests (CPU, studio-install)` can fail on any PR, depending on what
runs at the same time on the other xdist workers (seen on #17533):

```
tests/studio/install/test_sentence_transformers_pin.py:47: in test_pinned_sentence_transformers_can_log_with_the_pinned_transformers
E   FileNotFoundError: [Errno 2] No such file or directory: '.../studio/backend/requirements/single-env/.data-designer-deps-filtered-bpfrp0a_.txt'
```

`install_python_stack._filter_requirements` writes a hidden
`.<stem>-filtered-*.txt` copy beside its source file, so relative
`-r`/`-c` lines still resolve, and the installer deletes it again
afterwards. Tests that drive the installer do this inside the repo's own
`studio/backend/requirements` tree. The pin test added in #17311 walks
that tree with `rglob("*.txt")` and reads every match, so when another
worker's copy disappears between the walk and the read, it fails.

The installer is right to put the copy there, and the pin check itself
is right. The scan just has to ignore those copies, the same way its
sibling scans already do (`test_transformers_tokenizers_pair.py` skips
dot-named files, and `test_diffusers_pin.py` skips the `-filtered-`
pattern).

## Change

- `tests/studio/install/test_sentence_transformers_pin.py`: the scan now
goes through a `_requirement_files()` helper that skips dot-named files.
- New `test_a_filtered_copy_vanishing_mid_scan_is_not_read`: it plants a
dangling `.data-designer-deps-filtered-*.txt` link (a copy deleted
mid-scan) next to a real file and checks that the scan skips it. Without
the skip, that test fails with the CI error.

No library code changes.

## Testing

- `test_sentence_transformers_pin.py`,
`test_transformers_tokenizers_pair.py`, `test_diffusers_pin.py`: 76
passed.
- With the skip removed,
`test_a_filtered_copy_vanishing_mid_scan_is_not_read` fails.
@danielhanchen danielhanchen self-assigned this Nov 13, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 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-13T15:41:02.328870Z f4bead9 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: f4bead9014

ℹ️ 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".

# Conflicts:
#	studio/backend/core/export/q4nx.py

[skip ci]
@danielhanchen
danielhanchen merged commit 826fe9a into unslothai:main Nov 14, 2026
oobabooga pushed a commit to oobabooga/unsloth that referenced this pull request Nov 17, 2026
…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**
![Q4NX
files](https://raw.githubusercontent.com/LeoBorcherding/unsloth/14512efb26082aaaa40a9688fab7f15b69a84fef/npu-17636/v2/01-export-q4nx-files.png)

**Convert settings, Q4_1**
![Q4NX
settings](https://raw.githubusercontent.com/LeoBorcherding/unsloth/14512efb26082aaaa40a9688fab7f15b69a84fef/npu-17636/v2/02-export-q4nx-settings.png)

**Converting**

![Converting](https://raw.githubusercontent.com/LeoBorcherding/unsloth/14512efb26082aaaa40a9688fab7f15b69a84fef/npu-17636/v2/03-export-q4nx-converting.png)

**Done**

![Done](https://raw.githubusercontent.com/LeoBorcherding/unsloth/14512efb26082aaaa40a9688fab7f15b69a84fef/npu-17636/v2/04-export-q4nx-done.png)

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

![Picker](https://raw.githubusercontent.com/LeoBorcherding/unsloth/14512efb26082aaaa40a9688fab7f15b69a84fef/npu-17636/v2/05-picker-npu-converted.png)

**Loaded, temperature 0**
![Run
settings](https://raw.githubusercontent.com/LeoBorcherding/unsloth/14512efb26082aaaa40a9688fab7f15b69a84fef/npu-17636/v2/06-run-settings-temperature-0.png)

**Chat on the NPU**

![Chat](https://raw.githubusercontent.com/LeoBorcherding/unsloth/14512efb26082aaaa40a9688fab7f15b69a84fef/npu-17636/v2/07-chat-npu-reply.png)

**Reply stats**

![Stats](https://raw.githubusercontent.com/LeoBorcherding/unsloth/14512efb26082aaaa40a9688fab7f15b69a84fef/npu-17636/v2/08-chat-npu-reply-stats.png)

---------

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