Skip to content

[Bug] AMD NPU: Qwen3.5 Q4NX exports fail to load in FastFlowLM - #17759

Merged
danielhanchen merged 1 commit into
mainfrom
studio/npu-q4nx-qwen35-q4k
Nov 14, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
studio/npu-q4nx-qwen35-q4k

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Exporting a Qwen3.5 GGUF to Q4NX produced a file FastFlowLM cannot run. Checked on a real Ryzen AI NPU (Strix Halo, FastFlowLM 1.0.12, Lemonade 2026.44.1) by converting the stock unsloth/Qwen3.5-0.8B-GGUF Q4_K_M through Studio's own convert_existing_gguf, putting the result in place of FastFlowLM's Qwen3.5-0.8B-NPU2/model.q4nx, loading it and asking for one word:

q4k converter Windows 11 Linux (amdxdna)
FastFlowLM's own file (control) Hello! Hello!
main (93b8398) Weight not found: model.layers.0.linear_attn.ssm_alpha_proj.bf16.weight FastFlowLM aborts in qwen3_5vl_desc::load_linear_weights (exit 134)
93b8398 with the bf16 prefill copies written (ROCm/FLM_Q4NX_Converter#22) loads, answers //////////////// same abort
ROCm/FLM_Q4NX_Converter#26 head ea1df7e loads, answers //////////////// same abort
ea1df7e with ssm_out packed as Q4_K in the 0.8B config (this PR) Hello. Hello!

The last row writes 560,985,936 bytes, the same size as FastFlowLM's own file.

The same base-vs-head run on Qwen3.5-2B (stock unsloth/Qwen3.5-2B-GGUF Q4_K_M), both OSes: FastFlowLM's file answers Hi; main writes 1,358,335,544 bytes and FastFlowLM fails to start; this PR writes 1,339,269,144 bytes and answers Hi. The rest of the real-NPU run (enable, catalog, download, load, chat, pins, cancel / resume) is unchanged between base and head on both OSes.

What changes

  • The q4k pin moves to ea1df7e, the head of qwen3.5: encode Q4_K targets and emit the bf16 prefill copies ROCm/FLM_Q4NX_Converter#26 (on top of 93b8398). It writes the bf16 copies of ssm_alpha/beta_proj that FastFlowLM 1.0.11+ requires and encodes Q4_K targets instead of downgrading them to Q4_1. codeload serves the commit from the ROCm repo URL, and the archive sha256 is pinned as before.
  • Paged_adam8_bit has casting issues #26 switches only the 9B config to Q4_K. The 4B and 9B configs pack linear_out_proj (ssm_out) as Q4_K, but 0.8B and 2B still say Q4_1. A new config_overrides entry in q4nx_converter_pins.json sets those two after the hash-checked archive is extracted. It is recorded in the install marker, so a changed override reinstalls, and an override naming a key the config lacks refuses to install.
  • The q4nx pin (other architectures) is unchanged.

Tests

tests/studio/install/test_install_q4nx_converter.py: 12 passed (overrides applied, changed overrides reinstall, a missing key installs nothing, shipped pins). Backend Q4NX export tests: 75 passed.

The export stays behind the NPU + FastFlowLM gate, so NVIDIA and other machines never download the converter.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: 🔄 Running

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-11-14T12:51:38.043424Z 82dbca3 PR opened
ℹ️ 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

chatgpt-codex-connector Bot commented Nov 14, 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-14T12:53:27.074541Z 82dbca3 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 82dbca307a

ℹ️ 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 7c11539 into main Nov 14, 2026
@danielhanchen
danielhanchen deleted the studio/npu-q4nx-qwen35-q4k branch November 14, 2026 13:30
danielhanchen added a commit to LeoBorcherding/unsloth that referenced this pull request Nov 17, 2026
… models that read another layout, so Qwen3.5 from a Q4_0 GGUF answers with repeated slashes (unslothai#18064)

A Q4_0 GGUF of Qwen3.5-4B converts to Q4NX in Unsloth Studio without an
error, loads on the AMD NPU, and answers "hello" with nothing but `/`.
This makes the converter refuse that source with a message, and the
export falls through to the next selected quant that fits.

![main: Q4_0 answers with
slashes](https://raw.githubusercontent.com/LeoBorcherding/unsloth/ff6a7b823d99bb08fe385403bd1477011157c957/q4nx-srcquant/main-qwen35-4b-q4_0-06-chat-reply.png)

## Cause

Both pinned ROCm/FLM_Q4NX_Converter commits pack a Q4_0, Q4_1 or Q8_0
tensor (the `q4k` one also Q4_K) in its own layout, whatever the model's
config targets for that slot. `GGUFTensor.get_used_quantization_type`
returns the source type for those, and `unpack` passes the blocks
through. FastFlowLM reads each slot as the config says:

| config reads | models | what goes wrong |
|---|---|---|
| Q4_0 (signed nibbles) | Qwen2 / Qwen2.5, LFM2 | a Q4_1 or Q8_0 source
is read as noise |
| Q4_1 (unsigned plus a min) | Qwen3, Llama, Gemma 3/4, Phi-4 mini,
gpt-oss, Nanbeige, Qwen2.5-VL, Qwen3-VL | a Q4_0 or Q8_0 source is read
as noise |
| Q4_K (super-blocks) | Qwen3.5 0.8B to 9B, 35B-A3B (`q4k` pin
`ea1df7e`) | `unpack` re-encodes to a Q4_K triple, but the slot is then
packed with `tensor_type=Q4_0` (the source type), so the bytes are
neither |

Nothing errors at any step. The stock `unsloth/Qwen3.5-4B-GGUF` Q4_0 has
172 Q4_0 and 4 Q4_1 tensors, so almost every weight is wrong.

## Fix

- `core/export/q4nx.py`: the converter subprocess patches
`GGUFTensor.unpack` to compare the type the converter will pack (its own
`get_used_quantization_type`) with the target. On the first quantized
mismatch among Q4_0 / Q4_1 / Q4_K / Q8_0 it prints the tensor, both
types and what to use instead, and exits 3, which is raised as
`SourceMismatch`. Floats, MXFP4 (gpt-oss experts) and anything the
converter re-quantizes itself are untouched. The rule was checked
against the real `GGUFTensor` at both pins (`dd0993c`, `ea1df7e`,
archive hashes match `q4nx_converter_pins.json`): `dd0993c` refuses
Q4_0/Q4_1/Q8_0 into a different 4- or 8-bit target, and `ea1df7e`
additionally Q4_K into a Q4_0/Q4_1 slot (the 0.8B `ssm_out` case unslothai#17759
fixed by config override) but not Q4_0 into a Q8_0 slot, which it
re-quantizes.
- `core/export/export.py`: the GGUF export with "Q4NX" ticked tries each
selected source quant in turn, the ones the architecture's converter
packs as is first, and moves on when one is refused.
`DIRECT_QUANTS["q4k"]` is now Q4_K_M only.
- Export page Q4NX card: a Q4_0 or Q4_1 the model reads in another
layout is tagged "won't convert", sorted last, explained in red, and the
summary says "Convertible: No". Which layout each architecture reads
mirrors the converter configs (`qwen2`, `lfm2` read Q4_0; `qwen35`,
`qwen35moe` Q4_K; the rest Q4_1). When the architecture isn't known yet,
nothing changes and the converter decides.

## Real NPU, main vs this branch

AMD DevLab Strix Halo runner on oobabooga's fork: Ryzen AI MAX+ 395
(Radeon 8060S), NPU Strix Halo (XDNA2, amdxdna 2.25.260102.56, firmware
1.1.2.65), Ubuntu 24.04.5, kernel 7.0.0-43, FastFlowLM 1.0.12, Lemonade
2026.44.1. Run
[44003434291](https://github.com/oobabooga/unsloth/actions/runs/44003434291),
one job, both legs on the same host, driven through the Export page and
the chat with Playwright (temperature 0).

Both legs carry unslothai#17636 (open), which is what lists a converted model in
the NPU picker. before = upstream main `9034f08c29` + unslothai#17636
`f39b6f687d` (`56b0ddfde7`); after = that + this PR's `9b42b59706`
(`b6c8be8e95`). The head has since moved to `2c6ed1d3bb`, which only
changes the summary's "Convertible" text on the card.

| source | before | after |
|---|---|---|
| `unsloth/Qwen3.5-4B-GGUF` Q4_0 | converts in 112 s, loads, answers
"hello" with `/` until stopped at 15 min | refused in 28 s:
`blk.0.attn_gate.weight is Q4_0, which the Q4NX converter packs as is
into a model that reads Q4_K there, so FastFlowLM would read noise.
Convert a Q4_K_M GGUF instead.` |
| `unsloth/Qwen3.5-4B-GGUF` Q4_K_M | (not run) | converts in 97 s, loads
in 6 s, answers `Hello! How can I help you today?` at 13.4 tok/s |
| `unsloth/LFM2-1.2B-GGUF` Q4_0 (a model that reads Q4_0) | (not run) |
converts in 16 s, not refused. The chat step didn't run: the harness
looked for a "Select model" button that is labelled with the loaded
model's name by then |

<details><summary>Screenshots</summary>

before, Q4_0 converted with no error:

![](https://raw.githubusercontent.com/LeoBorcherding/unsloth/ff6a7b823d99bb08fe385403bd1477011157c957/q4nx-srcquant/main-qwen35-4b-q4_0-03-converted.png)

before, streaming:

![](https://raw.githubusercontent.com/LeoBorcherding/unsloth/ff6a7b823d99bb08fe385403bd1477011157c957/q4nx-srcquant/main-qwen35-4b-q4_0-05-chat-streaming.png)

after, Q4_0 refused on the card:

![](https://raw.githubusercontent.com/LeoBorcherding/unsloth/ff6a7b823d99bb08fe385403bd1477011157c957/q4nx-srcquant/branch-qwen35-4b-q4_0-03-refused.png)

after, Q4_K_M answers:

![](https://raw.githubusercontent.com/LeoBorcherding/unsloth/ff6a7b823d99bb08fe385403bd1477011157c957/q4nx-srcquant/branch-qwen35-4b-q4_k_m-06-chat-reply.png)

after, LFM2-1.2B Q4_0 converts:

![](https://raw.githubusercontent.com/LeoBorcherding/unsloth/ff6a7b823d99bb08fe385403bd1477011157c957/q4nx-srcquant/branch-lfm2-1.2b-q4_0-03-converted.png)

</details>

Not covered: Windows, a Q4_1 source into Qwen2.5 or LFM2, a Q4_0 source
into a `q4nx`-converter model such as Qwen3 on the NPU (the unit tests
and the per-pin check cover the rule, no NPU run did), and a coherent
LFM2 Q4_0 answer.

## Tests

- `studio/backend/tests/test_export_npu_q4nx.py`: the real
`_RUN_CONVERTER` script against a stub converter whose
`get_used_quantization_type` mirrors each pin (22 source/target cases
across `q4nx` and `q4k`), the export falling through a refused source
and reporting the last refusal, `SourceMismatch` from exit 3, and Q4_K_M
first for Qwen3.5. 77 passed. `test_export_q4nx_accounts.py` +
`test_export_gguf_discovery.py`: 57 passed.
`tests/studio/install/test_install_q4nx_converter.py`: 12 passed.
- `studio/frontend/tests/export-q4nx-source.test.ts`: per-architecture
packing, sort order, summary rows. Full frontend suite 16469 passed;
`npm run typecheck` clean.

## Related

- unslothai#10330 is the same `////` symptom on Strix Halo, but through llama.cpp
with a GGUF, not Q4NX, so it is not this cause.
- ROCm/FLM_Q4NX_Converter#9: a Q8_0 Qwen2.5-Coder conversion "gives
gibberish" while Q4 works, which matches the Q8_0-into-Q4_0 pass-through
above.
- unslothai#17636 lists converted Q4NX models in the NPU picker; unslothai#17759 bumped
the `q4k` pin and overrode the 0.8B/2B `ssm_out` slot.

---------

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant