Repository navigation
npu converter: --dtype bf16 writes no tiles, so the engine and a reference can be compared on the same weights (#796) - #846
Conversation
…rence can be compared on the same weights (#796) `tools/safetensors_to_q4nx.py pack --dtype bf16` keeps every tensor at its source dtype (bf16, or the F32 a transform forces) instead of writing q4_1 tiles. It is the container for measuring, not for serving: with the weights held fixed, an engine run and a reference run differ only in the forward, and what q4_1 costs becomes a separate delta instead of an unexplained one. Used this round for #796's parity row against the pack's own d3_runtime.py: `verify` reports 0 error on the 1.5 GB container (320/320 tensors), and the two containers of the same pack (bf16 and q4_1) answer the same ten contract requests. The row itself, and what it found (the gap is not weight precision), is on the issue. Test: `ctest safetensors_to_q4nx` gains the bf16 container row -- no I8 tile anywhere, the transform-forced F32 tensor stays F32, a tileable projection is BF16, and `verify` accepts it.
PR Reviewer Guide 🔍(Review updated until commit 03e1476)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: READY at 1a42be6f — --dtype bf16 does what the page says, re-derived on a real checkpoint rather than on
the PR's synthetic fixture.
python3 tests/safetensors_to_q4nx_test.py tools/safetensors_to_q4nx.py -> npu_plan_generate: ok-style single line,
rc 0 (the file's check() prints only failures, so rc is the signal). The new cases are the ones that matter: no I8
in the container's dtypes, ssm_a stays F32 under --dtype bf16 (the transform-forced case), a tileable projection
comes out BF16, and verify accepts it.
Then the same on a real model, which the PR does not do and the doc's claim deserves — Qwen2.5-0.5B-Instruct-hf on
this box, 290 tensors, --dtype bf16:
wrote /tmp/tprs846/bf16/model.q4nx (988097928 bytes, 290 tensors)
$ python3 tools/safetensors_to_q4nx.py verify … /tmp/tprs846/bf16
290/290 tensors ok # every row "bf16 max err 0 (bound …)"
$ read_q4nx(model.q4nx) -> 290 tensors, dtypes {'BF16': 290}, any I8: False
988,097,928 B for a 0.5B checkpoint is bf16 with no tiles, the tensor set is identical to the --dtype auto container's,
and max err 0 is literally exact — "the weights are held fixed" is true of the bytes, not approximately true.
Two notes, neither a gate. (1) The page says the d3-lite parity row is measured this way; that row needs the pack's own
d3_runtime.py and a NPU_INFER_HOST_GEMM=1 serve, which I did not run — the container side is verified here, the row
is the lane's. (2) pack happily writes a container with no tokenizer and only says so in a WARNING line (my run hit
it: the HF checkpoint has no tokenizer.json), and the page's own text says 1bit forward-serve will refuse such a
container — the mode that exists to be served by a reference is the mode most likely to hit this, so it might be worth
refusing outright or copying tokenizer.json when the source dir has one. Pre-existing behaviour, not introduced here.
No device time, no GPU claim: this is a converter and a container, and nothing in it opens the NPU.
|
Correction to one string in my review above: the test prints |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 03e1476 (the main merge; own files unchanged).
Re-verified rather than assumed: at this head all three of the PR's files — tools/safetensors_to_q4nx.py,
tests/safetensors_to_q4nx_test.py, docs/npu.md — are byte-identical to the blobs I verdicted at 1a42be6
(git rev-parse compared). The cheap gate re-run here anyway: tests/safetensors_to_q4nx_test.py -> safetensors_to_q4nx: ok, rc 0, and tools/copyright.py --check rc 0.
The 19:21Z substance stands: --dtype bf16 writes the same tensor set with no I8 tiles, keeps the transform-forced F32,
and on a real checkpoint (Qwen2.5-0.5B-Instruct-hf) produced 290 tensors all BF16 with verify 290/290 at max err 0 —
frame the weights exactly, which is the point of that mode.
|
Persistent review updated to latest commit 03e1476 |
One new flag and one test row; no behaviour change to the default path.
tools/safetensors_to_q4nx.py pack --dtype bf16keeps every tensor at its source dtype (bf16, or the F32 atransform forces) instead of writing q4_1 tiles. The default
--dtype autois untouched.Why it exists. engine#796's remaining host-side ask is numeric parity against the pack's own
d3_runtime.py.Comparing an engine run of a q4_1 pack against a bf16 reference mixes two causes: the forward, and the weight
precision. With this flag the weights are held fixed, so:
Measured on the real
vllm-sr/d3-litepack this round (host-side convert, then engine runs under onenpu-holdticket each, host-GEMM, no device):
pack --dtype bf16visual.*skippedverifyon itbf16 max err 0) — no loss by constructionctest safetensors_to_q4nxI8anywhere, forced-F32 stays F32, tileable projection is BF16,verifyaccepts it)tools/copyright.py --checkThe parity row itself is posted on #796, including the part that matters: the engine's answers do not match
the reference, and quantization alone is not the reason (bf16-vs-bf16 still differs by |dp| up to 0.84).
Not in it: no
--dtype f16, no per-tensor overrides, and nothing here changes what a served pack looks like.