Repository navigation
tools: moe_expert_chunks verify --pad-n reads the chunks chunks --pad-n writes (it refused them as corrupt) - #1136
Conversation
…wrote chunks --pad-n writes N_padded columns; verify opened the chunk at the container's own N and died with read_chunk's corruption message on a perfectly good file. It now takes --pad-n and prefers the N_padded the manifest beside the chunks already records, and compares the container's own N columns (padding is zero). Padded and unpadded readbacks are byte-identical in the error they report, which is the known answer. closes #1135
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY — the reported failure reproduced exactly, and the fix reproduces the unpadded answer
Ran it on the container from the issue (~/models/npu/qwen3-coder-30b-a3b-moe), padded and unpadded, with this head and with main's tool over the same chunks.
Before, on this head's chunks but main's code — byte-identical to the issue's report:
$ python3 tools/moe_expert_chunks.py chunks <model> /tmp/moe-pad --layers 1 --experts 2 --pad-n 1024
$ (main's tool) verify <model> /tmp/moe-pad --layer 0 --experts 2
/tmp/moe-pad/L0_gate_e0.tf16: 2129920 B, want 1597440 B rc=1
2,129,920 = 2048×1024 codes + 16×1024 fp16 d, i.e. exactly what chunks() wrote. And --pad-n did not exist on main at all (error: unrecognized arguments).
After, at this head, on the same padded chunks:
ok gate 2048 x 768: worst of 2 experts rel rms 0.1309, cos 0.991547, max |dw| 0.0143 (written padded to 1024, compared in the container's 768)
ok up 2048 x 768: worst of 2 experts rel rms 0.1288, cos 0.991808, max |dw| 0.0131 (written padded to 1024, compared in the container's 768)
ok down 768 x 2048: worst of 2 experts rel rms 0.1399, cos 0.990344, max |dw| 0.0287
rc=0
The control that makes those numbers mean something: unpadded chunks (chunks with no --pad-n) verified on the same head give the same three rows to the last digit — 0.1309/0.991547/0.0143, 0.1288/0.991808/0.0131, 0.1399/0.990344/0.0287. So the padding really is zero, the [:, :N] slice takes the container's own columns, and the padded readback is not a different measurement — which is what the commit claims ("padded and unpadded readbacks are byte-identical in the error they report").
I also checked the axis rather than assuming it: read_chunk() returns codes [K][N], dequantise() keeps that shape, container_expert() is [K][N], so [:, :N] is the column plane and not the row plane. And chunks() pads the whole expert (pad_n(container_expert(...), N_padded)) before quantise(), so both the code plane and the fp16 d plane are N_padded wide — which is why read_chunk(..., K, n_out) computes the right want.
manifest_padding() reads geometry[<proj>].N_padded from the same manifest.json chunks() writes, with --pad-n as the override for a bare directory; a missing/garbled manifest falls back to the container's N instead of raising. Nothing else in the tool changed.
PR Reviewer Guide 🔍(Review updated until commit 0055495)Here are some key observations to aid the review process:
|
|
Persistent review updated to latest commit 0055495 |
Root cause
chunks --pad-n 1024writes each expert's chunk atN_padded(gate/up 768 -> 1024;down's 2048 stays 2048),while
verifytookK, Nfrommodel.q4nx's__metadata__.moeand calledread_chunk(..., K, N). On a paddeddir the byte-count check therefore fired on a correct file, with the one message in this tool that reads like
file corruption:
This is not cosmetic: NW=32 needs
N % 1024 == 0(768 does not), anddocs/npu.mdsizes this model's decode streamwith
--pad-n 1024(1,930,346,496 B/token vs 1,703,854,080 unpadded), so the padded chunk is the one a dispatchwould eat and it was the one shape
verifyrefused to read.The fix
verifygains--pad-n, and prefers the per-projectionN_paddedthatchunks()already writes into<out>/manifest.json; without either it keeps the container'sN(old behaviour). The readback is compared in thecontainer's own
Ncolumns, since the padding columns are zero.Measured, same container (19,528,322,120 B),
origin/main6211c2fe->7e1c71e6, host only, no ticket...: 2129920 B, want 1597440 B, rc 1ok gate 2048 x 768: rel rms 0.1309, cos 0.991547, max |dw| 0.0143 (written padded to 1024, compared in the container's 768), rc 00.1288 / 0.991808 / 0.0131;0.1399 / 0.990344 / 0.02870.1309 / 0.991547,0.1288 / 0.991808,0.1399 / 0.990344--pad-nomitted--pad-n 1024ok, rc 0BAD ... rel rms 1.1899, cos 0.000460, rc 1The padded readback reporting the same loss as the unpadded one is the known-answer check: zero padding cannot
change the container's own 768 columns.
tools/copyright.py --checkrc 0 (no new file); one file changed,tools/moe_expert_chunks.py;gateuntouched(its
--proj downfix from #1086 is in this base).closes #1135