Mix precision - #20
Open
vegah wants to merge 2 commits into
Open
Conversation
Q8_0 has no bias term, but _pack_q8nx reserved space for one anyway, emitting scales + zeros + data. FastFlowLM's own builds do not: a 32x256 block is 512 bytes of scales plus 8192 of data = 8704, and the placeholder made it 9216. The mismatch is invisible until the model is loaded. The file is valid safetensors with every expected tensor name and a plausible size, and the runtime then exits during load without printing anything, because the NPU kernels are compiled for a fixed tile layout. Verified against FastFlowLM/Qwen3.5-9B-NPU2: converting the stock Qwen/Qwen3.5-9B now reproduces the published model.q4nx byte-for-byte in size with all 475 tensors matching shape and dtype, and it generates coherent text on an XDNA2 NPU. Also checked against the published 0.8B, 2B and 4B builds, which all use the 8704 layout.
|
Can confirm these fixes; because I did basically the same in my fork and it worked; https://huggingface.co/Atomic-Germ/NuExtract3-4B-NPU2 is a qwen3.5, as is https://huggingface.co/Atomic-Germ/Qwopus3.5-9B-Coder-NPU2 , etc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
maincannot currently produce a loadablemodel.q4nxfor any published Qwen3.5build. The converter runs to completion and writes a file that looks entirely
correct — valid safetensors, every expected tensor name, a size within 0.15 % of
the official build — and FastFlowLM then exits during model load without
printing anything, because the NPU kernels are compiled for a fixed tile
layout.
Two changes are needed to close the gap:
038e67e break: q8nx standard— yours, frommix-precision, unmerged asof this writing. It routes Q8_0 through
_pack_q8nxinstead of_pack_q4nx_8b, which stopscol_block_sizebeing forced 256 → 128 andpadded up to the Q4_1 block size. That alone moves the middle dimension from
32 to 16, matching FastFlowLM. Carried here unchanged; all credit yours.
e5cfd3a— the only new commit in this PR. One leftover remained in thatpath: Q8_0 has no bias term, but
_pack_q8nxstill reserves space for one, somix-precisionon its own still produces a file that will not load.If you would rather land these separately, merging
mix-precisionfirst and thentaking
e5cfd3aon top gives the same result — the two are independent edits tothe same function.
Technical Details
_pack_q8nxemits a placeholder bias block whenm is None:FastFlowLM's own builds reserve no such space. For a 32 × 256 block:
The change drops the placeholder, leaving
[scales, data].For
configs/qwen3.5_9b.jsonthis affects the four tensor families carrying"default_tensor_type": "Q8_0"—linear_alpha_proj,linear_beta_proj,linear_out_projandlm_head. That is 24 GatedDeltaNet layers × 3 plus theoutput head = 73 of 475 tensors. The other 402 (Q4_1) were already correct on
main, which is why the size difference is small enough to be easy to miss.The
8704figure is not specific to the 9B — it holds across the whole publishedQwen3.5 line (see Test Result).
Test Plan
Converted the stock
Qwen/Qwen3.5-9Band compared the output against thepublished
FastFlowLM/Qwen3.5-9B-NPU2:model.q4nxis a safetensors file, so the header can be compared directly —including against published builds over HTTP range requests, without downloading
7 GB:
Then loaded the result on hardware: Ryzen AI 9 HX 370 (XDNA2), FastFlowLM
0.9.4x, registered as a separate model alongside the stock one.
Test Result
Layout matches the published build exactly.
Before the fix, those 73 tensors were
[…, 16, 9216]against the expected[…, 16, 8704]; on unmodifiedmainthey were[…, 32, 5120].The 8704 layout is consistent across every published Qwen3.5 build, read from
their safetensors headers:
lm_head(Q8_0)ssm_out(Q8_0)down_proj(Q4_1)[7760, 4, 8704][32, 8, 8704][32, 14, 5120][7760, 8, 8704][64, 8, 8704][64, 24, 5120][7760, 10, 8704][80, 16, 8704][80, 36, 5120][7760, 16, 8704][128, 16, 8704][128, 48, 5120]Runs on the NPU. Coherent multilingual generation, correct code-switching, no
repetition or token corruption:
This last check matters beyond "it loads": matching shapes only prove the
container is right. A wrong element ordering inside each Q8 block would also
load and then emit fluent nonsense.
Also verified on modified weights. A LoRA fine-tune of the same base, merged
with
llama-export-lora, converts to amodel.q4nxof identical size with all475 tensors matching — as expected, since a LoRA merge only touches Q4_1 tensors
and leaves the 73 Q8_0 ones untouched.
For reference, the one locally-installed model with the old 5120-wide Q8_0
layout is a Qwen3.5-4B at
flm_version 0.9.36, which current FastFlowLM alreadyrefuses:
Submission Checklist