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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
- name: Configure
run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc-15 -DCMAKE_CXX_COMPILER=g++-15
- name: Build
run: cmake --build build --target onebit npu_full_elf_test npu_pack_test npu_q4nx_test npu_lax_test tokenizer_test think_split_test -j
run: cmake --build build --target onebit npu_full_elf_test npu_pack_test npu_q4nx_test npu_private_route_test tokenizer_test think_split_test -j
- name: Test
run: ctest --test-dir build --output-on-failure
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@
branch = main
# ZINC (docs/zinc.md): upstream zolotukhin/zinc, built by scripts/build-zinc.sh;
# .github/workflows/bump-zinc.yml keeps it current.
# The 35B MoE whole-layer decode (docs/npu-lax.md): the open kernels, MIT, built by
# scripts/build-lax.sh; the branch carries our fixes and optimisations of the lax design.
[submodule "third_party/OpenFlowLM-Next"]
path = third_party/OpenFlowLM-Next
url = https://github.com/bong-water-water-bong/OpenFlowLM-Next.git
branch = 1bit/lax-35b
[submodule "third_party/zinc"]
path = third_party/zinc
url = https://github.com/zolotukhin/zinc.git
Expand Down
100 changes: 24 additions & 76 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,8 @@ option(ONEBIT_NPU_HOST "Build the NPU host library and its tests" ${_onebit_npu_
if(ONEBIT_NPU_HOST)
find_package(PkgConfig REQUIRED)
pkg_check_modules(PCRE2 REQUIRED IMPORTED_TARGET libpcre2-8)
add_library(onebit_npu STATIC npu/full_elf.cpp npu/lax_elf.cpp npu/lax_pack.cpp npu/lax_stream.cpp npu/lax_turns.cpp npu/model.cpp npu/pack.cpp npu/q4nx.cpp
add_library(onebit_npu STATIC npu/full_elf.cpp npu/model.cpp npu/pack.cpp npu/private_route.cpp npu/q4nx.cpp
npu/tokenizer.cpp)
# The lax packer's q8 -> q4_1 re-quantization must round every float32 step on its own,
# as the reference packer's NumPy does (npu/lax_pack.h): no fused multiply-adds.
set_source_files_properties(npu/lax_pack.cpp PROPERTIES COMPILE_OPTIONS -ffp-contract=off)
target_include_directories(onebit_npu PUBLIC npu)
target_link_libraries(onebit_npu PUBLIC nlohmann_json::nlohmann_json PRIVATE PkgConfig::PCRE2)

Expand Down Expand Up @@ -250,16 +247,10 @@ endif()
if(ONEBIT_NPU_MODEL AND ONEBIT_NPU_BO_DUMP)
add_test(NAME npu_pack_model COMMAND npu_pack_test ${ONEBIT_NPU_MODEL} ${ONEBIT_NPU_BO_DUMP})
endif()
# The Qwen3.6-35B-A3B lax decode's host side (docs/npu-lax.md): CI checks the transforms
# against the reference packer's hashes; with the model, all 83 buffers against its table.
add_executable(npu_lax_test tests/npu_lax_test.cpp)
target_link_libraries(npu_lax_test PRIVATE onebit_npu)
add_test(NAME npu_lax_host COMMAND npu_lax_test)
set(ONEBIT_NPU_LAX_MODEL "" CACHE PATH "Qwen3.6-35B-A3B Q4NX directory, for the lax packer and decode tests")
if(ONEBIT_NPU_LAX_MODEL)
add_test(NAME npu_lax_pack_model
COMMAND npu_lax_test --model ${ONEBIT_NPU_LAX_MODEL} --sha256 ${CMAKE_SOURCE_DIR}/tests/golden/npu_lax/sha256.tsv)
endif()
# The private NPU route registry (npu/private_route.h), without an add-on.
add_executable(npu_private_route_test tests/npu_private_route_test.cpp)
target_link_libraries(npu_private_route_test PRIVATE onebit_npu)
add_test(NAME npu_private_route COMMAND npu_private_route_test)
endif() # ONEBIT_NPU_HOST

# The lane itself: needs XRT (the NPU runtime) and an XDNA NPU to run.
Expand All @@ -272,10 +263,10 @@ if(ONEBIT_NPU)
if(NOT EXISTS "${ONEBIT_XRT_ROOT}/include/xrt/xrt_device.h")
message(FATAL_ERROR "ONEBIT_NPU needs XRT; none at ONEBIT_XRT_ROOT=${ONEBIT_XRT_ROOT}")
endif()
add_library(onebit_npu_lane STATIC npu/lane.cpp npu/generate.cpp npu/lax.cpp npu/lax_elf_kernels.cpp)
add_library(onebit_npu_lane STATIC npu/lane.cpp npu/generate.cpp)
target_include_directories(onebit_npu_lane SYSTEM PUBLIC ${ONEBIT_XRT_ROOT}/include)
target_link_libraries(onebit_npu_lane PUBLIC onebit_npu ${ONEBIT_XRT_ROOT}/lib/libxrt_coreutil.so)
target_sources(onebit PRIVATE app/unified.cpp app/npu_lax.cpp)
target_sources(onebit PRIVATE app/unified.cpp)
target_link_libraries(onebit PRIVATE onebit_npu_lane)
target_compile_definitions(onebit PRIVATE ONEBIT_NPU)
set_target_properties(onebit PROPERTIES BUILD_RPATH ${ONEBIT_XRT_ROOT}/lib INSTALL_RPATH ${ONEBIT_XRT_ROOT}/lib)
Expand All @@ -286,69 +277,26 @@ if(ONEBIT_NPU)
COMMAND ${CMAKE_SOURCE_DIR}/tests/npu_lane_e2e.sh $<TARGET_FILE:onebit>
${ONEBIT_NPU_MODEL} ${ONEBIT_NPU_KERNELS} ${ONEBIT_NPU_REFERENCE})
endif()
# `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).
add_test(NAME npu_lax_patches
COMMAND npu_lax_test --insts ${ONEBIT_NPU_LAX_KERNELS}/lax_a/insts.bin
--patches ${CMAKE_SOURCE_DIR}/tests/golden/npu_lax/lax_a_patches.tsv)
# The full-ELF position sites of lax_a/insts.elf (tests/golden/npu_lax/lax_a_elf_sites.tsv
# names its md5); with the harness's full ELFs for the same build, every assembled ELF
# byte for byte.
set(ONEBIT_NPU_LAX_ELF_GOLDEN "" CACHE PATH "harness/full_elf.py lax output for the same kernel build (lax_init.elf, lxf.elf, axf_p<N>.elf, ln.elf, lm.elf)")
set(_golden)
if(ONEBIT_NPU_LAX_ELF_GOLDEN)
set(_golden --golden ${ONEBIT_NPU_LAX_ELF_GOLDEN})
endif()
add_test(NAME npu_lax_elf
COMMAND npu_lax_test --elf ${ONEBIT_NPU_LAX_KERNELS}
--sites ${CMAKE_SOURCE_DIR}/tests/golden/npu_lax/lax_a_elf_sites.tsv ${_golden})
endif()

# Private NPU routes (docs/npu.md, "Private routes"): closed-source add-ons in a checkout of
# the private npu-kernels repository. Its addons/ directory defines the target
# onebit_npu_private, which holds register_private_addon() (npu/private_route.h) and brings
# its own options and tests.
set(ONEBIT_NPU_PRIVATE "" CACHE PATH "An npu-kernels checkout whose addons/ are built into 1bit (needs ONEBIT_NPU)")
if(ONEBIT_NPU_PRIVATE)
if(NOT ONEBIT_NPU)
message(FATAL_ERROR "ONEBIT_NPU_PRIVATE needs ONEBIT_NPU=ON")
endif()
if(ONEBIT_NPU_LAX_MODEL AND ONEBIT_NPU_LAX_KERNELS AND ONEBIT_NPU_LAX_REF)
# Full ELFs (the default), and the classic xclbin path kept for A/B.
add_test(NAME npu_lax_e2e
COMMAND ${CMAKE_SOURCE_DIR}/tests/npu_lax_cpp.sh $<TARGET_FILE:onebit>
${ONEBIT_NPU_LAX_MODEL} ${ONEBIT_NPU_LAX_KERNELS} ${ONEBIT_NPU_LAX_REF} elf)
add_test(NAME npu_lax_e2e_classic
COMMAND ${CMAKE_SOURCE_DIR}/tests/npu_lax_cpp.sh $<TARGET_FILE:onebit>
${ONEBIT_NPU_LAX_MODEL} ${ONEBIT_NPU_LAX_KERNELS} ${ONEBIT_NPU_LAX_REF} classic)
if(NOT EXISTS "${ONEBIT_NPU_PRIVATE}/addons/CMakeLists.txt")
message(FATAL_ERROR "ONEBIT_NPU_PRIVATE=${ONEBIT_NPU_PRIVATE} has no addons/CMakeLists.txt")
endif()
if(ONEBIT_NPU_LAX_MODEL AND ONEBIT_NPU_LAX_KERNELS)
# A DeltaNet state snapshot restored after another continuation gives the logits of the
# same prefix fed from scratch, bit for bit; a Session follow-up from it, the same tokens.
add_test(NAME npu_lax_snapshot
COMMAND onebit npu-lax --model ${ONEBIT_NPU_LAX_MODEL} --kernels ${ONEBIT_NPU_LAX_KERNELS}
--snapshot-check)
# `1bit serve --device npu` on the 35B: the route, one chat round trip, no xclbin opened.
add_test(NAME npu_lax_serve
COMMAND ${CMAKE_SOURCE_DIR}/tests/npu_lax_serve.sh $<TARGET_FILE:onebit>
${ONEBIT_NPU_LAX_MODEL} ${ONEBIT_NPU_LAX_KERNELS})
add_subdirectory(${ONEBIT_NPU_PRIVATE}/addons ${CMAKE_BINARY_DIR}/npu_private)
if(NOT TARGET onebit_npu_private)
message(FATAL_ERROR "${ONEBIT_NPU_PRIVATE}/addons defines no onebit_npu_private target")
endif()
target_link_libraries(onebit PRIVATE onebit_npu_private)
target_compile_definitions(onebit PRIVATE ONEBIT_NPU_PRIVATE)
endif()


Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ This repository exists to be reviewable. Five rules keep it that way.
checked on each backend. Docs quote the second number.
4. **No binaries without source.** NPU kernels are built from source in this
repository (or a pinned submodule) into full ELFs. No vendored xclbins.
A private add-on (docs/npu.md, "Private routes") builds its kernels from
source in its own repository.
5. **Every file carries the copyright and Apache-2.0 notice.** Run
`python3 tools/copyright.py --fix` before committing; CI runs `--check`.
Files that cannot hold a comment (binaries, JSON, test data) are exempt,
Expand Down
12 changes: 0 additions & 12 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,6 @@ ComfyUI.cpp (third_party/comfyui.cpp)
vendors stb (MIT / public domain), nlohmann/json (MIT) and the CLIP BPE
vocabulary (MIT).

OpenFlowLM-Next open kernels (third_party/OpenFlowLM-Next; only open_kernels/ is built)
https://github.com/bong-water-water-bong/OpenFlowLM-Next
(a fork of https://github.com/Atomic-Germ/OpenFlowLM-Next)
open_kernels/: Copyright (c) 2026 Cyrus Attoun and phlegm contributors;
portions derived from OpenFlowLM (https://github.com/OpenFlowLM/OpenFlowLM),
Copyright (c) 2026 Advanced Micro Devices, Inc.
License: MIT (open_kernels/LICENSE); the rest of the tree: Copyright (c)
OpenFlowLM Community, MIT (LICENSE_OPEN_RUNTIME.md)
Includes GEMV tile arithmetic and a smoke test adapted from vegah/LLMNpuTest
(https://github.com/vegah/LLMNpuTest), Apache-2.0
(open_kernels/designs/rot13/LICENSE.LLMNpuTest; attributed in the file headers)

Hugging Face tokenizers (third_party/tokenizers)
https://github.com/huggingface/tokenizers
Copyright Hugging Face, Inc. and the tokenizers authors
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ serves each model behind an OpenAI-compatible API (`1bit serve`), whatever devic
> ([docs/hrx.md](docs/hrx.md)), Vulkan from upstream llama.cpp's latest release ([docs/vulkan.md](docs/vulkan.md)), the NPU engine on full ELFs with the
> upstream XDNA stack pinned ([docs/npu.md](docs/npu.md); its layer kernel is not yet built from
> source), ZINC ([docs/zinc.md](docs/zinc.md)) and MLX ([docs/apple.md](docs/apple.md)). Experimental,
> and served by `1bit serve --device npu` on full ELFs: Qwen3.6-35B-A3B on the NPU, the whole 40-layer
> MoE token as one runlist submit, parity against fp64 given the NPU's expert choice, 16.3-16.5 tok/s decode ([docs/npu-lax.md](docs/npu-lax.md)). Next is step 4,
> and closed source: Qwen3.6-35B-A3B on the NPU through a private add-on, parity against fp64 passes,
> 16.3-16.5 tok/s decode ([docs/npu.md](docs/npu.md#private-routes)). Next is step 4,
> the Laya router. The working engine is being ported from
> [1bit-MONSTER](https://github.com/1bit-MONSTER/1bit-MONSTER); see [docs/PORTING.md](docs/PORTING.md).
> Measured results are on the [wiki](https://github.com/1bit-MONSTER/engine/wiki). This repository
Expand Down
20 changes: 13 additions & 7 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
// OpenAI endpoints; serve's NPU route.
// 1bit npu-run [options] token ids in, token ids out, on the NPU fast
// lane (docs/npu.md); for checks and benchmarks.
// 1bit npu-lax [options] Qwen3.6-35B-A3B on the NPU lax kernels: greedy
// chat, or the parity check (docs/npu-lax.md).
// 1bit <command> [options] a command a private NPU add-on registered
// (-DONEBIT_NPU_PRIVATE builds; docs/npu.md).
//
// See docs/PORTING.md for what lands next.

#ifdef ONEBIT_NPU
#include "generate.h"
#include "model.h"
#include "npu_lax.h"
#include "private_route.h"
#include "unified.h"
#endif
#include "serve.h"
Expand Down Expand Up @@ -64,11 +64,14 @@ void usage(FILE* out) {
#ifdef ONEBIT_NPU
" unified -m <model dir> serve one NPU model (OpenAI endpoints)\n"
" npu-run [options] generate on the NPU fast lane (npu-run --help)\n"
" npu-lax [options] Qwen3.6-35B-A3B on the NPU lax kernels (npu-lax --help)\n"
#endif
" comfy <workflow.json> run a ComfyUI workflow with ComfyUI.cpp (docs/comfyui.md)\n"
" version print the version\n"
" help show this help\n");
#ifdef ONEBIT_NPU
for (const auto& c : onebit::npu::private_commands())
std::fprintf(out, " %-27s %s\n", (c.name + " [options]").c_str(), c.help.c_str());
#endif
}

#ifdef ONEBIT_NPU
Expand Down Expand Up @@ -181,6 +184,9 @@ int run_comfy(int argc, char** argv) {
} // namespace

int main(int argc, char** argv) {
#ifdef ONEBIT_NPU_PRIVATE
onebit::npu::register_private_addon();
#endif
if (argc < 2) {
usage(stderr);
return 2;
Expand Down Expand Up @@ -211,11 +217,11 @@ int main(int argc, char** argv) {
return 1;
}
}
if (cmd == "npu-lax") {
if (const auto* c = onebit::npu::find_private_command(cmd)) {
try {
return onebit::run_npu_lax(argc - 2, argv + 2);
return c->run(argc - 2, argv + 2);
} catch (const std::exception& e) {
std::fprintf(stderr, "1bit npu-lax: %s\n", e.what());
std::fprintf(stderr, "1bit %s: %s\n", cmd.c_str(), e.what());
return 1;
}
}
Expand Down
Loading
Loading