Skip to content
Merged
27 changes: 27 additions & 0 deletions config/npu-kernels.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2026 bong-water-water-bong
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# The private NPU kernels the release builds into the NPU lane (docs/npu.md; docs/releases.md).
# The kernels are private: their source is not part of this repository and is never published with
# the release. They ship only as compiled, encrypted artifacts that `1bit` verifies and decrypts
# in memory at load. scripts/fetch-private.sh checks out exactly this commit of this repository
# (with the release machine's GitHub credentials); the build passes the checkout as
# ONEBIT_NPU_PRIVATE, and the release stops if it cannot be fetched.
#
# Move the pin by hand, after the NPU check on Strix Halo (docs/npu.md, "Checking the NPU").
repo=1bit-MONSTER/npu-kernels
sha=6eee76074347f649282dcc8d25c36e2269b84be3
path=addons
require=CMakeLists.txt register.cpp release-kernels.sh
17 changes: 15 additions & 2 deletions docs/npu.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ They are not merged into this repository yet. The release carries the NPU runtim
package serves GGUF models on HRX, not NPU models ([releases.md](releases.md#the-npu-engine)).

The NPU runtime and the NPU kernels are proprietary and closed source
([releases.md](releases.md#private-components)). This page covers the public parts: the model
format, how `1bit serve` runs an NPU model, and how to build.
([releases.md](releases.md#private-components)). They ship only as compiled binaries: the runtime
is compiled into `1bit`, and the kernels ship as compiled, encrypted artifacts that `1bit` verifies
and decrypts in memory at load (a wrong key fails cleanly, and nothing phones home). Their source,
build and method are not in this repository or in any release. This page covers the public parts:
the model format, how `1bit serve` runs an NPU model, and how to build.

AMD's own NPU stack is a separate route that ships today: `1bit serve --device onnx` runs Ryzen AI
Software's ONNX Runtime GenAI (the RyzenAI provider) on the NPU, on Linux too, from the user's own
Expand Down Expand Up @@ -121,6 +124,16 @@ published FastFlowLM model, is trusted as published.

## Serving

The 1bit NPU engine runs the model on the XDNA 2 NPU. With a release package that carries the NPU
kernels (dense Qwen3: 0.6B, 1.7B and 4B):

```
./1bit serve -m <Qwen3 NPU model dir> --port 8000
```

In Lemonade, the `onebit` recipe's `npu` backend serves the same directories (`--onebit npu`).
The model directory holds the weights only; the kernels ship inside the package.

- **Tokenizer:** `npu/tokenizer.cpp` reads `tokenizer.json` directly (PCRE2 for the
pre-tokenizer regex). Added tokens with `special: false`, such as Qwen3's `<think>` and
`</think>`, stay whole, as Hugging Face `tokenizers` does.
Expand Down
16 changes: 12 additions & 4 deletions docs/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ The builds target Strix Halo: the llama.cpp backends are built with `GGML_NATIVE
### The NPU engine

The release is the HRX runtime with our HIP kernels and the NPU engine, all inside Lemonade. The
NPU engine is in progress: the release carries its runtime, compiled into `1bit`, and the `onebit`
recipe's `npu` backend, but the NPU layer and lm-head kernels built from source are not merged yet
([npu.md](npu.md)). Until they are, NPU models
are not served from a release package; HRX serves the GGUF models.
release carries the NPU runtime, compiled into `1bit`, and the `onebit` recipe's `npu` backend.
The NPU kernels are closed too: they ship as compiled, encrypted artifacts (`config/npu-kernels.config`,
`ONEBIT_NPU_PRIVATE`) that `1bit` verifies and decrypts in memory at load, failing cleanly on a
wrong key with no network callback of any kind; a lifted kernel file is ciphertext and does not run
([npu.md](npu.md)). Wiring the kernels into the weekly release package is the last step; until a
package carries them, HRX serves the GGUF models.

`scripts/weekly.sh` packs them with `WEEKLY_NPU_KERNELS=1` (off until the hardware gate's `npu`
phase passes on Strix Halo): the sealed kernel sets go beside `1bit` in `npu/kernels`, the build
loads sealed kernels only (`ONEBIT_NPU_RELEASE`), and the package checks refuse a plaintext kernel,
an ELF for anything but the host, a symbol table in `1bit`, or a private source name in it. The
release machine holds the kernel key in `ONEBIT_NPU_KEY_DIR` (default `~/.config/1bit-npu-key`).

### Private components

Expand Down
50 changes: 47 additions & 3 deletions scripts/hw-gate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
# rows without server arguments
# needle tests/hrx_long_prompt.py: the 320-record needle (7.1K tokens on Qwen3, 7.4K on ZAYA1;
# #319, #369) on Qwen3-0.6B (f16 and both q8_0 KV caches) and ZAYA1-8B
# npu the NPU engine's own correctness + speed check on Strix Halo, run through a private
# checker ($HW_GATE_NPU_CHECK): dense Qwen3-0.6B decode vs an fp64 reference (oracle),
# a 64-position greedy build, the prompt prefill, run-to-run reproducibility and a
# tok/s floor (HW_GATE_NPU_FLOOR). Auto-skips with no NPU or no checker configured; not
# in the default phases (add it with --phases npu).
# placement every graph the server scheduled for a gate model (load, warmup, the kat prompts,
# the needle) is all on HRX: ggml-hrx's placement report (GGML_HRX_REPORT=2, engine #390)
# names no node off HRX, as `1bit serve` now requires by default (docs/serve.md)
Expand Down Expand Up @@ -392,9 +397,12 @@ if [ -z "$BIN" ]; then
fi
fi
fi
for b in llama-server test-backend-ops llama-perplexity; do
[ -x "$BIN/$b" ] || { note "::error::$BIN/$b missing"; exit 2; }
done
# the llama.cpp binaries, for the HRX phases (an npu-only run needs none of them)
if has build || has ops || has kat || has kld || has needle || has placement; then
for b in llama-server test-backend-ops llama-perplexity; do
[ -x "$BIN/$b" ] || { note "::error::$BIN/$b missing"; exit 2; }
done
fi

# ---- the GPU token, before the first GPU step (gpu() would take it too, but its output is a step log)
if has ops || has kat || has needle || has kld || has placement; then
Expand Down Expand Up @@ -534,6 +542,42 @@ if has kat || has needle || has kld; then
done <<< "$MODEL_TABLE"
fi

# ---- npu (the NPU engine on Strix Halo; neutral, auto-skips without an NPU) ----------------
# The checks themselves live in a private checker ($HW_GATE_NPU_CHECK): the NPU runtime and
# kernels are closed source, so this phase only runs it, reads its neutral result lines and
# applies the speed floor. It prints: oracle/greedy64/prefill/reproducible <PASS|FAIL> and
# tok_s <float>. oracle is dense Qwen3-0.6B decode vs an fp64 reference (token for token over a
# prompt + teacher-forced steps), greedy64 the 64-position build, prefill the prompt prefill,
# reproducible that repeated runs match byte for byte. Set HW_GATE_NPU_CHECK to the private
# checker (it reads its own settings from the environment) and
# HW_GATE_NPU_FLOOR to the tok/s floor (default 30). The NPU shares the box: this runs inside
# the gate's GPU claim and holds ~/npu.lock, and is NOT wrapped in thermal-run (its freeze can
# abort an NPU dispatch); cool() gates the start instead.
if has npu; then
t0=$(date +%s)
if [ ! -e /dev/accel/accel0 ]; then
result npu SKIP 0 "no NPU (/dev/accel/accel0) on this host"
elif [ -z "${HW_GATE_NPU_CHECK:-}" ]; then
result npu SKIP 0 "no NPU check configured (HW_GATE_NPU_CHECK); the checker and kernels are private"
else
cool
log=$OUT/npu.log
flock -w "$LOCK_WAIT" -E 75 "$LOCK" sh -c "$HW_GATE_NPU_CHECK" > "$log" 2>&1
rc=$?
floor=${HW_GATE_NPU_FLOOR:-30}
get() { sed -n "s/^$1 //p" "$log" | tail -n 1; }
oracle=$(get oracle); greedy=$(get greedy64); prefill=$(get prefill); repro=$(get reproducible); tps=$(get tok_s)
st=PASS
for v in "$oracle" "$greedy" "$prefill" "$repro"; do [ "$v" = PASS ] || st=FAIL; done
[ "$rc" = 75 ] && { st=FAIL; infra=1; }
slow=""
# no number is a failure, not a skipped floor (the first on-device run printed an empty tok_s)
if ! [[ "$tps" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then st=FAIL; slow=" (no tok/s reported: the speed floor cannot be checked)"
elif awk -v t="$tps" -v f="$floor" 'BEGIN{exit !(t+0 < f+0)}'; then st=FAIL; slow=" (below the ${floor} tok/s floor)"; fi
result npu $st $(( $(date +%s) - t0 )) "oracle=${oracle:-?} greedy64=${greedy:-?} prefill=${prefill:-?} reproducible=${repro:-?}${tps:+ tok/s=$tps}$slow"
fi
fi

# ---- summary ---------------------------------------------------------------------------------
total=$(( $(date +%s) - START ))
nfail=$(awk -F'\t' '$2 == "FAIL"' "$RESULTS" | wc -l)
Expand Down
9 changes: 9 additions & 0 deletions scripts/package-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ if [ -d "$stage/onnx" ]; then
done
fi

# the sealed NPU kernel sets (scripts/weekly.sh, WEEKLY_NPU_KERNELS): encrypted artifacts, packed
# beside 1bit in npu/kernels, where it looks for them
if [ -d "$build/npu/kernels" ]; then
mkdir -p "$stage/npu"
cp -a "$build/npu/kernels" "$stage/npu/"
echo " npu/kernels: $(ls "$stage/npu/kernels" | wc -l) sets"
fi

# Every program and library finds its libraries beside itself (scripts/pack-elf.sh): a library it
# loads from elsewhere in the build tree (HRX's libhrx, libloomc) or LLVM's OpenMP runtime
# (libomp.so, which ggml's CPU code links when TheRock's amdclang builds llama.cpp) is copied beside
Expand Down Expand Up @@ -86,6 +94,7 @@ cat > "$stage/README.txt" <<EOF
1bit engine $ver for Linux x86_64 (Strix Halo / Ryzen AI): https://1bit.gg/

./1bit serve -m model.gguf --port 8000 (--device auto: HRX0, else the CPU)
$( [ -d "$stage/npu/kernels" ] && printf ' ./1bit serve -m <Qwen3 NPU model dir> --port 8000 (the 1bit NPU engine, XDNA 2 NPU)\n' )

Ubuntu 26.04 with the Lemonade PPA's lemond: sudo ./install-lemonade-ppa.sh
(installs to /opt/1bit; lemond's HRX recipe then runs this llama-server)
Expand Down
53 changes: 52 additions & 1 deletion scripts/weekly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ build() {
[ -d "$HOME/models/laya-pinned" ] && extra+=(-DONEBIT_LAYA_ROOT="$HOME/models/laya-pinned")
# shellcheck disable=SC2206
extra+=(${WEEKLY_CMAKE_ARGS:-})
# The NPU kernels (docs/releases.md, "The NPU engine"): sealed, packed beside 1bit in
# npu/kernels. Off until the hardware gate's npu phase passes on Strix Halo; then
# WEEKLY_NPU_KERNELS defaults to 1. The private checkout does the work through its one entry
# point (key install, sealing, the per-commit kernel cache); this script names nothing in it.
# ONEBIT_NPU_RELEASE makes the built 1bit load sealed kernels only.
if [ "${WEEKLY_NPU_KERNELS:-0}" = 1 ]; then
"$SRC/scripts/fetch-private.sh" "$SRC/config/npu-kernels.config" "$W/npu-kernels" > /dev/null 2>> "$LOGS/private.log" ||
{ cat "$LOGS/private.log"; return 1; }
guard "$W/npu-kernels/addons/release-kernels.sh" "$BUILD/npu/kernels" "${ONEBIT_NPU_KEY_DIR:-$HOME/.config/1bit-npu-key}" \
> "$LOGS/npu-kernels.log" 2>&1 || { tail -n 5 "$LOGS/npu-kernels.log"; return 1; }
extra+=(-DONEBIT_NPU_PRIVATE="$W/npu-kernels" -DONEBIT_NPU_RELEASE=ON)
say "NPU kernels $(git -C "$W/npu-kernels" rev-parse --short HEAD): $(ls "$BUILD/npu/kernels" | wc -l) sealed sets"
fi
# The ONNX backend ships with Microsoft's ONNX Runtime (GenAI) only: with RYZENAI_INSTALL_PATH
# set, build-onnx.sh would copy AMD's Ryzen AI Software libraries beside ryzenai-server and
# they would land in the package (package_checks refuses them too). The NPU through ONNX uses
Expand Down Expand Up @@ -261,6 +274,9 @@ stage_test() { run_tests; }
# no source no source file (.hip .c .cc .cpp .cxx .h .hpp .inc .cu .py .cmake) and no file named
# like one of the private checkouts' files
# licensed the closed binaries' LICENSE-BINARY and NOTICE-BINARY are packed beside LICENSE and NOTICE
# npu (with WEEKLY_NPU_KERNELS) every file under npu/kernels but layout.json is sealed, never a
# plaintext ELF; every ELF in the tarball is for the host (x86-64); the packed 1bit has no
# symbol table and its strings name no private source file and no build-machine home
# onnx onnx/ holds ryzenai-server, Microsoft's libonnxruntime-genai / libonnxruntime and their
# licence texts, nothing else: no part of AMD's Ryzen AI Software (the RyzenAI / VitisAI
# providers, AMD_LICENSE, the AIE compiler libraries), which users install themselves
Expand Down Expand Up @@ -292,12 +308,47 @@ package_checks() { # package_checks <linux tarball>
n=$(find "$t" -type f \( -name '*.hip' -o -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.cxx' \
-o -name '*.h' -o -name '*.hpp' -o -name '*.inc' -o -name '*.cu' -o -name '*.py' -o -name '*.cmake' \) | tee >(cat >&2) | wc -l)
[ "$n" = 0 ] || { echo "FAIL source files in the tarball"; bad=1; }
names=$(for pin in npu-runtime gpu-kernels; do
names=$(for pin in npu-runtime gpu-kernels npu-kernels; do
[ -d "$W/$pin" ] || continue
git -C "$W/$pin" ls-files -- "$(sed -n 's/^path=//p' "$SRC/config/$pin.config")" 2>/dev/null
done | xargs -r -n1 basename | grep -v -x -E 'README.md|NOTICE|LICENSE' | LC_ALL=C sort -u)
n=$(find "$t" -type f -printf '%f\n' | LC_ALL=C sort -u | LC_ALL=C comm -12 - <(echo "$names") | tee >(cat >&2) | wc -l)
[ "$n" = 0 ] || { echo "FAIL files named like the private sources in the tarball"; bad=1; }
[ $bad = 0 ] && echo "ok no private source in $(basename "$1")"
# The NPU kernels, when the package carries them (WEEKLY_NPU_KERNELS): every kernel file is
# sealed (never a plaintext ELF), no ELF in the tarball is for anything but the host (an NPU
# kernel would be), the shipped 1bit has no symbol table, and its strings name no private
# source file and no build-machine home.
local nk=0 m privsrc
while IFS= read -r -d '' f; do
[ "$(basename "$f")" = layout.json ] && continue
[ "$(head -c 8 "$f")" = 1BPKCRYP ] || { echo "FAIL $f is not a sealed kernel artifact"; nk=$((nk + 1)); }
done < <(find "$t" -path '*/npu/kernels/*' -type f -print0)
[ "$nk" = 0 ] || bad=1
n=$(find "$t" -path '*/npu/kernels/*' -type f | wc -l)
[ "$n" = 0 ] || [ "$nk" != 0 ] || echo "ok NPU kernels: $n files under npu/kernels, all sealed"
nk=0
while IFS= read -r -d '' f; do
pack_is_elf "$f" || continue
m=$(od -An -t u2 -j 18 -N 2 "$f" | tr -d ' ')
[ "$m" = 62 ] || { echo "FAIL $f is an ELF for machine $m, not the host (x86-64)"; nk=$((nk + 1)); }
done < <(find "$t" -type f -print0)
[ "$nk" = 0 ] && echo "ok every ELF in $(basename "$1") is a host (x86-64) program or library" || bad=1
f=$(find "$t" -maxdepth 2 -type f -name 1bit | head -1)
if [ -n "$f" ]; then
local b1=0
n=$(nm --defined-only "$f" 2>/dev/null | wc -l)
[ "$n" = 0 ] || { echo "FAIL the packed 1bit still has a symbol table ($n symbols)"; b1=1; }
privsrc=$(for pin in npu-runtime npu-kernels; do
[ -d "$W/$pin" ] || continue
git -C "$W/$pin" ls-files -- "$(sed -n 's/^path=//p' "$SRC/config/$pin.config")" 2>/dev/null
done | grep -E '\.(c|cc|cpp|cxx|h|hpp|py)$' | xargs -r -n1 basename | LC_ALL=C sort -u)
n=0; [ -z "$privsrc" ] || n=$(strings -a "$f" | grep -c -F -f <(printf '%s\n' "$privsrc") || true)
[ "$n" = 0 ] || { echo "FAIL the packed 1bit names a private source file ($n strings)"; b1=1; }
n=$(strings -a "$f" | grep -c '/home/' || true)
[ "$n" = 0 ] || { echo "FAIL the packed 1bit names a build-machine home ($n strings)"; b1=1; }
if [ $b1 = 0 ]; then echo "ok the packed 1bit: no symbol table, no private source names, no build-machine paths"; else bad=1; fi
fi
for f in LICENSE NOTICE LICENSE-BINARY NOTICE-BINARY; do
n=$(find "$t" -maxdepth 2 -type f -name "$f" | wc -l)
[ "$n" != 0 ] || { echo "FAIL $f is not in $(basename "$1")"; bad=1; }
Expand Down
Loading