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
84 changes: 84 additions & 0 deletions .github/workflows/dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,90 @@ jobs:
llama-turboquant-macos-arm64.tar.gz
retention-days: 14

# Decision mode (DECISION.md): C++ unit tests and the offline server contract
# tests. Warnings are errors on the Linux leg only. Builds only what the
# tests need and no archive, so publish-dev-latest does not wait for it.
decision-tests:
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, windows-2025]
runs-on: ${{ matrix.os }}

steps:
- name: Clone
uses: actions/checkout@v6

- name: ccache
uses: ggml-org/ccache-action@v1.2.21
with:
key: turboquant-decision-tests-${{ matrix.os }}
evict-old-files: 1d

- name: Build (Linux)
if: ${{ runner.os == 'Linux' }}
run: |
cmake -B build \
-DCMAKE_BUILD_TYPE=Release \
-DGGML_NATIVE=OFF \
-DLLAMA_CURL=OFF \
-DLLAMA_OPENSSL=OFF \
-DLLAMA_BUILD_SERVER=ON \
-DLLAMA_BUILD_TOOLS=ON \
-DLLAMA_BUILD_TESTS=ON \
-DLLAMA_BUILD_EXAMPLES=OFF \
-DLLAMA_FATAL_WARNINGS=ON
cmake --build build --config Release -j $(nproc) \
--target test-decision-json test-decision-request test-decision-calib test-decision-router test-decision-reference test-laya-convert llama-server llama-laya-cli llama-laya-convert

# same toolchain as the server.yml Windows job
- name: Build (Windows)
if: ${{ runner.os == 'Windows' }}
shell: cmd
run: |
cmake -B build -G "Ninja Multi-Config" ^
-DCMAKE_TOOLCHAIN_FILE=cmake/x64-windows-llvm.cmake ^
-DGGML_NATIVE=OFF ^
-DLLAMA_CURL=OFF ^
-DLLAMA_OPENSSL=OFF ^
-DLLAMA_BUILD_SERVER=ON ^
-DLLAMA_BUILD_TOOLS=ON ^
-DLLAMA_BUILD_TESTS=ON ^
-DLLAMA_BUILD_EXAMPLES=OFF
cmake --build build --config Release -j %NUMBER_OF_PROCESSORS% ^
--target test-decision-json test-decision-request test-decision-calib test-decision-router test-decision-reference test-laya-convert llama-server llama-laya-cli llama-laya-convert

# decision + the checkpoint converter (test-laya-convert, test-decision-checkpoint-cli); the Python
# cross-check (label python) needs torch + transformers 5.17 and runs locally (make_tiny_hf_laya.py --check)
- name: Unit tests
run: ctest --test-dir build -C Release -R "decision|laya-convert" -LE python --output-on-failure

- name: Python setup
uses: actions/setup-python@v6
with:
python-version: '3.11'
pip-install: -r tools/server/tests/requirements.txt

# the Python reference of the router rendering and the calibration tools; the golden file
# that test-decision-reference reads must match a fresh run of its generator
- name: Reference tests
shell: bash
env:
PYTHONIOENCODING: 'utf-8'
run: |
python -m pip install jsonschema
python tests/decision/gen_router_golden.py --check
python -m pytest -v tests/decision/test_reference.py

# offline: the tests generate a tiny random laya GGUF
- name: Server tests
shell: bash
env:
PYTHONIOENCODING: ':replace'
run: |
cd tools/server/tests
python -m pytest -v unit/test_decision.py

# Republishes the rolling `dev-latest` prerelease with whatever archives the
# build jobs produced. Runs even when some jobs fail (if: always()) so a
# broken backend never blocks the others from shipping to testers — the
Expand Down
130 changes: 130 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,136 @@ commit list underneath.

Releases before `b10269-1.5.0` predate this file; see the git history.

## Unreleased

### Added

- **Decision models in `llama-server`** (`--decision`, see `DECISION.md`). A
separate server mode for Jev-class decision models: no chat routes, one CPU
worker, calibrated probabilities instead of generated text.
- `POST /v1/systemone`: TypeSafe-compatible typed questions (noul, choice,
score) over a state.
- `POST /v1/router/score`: executor cards in, an independent calibrated
`p_success` per candidate out (Platt calibration from the model's spec; 501
unless calibrated or `--decision-allow-uncalibrated`).
- `/health`, `/props` (`decision` block with limits, plan and calibration),
`/v1/models` capabilities, an error envelope with stable reason codes, and a
bounded queue (429 + `Retry-After`).
- New flags: `--decision`, `--decision-spec`, `--decision-plan`,
`--decision-queue`, `--decision-max-items`, `--decision-allow-uncalibrated`,
`--decision-debug`.
- **Laya decision model support** (`tools/laya`, `llama-laya-cli`), based on
upstream PR #29363: converter for `laya-multilingual`, GGUF arch `laya`, a
self-contained CPU graph, and a tokenizer that matches the HF tokenizer exactly.
Inputs follow the laya 0.3.21 PyTorch reference. On a 2605-question parity set
the F32 GGUF matches the reference to 6.6e-4 in scorer logits with identical
answers; F16 changes 2 answers, both near-ties.
- **English Laya checkpoints** `convaiinnovations/laya` (512 ctx) and
`laya-typed-decisions` (1024 ctx), ModernBERT-large encoder: the converter
handles them, `tools/laya` gets a second tokenizer (ModernBERT / OLMo
byte-level BPE with NFC, 0 mismatches against the HF tokenizer on 13.6k strings,
10.7k of them English-heavy), the special ids come from the tokenizer (`[CLS]`
50281, `[MASK]` 50284 with lstrip; a GGUF whose mask id is not
`laya.marker_token_id` no longer loads), and the checkpoint's
`temperature_by_options` buckets are stored in the GGUF and applied like the
reference. On 1491 English questions the F32 GGUFs match the PyTorch reference
with identical answers (max |dlogit| 4.2e-4 and 6.8e-5). F16 through the server
keeps every answer with the `blas` kernels, the macOS default (1.3e-2 and
4.6e-3); with the `default` ggml kernels, the Linux and Windows default, it
reaches 0.24 and 3.8e-2 with one near-tie answer change on `laya`
(`llama-laya-cli`, which packs the questions of an item: 0.44, two changes). About 2.2x the compute of `laya-multilingual` per token on an
M4 Max (router N=1 221 vs 111 ms at `-t 12`) and 944 vs 519 MiB footprint in
F16 (see `DECISION.md`, "English checkpoints").
`laya-multilingual` results are unchanged bit for bit with the `default`
kernels (`llama-laya-cli`, and the server with `--decision-kernels default`).
- **Model metadata `decision.spec`**, stamped into a GGUF without reconversion
with `gguf-py/gguf/scripts/gguf_decision_spec.py`. A calibration marked
required must cover every question type and option count, or the model does not
load.
- **`llama-decision-bench`** and `scripts/bench-decision.sh`: in-process latency
(p50/p95/p99 per phase), CPU seconds, memory and logits-hash determinism of
decision requests, plus server time-to-ready and first request after idle, with
the machine's power source and load recorded next to the numbers.
- **Router training and calibration tools** (`DECISION.md`, "Training and
calibration tools"): `tools/decision/reference.py`, a stdlib Python reference of
the router input (strict JSON, executor cards, `card-v1`, router state,
`escape-control` from the GGUF vocabulary), checked against the engine byte for
byte on 540 golden requests (`test-decision-reference`) and through the server's
render route; the card as JSON Schema; `scripts/fit-router-calibration.py`
(collects the server's raw router logits, fits the Platt `router.calibration`
block with bootstrap-interval ECE / Brier before and after, and prints the
`gguf_decision_spec.py` command instead of touching the GGUF); and
`scripts/router-baselines.py` (pass-rate heuristic and logistic regression on
card metrics, same data format and metrics).
- **Decision CPU levers** (laya engine): `token_embd` stays in a read-only file
mapping and the GGUF metadata is freed after the load (Q8_0 with the `default`
kernels: RSS 637 -> 262 MiB and footprint 764 -> 389 MiB after load; the macOS
default `auto` adds the BLAS backend, 408 MiB; results bitwise unchanged); one persistent ggml
threadpool; a warm-up pass at load (`--no-warmup` skips it); `--load-mode mlock`
/ `mmap+mlock` lock the model; the default thread count is the performance cores
(Windows: highest `EfficiencyClass`); `KMP_BLOCKTIME=0` / `OMP_WAIT_POLICY=passive`
unless set. New `--decision-kernels auto|default|repack|blas|repack+blas` (also
spec `plan.kernels`, shown in `/props.decision.plan.kernels`): `auto`, the new
default, uses the Accelerate BLAS backend on macOS, which is 2-2.3x faster, uses
3-4x fewer CPU seconds and is closer to the PyTorch reference than the ggml kernels
for F16 and Q8_0 (F16: 2604/2604 argmax agreement); `repack` enables
the CPU repack buffers for quantized weights. The BLAS backend runs with
min(`-t`, 8) threads (it starts new threads for every weight conversion; at
`-t 12`, 12 threads were up to 10% slower than 4 or 8 on `laya-multilingual`, and
4 was 3-5% slower than 8 on the larger English encoder). `llama-laya-cli` gets `--kernels`,
`--no-mmap` and `--mlock` and keeps the `default` kernels. `/props.decision`
also shows the BLAS threads and the weight bytes loaded / mapped / repacked.

- **Laya checkpoints without Python.** `llama-server --decision -m <dir>` and
`llama-laya-cli -m <dir>` take a laya Hugging Face checkpoint directory (an HF
snapshot works as it is). The first start converts it into a GGUF cache,
later starts reuse it ("converted" / "cache hit" in the log), and the cached
GGUF is loaded exactly like `-m FILE`. The cache lives in
`$LLAMA_CACHE/laya/gguf-cache` or the user cache (macOS
`~/Library/Caches/llama.cpp/laya/gguf-cache`, Linux `~/.cache/...`, Windows
`%LOCALAPPDATA%\...`), never in the checkpoint; new flags
`--decision-convert-cache DIR` and `--decision-convert-type f16|f32`
(default f16; the converter's q8_0 is not the precision-protected Q8_0 recipe,
use `tests/laya/quantize.sh` on the f16 GGUF). The cache key covers the
converter version, the outtype and the files the converter can read (root,
`encoder/`, `tokenizer/`; files up to 8 MiB by content, larger ones such as the
weights by size + mtime + symlink target). Writes are atomic and synced to disk.
`/props.decision` shows `source` (`gguf` / `checkpoint-dir`) and `cache_path`.
The conversion is the new `llama-laya-convert` (C++, no Python; also
usable on its own), byte-identical to `convert_hf_to_gguf.py` for all three
published checkpoints in f32, f16 and q8_0, with and without `--model-name`
(18 of 18 files), and 6-19x faster (0.2-1.8 s per f16 file). A first start of
`laya-multilingual` takes about 1.2-1.3 s instead of 0.3 s and peaks at about
515 MiB instead of 372 MiB RSS.

### Notes

- Decision mode runs on the CPU backend only; start it with `--device none` next
to a GPU chat server.
- A laya GGUF started without `--decision` fails fast with a hint.
- **Decision server numerics on macOS change**: the default kernels there are now
`cpu+blas` (Accelerate), so macOS server logits differ slightly from Phase 1 and
from Linux and Windows, where `auto` stays on the ggml kernels and nothing
changes. `--decision-kernels default` restores the Phase 1 numerics bit for bit on
every platform. An explicit `--decision-kernels blas` fails at load on a
build without a BLAS backend.
- Recommended laya precision is F16: Q8_0 is about 1.5x faster but changes about
2% of answers on the parity set.
- Windows: decision model, spec and input paths may contain non-ASCII characters
(for example a Cyrillic user folder), and `llama-laya-cli` prints LF line ends on
every platform, so its output compares byte for byte with the golden files.
- A router calibration fitted with `scripts/fit-router-calibration.py` pins the
kernels its logits came from (`plan.kernels`): one fitted on a Mac pins `blas`
and needs a BLAS build elsewhere. Collect on the target platform, or start the
collecting server with `--decision-kernels default`.

### Changed

- **Qwen3.5 / Qwen3-Next / Kimi-Linear / Kimi-K3 / BailingMoeV3 numerics:** the
Gated DeltaNet q/k normalization now uses upstream's `rsqrt(sum(x^2) + eps)`
form (upstream 5fdfa6282). Logits of these models shift slightly; results
measured on earlier builds are not bit-identical.

## b10269-1.6.0

### Added
Expand Down
Loading
Loading