Repository navigation
npu: emit the MTP head as pb16i images that keep the additive min (exact, not 11-18 % lossy) - #791
Conversation
PR Reviewer Guide 🔍(Review updated until commit c2ef316)Here are some key observations to aid the review process:
|
…act, not 11-18 % lossy) The source head's cells are w = q4*S + M with an ADDITIVE per-(32-K group, column) min. A pb16i tile has no bias, so the plain conversion drops M and the images report 0.113-0.182 rel-L1 per tensor. The min is constant per (group, column), so it does not have to be dropped: keep the source codes (q4-8, exactly representable in int4), carry the per-column exponent and int16 magnitudes, and ship M + 8*S as a host table that the GEMV recovers from eight activation group sums. Emitted for all eight head matrices into ~/models/npu/bonsai2-27b-mtp-head/pb16i-exact/ in the sealed tile order (layout_w4.py pack-pb16i: [c][ki][nt][r], 4,608 B per tile), with .add (float32 [K/32][N]), .eref (int16 [N]) and a manifest. Self-checks on the real artifact: image round-trip 0 mismatches on every tensor; full-matrix GEMV against the exact float weights rel-L1 1.6e-5 .. 1.6e-4 (against 0.113-0.182 for the lossy form); and the whole head step, source cells vs emitted images, agrees with hidden cosine 1.00000000 and rel-L1 1.8e-4. Stacks on the open #789, which adds mtp_head_ref.load_q4k_head() -- this tool uses it to read the q4_k cells rather than duplicating the container logic.
2d13ab1 to
66e01be
Compare
|
Persistent review updated to latest commit 66e01be |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
First review, and this is one of the cleanest verifications I have had: I ran the emitter and it reproduces the table to the
digit.
$ python3 tools/mtp_head_pb16i_exact.py (7.7 s wall)
fc 10240x5120 tiles= 6400 image= 29.49 MB add= 6.55 MB roundtrip=OK rel-L1(gemv)=1.56e-04 zeroed=0
q 5120x12288 tiles= 7680 image= 35.39 MB add= 7.86 MB roundtrip=OK rel-L1(gemv)=1.83e-05 zeroed=0
k/v 5120x1024 tiles= 640 image= 2.95 MB roundtrip=OK rel-L1=2.06e-05/1.77e-05 zeroed=0
o 6144x5120 tiles= 3840 image= 17.69 MB roundtrip=OK rel-L1=2.30e-05 zeroed=0
gate/up 5120x17408 tiles= 10880 image= 50.14 MB roundtrip=OK rel-L1=1.76e-05/1.64e-05 zeroed=0
down 17408x5120 tiles= 10880 image= 50.14 MB roundtrip=OK rel-L1=1.96e-05 zeroed=0
head step: source vs emitted images -> hidden cosine=1.00000000 rel-L1=1.84e-04
worst per-tensor rel-L1(GEMV) = 1.56e-04
and the manifest on disk carries the per-tensor evidence rather than only the summary: roundtrip_mismatches: 0,
zeroed_groups: 0, ms_absmax: 32760 (of int16's 32,767, so no column is near saturation), e_ref in −22…−18, and
add_absmax per tensor. The artifact is 279 MB under
~/models/npu/bonsai2-27b-mtp-head/pb16i-exact/, as stated.
The claim that matters is the comparison, and it is real: the delivered pb16i form is 0.113–0.182 rel-L1 per tensor
(that is the manifest I verified independently earlier, rel_l1_residual 0.1129–0.1815) against 1.6e-05 – 1.6e-04 here
— about three orders of magnitude — and end to end the head step through the emitted artifact matches the float reference at
cosine 1.00000000. That is the difference between "pb16i cannot represent this head" (which is what I accepted on #789)
and "pb16i cannot represent it without the side table", and the side table is the fix, exactly as #789 argued.
Stacking note: the body says it stacks on #789, which has since merged (f5f19ad2), so the branch is behind and will
need one rebase before it can be merged — but load_q4k_head() resolves and the run above is on this tree, so nothing is
missing from the dependency. No device, no decode-path change; this is emit-only.
tprs-ready applied. For the 08:00 tickets: the six shared shapes and the host-side fc split are stated in the body, and
fc (K=10240) correctly has no sealed counterpart.
|
Persistent review updated to latest commit c2ef316 |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
At c2ef316a (update-branched onto ebc11395), build green, and its one file is byte-identical to the head I reviewed
(git diff --stat 66e01bee <head> -- tools/mtp_head_pb16i_exact.py → empty), so the measurement stands:
fc 6,400 tiles 29.49 MB rel-L1(GEMV) 1.56e-04 | q 7,680 / 1.83e-05 | k 640 / 2.06e-05 | v 640 / 1.77e-05
o 3,840 / 2.30e-05 | gate 10,880 / 1.76e-05 | up 10,880 / 1.64e-05 | down 10,880 / 1.96e-05
roundtrip=OK and zeroed=0 on all eight; head step cosine 1.00000000, rel-L1 1.84e-04
against 0.1129–0.1815 for the delivered lossy pb16i form (the manifest I verified independently) — about three orders of
magnitude, from carrying M + 8·S as a host side table and keeping the source codes rather than requantising. The artifact is
279 MB on disk with the per-tensor evidence in its manifest (roundtrip_mismatches: 0, zeroed_groups: 0, ms_absmax: 32760 of 32,767, e_ref −22…−18).
Also pre-checked at this head: tools/copyright.py --check → rc 0. tprs-ready stays.
Pre-window host work for the 08:00 MTP head run: emit the eight head matrices as pb16i images that do not throw the
additive min away, in the sealed tile order, self-checked against the oracle. Stacks on the open #789 (which adds
mtp_head_ref.load_q4k_head(), used here instead of duplicating container logic).Why. The source head's cells are
w = q4*S + Mwith an additive per-(32-K group, column) min. A pb16i tile has nobias term, so the plain conversion drops
M, and~/models/npu/bonsai2-27b-mtp-head/pb16i/reports 0.113–0.182rel-L1 per tensor as a result. The min is constant per (group, column), so it does not have to be dropped: keep the
source codes (
q4 − 8, exactly representable in int4), carry the per-column exponent and int16 magnitudes, and shipM + 8·Sas a host table that a GEMV recovers from eight activation group sums.Emitted (
~/models/npu/bonsai2-27b-mtp-head/pb16i-exact/, 279 MB):<t>.pb16iin the sealed tile order(
layout_w4.py pack-pb16i:[c][ki][nt][r], 4,608 B/tile),<t>.add(float32[K/32][N]),<t>.eref(int16[N]),manifest.jsonwith geometry, per-tensor error and the exponent range.Self-checks on the real artifact (
python3 tools/mtp_head_pb16i_exact.py):against 0.113–0.182 for the delivered lossy form — roughly three orders of magnitude — and no column loses a group
(
zeroed_groups: 0,|ms|max 32,760 of int16's 32,767). End to end: the whole head step run through the emittedartifact (
Pb16Matrix= the device's int path plus the host table) versus the float reference agrees with hiddencosine 1.00000000, rel-L1 1.8e-04.
For the 08:00 tickets: the six shapes the head shares with the sealed M=16 family bind these images directly
(
D_K17408_N5120← down,G/U_K5120_N17408← gate/up,O_K6144_N5120← o,QKVFAKV_K5120_N1024← k/v,QKVFAQ_K5120_N6144← q and the output gate as two halves);fc(K=10240) has no sealed counterpart and stays onthe host. The host side consumes
.addasΣ_g add[g,n]·A_gand.erefas the per-column exponent.No device, no GPU; nothing in the decode path changes. Not merged here.