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
30 changes: 22 additions & 8 deletions app/serve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,19 +892,33 @@ std::vector<std::string> gguf_devices() {
return devices;
}

// --device auto for a .gguf: HRX where the build has it. The features HRX does not run yet keep
// Vulkan until they are ported or dropped: --moe-slots (experts streamed from the drive), and
// --parallel on the gated delta-net architectures (no multi-sequence delta-net on HRX).
// The GGUF architectures a pinned Vulkan llama.cpp maps and the HRX one does not
// (registry/architectures.json: "vulkan" in backends, "hrx" not). tests/device_route.sh checks
// this list against the registry, so regenerate both together.
bool hrx_missing_arch(const std::string& arch) {
static const char* const archs[] = {
"bailingmoe3", "blackmamba", "dots3note", "granite_swa", "graniteswitch", "hrm_text",
"hy_v4", "kimi-k3", "maple", "minimax-01", "muse-glimmer", "pockettts",
"qwen3tts", "qwen4exp", "spark2_5", "zamba", "zamba2"};
for (const char* a : archs)
if (arch == a) return true;
return false;
}

// --device auto for a .gguf: HRX where the build has it. What HRX does not run yet, or runs well
// below Vulkan, keeps Vulkan until it is ported or dropped: architectures HRX does not map
// (hrx_missing_arch), --moe-slots (experts streamed from the drive), --parallel on the gated
// delta-net architectures (no multi-sequence delta-net on HRX), --mtp (HRX drafts at 65-78% of
// Vulkan's speed) and --mmproj (an open RFC #213 gate).
std::string auto_gguf_device(const Options& o) {
#if defined(_WIN32)
(void)o;
return "cpu"; // no GPU route on Windows yet (docs/windows.md)
#elif defined(ONEBIT_HRX_SERVER)
if (o.moe_slots != 0) return "vulkan";
if (o.parallel > 1) {
const std::string arch = gguf_architecture(o.model);
if (arch == "qwen35" || arch == "qwen35moe" || arch == "qwen3next") return "vulkan";
}
if (o.moe_slots != 0 || !o.mtp.empty() || !o.mmproj.empty()) return "vulkan";
const std::string arch = gguf_architecture(o.model);
if (hrx_missing_arch(arch)) return "vulkan";
if (o.parallel > 1 && (arch == "qwen35" || arch == "qwen35moe" || arch == "qwen3next")) return "vulkan";
return "hrx";
#else
(void)o;
Expand Down
2 changes: 1 addition & 1 deletion docs/serve.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ inherits it). On `npu`, `zinc`, `ds4` and `mlx` they answer 501.
|---|---|---|
| NPU model directory (`model.q4nx` + `npu/`, docs/npu.md) | `auto`, `npu` | the NPU fast lane, in process |
| Qwen3.6-35B-A3B Q4NX directory (`model_type` `qwen3_5_moe`) | `auto`, `npu` | the private NPU route, in process, in builds with `-DONEBIT_NPU_PRIVATE` (docs/npu.md, "Private routes") |
| `.gguf` | `auto`, `hrx` | the HRX build's llama-server on `HRX0` (docs/hrx.md). In a build without HRX, `auto` still means Vulkan, and so does `auto` with `--moe-slots` or with `--parallel` on a gated delta-net model (Qwen3.5, Qwen3.8, Qwen3-Next), which HRX does not run yet |
| `.gguf` | `auto`, `hrx` | the HRX build's llama-server on `HRX0` (docs/hrx.md). In a build without HRX, `auto` still means Vulkan, and so does `auto` for what HRX does not run yet, or runs well below Vulkan: an architecture the HRX build does not map (registry/architectures.json; among them Qwen3.8-Flash-Next and Zyphra Zamba, Zamba2 and BlackMamba), `--moe-slots`, `--parallel` on a gated delta-net model (Qwen3.5, Qwen3.8, Qwen3-Next), `--mtp` (HRX drafts at 65-78% of Vulkan speed) and `--mmproj` (an open RFC #213 gate). Long prompts are slower on HRX than on ROCm until the HRX prompt-matmul routing (llama.cpp fork #55) is pinned: pp512 on Qwen3.8-27B is 97-99 tok/s today |
| `.gguf` | `vulkan` | the upstream llama.cpp build's llama-server on `Vulkan0` (docs/vulkan.md), while Vulkan is still in the build. It is leaving the engine (RFC #213) |
| `.gguf` | `cpu` | llama-server with no GPU layers; `auto` on Windows, which has no GPU route yet (docs/windows.md) |
| `.gguf` | `vulkan --prefill-device hrx` | the HRX build's llama-server decoding on `Vulkan0`, long prompt prefixes prefilled on `HRX0` over one shared KV cache (docs/hrx.md, "Prefill on HRX, decode on Vulkan") |
Expand Down
41 changes: 34 additions & 7 deletions tests/device_route.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
# Which device `1bit serve` starts a plain .gguf on, without a GPU:
# - --device cpu: llama-server with no GPU layers and no --device,
# - --device auto: HRX0 in a build with HRX, Vulkan0 in one without (Vulkan is leaving the engine,
# RFC #213; a build without HRX, like CI's, keeps it until the Vulkan build is removed).
# RFC #213; a build without HRX, like CI's, keeps it until the Vulkan build is removed),
# - --device auto keeps Vulkan0 for an architecture HRX does not map (Qwen3.8-Flash-Next's
# qwen4exp), for --mtp and for --mmproj,
# - serve.cpp's hrx_missing_arch list matches registry/architectures.json.
#
# usage: tests/device_route.sh path/to/1bit
set -uo pipefail
Expand All @@ -32,9 +35,11 @@ check() { if eval "$2"; then echo "ok $1"; else echo "FAIL $1"; fail=1; fi; }
python3 - "$scratch" <<'PY'
import struct, sys
def s(x): b = x.encode(); return struct.pack("<Q", len(b)) + b
kv = s("general.architecture") + struct.pack("<I", 8) + s("llama")
open(sys.argv[1] + "/plain.gguf", "wb").write(b"GGUF" + struct.pack("<IQQ", 3, 0, 1) + kv)
for name, arch in (("plain", "llama"), ("flashnext", "qwen4exp")):
kv = s("general.architecture") + struct.pack("<I", 8) + s(arch)
open(f"{sys.argv[1]}/{name}.gguf", "wb").write(b"GGUF" + struct.pack("<IQQ", 3, 0, 1) + kv)
PY
: > "$scratch/head.gguf"

cat > "$scratch/backend.py" <<'PY'
#!/usr/bin/env python3
Expand All @@ -52,25 +57,47 @@ HTTPServer(("127.0.0.1", port), H).serve_forever()
PY
chmod +x "$scratch/backend.py"

run() { # <record> [serve args]
run() { # <record> <model> [serve args]
local port
port=$(python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1])')
RECORD="$1" "$bin" serve -m "$scratch/plain.gguf" --port "$port" --llama-server "$scratch/backend.py" "${@:2}" >"$1.log" 2>&1 &
RECORD="$1" "$bin" serve -m "$scratch/$2.gguf" --port "$port" --llama-server "$scratch/backend.py" "${@:3}" >"$1.log" 2>&1 &
pid=$!
for _ in $(seq 1 100); do [ -s "$1" ] && break; sleep 0.1; done
kill -9 "$pid" 2>/dev/null; wait "$pid" 2>/dev/null
}
field() { python3 -c 'import json,sys; r=json.load(open(sys.argv[1])); print(eval(sys.argv[2]))' "$1" "$2"; }
after() { field "$1" "r[\"argv\"][r[\"argv\"].index(\"$2\")+1] if \"$2\" in r[\"argv\"] else None"; }

run "$scratch/cpu.json" --device cpu
run "$scratch/cpu.json" plain --device cpu
check "--device cpu runs no GPU layers" '[ "$(after "$scratch/cpu.json" -ngl)" = 0 ]'
check " and names no device" '[ "$(after "$scratch/cpu.json" --device)" = None ]'

run "$scratch/auto.json"
run "$scratch/auto.json" plain
expected=Vulkan0 # the build's CMake cache says whether it has HRX
if grep -q "^ONEBIT_HRX:BOOL=ON" "$(dirname "$bin")/CMakeCache.txt" 2>/dev/null; then expected=HRX0; fi
check "--device auto runs a plain .gguf on $expected (this build)" '[ "$(after "$scratch/auto.json" --device)" = "$expected" ]'

run "$scratch/flashnext.json" flashnext
check "--device auto keeps an architecture HRX does not map on Vulkan0" '[ "$(after "$scratch/flashnext.json" --device)" = Vulkan0 ]'
run "$scratch/mtp.json" plain --mtp "$scratch/head.gguf"
check "--device auto keeps --mtp on Vulkan0" '[ "$(after "$scratch/mtp.json" --device)" = Vulkan0 ]'
run "$scratch/mmproj.json" plain --mmproj "$scratch/head.gguf"
check "--device auto keeps --mmproj on Vulkan0" '[ "$(after "$scratch/mmproj.json" --device)" = Vulkan0 ]'

root=$(cd "$(dirname "$0")/.." && pwd)
check "hrx_missing_arch matches registry/architectures.json" 'python3 - "$root" <<'"'"'PY'"'"'
import json, re, sys
root = sys.argv[1]
a = json.load(open(root + "/registry/architectures.json"))["architectures"].values()
want = {v["gguf"] for v in a if "vulkan" in v["backends"] and "hrx" not in v["backends"]}
src = open(root + "/app/serve.cpp").read()
body = src[src.index("bool hrx_missing_arch"):]
body = body[body.index("{"):body.index("};")]
have = set(re.findall(r"\"([^\"]+)\"", body))
if want != have:
print("registry only:", sorted(want - have), "serve.cpp only:", sorted(have - want))
sys.exit(1)
PY'

if [ $fail -ne 0 ]; then for f in "$scratch"/*.log; do echo "--- $f"; cat "$f"; done; echo FAIL; exit 1; fi
echo PASS
Loading