Skip to content

[Bug] AMD NPU: Q4NX export packs Q4_0, Q4_1 or Q8_0 blocks as is into models that read another layout, so Qwen3.5 from a Q4_0 GGUF answers with repeated slashes - #18064

Merged
danielhanchen merged 5 commits into
unslothai:mainfrom
LeoBorcherding:studio/q4nx-source-quant-guard
Nov 17, 2026

Conversation

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

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

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 [Bug] AMD NPU: Qwen3.5 Q4NX exports fail to load in FastFlowLM #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, one job, both legs on the same host, driven through the Export page and the chat with Playwright (temperature 0).

Both legs carry #17636 (open), which is what lists a converted model in the NPU picker. before = upstream main 9034f08c29 + #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
Screenshots

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:

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

…rong layout for the AMD NPU

Both pinned FLM converters pack a Q4_0, Q4_1 or Q8_0 tensor (q4k: also Q4_K) in its own layout,
whatever the model's config targets for that slot. FastFlowLM reads each slot as the config says:
Q4_0 signed nibbles for Qwen2 / LFM2, Q4_1 unsigned plus a min for Qwen3, Llama and the rest of
the q4nx converter's models, Q4_K super-blocks for Qwen3.5. So a Q4_0 GGUF of Qwen3.5 or Qwen3,
or a Q4_1 of Qwen2.5, converts without an error and answers with repeated slashes.

The converter run now patches GGUFTensor.unpack to compare the type the converter will pack
(its own get_used_quantization_type) with the target, and exits 3 on the first mismatch. That
is raised as SourceMismatch, and the export tries the next selected source quant, the ones the
architecture's converter packs as is first (Q4_K_M for Qwen3.5). The Export page's Q4NX card
marks a Q4_0 or Q4_1 the model can't read as "won't convert" and sorts it last.
@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 17, 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-17T16:29:50.869700Z 41945de 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. Already looking forward to the next diff.

Reviewed commit: 41945de8ef

ℹ️ 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 b48ca2e into unslothai:main Nov 17, 2026
danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 23, 2026
…n the repo and calls a local Qwen3.5 Q4_0 "packs directly" (unslothai#18522)

The Q4NX source picker on the Export page lists every GGUF file a repo
ships. For `unsloth/Qwen3.5-4B-GGUF` that is 22 files, and only one,
Q4_K_M, packs as is; the other 21 are dequantized and rounded to 4-bit
again, or refused, so the list buries the one file you want.

Separately, an **On Device** GGUF never has its architecture read before
conversion, so a local Qwen3.5 Q4_0 is labeled "packs directly". That is
the file unslothai#18064 refuses, because it answers with
repeated slashes.

**What changes**
- Each model lists the files that pack as is. The rest sit behind "N
more files, re-quantized or not readable by this model". A file you
already picked stays visible.
- `q4nxArchitecture` falls back to the model name when the architecture
is unknown, for the families whose layout isn't the Q4_1 default:
Qwen3.5/3.6 (Q4_K), Qwen2.5 (Q4_0, not VL) and LFM2 (Q4_0). A local
Qwen3.5 Q4_0 now reads "won't convert", Q4_K_M "packs directly".

**Tests:** `export-q4nx-source.test.ts` covers the name fallback and the
short list. Frontend suite and typecheck pass.

**Before / after** on AMD DevLab gfx1151 (Radeon 8060S, XDNA2 NPU),
Ubuntu 24.04, kernel 7.0.0-43, FastFlowLM 1.0.12 / Lemonade 2026.44.1,
measured at `6eb70fd` vs main `33c6179` ([run
44425657543](https://github.com/oobabooga/unsloth/actions/runs/44425657543)).
Export > Convert to Q4NX, `unsloth/Qwen3.5-4B-GGUF` with Q4_K_M picked.

| before (main) | after (this branch) |
|---|---|
| ![before: all 22 GGUF files
listed](https://raw.githubusercontent.com/LeoBorcherding/unsloth/0e78f684bdbbed8569bfabf62afcd42975aa9f85/q4nx-picker/before.png)
| ![after: Q4_K_M listed, 21 more
folded](https://raw.githubusercontent.com/LeoBorcherding/unsloth/0e78f684bdbbed8569bfabf62afcd42975aa9f85/q4nx-picker/after.png)
|

Not run: the On Device path on a real local Qwen3.5 Q4_0 file; that half
is covered by the unit test, not a screenshot.


## Maintainer changes

- Synced with main.
- The name fallback reads only the last path segment, so a parent folder
never names the family (an On Device
`/models/Qwen3.5-comparisons/Qwen2.5-3B-Instruct-Q4_0.gguf` stays
Qwen2.5 and packs directly).
- The Qwen3.5 Omni override reads the same last segment, so
`/models/omni/Qwen3.5-4B-Q4_K_M.gguf` is not treated as Omni.

## Before / after at the current head

Export > Convert to Q4NX, `unsloth/Qwen3.5-4B-GGUF`, two isolated Studio
installs built from the merge base and from this branch (`f71fdf825`).
The NPU status is answered as ready in the browser so the tab renders;
the file listing and packing tags are each build's own.

| before (main): 22 files listed | after: Q4_K_M, then "21 more files,
re-quantized or not readable by this model" |
|---|---|
| ![before: all 22 GGUF files
listed](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/18522/q4nx_before-b58375449237.png)
| ![after: Q4_K_M listed, 21 more
folded](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/18522/q4nx_after-383143bdde94.png)
|

Opening the fold lists the same 22 files as before.

---------

Co-authored-by: oobabooga <[email protected]>
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.

2 participants