Skip to content
Closed
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/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ body:
id: device
attributes:
label: Device
options: [auto, npu, hrx, cpu, ds4, mlx, onnx, not sure]
options: [auto, npu, hrx, cpu, ds4, onnx, not sure]
validations:
required: true
- type: input
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/model_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ body:
attributes:
label: Device you want it on
multiple: true
options: [npu, hrx, cpu, ds4, mlx, onnx, any]
options: [npu, hrx, cpu, ds4, onnx, any]
validations:
required: true
- type: textarea
Expand Down
2 changes: 1 addition & 1 deletion .pr_agent.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ persistent_comment = true
extra_instructions = """
This is the 1bit engine: a C++26 inference engine behind an OpenAI-compatible API (`1bit serve`), running inside
Lemonade, on AMD Strix Halo's XDNA 2 NPU (fast lane, the from-scratch dx kernels), the Radeon iGPU (HRX
through a pinned llama.cpp build; no Vulkan or ROCm llama.cpp since RFC #213 stage 3), DwarfStar, ONNX and MLX. Review like an engineer who runs this on the hardware:
through a pinned llama.cpp build with HIP kernels; no Vulkan, ROCm backend, Metal, ZINC or CUDA), DwarfStar and ONNX. Review like an engineer who runs this on the hardware:
- correctness first: tensor shapes and strides, KV-cache positions and rollback, bf16/f32 rounding (dx kernels
round to nearest even), NPU hardware-context and runlist lifetimes, lifetimes of child processes and ports;
- C++: ownership and RAII, no allocations in per-token loops, exceptions reaching main, thread safety of shared state;
Expand Down
9 changes: 1 addition & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ endif()
# ── Step 3: NPU engine, full ELFs only (docs/npu.md) ──────────────────────
# Host side (full-ELF generation, model reader, buffer packing): pure C++, no
# XRT. It needs PCRE2 (the tokenizer), and macOS has no NPU, so it is off there
# by default; the Lemonade face (including the mlx backend) does not use it.
# by default.
if(APPLE)
set(_onebit_npu_host_default OFF)
else()
Expand Down Expand Up @@ -490,10 +490,3 @@ if(ONEBIT_NPU_PRIVATE)
endif()


# MLX on Apple Silicon: `1bit serve --device mlx` (docs/apple.md).
set(ONEBIT_MLX_SERVER "" CACHE FILEPATH "lemon-mlx-engine's server binary, for serve_e2e_mlx")
if(APPLE AND ONEBIT_MLX_SERVER)
add_test(NAME serve_e2e_mlx
COMMAND ${CMAKE_SOURCE_DIR}/tests/serve_e2e.sh $<TARGET_FILE:onebit> mlx-community/Qwen3-0.6B-4bit mlx
--mlx-server ${ONEBIT_MLX_SERVER})
endif()
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ Lemonade runs the engine as one of its backends, the same way it runs `llama-ser
serves each model behind an OpenAI-compatible API (`1bit serve`), whatever device runs it:

- the XDNA 2 NPU engine
- HRX on the Radeon iGPU (AMD's ggml-hrx with our Loom kernels), the engine's one GPU route ([docs/hrx.md](docs/hrx.md)), and the CPU from the same llama.cpp build
- HRX on the Radeon iGPU (AMD's ggml-hrx with our Loom and HIP kernels), the engine's one GPU route ([docs/hrx.md](docs/hrx.md)), and the CPU from the same llama.cpp build
- MoE experts streamed from the drive (`1bit serve --moe-slots N`), for MoE models larger than memory: kept, but not in this build until it moves to HRX with Qwen3.8-Flash-Next ([docs/moe-streaming.md](docs/moe-streaming.md))
- DwarfStar, for DeepSeek V4 Flash, GLM 5.x and Qwen3.8-Flash-Next in its own GGUFs, with SSD expert streaming
- MLX on Apple Silicon, through lemon-mlx-engine
- ONNX Runtime GenAI models (Lemonade's ONNX format) on the CPU ([docs/onnx.md](docs/onnx.md))
- Laya, which decides where each request runs
- every Hugging Face model architecture, kept current by a daily census
Expand All @@ -39,9 +38,13 @@ Every tuned setting `1bit serve` gives a backend is a recipe with its measuremen
`tools/bench.py`, which A/B-measures configurations against a baseline in the same run
([docs/bench.md](docs/bench.md)).

Packages ship every Sunday, rebuilt at that week's upstream pins: Linux, Lemonade with the engine,
Windows and 1bit OS ([docs/releases.md](docs/releases.md)). The first release ships on Sunday,
4 October 2026.
On the GPU the engine is pure HRX with HIP kernels; no Vulkan, ROCm backend, Metal, ZINC or CUDA. Every other backend and platform
(Vulkan, ROCm, CUDA, Apple's MLX and Metal, Windows) is Lemonade's, through its own backends and builds.

**Install:** through Lemonade. Packages ship every Sunday, rebuilt at that week's upstream pins:
Lemonade with the onebit recipe and the engine (unpack it and run `lemond-onebit`), and 1bit OS, a
Lemonade appliance with the engine on a bootable USB stick ([docs/releases.md](docs/releases.md)).
The engine has no standalone package of its own.

> **Direction:** the engine is HRX (AMD's ggml-hrx, kernels in Loom or HIP) plus the NPU.[^geramyl] HRX met the decode gates in
> [RFC #213](https://github.com/1bit-MONSTER/engine/discussions/213), and its stage 3 removed the
Expand All @@ -57,8 +60,8 @@ Windows and 1bit OS ([docs/releases.md](docs/releases.md)). The first release sh
> ([docs/hrx.md](docs/hrx.md); its decode-split race, #123/#140, is fixed and the kernel is on by default; Q2_K, IQ2 and IQ3_XXS GGUFs run on HRX instead of the CPU, and `--mtp` on Qwen3.8-27B runs NaN-free since #257), the NPU engine on full ELFs with the
> upstream XDNA stack pinned ([docs/npu.md](docs/npu.md); its layer kernel and lm-head now decode from
> source, ELF to ELF, with no xclbin at any point, verified on Qwen3-0.6B/1.7B/4B against an fp64
> reference — the kernel sources stay private and are not yet merged here, docs/npu.md Step 3d) and
> MLX ([docs/apple.md](docs/apple.md)). ZAYA1-8B (Zyphra)
> reference — the kernel sources stay private and are not yet merged here, docs/npu.md Step 3d).
> The MLX route on Apple Silicon is removed (Lemonade serves MLX). ZAYA1-8B (Zyphra)
> runs from our llama.cpp on HRX, matching transformers, at about 90 tok/s decode in Q4_K_M
> ([docs/hrx.md](docs/hrx.md)). The rest of Zyphra's family (Zamba, Zamba2, BlackMamba) and
> Qwen3.8-Flash-Next ran only on the removed Vulkan build; they are to be ported to HRX. Experimental,
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ unless they ask us not to.
## Scope

- **The engine:** `1bit` and `1bit serve`, and the scripts and workflows in this repository.
- **Our packages:** the weekly release packages (the Linux tarball, the Windows zip, 1bit OS).
- **Our packages:** the weekly release packages (Lemonade with the onebit recipe and the engine, and 1bit OS).
- **Out of scope here:** the pinned upstreams (llama.cpp, HRX, Lemonade, the XDNA driver and
the others in `third_party/`). Report those to their own projects, though we want to know if a
pin we ship is affected.
Expand Down
2 changes: 1 addition & 1 deletion app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// 1bit: the engine binary. Subcommands:
//
// 1bit serve -m <model> one model on any device (NPU, HRX, CPU,
// DwarfStar, ONNX, MLX) behind an OpenAI-compatible API;
// DwarfStar, ONNX) behind an OpenAI-compatible API;
// how the engine runs inside Lemonade (docs/serve.md).
// 1bit unified -m <model dir> one native model on the NPU fast lane behind
// OpenAI endpoints; serve's NPU route.
Expand Down
55 changes: 24 additions & 31 deletions app/serve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// `1bit serve -m <model> [--port 8000] [--device auto|npu|hrx|cpu|ds4|mlx|onnx] [--mtp HEAD]`
// `1bit serve -m <model> [--port 8000] [--device auto|npu|hrx|cpu|ds4|onnx] [--mtp HEAD]`
// [--npu-opt KEY=VALUE ...]
//
// The engine's one front door (docs/serve.md): one model per process behind an
Expand All @@ -31,7 +31,6 @@
// -DONEBIT_NPU_PRIVATE (docs/npu.md)
// a .gguf, --device hrx -> the HRX build's llama-server on HRX0
// a .gguf, --device cpu -> the same llama-server with no GPU layers
// (the Windows package's route, docs/windows.md)
// a .1bp (1BP v5 package), --device auto|ds4 -> the same ds4-server (our DwarfStar fork reads 1BP)
// a DwarfStar .gguf, --device ds4 -> this build's DwarfStar ds4-server (DeepSeek
// V4/V4.1 Flash, GLM 5.x, Qwen3.8-Flash-Next in
Expand All @@ -48,12 +47,12 @@
// drafts a block per step (docs/serve.md)
// --mmproj <mmproj.gguf> on hrx or cpu -> images: the vision encoder runs beside the
// model, and chat messages may carry image parts
// a Hugging Face id, --device mlx (macOS) -> lemon-mlx-engine's server
// For a .gguf, the engine starts that server as a private child on a loopback
// port and forwards the OpenAI routes to it, streaming included. `auto` picks
// HRX for a .gguf where the build has it, else the CPU (auto_gguf_device). The engine has
// no Vulkan or ROCm build (RFC #213 stage 3): what HRX does not run, serve declines with a
// clear message, and Lemonade serves it with its own llamacpp backends.
// no Vulkan, ROCm, Metal/MLX, ZINC or CUDA route: it is pure HRX with HIP kernels on the GPU.
// What HRX does not run, serve declines with a clear message, and Lemonade serves it with its
// own backends.
#include "serve.h"

#include "built_path.h"
Expand Down Expand Up @@ -138,7 +137,7 @@ struct Options {
std::string model, host = "127.0.0.1", device = "auto", alias;
int port = 8000, ctx_size = 0;
std::string flash_attn; // -fa on/off forwarded to the child llama-server
std::string llama_server, hrx_libhsa, mlx, ds4;
std::string llama_server, hrx_libhsa, ds4;
bool ssd_streaming = false; // --device ds4: stream routed experts from the SSD
std::string mtp;
std::string dflash; // DFlash block-diffusion draft model for the target
Expand Down Expand Up @@ -180,7 +179,7 @@ std::string hrx_libhsa(const std::string& option) {
}

// The llama-server --device hrx and cpu run: the HRX build's (HRX0 and the CPU, no Vulkan),
// else one on PATH (the Windows package puts a CPU llama-server beside 1bit.exe).
// else one on PATH.
std::string default_llama_server() {
if (const char* e = std::getenv("ONEBIT_LLAMA_SERVER"); e && *e) return e;
#ifdef ONEBIT_HRX_SERVER
Expand All @@ -191,8 +190,8 @@ std::string default_llama_server() {
}

// The devices this engine no longer has (RFC #213 stage 3, 2026-10-01: HRX + NPU only, zero
// Vulkan, zero ROCm; the core strip, 2026-10-04: no ZINC). Asked for by name, serve says so
// instead of failing somewhere later.
// Vulkan, zero ROCm; the core strip, 2026-10-04: no ZINC; 2026-10-12: no MLX/Metal). Asked for
// by name, serve says so instead of failing somewhere later.
void refuse_removed_device(const std::string& device) {
if (device == "vulkan" || device == "rocm")
throw std::runtime_error("--device " + device + " was removed: the engine's GPU route is HRX (--device hrx, or auto), "
Expand All @@ -201,6 +200,9 @@ void refuse_removed_device(const std::string& device) {
if (device == "zinc")
throw std::runtime_error("--device zinc was removed: the engine no longer builds ZINC (its GPU route is HRX, "
"--device hrx, or auto). Lemonade's own llamacpp backends serve other GPUs (docs/lemonade.md)");
if (device == "mlx")
throw std::runtime_error("--device mlx was removed: the engine has no MLX or Metal route (its GPU route is HRX). "
"Lemonade's own MLX backend serves Apple Silicon (docs/lemonade.md)");
}

// An "H32" file: a Q4_0 whose matmul weights were rotated by a 32-point Walsh-Hadamard transform
Expand Down Expand Up @@ -295,10 +297,6 @@ std::string default_ds4() {
std::atomic<bool> g_stop{false};
extern "C" void on_stop_signal(int) { g_stop = true; }

std::string default_mlx() {
if (const char* e = std::getenv("LEMONADE_MLX_SERVER"); e && *e) return e;
return "lemon-mlx-server";
}

int free_port() {
#ifdef _WIN32
Expand Down Expand Up @@ -750,14 +748,9 @@ Launch launch_for(const Options& o, const std::string& device, int child_port) {
if (o.ctx_size > 0) { argv.push_back("--ctx-size"); argv.push_back(std::to_string(o.ctx_size)); }
return l;
}
if (device == "mlx") {
// lemon-mlx-engine: `<server> <hf id> --port <p>`; it picks the model by
// Hugging Face id, so requests carry that id (docs/apple.md).
argv = {o.mlx.empty() ? default_mlx() : o.mlx, o.model, "--port", std::to_string(child_port)};
set_model = o.model;
} else if (device == "hrx" || device == "cpu") {
// --device cpu: llama-server with no GPU layers (the Windows package's route until HRX runs
// there, and what --device auto falls back to where HRX has no route for a request)
if (device == "hrx" || device == "cpu") {
// --device cpu: llama-server with no GPU layers (what --device auto falls back to where
// HRX has no route for a request, and in a build without HRX)
refuse_missing_arch(o.model);
argv = {o.llama_server.empty() ? default_llama_server() : o.llama_server,
"-m", o.model, "--host", "127.0.0.1", "--port", std::to_string(child_port)};
Expand Down Expand Up @@ -843,7 +836,7 @@ Launch launch_for(const Options& o, const std::string& device, int child_port) {
if (o.parallel > 1) {
// continuous batching: N requests decode together, one read of the weights per step
// for all of them; llama-server splits --ctx-size across the slots
if (device == "mlx" || device == "ds4") throw std::runtime_error("--parallel works on the llama.cpp devices (hrx, cpu)");
if (device == "ds4") throw std::runtime_error("--parallel works on the llama.cpp devices (hrx, cpu)");
argv.insert(argv.end(), {"-np", std::to_string(o.parallel)});
if (device == "hrx") {
// HRX runs attention on the GPU only with one KV stream: -kvu shares one cache across
Expand All @@ -868,7 +861,7 @@ Launch launch_for(const Options& o, const std::string& device, int child_port) {
// the MTP head (--mtp) or a DFlash block-diffusion draft model (--dflash) drafts tokens
// on the same device; the model checks them in one batch
const char* flag = o.mtp.empty() ? "--dflash" : "--mtp";
if (device == "mlx" || device == "ds4") throw std::runtime_error(std::string(flag) + " works on the llama.cpp devices (hrx, cpu)");
if (device == "ds4") throw std::runtime_error(std::string(flag) + " works on the llama.cpp devices (hrx, cpu)");
l.mtp = true;
if (!o.mtp.empty()) argv.insert(argv.end(), {"--spec-type", "draft-mtp", "-md", o.mtp, "-ngld", "99"});
else argv.insert(argv.end(), {"--spec-type", "draft-dflash", "-md", o.dflash, "-ngld", "99"});
Expand All @@ -886,7 +879,7 @@ Launch launch_for(const Options& o, const std::string& device, int child_port) {
if (!o.mtp_p_min.empty()) { argv.push_back("--spec-draft-p-min"); argv.push_back(o.mtp_p_min); }
}
if (!o.mmproj.empty()) {
if (device == "mlx" || device == "ds4") throw std::runtime_error("--mmproj works on the llama.cpp devices (hrx, cpu)");
if (device == "ds4") throw std::runtime_error("--mmproj works on the llama.cpp devices (hrx, cpu)");
// an image is decoded as one ubatch: models that attend to it bidirectionally (ZAYA1-VL,
// Gemma 3) need all of it in one, and Qwen2.5-VL towers cap an image at 4096 tokens
argv.insert(argv.end(), {"--mmproj", o.mmproj, "-b", "4096", "-ub", "4096"});
Expand Down Expand Up @@ -974,7 +967,7 @@ std::vector<std::string> gguf_devices() {
std::string auto_gguf_device(const Options& o) {
#if defined(_WIN32) || !defined(ONEBIT_HRX_SERVER)
(void)o;
return "cpu"; // no GPU route on Windows yet (docs/windows.md), nor in a build without HRX
return "cpu"; // no GPU route in a build without HRX (or on Windows)
#else
(void)o;
return "hrx";
Expand Down Expand Up @@ -1500,7 +1493,7 @@ int serve_child(const Options& given) {
srv.Post("/v1/completions", post);
// The rest of llama-server's API, for the devices that run llama-server (Lemonade's
// llamacpp backend, which the onebit recipe inherits, forwards these to us). They go to
// the first backend; the NPU, DwarfStar and MLX answer 501.
// the first backend; the NPU and DwarfStar answer 501.
const bool llama = device == "hrx" || device == "cpu" ||
(laya && (backends[0].device == "hrx" || backends[0].device == "cpu"));
auto unsupported = [&](const httplib::Request& q, httplib::Response& r) {
Expand Down Expand Up @@ -1862,8 +1855,8 @@ std::string repack_gguf_lane(const std::string& gguf, const std::string& lane_di
void usage(FILE* out) {
std::fprintf(out,
"usage: 1bit serve -m <model> [--port 8000] [--host 127.0.0.1]\n"
" [--device auto|npu|hrx|cpu|ds4|mlx|onnx] [--ctx-size N] [--alias NAME]\n"
" [--llama-server PATH] [--hrx-libhsa PATH] [--mlx-server PATH]\n"
" [--device auto|npu|hrx|cpu|ds4|onnx] [--ctx-size N] [--alias NAME]\n"
" [--llama-server PATH] [--hrx-libhsa PATH]\n"
" [--ds4 PATH] [--ssd-streaming] DwarfStar (--device ds4; docs/dwarfstar.md)\n"
" [--mtp HEAD.gguf] [--mtp-max N] [--mtp-p-min P] multi-token prediction (hrx, cpu)\n"
" [--dflash DRAFT.gguf] DFlash draft model instead of --mtp; --mtp-max/--mtp-p-min apply\n"
Expand All @@ -1886,7 +1879,7 @@ void usage(FILE* out) {
" config/pm-experts.json, built in; URL default http://127.0.0.1:8000; docs/pm.md)\n"
" <model>: an NPU model directory (model.q4nx + npu/, or one a private NPU route serves),\n"
" an ONNX Runtime GenAI directory (genai_config.json: --device onnx),\n"
" a .gguf file, or with --device mlx a Hugging Face id (mlx-community/...)\n");
" or a .gguf file\n");
}

} // namespace
Expand All @@ -1912,7 +1905,8 @@ int run_serve(int argc, char** argv) {
else if (a == "--ds4") o.ds4 = next();
else if (a == "--ssd-streaming") o.ssd_streaming = true;
else if (a == "--hrx-libhsa") o.hrx_libhsa = next();
else if (a == "--mlx-server") o.mlx = next();
else if (a == "--mlx-server")
throw std::runtime_error("--mlx-server was removed with the engine's MLX route; Lemonade's own MLX backend serves Apple Silicon (docs/lemonade.md)");
else if (a == "--prefill-device" || a == "--prefill-min-tokens" || a == "--lean" || a == "--adaptive" ||
a == "--adaptive-at" || a == "--long-model" || a == "--long-from")
// RFC #213 stage 3: these ran on the Vulkan and ROCm builds the engine no longer ships
Expand Down Expand Up @@ -1985,7 +1979,6 @@ int run_serve(int argc, char** argv) {
throw std::runtime_error("this build has no NPU lane (configure with -DONEBIT_NPU=ON)");
#endif
}
if (o.device == "mlx") return serve_child(o);
#ifdef ONEBIT_NPU
if (fs::path(o.model).extension() == ".gguf" && o.device == "npu") {
// Fused-lane first (opt-in via ONEBIT_NPU_LANE_DIR): pack the GGUF in the
Expand Down
1 change: 1 addition & 0 deletions cmake/laya-ggml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ExternalProject_Add(laya_ggml
-DGGMLC_ENABLE_HRX=ON -DGGMLC_GGML_DIR=${CMAKE_SOURCE_DIR}/third_party/llama.cpp/ggml
-DHRX_SOURCE_DIR=${CMAKE_SOURCE_DIR}/third_party/hrx-system
-DGGML_NATIVE=ON -DGGMLC_BUILD_EXAMPLES=ON
-DGGML_VULKAN=OFF -DGGML_HIP=OFF -DGGML_CUDA=OFF -DGGML_METAL=OFF
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target laya
BUILD_BYPRODUCTS ${ONEBIT_LAYA_GGML_BIN}
INSTALL_COMMAND ""
Expand Down
Loading
Loading