Repository navigation
npu-pack: import can declare the device weight layout, so a b8 kernel set is one command away - #1217
Conversation
… set is one command away (refs #1189) A container that will be served against the b8 (blocked-B) int8 kernel family must declare `q4nx_weight_layout: "b8"` in its config.json; nothing in the pack says that, because the layout is a property of the runtime the user picks, not of the pack. Until now the only way to say it was to edit the imported container's config.json by hand. 1bit npu-pack import <pack> -o <dir> --weight-layout b8 writes the key, and the absence of the key stays the row-major default every earlier container has. The flag accepts only what an import can actually produce a loadable container for: b8 (nothing else needed) and rm (no key). t2s and pb16i are refused by name with the reason -- both also need q4nx_weight_layout_version and a directory of per-layer images, which an import cannot invent, so accepting them would write a container that refuses to load. Measured on the Phi-3.5-mini pack (device-free import, then one npu-hold ticket): import --weight-layout b8: 291 tensors, 454,392 tiles, rel_err 2.790e-03 -- the same numbers as without the flag -- and config.json carries q4nx_weight_layout "b8" 1bit serve -m <dir> --device npu: 8/8 full ELFs, 'weight layout: b8 blocked 8x8 microtiles', 'The capital of France is' -> ' Paris.', amdxdna ERROR 0, ticket held 30 s Test: tests/npu_pack_import_test.cpp gains a device-free leg (weight_layout_refusal: b8/rm/absent accepted, pb16i/t2s/unknown refused by name), run by ctest's npu_pack_import with no pack present.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at c321d662.
Device-free half re-derived end to end with my own build (Release, gcc-16) on the Phi-3.5-mini pack:
$ 1bit npu-pack import ~/models/oga/Phi-3.5-mini-instruct_rai_1.8.0_npu_4K -o /tmp/phi-reimport --weight-layout b8
imported 291 tensors, 454392 q4_1 tiles into /tmp/phi-reimport
container: read back through q4nx::dequant_tile rel_err 2.790e-03 max |diff| 8.545e-04
layout: declares q4nx_weight_layout "b8" -- this container needs the _b8 kernel family, ...
config.json -> q4nx_weight_layout = 'b8'
- The two load-bearing numbers are the body's exactly (291 tensors, 454,392 tiles,
rel_err 2.790e-03,max |diff| 8.545e-04). - "Changes exactly one key" proven by diff, not by inspection:
--weight-layout rmwrites no key at all ('q4nx_weight_layout' in config.json-> False) and the pretty-printed configs differ by exactly one line,"q4nx_weight_layout": "b8",. So every container the importer wrote before is byte-identical without the flag. - The refusals are by name with the reason, which is the part that stops someone writing a container that will not load:
--weight-layout t2s -> rc 1: t2s also needs q4nx_weight_layout_version (5 or 6) and a directory of per-layer t2s images; import cannot invent either
--weight-layout pb16i -> rc 1: pb16i also needs version 4 and a directory of per-layer pb16i images; import cannot invent either
--weight-layout bogus -> rc 1: unknown weight layout "bogus" (the containers the forward reads declare "b8" or nothing at all, ...)
Accepting t2s/pb16i because the forward reads them would have been the tempting mistake; refusing them with the missing obligation named is right.
Not re-derived: the 1bit serve -m /tmp/phi-reimport --device npu arm under the ticket (that is the device half, and it is yours). Note the import prints self-check: skipped -- the head is not tied to the embedding, which is a pre-existing property of this pack, not something this flag changes — worth one line in the body so the next reader does not think the flag skipped it.
PR Reviewer Guide 🔍(Review updated until commit 0d850a7)Here are some key observations to aid the review process:
|
|
Persistent review updated to latest commit a717d30 |
|
Persistent review updated to latest commit 33c9f6e |
|
Persistent review updated to latest commit d56ed28 |
|
Persistent review updated to latest commit 0d850a7 |
Root cause
A container served against the b8 (blocked-B) int8 kernel family must declare
q4nx_weight_layout: "b8"in itsconfig.json— that key is what selects the_b8/_b8_m16ELF names and makespackBwrite the blocked imagehost-side. Nothing in an OGA pack says that, because the layout is a property of the runtime the user picks, not of the
pack, so until now the only way to say it was to hand-edit the imported container's
config.json.That is the last manual step in the path this lane just validated end to end (Phi-3.5-mini OGA pack → import →
our b8 kernel set →
1bit serve --device npu), so it is worth closing:The change
Options::weight_layout, written into the container'sconfig.jsonasq4nx_weight_layoutwhen it is not thedefault. Absent stays absent for the row-major family, so every container the importer has ever written is
byte-for-byte unchanged without the flag.
weight_layout_refusal()accepts only what an import can actually produce a loadable container for:b8(needsnothing else) and
rm(no key).t2sandpb16iare refused by name with the reason — both also needq4nx_weight_layout_versionand a directory of per-layer images, which an import cannot invent, so accepting themwould write a container that refuses to load.
Measured
Device-free, on the Phi-3.5-mini pack (the same pack as #1209), then one NPU ticket:
The import numbers are identical to the flag-less run (291 tensors, 454,392 tiles, 2.790e-03), so the flag changes
exactly one key.
So a pack directory plus one command now produces a container that the NPU route serves, with no hand editing.
Test
tests/npu_pack_import_test.cppgains a device-free leg (weight_layout_refusal): absent/rm/b8accepted,pb16i/t2s/an unknown name refused, the unknown one refused by name. It runs under ctest's existingnpu_pack_importentry, which needs no pack (CI runs it as-is).Refs #1189 (the pack whose kernel set needed this), not a close: #1209 is the close.