Skip to content

[Bug] AMD NPU: convert stock Qwen3.5 GGUFs to Q4NX with the converter fix that stops routing them to the Qwen3 converter - #17521

Merged
danielhanchen merged 3 commits into
unslothai:mainfrom
LeoBorcherding:studio/npu-q4nx-converter-qwen35
Nov 14, 2026
Merged

danielhanchen merged 3 commits into
unslothai:mainfrom
LeoBorcherding:studio/npu-q4nx-converter-qwen35

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Exporting a stock llama.cpp qwen35 / qwen35moe GGUF to Q4NX used the converter pinned at ROCm/FLM_Q4NX_Converter d1d5232. At that commit, stock Qwen3.5 GGUFs (and their mmproj) are routed to the plain Qwen3 converter, and the MTP block leaks in as a bogus extra decoder layer. The conversion also crashes when general.basename is missing, and full-attention layers are guessed as "every Nth layer" instead of read from attn_q.weight.

This bumps the q4k pin to 93b8398 (ROCm/FLM_Q4NX_Converter#25), which fixes all four. It's 2 commits ahead of d1d5232 and is the converter's current main. convert.py is unchanged, so the command Unsloth Studio runs is the same. The q4nx pin for other architectures stays on dd0993c.

Tests

test_install_q4nx_converter.py now asserts the 93b8398 pin (9 passed). A live install of the q4k converter from codeload verified the new sha256 and extracted convert.py.

Tested on Windows 11, Ryzen 9 9950X + 2x R9700, no NPU: unit tests plus a live download and verify of the pinned archive. No Qwen3.5 GGUF was converted end to end, and nothing was run on a Ryzen AI NPU.

Fine-tunes exported from Studio

The pin bump alone fixes stock GGUFs, but not the GGUF Studio writes for a fine-tune. Studio saves the merge into a folder called model, so llama.cpp names the GGUF general.name = "Model" with no general.basename. The 93b8398 converter only runs its Qwen3.5 size detection when the name starts with Qwen3., so these still fail with Unsupported model architecture: qwen35 (at d1d5232 they crashed on the missing basename). The converter README says -f is needed for fine-tunes with a custom name.

convert_gguf_to_q4nx now takes the exported (or base model) config.json. When the GGUF is qwen35 and the config's model_type is qwen3_5 / qwen3_5_text, it asks the pinned converter's own geometry lookup for the family and passes it as the override. MiniCPM-V 4.6 also exports as qwen35, which is why the config decides rather than the GGUF.

It also refuses qwen35 / qwen35moe GGUFs whose linear-attention tensors are merged (attn_qkv_gate, ssm_beta_alpha, from ggml-org/llama.cpp#32102, merged after Studio's current b12340 prebuilt). The pinned converter skips those tensors and still exits 0, writing a model.q4nx with the delta-net projections missing.

Checked with a random-weight Qwen3.5-0.8B (real config and tensor shapes) converted with llama.cpp b12340 and quantized to Q4_K_M, through Studio's own convert_gguf_to_q4nx and the real pinned converter:

GGUF merge base (d1d5232) PR as submitted (93b8398) this branch
fine-tune (name=Model, no basename) AttributeError: 'NoneType' object has no attribute 'lower' ValueError: Unsupported model architecture: qwen35 converts
stock (basename=Qwen3.5) KeyError: 'blk.0.attn_gate.weight' (Qwen3 converter) converts converts
stock, llama.cpp master (merged tensors) KeyError: 'blk.0.attn_qkv_gate.weight' converts, 72 tensors missing, exit 0 refused with a message

The fine-tune and stock conversions on this branch produce a byte-identical model.q4nx (sha256 7ba457b6...), the same file the PR as submitted writes for the stock GGUF. The converter's check_qwen35_family.py against the HF weights: 365 PASS, ALL PASS, no MTP tensors.

The same base-vs-head conversion on the AMD gfx1151 runners (Ryzen AI Max boxes, both with an NPU present but no FastFlowLM installed), each building its own GGUF with llama.cpp b12340:

host merge base this branch checker
Linux, Studio venv from install.sh --local AttributeError: 'NoneType' object has no attribute 'lower' converts (33 s) 365 PASS, ALL PASS
Windows 11, Python 3.12 venv AttributeError: 'NoneType' object has no attribute 'lower' converts (42 s) 365 PASS, ALL PASS

Not run: loading the converted model.q4nx on a Ryzen AI NPU with FastFlowLM.

ROCm/FLM_Q4NX_Converter 93b8398 stops routing stock qwen35 GGUFs to the
plain Qwen3 converter, drops the MTP block that leaked in as an extra
decoder layer, no longer crashes without general.basename, and detects
full-attention layers from attn_q.weight. convert.py is unchanged, so the
CLI Unsloth Studio calls is the same.
@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 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-13T18:20:52.040900Z 53856a9 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. Another round soon, please!

Reviewed commit: 08c6f0ffce

ℹ️ 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 added a commit that referenced this pull request Nov 13, 2026
…al extra (#17687)

## Summary

`Core (HF=latest + TRL=latest)` fails on every PR since TRL 1.18.0 was
released today (for example on the staging runs for #17521, #17534 and
#16421):

```
FAILED tests/_trl_trainer_discovery_shim.py::test_unsloth_patches_experimental_trainers_via_thin_wrappers
AssertionError: experimental *Trainer classes declared in source but not importable: [('async_grpo', 'HarnessAsyncGRPOTrainer')]
```

TRL 1.18 added `trl/experimental/async_grpo/openenv_harness.py`, which
defines `HarnessAsyncGRPOTrainer` and imports the optional `openenv`
package at module level. The CI job does not install `openenv`, so that
one submodule cannot be imported. The inline test (in
`consolidated-tests-ci.yml`) finds every `class *Trainer` in
`trl.experimental.*` by regex, walks the package's submodules to locate
each one, and swallows submodule import errors. So the class is reported
as "declared in source but not importable", as if TRL's public surface
had drifted.

TRL is right, and Unsloth does not patch this trainer. The test already
skips a whole experimental package whose `__init__` needs an optional
dependency (`IMPORT-SKIP`), but it had no equivalent for a single
submodule.

Reproduced with TRL 1.18.0 and transformers 5.23.0: 1 failed, 4 passed.

## Change

In the submodule walk, a `ModuleNotFoundError` for a non-`trl` module
counts as an optional-extra skip, but only when the submodule that
failed is the file declaring the class. It is logged as an `IMPORT-SKIP`
line naming the module and the missing package. Every other case still
lands in `missing`:

- a class that is not defined anywhere;
- a submodule failing for another reason;
- a missing `trl.*` module.

## Testing

Running the inline test extracted from the workflow:

- TRL 1.18.0: 5 passed, with `IMPORT-SKIP
trl.experimental.async_grpo.openenv_harness.HarnessAsyncGRPOTrainer:
needs the optional openenv`.
- TRL 1.17.1: 5 passed, unchanged.
- Sabotage: a `trl/experimental/async_grpo/zz_ghost.py` that raises
`RuntimeError` before declaring `GhostTrainer` still fails with
`[('async_grpo', 'GhostTrainer')]`.
- The workflow YAML parses, and the workflow-content tests
(`test_cache_budget_discipline.py`, `test_pip_cache_naming.py`,
`test_zoo_suite_parallel_isolation.py`, `test_trl_cap_sites.py`): 295
passed, 3 skipped.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 53856a9357

ℹ️ 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 4f21403 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