Repository navigation
npu-pack: a final norm at a pseudo layer is aliased to model.norm.weight, not replaced by a unit gain (engine#2561) - #2564
Conversation
…ght, not replaced by a unit gain phi-4's exporter attaches the final norm to a PSEUDO LAYER INDEX (`model.layers.<num_hidden_layers>/final_norm_layernorm`, SkipSimplifiedLayerNormalization) rather than to model scope. The detector compared two exact names, so a pack that carries a learned final norm looked like one that carries none: npu-pack wrote a UNIT gain over it and said so, and on amd/phi-4_rai_1.9.0_npu every prompt then answered " void void void ..." with an output that did not depend on the input (engine#2561). The pseudo-layer spelling is now detected and ALIASED to the name the forward reads. It is an alias, not a copy: the auxiliary pass already keeps anything matching `layernorm.weight` under its own name, so the bytes are only referenced twice. The unit-gain fallback stays for packs that genuinely have no final norm, and the message now names the tensor it found. The arm is in the existing external-data fixture (the standalone version could not reach the block: a pack with no quantised matmul returns early, before the norms), with values that are never 1.0 -- a first version of the arm accepted "one element matches", which a unit gain satisfies by coincidence. Measured both ways: main's pack_import.cpp 2 FAIL (pseudo-layer final norm: every element is the pack's, not a unit gain) this commit 0 FAIL, suite passes
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 97fd0e0: READY
The arm fails on the mutant with the sentence that names the bug, and it fails on both legs — which is the part that makes it a real arm rather than a fixture-shaped one.
unmodified: all npu-pack checks passed
mutant (the pseudo-layer name no longer matches):
FAIL external success: pseudo-layer final norm: every element is the pack's, not a unit gain (engine#2561)
FAIL external success (b8): pseudo-layer final norm: every element is the pack's, not a unit gain (engine#2561)
2 check(s) failed
The bug and why the fix is an alias rather than a copy
phi-4's exporter puts the final norm at a pseudo layer index — model.layers.<num_hidden_layers>/final_norm_layernorm — which is neither of the two names the container reads. Exact-name detection therefore wrote a unit gain over a pack that carries a learned one, and the measured symptom is the one that cannot be mistaken: every prompt answered " void void void …" with an input-independent output.
The fix aliases the pack's tensor to model.norm.weight instead of writing another copy of the unit gain, and that is the right choice for a reason the code says out loud: the tensor is already in the container under its own name (the auxiliary copy keeps anything matching layernorm.weight), so a second copy would leave two tensors that must agree and no rule for which wins. An alias has one answer.
The guard is the one I would have asked for: if (n == p.dims.hidden) — the found tensor must have exactly hidden elements before it is accepted as the final norm. A final_norm_layernorm of the wrong width is not silently coerced into model.norm.weight.
The arm's own comment is the best thing in the diff
EVERY element must match: an arm that accepts "one element matches" passes on a unit gain by coincidence whenever any fixture value is 1.0 — measured on main, where the first version of this arm passed.
That is a vacuity check written from having hit it: the fixture deliberately contains no 1.0 (No value is 1.0, so a unit gain cannot pass by), and the arm compares all elements. I confirmed both legs are exercised — the mutant fails the external success and external success (b8) legs, so the arm is not riding a single code path.
Notes, not requests
- The message is the right shape:
npu-pack: the final RMSNorm was at a pseudo layer (model.layers.1.final_norm_layernorm.weight, not model scope); wrote it to model.norm.weight instead of a unit gain— it names the source name, the destination, and what it declined to do. A silent alias would have been as hard to debug as the original unit gain. pack leg SKIPPED— the crafted-ONNX legs run without a model, so this PR is fully exercised in CI despite the skip line; worth knowing when reading a green row.
|
VERDICT: READY This is the best kind of import fix: the importer said exactly what it was doing, and what it was doing was wrong. "the pack carries no final RMSNorm weight; wrote a unit gain" is a warning that reads like a benign fallback — and a unit gain on the final norm means the last layer's output scale is unconstrained, which is precisely why every prompt got the same text. The lesson worth putting in the commit message: an importer that substitutes a plausible default has converted a missing mapping into wrong output, and the only reason this was findable is that the warning existed. Three asks:
And one thing to record while this is fresh: how the importer tells a pseudo layer from a real one, in one sentence. That definition is what a future pack with a |
The real-pack row I said I could not claim — now measured, end to end
The tensor it names is the one engine#2561 reported: pseudo layer 40,
Two notes, because the first attempt at this was wrong:
|
…'s packer writes them (Fixes #2561) phi-4 (1.9.0) imported with 0 gaps and answered 'void void ...' on every prompt. Three reader bugs, proven by a known-answer write through AMD's own packer as an offline oracle (mladf v2, K 5120 x N 1024, group 128: the blob's own geometry; 100 % of planted codes / zeros / scales recovered by the new layout, 6 / 9 / 0 % by the old): - subvolume `half` holds rows half*32 + r: the halves are NOT swapped; - one zero point per output row per 128-block, in the 16 bytes at +2048 (not four per row from 64 bytes); - the nibbles are the ONNX fields as given, unsigned: w = (c - z) * s. Plus rope_theta from the pack's cos_cache when config.json is empty (phi-4: 250000, corr 1.0000; default 10000). The pseudo-layer final norm landed separately in #2564. phi-4 layer-0 qkv now matches HF x the AWQ fold ratio at corr +0.992 (was 0.00), and the model answers 'Paris.', 'hydrogen ...', 'Neil Armstrong.' on --device npu. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…'s packer writes them (Fixes #2561) (#2567) phi-4 (1.9.0) imported with 0 gaps and answered 'void void ...' on every prompt. Three reader bugs, proven by a known-answer write through AMD's own packer as an offline oracle (mladf v2, K 5120 x N 1024, group 128: the blob's own geometry; 100 % of planted codes / zeros / scales recovered by the new layout, 6 / 9 / 0 % by the old): - subvolume `half` holds rows half*32 + r: the halves are NOT swapped; - one zero point per output row per 128-block, in the 16 bytes at +2048 (not four per row from 64 bytes); - the nibbles are the ONNX fields as given, unsigned: w = (c - z) * s. Plus rope_theta from the pack's cos_cache when config.json is empty (phi-4: 250000, corr 1.0000; default 10000). The pseudo-layer final norm landed separately in #2564. phi-4 layer-0 qkv now matches HF x the AWQ fold ratio at corr +0.992 (was 0.00), and the model answers 'Paris.', 'hydrogen ...', 'Neil Armstrong.' on --device npu. Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
What engine#2561 found
amd/phi-4_rai_1.9.0_npu(external-data genre) answers every prompt with the same text —' void void void …'— and the issue traced it to the final RMSNorm: the importer reported "the pack carries no final RMSNorm weight; wrote a unit gain" while the pack's graph has one, attached to a pseudo layer 40:The bug, in one line
Two exact names. phi-4's exporter writes the norm at
model.layers.<num_hidden_layers>/final_norm_layernorm, which matches neither, so a pack with a learned final norm was treated as one without one and got a unit gain written over it — an input-independent output, exactly as reported.Change
final_norm_layernorm.weight,final_layernorm.weight) and alias that tensor tomodel.norm.weight— the name the forward reads. It is an alias rather than a copy because the auxiliary pass already keeps anything matchinglayernorm.weightin the container under its own name; only the reference is added, not the bytes.Verified — both directions, on the repo's own test
The arm lives in the existing external-data fixture (
tests/npu_pack_import_test.cpp): its.datagains amodel.layers.1.final_norm_layernorm.weighttensor whose values are never 1.0 (0.3 + 0.05·(i mod 9)), and the assertion requires every element of the container'smodel.norm.weightto equal it.and with the fix the importer says what it did:
Built and run with
-DONEBIT_BUILD_TESTS=ON, targetnpu_pack_import_test, under~/lb/thermal-run.sh(CPU only, no GPU job, no ticket).Two things this does not claim
' void void …'answer is engine#2561's owner's device row to close.-1e-2tolerance is bf16's 8 mantissa bits, not slack.