Repository navigation
[Bug] AMD NPU: Qwen3.5 Q4NX exports fail to load in FastFlowLM - #17759
Conversation
…wen3.5 exports load on the NPU
Codex Review Summary: 🔄 RunningThis 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 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 |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
… 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.  ## 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:  before, streaming:  after, Q4_0 refused on the card:  after, Q4_K_M answers:  after, LFM2-1.2B Q4_0 converts:  </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]>
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-GGUFQ4_K_M through Studio's ownconvert_existing_gguf, putting the result in place of FastFlowLM'sQwen3.5-0.8B-NPU2/model.q4nx, loading it and asking for one word:Hello!Hello!93b8398)Weight not found: model.layers.0.linear_attn.ssm_alpha_proj.bf16.weightqwen3_5vl_desc::load_linear_weights(exit 134)93b8398with the bf16 prefill copies written (ROCm/FLM_Q4NX_Converter#22)////////////////ea1df7e////////////////ea1df7ewithssm_outpacked 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-GGUFQ4_K_M), both OSes: FastFlowLM's file answersHi; main writes 1,358,335,544 bytes and FastFlowLM fails to start; this PR writes 1,339,269,144 bytes and answersHi. 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
q4kpin moves toea1df7e, the head of qwen3.5: encode Q4_K targets and emit the bf16 prefill copies ROCm/FLM_Q4NX_Converter#26 (on top of93b8398). It writes the bf16 copies ofssm_alpha/beta_projthat 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.linear_out_proj(ssm_out) as Q4_K, but 0.8B and 2B still say Q4_1. A newconfig_overridesentry inq4nx_converter_pins.jsonsets 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.q4nxpin (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.