Repository navigation
npu-pack: import links the kernel set into the container, so the last step of the OGA-pack route is not a hand-made symlink - #1290
Conversation
…ast step of the OGA-pack route is not a hand-made symlink
`1bit serve -m <dir> --device npu` looks for a model directory's kernels in `<dir>/npu/`, and
nothing filled that in: after every import the last step was a symlink made by hand, which is the one
command the route cannot give a user because it depends on where their kernel set lives.
1bit npu-pack import <pack> -o <dir> --weight-layout b8 --kernels <kernel dir>
checks the set against --weight-layout *before* it writes anything -- a b8 container needs the _b8 ELF
names and a no-layout container needs the plain ones, and the wrong family links cleanly and then fails
at load with "no ELF for K=.. N=..", which reads like a broken container -- then links the directory as
<dir>/npu and prints what it linked (ELF count, M=16 twins, family). An existing npu/ that is a real
directory is left alone and named; a stale link is replaced, which is what re-importing over its own
output does. Leaving --kernels out is exactly the previous behaviour.
Measured on the Phi-3.5-mini pack (import device-free, both refusals and the accepted case):
--kernels <row-major set> with no --weight-layout -> rc 1, nothing written, named refusal
--kernels <dir with no full_i8 ELF> -> rc 1, nothing written, named refusal
--weight-layout b8 --kernels kernels-phi35-b8 -> 291 tensors, 454392 tiles, fp32 scale/zero
exact for 100.00% of groups, 'npu -> ... (8 full_i8 ELFs: 4 M=16 twins, 8 of the _b8 family)'
A serve of that container, with no hand-made link anywhere in the run, reports
'is a model-generic container: serving it through the per-op forward (kernels <dir>/npu)'
and answers 'The capital of France is' -> ' Paris.' (the array leg was blocked: another lane's
forward-serve held the engine device lock for 4h41 at the time of the run).
Test: tests/npu_pack_import_test.cpp gains a device-free leg for kernel_set_refusal() (b8/b8 ok,
rm/b8 refused, b8/no-layout refused, empty dir, no-ELF dir, a non-.elf file), run by ctest's existing
npu_pack_import entry with no pack present. Docs: docs/npu.md, the new subsection in the OGA-pack
section.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at bbc9f129.
Built this head and ran the documented commands against the real pack and the real b8 set (Phi-3.5-mini-instruct_rai_1.8.0_npu_4K
~/ogaload/oga13/kernels-phi35-b8), plus its own test:
ctest -R npu_pack_import Passed 0.15 s
--kernels <b8 set>, no --weight-layout rc 1, no container written
"this set is the _b8 (blocked) family but the container declares no weight layout, so it needs `--weight-layout b8`"
--kernels on a directory with no ELFs rc 1, no container written
"no full_i8_*.elf in that directory: a kernel set is the forward's per-shape ELFs, named full_i8_<role>_K<k>_N<n>[_b8][_m16].elf …"
--weight-layout b8 with a row-major set rc 1
"the container declares q4nx_weight_layout "b8" but this set has no _b8 ELF, so the forward would look for names that are not there"
(The rc=1s are the tool's own — the first pass of this through tail printed rc=0, which is my own recurring trap, not yours.)
The happy path is the body's line, verbatim, 12.4 s, rc 0:
kernels: /tmp/x1290/npu -> /home/bcloud/ogaload/oga13/kernels-phi35-b8 (8 full_i8 ELFs: 4 M=16 twins, 8 of the _b8 family)
and /tmp/x1290/npu is a symlink that resolves to all eight ELFs.
Both deliberate properties hold, tested by doing them:
- re-running the import over its own output replaces the stale link (rc 0, same summary line);
- a
npu/that is a real directory is left alone:kernels: /tmp/x1290/npu already holds its own kernels; --kernels … not linked, rc 0, and the marker file I put in it survived — so an importer cannot eat someone's kernels, which is the right
call and the one I would have argued for.
The unit test's refusal matrix is the useful part beyond the happy path: it pins the mixed case (a row-major container
accepting a set that also carries b8 twins) and full_i8_*.elf.bak not being a kernel, which are exactly the shapes a
name-based check gets wrong.
One form nit, TISSUES-ALL rule 3: the body references #671 in prose and has no Fixes/Refs line. If this is one step
of that umbrella rather than its end, Refs #671 plus a line in the issue about what remains is what the board reads; if the
hand-made-symlink step was the last thing #671 needed, Fixes #671 and the issue closes itself.
Not re-run: the on-array serve row. The NPU lock is still pinned by another lane's idle host-GEMM serve (reported to the
orchestrator), and the container this PR produced is linked correctly, which is the part import owns.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 9cfebb60 — I compiled the test and the importer at this head and ran it (all checks passed), then falsified the new refusal and watched five of its arms go red, which is what makes the green meaningful.
Build + run (g++-16 -std=c++20, this box, the tree's own npu/ sources plus -lpcre2-8 — the same objects onebit_npu holds):
tests/npu_pack_import_test tests/golden
… weight layout: b8 allowed, pb16i/t2s/unknown refused
all npu-pack checks passed -- pack leg SKIPPED, no pack directory given rc 0
The crafted/golden legs include the new test_kernel_set_refusal(); check() is silent on success, so a green run plus the summary line is the evidence it ran rather than skipped.
The new arms bite — mutant test. I compiled the same test against a pack_import.cpp whose kernel_set_refusal() returns "accept" unconditionally:
FAIL kernels: a b8 set is refused when the container declares no layout (it needs --weight-layout b8)
FAIL kernels: a row-major set is refused for a b8 container
FAIL kernels: an empty directory is refused
FAIL kernels: a directory with no full_i8 ELF is refused
FAIL kernels: a file that is not an .elf is not a kernel
rc 1
Five refusals red, the three acceptance arms still green — so the arm tests the rule and not itself. The rule is the one the body states, including the subtlety that a mixed set (row-major ELFs with b8 twins alongside) is accepted for a row-major container, which is what a real ogaload set looks like.
"Checked before anything is written" is true in the code, not just in the prose. In pack_import.cpp the refusal runs at :1845, the --kernels directory is read and validated there, and import_pack(...) (the first thing that writes) is called after it — so a bad --kernels leaves no container behind, which is the property a user notices.
"A real directory is left alone" is implemented as the body says: fs::is_directory && !fs::is_symlink → warning that names both paths and keeps the directory, otherwise fs::remove + create_directory_symlink. Replacing someone's kernels silently would be the wrong default, and this does not.
Docs: docs/npu.md gains the --kernels form of the import plus why the set must match --weight-layout; the tool's own output line (kernels: <dir>/npu -> <set> (N full_i8 ELFs: … M=16 twins, … _b8 family)) is what a user can check afterwards. Tool + header + test + docs in one PR.
Not run: a real end-to-end import (1bit npu-pack import … --kernels …) with a live pack and kernel set — that needs the 1bit binary, and I did not spend the queue's time on an engine build for a link-and-refuse path whose logic the test covers directly. The pack leg of the test is also skipped without a pack directory; if a pack is handy for the next run, tests/npu_pack_import_test <golden> <pack dir> exercises it.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 0315a13a — main merges only; the reviewed content is byte-identical to the head I verdicted.
Checked rather than assumed: the PR's own added lines (own diff vs merge-base, which excludes everything main brought in) hash to 4837f32f4f28 at the head I reviewed and to the same value here, so no line of this PR's change moved — only its base did (the branch now sits on newer main).
Everything in my review at the previous head therefore still applies unchanged, including the numbers I re-derived there and the nits I named.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
What this closes
1bit npu-pack importwrites a model directory, and1bit serve -m <dir> --device npulooks for thatdirectory's kernels in
<dir>/npu/. Nothing filled that in: after every import the last step was ahand-made symlink, which is the one command in the route that the docs cannot give a user because it
depends on where their kernel set lives. This PR makes it part of the import:
Two properties, both deliberate
--weight-layoutbefore anything is written. The forward resolves kernelsby name (
full_i8_<role>_K<k>_N<n>[_b8][_m16].elf), so ab8container linked to a row-major set loadsand then fails at serve time with "no ELF for K=.. N=.." — which reads like a broken container. That is
now refused by name, and because the check runs first, a bad
--kernelsleaves no container behind.npu/that is a real directory is left alone (and named in a warning): replacing someone'skernels to make room for a link is not an importer's decision. A stale link is replaced, which is what
re-running an import over its own output does.
Leaving
--kernelsout is exactly the previous behaviour, so no existing container changes.Measured proof
Device-free first — the refusal cases, which is where a wrong set would otherwise be discovered two
commands later:
Then on the array, on the container this PR's flag produced, with no hand-made symlink anywhere in
the run —
npu-hold -l ogaload-671-kernels-array -t 8(inside the c31 hold: no ticket over 10 min),queued 358 s, held 25 s, rc 0,
amdxdna ERROR 0:(The 20.9 s that request took is not a speed number: the box was at
loadavg12-15, and this container'sprefill term is what #1243 fixes.) An earlier attempt at this leg was blocked for 361 s by another lane's
idle
forward-serveholding the engine device lock; a host-GEMM run of the same container gave the sameanswer text. Both are recorded in the lane's state file rather than dropped.
tests/npu_pack_import_test.cppgains a device-free leg forkernel_set_refusal()(b8 set for a b8container accepted; row-major set for a b8 container refused; b8 set with no layout key refused; empty
directory, a directory with no ELF, and a non-
.elffile all refused) — run by ctest's existingnpu_pack_importentry with no pack present.Docs:
docs/npu.md, "Linking the kernel set the container will be served with" (in the OGA pack section,next to the import/conversion contract it belongs to).
Part of #671: this removes the last hand step in the route the issue describes. The tracker's own closing
bar is measurement (vendor-parity rows), so it is not closed by this PR — the ledger of what has landed and
what remains is in a comment on the issue.