Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,28 @@ if(ONEBIT_NPU)
# `1bit npu-lax`: parity on three positions against the fp64 reference, then one chat turn.
set(ONEBIT_NPU_LAX_KERNELS "" CACHE PATH "scripts/build-lax.sh's <prefix>/kernels")
set(ONEBIT_NPU_LAX_REF "" CACHE PATH "make_decode.py --requant --tokens 3 output (xres<t>.bin, ref_logits*.bin)")
# 1bit serve's own lax kernels, so a Qwen3.6-35B-A3B directory needs no --npu-kernels (in
# Lemonade, the downloaded model directory is all it gets). ONEBIT_NPU_LAX builds them from
# third_party/OpenFlowLM-Next with scripts/build-lax.sh into the build tree, once (they are
# rebuilt when missing); otherwise ONEBIT_NPU_LAX_KERNELS, when set, is the default.
option(ONEBIT_NPU_LAX "Build the lax kernels with scripts/build-lax.sh (needs IRON_VENV and AIETOOLS)" OFF)
if(ONEBIT_NPU_LAX)
set(IRON_VENV "$ENV{IRON_VENV}" CACHE PATH "mlir-aie 1.4.2 + Peano venv, for scripts/build-lax.sh")
set(AIETOOLS "$ENV{AIETOOLS}" CACHE PATH "Vitis aietools directory (aiebu-asm), for scripts/build-lax.sh")
if(NOT IRON_VENV OR NOT AIETOOLS)
message(FATAL_ERROR "ONEBIT_NPU_LAX needs IRON_VENV and AIETOOLS (docs/npu-lax.md)")
endif()
set(_lax_kernels ${CMAKE_BINARY_DIR}/lax/kernels)
add_custom_command(OUTPUT ${_lax_kernels}/lax_l/insts.elf
COMMAND ${CMAKE_COMMAND} -E env IRON_VENV=${IRON_VENV} AIETOOLS=${AIETOOLS}
${CMAKE_SOURCE_DIR}/scripts/build-lax.sh ${CMAKE_BINARY_DIR}/lax
USES_TERMINAL)
add_custom_target(lax_kernels DEPENDS ${_lax_kernels}/lax_l/insts.elf)
add_dependencies(onebit lax_kernels)
target_compile_definitions(onebit PRIVATE ONEBIT_NPU_LAX_KERNELS_DEFAULT="${_lax_kernels}")
elseif(ONEBIT_NPU_LAX_KERNELS)
target_compile_definitions(onebit PRIVATE ONEBIT_NPU_LAX_KERNELS_DEFAULT="${ONEBIT_NPU_LAX_KERNELS}")
endif()
if(ONEBIT_NPU_LAX_KERNELS)
# The full-attention stream's position patches, against the reference harness's table
# for the pinned build (tests/golden/npu_lax/lax_a_patches.tsv names its md5).
Expand Down
4 changes: 2 additions & 2 deletions app/serve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,8 @@ int run_serve(int argc, char** argv) {
#ifdef ONEBIT_NPU
if (!is_npu_model_dir(o.model, o.npu_kernels))
throw std::runtime_error(o.model + " is not an NPU model directory (the fast lane needs npu/; "
"Qwen3.6-35B-A3B needs the lax kernels: --npu-kernels, <dir>/npu/lax or "
"$ONEBIT_NPU_LAX_KERNELS)");
"Qwen3.6-35B-A3B needs the lax kernels: --npu-kernels, <dir>/npu/lax, "
"$ONEBIT_NPU_LAX_KERNELS or a -DONEBIT_NPU_LAX build)");
// The NPU serves in process (unified.cpp).
std::vector<std::string> args = {"-m", o.model, "-p", std::to_string(o.port), "--host", o.host};
if (!o.alias.empty()) { args.push_back("--alias"); args.push_back(o.alias); }
Expand Down
6 changes: 5 additions & 1 deletion app/unified.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ std::string lax_kernel_dir(const std::string& dir, const std::string& lax_kernel
if (!lax_kernels.empty()) return lax_kernels;
if (has_lax_kernels(dir + "/npu/lax")) return dir + "/npu/lax";
if (const char* env = std::getenv("ONEBIT_NPU_LAX_KERNELS"); env && *env) return env;
#ifdef ONEBIT_NPU_LAX_KERNELS_DEFAULT
if (has_lax_kernels(ONEBIT_NPU_LAX_KERNELS_DEFAULT)) return ONEBIT_NPU_LAX_KERNELS_DEFAULT; // this build's
#endif
return "";
}

Expand Down Expand Up @@ -340,7 +343,8 @@ int run_unified(int argc, char** argv) {
" [--kernels DIR] [--transport elf|classic] [--snapshots 4]\n"
" <model dir> holds model.q4nx, config.json, tokenizer.json, and for the fast lane\n"
" npu/ (its kernels); Qwen3.6-35B-A3B runs on the lax kernels in --kernels,\n"
" else <model dir>/npu/lax, else $ONEBIT_NPU_LAX_KERNELS (docs/npu-lax.md)\n"
" else <model dir>/npu/lax, else $ONEBIT_NPU_LAX_KERNELS, else this build's\n"
" (-DONEBIT_NPU_LAX, docs/npu-lax.md)\n"
" --transport the lax kernels as full ELFs (default) or classic xclbin, for A/B\n"
" --snapshots DeltaNet state snapshots the lax decode keeps in host memory for chat\n"
" follow-ups (70 MB each; 0: only exact extensions reuse the cache)\n");
Expand Down
10 changes: 7 additions & 3 deletions docs/lemonade.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ What "fully embedded" still needs, measured on Strix Halo. The runs use the pinn
|---|---|---|
| Vulkan | 19 / 31 | **29 / 29 run, all pass** (2 skipped, as for llamacpp) |
| HRX | 19 / 31 | 26 / 29 run: reranking fails in HRX's JIT |
| NPU | 3 / 31 | 3 / 31: Lemonade hands the engine a GGUF |
| NPU | 3 / 31 | Qwen3.6-35B-A3B loads and answers through Lemonade; the suite's small test models are GGUF |

1. ~~**Declare what already works.**~~ Done (fork #6). The recipe now declares tool calls,
`stop`, async, the Responses API, slots, tokenize, embeddings and reranking.
Expand All @@ -98,8 +98,12 @@ What "fully embedded" still needs, measured on Strix Halo. The runs use the pinn
`--reranking`, and the recipe serves those modes.
5. **Reranking on HRX.** HRX's JIT can't link the fp32 matmul-with-bias kernel that
jina-reranker-v1-tiny needs. (engine, HRX fork)
6. **The NPU from Lemonade.** Lemonade needs to download and hand over an NPU model
directory, and `1bit serve --device npu` needs to take it. (engine + fork)
6. **The NPU from Lemonade.** Qwen3.6-35B-A3B now runs: Lemonade downloads the Q4NX checkpoint
repo, the recipe hands `1bit serve` the directory, and the engine runs it on its own lax
kernels as full ELFs (16.0 tok/s). Still open:
- the smaller NPU models: their lane kernels are captured, not built from source;
- `reasoning_content`: the NPU route returns the thinking inside `content`;
- models in our own Hugging Face repos. (engine + fork)
7. **Beyond the LLM suite:**
- image generation: `1bit comfy` behind Lemonade's image endpoint;
- the Laya router;
Expand Down
7 changes: 7 additions & 0 deletions docs/npu-lax.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ tests/npu_lax_parity.sh ~/.cache/lax <model dir> ~/.cache/lax-ref # from the
```

The kernels land in `~/.cache/lax/kernels` in the layout under "Kernel directory".

`1bit serve` finds the kernels in this order: `--npu-kernels`, `<model dir>/npu/lax`,
`$ONEBIT_NPU_LAX_KERNELS`, then the build's own. `-DONEBIT_NPU_LAX=ON` builds them into the
build tree with this script (it needs `IRON_VENV` and `AIETOOLS`), and `-DONEBIT_NPU_LAX_KERNELS=<dir>`
names an existing build. So a model directory is all `1bit serve` needs, which is all Lemonade
hands it. Through Lemonade on Strix Halo (fork `onebit` recipe, `FastFlowLM/Qwen3.6-35B-A3B-NPU2`
at `0cad628`), the model loaded in 30 s on full ELFs and answered "Paris" at 16.0 tok/s.
`<model dir>` is a Q4NX model directory (`model.q4nx`, `config.json`, `tokenizer.json`).
The weights are packed from `model.q4nx` at load time and streamed into the XRT
buffers, so no pre-packed files are needed. `--requant` is required, because the `lax`
Expand Down
Loading