Skip to content

tools: moe_expert_chunks verify refuses the very chunks chunks --pad-n writes, with a byte-count that reads like corruption #1135

Closed

Description

@bong-water-water-bong

What happens

tools/moe_expert_chunks.py chunks --pad-n N writes each expert's chunk with N_padded columns; verify, the
only host check on that chunk's int4 quantisation error, opens the chunk at the container's own N and dies
before comparing anything:

$ python3 tools/moe_expert_chunks.py chunks ~/models/npu/qwen3-coder-30b-a3b-moe /tmp/moe-pad --layers 1 --experts 2 --pad-n 1024
wrote 6 chunks + manifest.json to /tmp/moe-pad

$ python3 tools/moe_expert_chunks.py verify ~/models/npu/qwen3-coder-30b-a3b-moe /tmp/moe-pad --layer 0 --experts 2
/tmp/moe-pad/L0_gate_e0.tf16: 2129920 B, want 1597440 B
rc=1

Both the chunk and the file are exactly right: 2048x1024 int8 codes + 2048/128x1024 fp16 d = 2,129,920 B. The
message is read_chunk's corruption complaint, so the first reading of it is a damaged file, not a wrong width.

Root cause

verify takes K, N from model.q4nx's __metadata__.moe and has no notion of the padding chunks() applies,
while chunks() has per-projection padding (gate/up 768 -> 1024, down's 2048 stays 2048). The manifest it writes
beside the chunks already records N_padded per projection; verify never reads it.

Why it matters rather than being cosmetic

The pad is not optional decoration: the arena's NW=32 geometry needs N % 1024 == 0 (npu_expert_chunks.geometry
reports ok_at_nw32: false for 768), and docs/npu.md sizes this model's stream with --pad-n 1024
(1,930,346,496 B/token against 1,703,854,080 unpadded). So the padded chunk is the one a dispatch would eat, and
until now it was the one shape verify refused to check — the padded arm could not be quoted at all.

Fix, and the known-answer check on it

verify gains --pad-n, and reads N_padded per projection from <out>/manifest.json when there is one; the
comparison is then the container's own N columns (padding columns are zero). Measured on the same container,
origin/main 6211c2fe:

arm before after
padded chunks + manifest (the reproducer) 2129920 B, want 1597440 B, rc 1 `ok gate 2048 x 768: rel rms 0.1309, cos 0.991547, max
same, up / down — 0.1288 / cos 0.991808 / 0.0131, 0.1399 / cos 0.990344 / 0.0287
unpadded chunks (regression) 0.1309 / 0.991547, 0.1288 / 0.991808, 0.1399 / 0.990344 byte-identical
padded dir with no manifest, --pad-n omitted — still refuses (no way to know the width)
padded dir with no manifest, --pad-n 1024 — ok, rc 0
expert 1's chunk copied over expert 0's — BAD ... rel rms 1.1899, cos 0.000460, rc 1

The padded numbers being identical to the unpadded ones is the known answer: zero padding cannot change the
container's own 768 columns, so a fix that changed them would be wrong.

Device-free, host-only: the container is read, no NPU ticket, no ELF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions