Skip to content

tools: check a Q4NX directory's chunk layout before it is served (#587) - #617

Merged
bong-water-water-bong merged 4 commits into
mainfrom
pm/587
Oct 27, 2026
Merged

bong-water-water-bong merged 4 commits into
mainfrom
pm/587

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Part of #587 (preflight only; the issue stays open — the 27B does not yet produce correct text on the NPU).

tools/: validates a Q4NX directory before it is served — chunk count, per-chunk sizes, quant-tile compatibility and the file hashes, so a model that would fail inside the runtime fails here with a reason instead.

Evidence

Run against ~/models/npu/Qwen3.8-27B-NPU2: model.q4nx 17,097,334,824 B, sha256 2f0c797f…eaf00fa1, 962 entries — 408 Q4_K chunks (4736 B) + 98 Q8 chunks (8704 B), no q4_1 tile tensor, 0 errors; vision_weight.q4nx 959,336,080 B, 0 quantized tensors, reported unused.

Not in this PR

The 27B runtime work (GDN row-padding dequant, weight-cache fix, device-path correctness) is not included: it is unfinished and the model still returns garbage on the device.

A published FastFlowLM `*-NPU2` directory is served as it is, so the only thing the engine can
say about it up front is whether every tensor's shape names one of the three chunk kinds
(npu/q4nx.h) and whether the declared bytes are the tiles that kind needs.
tools/check_q4nx_dir.py reads the container header the way npu/model.cpp does - no numpy, no
gguf, no dequantize - names each quantized tensor's kind, and exits 1 on an unknown chunk size,
a tensor shorter than its layout needs, or offsets past the end of the file. It reports the Q8
tensors rather than asserting a layout: two code layouts share the 8704-byte chunk and the
container does not say which.

`--self-test` builds the synthetic containers (one tensor of each kind; an int8 tensor whose
last dimension names no kind; a truncated tensor; a directory with two .q4nx files) and the new
ctest `q4nx_dir_check` runs it, so the check is proved on a box with no NPU and no model.

Checked against the real file, FastFlowLM/Qwen3.8-27B-NPU2 (17,097,334,824 B, sha256
2f0c797f...eaf00fa1): 962 table entries, 506 quantized tensors - 408 Q4_K, 98 Q8, no q4_1 -
17,044,684,800 chunk bytes, 0 errors; vision_weight.q4nx (959,336,080 B) carries no quantized
tensor at all. Nothing was dequantized; the Q8 layout stays unverified for this model, so no
decoder is pointed at it yet (engine #587 has no 27B delta-net lane).
@bong-water-water-bong
bong-water-water-bong enabled auto-merge (squash) October 27, 2026 08:46
@bong-water-water-bong
bong-water-water-bong merged commit 2202faa into main Oct 27, 2026
7 of 8 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the pm/587 branch October 27, 2026 09:34
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