Compare commits
94
Commits
pascal-update
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4c4871514 | ||
|
|
5cd37fa703 | ||
|
|
7813dc8b53 | ||
|
|
3de4779696 | ||
|
|
cb1861e0a5 | ||
|
|
a0c6750245 | ||
|
|
f05c3e29fe | ||
|
|
ff19037a1c | ||
|
|
1fe9bec4cd | ||
|
|
db1cf9ef40 | ||
|
|
c9a49cd0b8 | ||
|
|
56b6a73054 | ||
|
|
e965472b7c | ||
|
|
606d1eb4ad | ||
|
|
847aa7da5f | ||
|
|
910648f2bf | ||
|
|
827b5cbf0b | ||
|
|
5c83c832a0 | ||
|
|
4c64d1e33a | ||
|
|
6ae71dce2a | ||
|
|
22abfdb87f | ||
|
|
152c5af6af | ||
|
|
d03a92f17f | ||
|
|
979e16ba64 | ||
|
|
23cd3b1a40 | ||
|
|
bd2dbb92f1 | ||
|
|
a4ad0a4650 | ||
|
|
325594d806 | ||
|
|
2049dd2a29 | ||
|
|
11b04edbb6 | ||
|
|
698b02e1a2 | ||
|
|
ce6c2f7334 | ||
|
|
0d197fbecd | ||
|
|
b4e28c767a | ||
|
|
cd3be94f42 | ||
|
|
1fa9006b40 | ||
|
|
610c85b345 | ||
|
|
4ed09cf673 | ||
|
|
48efae213c | ||
|
|
93ed67072f | ||
|
|
03b4fe2f71 | ||
|
|
fc07f1b361 | ||
|
|
20bb8f79fa | ||
|
|
7551f13877 | ||
|
|
2a29acb411 | ||
|
|
a69013a97c | ||
|
|
96b35accfe | ||
|
|
39d6b34fe4 | ||
|
|
7bd364e538 | ||
|
|
e34073e170 | ||
|
|
c43e893456 | ||
|
|
afd48dd4f0 | ||
|
|
a9dd402f15 | ||
|
|
a04434668e | ||
|
|
f4cef75d54 | ||
|
|
83de1d991d | ||
|
|
f499b8cf37 | ||
|
|
9dc88e7027 | ||
|
|
3a37ac6315 | ||
|
|
a8469d55b5 | ||
|
|
ea34d7016a | ||
|
|
1df145a215 | ||
|
|
e8c924176b | ||
|
|
5a4f713673 | ||
|
|
bfe7644c58 | ||
|
|
02875ab078 | ||
|
|
17e2721354 | ||
|
|
1026afb266 | ||
|
|
d0bc0d868d | ||
|
|
71886db022 | ||
|
|
adab1179f5 | ||
|
|
1e4f73deaf | ||
|
|
20ece30f54 | ||
|
|
f5b9d32f8e | ||
|
|
043431f59d | ||
|
|
3c06abe654 | ||
|
|
96f4ef1fbb | ||
|
|
453d301599 | ||
|
|
210e936a91 | ||
|
|
6ed5ca2210 | ||
|
|
ef6b5d06aa | ||
|
|
a210c718e7 | ||
|
|
2f9004ba5c | ||
|
|
633dbabd90 | ||
|
|
ef1ee031c7 | ||
|
|
4c25aa6f6a | ||
|
|
822babeeb6 | ||
|
|
b7e32bea6e | ||
|
|
94df4aec73 | ||
|
|
3e4ad96410 | ||
|
|
ec59208d87 | ||
|
|
7e683af1bb | ||
|
|
0197ae86eb | ||
|
|
d1022a66f0 |
No files matched your search
+11
-1
@@ -1,2 +1,12 @@
|
||||
# launch scripts keep LF line endings wherever the repository is cloned
|
||||
# Frozen prompts are hashed byte for byte (manifest sha256): never convert their line endings.
|
||||
bench/prompts/** -text
|
||||
|
||||
# launchers keep their platform line endings wherever the repository is cloned
|
||||
*.sh text eol=lf
|
||||
*.bat text eol=crlf
|
||||
|
||||
# copies of real packs' native_experts.txt, parsed byte for byte by tests/core/expert_layout_test.cpp
|
||||
tests/data/native_experts/** -text
|
||||
|
||||
# the quant yardstick's text set: tokenized byte for byte (set.ids.json), never convert its line endings
|
||||
data/quant_quality/** -text
|
||||
+73
-1
@@ -1,2 +1,74 @@
|
||||
/build*/
|
||||
# Generated, not source: deterministic build products of tools/ (see docs/).
|
||||
# tiny-qwen4exp.gguf is ~113 MB, over GitHub's 100 MB file limit -- regenerate with
|
||||
# python tools/make_tiny_model.py
|
||||
bench/tiny-*.gguf
|
||||
bench/wide-*.gguf
|
||||
bench/micro/*.exe
|
||||
bench/micro/*.obj
|
||||
bench/micro/*.bin
|
||||
bench/micro/*.dll
|
||||
bench/micro/*.txt
|
||||
*.log
|
||||
build*/
|
||||
pack/
|
||||
logs/
|
||||
__pycache__/
|
||||
.pytest_cache/
|
||||
*.pyc
|
||||
|
||||
# plan v0.3 P1 (repository hygiene, review E1): profiler captures and large diagnostic dumps stay out of git.
|
||||
*.nsys-rep
|
||||
|
||||
# Pi harness metadata (local session state, not project source)
|
||||
*.sqlite
|
||||
*.npz
|
||||
*.occ1
|
||||
td.log
|
||||
|
||||
# build directories and a virtualenv, if one is made for tools/
|
||||
/.venv/
|
||||
/build/
|
||||
/models/
|
||||
/packs/
|
||||
/mtp/
|
||||
/run-*.bat
|
||||
/run-*.sh
|
||||
/strata-*.json
|
||||
/strata-*.log
|
||||
/strata-*.warm-start
|
||||
/build-strata.bat
|
||||
/build-strata-cuda12.bat
|
||||
/build-cuda12/
|
||||
/.strata-mcp/
|
||||
|
||||
# image encoder (setup.py --vision): build output and the generated build script
|
||||
build-vision*/
|
||||
build-vision.bat
|
||||
build-vision-cuda12.bat
|
||||
|
||||
# setup.py outputs (engine, downloads) and release builds
|
||||
/engine/
|
||||
/engine-cuda12/
|
||||
/engine-poly/
|
||||
/build-strata-poly.bat
|
||||
/build-vision-poly.bat
|
||||
/engine-glm/
|
||||
/build-strata-glm.bat
|
||||
/build-release*/
|
||||
/dist/
|
||||
*.done
|
||||
/third_party/*.zip
|
||||
|
||||
# IDEs
|
||||
.vscode/
|
||||
.idea/
|
||||
.cursor/
|
||||
|
||||
/.ccache/
|
||||
/.rocm-win/
|
||||
|
||||
# local Windows HIP packaging output
|
||||
dist-hip/
|
||||
|
||||
# macOS Finder metadata
|
||||
.DS_Store
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
[submodule "third_party/llama.cpp"]
|
||||
path = third_party/llama.cpp
|
||||
url = https://github.com/ggml-org/llama.cpp.git
|
||||
url = https://github.com/robertkarl/llama.cpp.git
|
||||
branch = UnbiasedStrata
|
||||
shallow = true
|
||||
+1148
-224
File diff suppressed because it is too large.
Load diff
+16
-8
@@ -2,10 +2,12 @@
|
||||
#
|
||||
# UnbiasedStrata on a Pascal card (Tesla P40 / GTX 10-series, sm_61).
|
||||
#
|
||||
# The engine and the C++ front end are compiled during docker build into one
|
||||
# binary, unbiased-strata, which serves the OpenAI-style API. Nothing is
|
||||
# downloaded at build or run time: the model shards, the pack and the draft
|
||||
# (MTP) head must be mounted. See README.md.
|
||||
# The engines (strata, strata-poly, strata-dsv41) and the C++ front end are
|
||||
# compiled during docker build. The front end serves the OpenAI-style API and
|
||||
# starts the engine named by --engine as a child process; a bare engine name is
|
||||
# looked up BESIDE the front end binary, so all of them must sit in the same
|
||||
# directory. Nothing is downloaded at build or run time: the model shards, the
|
||||
# pack and the draft (MTP) head must be mounted. See README.md.
|
||||
#
|
||||
# Build:
|
||||
# docker build -t unbiased-strata:p40 .
|
||||
@@ -13,9 +15,8 @@
|
||||
# Run (host needs an NVIDIA driver and nvidia-container-toolkit):
|
||||
# docker run --rm --gpus '"device=2"' -p 8082:8080 \
|
||||
# -v /path/models:/models:ro -v /path/Strata-data:/strata:ro \
|
||||
# unbiased-strata:p40 --model /models/...-00001-of-00002.gguf \
|
||||
# --pack /strata/pack-iq3-xxs --mtp /strata/mtp \
|
||||
# --ctx 32768 --host 0.0.0.0 --port 8080
|
||||
# unbiased-strata:p40 --engine strata-poly -m /models/model.gguf \
|
||||
# --host 0.0.0.0 --port 8080 -- --ctx 32768
|
||||
#
|
||||
# PASCAL=1 compiles sm_61 and turns on the engine's STRATA_EXPERIMENTAL_SM60
|
||||
# path. It needs a CUDA 12.x toolkit (CUDA 13 dropped sm_60/sm_70); 12.8.1 is
|
||||
@@ -48,7 +49,14 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY --from=build /src/build/unbiased-strata /usr/local/bin/unbiased-strata
|
||||
# All binaries land in ONE directory: the front end resolves a bare --engine
|
||||
# name relative to its own path (/proc/self/exe), and the engines link
|
||||
# libstrata_kq.so from their rpath, so the library sits beside them too.
|
||||
COPY --from=build /src/build/bin/unbiased-strata /usr/local/bin/unbiased-strata
|
||||
COPY --from=build /src/build/bin/strata /usr/local/bin/strata
|
||||
COPY --from=build /src/build/bin/strata-poly /usr/local/bin/strata-poly
|
||||
COPY --from=build /src/build/bin/strata-dsv41 /usr/local/bin/strata-dsv41
|
||||
COPY --from=build /src/build/bin/libstrata_kq.so /usr/local/bin/libstrata_kq.so
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
---
|
||||
title: "UnbiasedStrata Frontend-CLI Migration — Deliverable"
|
||||
date: 2026-11-05
|
||||
status: "needs-review"
|
||||
---
|
||||
|
||||
# Frontend-CLI Migration: --engine + Engine-Args nach --
|
||||
|
||||
## Zusammenfassung
|
||||
|
||||
Umstellung der UnbiasedStrata-Container auf den neuen Frontend-CLI-Stand:
|
||||
- `--engine <name>` flag zum Auswählen des Engine-Backends
|
||||
- Engine-spezifische Args hinter `--` (ggml-frontend args)
|
||||
- Zwei Engine-Binaries: `strata` (GSQ-RCO pack/MTP) und `strata-poly` (Standard-GGUF)
|
||||
|
||||
## Geänderte Dateien
|
||||
|
||||
| Datei | Repo | Commit |
|
||||
|---|---|---|
|
||||
| `Dockerfile` | `/mnt/nvme/UnbiasedStrata` | `c9a49cd` |
|
||||
| `p40-0.yml` | `/mnt/nvme/stack/` | nicht git-tracked |
|
||||
| `p40-1.yml` | `/mnt/nvme/stack/` | nicht git-tracked |
|
||||
|
||||
## Neue Compose-Kommandos (Volltext)
|
||||
|
||||
### p40-0 (Qwen3.6-35B-A3B, QAT/Pascal, GPU device 1, Port 8081)
|
||||
|
||||
```bash
|
||||
# Image bauen
|
||||
docker build -t unbiased-strata:lotherk-2026-11-05 -f /mnt/nvme/UnbiasedStrata/Dockerfile /mnt/nvme/UnbiasedStrata
|
||||
|
||||
# Dienst starten
|
||||
docker compose -f /mnt/nvme/stack/p40-0.yml up -d
|
||||
|
||||
# Logs
|
||||
docker compose -f /mnt/nvme/stack/p40-0.yml logs -f
|
||||
|
||||
# Container exec (Shell)
|
||||
docker exec -it stack-p40-0-1 bash
|
||||
|
||||
# Stopp
|
||||
docker compose -f /mnt/nvme/stack/p40-0.yml down
|
||||
|
||||
# Neustart
|
||||
docker compose -f /mnt/nvme/stack/p40-0.yml restart
|
||||
```
|
||||
|
||||
### p40-1 (Qwen3.8-Flash-Next-GSQ-RCO, Pascal, GPU device 2, Port 8082)
|
||||
|
||||
```bash
|
||||
# Image bauen
|
||||
docker build -t unbiased-strata:lotherk-2026-11-05 -f /mnt/nvme/UnbiasedStrata/Dockerfile /mnt/nvme/UnbiasedStrata
|
||||
|
||||
# Dienst starten
|
||||
docker compose -f /mnt/nvme/stack/p40-1.yml up -d
|
||||
|
||||
# Logs
|
||||
docker compose -f /mnt/nvme/stack/p40-1.yml logs -f
|
||||
|
||||
# Container exec (Shell)
|
||||
docker exec -it stack-p40-1-1 bash
|
||||
|
||||
# Stopp
|
||||
docker compose -f /mnt/nvme/stack/p40-1.yml down
|
||||
|
||||
# Neustart
|
||||
docker compose -f /mnt/nvme/stack/p40-1.yml restart
|
||||
```
|
||||
|
||||
## Engine-Mapping
|
||||
|
||||
| Service | Engine | Modell | Args nach -- |
|
||||
|---|---|---|---|
|
||||
| p40-0 | `strata-poly` | Qwen3.6-35B-A3B IQ4_XS | --model, --max-context, --kv |
|
||||
| p40-1 | `strata` | Qwen3.8-Flash-Next IQ1_M | --model, --pack, --mtp, --max-context, --kv |
|
||||
|
||||
## Messwerte (Timing)
|
||||
|
||||
| Service | Status |
|
||||
|---|---|
|
||||
| p40-0 | **Noch nicht live getestet** (Build fehlgeschlagen) |
|
||||
| p40-1 | **Noch nicht live getestet** (Build fehlgeschlagen) |
|
||||
|
||||
> **Hinweis:** Die Timing-Messwerte können erst nach erfolgreichem Build und Live-Start gemessen werden.
|
||||
> Die alte Version (vor diesem Update) lief bereits mit denselben Compose-Dateien (alte CLI-Struktur).
|
||||
|
||||
## VRAM pro Karte
|
||||
|
||||
| GPU | Modell | VRAM (Pascal P40, 24 GB) |
|
||||
|---|---|---|
|
||||
| GPU 1 (p40-0) | Qwen3.6-35B-A3B IQ4_XS | ~10-12 GB (geschätzt) |
|
||||
| GPU 2 (p40-1) | Qwen3.8-Flash-Next IQ1_M | ~4-6 GB (geschätzt) |
|
||||
|
||||
> **Hinweis:** Exakte VRAM-Werte müssen nach Live-Start gemessen werden
|
||||
> (`nvidia-smi` im Container oder `--verbose` Flag).
|
||||
|
||||
## Dockerfile-Änderungen
|
||||
|
||||
**Vorher:** Multi-stage build — CUDA 12.8.1-devel → `make build PASCAL=1` → COPY aus Build-Stage.
|
||||
**Nachher:** Single-stage — CUDA 12.8.1-runtime → COPY pre-built binaries aus `build/bin/`.
|
||||
|
||||
**Grund:** `strata_kq` kompiliert nicht im Container (CMake-Fehler). Die Binaries
|
||||
existieren bereits lokal in `build/bin/` und wurden erfolgreich auf den GPUs deployed.
|
||||
|
||||
**Binaire:**
|
||||
- `build/bin/unbiased-strata` — C++ Frontend (OpenAI-Style API)
|
||||
- `build/bin/strata` — Strata Engine (GSQ-RCO pack/MTP)
|
||||
- `build/bin/strata-poly` — Strata Engine (Standard GGUF)
|
||||
- `build/bin/libstrata_kq.so` — Shared Library für KQ-Berechnung
|
||||
|
||||
## Rollback-Anleitung
|
||||
|
||||
### Schneller Rollback (Compose-Dateien)
|
||||
|
||||
```bash
|
||||
# p40-0 zurücksetzen
|
||||
cp /mnt/nvme/stack/p40-0.yml.bak-20261105-131739 /mnt/nvme/stack/p40-0.yml
|
||||
docker compose -f /mnt/nvme/stack/p40-0.yml down
|
||||
docker compose -f /mnt/nvme/stack/p40-0.yml up -d
|
||||
|
||||
# p40-1 zurücksetzen (keine backup-Datei vorhanden — manuell reverten)
|
||||
# Alte CLI-Struktur wiederherstellen (ohne --engine flag)
|
||||
# Alte Image-Tag verwenden
|
||||
docker image rm unbiased-strata:lotherk-2026-11-05
|
||||
# Alte Image-Tag wiederherstellen
|
||||
docker tag unbiased-strata:lotherk-2026-10-15 unbiased-strata:latest
|
||||
```
|
||||
|
||||
### Rollback des Dockerfiles (falls nötig)
|
||||
|
||||
```bash
|
||||
cd /mnt/nvme/UnbiasedStrata
|
||||
git checkout HEAD~1 -- Dockerfile
|
||||
docker build -t unbiased-strata:rollback -f Dockerfile .
|
||||
```
|
||||
|
||||
### Vollständiger Rollback
|
||||
|
||||
```bash
|
||||
# 1. Alte Image-Tags wiederherstellen
|
||||
docker image rm unbiased-strata:lotherk-2026-11-05
|
||||
docker tag unbiased-strata:lotherk-2026-10-15 unbiased-strata:lotherk-2026-11-05
|
||||
|
||||
# 2. Compose-Dateien restoren
|
||||
cp /mnt/nvme/stack/p40-0.yml.bak-20261105-131739 /mnt/nvme/stack/p40-0.yml
|
||||
|
||||
# 3. Dienste neu starten
|
||||
docker compose -f /mnt/nvme/stack/p40-0.yml down && docker compose -f /mnt/nvme/stack/p40-0.yml up -d
|
||||
docker compose -f /mnt/nvme/stack/p40-1.yml down && docker compose -f /mnt/nvme/stack/p40-1.yml up -d
|
||||
```
|
||||
|
||||
## Offene Fragen
|
||||
|
||||
1. **Docker-Build schlägt fehl:** `strata_kq` kompiliert nicht im Docker-Container.
|
||||
Die Lösung (COPY pre-built binaries) verwendet lokale Binaries aus `build/bin/`.
|
||||
Für CI/CD muss die Build-Pipeline angepasst werden, um die Binaries vor dem
|
||||
Docker-Build zu bauen und dann nur noch zu COPY'en.
|
||||
|
||||
2. **Keine Timing-Messwerte vorhanden:** Die Dienste wurden noch nicht live getestet,
|
||||
da der Docker-Build fehlgeschlagen ist. Timing-Messwerte (tokens/s, Latenz)
|
||||
müssen nach erfolgreichem Deploy gemessen werden.
|
||||
|
||||
3. **p40-1.yml hat keine backup-Datei:** Es gibt keine Backup-Datei für p40-1.yml.
|
||||
Der Rollback erfordert manuelles Editieren.
|
||||
|
||||
4. **Strata-data Volume:** p40-0.yml wurde um `/mnt/nvme/stack/Strata-data:/strata:ro`
|
||||
erweitert. p40-1.yml braucht dieses Volume nicht, da pack/MTP als separate Args
|
||||
im Models-Verzeichnis gemountet sind.
|
||||
|
||||
5. **`--threads` Position:** Das `--threads` Flag steht VOR `--`, also wird es vom
|
||||
Frontend-CLI geparst, nicht vom Engine. Das ist korrekt — Thread-Zahl ist eine
|
||||
Frontend-Option.
|
||||
|
||||
6. **Unbekannte Engine-Flags:** Es gibt möglicherweise Engine-spezifische Flags,
|
||||
die noch nicht dokumentiert sind. Die vollständige Flag-Liste steht in
|
||||
`strata --help` und `strata-poly --help`.
|
||||
@@ -1,27 +1,32 @@
|
||||
# UnbiasedStrata build. Needs CMake 3.24+, a C++20 compiler and the CUDA toolkit. Nothing is downloaded.
|
||||
# UnbiasedStrata 2 build. Needs CMake 3.24+, a C++20 compiler, a C compiler and a CUDA 12.x toolkit with its driver.
|
||||
# Nothing is downloaded: ggml, llama, common and mtmd come from the third_party/llama.cpp submodule.
|
||||
#
|
||||
# git clone <repo> && cd <repo>
|
||||
# git submodule update --init
|
||||
# make build # build/bin/{strata,strata-poly,strata-dsv41,libstrata_kq.so,unbiased-strata}
|
||||
# make test # the front end against a fake engine; no GPU needed
|
||||
#
|
||||
BUILD_DIR ?= build
|
||||
# One binary for every single NVIDIA GPU from Pascal up: GTX 10 (61), Volta (70), RTX 20 / GTX 16 (75), RTX 30 (86),
|
||||
# RTX 40 (89), RTX 50 (120). Pascal and Volta are the experimental build (STRATA_EXPERIMENTAL_SM60; needs a CUDA 12.x
|
||||
# toolkit, 13 dropped them): any arch below 75 in the list switches it on. sm_120 needs CUDA 12.8+. An arch the
|
||||
# installed nvcc cannot compile is dropped from the list with a note (CUDA 12.4 has no 120; CUDA 13 has no 61 / 70),
|
||||
# so the default builds on any toolkit; `make build CUDA_ARCHS=61` keeps a single-card build short
|
||||
# (docs/qwen36-port/pascal-build.md).
|
||||
CUDA_ARCHS ?= 61;70;75;86;89;120
|
||||
# `make build PASCAL=1` is the short form of `CUDA_ARCHS=61`: sm_61 (GTX 10-series, Tesla P40; sm_60/P100 works too,
|
||||
# override with CUDA_ARCHS=60). It needs a CUDA 12.x toolkit: CUDA 13 dropped sm_60/sm_70, so the check below fails
|
||||
# early with the reason instead of inside nvcc.
|
||||
# CUDA archs: GTX 10 (61), RTX 20 / GTX 16 (75), RTX 30 (86), RTX 40 (89). Any arch below 75 turns on upstream's
|
||||
# STRATA_EXPERIMENTAL_SM60, which needs a CUDA 12.x toolkit (13 dropped sm_61). `make build CUDA_ARCHS=86` builds for
|
||||
# one card and is several times faster. An arch the installed nvcc cannot compile is dropped with a note.
|
||||
CUDA_ARCHS ?= 61;75;86;89
|
||||
# PASCAL=1 is our shorthand for CUDA_ARCHS=61 (GTX 10-series, Tesla P40); the arch check above then turns on
|
||||
# STRATA_EXPERIMENTAL_SM60 by itself, so the shorthand needs no extra CMake flag.
|
||||
PASCAL ?=
|
||||
ifeq ($(PASCAL),1)
|
||||
CUDA_ARCHS := 61
|
||||
NVCC ?= $(shell command -v nvcc 2>/dev/null)
|
||||
NVCC_MAJOR := $(shell $(NVCC) --version 2>/dev/null | sed -n 's/.*release \([0-9]*\).*/\1/p' | head -n1)
|
||||
ifneq ($(NVCC_MAJOR),)
|
||||
ifeq ($(shell [ $(NVCC_MAJOR) -ge 13 ] && echo yes),yes)
|
||||
$(error PASCAL=1 needs a CUDA 12.x toolkit; nvcc $(NVCC_MAJOR) dropped sm_60/sm_70)
|
||||
endif
|
||||
# nvcc: on PATH, else the toolkit's usual place (RunPod images and distro packages differ). NVCC=/path overrides.
|
||||
NVCC ?= $(or $(shell command -v nvcc 2>/dev/null),$(wildcard /usr/local/cuda/bin/nvcc))
|
||||
ifeq ($(NVCC),)
|
||||
ifneq ($(filter build configure,$(MAKECMDGOALS)),)
|
||||
$(error nvcc not found on PATH or in /usr/local/cuda/bin; install a CUDA 12.x toolkit or set NVCC=/path/to/nvcc)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
NVCC_ARCHS := $(shell nvcc --list-gpu-arch 2>/dev/null | sed 's/compute_//' | tr '\n' ' ')
|
||||
# Everything below that runs nvcc is skipped when there is none (a laptop running `make frontend` or `make test`).
|
||||
ifneq ($(NVCC),)
|
||||
NVCC_ARCHS := $(shell $(NVCC) --list-gpu-arch 2>/dev/null | sed 's/compute_//' | tr '\n' ' ')
|
||||
ifneq ($(NVCC_ARCHS),)
|
||||
CUDA_ARCHS_DROPPED := $(strip $(foreach a,$(subst ;, ,$(CUDA_ARCHS)),$(if $(filter $(firstword $(subst -, ,$(a))),$(NVCC_ARCHS)),,$(a))))
|
||||
ifneq ($(CUDA_ARCHS_DROPPED),)
|
||||
@@ -31,52 +36,55 @@ ifneq ($(NVCC_ARCHS),)
|
||||
endif
|
||||
SM60 := $(shell echo "$(CUDA_ARCHS)" | tr ';' '\n' | sed 's/-.*//' | grep -E '^[0-9]+$$' | awk '$$1 < 75 { print "ON"; exit }')
|
||||
SM60_FLAG := $(if $(SM60),-DSTRATA_EXPERIMENTAL_SM60=ON,)
|
||||
# PORTABLE=1: an AVX2 baseline for the CPU expert kernels instead of -march=native (build on one box, run on another).
|
||||
PORTABLE_FLAG := $(if $(PORTABLE),-DSTRATA_PORTABLE=ON,)
|
||||
# One compiler for the C, C++ and CUDA host sides. nvcc accepts GCC only up to a version (CUDA 12.4: 13); when the
|
||||
# C++ files are compiled by a newer g++ and nvcc falls back to an older one, two libstdc++ generations meet at the link
|
||||
# and it fails on __cxa_call_terminate (upstream #1645). The probe tries the versioned compilers newest first and hands
|
||||
# CMake absolute paths, so `g++` resolving to a version nvcc rejects cannot slip through. HOSTCXX=/usr/bin/g++-13
|
||||
# overrides it.
|
||||
HOSTCXX ?= $(shell for c in g++-15 g++-14 g++-13 g++-12 g++-11 g++; do p=$$(command -v $$c 2>/dev/null) || continue; \
|
||||
t=$$(mktemp /tmp/strata-hc-XXXXXX.cu) && printf 'int main(){return 0;}\n' > $$t && \
|
||||
if $(NVCC) -ccbin $$p -c $$t -o /dev/null >/dev/null 2>&1; then rm -f $$t; echo $$p; break; fi; rm -f $$t; done)
|
||||
HOSTCC := $(subst g++,gcc,$(HOSTCXX))
|
||||
endif
|
||||
COMPILER_FLAGS := $(if $(HOSTCXX),-DCMAKE_C_COMPILER=$(HOSTCC) -DCMAKE_CXX_COMPILER=$(HOSTCXX) -DCMAKE_CUDA_HOST_COMPILER=$(HOSTCXX),)
|
||||
# capped: inside a container nproc reports the host's CPUs, not the container's quota
|
||||
JOBS ?= $(shell n=$$(nproc 2>/dev/null || echo 4); [ $$n -gt 16 ] && n=16; echo $$n)
|
||||
# what `make build` produces; upstream's `all` also builds about 70 parity and bench programs
|
||||
TARGETS := strata strata-poly strata-dsv41 strata_kq unbiased-strata
|
||||
|
||||
.PHONY: build clean
|
||||
.PHONY: build configure clean test
|
||||
|
||||
build:
|
||||
configure:
|
||||
@test -f third_party/llama.cpp/ggml/CMakeLists.txt || \
|
||||
{ echo "third_party/llama.cpp is empty: run 'git submodule update --init' first"; exit 1; }
|
||||
@git -C third_party/llama.cpp apply --check --reverse ../../patches/llama.cpp-qwen3-coder-any-argument-order.patch 2>/dev/null || \
|
||||
git -C third_party/llama.cpp apply ../../patches/llama.cpp-qwen3-coder-any-argument-order.patch
|
||||
cmake -S . -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_NATIVE_EXPERTS=ON \
|
||||
-DSTRATA_PORTABLE=ON -DSTRATA_MMQ_KQUANTS=ON -DSTRATA_BUILD_TESTS=OFF "-DCMAKE_CUDA_ARCHITECTURES=$(CUDA_ARCHS)" $(SM60_FLAG) $(CMAKE_EXTRA)
|
||||
cmake --build $(BUILD_DIR) -j $(JOBS) --target unbiased-strata
|
||||
@echo "built: $(BUILD_DIR)/unbiased-strata"
|
||||
-DSTRATA_MMQ_KQUANTS=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_BUILD_DSV41=ON -DSTRATA_BUILD_TESTS=OFF \
|
||||
"-DCMAKE_CUDA_ARCHITECTURES=$(CUDA_ARCHS)" $(SM60_FLAG) $(PORTABLE_FLAG) $(COMPILER_FLAGS) -DCMAKE_CUDA_COMPILER=$(NVCC) \
|
||||
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=$(abspath $(BUILD_DIR))/bin \
|
||||
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$(abspath $(BUILD_DIR))/bin $(CMAKE_EXTRA)
|
||||
|
||||
build: configure
|
||||
cmake --build $(BUILD_DIR) -j $(JOBS) --target $(TARGETS)
|
||||
@echo "built:"; ls -1 $(BUILD_DIR)/bin/strata $(BUILD_DIR)/bin/strata-poly $(BUILD_DIR)/bin/strata-dsv41 $(BUILD_DIR)/bin/libstrata_kq.so $(BUILD_DIR)/bin/unbiased-strata
|
||||
|
||||
# The front end alone, without CUDA: for a laptop or a CI box. Needs only a C++20 compiler and CMake.
|
||||
.PHONY: frontend
|
||||
frontend:
|
||||
cmake -S . -B $(BUILD_DIR)-frontend -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_BUILD_TESTS=OFF \
|
||||
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=$(abspath $(BUILD_DIR))-frontend/bin $(CMAKE_EXTRA)
|
||||
cmake --build $(BUILD_DIR)-frontend -j $(JOBS) --target unbiased-strata
|
||||
|
||||
# The front end's tests, against a fake engine (frontend/tests/fake-engine.py): the adapter's cases (cancel, drain,
|
||||
# backpressure, child exit, ERR) and the HTTP surface a coding agent touches (frontend/tests/e2e.sh). Needs python3
|
||||
# and curl; no GPU and no model. Runs in the CUDA-free build directory, so it works on the build box and on a laptop.
|
||||
test: frontend
|
||||
cmake --build $(BUILD_DIR)-frontend -j $(JOBS) --target engine_test literals_test picture_cache_test
|
||||
$(BUILD_DIR)-frontend/bin/engine_test frontend/tests/fake-engine.py
|
||||
$(BUILD_DIR)-frontend/bin/literals_test
|
||||
$(BUILD_DIR)-frontend/bin/picture_cache_test
|
||||
frontend/tests/e2e.sh $(BUILD_DIR)-frontend/bin/unbiased-strata
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
|
||||
# Protocol and child supervision regressions; no CUDA/model required.
|
||||
.PHONY: test-frontend
|
||||
test-frontend:
|
||||
mkdir -p $(BUILD_DIR)/frontend-tests
|
||||
$(CXX) -std=c++20 -Wall -Wextra -Werror frontend/child_watch_test.cpp -o $(BUILD_DIR)/frontend-tests/child-watch-test
|
||||
$(BUILD_DIR)/frontend-tests/child-watch-test
|
||||
$(CXX) -std=c++20 -Wall -Wextra -Werror frontend/engine_test.cpp -o $(BUILD_DIR)/frontend-tests/engine-test
|
||||
$(BUILD_DIR)/frontend-tests/engine-test
|
||||
$(CXX) -std=c++20 -Wall -Wextra -Werror -pthread frontend/engine_backpressure_test.cpp -o $(BUILD_DIR)/frontend-tests/engine-backpressure-test
|
||||
$(BUILD_DIR)/frontend-tests/engine-backpressure-test
|
||||
|
||||
# Model-template compatibility; CPU only, after the regular build produced llama libraries.
|
||||
.PHONY: test-chat-parser
|
||||
test-chat-parser:
|
||||
@test -n "$(MODEL)" || { echo 'set MODEL to the first GGUF shard'; exit 2; }
|
||||
mkdir -p $(BUILD_DIR)/frontend-tests
|
||||
$(CXX) -std=c++20 -O0 -Ifrontend -Ithird_party/llama.cpp/include -Ithird_party/llama.cpp/common \
|
||||
-Ithird_party/llama.cpp/ggml/include -Ithird_party/llama.cpp/vendor -Ithird_party/llama.cpp/tools/mtmd \
|
||||
frontend/chat_parser_test.cpp \
|
||||
-o $(BUILD_DIR)/frontend-tests/chat-parser-test $(BUILD_DIR)/llama.cpp/tools/mtmd/libmtmd.a \
|
||||
$(BUILD_DIR)/llama.cpp/vendor/hash/libvendor-hash.a $(BUILD_DIR)/llama.cpp/common/libllama-common.a \
|
||||
$(BUILD_DIR)/llama.cpp/src/libllama.a $(BUILD_DIR)/llama.cpp/vendor/cpp-httplib/libcpp-httplib.a \
|
||||
$(BUILD_DIR)/ggml/src/libggml.a $(BUILD_DIR)/ggml/src/libggml-cpu.a $(BUILD_DIR)/ggml/src/libggml-base.a \
|
||||
$(BUILD_DIR)/llama.cpp/common/libllama-common-base.a -lpthread -ldl -lm
|
||||
$(BUILD_DIR)/frontend-tests/chat-parser-test "$(MODEL)"
|
||||
|
||||
# Against a running server: a request may ask for more tokens than the context has left (REGINA-112).
|
||||
.PHONY: test-serve
|
||||
test-serve:
|
||||
@test -n "$(PORT)" || { echo 'set PORT to a running server ([HOST:]PORT)'; exit 2; }
|
||||
python3 tests/python/serve_max_tokens_check.py $(PORT)
|
||||
@@ -0,0 +1,401 @@
|
||||
# UnbiasedStrata 2: plan
|
||||
|
||||
Fork of PolyStrata v0.1.45-poly.1 (VecSzn/PolyStrata, commit d0cd84dc) that keeps the engines and
|
||||
replaces the Python around them with C++ from the llama.cpp tree the engines already pin.
|
||||
|
||||
Status: decisions taken 2026-10-17 (§12). Items marked **[D]** were open at review time; §12 is the answer.
|
||||
|
||||
Sources: inventories of `serve/`, `tools/`, the CMake tree, the previous fork
|
||||
(`~/Code/UnbiasedStrata`) and llama.cpp `tools/server` at commit 3cf03257, taken 2026-10-17.
|
||||
File:line cites refer to the upstream checkout at `PolyStrata-v0.1.45-poly.1/` unless noted.
|
||||
|
||||
## 1. What upstream is, in one page
|
||||
|
||||
Two engine binaries, both speaking the same line protocol over stdin/stdout:
|
||||
|
||||
- `strata` (`src/program/generate.cpp`, 16k lines): Qwen3.8-Flash-Next from packs (`--pack`, `--mtp`).
|
||||
Also runs `--native` GGUF for qwen4exp/qwen35moe and dispatches qwen35moe to `src/qwen35/`.
|
||||
- `strata-poly` (`src/poly/`, 11k lines): GGUF read in place. glm5-next, qwen35moe (Qwen3.6-35B-A3B,
|
||||
Ornith, Tiel Coder, MiniCPM-V), gemma4, deepseek4, lfm2moe. No packing step.
|
||||
|
||||
The protocol (`docs/BACKENDS.md`, `serve/server.py:861-2080`, `generate.cpp:11621-14631`):
|
||||
|
||||
```
|
||||
in: GEN <max_new> [key=value ...] <id,id,...>
|
||||
GENI <max_new> [key=value ...] <embeddings-file> <id,id,...>
|
||||
STOP | QUIT | SAVE <path> | RESTORE <path> | VRAM [mib] | BGEN/BSTOP/BYIELD (--batch)
|
||||
out: INFO k=v ... ; READY <max_context> stop
|
||||
T <id> | PP <done> <total> <ms> <tok/s> | RESUME <n> | REUSED <n>
|
||||
DONE <generated> <prompt> <prompt_ms> <decode_ms> <finish> <drafts_acc> <drafts_off> <reused> ...
|
||||
ERR <msg> | FATAL <msg>
|
||||
```
|
||||
|
||||
The engine never tokenizes, never sees text, never sees a tool call. It samples on its own (GPU in
|
||||
`strata`, CPU in `strata-poly`) and returns token ids. Images arrive as embedding rows in a file
|
||||
(`SVE1` records) produced by `strata-vision`, a 302-line C++ child built on llama.cpp `mtmd`
|
||||
(`tools/vision/`).
|
||||
|
||||
Everything else is Python: tokenizer (`tools/strata_tokenizer.py`, hand-written BPE), Jinja
|
||||
templating (jinja2), five per-family tool-call parsers, SSE, three API dialects, MCP, metrics, web
|
||||
UI, model switching, installers. `serve/` is 13.2k lines of non-test Python plus 16.9k of tests.
|
||||
`setup.py` is 8,223 lines.
|
||||
|
||||
The engines use no `llama_*` API. They include `ggml.h`, `ggml-cpu.h`, and compile selected
|
||||
`ggml-cuda` sources (MMQ instances, `quantize.cu`) directly into their own libraries. The build
|
||||
takes `ggml-base` and `ggml-cpu` from `STRATA_GGML_DIR` and nothing else; `STRATA_GGML_DIR` empty
|
||||
means `FetchContent` of llama.cpp at 3cf03257 (`CMakeLists.txt:1459-1468`). The engine build runs no
|
||||
Python. The only build-time network access is that fetch.
|
||||
|
||||
## 2. Measured baselines already in hand
|
||||
|
||||
RTX 3090 24 GB, EPYC 7H12, CUDA 12.8, same pod, 2026-10-17. Recorded in this repo under
|
||||
`benchmark-results/` (upstream) and `results/` (llama.cpp).
|
||||
|
||||
| Engine | Model | Decode tok/s | PP tok/s at 32K | Notes |
|
||||
| --- | --- | ---: | ---: | --- |
|
||||
| PolyStrata v0.1.45 `strata` | Flash-Next GSQ-RCO IQ3_XXS, MTP spec 4 | 112.5 | 2,404 | 15 expert workers, int8 KV, 64K ctx |
|
||||
| llama.cpp 797de63 | Flash-Next GSQ-RCO IQ2_XS, MTP draft 2 | 41 to 48 | 515 to 558 | 14 GB expert cache, different quant |
|
||||
| PolyStrata (upstream docs, RTX 5090) | Qwen3.6-35B-A3B UD-Q3_K_M | 323 / 268 / 179 | 4,239 to 5,789 | `docs/BACKENDS.md`; not our card |
|
||||
|
||||
No Qwen3.6 number exists for the 3090 yet, on either side. Step 8 produces both.
|
||||
|
||||
## 3. Inventory of `serve/`: keep, write, or drop
|
||||
|
||||
"llama.cpp has it" means the code exists in the pinned submodule and is used unmodified.
|
||||
|
||||
| Feature in `serve/` | Disposition | Source |
|
||||
| --- | --- | --- |
|
||||
| `POST /v1/chat/completions`, stream and not; messages with system/user/assistant/tool, `reasoning_content` in and out | llama.cpp has it | `tools/server/server-common.cpp:1151-1425` parse, `server-task.cpp` results, `format_oai_sse` |
|
||||
| Chat template from the GGUF, `chat_template_kwargs`, `enable_thinking`, `reasoning_effort`, `preserve_thinking` | llama.cpp has it | `common/chat.cpp` `common_chat_templates_init/apply` on a vocab-only model |
|
||||
| Tokenize and detokenize | llama.cpp has it | `llama_vocab` from the GGUF, `vocab_only=true` |
|
||||
| Reasoning and tool-call parsing, incremental, per family (Qwen, GLM, Gemma 4, DeepSeek, LFM2) | llama.cpp has it | `common_chat_parse` PEG autoparser plus 15 hand-written parsers, `common_chat_msg_diff` |
|
||||
| Streaming deltas for content, reasoning and partial tool-call arguments | llama.cpp has it | `task_result_state::update_chat_msg`, `server-task.cpp:170-177` |
|
||||
| SSE framing, `[DONE]`, keepalive pings, client-disconnect cancel | llama.cpp has it | `server-http.cpp:544-583`, `sse_ping_interval`, `is_connection_closed` |
|
||||
| `max_tokens` clamp, context overflow 400 | llama.cpp has it; we add the `strata` engine's 8-token reserve | old fork `main.cpp:345-362` (`kEngineReserve = 8`, REGINA-112) |
|
||||
| Sampling: temperature, top_p, top_k, min_p, seed, penalties, `logit_bias`, `stop` | we write: map request fields to `GEN` keys (~80 lines); stop strings via server's `process_token` logic | engine keys at `generate.cpp:11626-11682`, `src/poly/main.cpp:561-572` |
|
||||
| Model-card default sampling per family when the client sends none | we write: CLI defaults like `llama-server` (`--temp` etc.), ~20 lines. pi always sends them | `serve/server.py:7380` |
|
||||
| `tool_choice=required` or a named tool | best effort: the template emits the opener grammar, the engine cannot enforce it. Same as upstream, which writes the opener into the prompt. We log a parse failure with raw output | see §5 |
|
||||
| `response_format` json_object / json_schema | **[D]** validate-only like upstream (~40 lines), or drop. Recommendation: drop in v1, revisit if a client needs it | `serve/structured.py` |
|
||||
| Images: `image_url` base64, multiple per message | llama.cpp has it: `mtmd` in-process, CPU encode by default, GPU by flag. We write the splice of pad ids and the `SVE1` file (~150 lines, old fork `vision.hpp`) | `tools/mtmd`, `generate.cpp:10558-10562`, `src/poly/main.cpp:211-222` |
|
||||
| Images from `http://` URLs | drop (rule 1: network at request time) | `serve/server.py:2451-2466` |
|
||||
| Prompt cache, conversation checkpoints | engine-side; we send `turn_at=` for poly and nothing else | `serve/server.py:1272` |
|
||||
| `GET /v1/models`, `/health` | llama.cpp has it; `/health` adds the engine's child state | |
|
||||
| `GET /metrics` Prometheus | llama.cpp has it (`server-task` metrics) if it falls out of design C; otherwise drop | `serve/prometheus.py` |
|
||||
| `GET /props`, `/slots`, `/v1/status` | drop `/slots` and `/v1/status`; `/props` only if free | |
|
||||
| `POST /v1/messages` (Anthropic), `/v1/responses` | **[D]** llama.cpp has the conversions (`server-chat.cpp`). Keep only if they compile with zero extra code, marked untested. pi uses chat completions | |
|
||||
| `/v1/messages/count_tokens` | drop | |
|
||||
| MCP hub, `strata_mcp` server-side tool execution | drop (rule 1: outbound HTTP at start; pi runs its own tools) | `serve/mcp.py` |
|
||||
| Web UI, API monitor, `/settings`, `/config`, telemetry sampler | drop (rule 4 and not needed; llama.cpp's UI downloads assets at build unless `LLAMA_USE_PREBUILT_UI=OFF`) | `serve/web/`, `serve/telemetry.py` |
|
||||
| Image generation via `sd-cli` | drop (rule 1: downloads stable-diffusion.cpp) | `serve/images.py`, `tools/image/` |
|
||||
| Replicas, CPU affinity, `--batch` slot scheduling (`BGEN`) | drop in v1. One request at a time, queued. Engine `--batch` stays in the tree, "present, unmeasured" | `serve/replicas.py`, `server.py:1572-1900` |
|
||||
| Model switching, load/unload, `VRAM` resize | drop in v1: one model per process, one systemd unit per model | `server.py` `Service.switch_model` |
|
||||
| `SAVE`/`RESTORE` sessions | drop in v1; engine keeps the feature | |
|
||||
| API key, Host and Origin checks | llama.cpp has `--api-key`; bind `127.0.0.1` by default | `server-http.cpp` middleware |
|
||||
| Reasoning budget, wrap-up injection, loop recovery, `tool_call_recovery`, `drop_oldest`, `env_to_user`, `warm_start`, `strata_prefix`, `strata_tune`, speed projection cvec | drop (heuristics and extensions; need logits or are upstream-only) | `server.py:4584-4932` |
|
||||
| `keepawake`, `winjob`, `cache_drop`, `session_save_retry` | drop (Windows or niceties) | |
|
||||
| `n`, `logprobs`, `stream_options` | not in upstream either; drop | |
|
||||
|
||||
New C++ we write regardless of design (§5): the engine adapter (spawn, `READY`/`INFO`, `GEN`/`GENI`
|
||||
write, `T`/`PP`/`RESUME`/`DONE`/`ERR`/`FATAL` read, `STOP` plus drain, watchdog-aware supervision),
|
||||
about 400 lines, with the old fork's `engine.hpp` and its three fake-engine tests as the reference.
|
||||
|
||||
## 4. Inventory of `tools/` and installers
|
||||
|
||||
The serving path touches nothing in `tools/` at request time except, on AMD, the 15 hipBLASLt and
|
||||
rocBLAS tuning tables in `tools/hip/*.txt` which the engine reads through env vars. Those stay where
|
||||
they are.
|
||||
|
||||
Offline tools that stay (rule: Python that runs once to produce model files is allowed):
|
||||
|
||||
| Group | Files | Network |
|
||||
| --- | --- | --- |
|
||||
| Flash-Next pack chain | `iq_pack.py`, `strata_tokenizer.py`, `gguf_reader.py`, `strata_pack.py`, `canonical_xcheck.py`, `pack_layer.py`, `pack_index.py`, `_paths.py`, `gguf_writer.py` | none |
|
||||
| MTP draft head | `mtp_fetch.py` (HF range reads), `mtp_pack.py`, `mtp_rt.py`, `draft_vocab.py`, `glm_draft_fetch.py` (HF) | the two fetchers, by design; they run once |
|
||||
| Quantization, NVFP4, inspection | `nvfp4_*.py`, `embd_bf16_pack.py`, `ple_fp8_pack.py`, `quant_*.py`, `quantscope.py`, `strata_inspect.py`, `iq_fixture.py` | HF API only when given a repo name |
|
||||
| Profiling and calibration | `make_profile*.py`, `collect_profile_traces.py`, `bench_eviction.py`, `replay_cache_policy.py`, `check_isa_guard.py` | none |
|
||||
| Benchmarks and engine gates | `strata_bench.py`, `ab_engine.py`, `agent_turns_bench.py`, `*_test.py` engine probes, `qwen35/` parity gates | localhost |
|
||||
| `calibrate.py` | imports `setup` and `serve.server`; stays in the tree but cannot run after the cut. Documented as such | |
|
||||
| Vision encoder source | `tools/vision/` (C++, mtmd). Stays unbuilt; the front end encodes in-process | |
|
||||
|
||||
The pack chain, as `setup.py:7851-7897` runs it, becomes a documented manual procedure in `README.md`:
|
||||
|
||||
```
|
||||
python tools/iq_pack.py --gguf <shard1> --out <pack> # add --compat-bf16 for Unsloth
|
||||
STRATA_SOURCE=huggingface python tools/mtp_fetch.py fetch --out <mtp>
|
||||
python tools/mtp_pack.py --src <mtp> --experts q2_0 --out <mtp>/mtp-q2_0.gguf
|
||||
python tools/mtp_rt.py --gguf <mtp>/mtp-q2_0.gguf --out <mtp>/rt
|
||||
cp data/draft_vocab.bin <mtp>/rt/draft_vocab.bin
|
||||
```
|
||||
|
||||
`mtp_pack.py` and `mtp_rt.py` need llama.cpp's `gguf-py`; `tools/_paths.py:16` already looks in
|
||||
`third_party/llama.cpp/gguf-py`, so the submodule satisfies it. Python deps for the tools: numpy and
|
||||
regex. `requirements.txt` shrinks to those two and moves to `tools/requirements.txt`.
|
||||
|
||||
`setup.py` jobs that are not downloads and must become documented flags (`setup.py` lines):
|
||||
GPU and compute-capability detection (1305-1437), CPU ISA floor and `--pool-workers` (1099-1304),
|
||||
RAM mode and KV streaming (4455-4544, 7949-7995), context and KV type and rope scaling (7589-7650,
|
||||
5882-5917), the cmake flag set (4397-4403), engine argument assembly (7910-8060), run-config JSON
|
||||
(8077-8160), draft vocab copy (5759), HIP table pick (3395). The fork's `README.md` gets a table of
|
||||
these as explicit engine flags per model, with the values setup would have chosen for a 24 GB card.
|
||||
|
||||
## 5. Front end: three designs, one recommendation
|
||||
|
||||
The engine returns sampled tokens, not logits. That fact rules every design: grammar-constrained
|
||||
decoding (`json_schema`, `tool_choice=required`, reasoning budget) cannot be enforced without an
|
||||
engine change. Upstream has the same limit (`v1_status` advertises `constrained_decoding: false`).
|
||||
We accept it, as upstream does, and log raw model output whenever a tool call fails to parse.
|
||||
|
||||
**A. llama.cpp `tools/server` with the Strata engine behind its slot loop.** `server-context.cpp`
|
||||
is 5,558 lines; about 2,500 of them assume one `llama_batch` across slots, per-slot logit indices,
|
||||
`common_sampler` reading logits through `llama_context`, and `llama_memory_seq_*` for cache and
|
||||
checkpoints (`server-context.cpp:111-237, 2857-4024`). Substituting an engine that batches,
|
||||
caches, samples and drafts internally is a rewrite of that file, not a patch. Every pin bump
|
||||
re-ports it. Rejected.
|
||||
|
||||
**B. New main on `common` + `mtmd` + `httplib`.** What the old fork did: 1,269 lines, proven under
|
||||
pi for a week, zero llama.cpp patches beyond the parser fix. Cost: hand-written SSE, disconnect,
|
||||
keepalive, OpenAI JSON shapes, request parsing, delta diffs. Seven of its fourteen production bugs
|
||||
were in exactly that hand-written layer (streaming held back content, silent wire during tool
|
||||
calls, no `max_tokens` clamp, pipe drain, control-token tokenization).
|
||||
|
||||
**C. Hybrid: compile the engine-agnostic server files unmodified, replace `server-context.cpp`.**
|
||||
From the submodule, as-is: `server-http` (838), `server-queue` (621), `server-task` (1,901),
|
||||
`server-common` (1,986), `server-chat` (692), `server-schema` (662), `server-stream` (668). New:
|
||||
`frontend/strata-context.cpp` implementing the queue callbacks and the routes we keep, the engine
|
||||
adapter, a vision module, `main.cpp`, and a 20-line stub for `llama_ui_*` so `server-http` links
|
||||
without the UI target. Estimated 2,000 to 3,000 new lines. Patches to llama.cpp: 0 to 30 lines
|
||||
(five `server-common` signatures take `llama_context*` only to reach the vocab; we either avoid
|
||||
those five or add vocab overloads). Compile-time seam when the pin moves: about six types.
|
||||
|
||||
**Recommendation: C**, because it is the ethos of this fork applied to the front end. SSE,
|
||||
disconnect handling, pings, request schema, result formatting, incremental tool-call deltas and
|
||||
Prometheus metrics come from llama.cpp unchanged, and the bugs the old fork spent a week on are in
|
||||
code we did not write. The risk is the undocumented internal API of `tools/server`; the pin is
|
||||
fixed, so that risk is paid once. Gate: step 4 must have `/v1/models` and a non-streaming chat
|
||||
completion working against a fake engine, with the seven server files compiling unmodified, within
|
||||
the first front-end commit. If that needs more than 30 patch lines to llama.cpp, fall back to B
|
||||
with the old fork's `main.cpp` as the starting point. **[D]**
|
||||
|
||||
Facts that shape the implementation either way:
|
||||
|
||||
- The vocab-only `llama_model` has no hparams (`src/llama-model.cpp:1250`), so `n_embd`, rope type
|
||||
and context length come from the GGUF through `gguf_*` or Strata's own reader. The old fork did
|
||||
this for the projector width check (`vision.hpp:72-87`).
|
||||
- `mtmd` on a vocab-only model misclassifies M-RoPE position type. We only take embeddings
|
||||
(`mtmd_encode_chunk`, `mtmd_get_output_embd`); the engine computes positions itself, so this does
|
||||
not matter.
|
||||
- `setup.py` builds `strata-vision` from llama.cpp 69f201a2, not the engine pin, for MiniCPM-V
|
||||
(`setup.py:186-189`). We use one pin. MiniCPM-V images are "present, unmeasured, possibly
|
||||
unsupported at 3cf03257" until checked.
|
||||
- The parser patch `qwen3-coder any argument order` from the old fork (`patches/`) is still needed
|
||||
at this pin: Qwen3.6 and Qwen3.8 route to that parser and the upstream grammar silently drops a
|
||||
call whose optional argument comes first. Applied once, at configure time, idempotently (the old
|
||||
fork had to apply it in two places; we apply it in one). (2026-10-19: the patch and its DeepSeek/GLM counterpart are commits on robertkarl/llama.cpp, branch `UnbiasedStrata`, which the submodule pins; nothing is applied at configure any more.)
|
||||
- Prompt caching stays in the engine. The front end sends the full id list every request.
|
||||
- Encode images on CPU by default to leave VRAM for the expert cache; `--vision-gpu` to move it.
|
||||
|
||||
## 6. Engines and models
|
||||
|
||||
Keep both engines in the build. **[D]**
|
||||
|
||||
| Engine | Model | Status at the end of this plan |
|
||||
| --- | --- | --- |
|
||||
| `strata` | Qwen3.8-Flash-Next GSQ-RCO IQ3_XXS, MTP spec 4, 24 GB card | measured against upstream, same pod |
|
||||
| `strata-poly` | Qwen3.6-35B-A3B Unsloth UD-Q3_K_M (17.1 GB), draft block in the file | measured against upstream, same pod |
|
||||
| `strata-poly` | GLM 5.3 Flash, DeepSeek V4 Flash, LFM2.5, Ornith, Gemma 4, Tiel Coder, MiniCPM-V | present, unmeasured |
|
||||
| `strata` | other Flash-Next quants, Coder, Unsloth NVFP4 | present, unmeasured |
|
||||
|
||||
Images: Qwen3.6 verified; Gemma 4 and MiniCPM-V present, unmeasured.
|
||||
|
||||
**One binary.** Both engines and the front end in one executable, dispatched on a hidden `--engine
|
||||
strata|poly` first argument, forked by the front end before any thread exists (the old fork's
|
||||
pattern, `main.cpp:742-765`). Two engine `main()`s are renamed without touching engine source, by a
|
||||
wrapper translation unit that defines `main` away and includes the engine's file (old fork
|
||||
`engine_entry.cpp`). Costs that are build-only: `strata_mmq` and `strata_poly_mmq` both compile
|
||||
`quantize.cu` and `ggml_cuda_host.cu` and must merge into one MMQ library with the union of the
|
||||
per-type instance files (`CMakeLists.txt:1577, 2035`); `strata_kq` is a shared object dlopened from
|
||||
the exe's directory (`src/prefill/mmq_kq_loader.cpp:43-60`). Upstream made it a `.so` on purpose
|
||||
(`CMakeLists.txt:1666-1669`): it is an optional plugin carrying its own copy of `ggml_cuda_host.cu`
|
||||
and the static CUDA runtime, and without the file K-quant experts fall back to the FP16 prompt
|
||||
path. Qwen3.6 UD-Q3_K_M is K-quant, so we need it. Linking it in means removing that duplicate
|
||||
copy and the dlopen seam (`mmq_kq_lib.cu`, `mmq_kq_loader.cpp`): an engine build change with a
|
||||
measurable gate (PP on a K-quant model equal before and after). Risk: non-`main` symbol clashes
|
||||
between `generate.cpp` and `src/poly/main.cpp`. Fallbacks, in order: one binary plus
|
||||
`libstrata_kq.so` beside it; three executables in one `build/bin/`, copied as a directory. **[D]**
|
||||
|
||||
## 7. Build layout
|
||||
|
||||
```
|
||||
Makefile make build | make test | make bench ; CUDA_ARCHS=, PORTABLE=, JOBS=
|
||||
CMakeLists.txt upstream's, plus: submodule default, front end, merged MMQ lib
|
||||
.gitmodules third_party/llama.cpp -> robertkarl/llama.cpp branch UnbiasedStrata (3cf03257 + parser commits), shallow
|
||||
(patches/ applied at configure until 2026-10-19; now commits on that branch, see UPSTREAM.md)
|
||||
frontend/ strata-context.cpp, engine.hpp, vision.hpp, ui_stub.cpp, main.cpp, tests
|
||||
src/ include/ upstream engine, unchanged except what UPSTREAM.md lists
|
||||
tools/ upstream's offline Python, minus installers (§8)
|
||||
data/ upstream's profiles and draft vocabs (runtime data, kept)
|
||||
docs/ upstream's engineering docs (kept), minus marketing (§8)
|
||||
bench/ bench_vs_llama.py + corpus, kernel probes, correctness/ harness (2026-10-19: per-run records and
|
||||
upstream's results/ removed from the tree, in history at 7551f138)
|
||||
sycl/ metal/ tests/ kept, unbuilt
|
||||
README.md UPSTREAM.md PLAN.md LICENSE
|
||||
```
|
||||
|
||||
CMake changes to upstream, each one hunk, recorded in `UPSTREAM.md`:
|
||||
|
||||
1. `STRATA_GGML_DIR` default becomes `third_party/llama.cpp`; `FATAL_ERROR` with the submodule
|
||||
command if `ggml/CMakeLists.txt` is missing; the `FetchContent` block is deleted
|
||||
(`CMakeLists.txt:1416, 1456-1469`). `FETCHCONTENT_FULLY_DISCONNECTED ON` as a belt.
|
||||
2. `.gitignore:31` stops ignoring `/third_party/llama.cpp*`.
|
||||
3. A configure-time `execute_process(git apply --check ...)` step for `patches/`, idempotent.
|
||||
4. A second `add_subdirectory(third_party/llama.cpp)` with `LLAMA_BUILD_COMMON=ON`,
|
||||
`LLAMA_BUILD_MTMD=ON`, `LLAMA_BUILD_SERVER=OFF`, `LLAMA_BUILD_TOOLS/TESTS/EXAMPLES=OFF`,
|
||||
`LLAMA_USE_PREBUILT_UI=OFF`, `LLAMA_OPENSSL=OFF`, `LLAMA_LLGUIDANCE=OFF`. `LLAMA_CURL` is already a
|
||||
no-op at this pin. The `tools/server/*.cpp` files we reuse are listed as sources of our own
|
||||
static library pointing into the submodule.
|
||||
5. The one-binary merge (§6).
|
||||
|
||||
`make build` runs one configure and builds only the targets we ship: not `all`, which includes
|
||||
about 70 parity and bench executables that are not test-gated (`CMakeLists.txt:850-1256`).
|
||||
|
||||
Defaults: `-DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=OFF -DSTRATA_MMQ_KQUANTS=ON
|
||||
-DSTRATA_Q6K_EXPERTS=ON`, `CMAKE_CUDA_ARCHITECTURES` from `CUDA_ARCHS`, default `61;75;86;89`, with
|
||||
`STRATA_EXPERIMENTAL_SM60=ON` added whenever an arch below 75 is listed (upstream refuses sm_61
|
||||
without it, `CMakeLists.txt:190-196`). Upstream's default is `120` alone, which needs CUDA 13.
|
||||
`GGML_NATIVE=ON` means `-march=native` for the CPU expert kernels: build where you run, or
|
||||
`PORTABLE=1` for an AVX2 baseline. **[D]** on the arch list: each arch adds minutes of nvcc time.
|
||||
|
||||
Requirements on the build box, same as llama.cpp plus: CMake 3.24 or newer (Ubuntu 22.04 ships
|
||||
3.22), a C++20 compiler, CUDA 12.x toolkit, driver. No Python, no git access after
|
||||
`git submodule update --init`.
|
||||
|
||||
## 8. Cut list
|
||||
|
||||
Each entry names the rule from the brief: (1) network at setup, build or start; (2) Python between a
|
||||
request and a token; (3) breaks or complicates the one-command build; (4) marketing.
|
||||
|
||||
| Path | Size | Rule |
|
||||
| --- | --- | --- |
|
||||
| `setup.py`, `setup.sh`, `SETUP.bat`, `START-HERE.bat`, `UPDATE.bat`, `update.sh` | 530 KB | 1 |
|
||||
| `serve/` (92 files; server, three API dialects, MCP, UI, telemetry, tests) | 2.0 MB, 33.9k lines | 2 |
|
||||
| `polystrata.py` (imports `serve/` and `setup`) | 12 KB | 2 |
|
||||
| `Dockerfile`, `docker-entrypoint.sh`, `flake.nix`, `flake.lock`, `.dockerignore` | | 1 |
|
||||
| `requirements.txt` (jinja2, pillow, psutil, requests, cmake, ninja...) | | 1; replaced by `tools/requirements.txt` with numpy and regex |
|
||||
| `tools/strata_mcp.py` (installer driven over MCP) and its test | 1,885 lines | 1 |
|
||||
| `tools/image/` (stable-diffusion.cpp, Vulkan SDK, HF downloads) | | 1 |
|
||||
| `tools/hip/package_windows.py` (AMD nightly wheels) | | 1 |
|
||||
| `tools/test_setup_*.py` and the two golden JSONs (test `setup.py`) | 44 files | 1, follows `setup.py` |
|
||||
| `tools/test_strata_mcp.py`, `test_qimage.py`, `test_docker_entrypoint.py`, `test_poly_prebuilt.py`, `test_chat.py` | | follow their subjects |
|
||||
| `README.{de,es,fr,ja,pt-BR,zh-CN}.md` | 383 KB | 4 |
|
||||
| `docs/media/` (9.6 MB webp demo, 1.8 MB gif, figures) | 12 MB | 4 |
|
||||
| `.github/` (issue and PR templates), `SECURITY.md`, `AGENTS.md` | | 4 |
|
||||
| `docs/INSTALL.md`, `AI_SETUP.md`, `MCP_SERVER.md`, `IMAGES.md`, `LLAMA_SWAP.md`, `COMMUNITY_BENCHMARKS.md`, `FAQ.md` | | **[D]** documents only cut components; recommend cut, rest of `docs/` stays |
|
||||
| `README.md` | 57 KB | rewritten (§10) |
|
||||
|
||||
Kept although large and unbuilt, per the brief: `sycl/` (7.8 MB), `metal/` (1.2 MB), `tests/`,
|
||||
`bench/` (23 MB of upstream results and the profile corpus; the results went 2026-10-19, see UPSTREAM.md), `docs/` engineering pages (`DETAILS.md`,
|
||||
`BACKENDS.md`, `QUANTS.md`, `MULTI_GPU.md`, `AMD_HIP.md`, `INTEL.md`, ...), `data/`, `ref/`,
|
||||
`third_party/ggml/` (upstream's `ggml-common.h` copy), `tools/vision/`, `chat.py` (stdlib client,
|
||||
depends on nothing), `tools/make_poly_release.py`, `tools/calibrate.py` (inert after the cut).
|
||||
|
||||
Expected diff shape: removals dominated by `setup.py`, `serve/`, translations and media; `src/` and
|
||||
`include/` untouched at import plus whatever `UPSTREAM.md` lists.
|
||||
|
||||
## 9. Steps, each a commit, each gated
|
||||
|
||||
| # | Step | Gate (what is verified before the commit) |
|
||||
| --- | --- | --- |
|
||||
| 0 | Decisions in this file signed off | you |
|
||||
| 1 | Import `PolyStrata-v0.1.45-poly.1/` as the root commit, byte for byte | `diff -r` against the checkout is empty; `git log` shows one commit |
|
||||
| 2 | Submodule at `third_party/llama.cpp` @ 3cf03257 shallow; CMake hunks 1 to 4; `Makefile`; `patches/` with the parser patch; `UPSTREAM.md` opened | `make build` on a Linux CUDA box with networking disabled (`unshare -n` or firewall) produces `strata`, `strata-poly`; `strace -f -e trace=network` shows no connects |
|
||||
| 3 | Cuts (§8), one commit per rule group, message cites the rule | `make build` still passes offline |
|
||||
| 4 | Front end skeleton (design C): server files from the submodule, `strata-context.cpp`, engine adapter, fake engine | `make test`: fake-engine tests (drain on error, cancel, backpressure, child exit diagnosis, ported from the old fork); `/v1/models`; non-streaming chat against the fake engine. Decision gate for C vs B |
|
||||
| 5 | One binary (§6) | the single executable runs `--engine strata --version` and `--engine poly --version`; still offline |
|
||||
| 6 | First end-to-end chat, both engines | Qwen3.6 UD-Q3_K_M from GGUF; Flash-Next IQ3_XXS from the pod's existing pack and MTP dir. Streaming and non-streaming, reasoning on and off, greedy output equal to upstream PolyStrata on the same ids (teacher-forced id comparison, not text) |
|
||||
| 7 | Tool calls under pi | pi completes a multi-step coding task against each model. Test the request shapes pi sends: no `max_tokens`, `max_tokens` 32768, optional arguments first, `reasoning_content` on assistant messages, parallel calls, a client that disconnects mid-stream, a stream silent during a long prompt. Raw output logged on parse failure |
|
||||
| 8 | Images | a screenshot through pi to Qwen3.6; projector width checked against the model | Done 2026-10-18 on the A6000 VM (`bench/unbiased/2026-10-18-a6000-qwen36-iq4xs-images-step8/`): six facts read off a 1920x1080 screenshot, by the API and through pi; width check at start. Encoder on the CPU only (15 s a picture at the 300-row default on a Ryzen 7 1700); giving it the card is a build change, open. |
|
||||
| 9 | Measurements (§11) | tables under `bench/unbiased/` with commands, raw outputs, checksums of the model files | Rows 1-2 done 2026-10-18 (`bench/unbiased/2026-10-17-3090pod-step9/`); row 3 done (within noise per token); one cell to explain (Qwen3.6 16K prefill 2.3 % slower). |
|
||||
| 10 | `README.md`, `UPSTREAM.md` complete | every `src/`/`include/` hunk since the import appears in `UPSTREAM.md`; README has only numbers that have rows | Done 2026-10-18: README rewritten (build, run lines, pack chain, measured table from step 9 and 6 records only, limits, cut rule); UPSTREAM.md gains the front-end behaviour list; `src/`/`include/` diff since import is empty. |
|
||||
| 11 | **Correctness plan** (added 2026-10-17). An agent writes `docs/CORRECTNESS-PLAN.md`: how to check PolyStrata's engines against llama.cpp at the pinned commit for the kernels actually in use on our target (the expert MMQ paths for IQ3_XXS and the K-quants, the MTP draft layer, the Q8/int8 KV paths, the prompt path, `strata-poly`'s qwen35moe path), which of upstream's ~70 parity and bench programs cover them and what each compares against, the teacher-forced greedy id comparison against llama.cpp for Flash-Next and Qwen3.6 (same ids in, how many tokens, what divergence is tolerated and why), what a failure would mean for the fork, and the cost in machine time. Planning only: this step runs nothing on a GPU and changes no code | the document, with each proposed check naming the program or script, the reference it compares against and the pass criterion; your sign-off on which checks become a later step |
|
||||
| 12 | **Correctness checks** (added 2026-10-17). Run the checks step 11 proposed and you signed off: upstream's parity programs that cover the kernels in use, and the teacher-forced greedy id comparison of each engine against llama.cpp at the pinned commit for Flash-Next IQ3_XXS and Qwen3.6 UD-Q3_K_M. Results, commands and raw outputs under `bench/unbiased/correctness/`; a divergence is a bug to find, in the engine or in llama.cpp, before any README claim beyond "same output as upstream PolyStrata" | every signed-off check has a result on disk with its pass criterion met, or an open finding with the first diverging token, the inputs that reproduce it and which side is wrong; `docs/MODEL-FILES.md` says per file whether it passed | Done 2026-10-18 on the A6000 VM (`bench/unbiased/correctness/`): 38 parity programs pass, `poly_expert_parity` fails its own bound on one UD-Q3_K_M expert (USTRAT-1); teacher-forced distributions of both engines on 16 sequences per model are within llama.cpp's own CPU-vs-GPU spread on every set and arm (T2); the greedy token agrees at every 0.5-nat-margin position but a handful of near ties per arm (USTRAT-3, USTRAT-5); drafting is not bitwise inert above 4-token windows (USTRAT-2); `strata`'s bits depend on the free VRAM at start unless the expert cache is pinned (USTRAT-4); `check-batch 4` passes. `docs/MODEL-FILES.md` has the per-file column. Not covered on 48 GB: the 24 GB tier pattern, a full-GPU Flash-Next reference. **Extended 2026-10-19 to DeepSeek V4 Flash UD-IQ2_XXS and GLM 5.3 Flash 3.0bit** on a 2x RTX PRO 6000 pod (the 2x B200 run was lost with the pod): T2 passes every set and arm (DeepSeek 0.69-1.06x, GLM 0.89-1.13x the floor); T1 flips at 3 (DeepSeek) and 5 (GLM) margin positions where both llama.cpp runs agree, T2 holding (USTRAT-10); the GLM draft arm is not bitwise the base arm because the draft block's VRAM moves 52 experts to the CPU (USTRAT-9); DeepSeek's is, on 15 of 16. GLM's reference is llama.cpp master 99db719b (the pinned tree lacks `glm5-next`); a master-vs-pinned CPU probe on DeepSeek measures the reference's own drift (`bench/unbiased/correctness/README.md` section 8). `--kv q8_0` is qwen35moe-only, not run. |
|
||||
| 13 | **Model acceptance suite** (added 2026-10-17; scope cut 2026-10-19 after step 12: the model math is proven within llama.cpp's own spread, so this step checks what teacher-forced greedy cannot: the sampled path end to end and a coding agent doing real work against each model family). (a) For every model family the fork serves, on a box that holds it: Qwen3.8-Flash-Next IQ3_XXS (RTX 3090 pod), Qwen3.6-35B-A3B UD-Q3_K_M and UD-IQ4_XS (3090 pod, A6000 VM), DeepSeek V4 Flash UD-IQ2_XXS and GLM 5.3 Flash 3.0bit (the 2x B200 pod: first bring-up of both on this fork, `strata-poly`, `src/poly/deepseek4.cpp`, upstream's docs/DEEPSEEK.md and docs/GLM.md run lines). (b) The task: pi, with its tools, in a fresh sandbox directory on the pod, against the fork's server, told to write a minesweeper clone in html/js/css and make it run; sampled, not greedy (the model card's defaults, fixed seed; a second run at temperature 1.0). The page it leaves is rendered headless (lookingglass) and must load without a console error and expose a clickable grid; pi's transcript, the server log, token counts and wall time are the record. (c) The API-only variant of the same prompt for the row's decode and prompt tok/s against the step 6/9 numbers for that card, a 15 % band. One script, `frontend/tests/acceptance-real-engine.sh`, the same for every family; the pod setup downloads every file fresh from Hugging Face onto the container disk (the RunPod network volume is too slow to serve from), `tools/pod/bringup.sh`. Dropped from the 2026-10-17 stub: models whose files we do not have beyond those four families, judging the page beyond render and a click, and the first-run-sets-the-range machinery (step 14 owns performance) | per family: loaded, pi produced a page that renders and clicks, decode and PP inside the band; DeepSeek V4 Flash and GLM 5.3 Flash rows added to `docs/MODEL-FILES.md` with hashes and the box **Done 2026-10-19** (fork commits a8469d55, 3a37ac63 and the closing commit; record `bench/unbiased/2026-10-19-step13-acceptance/`, harness `tools/acceptance/`, API script `frontend/tests/acceptance-real-engine.sh`). Per model family, pi 0.85.1 in Docker with tools, sampled as the model card asks, four work items (md-toc CLI, HTTP KV store, three planted bugs, Minesweeper; Minesweeper again at temperature 1.0): Flash-Next IQ3_XXS and Qwen3.6 UD-Q3_K_M on the RTX 3090 pod 5 of 5 each; Qwen3.6 UD-IQ4_XS on the A6000 VM 5 of 6 (the temperature-1.0 page throws a ReferenceError of its own); DeepSeek V4 Flash UD-IQ2_XXS and GLM 5.3 Flash 3.0bit on the 2x B200 pod 5 of 5 each after two fork fixes found by this step: GLM's architecture name refused by the vocabulary load (USTRAT-6, `frontend/strata_context.cpp`) and tool-call arguments out of schema order rejected by llama.cpp's grammars because the engine samples unconstrained (USTRAT-7, `patches/llama.cpp-any-argument-order.patch`); GLM also needs `reasoning_effort` low or high (its template treats anything else as max). API-only checks: thinking split, seeded repeat, tool call, decode and prompt speed within 15 % of step 9 on the 3090 (Flash-Next only with `--pool-workers 15`; 24 is 14 % slower), first figures on the B200 (DeepSeek 72 tok/s, GLM 74 tok/s decode on one card), A6000 IQ4_XS prose decode 175 tok/s recorded as its own baseline. Both pods downloaded every file fresh from HF (`tools/pod/bringup.sh`). |
|
||||
| 14 | **Performance parity protocol** (added 2026-10-18; the ship bar is "within 5 % of upstream on decode and prompt processing", every model, every target card). Builds on step 9. (a) Same engine binary on both sides first: the fork front end driving upstream's engine binaries (the `forkfe-upengine-*` arms of 2026-10-18) separates the front end from the engine build; then both engines built with the same compiler, nvcc, flags and `-march` recorded, so the two binaries differ in nothing but the tree they were built in. (b) Workloads, each 5 runs, median and range, greedy: short chat decode; sustained 512-token decode; prefill 4K / 16K / 32K and the model's maximum context; agent turns with growing history, with the reused-token counts recorded (a front end that renders the template differently breaks the prompt cache, and that shows as `cache_n`, not as tok/s); time to first token; inter-token latency p50 and p99 from the client's timestamps; client-side tok/s next to engine-side tok/s (the SSE and JSON cost of each front end); cold start to READY and warm start. (c) Every file in `docs/MODEL-FILES.md`, on each target card (Pascal 1080 Ti, RTX 3090, A6000), upstream and fork back to back. (d) A 1-hour soak of mixed request shapes with RSS and VRAM sampled every minute. Pass: fork median within 5 % of upstream on every (model, card, workload) cell, or the ranges overlap; `cache_n` equal per turn; RSS and VRAM flat. Any cell outside is a finding with the arm directories that reproduce it | tables under `bench/unbiased/parity/<date>-<card>/` with provenance (engine sha256, compiler, flags) per arm; every cell filled or marked blocked with the reason |
|
||||
| 15 | **Accuracy protocol against llama.cpp** (added 2026-10-18; extends step 12 with pass criteria). The reference is llama.cpp at the pinned commit, CUDA build, on the same GGUF. (a) Noise floor first: llama.cpp CUDA versus llama.cpp CPU on the same model and ids, per-position logits: max abs difference, KL(ref||other) per position, top-1 agreement. That floor is the tolerance, as the user put it: "as close as llama.cpp's GPU and CPU kernels are to each other". (b) Kernel level: upstream's parity programs that cover the kernels in use (step 11's list) at the pinned commit on each target arch, all green; the per-kernel error against the ggml reference recorded, not only pass/fail; target 1e-5 relative where the kernel is exact-arithmetic (norms, rope, residual), and the quant kernels within the floor from (a). (c) Logit level, teacher-forced: the engine's per-position logits along fixed ids (upstream's `--teacher-force` style diagnostics, `tools/canonical_xcheck.py`) against llama.cpp CUDA for Flash-Next IQ3_XXS and Qwen3.6 UD-Q3_K_M and UD-IQ4_XS: per-position KL median and p99, top-1 agreement rate, first position where the greedy argmax differs; 20 prompts of 512 to 4096 tokens including code and a tool-call transcript. Pass: median KL within 2x the floor from (a), top-1 agreement not below the floor's. (d) Perplexity on a fixed public text (a wikitext-2 slice, 64K tokens) engine versus llama.cpp CUDA: within 1 %. (e) Speculation is lossless: greedy ids with `--spec 0` equal to `--spec 4` and to the drafter off, for 20 prompts x 512 tokens; sampled with a fixed seed likewise. (f) Each speed knob upstream ships on by default that changes answers (`--tail-skip`, `STRATA_ROUTE_TAIL_SKIP`, int8 KV, `--spec-min-p`) measured off versus on with the (c) metrics, so the README states the accuracy cost of each default. (g) Long context: a needle test (`tools/needle_bench.py`) at 32K and the model's maximum, engine versus llama.cpp. Pass criteria written down before the runs | `bench/unbiased/correctness/<date>/` with the floor, every metric per model, the commands and the raw logits' checksums; `docs/MODEL-FILES.md` says per file: KL median and p99 against llama.cpp, top-1 agreement, PPL ratio |
|
||||
| 16 | **Front-end equivalence to upstream's Python server** (added 2026-10-18; the part of the port that is not the engine). (a) Prompt rendering: a corpus of chat requests (system prompt, multi-turn, tools with optional arguments, tool results, `reasoning_content` on assistant turns, `enable_thinking` on and off, `preserve_thinking`, an image once step 8 lands) rendered by upstream's jinja2 path and by llama.cpp's template engine in the fork: the token id sequences must be identical, per model template. A difference changes what the model sees and breaks checkpoint reuse. (b) Output parsing: a corpus of raw model outputs (tool calls in both argument orders, parallel calls, reasoning blocks, truncated streams) parsed by upstream's per-family parsers and by llama.cpp's: same `tool_calls`, same `content`, same `reasoning_content`. (c) Streaming equals non-streaming: for the same seed, the concatenated deltas equal the non-streamed message, usage counts equal the engine's `DONE` counts. (d) API conformance: the HTTP-level tests of upstream's `serve/` (import commit, 58 files) that apply to the kept surface, ported to run against both servers; cancel and disconnect semantics (the engine is told to stop; the next request is clean) on both. (e) Task level: pi on 10 fixed coding tasks x 3 runs per server, pass rate and tokens per wall second; within noise | corpora and results under `bench/unbiased/frontend-equivalence/`; a rendering or parsing difference is a bug in the fork unless upstream is shown wrong, with the request that reproduces it |
|
||||
| 17 | **Release gate** (added 2026-10-18). Steps 12 to 16 green or every open finding written in `README.md` with its size; the acceptance suite (13) run on every file on at least one card; `UPSTREAM.md` current; a tagged commit with the `bench/unbiased/` directories it was judged on | the tag; the README's measured table cites only those directories |
|
||||
| 18 | **Multi-GPU** (added 2026-10-19, user priority after the correctness work). Upstream runs one model across several cards as a layer split (`docs/MULTI_GPU.md`): `strata` (Flash-Next) with `--layer-split`, `--split-device`, `--split-skip-if-fits`, the chunk pipeline, `--pipeline-windows` and the `STRATA_SPLIT_*` variables; `strata-poly` with `--layer-split auto|N[,N...]` across the cards `CUDA_VISIBLE_DEVICES` shows it (two RTX 3080 measured upstream for Qwen3.6, Gemma 4, GLM REAP50; two cards hold about twice the experts, decode and prefill gain follow from that). The engines' code is unchanged in this fork, so the capability is intact; what went with `setup.py` and `serve/` (UPSTREAM.md, Removed) is the glue: card detection and the `--gpus 0,1` choice, the run-config `"gpu"`/`"layer_split"` fields, putting the faster card last, `--calibrate` setting `--prefill-pipe`, and `tools/batch_test.py`'s config-driven `--layer-split`. Nothing in the fork has exercised a split yet; the first run is the 2x RTX PRO 6000 pod (DeepSeek V4 Flash UD-Q4_K_XL / UD-Q8_K_XL, `tools/pod/serve.sh deepseek-q4|deepseek-q8`, `--layer-split auto`). Work: (a) README Run section documents `CUDA_VISIBLE_DEVICES` plus `--layer-split` for both engines as the replacement for `--gpus`, including the faster-card-last rule; (b) the front end passes the environment through untouched and `/props` or the log says which cards and layers each stage took; (c) measured: one card vs two, same model and workloads as step 14, on the 2-card pod for strata-poly (DeepSeek, GLM) and, when a 2-card 24 GB-class box exists, Flash-Next with `strata`; (d) correctness: the step-12 arms (T1/T2 against llama.cpp, T0 base vs draft) on the split, since upstream notes the rounding changes with which card or the CPU computes an expert; (e) upstream's layer-split parity and gate programs that still build, run and recorded | `bench/unbiased/multi-gpu/<date>-<box>/` tables with the split chosen per cell and the engine log lines naming each card's layers; README section with the flags and the measured rows; any divergence a finding with the inputs that reproduce it |
|
||||
|
||||
Steps 14 to 17 (2026-10-18) are the ship bar for consumers of PolyStrata: as fast and as accurate as upstream within
|
||||
5 % on decode and prompt processing, kernels within 1e-5 where exact and otherwise within the spread between
|
||||
llama.cpp's own GPU and CPU kernels, logits close in KL, and the front end rendering and parsing exactly what the
|
||||
Python server did. Step 8 (images) precedes them in order; step 5 stays on its fallback by decision.
|
||||
|
||||
Step 13 is the minimum "does it work" bar per model file: load, a sampled program that runs, speed inside a known
|
||||
range. It is a sanity check, not a correctness proof: a kernel that is slightly wrong still writes a program that runs,
|
||||
and only step 12's id comparison against llama.cpp shows the engine computes what it should. Both stay.
|
||||
Step 11 is a plan, not a run, and step 12 runs what it proposes; they exist because the plan above inherits the engines' correctness from upstream without
|
||||
checking it (TRELLO.md: "Vet polystrata fork on correctness"), and the step-6 gate as run compared text and token counts,
|
||||
not ids. Steps 2, 6, 7, 8, 9 need a Linux box with an NVIDIA card. You hand me the machines; the RunPod pod
|
||||
from the 2026-10-17 benchmark has the IQ3_XXS pack, the MTP dir and the upstream build. Nothing
|
||||
runs on the homelab.
|
||||
|
||||
## 10. Documents
|
||||
|
||||
`README.md`: what it is (one paragraph), the two engines and the model table with measured versus
|
||||
present-unmeasured, the exact build lines, the exact run line per measured model with every flag
|
||||
`setup.py` would have chosen, the pack chain, the measured table, the cut list with rules, known
|
||||
limits (no constrained decoding, one request at a time, CPU image encode time). No superlatives.
|
||||
|
||||
`UPSTREAM.md`: the upstream commit; the llama.cpp pin; each engine or build hunk with file, reason,
|
||||
and the measurement that justified it; each commit on the llama.cpp fork's branch; the list of features dropped
|
||||
relative to upstream with the rule. Updated in the same commit as any engine or build change.
|
||||
|
||||
## 11. Measurements
|
||||
|
||||
Same pod, same card, same model file (SHA-256 recorded), same context, same sampling, same client
|
||||
script, upstream PolyStrata and this fork back to back, three runs each, median and range.
|
||||
|
||||
| Row | Model | Workloads |
|
||||
| --- | --- | --- |
|
||||
| 1 | Flash-Next IQ3_XXS, MTP spec 4, 64K ctx, int8 KV | short chat decode, 512-token sustained decode, PP at 4K/16K/32K, agent turns with growing history (the existing `bench/community.py` suite) |
|
||||
| 2 | Qwen3.6-35B-A3B UD-Q3_K_M, draft on, 32K ctx | same |
|
||||
| 3 | Row 1 with pi: wall time and tokens for a fixed coding task | one task, three runs |
|
||||
|
||||
Pass: fork within noise of upstream (the run-to-run range) on decode and PP. A fork slower than
|
||||
upstream on any row is a bug to find before the README claims anything. The llama.cpp rows already
|
||||
recorded stay in the table as context, labelled with their different quant.
|
||||
|
||||
Rows 1 and 2 measured 2026-10-18 UTC on the RTX 3090 pod: the step-9 record (in history at 7551f138, `bench/unbiased/2026-10-17-3090pod-step9/`).
|
||||
Row 1 (Flash-Next): fork faster on every workload (chat decode 103.1 vs 87.1 tok/s, sustained 119.1 vs 105.1,
|
||||
prefill 4K/16K/32K 2065/2531/2616 vs 1924/2342/2393). Row 2 (Qwen3.6 UD-Q3_K_M): decode within the
|
||||
run-to-run range (chat 213.5 vs 220.8, sustained 200.0 vs 207.6, ranges overlap); prefill 4K 4.7 % faster,
|
||||
prefill 16K 2.3 % slower with non-overlapping ranges (3486 vs 3570), which the pass rule counts as a finding
|
||||
to explain. The engine binaries were built separately in the two trees (sha256 in each arm's provenance),
|
||||
so an engine-build difference was suspected; the attribution arms of 07:04 UTC (fork front end driving
|
||||
upstream's engine binaries) confirm it: with one engine binary, prefill is equal within 1 % and decode within the
|
||||
run-to-run range on both models, so the front end passes and the differences are the engine builds (step 14a makes
|
||||
them identical in flags). Two client-compatibility gaps found and fixed on the way
|
||||
(`/health` fields, usage in streams; commits 453d3015, 96f4ef1f). Row 3 (pi, Flash-Next): all six runs complete the task; wall time per generated token within noise (fork 76.6 vs
|
||||
upstream 72.1 tok/s median); raw wall medians 44.7 vs 36.3 s because the sampled trajectories differed in length.
|
||||
|
||||
## 12. Decisions, taken 2026-10-17
|
||||
|
||||
1. **Repository.** The fork continues the `UnbiasedStrata` repo (`~/Code/UnbiasedStrata`, remote
|
||||
`robertkarl.net:UnbiasedStrata`) in place. The present head is tagged first. Commit 1 removes every
|
||||
tracked file, `.gitignore`, `.gitmodules` and both submodules (an empty tree). Commit 2 imports
|
||||
PolyStrata byte for byte. The diff baseline is commit 2. `unbiasedstrata2/` stays as the notes and
|
||||
bench workspace.
|
||||
2. **Design C** with the step-4 gate and B as fallback (§5).
|
||||
3. **Three executables** in `build/bin/`: `strata`, `strata-poly`, the front end, plus
|
||||
`libstrata_kq.so` beside them. The directory is what gets copied. No MMQ merge, no symbol dedup.
|
||||
§6's one-binary paragraph is superseded.
|
||||
4. **Drops:** everything in §3 marked drop goes, including structured output, the Anthropic and
|
||||
Responses dialects and Prometheus.
|
||||
5. **Gray-zone cuts:** the seven installer docs, `chat.py` and `tools/calibrate.py` are cut.
|
||||
6. **CUDA archs** default `61;75;86;89`.
|
||||
7. **Measured models:** Flash-Next GSQ-RCO IQ3_XXS and Qwen3.6-35B-A3B UD-Q3_K_M (unchanged).
|
||||
8. **Machines:** a homelab GPU box for the offline build proof only, without touching running
|
||||
services. Measurements wait for a pod you hand me; steps 6 to 9 are blocked until then.
|
||||
|
||||
No new third-party tool or dependency is introduced by this plan. Everything comes from the
|
||||
upstream tree, the pinned llama.cpp submodule, CMake, a C++20 compiler and the CUDA toolkit.
|
||||
@@ -1,44 +1,94 @@
|
||||
# UnbiasedStrata
|
||||
## Credits and license
|
||||
|
||||
[Strata](https://github.com/Niko1221/Strata)'s inference engine and llama.cpp's tokenizer, chat-template and
|
||||
HTTP code, built into one binary that serves Qwen3.8-Flash-Next (one 24 GB+ card, 128 GB RAM) and
|
||||
Qwen3.6-35B-A3B (any single NVIDIA card from 6 to 32 GB, Pascal or newer) over an OpenAI-style API. No
|
||||
network is needed to build or run it: rsync the source, run `make build`, start the binary. No Python, no
|
||||
installer.
|
||||
The engines are PolyStrata's, by VecSzn and contributors, built on [Strata](https://github.com/Niko1221/Strata) by
|
||||
Niko1221. The front end is built from [llama.cpp / ggml](https://github.com/ggml-org/llama.cpp)'s server, common and
|
||||
mtmd code. Qwen3.8-Flash-Next and Qwen3.6-35B-A3B are by the Qwen team; the IQ3_XXS GSQ-RCO file is
|
||||
[ISTA-DASLab](https://huggingface.co/ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF)'s, the Qwen3.6 files are
|
||||
[Unsloth](https://huggingface.co/unsloth)'s. Upstream's full credits: [docs/HOW_IT_WORKS.md](docs/HOW_IT_WORKS.md#credits).
|
||||
MIT License ([LICENSE](LICENSE)); some parts and every model have their own licenses
|
||||
([which ones](docs/HOW_IT_WORKS.md#license)).
|
||||
|
||||
## Requirements
|
||||
# UnbiasedStrata 2 - note from a human.
|
||||
|
||||
| | Build | Run |
|
||||
| --- | --- | --- |
|
||||
| Network access | no | no |
|
||||
| CMake 3.24+, C++20 compiler (tested: g++ 13.3) | yes | no |
|
||||
| CUDA | toolkit 12.x (tested: 12.4 and 12.8; 12.8+ for RTX 50; CUDA 13 dropped Pascal and Volta) | `libcudart.so.12`, `libcublas.so.12`, `libcublasLt.so.12` and the NVIDIA driver |
|
||||
|
||||
Hardware: Linux, x86-64 with AVX2, one NVIDIA card.
|
||||
Issues with Strata / PolyStrata:
|
||||
|
||||
| Model | Card | RAM |
|
||||
| --- | --- | --- |
|
||||
| Qwen3.8-Flash-Next | 24 GB or more (RTX 30, 40 or 50) | 128 GB |
|
||||
| Qwen3.6-35B-A3B | 6 to 32 GB, Pascal (GTX 10 series, sm_61) or newer, one card | enough to hold the experts the card does not: 32 GB for Q4_K_XL on an 11 GB card, 16 GB for IQ3_XXS (the table under Sizing) |
|
||||
* piping instructions from markdown into agent == bad idea
|
||||
* replacing components at build-time or runtime isn't great
|
||||
* desired: clone; submodule init; make; situation
|
||||
|
||||
The model can be on a local disk or on a network volume; what the card does not hold is read into RAM at
|
||||
start, and what RAM does not hold is read from the file on a miss, so a slow store costs start-up time and,
|
||||
on the small cards, decode speed.
|
||||
UnbiasedStrata aims to be the suckless (dwm) variant of Strata.
|
||||
|
||||
## Build
|
||||
It's been vetted in a few ways:
|
||||
* agents went through and verified kernels to the difference between CPU/GPU within llama.cpp
|
||||
* full a run of Qwen 3.8 Flash Next over Bob-bench wide test set with a high score.
|
||||
|
||||
|
||||
This wouldn't exist without llama.cpp.
|
||||
|
||||
without Niko's Strata.
|
||||
|
||||
Without PolyStrata either.
|
||||
|
||||
Use at your own risk. Works on my machine.
|
||||
|
||||
|
||||
# AI generate nonsense from here on out
|
||||
|
||||
|
||||
|
||||
A fork of [PolyStrata](https://github.com/VecSzn/PolyStrata) v0.1.45-poly.1 that keeps its two inference engines
|
||||
unchanged and replaces everything around them: no installer, no downloads at build or start, no Python between a
|
||||
request and a token. One `make build` on a Linux box with an NVIDIA card produces the engines and a C++ front end,
|
||||
`unbiased-strata`, that serves an OpenAI-style chat API from llama.cpp's own server code. The target is one NVIDIA GPU,
|
||||
Pascal or newer, CUDA 12.x, Linux x86-64, on a machine that may have no network at all. What was changed and why is in
|
||||
[UPSTREAM.md](UPSTREAM.md); the plan this follows is [PLAN.md](PLAN.md).
|
||||
|
||||
Code: https://git.kropa.tech/hiddenbox/UnbiasedStrata (this fork; `upstream` is
|
||||
github.com/robertkarl/UnbiasedStrata, `origin` github.com/lotherk/UnbiasedStrata).
|
||||
|
||||
```
|
||||
rsync -a UnbiasedStrata/ host:UnbiasedStrata/ # or: git clone, then git submodule update --init
|
||||
ssh host 'cd UnbiasedStrata && make build' # produces build/unbiased-strata
|
||||
git clone <this repo> && cd UnbiasedStrata
|
||||
git submodule update --init # shallow, third_party/llama.cpp @ robertkarl/llama.cpp UnbiasedStrata (a6de9af3)
|
||||
make build # build/bin/{strata,strata-poly,strata-dsv41,libstrata_kq.so,unbiased-strata}
|
||||
make test # the front end against a fake engine; no GPU, no model
|
||||
```
|
||||
|
||||
The tree is 6 MB plus the pinned llama.cpp submodule in `third_party/` (about 170 MB checked out). The
|
||||
build fetches nothing. `make build JOBS=N` sets the job count; `CUDA_ARCHS` defaults to
|
||||
`61;70;75;86;89;120`, one binary for every card from Pascal up, minus any architecture the installed
|
||||
`nvcc` cannot compile (12.4 has no 120, 13 has no 61 or 70; the build says what it dropped). `make build
|
||||
CUDA_ARCHS=61` builds for one card in about 3 minutes. An architecture below 75 in the list turns on
|
||||
`STRATA_EXPERIMENTAL_SM60`, the Pascal/Volta build (FP32 and dp4a paths; no tensor cores). The
|
||||
chat-parser patch in `patches/` is applied to the submodule at configure time.
|
||||
## Box setup — CliffsNotes
|
||||
|
||||
Guest, both cards:
|
||||
|
||||
```bash
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y --no-install-recommends git cmake build-essential gcc-13 nvidia-cuda-toolkit linux-headers-amd64
|
||||
python3 -m venv ~/venv-strata && ~/venv-strata/bin/pip install -r tools/requirements.txt # offline pack tools only
|
||||
nvcc --version | tail -1 # CUDA 12.4.131
|
||||
g++-13 --version | head -1 # template default is 14.2; nvcc 12.4 accepts <= 13 (#1645)
|
||||
cmake --version | head -1 # 3.31.6, needs >= 3.24
|
||||
python3 --version; curl --version | head -1 # make test needs both
|
||||
nvidia-smi --query-gpu=driver_version --format=csv,noheader # 550.163.01
|
||||
ls /lib/modules/$(uname -r)/updates/dkms/ | head -1 # DKMS module must exist for the running kernel
|
||||
sudo apt-get install -y --no-install-recommends linux-headers-amd64 # before the first reboot after an apt kernel upgrade
|
||||
df -h / # toolkit costs ~8 GB
|
||||
```
|
||||
|
||||
Pascal — GTX 1080 Ti, compute 6.1:
|
||||
|
||||
```bash
|
||||
nvcc --list-gpu-arch | grep -q compute_61 # CUDA 13 has no sm_61; stay on 12.4
|
||||
nvidia-smi --query-gpu=driver_version --format=csv,noheader # 550 is below CUDA 13's requirement (>= 580)
|
||||
git clone https://git.kropa.tech/hiddenbox/UnbiasedStrata && cd UnbiasedStrata
|
||||
JOBS=4 make test # no GPU, no model
|
||||
JOBS=4 make build CUDA_ARCHS=61 # -DSTRATA_EXPERIMENTAL_SM60=ON, -ccbin /usr/bin/g++-13; 15 min, 398 MB, 53 warnings
|
||||
```
|
||||
|
||||
Ada — RTX 4090, compute 8.9:
|
||||
|
||||
```bash
|
||||
git clone https://git.kropa.tech/hiddenbox/UnbiasedStrata && cd UnbiasedStrata
|
||||
make test
|
||||
make build CUDA_ARCHS=89 # 6m40 on 16 cores, 557 MB, 0 warnings
|
||||
```
|
||||
|
||||
Pascal is an experimental, community build: `make build PASCAL=1` compiles sm_61 (GTX 10-series, Tesla P40;
|
||||
`CUDA_ARCHS=60` for P100) and turns on the engine's `STRATA_EXPERIMENTAL_SM60` path. It needs a CUDA 12.x
|
||||
@@ -49,221 +99,160 @@ cache.
|
||||
## Run
|
||||
|
||||
```
|
||||
# Qwen3.8-Flash-Next
|
||||
./unbiased-strata --model /models/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00001-of-00002.gguf \
|
||||
--pack /models/pack-iq3-xxs --mtp /models/mtp
|
||||
# Qwen3.6-35B-A3B at the full 262,144-token context (the engine sizes itself to the card; see Sizing)
|
||||
./unbiased-strata --model /models/Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf \
|
||||
--pack /models/qwen36-q4 --mtp /models/qwen36-mtp-draft --ctx 262144 -- --kv q4_0
|
||||
unbiased-strata --engine <strata|strata-poly|strata-dsv41|path> -m <model.gguf> [llama-server options] -- <engine options>
|
||||
```
|
||||
|
||||
| | |
|
||||
| --- | --- |
|
||||
| Endpoints | `POST /v1/chat/completions` (streaming or not), `GET /v1/models`, `GET /health`, on `127.0.0.1:8080` |
|
||||
| Options | `--ctx N` (32768), `--threads N` (default: physical cores, or half the CPU quota in a container), `--host`, `--port`, `--mmproj PATH`, `--vision-tokens N` (1024), `--fit-max-tokens` / `--no-fit-max-tokens` (default: on); sampling defaults (a request's own fields win): `--temperature F` (0, greedy), `--top-k N` (1..64), `--top-p F`, `--min-p F`, `--repeat-last-n N`, `--repeat-penalty F`, `--presence-penalty F`, `--frequency-penalty F`, `--dry-multiplier F`, `--dry-base F`, `--dry-allowed-length N`, `--dry-penalty-last-n N`, `--dry-breakers LIST`, `--seed N`; engine flags after `--`: `--kv fp16\|q4_0\|int8`, `--vram-cap MiB` and `--ram-cap GiB` (plan as a smaller card or host), `--expert-cache N`, `--prompt-cache N` (checkpoints kept between requests) |
|
||||
| Context | a request whose `max_tokens` would run past `--ctx` has it shortened to the room left; with `--no-fit-max-tokens` it is refused (400) instead |
|
||||
| Sampling | greedy unless the effective `temperature` > 0; `temperature`, `top_p`, `top_k` (1..64), `min_p`, `seed`, `presence_penalty`, `frequency_penalty`, `repeat_penalty` and `repeat_last_n` per request, else the launch defaults; a penalty with a zero window uses 64 (`repeat_last_n` / the alias `penalty_last_n`) |
|
||||
| DRY | llama.cpp's `dry` anti-repetition sampler, on when `dry_multiplier` and `dry_penalty_last_n` are both set (per request, else `--dry-multiplier` / `--dry-penalty-last-n`): a token that would extend a repeat longer than `dry_allowed_length` loses `dry_multiplier * dry_base^(repeat - allowed_length)` over the last `dry_penalty_last_n` tokens. `dry_sequence_breakers` / `--dry-breakers` (literal strings, `\|`-separated; default newline, `:`, `"`, `*`) restart the repeat count. Applies in greedy and sampled mode; the front end tokenizes the breakers (the engine has no tokenizer) |
|
||||
| Reasoning | returned as `reasoning_content`; `"reasoning_effort": "none"` turns it off |
|
||||
| Tools | OpenAI format (`tools`, `tool_calls`) |
|
||||
| Images | with `--mmproj`, OpenAI `image_url` parts holding a base64 `data:image/...` URL (PNG, JPEG, BMP or GIF), several per message |
|
||||
| Not supported | more than one GPU, batch requests |
|
||||
`-m` names the GGUF the vocabulary and chat template are read from; no tensors are loaded from it by the front end.
|
||||
`--engine` takes a path, or a bare name looked up beside the program. Everything before `--` is a `llama-server`
|
||||
option (`--host`, `--port`, `--api-key`, `--alias`, `--temp`, `--top-k`, `--top-p`, `--min-p`,
|
||||
`--reasoning-format`, `--chat-template-kwargs`, `--sse-ping-interval`, ...); everything after `--` goes to the
|
||||
engine, which is started as a child process with `--serve` added and spoken to over its line protocol
|
||||
([docs/BACKENDS.md](docs/BACKENDS.md)). Where the model ends up (GPU cache, pinned RAM, SSD) and the three expert
|
||||
modes: [docs/MEMORY_LAYOUT.md](docs/MEMORY_LAYOUT.md). The server answers `/v1/chat/completions` (streaming and not), `/v1/models`,
|
||||
`/health`, `/props`, `/tokenize`, `/detokenize`, as llama.cpp's server does, one request at a time.
|
||||
|
||||
Images: `--mmproj /models/mmproj-Qwen3.8-Flash-Next-BF16.gguf` loads the model's own vision encoder (from the same
|
||||
Hugging Face repository as the GGUF; 0.9 GB). The encoder runs on the CPU, so the card keeps its expert cache:
|
||||
about 25 s and 1,000 prompt tokens for a 1-megapixel screenshot on 8 threads, 0.2 s for a small image; a repeated
|
||||
image is served from a cache. `GET /v1/models` then lists `image` under `input_modalities`. Without `--mmproj` an
|
||||
image request is refused with a 400.
|
||||
```
|
||||
build/bin/unbiased-strata --engine build/bin/strata-poly \
|
||||
-m /models/Qwen3.6-35B-A3B-UD-Q3_K_M.gguf --host 127.0.0.1 --port 18091 --alias qwen3.6-35b-a3b-ud-q3_k_m \
|
||||
-- --model /models/Qwen3.6-35B-A3B-UD-Q3_K_M.gguf --max-context 32768 \
|
||||
--expert-profile /models/expert-profile-q3km.txt --tail-skip 6
|
||||
```
|
||||
|
||||
The engine runs as a child process. When it exits or its stall watchdog fires, the front end exits with a failure
|
||||
status, for a supervisor such as systemd (`Restart=on-failure`) to restart; `/health` and `/v1/models` answer 503
|
||||
while the engine is down. Reasoning streams as it is generated; content and tool calls are sent once the whole
|
||||
message is parsed, so a partial tool-call JSON never changes arguments already sent. `make test-frontend` checks
|
||||
the child handling and the protocol without a model; `make test-chat-parser MODEL=<shard 1>` checks the chat
|
||||
template and tool-call parsing against the real GGUF.
|
||||
With pictures, add `--mmproj /models/mmproj-F16.gguf` (the projector from the same `-MTP` repository) and
|
||||
`--threads N` for the encoder before the `--`. The front end checks the projector's width against the model's at
|
||||
start, encodes each picture with llama.cpp's mtmd and hands the rows to the engine over upstream's `GENI`
|
||||
protocol. A picture is at most 300 rows by default (upstream's installer's CPU setting; `--image-max-tokens`
|
||||
changes it), which read a 1920x1080 dashboard correctly in 15 s of encoding on a Ryzen 7 1700.
|
||||
Flash-Next through `strata` takes the same `--mmproj` (its own BF16 projector) and also needs `--vision` after the
|
||||
`--`, or the engine refuses the rows ("this engine was started without --vision"); checked on the 4090, 2026-10-20.
|
||||
|
||||
## The supported models
|
||||
**Qwen3.8-Flash-Next GSQ-RCO IQ3_XXS** (`strata`; the two GGUF shards, the pack directory made from shard 1, the MTP
|
||||
draft directory). On the 24 GB card:
|
||||
|
||||
### Qwen3.8-Flash-Next
|
||||
```
|
||||
build/bin/unbiased-strata --engine build/bin/strata \
|
||||
-m /models/IQ3_XXS/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00001-of-00002.gguf \
|
||||
--host 127.0.0.1 --port 18090 --alias qwen3.8-flash-next-iq3_xxs --sse-ping-interval 10 \
|
||||
-- --pack /models/pack-iq3-xxs \
|
||||
--native /models/IQ3_XXS/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00001-of-00002.gguf \
|
||||
--ple-gguf /models/IQ3_XXS/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00002-of-00002.gguf \
|
||||
--expert-profile /models/pack-iq3-xxs/expert-profile.bin \
|
||||
--expert-cache auto --prefill auto --spec 4 --spec-min-p 0.5 --mtp /models/mtp \
|
||||
--max-context 65536 --kv int8 --ple-io ram --pool-workers 15 --kv-resident 32768
|
||||
```
|
||||
|
||||
Qwen3.8-Flash-Next (125B parameters, mixture of experts), the full model at IQ3_XXS quantization, from
|
||||
[ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF](https://huggingface.co/ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF),
|
||||
directory `IQ3_XXS`, revision `ed59f920`. No other model, quantization or pruned variant is supported. The
|
||||
draft (MTP) head is required.
|
||||
|
||||
Everything below must be on disk before start. Nothing is fetched.
|
||||
**DeepSeek-V4.1-Flash-1017, ISTA-DASLab IQ2_XXS** (`strata-dsv41`, Strata v0.2.4's third engine; the four shards,
|
||||
the shared Engram file, Unsloth's DSpark drafter and a pack directory made from them): [docs/DEEPSEEK41.md](docs/DEEPSEEK41.md).
|
||||
|
||||
| What | Size | SHA-256 or source |
|
||||
```
|
||||
build/bin/unbiased-strata --engine build/bin/strata-dsv41 \
|
||||
-m /models/dsv41/IQ2_XXS/DeepSeek-V4.1-Flash-1017-GSQ-RCO-IQ2_XXS-00001-of-00004.gguf \
|
||||
--host 127.0.0.1 --port 11434 --alias deepseek-v4.1-flash-1017-ista-iq2_xxs --sse-ping-interval 10 \
|
||||
--chat-template-file data/dsv41/chat_template-ista-1017.jinja --temp 1.0 --top-p 1.0 --min-p 0.0 --top-k 64 \
|
||||
-- --pack /models/dsv41/IQ2_XXS/maya-ds4 --max-context 131072 --dspark auto --gpus 0
|
||||
```
|
||||
|
||||
### Preparing a Flash-Next pack
|
||||
|
||||
`strata-poly` reads a GGUF as it is. `strata` needs a pack directory and an MTP draft directory made once, offline
|
||||
except for the draft download, with upstream's tools (`tools/requirements.txt`: numpy, regex; `gguf-py` comes from the
|
||||
submodule). This is what upstream's installer ran. Re-run in this fork on 2026-10-20 on three hosts; the MTP directory
|
||||
came out byte-identical each time, so it is published, with the commands and hashes, at
|
||||
https://huggingface.co/robertkarl/UnbiasedStrataPacks: copy it instead of fetching and quantizing.
|
||||
|
||||
```
|
||||
python tools/iq_pack.py --gguf <shard1> --out <pack> # --compat-bf16 for Unsloth files
|
||||
STRATA_SOURCE=huggingface python tools/mtp_fetch.py fetch --out <mtp>
|
||||
python tools/mtp_pack.py --src <mtp> --experts q2_0 --out <mtp>/mtp-q2_0.gguf
|
||||
python tools/mtp_rt.py --gguf <mtp>/mtp-q2_0.gguf --out <mtp>/rt
|
||||
cp data/draft_vocab.bin <mtp>/rt/draft_vocab.bin
|
||||
```
|
||||
|
||||
Model files themselves are downloaded on a machine with network access and copied to the inference box; the fork does
|
||||
not fetch them. The files that have been served, with sizes and SHA-256, are in
|
||||
[docs/MODEL-FILES.md](docs/MODEL-FILES.md).
|
||||
|
||||
## Container
|
||||
|
||||
The `Dockerfile` builds the sm_61 (Pascal) flavour in an `nvidia/cuda:12.8.1-devel-ubuntu24.04` stage with
|
||||
`make build PASCAL=1 CUDA_ARCHS=61`, then copies the front end and every engine into the runtime image, so
|
||||
`--engine strata`, `strata-poly` and `strata-dsv41` resolve beside the program. `CUDA_ARCHS` is a build argument
|
||||
(`--build-arg CUDA_ARCHS=86` for an RTX 30). Nothing is downloaded at build or run time; the model shards, the pack
|
||||
and the MTP draft directory are mounted.
|
||||
|
||||
```bash
|
||||
docker build -t unbiased-strata:p40 .
|
||||
docker run --rm --gpus '"device=0"' -p 8082:8080 \
|
||||
-v /path/models:/models:ro -v /path/strata-data:/strata:ro \
|
||||
unbiased-strata:p40 --engine strata \
|
||||
-m /models/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00001-of-00002.gguf \
|
||||
--host 0.0.0.0 --port 8080 --threads 6 \
|
||||
-- --pack /strata/pack-iq3-xxs --mtp /strata/mtp --max-context 262144
|
||||
```
|
||||
|
||||
The separator matters: everything before `--` is a llama-server option, everything after it goes to the engine
|
||||
(`frontend/main.cpp:91-120`). The image listens on 8080 and its healthcheck asks `/health`, which answers 503 while
|
||||
the engine loads — hence the 30-minute start period. `examples/compose/p40.yml` is the same setup as a compose
|
||||
service, but its `command` passes engine options without `--` and does not start (t0578).
|
||||
|
||||
## Measured
|
||||
|
||||
Each number came from a run directory with the command, the raw client output, the server log and the model files'
|
||||
checksums; the per-run records were removed from the tree on 2026-10-19 and are in git history at commit 7551f138 (`git checkout 7551f138 -- bench/unbiased bench/results`). What stays in `bench/` is
|
||||
reusable tooling only: upstream's `bench_vs_llama.py` and its corpus, the kernel probes, and `bench/correctness/`, the
|
||||
teacher-forced harness of the correctness checks. Tokens per second, median of 3 runs. Upstream is PolyStrata v0.1.45-poly.1 with its Python
|
||||
server, on the same card, the same files, the same client, back to back.
|
||||
|
||||
**Upstream versus this fork, RTX 3090, 2026-10-18** (the step-9 record, in history at 7551f138; the client is
|
||||
upstream's `tools/strata_bench.py --runs 3 --long` plus a three-document sustained supplement):
|
||||
|
||||
| Model | Workload | upstream | fork |
|
||||
| --- | --- | --- | --- |
|
||||
| Flash-Next IQ3_XXS, 64K ctx | chat decode | 87.1 | 103.1 |
|
||||
| | sustained decode, 512 tokens | 105.1 | 119.1 |
|
||||
| | prefill 4K / 16K / 32K | 1924 / 2342 / 2393 | 2065 / 2531 / 2616 |
|
||||
| | agent turn decode | 110.6 | 116.8 |
|
||||
| Qwen3.6 UD-Q3_K_M, 32K ctx | chat decode | 220.8 | 213.5 |
|
||||
| | sustained decode, 512 tokens | 207.6 | 200.0 |
|
||||
| | prefill 4K / 16K | 3652 / 3570 | 3822 / 3486 |
|
||||
| | agent turn decode | 194.0 | 186.9 |
|
||||
|
||||
Flash-Next: the fork is ahead on every workload. Qwen3.6: decode is within the run-to-run range; 16K prefill is 2.3 %
|
||||
slower with non-overlapping ranges and is recorded as an open finding. The two engines were built separately in the
|
||||
two trees, so an engine-build difference is not excluded.
|
||||
|
||||
**pi on a fixed coding task** (pi 0.85.1, Flash-Next on the 3090, three runs a side, `…-step9/row3/`): every run
|
||||
completed the task. Generated tokens per wall-clock second, the whole run: upstream 72.1, fork 76.6 (medians); the raw
|
||||
wall times (36.3 vs 44.7 s) follow the length of each sampled trajectory.
|
||||
|
||||
**Short-prompt decode through the fork, first end-to-end runs** (`…-step6/`, 2026-10-17; ranges over the smoke
|
||||
requests, not medians of a benchmark):
|
||||
|
||||
| Model | RTX 3090 | RTX A6000 |
|
||||
| --- | --- | --- |
|
||||
| `Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00001-of-00002.gguf` (weights) | 47.04 GB | `219ea929900dfa9ef091f3aa473fdba6874b65fcb36526d7d851ac9e95856d15` |
|
||||
| `Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00002-of-00002.gguf` (n-gram table), beside shard 1 | 28.80 GB | `316b46f3a2dbd68c900f43136ab9449f9dcc3725dfd8c794847c204bc161e113` |
|
||||
| Pack: `index.txt`, `dense.bin`, `native_experts.txt`, `conversions.json`, `expert-profile.bin` | 1.5 GB | made once with upstream's tools; not published yet |
|
||||
| Draft head: `experts.bin`, `dense.bin`, `dense.txt`, `draft_vocab.bin` | 0.8 GB | made once with upstream's tools; not published yet |
|
||||
| Qwen3.6 UD-Q3_K_M | 211 to 227 | 214 to 235 |
|
||||
| Qwen3.6 UD-IQ4_XS | 205 to 245 | 207 to 215 |
|
||||
|
||||
About 78 GB in total. The commands that make the pack and draft head, and the SHA-256 of every file they
|
||||
produce, are in [UPSTREAM.md](UPSTREAM.md).
|
||||
Greedy answers to the same prompt were identical on the two boxes and identical to upstream on the pod for both
|
||||
Flash-Next and Qwen3.6 (text and token count). Against llama.cpp at the pinned commit (PLAN.md step 12,
|
||||
harness `bench/correctness/`, record in history at 7551f138, 2026-10-18 on the A6000): teacher-forced on 16 sequences per model, both engines' per-step
|
||||
distributions are as close to llama.cpp's GPU run as llama.cpp's own CPU run is (mean KL 0.6 to 1.2x that spread on every
|
||||
set and arm), and the greedy token agrees at every position with a 0.5-nat margin except a handful of near ties per arm
|
||||
(Qwen3.6: 4 of 2,700; Flash-Next: 0 to 4 of about 2,880 depending on the arm). The findings, each with a ticket, are in
|
||||
that directory's README: upstream's own `poly_expert_parity` exceeds its bound on one expert; speculation is not bitwise
|
||||
inert above 4-token windows (it passes the KL gate); `strata`'s bits depend on the free VRAM at start when not every
|
||||
expert fits the card. Extended 2026-10-19 to DeepSeek V4 Flash UD-IQ2_XXS and GLM 5.3 Flash 3.0bit on a 2x RTX PRO 6000 pod (section 8 of that record): T2 holds on every set and arm, 0.69 to 1.13x llama.cpp's own CPU-vs-GPU spread; a handful of 0.5-nat-margin flips per model where both llama.cpp runs agree (USTRAT-10); on GLM the draft block's VRAM moves 52 experts to the CPU, so its answers are not bitwise the no-draft ones (USTRAT-9); and llama.cpp master's CPU run differs from the pinned commit's by as much as the engine does, so the DeepSeek numbers are against 3cf03257 specifically (USTRAT-11).
|
||||
|
||||
### Qwen3.6-35B-A3B
|
||||
**Model acceptance (PLAN.md step 13, 2026-10-19).** A coding agent (pi 0.85.1, in a container with tools, sampled as
|
||||
the model card asks) completed four work items through the fork's server with every served model: a Markdown
|
||||
table-of-contents CLI with tests, an HTTP key-value store with persistence, three planted bugs, and a browser
|
||||
Minesweeper that a headless browser can play; Minesweeper again at temperature 1.0. Flash-Next IQ3_XXS and Qwen3.6
|
||||
UD-Q3_K_M on an RTX 3090 and Qwen3.6 UD-IQ4_XS on the A6000 pass as is (the IQ4_XS temperature-1.0 page threw a
|
||||
`ReferenceError` of the agent's own making); DeepSeek V4 Flash UD-IQ2_XXS and GLM 5.3 Flash 3.0bit on a B200 pass
|
||||
after the two fixes under "Known limits" (argument order; GLM's architecture name in the vocabulary load). The
|
||||
API-only checks (`frontend/tests/acceptance-real-engine.sh`) hold decode and prompt reading within 15 % of step 9 on
|
||||
the 3090 (Flash-Next with the installer's `--pool-workers 15`; 24 costs 14 %) and record the first B200 figures
|
||||
(72 and 74 tok/s decode on one card). Record: the step-13 directory, in history at 7551f138. pi's compaction defaults (reserve 16K, keep the last 20K tokens) assume a window well above 64K: against a server at `--max-context 32768` a long pi session compacts to no effect and then sends `max_tokens: 1` ("Response was truncated before completion"); serve 128K or more to pi, or lower pi's `compaction` settings (USTRAT-8).
|
||||
|
||||
Qwen3.6-35B-A3B (35B parameters, 3B active: 40 layers, 256 experts of which 8 route per token, 30 Gated
|
||||
DeltaNet layers and 10 full-attention layers, 262,144-token context), unsloth's UD quantizations from
|
||||
[unsloth/Qwen3.6-35B-A3B-GGUF](https://huggingface.co/unsloth/Qwen3.6-35B-A3B-GGUF) and
|
||||
[unsloth/Qwen3.6-35B-A3B-MTP-GGUF](https://huggingface.co/unsloth/Qwen3.6-35B-A3B-MTP-GGUF). Two
|
||||
quantizations, with the pack and draft pack made by this repository's own tools (`tools/iq_pack.py`,
|
||||
`tools/make_profile.py`, `tools/mtp_qwen36_pack.py`; commands and every file's SHA-256 in
|
||||
[UPSTREAM.md](UPSTREAM.md)):
|
||||
|
||||
| What | Size | SHA-256 |
|
||||
| --- | --- | --- |
|
||||
| `Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf`, **the default** (K-quants: the fast AVX2 path for the experts the CPU computes) | 22.36 GB | `707a55a8a4397ecde44de0c499d3e68c1ad1d240d1da65826b4949d1043f4450` |
|
||||
| `Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf` from the **-MTP** repository (the same trunk plus the draft block `blk.40`; serves as the model file too) | 22.85 GB | `55983c5a75a1ab969824077b3bb3de4146e82a9234072b48ad4e8f92ad3fe9f1` |
|
||||
| `Qwen3.6-35B-A3B-UD-IQ3_XXS.gguf`, for 6 and 8 GB cards | 13.21 GB | `9c964e657212fea1f24905dd7b0a89b82fd807d19fab0b41da14251b07b88fbe` |
|
||||
| Pack `qwen36-q4/` or `qwen36-iq3/` (`index.txt`, `dense.bin`, `native_experts.txt`, `conversions.json`, `expert-profile.bin`, `tokenizer/`) | 65 MB | per file in UPSTREAM.md |
|
||||
| Draft pack `qwen36-mtp-draft/` (`experts.bin`, `dense.bin`, `dense.txt`, `native_experts.txt`, `mtp.json`, `draft_vocab.bin`), cut from the -MTP file's draft block; serves both quantizations | 0.5 GB | per file in UPSTREAM.md |
|
||||
|
||||
No other Qwen3.6 file is accepted: the IQ4_XS-MTP file's draft block (Q3_K experts) and the 27B dense model
|
||||
are refused by name. Images work with `--mmproj` and the model's own encoder (`mmproj-F16.gguf` from the -MTP repository,
|
||||
899 MB); the encoder runs on the CPU, so the first use of a full-screen image costs 24 s on an i9-9900K and
|
||||
about 70 s on a Ryzen 7 1700, and repeats are served from a cache.
|
||||
|
||||
#### Sizing
|
||||
|
||||
At start the engine prints its plan for the card it finds: the fixed set for the requested context (the
|
||||
dense weights, the drafter, the KV cache, the session, a reserve), then every remaining megabyte as expert
|
||||
slots, filled by the route-trace profile's rank. If the fixed set does not fit, the KV cache is streamed
|
||||
to RAM above a resident window, then the context is lowered toward 131,072, then the engine refuses with
|
||||
the numbers and suggests the IQ3_XXS file. It never silently picks a shorter context. The experts that do
|
||||
not fit in VRAM are read from pinned RAM when the host has it, else from the file on a miss; `/health`
|
||||
reports the VRAM hits, RAM reads and file reads per request. `--vram-cap` and `--ram-cap` make a big card
|
||||
plan like a small one.
|
||||
|
||||
| VRAM | Q4_K_XL at 262,144, q4_0 KV: fixed set, experts resident | IQ3_XXS: fixed set, experts resident |
|
||||
| --- | --- | --- |
|
||||
| 24 GB (RTX 4090) | 4,823 MiB; 9,980 of 10,240 (97%) | 4,331 MiB; all 10,240, 8.8 GB spare |
|
||||
| 11 GB (GTX 1080 Ti) | 4,461 MiB; 3,575 (35%) | 4,019 MiB; 6,748 (66%) |
|
||||
| 8 GB | 1,949 (19%) | 3,873 (38%) |
|
||||
| 6 GB | 598 (6%) | 1,486 (15%) |
|
||||
|
||||
The 24 GB row is measured; the others are the planner's figures from the same files under `--vram-cap`
|
||||
(docs/qwen36-port/step2-notes.md section 5, step4-pack.md section 5).
|
||||
|
||||
**RAM is a requirement, not a tier.** The engine assumes the card and the host RAM together hold the expert set;
|
||||
every expert the card does not hold is pinned in RAM. What the host must hold is the expert bytes minus the card's
|
||||
share, plus the engine's own 3 to 4 GB and the OS:
|
||||
|
||||
| VRAM | Q4_K_XL experts off the card | RAM to have | IQ3_XXS experts off the card | RAM to have |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 24 GB | none | 8 GB | none | 8 GB |
|
||||
| 16 GB | 8 GB | 16 GB | none | 8 GB |
|
||||
| 11 GB | 13 GB | 32 GB (24 is tight) | 4 GB | 12 GB |
|
||||
| 8 GB | 15 GB | 32 GB | 7 GB | 16 GB |
|
||||
| 6 GB | 17 GB | 32 GB | 9 GB | 16 GB |
|
||||
|
||||
Below those figures the engine still starts, maps the rest from the file and says so in its plan, but that is a
|
||||
fallback, not a supported configuration: measured once on the GTX 1080 Ti at Q4_K_XL under a 12 GiB memory bound,
|
||||
decode fell from 52 tokens/s to 12 to 15, the NVMe's rate, with about 12 experts per token read from the file.
|
||||
|
||||
## Status
|
||||
|
||||
Checked on one machine: RTX 3090, 32 vCPUs of an EPYC 7763, 125 GB RAM, CUDA 12.8, in a container.
|
||||
|
||||
| | |
|
||||
| --- | --- |
|
||||
| Build | from an rsynced tree with no git metadata; the binary holds no download code |
|
||||
| Serving | chat, streaming, reasoning, tool calls; a coding agent (pi) wrote and ran a program through it |
|
||||
| RTX 4090 (24 GB), 82 GB RAM, Debian, bare metal | serving with tool calls and images, through pi (file attachments and clipboard paste) and curl, over several days of use |
|
||||
| Start from local disk | 19 s with the files in the OS file cache |
|
||||
| Start from a network volume | 12 min for 76 GB (S3-backed RunPod volume, 120 to 330 MB/s). The volume refused reads twice with "cannot allocate memory"; the loader retried and went on |
|
||||
| Not tested | RTX 50 cards; a cold start from local disk |
|
||||
|
||||
Qwen3.6-35B-A3B, checked on the RTX 4090 (VM, 16 vCPU i9-9900K, 62 GB RAM, CUDA 12.4):
|
||||
|
||||
| | |
|
||||
| --- | --- |
|
||||
| Correctness | the engine's logits held to a numpy reference and to llama.cpp at every position of the real files (greedy top-1 64/64 on three prompts at IQ3_XXS, 61-64/64 at Q4_K_XL, mean KL 1e-3 to 7e-3); the expert-miss path (what every card below 24 GB runs on) held with the same prompts under `--vram-cap` |
|
||||
| Serving | chat, streaming of reasoning and answer per token, tool calls streamed and not, multi-turn prompt checkpoints at 262,144 context, at 24 GB, under an 11 GB cap (Q4_K_XL) and a 6 GB cap (IQ3_XXS); a coding agent (pi) wrote and ran a program through it |
|
||||
| Pascal | built and unit-tested on a GTX 1080 Ti (sm_61: every kernel parity test, the pack, the drafter, the verify window); the expert-miss path held to llama.cpp's logits there too |
|
||||
|
||||
Speed against llama.cpp on the same card (RTX 4090, `--vram-cap` for the smaller budgets, 262,144 context,
|
||||
no RAM cap, drafter on; llama.cpp with `--n-cpu-moe N` chosen to fit the same budget, no speculation). Decode
|
||||
is a 1,200-token answer to a 2.4K prompt; prefill is a 32K prompt. Tokens/s, engine / llama.cpp:
|
||||
|
||||
| Budget | Q4_K_XL decode | Q4_K_XL prefill | IQ3_XXS decode | IQ3_XXS prefill |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 24 GB | 251 / 159 (1.6x) | 4,319 / 8,604 (0.50x) | 318 / 167 (1.9x) | 4,426 / 8,245 (0.54x) |
|
||||
| 16 GB | 180 / 41 (4.4x) | 4,232 / 1,798 (2.4x) | 319 / 44 (7.3x) | 4,401 / 2,637 (1.7x) |
|
||||
| 12 GB | 122 / 38 (3.3x) | 3,877 / 1,475 (2.6x) | 256 / 40 (6.4x) | 4,381 / 2,223 (2.0x) |
|
||||
| 11 GB | 104 / 37 (2.8x) | 3,723 / 1,420 (2.6x) | 234 / 39 (6.1x) | 4,375 / 2,137 (2.1x) |
|
||||
| 8 GB | 64 / 33 (2.0x) | 3,003 / 1,212 (2.5x) | 135 / 34 (4.0x) | 4,320 / 1,854 (2.3x) |
|
||||
| 6 GB | 45 / 30 (1.5x) | 517 / 1,108 (0.47x) | 81 / 32 (2.5x) | 1,121 / 1,713 (0.65x) |
|
||||
|
||||
The llama.cpp 24 GB Q4_K_XL row is at 131,072 context; it does not load at 262,144 with every layer on the card.
|
||||
Prompt processing is the weak side: with every expert resident llama.cpp is twice as fast, and at 6 GB the engine
|
||||
spends the prompt copying experts to the card. Full tables, profiler windows and plots are in the regina
|
||||
repository's `analysis/qwen36-35b-single-gpu-ladder/engine-4090/`.
|
||||
|
||||
On the GTX 1080 Ti (VM, 14 vCPU of a Ryzen 7 1700, 52 GB RAM), against llama.cpp on the same card and host
|
||||
(`--n-cpu-moe N` at the lowest N that fits each budget, 8 threads, no speculation, the model file in RAM).
|
||||
262,144 context on both sides. Tokens/s, engine / llama.cpp:
|
||||
|
||||
| Budget | Q4_K_XL decode | Q4_K_XL prefill 3.1K | Q4_K_XL prefill 32K | IQ3_XXS decode | IQ3_XXS prefill 3.1K | IQ3_XXS prefill 32K |
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
| 11 GB (the card) | 66 / 28 (2.4x) | 941 / 570 (1.7x) | 462 / 545 (0.85x) | 81 / 33 (2.5x) | 910 / 904 (1.0x) | 453 / 714 (0.63x) |
|
||||
| 8 GB (`--vram-cap 8192`) | 54 / 25 (2.1x) | 911 / 488 (1.9x) | 442 / 487 (0.91x) | 69 / 28 (2.5x) | 900 / 747 (1.2x) | 453 / 637 (0.71x) |
|
||||
| 6 GB (`--vram-cap 6144`) | 42 / 24 (1.8x) | 361 / 452 (0.80x) | 265 / 460 (0.58x) | 55 / 24 (2.3x) | 748 / 614 (1.2x) | 437 / 562 (0.78x) |
|
||||
|
||||
Decode is 1.8 to 2.5 times llama.cpp; the GPU computes 85% of the decode window against llama.cpp's 39 to 45%.
|
||||
A long prompt is slower than llama.cpp at every budget on this card. The draft head is worth a third of the decode
|
||||
speed (49 tokens/s without drafts at Q4_K_XL on the full card). Tables and plots: regina
|
||||
`analysis/qwen36-35b-single-gpu-ladder/engine-1080ti/` and `llama-1080ti-52g/`.
|
||||
|
||||
Speed, one run of each, same machine and model files, greedy sampling, reasoning off. Generation is the mean
|
||||
of 8 different prompts of 400 tokens; prompt speed is the mean of 2 different prompts of about 20,000 tokens.
|
||||
|
||||
| | Generation, tokens/s | Prompt, tokens/s |
|
||||
| --- | --- | --- |
|
||||
| This fork | 107 (87 to 116) | 2,483 |
|
||||
| Upstream, with `--pool-workers 15 --ple-io ram` | 78 (61 to 93) | 2,439 |
|
||||
| Upstream, arguments as its installer writes them | 20 (16 to 21) | 2,368 |
|
||||
|
||||
Upstream as installed started 127 CPU workers on the container's 32 vCPUs and read the n-gram table from
|
||||
disk per token; the middle row removes both. The remaining gap to the fork is not explained yet: the two
|
||||
builds differ in compile flags and in how the n-gram table is held in RAM, and each row is a single run.
|
||||
|
||||
## Known problems
|
||||
|
||||
- Text in a message that looks like a control token (`<think>`, `<tool_call>`) is tokenized as that control
|
||||
token. Upstream's tokenizer keeps it as plain text.
|
||||
- Replies are not reproducible token for token between runs or between this fork and upstream, even with
|
||||
greedy sampling, so "same output" cannot be checked by comparing text.
|
||||
For Qwen3.6-35B-A3B the cause is traced: an expert the card does not hold is computed by a different
|
||||
kernel on the CPU, and the cache keeps changing which experts those are for the first few requests; replies
|
||||
diverge only where two tokens are within about 0.3 logits, and every state holds to llama.cpp's logits.
|
||||
`--adapt-every 0 --suffix-draft 0` makes a request repeat token for token. `--pcie-frac 1.0` does too
|
||||
only while a layer misses fewer than 16 experts per window; past that the rest are computed on the CPU.
|
||||
- Qwen3.6-35B-A3B: between user turns the prompt cache reuses the previous prompt but not the previous reply,
|
||||
because the model's template re-renders an earlier reply without its reasoning. Tool loops reuse nearly
|
||||
everything (1,867 of 1,948 tokens in a pi session); `chat_template_kwargs.preserve_thinking` with
|
||||
`reasoning_content` sent back reuses the reply too, at the cost of keeping old reasoning in context.
|
||||
A tool call arrives as one delta, not streamed. Images are checked on one screenshot only, and not
|
||||
against llama.cpp; the RTX 50 and Volta builds have not
|
||||
run on a card. Prompt processing is slower than llama.cpp with every expert on the card, at 6 GB, and for long
|
||||
prompts on a GTX 1080 Ti.
|
||||
|
||||
## Compared with upstream Strata (6f32ec0)
|
||||
|
||||
| | Upstream | This fork |
|
||||
| --- | --- | --- |
|
||||
| Engine source (`src/`, `include/`) | 272 files | 58 files changed for the Qwen3.6 port (the model geometry read from the GGUF, the plain-residual block, dense attention, the SiLU-gated DeltaNet, the expert kernels for the UD quantizations, the VRAM planner, the drafter pack) plus retrying reads from slow stores; docs/qwen36-port/ has the per-step notes |
|
||||
| Build | clones llama.cpp during CMake | pinned submodule, fetches nothing; one patch, applied at configure time: tool-call arguments in any order (see UPSTREAM.md) |
|
||||
| Setup | Python installer downloads the model and builds the pack and draft head | none; files must already exist |
|
||||
| Server | Python | C++, in the same binary (`frontend/`), with the image encoder from llama.cpp's `mtmd` |
|
||||
| Python | 33,745 lines | 0 |
|
||||
| C, C++ and CUDA | 208,254 lines (with tests and the Intel port) | 84,086 lines |
|
||||
| Tracked files | 851, 27 MB | 292, 6 MB |
|
||||
| Configurations | several models, NVIDIA, AMD and Intel, Linux and Windows, multi-GPU | two models, one NVIDIA card (Pascal to RTX 50), Linux |
|
||||
|
||||
## Credits and licence
|
||||
|
||||
MIT, as upstream. The engine is the work of Niko1221 and the Strata contributors; see [LICENSE](LICENSE) and
|
||||
[UPSTREAM.md](UPSTREAM.md). llama.cpp and ggml are MIT. The model files have their own licences.
|
||||
+193
-100
@@ -4,119 +4,212 @@
|
||||
|
||||
| What | Where | Version |
|
||||
| --- | --- | --- |
|
||||
| Engine | https://github.com/Niko1221/Strata | commit `6f32ec070f23ced9f50e704d854d775da52591ab`, engine 0.1.39 |
|
||||
| ggml (CPU backend, CUDA matrix kernels) | https://github.com/ggml-org/llama.cpp, as the submodule `third_party/llama.cpp` | commit `3cf03257f219afbe7334045ff7c6a06ac68c627d`, the one upstream Strata pins |
|
||||
| Engines (`strata`, `strata-poly`), tools, docs | https://github.com/VecSzn/PolyStrata | tag `v0.1.45-poly.1`, commit `d0cd84dc6bd009d1d9e2191e4e28cc76b80f1ee3` |
|
||||
| ggml, llama, common, mtmd, cpp-httplib | https://github.com/robertkarl/llama.cpp, branch `UnbiasedStrata`, as the submodule `third_party/llama.cpp` | commit `385445fad49e42fa718b5e1f71668f35b7a08559`: ggml-org `3cf03257f219afbe7334045ff7c6a06ac68c627d` (the commit upstream pins) plus the six parser commits below |
|
||||
| DeepSeek-V4.1 engine (`strata-dsv41`: `src/dsv41`, `include/strata/dsv41`, `tests/dsv41`, `tools/dsv41`, `data/dsv41`, `tools/trellis/tqenc.*`), the trellis and `iq*x_rows` CPU kernels it needs | https://github.com/Niko1221/Strata | tag `v0.2.4`, commit `96ca4383` (2026-10-24); see "DeepSeek-V4.1 engine" below |
|
||||
| llama.cpp's DeepSeek V4.1 chat template detection and DSML parser | https://github.com/ggml-org/llama.cpp pull 30817, head `b72050d0` | the `common/chat.cpp`, `common/chat.h`, `common/parsers/deepseek.cpp` hunks only, as commit `44072a1` on the submodule branch `deepseek41-parser` (on `385445f`) |
|
||||
|
||||
The first commit of this repository is the upstream snapshot as published. One file was not imported:
|
||||
`bench/results/2026-09-30-community-rtx-5090/engine.log`, which upstream's own ignore rules exclude.
|
||||
`git diff <first commit> HEAD -- src include CMakeLists.txt` shows every change to the engine and its build.
|
||||
Commit `0197ae86` ("Import PolyStrata v0.1.45-poly.1 (d0cd84dc) unmodified") is the upstream tree, every tracked
|
||||
file, with the same tree hash as upstream's commit. `git diff 0197ae86 HEAD` is the whole story of this fork;
|
||||
`git diff 0197ae86 HEAD -- src include` is every change to the engines.
|
||||
|
||||
## What this fork changed
|
||||
The history before that commit is UnbiasedStrata 1, a fork of Niko1221/Strata 0.1.39, ended at the tags
|
||||
`unbiasedstrata-1` and `unbiasedstrata-1-muse-spark-native`.
|
||||
|
||||
- **Build:** ggml is taken from the submodule. Upstream cloned llama.cpp during the build.
|
||||
- **Removed:** the Python installer and launchers, the Python server and web app, the Python tools, the
|
||||
Intel SYCL port, Docker files, benchmark results, the test suite, translations, and all docs except
|
||||
`docs/upstream/DETAILS.md` and the paper.
|
||||
- **Added:** `frontend/`, the C++ front end (tokenizer, chat template, output parser and HTTP API, using
|
||||
llama.cpp's code from the submodule), and a build target that links it with the engine into one binary.
|
||||
- **ggml / llama.cpp common (`third_party/llama.cpp`):** one change, kept as
|
||||
`patches/llama.cpp-qwen3-coder-any-argument-order.patch`, applied to the submodule's working tree at CMake
|
||||
configure time (and by `make build`); Qwen3.6's template routes to the same parser:
|
||||
the Qwen3-Coder tool-call grammar accepts a call's arguments in any order. Upstream requires the
|
||||
required arguments first; Qwen3.8 Flash-Next often writes the optional ones first (`limit`, `offset`,
|
||||
`path`), and because the grammar's tool-call group is optional and has no end anchor, such a call was
|
||||
dropped silently: the client got `finish_reason=stop` and an empty answer (2026-10-08).
|
||||
- **Engine source (`src/`, `include/`):** three changes, all for loading from a slow or remote store. The
|
||||
engine's own program is compiled into the binary with its entry point renamed; the front end starts it
|
||||
as a child process.
|
||||
- `include/strata/platform/robust_read.hpp` (new): positional reads that retry an error a network store
|
||||
gives for a moment, and lower the number of parallel readers while it does.
|
||||
- `src/core/expert_source.cpp`: the expert loader reads through it, reports progress, and names the file,
|
||||
offset and error when it fails.
|
||||
- `src/kernels/ngram.cpp`: `--ple-io ram` reads the n-gram table into memory of its own with 16 readers,
|
||||
where upstream locked the file mapping (which fails under a container's `ulimit -l`).
|
||||
## Rules
|
||||
|
||||
Code paths for other models, AMD cards and Windows are still present in the engine source. They are not
|
||||
built by `make build`, not tested and not supported here.
|
||||
A thing is removed only when it (1) reaches the network during setup, build or start-up, (2) puts Python
|
||||
between a request and a token, (3) breaks or complicates the one-command build, or (4) is marketing.
|
||||
Everything else stays, built or not. Engine changes are bug fixes for the target (Linux x86-64, one NVIDIA
|
||||
GPU, Pascal or newer, CUDA 12.x), each recorded below with the file, the reason and the measurement.
|
||||
|
||||
## Prepared model files
|
||||
## Build (`CMakeLists.txt`, `Makefile`, `.gitmodules`, `.gitignore`)
|
||||
|
||||
The pack and the draft head are produced once with upstream Strata's tools at the commit above. These are
|
||||
the commands that were used, with `U` an upstream checkout, `G` this repository's
|
||||
`third_party/llama.cpp/gguf-py`, and Python 3 with `numpy` and `regex`:
|
||||
- **ggml from the submodule, not a fetch.** `STRATA_GGML_DIR` defaults to `third_party/llama.cpp` and the
|
||||
configure stops with the `git submodule update --init` line if `ggml/CMakeLists.txt` is missing. Upstream's
|
||||
`FetchContent` of llama.cpp (the only network access of its build) is deleted. The three later
|
||||
`if(STRATA_GGML_DIR)` blocks are unchanged; their `else()` branches are now dead. `.gitignore` no longer
|
||||
ignores `/third_party/llama.cpp*`.
|
||||
- **llama.cpp changes are commits on a fork, not configure-time patches.** The submodule points at
|
||||
robertkarl/llama.cpp, branch `UnbiasedStrata`: ggml-org `3cf03257` plus the two commits under "Changes to llama.cpp"
|
||||
below. Until 2026-10-19 the same changes were `patches/*.patch`, applied to the submodule's working tree by CMake at
|
||||
configure (UnbiasedStrata 1 did it in `make` and in CMake both), which left the submodule dirty after every build and
|
||||
meant the pinned commit alone did not name the sources compiled. The pin now does; `git status` is clean after a build.
|
||||
- **llama.cpp's libraries for the front end.** A second `add_subdirectory` of the submodule with
|
||||
`LLAMA_BUILD_COMMON` and `LLAMA_BUILD_MTMD` on and tests, tools, examples, server, app, UI, prebuilt UI,
|
||||
OpenSSL and llguidance off. It reuses the ggml targets configured above. Gated by `STRATA_FRONTEND` (default on),
|
||||
not by CUDA, so the front end also builds on a machine without a GPU.
|
||||
- **The front end, `unbiased-strata`.** Seven of llama.cpp's `tools/server` files are compiled unmodified from the
|
||||
submodule into a static library (`server-http`, `server-queue`, `server-task`, `server-common`, `server-chat`,
|
||||
`server-schema`, `server-stream`): the HTTP layer, the task queue, the OpenAI request and result types, SSE
|
||||
framing, the request schema. The eighth, `server-context.cpp`, is bound to `llama_context` and is replaced by
|
||||
`frontend/strata_context.cpp`, which runs the engine as a child process over its line protocol (`docs/BACKENDS.md`)
|
||||
and uses a vocab-only `llama_model` for tokenizing, the chat template and the output parsers. `server-http.cpp`
|
||||
references the web UI's asset table (`ui.h`, generated by `tools/ui` at build time, which downloads); `frontend/
|
||||
ui_stub/` provides an empty one. No patch to llama.cpp was needed for this; the undocumented internal API of
|
||||
`tools/server` is used as it is at the pinned commit.
|
||||
- **`Makefile`.** `make build` configures once and builds `strata`, `strata-poly`, `strata_kq` and `unbiased-strata`
|
||||
into `build/bin/`, not upstream's `all`, which also builds about 70 parity and bench programs. `make frontend`
|
||||
builds the front end alone without CUDA into `build-frontend/`; `make test` builds and runs the front end's tests
|
||||
there against a fake engine (`frontend/tests/`): the adapter's cases and the HTTP surface a coding agent touches.
|
||||
The nvcc check applies only to the `build` and `configure` goals.
|
||||
`CUDA_ARCHS` defaults to `61;75;86;89`; an arch below 75 adds upstream's `STRATA_EXPERIMENTAL_SM60`
|
||||
(upstream's default is `120`, which needs CUDA 13). `PORTABLE=1` gives the AVX2 baseline instead of
|
||||
`-march=native`. One GCC for the C, C++ and nvcc host sides: the Makefile probes `g++-15`, `g++-14`, ... with
|
||||
`nvcc -ccbin` and passes the newest accepted one as `CMAKE_C_COMPILER`, `CMAKE_CXX_COMPILER` and
|
||||
`CMAKE_CUDA_HOST_COMPILER`. Without that, on a box whose default `g++` is newer than nvcc accepts (Debian 13 with
|
||||
CUDA 12.4: GCC 14 against a GCC 13 limit), the C++ files were compiled by GCC 14 and the CUDA files by GCC 13, and
|
||||
`strata` failed to link on `__cxa_call_terminate` (upstream's installer handles the same case, its #1645).
|
||||
`HOSTCXX=/usr/bin/g++-13` overrides the probe.
|
||||
|
||||
```
|
||||
export STRATA_GGUF_PY=$G
|
||||
# the pack, from the model's first shard (the second must be beside it)
|
||||
python $U/tools/iq_pack.py --gguf Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00001-of-00002.gguf --out pack-iq3-xxs
|
||||
cp $U/data/expert-profile.bin pack-iq3-xxs/
|
||||
## Front end behaviour (`frontend/`), where it differs from llama-server or from upstream's server
|
||||
|
||||
# the draft head, from the original checkpoint's 31 draft-head tensors (about 5 GB, fetched over HTTP)
|
||||
python $U/tools/mtp_fetch.py fetch --out mtp-bf16
|
||||
python $U/tools/mtp_fetch.py verify --out mtp-bf16
|
||||
python $U/tools/mtp_pack.py --src mtp-bf16 --experts q2_0 --out mtp-bf16/mtp-q2_0.gguf
|
||||
python $U/tools/mtp_rt.py --gguf mtp-bf16/mtp-q2_0.gguf --out mtp
|
||||
cp $U/data/draft_vocab.bin mtp/
|
||||
```
|
||||
Recorded here because a client written for one of the two may notice.
|
||||
|
||||
The model shards used were revision `ed59f92082b1e93c0e96d60a8b11aab089b52f09` of
|
||||
ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF, verified against their published SHA-256 checksums. The
|
||||
prepared files have not been published yet. Building them twice gave the same bytes; their SHA-256:
|
||||
- **`/health`** returns llama.cpp's `{"status": "ok", "busy": ...}` plus upstream's `"service": "strata"`,
|
||||
`"loaded": true`, `"model"`, `"max_context"` (commit 453d3015). Upstream's `tools/strata_bench.py` refuses a server
|
||||
without the first two; the first step-9 fork arm was lost to that
|
||||
(the step-9 record's README; records are in history at 7551f138, `bench/unbiased/`).
|
||||
- **Streams always end with a usage chunk** (empty `choices`, `usage`, `timings`), as upstream's server does,
|
||||
whether or not the client sent `stream_options.include_usage`; llama-server sends it only on request (96f4ef1f).
|
||||
Same reason: the bench client reads `prompt_tokens` from it.
|
||||
- **One slot.** Requests are served one at a time in arrival order, as upstream's server does with one engine.
|
||||
- **No constrained decoding.** `response_format` and tool schemas are parsed and used for output parsing, not
|
||||
enforced at the sampler, because the engine samples; logged once per such request.
|
||||
- **Pictures are encoded in the front end** (`--mmproj FILE`, commit 71886db0 and after): llama.cpp's mtmd runs the
|
||||
projector and the front end writes upstream's `SVE1` record file and sends `GENI … image_pad=<id> <file>`, the
|
||||
protocol upstream's Python server spoke to `strata-vision`. Projector width is checked against the model's
|
||||
embedding width at start. The default row budget is upstream's installer's (300 on the CPU, 1024 on the GPU;
|
||||
`--image-max-tokens` overrides). The encoder runs on the CPU: the front end's ggml is built without CUDA, and
|
||||
`--mmproj-gpu` is refused when ggml has no GPU device (17e27213). Measured in
|
||||
2026-10-18 on the A6000 (record in history at 7551f138).
|
||||
- **`--sse-ping-interval`** is llama-server's (default 30 s); the measured Flash-Next runs used 10.
|
||||
- **SIGTERM exits 1**, not 0, after stopping the engine: the engine child dies with the process group and the front
|
||||
end reports it as an engine death with an empty message. Open; matters only to a service manager.
|
||||
- **Default `min_p`** is llama-server's 0.05 when a request omits it; upstream's server sends none. pi sends 0.
|
||||
|
||||
```
|
||||
68beec784ea64aeecace591b33debb8ba331a9ad257a3e1b68c5c701dd22b267 pack-iq3-xxs/conversions.json
|
||||
d2af3d8331e5c7a1985d1d589747230f9d56719a6d33c7cddc9ee6b81cde6b13 pack-iq3-xxs/dense.bin
|
||||
8f59b4aa8873209dff11c11e37bcda9529a1335b724a1afeea37bf6388975baf pack-iq3-xxs/expert-profile.bin
|
||||
1afe12b36cd2d13bf122b741fa0e81e1f751319cc3c451e54ba75524d825f148 pack-iq3-xxs/index.txt
|
||||
ae28cf7a2a1c9063c4b55d6c8cf86d4d079dcddcf597f9e8697c9157d462c0ee pack-iq3-xxs/native_experts.txt
|
||||
c724dc0b0822ada5d2977bf5bde821605feabaa64ea2e0045b67ca656329070a mtp/dense.bin
|
||||
991456cf4eb266eb8a888c349e548d11bc640f5dbd9149439aa9786af0f732fd mtp/dense.txt
|
||||
b1e1d3a7a9e4bf862dcd5923ce661fb59bbd07907e594df5cf86a62ac235cb91 mtp/draft_vocab.bin
|
||||
09398406be61f1f54c93861f449e48b8df0bfccbc9ec9b2b7636775a6ea9244f mtp/experts.bin
|
||||
```
|
||||
## Changes to llama.cpp (robertkarl/llama.cpp, branch `UnbiasedStrata`)
|
||||
|
||||
## Prepared files for Qwen3.6-35B-A3B
|
||||
Six commits on top of ggml-org `3cf03257`; `git -C third_party/llama.cpp diff 3cf03257 HEAD` is exactly these.
|
||||
|
||||
Made with this repository's own tools (Python 3 with `numpy`; `STRATA_GGUF_PY` at `third_party/llama.cpp/gguf-py`),
|
||||
from unsloth's files: `Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf` and `Qwen3.6-35B-A3B-UD-IQ3_XXS.gguf` of
|
||||
[unsloth/Qwen3.6-35B-A3B-GGUF](https://huggingface.co/unsloth/Qwen3.6-35B-A3B-GGUF), and the `-MTP` repository's
|
||||
`Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf` (41 blocks; the draft block is `blk.40`) for the draft pack.
|
||||
- `9547d8d` (`common/parsers/qwen3-coder.cpp`): the Qwen3-Coder
|
||||
tool-call grammar accepts a call's arguments in any order. Upstream takes the required ones first and the
|
||||
optional ones after; Qwen3.8 Flash-Next often writes the optional ones first (`limit`, `offset`, `path`), and
|
||||
because the grammar's tool-call group is optional and has no end anchor, such a call was dropped silently:
|
||||
the client got `finish_reason=stop` and an empty answer (UnbiasedStrata 1, 2026-10-08, REGINA-104). Qwen3.6's
|
||||
template routes to the same parser. Carried over from UnbiasedStrata 1 unchanged.
|
||||
- `a6de9af` (`common/chat-auto-parser-generator.cpp`, `common/parsers/deepseek.cpp`): the same for every
|
||||
template the auto-generated PEG grammar serves (DeepSeek V4 Flash's DSML, GLM 5.3 Flash's `<arg_key>` form, and
|
||||
the rest). Upstream accepts the required arguments only in the schema's order, which holds when its own sampler
|
||||
is constrained by the grammar; this engine samples unconstrained, and both models wrote `content` before `path`
|
||||
for a `write` tool that declares `path` first, so a finished, well-formed call was reported to the client as
|
||||
"output does not match the expected peg-native format" (PLAN.md step 13, 2026-10-19, USTRAT-7). Whether every
|
||||
required argument is present is left to the tool, as upstream already leaves it for optional-only tools.
|
||||
|
||||
```
|
||||
export STRATA_GGUF_PY=$PWD/third_party/llama.cpp/gguf-py
|
||||
# the pack, one per model file (the tokenizer, the dense weights' index, the expert table, the route profile)
|
||||
python3 -I tools/iq_pack.py --gguf Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf --out qwen36-q4
|
||||
python3 -I tools/iq_pack.py --gguf Qwen3.6-35B-A3B-UD-IQ3_XXS.gguf --out qwen36-iq3
|
||||
cp data/qwen36-expert-profile.bin qwen36-q4/expert-profile.bin # tools/make_profile.py from the route trace
|
||||
cp data/qwen36-expert-profile.bin qwen36-iq3/expert-profile.bin
|
||||
# the draft pack, from the -MTP file's draft block; serves either trunk
|
||||
python3 -I tools/mtp_qwen36_pack.py --gguf Qwen3.6-35B-A3B-UD-Q4_K_XL-MTP.gguf --out qwen36-mtp-draft
|
||||
```
|
||||
- `1421694` (`tools/server/server-task.cpp`): a partial re-parse that reports fewer tool calls than the previous
|
||||
one no longer throws (the request died with a 500 mid-stream, "Invalid diff: now finding less tool calls!"); the
|
||||
previous message is kept, nothing is emitted for that token, and the raw generated text is logged. A non-partial
|
||||
parse failure returns the raw text as content instead of failing the request (issue #17, 2026-10-20).
|
||||
- `638a7e2` (`common/parsers/qwen3-coder.cpp`, `tests/test-chat.cpp`): the Qwen3-Coder grammar skips a stuttered
|
||||
`</parameter>` close tag. Qwen3.8 Flash-Next Coder IQ1_M, sampled without the grammar, wrote the tag twice before
|
||||
`</function>` in 7 of 673 requests of a BBW run (2026-10-20); each one failed the whole call and, through the diff
|
||||
check above, the request. The value still ends at the first close. Test in the Qwen3-Coder section of test-chat.
|
||||
- `4174b21` (`common/parsers/qwen3-coder.cpp`, `tools/server/server-task.cpp`, `tests/test-chat.cpp`): the same
|
||||
shard also leaves a blank line between the last `</parameter>` and `</function>` (memcached-bisect-deep,
|
||||
2026-10-21); the grammar now skips blank lines between arguments and before `</function>` and `</tool_call>`.
|
||||
And the final, non-partial parse gets the same guard as the partial one: when it finds fewer tool calls than were
|
||||
streamed, the streamed calls stand (arguments as last parsed) and the raw text is logged, instead of the diff
|
||||
check throwing and the request ending in a 500 after the hold-delta guard had kept it alive. Two blank-line cases
|
||||
in test-chat.
|
||||
- `385445f` (`common/parsers/qwen3-coder.cpp`, `tests/test-chat.cpp`): the third shape (prime-frontend, 2026-10-21):
|
||||
`</content>` and `</invoke>` after the real `</parameter>`, a blank line, `</parameter>` again. The stuttered-close
|
||||
rule becomes general: any close tag that is not `</function>` or `</tool_call>` is skipped between arguments.
|
||||
## Engine source (`src/`, `include/`)
|
||||
|
||||
`--draft-vocab none` leaves `draft_vocab.bin` out (the drafter then scores the whole vocabulary: a few percent
|
||||
higher acceptance, 345 MiB more VRAM for the head). Building twice gives the same bytes. SHA-256:
|
||||
No changes: `git diff 0197ae86 HEAD -- src include` is empty (checked 2026-10-18). The engines measured in step 9 are
|
||||
these sources built in this tree; their binaries differ from upstream's build of the same sources, and the step-9
|
||||
record says so where it matters.
|
||||
|
||||
```
|
||||
9c964e657212fea1f24905dd7b0a89b82fd807d19fab0b41da14251b07b88fbe Qwen3.6-35B-A3B-UD-IQ3_XXS.gguf
|
||||
707a55a8a4397ecde44de0c499d3e68c1ad1d240d1da65826b4949d1043f4450 Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf
|
||||
55983c5a75a1ab969824077b3bb3de4146e82a9234072b48ad4e8f92ad3fe9f1 Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf (the -MTP repository's file)
|
||||
7c20e11993ff853fe5698843d610b2a87927b04f9a4607551f4e023a39bc71ba qwen36-q4/conversions.json
|
||||
53467f9b49bbc57d570eb8802125144dd4b4d7fd6a658d685ef72005d75a5f4f qwen36-q4/dense.bin
|
||||
eb2ed6c8d86ebe0c16bb7a09af6c24fc4059627cc95e35def07c41568a30283c qwen36-q4/expert-profile.bin
|
||||
1a4725f13e24691a3d6fd10dba4bb6cb217c4831ff8d5529865fc01f39413c79 qwen36-q4/index.txt
|
||||
257d84e2d36a2e6572cd0dd8382283defe28bc07c2c97ece22ab6c1bd2f5bff4 qwen36-q4/native_experts.txt
|
||||
39bf397e3fb8591ab84cb9142dbd43f665c3bff456e9772c47dc04db5ca28195 qwen36-iq3/conversions.json
|
||||
53467f9b49bbc57d570eb8802125144dd4b4d7fd6a658d685ef72005d75a5f4f qwen36-iq3/dense.bin
|
||||
eb2ed6c8d86ebe0c16bb7a09af6c24fc4059627cc95e35def07c41568a30283c qwen36-iq3/expert-profile.bin
|
||||
685d475659736b415a5801413f116a4371970d3cb24b16e53625b98019895c73 qwen36-iq3/index.txt
|
||||
820053214b08d3eab1378705fb7c345a724ed0fe16544df07b2f519423bb10e8 qwen36-iq3/native_experts.txt
|
||||
4a93092f5716d289367b97ce107d8b08b2236a8e1954bc7f746881875c73d03a qwen36-mtp-draft/dense.bin
|
||||
dd5990d0ef0926252cad59090fa1d00f138db2e3f316eb96691db83940cde339 qwen36-mtp-draft/dense.txt
|
||||
b1e1d3a7a9e4bf862dcd5923ce661fb59bbd07907e594df5cf86a62ac235cb91 qwen36-mtp-draft/draft_vocab.bin
|
||||
9126741d7e98f0e470cd04bf7ce3c91a89c08c116af02aa2d8d666c4195fdb15 qwen36-mtp-draft/experts.bin
|
||||
1e5ad8c088196bc95b49534ce68db9c278635c8a68f7b605ef1776589dea29d7 qwen36-mtp-draft/mtp.json
|
||||
048604044d93d7dd4e4e1140deba8ccf681b5c7c11e330e9434a570af42bcfa2 qwen36-mtp-draft/native_experts.txt
|
||||
```
|
||||
Step 12 (harness `bench/correctness/`; record in history at 7551f138, `bench/unbiased/correctness/`; 2026-10-18) checked these builds against llama.cpp `3cf03257`: upstream's
|
||||
parity programs that cover the kernels in use (38 pass, `poly_expert_parity` fails its own bound on one UD-Q3_K_M expert),
|
||||
and teacher-forced per-step distributions on 16 sequences per model (within llama.cpp's own CPU-vs-GPU spread on every set
|
||||
and arm). Two upstream claims did not hold and are not repeated here: the draft block is not bitwise inert above 4-token
|
||||
windows, and `strata`'s output is not reproducible across starts unless the expert cache is pinned. Tickets USTRAT-1 to 5.
|
||||
|
||||
(`dense.bin` is byte-identical between the two packs: the dense weights unsloth keeps unquantized are the same in
|
||||
both files. The tokenizer directory's files are listed in `qwen36-*/index.txt`.)
|
||||
One test-only hunk since (2026-10-19, correctness checks of DeepSeek V4 Flash and GLM 5.3 Flash): `src/poly/main.cpp`
|
||||
`--tokens`, `--eos-ids` and `--follow` accept `@FILE` (the comma-separated ids read from that file), because a 31K-id
|
||||
list is over Linux's 128 KiB single-argument limit. `tools/qwen35/q36_llama_dump.cpp` (upstream's llama.cpp-side parity
|
||||
program, not part of the build) takes the same `@FILE` for `--tokens` and `--force`. Nothing on the serve path changes.
|
||||
|
||||
## DeepSeek-V4.1 engine (`src/dsv41`, from Strata v0.2.4)
|
||||
|
||||
Added 2026-10-24 to run DeepSeek-V4.1-Flash-1017 (ISTA-DASLab's GSQ-RCO GGUF sets) on the A6000 VM. Neither engine of
|
||||
this fork reads a `deepseek41` GGUF (`strata-poly` knows `deepseek4`, V4 Flash), and the pinned llama.cpp predates the
|
||||
architecture, so the engine is upstream Strata's third one, `strata-dsv41` - itself a port of Project Maya's `maya-ds4`
|
||||
(MIT; `third_party/project-maya/NOTICE.md`, the vendored EXL3 / sampler / window kernels under `src/dsv41/vendor/`).
|
||||
|
||||
- **Taken unmodified from Niko1221/Strata `v0.2.4` (96ca4383):** `src/dsv41/`, `include/strata/dsv41/`, `tests/dsv41/`,
|
||||
`tools/dsv41/{pack_gguf,smoke,tune}.py`, `data/dsv41/` (the shipped hot-expert profiles), `tools/trellis/tqenc.{cpp,hpp}`
|
||||
(the tests' encoder), `third_party/project-maya/`, `third_party/ggml/ggml-common-tq.h`, and upstream's `docs/DEEPSEEK41.md`
|
||||
(rewritten for this fork afterwards). `diff -r` against the tag's tree is the check.
|
||||
- **`src/kernels/cpu` and `include/strata/kernels/cpu`:** upstream's `iq_avx2.{cpp,hpp}`, `iq_avx2_rows.inl`,
|
||||
`iq_avx512.{cpp,hpp}` replace this fork's v0.1.45-poly.1 copies - they add the engine's CPU lane rows `iq256x_rows` /
|
||||
`iq512x_rows` (ggml's float order, so a token's dot is ggml-cpu's bit for bit) and, upstream states, leave `iq256_*` /
|
||||
`iq512_*` as they were (`iq_avx2_parity` is the check here) - and the trellis CPU lane `tq_cpu.{hpp,cpp}`,
|
||||
`tq_avx2.cpp`, `tq_avx512.cpp`, `tq_states.hpp`, `tq_computed.hpp` is new in `strata_kernels_cpu`. `expert_layout.hpp`
|
||||
stays at layout version 4: upstream's 5 only adds Hadamard-folded packs, which nothing here makes or reads.
|
||||
`iq_avx512.cpp` is built with `-mavx512vpopcntdq -mbmi2` as upstream does (`iq512x_rows` uses them).
|
||||
- **`CMakeLists.txt`:** upstream's `strata-dsv41` block as it is, but ggml.h / ggml-cpu.h come through
|
||||
`strata_kernels_cpu`'s `ggml-cpu` link from the submodule (no FetchContent, rule 1), and the option is turned on by the
|
||||
`Makefile` (`STRATA_BUILD_DSV41=ON`; `strata-dsv41` is in `TARGETS`). The engine is compiled with
|
||||
`STRATA_DSV41_TQ_CPU=1`, the ggml-cpu lane the IST-DAS sets' experts beyond VRAM run on.
|
||||
- **Not taken:** upstream's `setup.py` / `strata launch` plumbing (rules 1 and 2), the signed engine-package feed, the
|
||||
Python server's `serve/dsml.py` (this fork's front end parses DSML with llama.cpp's `common/parsers/deepseek.cpp`,
|
||||
below) and the fixture template `serve/fixtures/deepseek41/chat_template.jinja` (the GGUF's own template is used).
|
||||
- **Serving:** the front end starts it like the other two, `--engine strata-dsv41 -m <shard 1> ... -- --pack <pack>
|
||||
--max-context N --dspark auto`; `--serve` is added. Its line protocol is the one `frontend/engine.hpp` speaks
|
||||
(`READY`, `INFO`, `T`, `DONE`, `ERR`); its extra `STAT` and `NOTE` lines are ignored as `OTHER`. The front end's
|
||||
vocabulary load falls back to the `general.architecture` override (USTRAT-6's path) because the pinned llama.cpp
|
||||
does not know `deepseek41`.
|
||||
|
||||
## Removed
|
||||
|
||||
Each entry names the rule above that it satisfies.
|
||||
|
||||
- **Rule 1, installers and downloaders:** `setup.py` (8,223 lines: hardware detection, pip, CUDA, llama.cpp zips,
|
||||
prebuilt engines from GitHub releases, model files from Hugging Face or ModelScope, pack and MTP orchestration,
|
||||
run-config JSON, start), `setup.sh`, `SETUP.bat`, `START-HERE.bat`, `UPDATE.bat`, `update.sh`, `Dockerfile`,
|
||||
`docker-entrypoint.sh`, `.dockerignore`, `flake.nix`, `flake.lock`, `requirements.txt` (replaced by
|
||||
`tools/requirements.txt`: numpy and regex, for the offline tools only), `conftest.py` (pytest root for
|
||||
`setup.py`'s tests), `tools/strata_mcp.py` (an installer driven over MCP), `tools/image/` (stable-diffusion.cpp,
|
||||
Vulkan SDK and model downloads), `tools/hip/package_windows.py` (AMD nightly wheels), and their tests
|
||||
(`tools/test_setup_*.py` with two golden JSONs, `test_strata_mcp.py`, `test_qimage.py`,
|
||||
`test_docker_entrypoint.py`, `test_poly_prebuilt.py`). The jobs of `setup.py` that were not downloads (choosing
|
||||
engine flags per card, RAM and context) become documented flags in `README.md`.
|
||||
- **Rule 2, Python in the serving path:** `serve/` (92 files, 33.9k lines: the HTTP server with the OpenAI,
|
||||
Anthropic and Responses dialects, the jinja2 chat templating, the Python tokenizer path, the per-family
|
||||
reasoning and tool-call parsers, MCP, structured output, replicas, Prometheus, the hardware monitor, the web
|
||||
UI and 58 test files) and `polystrata.py` (the terminal front end, which imports `serve/`). Replaced by the C++
|
||||
front end in `frontend/`, built from the pinned llama.cpp's `common`, `mtmd`, `cpp-httplib` and the
|
||||
engine-agnostic files of `tools/server`. The engines' stdin/stdout protocol is unchanged.
|
||||
- **Rule 4, marketing:** the six translated READMEs (383 KB), `docs/media/` (12 MB: a 9.6 MB demo video still,
|
||||
a 1.8 MB GIF, the figure SVGs and their generator), `.github/` (issue and PR templates), `SECURITY.md` (the
|
||||
upstream project's advisory process) and `AGENTS.md` (contributor notes for upstream's tests and installers).
|
||||
`README.md` is rewritten for this fork (PLAN.md step 10); the fork's model-file record is `docs/MODEL-FILES.md`,
|
||||
its measurements are the "Measured" section of `README.md` (records in history at 7551f138).
|
||||
- **Documents only removed components (decided 2026-10-17):** `docs/INSTALL.md`, `AI_SETUP.md`, `MCP_SERVER.md`,
|
||||
`IMAGES.md`, `LLAMA_SWAP.md`, `COMMUNITY_BENCHMARKS.md`, `FAQ.md`; `chat.py` (a terminal client) and
|
||||
`tools/calibrate.py` (imports `setup` and `serve.server`), with their tests.
|
||||
- **Scripts that imported removed modules (decided 2026-10-17):** the engine gate scripts that drove the engine
|
||||
through the Python server's `StrataEngine` class (`tools/batch_groups_cache_test.py`, `cancel_park_test.py`,
|
||||
`conversation_cache_*.py`, `conversation_restore_speed.py`, `logit_bias_english_example.py`,
|
||||
`logit_bias_http_probe.py`, `session_pressure_test.py`), `tools/strata_bench.py` with `bench.sh` and `BENCH.bat`
|
||||
(one helper from `setup`), `tools/make_poly_release.py`, and the tests that imported `setup` or `serve`
|
||||
(`test_mtp_fetch.py`, `test_shards.py`, `test_strata_tokenizer.py`, `test_effort_end_args.py`,
|
||||
`test_research_run.py`, `test_benchmark_prompt.py`, `test_dll_closure.py`, `test_windows_amd_gpu.py`, the
|
||||
`test_conversation_cache_*` and `test_strata_bench.py`). Upstream's copies run against upstream.
|
||||
- **Per-machine results and logs (decided 2026-10-19):** upstream's `bench/results/` (23 MB, one directory per
|
||||
community machine) and the fork's own `bench/unbiased/` run directories (57 MB). A result from one machine is a
|
||||
record, not source; the numbers that matter are in `README.md` "Measured", and the directories are in history at
|
||||
7551f138. `bench/` keeps what is reusable: `bench_vs_llama.py` with `profile_corpus.json`, the kernel probes, and
|
||||
`bench/correctness/` (the step-12 harness, moved from `bench/unbiased/correctness/scripts/`).
|
||||
@@ -0,0 +1,5 @@
|
||||
# what is this
|
||||
|
||||
Note from a human. This folder contained the detailed logs from Strata; PolyStrata; and UnbiasedStrata's implementations being checked against each other and llama-server.
|
||||
|
||||
It has been slimmed down only to reusable scripts.
|
||||
@@ -0,0 +1,281 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Strata vs llama.cpp head-to-head (stream 1402-h). Measurement only.
|
||||
|
||||
Both engines are driven through their OpenAI-compatible HTTP servers (/v1/chat/completions), with the same prompt
|
||||
text, same sampler settings and the same GGUF. Server-side timings (llama.cpp's names, which Strata's server also
|
||||
emits) give prompt tok/s and decode tok/s; time to first token is the server's prompt_ms (non-streaming request,
|
||||
so TTFT = prompt processing time). Peak VRAM comes from nvidia-smi polling (minus the idle baseline), RAM from the
|
||||
engine process tree (psutil RSS, which counts mmap'd file pages) and the system's used-memory delta.
|
||||
|
||||
python bench_vs_llama.py prompts --out DIR --tokenizer DIR --corpus FILE... # build 4K / 32K prompt files
|
||||
python bench_vs_llama.py run --machine CFG.json --out DIR --rounds N [--configs a,b] [--cells ...]
|
||||
python bench_vs_llama.py quality --machine CFG.json --out DIR [--configs a,b]
|
||||
python bench_vs_llama.py summary --out DIR
|
||||
|
||||
CFG.json: {"gguf": ..., "strata_cfg": ..., "llama_server": ..., "configs": [{"name","kind":"llama|strata","args":[...]}]}
|
||||
Interleaving: engines cannot be loaded together (12 GB card, 64 GB RAM), so one ROUND runs every config once
|
||||
(start, warm-up, cells, stop), and rounds alternate the config order. Medians are taken over rounds.
|
||||
The caller holds the machine's GPU lock. Processes are stopped by PID only.
|
||||
"""
|
||||
import argparse, json, os, statistics, subprocess, sys, threading, time, urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
import psutil
|
||||
|
||||
CELLS = [("4k", 4000, 2), ("32k", 32000, 1)] # (name, prompt tokens, reps per round)
|
||||
TEMPS = [0.0, 0.7]
|
||||
GEN = 256
|
||||
PORT = 8190
|
||||
|
||||
|
||||
def http(url, body=None, timeout=3600):
|
||||
req = urllib.request.Request(url, data=json.dumps(body).encode() if body is not None else None,
|
||||
headers={"Content-Type": "application/json"})
|
||||
with urllib.request.urlopen(req, timeout=timeout) as r:
|
||||
return json.loads(r.read())
|
||||
|
||||
|
||||
def vram_used_mib():
|
||||
try:
|
||||
out = subprocess.run(["nvidia-smi", "--query-gpu=memory.used", "--format=csv,noheader,nounits"],
|
||||
capture_output=True, text=True, timeout=20).stdout.split()
|
||||
return int(out[0])
|
||||
except Exception:
|
||||
return -1
|
||||
|
||||
|
||||
class Sampler(threading.Thread):
|
||||
def __init__(self, pid):
|
||||
super().__init__(daemon=True)
|
||||
self.pid, self.stop, self.vram, self.rss, self.sysused = pid, False, 0, 0, 0
|
||||
|
||||
def run(self):
|
||||
while not self.stop:
|
||||
self.vram = max(self.vram, vram_used_mib())
|
||||
try:
|
||||
p = psutil.Process(self.pid)
|
||||
self.rss = max(self.rss, sum(c.memory_info().rss for c in [p] + p.children(recursive=True)))
|
||||
except psutil.Error:
|
||||
pass
|
||||
self.sysused = max(self.sysused, psutil.virtual_memory().used)
|
||||
time.sleep(1.0)
|
||||
|
||||
|
||||
class Engine:
|
||||
def __init__(self, machine, cfg):
|
||||
self.m, self.cfg, self.proc, self.log = machine, cfg, None, None
|
||||
|
||||
def command(self):
|
||||
c = self.cfg
|
||||
if c["kind"] == "llama":
|
||||
return [self.m["llama_server"], "-m", self.m["gguf"], "--port", str(PORT), "--host", "127.0.0.1",
|
||||
"-np", "1", "--no-webui", "--jinja"] + c["args"]
|
||||
scfg = json.load(open(self.m["strata_cfg"], encoding="utf-8-sig"))
|
||||
scfg["port"] = PORT
|
||||
scfg.pop("vision", None)
|
||||
args = [a for a in scfg["args"]]
|
||||
for k, v in c.get("override", {}).items(): # replace "--flag value" pairs
|
||||
if k in args:
|
||||
args[args.index(k) + 1] = v
|
||||
else:
|
||||
args += [k, v]
|
||||
scfg["args"] = args + c["args"]
|
||||
if self.m.get("strata_exe"):
|
||||
scfg["exe"] = self.m["strata_exe"]
|
||||
p = Path(self.out) / ("strata-cfg-%s.json" % c["name"])
|
||||
p.write_text(json.dumps(scfg, indent=1))
|
||||
return [sys.executable, str(Path(self.m["serve"]) / "server.py"), "--engine", "strata", "--config", str(p),
|
||||
"--port", str(PORT)]
|
||||
|
||||
def start(self, out):
|
||||
self.out = out = str(Path(out).resolve())
|
||||
self.base_vram, self.base_used = vram_used_mib(), psutil.virtual_memory().used
|
||||
cmd = self.command()
|
||||
self.cmdline = " ".join(cmd)
|
||||
self.log = open(Path(out) / ("server-%s-%d.log" % (self.cfg["name"], int(time.time()))), "w", encoding="utf-8")
|
||||
env = dict(os.environ, PYTHONIOENCODING="utf-8")
|
||||
self.proc = subprocess.Popen(cmd, stdout=self.log, stderr=subprocess.STDOUT, env=env,
|
||||
cwd=self.m.get("cwd"))
|
||||
self.t0 = time.time()
|
||||
self.sampler = Sampler(self.proc.pid)
|
||||
self.sampler.start()
|
||||
health = "http://127.0.0.1:%d/health" % PORT
|
||||
while time.time() - self.t0 < 1500:
|
||||
if self.proc.poll() is not None:
|
||||
raise RuntimeError("server exited rc=%s (see %s)" % (self.proc.returncode, self.log.name))
|
||||
try:
|
||||
r = http(health, timeout=5)
|
||||
if r.get("status", "ok") == "ok":
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(2)
|
||||
else:
|
||||
raise RuntimeError("server not ready in 1500 s")
|
||||
self.load_s = time.time() - self.t0
|
||||
|
||||
def stop(self):
|
||||
if self.proc:
|
||||
self.sampler.stop = True
|
||||
try:
|
||||
p = psutil.Process(self.proc.pid)
|
||||
kids = p.children(recursive=True)
|
||||
for c in kids + [p]:
|
||||
try:
|
||||
c.terminate()
|
||||
except psutil.Error:
|
||||
pass
|
||||
psutil.wait_procs(kids + [p], timeout=30)
|
||||
for c in kids + [p]:
|
||||
try:
|
||||
if c.is_running():
|
||||
c.kill()
|
||||
except psutil.Error:
|
||||
pass
|
||||
except psutil.Error:
|
||||
pass
|
||||
self.log.close()
|
||||
self.proc = None
|
||||
time.sleep(5)
|
||||
|
||||
def chat(self, prompt, temp, max_tokens=GEN, seed=1):
|
||||
body = {"model": "x", "messages": [{"role": "user", "content": prompt}], "max_tokens": max_tokens,
|
||||
"temperature": temp, "top_k": 20, "top_p": 0.95, "seed": seed, "stream": False,
|
||||
"cache_prompt": False, "chat_template_kwargs": {"enable_thinking": False}}
|
||||
if temp == 0:
|
||||
body.pop("top_p"), body.pop("top_k")
|
||||
t = time.time()
|
||||
r = http("http://127.0.0.1:%d/v1/chat/completions" % PORT, body)
|
||||
wall = time.time() - t
|
||||
tm = r.get("timings") or {}
|
||||
u = r.get("usage") or {}
|
||||
return {"wall_s": round(wall, 2), "prompt_n": tm.get("prompt_n", u.get("prompt_tokens")),
|
||||
"prompt_ms": tm.get("prompt_ms"), "prompt_tps": tm.get("prompt_per_second"),
|
||||
"pred_n": tm.get("predicted_n", u.get("completion_tokens")), "pred_tps": tm.get("predicted_per_second"),
|
||||
"draft_n": tm.get("draft_n"), "draft_acc": tm.get("draft_n_accepted"),
|
||||
"text": (r["choices"][0]["message"].get("content") or "")}
|
||||
|
||||
|
||||
def cmd_prompts(a):
|
||||
sys.path.insert(0, str(Path(a.repo) / "tools"))
|
||||
import strata_tokenizer as ST
|
||||
tp = Path(a.tokenizer)
|
||||
vocab = json.loads((tp / "vocab.json").read_text(encoding="utf-8"))
|
||||
toks = [None] * len(vocab)
|
||||
for t, i in vocab.items():
|
||||
toks[i] = t
|
||||
tok = ST.Tokenizer(toks, (tp / "merges.txt").read_text(encoding="utf-8").split("\n"),
|
||||
json.loads((tp / "token_type.json").read_text()))
|
||||
corpus = "\n\n".join(Path(f).read_text(encoding="utf-8", errors="replace") for f in a.corpus)
|
||||
print("corpus chars", len(corpus))
|
||||
out = Path(a.out)
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
allids = tok.encode(corpus)
|
||||
print("corpus tokens", len(allids))
|
||||
for name, n, _ in CELLS:
|
||||
if len(allids) < n:
|
||||
raise SystemExit("corpus too small for %s" % name)
|
||||
(out / ("prompt-%s.txt" % name)).write_text(tok.decode(allids[:n]), encoding="utf-8")
|
||||
print(name, n, "tokens")
|
||||
|
||||
|
||||
def load_prompt(out, name):
|
||||
return (Path(out) / ("prompt-%s.txt" % name)).read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def cmd_run(a):
|
||||
m = json.load(open(a.machine))
|
||||
out = Path(a.out)
|
||||
(out / "raw").mkdir(parents=True, exist_ok=True)
|
||||
cfgs = [c for c in m["configs"] if not a.configs or c["name"] in a.configs.split(",")]
|
||||
cells = [c for c in CELLS if not a.cells or c[0] in a.cells.split(",")]
|
||||
prompts = {c[0]: load_prompt(out, c[0]) for c in cells}
|
||||
for rnd in range(a.start_round, a.start_round + a.rounds):
|
||||
order = cfgs if rnd % 2 == 0 else cfgs[::-1]
|
||||
for cfg in order:
|
||||
eng = Engine(m, cfg)
|
||||
rec_path = out / "raw" / ("%s.jsonl" % cfg["name"])
|
||||
try:
|
||||
eng.start(str(out))
|
||||
eng.chat("Say hello.", 0.0, 16) # warm-up, discarded
|
||||
eng.chat(prompts["4k"][:6000] if "4k" in prompts else "hi", 0.0, 32)
|
||||
for cname, n, reps in cells:
|
||||
for t in TEMPS:
|
||||
for k in range(reps):
|
||||
nonce = "[bench %s r%d %s t%.1f k%d %d]\n" % (cfg["name"], rnd, cname, t, k, time.time())
|
||||
r = eng.chat(nonce + prompts[cname] + "\n\nSummarize the text above in three sentences.", t)
|
||||
r.update(config=cfg["name"], round=rnd, cell=cname, temp=t, rep=k,
|
||||
vram_peak_mib=eng.sampler.vram, vram_base_mib=eng.base_vram,
|
||||
rss_peak_gib=round(eng.sampler.rss / 2**30, 2),
|
||||
sys_used_delta_gib=round((eng.sampler.sysused - eng.base_used) / 2**30, 2),
|
||||
load_s=round(eng.load_s, 1), cmd=eng.cmdline if (rnd == a.start_round and k == 0) else None)
|
||||
r["text"] = r["text"][:300]
|
||||
with open(rec_path, "a", encoding="utf-8") as f:
|
||||
f.write(json.dumps(r) + "\n")
|
||||
print(cfg["name"], rnd, cname, t, "pp %s tg %s draft %s/%s ttft %s" % (
|
||||
r["prompt_tps"], r["pred_tps"], r["draft_acc"], r["draft_n"], r["prompt_ms"]), flush=True)
|
||||
except Exception as e:
|
||||
print("ERROR", cfg["name"], rnd, repr(e), flush=True)
|
||||
with open(out / "raw" / "errors.log", "a") as f:
|
||||
f.write("%s r%d %r\n" % (cfg["name"], rnd, e))
|
||||
finally:
|
||||
eng.stop()
|
||||
|
||||
|
||||
QPROMPT = "Write a short story about a lighthouse keeper."
|
||||
|
||||
|
||||
def cmd_quality(a):
|
||||
m = json.load(open(a.machine))
|
||||
out = Path(a.out)
|
||||
(out / "raw").mkdir(parents=True, exist_ok=True)
|
||||
cfgs = [c for c in m["configs"] if not a.configs or c["name"] in a.configs.split(",")]
|
||||
res = {}
|
||||
for cfg in cfgs:
|
||||
eng = Engine(m, cfg)
|
||||
try:
|
||||
eng.start(str(out))
|
||||
eng.chat("Say hello.", 0.0, 16)
|
||||
for q in (QPROMPT, "Write a Python function that parses a CSV file into a list of dicts, with tests."):
|
||||
r = eng.chat(q, 0.0, 200)
|
||||
res.setdefault(cfg["name"], []).append(r["text"])
|
||||
finally:
|
||||
eng.stop()
|
||||
(out / "raw" / "quality.json").write_text(json.dumps(res, indent=1), encoding="utf-8")
|
||||
|
||||
|
||||
def cmd_summary(a):
|
||||
out = Path(a.out)
|
||||
rows = {}
|
||||
for f in sorted((out / "raw").glob("*.jsonl")):
|
||||
for line in open(f, encoding="utf-8"):
|
||||
r = json.loads(line)
|
||||
rows.setdefault((r["config"], r["cell"], r["temp"]), []).append(r)
|
||||
med = lambda xs: statistics.median(xs) if xs else float("nan")
|
||||
print("| config | ctx | temp | n | prompt tok/s | decode tok/s | TTFT s | draft acc | VRAM peak MiB (delta) | RSS GiB |")
|
||||
print("|---|---|---|---|---|---|---|---|---|---|")
|
||||
for (c, cell, t), rs in sorted(rows.items()):
|
||||
pp = [r["prompt_tps"] for r in rs if r["prompt_tps"]]
|
||||
tg = [r["pred_tps"] for r in rs if r["pred_tps"]]
|
||||
tt = [r["prompt_ms"] / 1000 for r in rs if r["prompt_ms"]]
|
||||
da = [r["draft_acc"] / r["draft_n"] for r in rs if r.get("draft_n")]
|
||||
print("| %s | %s | %.1f | %d | %.1f | %.2f | %.2f | %s | %d (+%d) | %.1f |" % (
|
||||
c, cell, t, len(rs), med(pp), med(tg), med(tt), ("%.2f" % med(da)) if da else "-",
|
||||
max(r["vram_peak_mib"] for r in rs), max(r["vram_peak_mib"] - r["vram_base_mib"] for r in rs),
|
||||
max(r["rss_peak_gib"] for r in rs)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("mode", choices=["prompts", "run", "quality", "summary"])
|
||||
ap.add_argument("--out", required=True)
|
||||
ap.add_argument("--machine")
|
||||
ap.add_argument("--configs")
|
||||
ap.add_argument("--cells")
|
||||
ap.add_argument("--rounds", type=int, default=1)
|
||||
ap.add_argument("--start-round", type=int, default=0)
|
||||
ap.add_argument("--tokenizer")
|
||||
ap.add_argument("--repo")
|
||||
ap.add_argument("--corpus", nargs="*")
|
||||
a = ap.parse_args()
|
||||
{"prompts": cmd_prompts, "run": cmd_run, "quality": cmd_quality, "summary": cmd_summary}[a.mode](a)
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
# Plan section 4 run order step 6: strata-poly --check-batch 4 on the short set, both Qwen3.6 files. Each short
|
||||
# prompt gives 4 prompts (the prompt minus its first 0..3 tokens), answered alone and then together; exit 1 on a
|
||||
# differing token.
|
||||
# Paths (the defaults are the homelab VM's; set them for another machine): US2_MODELS, the directory holding
|
||||
# qwen36/<file>.gguf (required); US2_BUILD, the UnbiasedStrata tree with build/bin (default: this script's
|
||||
# repository); US2_RESULTS, where results go (default ~/us2-results/correctness).
|
||||
B=${US2_BUILD:-$(cd "$(dirname "$0")/../.." && pwd)}/build/bin
|
||||
M=${US2_MODELS:?set US2_MODELS to the directory holding qwen36/}/qwen36
|
||||
mkdir -p "${US2_RESULTS:-$HOME/us2-results/correctness}" && cd "${US2_RESULTS:-$HOME/us2-results/correctness}" || exit 1
|
||||
for tag in qwen36-q3km:Qwen3.6-35B-A3B-UD-Q3_K_M.gguf qwen36-iq4xs:Qwen3.6-35B-A3B-UD-IQ4_XS.gguf; do
|
||||
name=${tag%%:*}; file=${tag#*:}; out=checkbatch/$name; mkdir -p $out
|
||||
for p in inputs/short/p*.prompt.ids; do
|
||||
seq=$(basename $p .prompt.ids)
|
||||
cmd="STRATA_FREEZE_EXPERTS=1 $B/strata-poly --model $M/$file --max-context 8192 --tail-skip 0 --no-draft --lookup 0 --window 1 --tokens \$(cat $p) --batch 4 --check-batch 4 --max-new 64"
|
||||
echo "$cmd # > $out/$seq.log" >> $out/command.sh
|
||||
STRATA_FREEZE_EXPERTS=1 $B/strata-poly --model $M/$file --max-context 8192 --tail-skip 0 --no-draft --lookup 0 --window 1 --tokens $(cat $p) --batch 4 --check-batch 4 --max-new 64 > $out/$seq.log 2>&1
|
||||
rc=$?
|
||||
echo "$name $seq: exit $rc; $(grep "^check-batch" $out/$seq.log | tr "\n" ";")"
|
||||
done
|
||||
done
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
"""reference/<tag>/<seq>.<gpu|cpu>.full (f32 [steps][vocab], kept on the box) -> <seq>.<mode>.top20.tsv committed:
|
||||
per step the argmax, the top-2 gap in nats and the 20 likeliest ids with their log-probabilities (id:logp)."""
|
||||
import os, pathlib, sys
|
||||
import numpy as np
|
||||
V = int(os.environ.get('US2_VOCAB', 248320))
|
||||
for f in sorted(pathlib.Path(sys.argv[1]).glob('*.full')):
|
||||
out = f.with_name(f.name[:-5] + '.top20.tsv')
|
||||
if out.exists(): continue
|
||||
a = np.fromfile(f, dtype=np.float32).reshape(-1, V).astype(np.float64)
|
||||
lines = ['step\targmax\ttop2_gap\ttop20(id:logp)']
|
||||
for s in range(len(a)):
|
||||
r = a[s]; m = r.max(); lp = r - (m + np.log(np.exp(r - m).sum()))
|
||||
idx = np.argpartition(-lp, 20)[:20]; idx = idx[np.argsort(-lp[idx])]
|
||||
lines.append(f'{s}\t{int(idx[0])}\t{lp[idx[0]] - lp[idx[1]]:.4f}\t' + ' '.join(f'{int(i)}:{lp[i]:.5f}' for i in idx))
|
||||
out.write_text('\n'.join(lines) + '\n'); print(out.name, len(a), 'steps')
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Step-12 inputs for a model whose tokenizer is not Qwen's (CORRECTNESS-PLAN.md 3.2; the DeepSeek V4 Flash and GLM 5.3
|
||||
Flash runs of 2026-10-19). Same texts as make-inputs.py (inputs-src/), tokenized through the fork front end that serves
|
||||
the model: /apply-template renders the model's own chat template, /tokenize gives the ids (special tokens parsed).
|
||||
make-inputs-model.py <root> <server-url> <deepseek|glm>
|
||||
Writes <root>/inputs/<set>/<seq>.prompt.ids, .json and realtext's .answer.ids. Raw text (long, realtext) is prefixed
|
||||
with the model's sequence start: DeepSeek <|begin_of_sentence|>, GLM [gMASK]<sop>, as the chat template does."""
|
||||
import json, pathlib, sys, urllib.request
|
||||
root, url, fam = pathlib.Path(sys.argv[1]), sys.argv[2].rstrip('/'), sys.argv[3]
|
||||
SRC = root / 'inputs-src'; OUT = root / 'inputs'
|
||||
|
||||
def post(path, body):
|
||||
req = urllib.request.Request(url + path, json.dumps(body).encode(), {'content-type': 'application/json'})
|
||||
return json.load(urllib.request.urlopen(req, timeout=600))
|
||||
|
||||
def tokenize(text):
|
||||
return post('/tokenize', {'content': text, 'add_special': False})['tokens']
|
||||
|
||||
def chat(q, think):
|
||||
"""The model's own template, thinking on or off. DeepSeek: the template's `thinking` switch (off renders
|
||||
`<|Assistant|></think>`). GLM: the template always opens <think>; off is an empty block, as Qwen's."""
|
||||
if fam == 'deepseek':
|
||||
return post('/apply-template', {'messages': [{'role': 'user', 'content': q}], 'chat_template_kwargs': {'thinking': think}})['prompt']
|
||||
p = post('/apply-template', {'messages': [{'role': 'user', 'content': q}]})['prompt']
|
||||
assert p.endswith('<think>'), p[-40:]
|
||||
return p if think else p + '</think>'
|
||||
|
||||
PREFIX = {'deepseek': '<|begin▁of▁sentence|>', 'glm': '[gMASK]<sop>'}[fam]
|
||||
|
||||
def write(setname, seq, prompt, answer=None, n_answer=None):
|
||||
d = OUT / setname; d.mkdir(parents=True, exist_ok=True)
|
||||
(d / f'{seq}.prompt.ids').write_text(','.join(map(str, prompt)) + '\n')
|
||||
if answer is not None:
|
||||
(d / f'{seq}.answer.ids').write_text(','.join(map(str, answer)) + '\n')
|
||||
meta = {'prompt_tokens': len(prompt), 'n_answer': len(answer) if answer else n_answer}
|
||||
(d / f'{seq}.json').write_text(json.dumps(meta) + '\n')
|
||||
print(setname, seq, meta, flush=True)
|
||||
|
||||
for i, q in enumerate(json.load(open(SRC / 'short.json'))):
|
||||
write('short', f'p{i:02d}', tokenize(chat(q, False)), n_answer=128)
|
||||
write('code', 'lru', tokenize(chat((SRC / 'code.txt').read_text().strip(), False)), n_answer=400)
|
||||
write('code', 'puzzle', tokenize(chat((SRC / 'reasoning.txt').read_text().strip(), True)), n_answer=324)
|
||||
doc = tokenize(PREFIX + (SRC / 'longdoc.txt').read_text())
|
||||
print('longdoc tokens', len(doc)); assert len(doc) >= 31744, len(doc)
|
||||
for name, n in (('d4k', 4096), ('d16k', 16384), ('d31k', 31744)):
|
||||
write('long', name, doc[:n], n_answer=256)
|
||||
write('realtext', 'r16k', doc[:16384 - 510], answer=doc[16384 - 510:16384])
|
||||
(root / 'inputs' / 'README.txt').write_text(f'{fam}: tokenized through {url} (fork front end /apply-template + /tokenize), texts from inputs-src/\n')
|
||||
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Step 12 inputs (CORRECTNESS-PLAN.md 3.2). Writes inputs/<set>/<seq>.prompt.ids (comma-separated token ids) and, for
|
||||
the real-text set, .answer.ids. Tokenizer: llama-tokenize from the reference build on the Qwen3.6 file (Flash-Next's
|
||||
tokenizer gives the same ids: checked on prompt 1, 2026-10-18). Chat prompts use Qwen's ChatML; thinking off = empty
|
||||
<think> block, as tools/qwen35/parity_prompts.ids."""
|
||||
import json, os, pathlib, subprocess, sys
|
||||
# Paths (the defaults are the homelab VM's; set them for another machine): US2_MODELS, the directory holding
|
||||
# qwen36/<file>.gguf (required); US2_BUILD, the UnbiasedStrata tree with build/bin (default: this script's
|
||||
# repository); US2_RESULTS, where results go (default ~/us2-results/correctness).
|
||||
def _models():
|
||||
m = os.environ.get('US2_MODELS')
|
||||
if not m:
|
||||
sys.exit('set US2_MODELS to the directory holding qwen36/')
|
||||
return pathlib.Path(m)
|
||||
BUILD = pathlib.Path(os.environ.get('US2_BUILD') or pathlib.Path(__file__).resolve().parents[2])
|
||||
ROOT = pathlib.Path(os.environ.get('US2_RESULTS') or pathlib.Path.home() / 'us2-results/correctness')
|
||||
TOK = pathlib.Path.home() / 'llamacpp-ref/build/bin/llama-tokenize'
|
||||
MODEL = str(_models() / 'qwen36/Qwen3.6-35B-A3B-UD-Q3_K_M.gguf')
|
||||
SRC = ROOT / 'inputs-src'; OUT = ROOT / 'inputs'
|
||||
|
||||
def tokenize(text):
|
||||
p = SRC / '_tmp.txt'; p.write_text(text)
|
||||
r = subprocess.run([str(TOK), '-m', MODEL, '--ids', '--no-bos', '-f', str(p)], capture_output=True, text=True)
|
||||
line = [l for l in r.stdout.splitlines() if l.startswith('[')][-1]
|
||||
return json.loads(line)
|
||||
|
||||
def chat(q, think):
|
||||
return ('<|im_start|>user\n' + q + '<|im_end|>\n<|im_start|>assistant\n' +
|
||||
('<think>\n' if think else '<think>\n\n</think>\n\n'))
|
||||
|
||||
def write(setname, seq, prompt, answer=None, n_answer=None):
|
||||
d = OUT / setname; d.mkdir(parents=True, exist_ok=True)
|
||||
(d / f'{seq}.prompt.ids').write_text(','.join(map(str, prompt)) + '\n')
|
||||
if answer is not None:
|
||||
(d / f'{seq}.answer.ids').write_text(','.join(map(str, answer)) + '\n')
|
||||
meta = {'prompt_tokens': len(prompt), 'n_answer': len(answer) if answer else n_answer}
|
||||
(d / f'{seq}.json').write_text(json.dumps(meta) + '\n')
|
||||
print(setname, seq, meta)
|
||||
|
||||
# short chat: upstream's 10 prompts, 128 answer tokens
|
||||
ref_ids = [list(map(int, l.split(','))) for l in open(BUILD / 'tools/qwen35/parity_prompts.ids') if l.strip()]
|
||||
for i, q in enumerate(json.load(open(SRC / 'short.json'))):
|
||||
ids = tokenize(chat(q, False))
|
||||
assert ids == ref_ids[i], (i, ids, ref_ids[i]) # the retokenized prompt must equal upstream's file
|
||||
write('short', f'p{i:02d}', ids, n_answer=128)
|
||||
# code (thinking off, 400) and reasoning (thinking on, 324)
|
||||
write('code', 'lru', tokenize(chat((SRC / 'code.txt').read_text().strip(), False)), n_answer=400)
|
||||
write('code', 'puzzle', tokenize(chat((SRC / 'reasoning.txt').read_text().strip(), True)), n_answer=324)
|
||||
# long prompts from the repository's docs, 256-token continuation each; real text = last 510 of the 16K document
|
||||
doc = tokenize((SRC / 'longdoc.txt').read_text())
|
||||
print('longdoc tokens', len(doc)); assert len(doc) >= 31744
|
||||
for name, n in (('d4k', 4096), ('d16k', 16384), ('d31k', 31744)):
|
||||
write('long', name, doc[:n], n_answer=256)
|
||||
write('realtext', 'r16k', doc[:16384 - 510], answer=doc[16384 - 510:16384])
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
# Run-order step 2 (CORRECTNESS-PLAN.md section 4): the component parities whose formats are in use. Registered ones
|
||||
# through ctest (one directory per test under parity/, with stdout+stderr and the exit code); the hand-run poly_*
|
||||
# programs after. Reconfigures first so iq_parity registers now that numpy is present.
|
||||
set -u
|
||||
# Paths (the defaults are the homelab VM's; set them for another machine): US2_MODELS, the directory holding
|
||||
# qwen36/<file>.gguf (required); US2_BUILD, the UnbiasedStrata tree with build/bin (default: this script's
|
||||
# repository); US2_RESULTS, where results go (default ~/us2-results/correctness).
|
||||
cd "${US2_BUILD:-$(cd "$(dirname "$0")/../.." && pwd)}" || exit 1
|
||||
R=${US2_RESULTS:-$HOME/us2-results/correctness}/parity; mkdir -p $R
|
||||
make configure CMAKE_EXTRA=-DSTRATA_BUILD_TESTS=ON CUDA_ARCHS=86 > $R/reconfigure.log 2>&1
|
||||
cmake --build build -j 8 --target iq_parity >> $R/reconfigure.log 2>&1; echo "iq_parity build exit $?" >> $R/reconfigure.log
|
||||
ctest --test-dir build -N > $R/ctest-list.txt 2>&1
|
||||
A="iq_parity iq_avx2_parity iq_avx2_parity_iq3s_mt1 q8k_quant_parity q8k_quant_parity_avx native_grouped_parity iq_multi_parity mmvq_multi_parity prefill_fused_iq_test prefill_mmq_scatter_test kv_q8_parity kv_stream_parity kv_steps_parity kv_window_parity gdn_parity gdn_rec_parity qsa_parity qsa_topk_parity verify_parity spec_verify_parity sampler_parity native_multi_parity rope_parity elementwise_parity decode_cluster_parity quantize_act_parity dequant_wide_parity pdl_parity dma_batch_parity batch_rows_parity verify_batch_parity router_top10_parity route_window_parity native_expert_parity_q4_K_q8_0 native_expert_parity_q6_K_q8_0 native_expert_parity_q8_0_q8_0 poly_kv_q8_test poly_workers_test"
|
||||
for t in $A; do
|
||||
d=$R/$t; mkdir -p $d
|
||||
cmd=$(ctest --test-dir build -N -V -R "^$t\$" 2>/dev/null | grep "Test command" | sed 's/.*Test command: //')
|
||||
echo "$cmd" > $d/command.sh
|
||||
if [ -z "$cmd" ]; then echo "NOT_REGISTERED_OR_NOT_BUILT" > $d/exit.txt; echo "$t: not registered"; continue; fi
|
||||
( cd build && timeout 1500 ctest --test-dir . -R "^$t\$" --output-on-failure --timeout 1200 -V > $d/ctest.txt 2>&1; echo $? > $d/exit.txt )
|
||||
echo "$t: exit $(cat $d/exit.txt) $(grep -oE "[0-9]+% tests passed|Passed|Failed|Not Run|Timeout" $d/ctest.txt | head -2 | tr '\n' ' ')"
|
||||
done
|
||||
# hand-run programs (section 2.2 "hand")
|
||||
M=${US2_MODELS:?set US2_MODELS to the directory holding qwen36/}/qwen36
|
||||
Q3=$M/Qwen3.6-35B-A3B-UD-Q3_K_M.gguf; IQ4=$M/Qwen3.6-35B-A3B-UD-IQ4_XS.gguf
|
||||
run() { n=$1; shift; d=$R/$n; mkdir -p $d; echo "$*" > $d/command.sh; timeout 3600 "$@" > $d/stdout.txt 2> $d/stderr.txt; echo $? > $d/exit.txt; echo "$n: exit $(cat $d/exit.txt), $(wc -l < $d/stdout.txt) stdout lines"; }
|
||||
B=$PWD/build/bin
|
||||
run poly_route_test $B/poly_route_test
|
||||
run poly_norm_q8_test $B/poly_norm_q8_test
|
||||
run poly_gemm_small_test $B/poly_gemm_small_test
|
||||
run poly_attend_test $B/poly_attend_test
|
||||
run poly_expert_parity_q3km $B/poly_expert_parity $Q3
|
||||
run poly_expert_parity_iq4xs $B/poly_expert_parity $IQ4
|
||||
run poly_draft_race_test_q3km $B/poly_draft_race_test $Q3
|
||||
echo ALL_DONE
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Configuration B arms (CORRECTNESS-PLAN.md 3.3): a fresh strata-poly process per sequence, teacher-forced on the
|
||||
reference answer, top-20 probabilities per step. poly-run.py <file-tag> <gguf> <arm> [seq ...]
|
||||
arms: base = --tail-skip 0 --no-draft --lookup 0 --window 1 (arm 1)
|
||||
draft = --tail-skip 0 (draft block, lookup 3, window 8 defaults) (arm 2; top.txt must equal base's bytes)
|
||||
kvq8 = base + --kv q8_0 (arm 3)
|
||||
pb512 = base + --prompt-batch 512 (3.3 last paragraph, step 0 only)
|
||||
Writes poly/<file-tag>/<arm>/<seq>.top.txt, .ids.txt, .log, command.sh."""
|
||||
import os, pathlib, subprocess, sys, time
|
||||
# US2_CORR_ROOT / US2_POLY: another model's root and engine binary (DeepSeek, GLM: 2026-10-19)
|
||||
ROOT = pathlib.Path(os.environ.get('US2_CORR_ROOT', pathlib.Path.home() / 'us2-results/correctness'))
|
||||
EXE = pathlib.Path(os.environ.get('US2_POLY', pathlib.Path.home() / 'us2-build/build/bin/strata-poly'))
|
||||
tag, gguf, arm = sys.argv[1], sys.argv[2], sys.argv[3]; only = set(sys.argv[4:])
|
||||
|
||||
def answer_path(p, seq, tag):
|
||||
"""The scored answer: the fixed one (<seq>.answer.ids, the real-text set) when it exists, else the reference
|
||||
model's own greedy answer <seq>.answer.<tag>.ids (a different file is a different model, so a different answer)."""
|
||||
fixed = p.parent / f'{seq}.answer.ids'
|
||||
return fixed if fixed.exists() else p.parent / f'{seq}.answer.{tag}.ids'
|
||||
ARMS = {'base': ['--tail-skip', '0', '--no-draft', '--lookup', '0', '--window', '1'],
|
||||
'draft': ['--tail-skip', '0'],
|
||||
'kvq8': ['--tail-skip', '0', '--no-draft', '--lookup', '0', '--window', '1', '--kv', 'q8_0'],
|
||||
'pb512': ['--tail-skip', '0', '--no-draft', '--lookup', '0', '--window', '1', '--prompt-batch', '512']}
|
||||
OUT = ROOT / 'poly' / tag / arm; OUT.mkdir(parents=True, exist_ok=True)
|
||||
env = dict(os.environ, STRATA_FREEZE_EXPERTS='1')
|
||||
for p in sorted(ROOT.glob('inputs/*/*.prompt.ids')):
|
||||
seq = p.name[:-len('.prompt.ids')]
|
||||
if only and seq not in only: continue
|
||||
ans_path = answer_path(p, seq, tag)
|
||||
if not ans_path.exists(): print(f'{seq}: no answer ids yet (reference GPU run missing)', flush=True); continue
|
||||
prompt = p.read_text().strip(); ans = ans_path.read_text().strip()
|
||||
n = len(ans.split(','))
|
||||
cmd = [str(EXE), '--model', gguf, '--max-context', '32768'] + ARMS[arm] + \
|
||||
['--tokens', f'@{p}', '--follow', f'@{ans_path}', '--max-new', str(n), '--top-probs', '20']
|
||||
t0 = time.time()
|
||||
try:
|
||||
with open(OUT / f'{seq}.top.txt', 'w') as err, open(OUT / f'{seq}.ids.txt', 'w') as out:
|
||||
r = subprocess.run(cmd, env=env, stdout=out, stderr=err)
|
||||
except OSError as e: # E2BIG: a 31K-id --tokens argument is over Linux's 128 KiB single-argument limit
|
||||
print(f'{p.parent.name}/{seq} {arm}: cannot exec ({e}); the id list needs a file option', flush=True)
|
||||
(OUT / f'{seq}.log').write_text(f'not run: {e}\n'); continue
|
||||
with open(OUT / 'command.sh', 'a') as f:
|
||||
f.write('STRATA_FREEZE_EXPERTS=1 ' + ' '.join(cmd) + '\n')
|
||||
# top lines go to stderr with the engine's log; keep the log lines apart from the top lines
|
||||
raw = (OUT / f'{seq}.top.txt').read_text().splitlines()
|
||||
(OUT / f'{seq}.log').write_text('\n'.join(l for l in raw if not l.startswith('top ')) + '\n')
|
||||
(OUT / f'{seq}.top.txt').write_text('\n'.join(l for l in raw if l.startswith('top ')) + '\n')
|
||||
steps = sum(1 for l in raw if l.startswith('top '))
|
||||
print(f'{p.parent.name}/{seq} {arm}: exit {r.returncode}, {steps} steps ({n} wanted), {time.time()-t0:.0f} s', flush=True)
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Re-align strata/<arm>/<seq>.pos.tsv rows to the reference answer (answer[k:], k in 0..3) -> .scored.tsv + .offset.txt.
|
||||
realign.py <arm> [seq ...]"""
|
||||
import pathlib, sys
|
||||
ROOT = pathlib.Path.home() / 'us2-results/correctness'
|
||||
arm = sys.argv[1]; only = set(sys.argv[2:])
|
||||
def answer_path(p, seq):
|
||||
fixed = p.parent / f'{seq}.answer.ids'
|
||||
return fixed if fixed.exists() else p.parent / f'{seq}.answer.flash-next.ids'
|
||||
for p in sorted(ROOT.glob('inputs/*/*.prompt.ids')):
|
||||
seq = p.name[:-len('.prompt.ids')]
|
||||
if only and seq not in only: continue
|
||||
pos = ROOT / 'strata' / arm / f'{seq}.pos.tsv'
|
||||
if not pos.exists(): continue
|
||||
ans = list(map(int, answer_path(p, seq).read_text().strip().split(',')))
|
||||
rows = [l.rstrip('\n').split('\t') for l in open(pos)]
|
||||
tg = [int(r[1]) for r in rows]
|
||||
start = None
|
||||
for k in range(4):
|
||||
a = ans[k:]
|
||||
start = next((i for i in range(len(tg) - len(a) + 1) if tg[i:i + len(a)] == a), None)
|
||||
if start is not None: break
|
||||
if start is None: print(f'{seq}: {len(rows)} rows, no match'); continue
|
||||
(pos.with_name(f'{seq}.scored.tsv')).write_text('\n'.join('\t'.join(r) for r in rows[start:start + len(ans) - k]) + '\n')
|
||||
(pos.with_name(f'{seq}.offset.txt')).write_text(f'{k}\n')
|
||||
print(f'{seq}: {len(rows)} rows, answer[{k}:] at row {start} (pos {rows[start][0]}), {len(ans) - k} scored')
|
||||
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Reference runs (CORRECTNESS-PLAN.md 3.1): llama.cpp 3cf03257 CUDA build, tools/qwen35/q36_llama_dump.
|
||||
ref-run.py <model-tag> <gguf> gpu|cpu [seq ...]
|
||||
gpu: --ngl 99, greedy for n_answer steps (or --force on a given answer), writes <seq>.gpu.full + <seq>.gpu.gen.txt and
|
||||
inputs/<set>/<seq>.answer.ids when the set has none (the GPU run's own greedy answer).
|
||||
cpu: --ngl 0, --force on the answer, writes <seq>.cpu.full.
|
||||
Full logits are f32 [steps][vocab]; every run also gets <seq>.<mode>.log (stderr) and command.sh."""
|
||||
import hashlib, json, os, pathlib, subprocess, sys, time
|
||||
# US2_CORR_ROOT / US2_DUMP: another model's root and reference build (DeepSeek, GLM: 2026-10-19)
|
||||
ROOT = pathlib.Path(os.environ.get('US2_CORR_ROOT', pathlib.Path.home() / 'us2-results/correctness'))
|
||||
DUMP = pathlib.Path(os.environ.get('US2_DUMP', pathlib.Path.home() / 'llamacpp-ref/tools/q36_llama_dump'))
|
||||
tag, gguf, mode = sys.argv[1], sys.argv[2], sys.argv[3]
|
||||
only = set(sys.argv[4:])
|
||||
|
||||
def answer_path(p, seq, tag):
|
||||
"""The scored answer: the fixed one (<seq>.answer.ids, the real-text set) when it exists, else the reference
|
||||
model's own greedy answer <seq>.answer.<tag>.ids (a different file is a different model, so a different answer)."""
|
||||
fixed = p.parent / f'{seq}.answer.ids'
|
||||
return fixed if fixed.exists() else p.parent / f'{seq}.answer.{tag}.ids'
|
||||
OUT = ROOT / 'reference' / tag; OUT.mkdir(parents=True, exist_ok=True)
|
||||
seqs = sorted(ROOT.glob('inputs/*/*.prompt.ids'))
|
||||
for p in seqs:
|
||||
seq = p.name[:-len('.prompt.ids')]; setname = p.parent.name
|
||||
if only and seq not in only: continue
|
||||
meta = json.load(open(p.parent / f'{seq}.json'))
|
||||
prompt = p.read_text().strip()
|
||||
ans_path = answer_path(p, seq, tag)
|
||||
n = meta['n_answer']
|
||||
nctx = ((meta['prompt_tokens'] + n + 8 + 255) // 256) * 256
|
||||
env = dict(os.environ, STRATA_DUMP_CTX=str(nctx))
|
||||
cmd = [str(DUMP), '--model', gguf, '--tokens', f'@{p}', '--ngl', '99' if mode == 'gpu' else '0',
|
||||
'--dump-full-logits', str(OUT / f'{seq}.{mode}.full')]
|
||||
if mode == 'cpu' or ans_path.exists():
|
||||
ans = ans_path.read_text().strip().split(',')
|
||||
# --force N ids runs N+1 steps; the engines score N steps, so force all but the last and let step N be greedy
|
||||
forced = OUT / f'{seq}.force.ids'; forced.write_text(','.join(ans[:-1]) + '\n')
|
||||
cmd += ['--force', f'@{forced}']
|
||||
else:
|
||||
cmd += ['--n', str(n)]
|
||||
t0 = time.time()
|
||||
# errors='replace': the DeepSeek vocabulary's pieces are not all valid UTF-8 in llama.cpp's load log (2026-10-19)
|
||||
r = subprocess.run(cmd, env=env, capture_output=True, text=True, errors='replace')
|
||||
dt = time.time() - t0
|
||||
(OUT / f'{seq}.{mode}.log').write_text(r.stderr)
|
||||
with open(OUT / 'command.sh', 'a') as f:
|
||||
f.write(f'STRATA_DUMP_CTX={nctx} ' + ' '.join(cmd) + '\n')
|
||||
if r.returncode != 0:
|
||||
print(f'{setname}/{seq} {mode}: EXIT {r.returncode} after {dt:.0f} s; see {seq}.{mode}.log', flush=True); continue
|
||||
gen = [l for l in r.stdout.splitlines() if l.startswith('gen:')][0].split()[1:]
|
||||
(OUT / f'{seq}.{mode}.gen.txt').write_text(','.join(gen) + '\n')
|
||||
if mode == 'gpu' and not ans_path.exists():
|
||||
ans_path.write_text(','.join(gen[:n]) + '\n')
|
||||
full = OUT / f'{seq}.{mode}.full'
|
||||
sha = hashlib.sha256(full.read_bytes()).hexdigest()
|
||||
(OUT / f'{seq}.{mode}.full.sha256').write_text(f'{sha} {full.name}\n')
|
||||
print(f'{setname}/{seq} {mode}: {len(gen)} steps, nctx {nctx}, {dt:.0f} s, {full.stat().st_size/1e6:.0f} MB', flush=True)
|
||||
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Score every engine run that has both reference files. score-all.py <poly|strata> <tag-or-arm-root> ...
|
||||
poly: score-all.py poly <file-tag> <ref-tag> <arm> e.g. poly qwen36-q3km qwen36-q3km base
|
||||
strata: score-all.py strata <ref-tag> <arm> (ref-tag is the Flash-Next reference directory)
|
||||
Writes scores/<tag>/<arm>/<seq>.tsv + <seq>.json and summary.md (per set: steps, top-1, KL, floor, ratio, T1, T2)."""
|
||||
import json, os, pathlib, subprocess, sys
|
||||
ROOT = pathlib.Path(os.environ.get('US2_CORR_ROOT', pathlib.Path.home() / 'us2-results/correctness'))
|
||||
kind = sys.argv[1]
|
||||
if kind == 'poly':
|
||||
tag, ref, arm = sys.argv[2:5]; runs = ROOT / 'poly' / tag / arm; glob = '*.top.txt'; strip = '.top.txt'
|
||||
else:
|
||||
ref, arm = sys.argv[2:4]; tag = 'flash-next'; runs = ROOT / 'strata' / arm; glob = '*.scored.tsv'; strip = '.scored.tsv'
|
||||
out = ROOT / 'scores' / tag / arm; out.mkdir(parents=True, exist_ok=True)
|
||||
sets = {p.name[:-len('.prompt.ids')]: p.parent.name for p in ROOT.glob('inputs/*/*.prompt.ids')}
|
||||
rows = []
|
||||
for f in sorted(runs.glob(glob)):
|
||||
seq = f.name[:-len(strip)]
|
||||
g, c = ROOT / 'reference' / ref / f'{seq}.gpu.full', ROOT / 'reference' / ref / f'{seq}.cpu.full'
|
||||
if not (g.exists() and c.exists()): print(f'{seq}: reference incomplete'); continue
|
||||
cmd = ['python3', str(ROOT / 'score.py'), kind, str(g), str(c), str(f)] + (['0'] if kind == 'strata' else []) + [str(out / f'{seq}.tsv')]
|
||||
r = subprocess.run(cmd, capture_output=True, text=True)
|
||||
js = [l for l in r.stderr.splitlines() if l.startswith('{')]
|
||||
if not js: print(f'{seq}: scorer failed: {r.stderr[-300:]}'); continue
|
||||
s = json.loads(js[-1]); s['seq'] = seq; s['set'] = sets.get(seq, '?')
|
||||
(out / f'{seq}.json').write_text(json.dumps(s, indent=1) + '\n'); rows.append(s)
|
||||
print(f"{s['set']}/{seq}: {s['steps']} steps, top1 {s['top1_agree']:.3f} (floor {s['floor']['top1_agree']:.3f}), "
|
||||
f"KL {s['kl_top20_mean']:.5f} vs floor top20 {s['floor']['kl_top20_mean']:.5f} (x{s['t2_ratio_vs_top20_floor']:.2f}; full-vocab floor {s['floor']['kl_full_mean']:.5f}), "
|
||||
f"T1 {s['T1']} ({s['t1_positions']} positions, {len(s['t1_failures'])} fail), T2 {s['T2']}")
|
||||
# summary
|
||||
lines = [f'# Scores: {tag} / {arm} against reference {ref}', '',
|
||||
'| Set | Seq | Steps | Top-1 agree | Floor top-1 | KL top20 (mean / p99) | Floor KL top20 | Ratio | Floor KL full (mean / p99) | T1 (positions >= 0.5 nat / failures) | T2 |',
|
||||
'| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |']
|
||||
for s in sorted(rows, key=lambda s: (s['set'], s['seq'])):
|
||||
fl = s['floor']
|
||||
lines.append(f"| {s['set']} | {s['seq']} | {s['steps']} | {s['top1_agree']:.3f} | {fl['top1_agree']:.3f} | {s['kl_top20_mean']:.5f} / {s['kl_top20_p99']:.4f} | "
|
||||
f"{fl['kl_top20_mean']:.5f} | {s['t2_ratio_vs_top20_floor']:.2f} | {fl['kl_full_mean']:.5f} / {fl['kl_full_p99']:.4f} | {s['T1']} ({s['t1_positions']} / {len(s['t1_failures'])}) | {s['T2']} |")
|
||||
if rows:
|
||||
import statistics
|
||||
agg = {}
|
||||
for s in rows: agg.setdefault(s['set'], []).append(s)
|
||||
lines += ['', '## Per set (steps-weighted)', '', '| Set | Steps | Top-1 agree | Floor top-1 | KL top20 | Floor KL top20 | Ratio | T1 failures | T2 |', '| --- | --- | --- | --- | --- | --- | --- | --- | --- |']
|
||||
for k, v in sorted(agg.items()):
|
||||
n = sum(s['steps'] for s in v)
|
||||
w = lambda key, sub=None: sum((s[key] if sub is None else s[sub][key]) * s['steps'] for s in v) / n
|
||||
kl, flk = w('kl_top20_mean'), w('kl_top20_mean', 'floor')
|
||||
fails = sum(len(s['t1_failures']) for s in v)
|
||||
lines.append(f"| {k} | {n} | {w('top1_agree'):.3f} | {w('top1_agree','floor'):.3f} | {kl:.5f} | {flk:.5f} | {kl/flk if flk else float('nan'):.2f} | {fails} | {'pass' if kl <= 1.5*flk else 'FAIL'} |")
|
||||
fails = [(s['seq'], f) for s in rows for f in s['t1_failures']]
|
||||
lines += ['', f"T1 failures (seq, step, llama argmax, engine argmax, gap): {fails if fails else 'none'}"]
|
||||
(out / 'summary.md').write_text('\n'.join(lines) + '\n'); print('summary ->', out / 'summary.md')
|
||||
@@ -0,0 +1,118 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Scorer (CORRECTNESS-PLAN.md 3.3, 3.4, 3.6). Per position: llama.cpp GPU argmax, its top-2 gap (nats), the engine's
|
||||
argmax and whether it agrees, top-20 overlap, KL(P || Q) with P = llama.cpp GPU over its top 20 + one bucket for the
|
||||
rest, Q = the engine's printed top 20 (+ rest = 1 - sum). The floor on the same positions: KL(GPU || CPU) over the full
|
||||
vocabulary and, for a like-for-like figure, over the same top-20 + rest bucket.
|
||||
|
||||
score.py floor <gpu.full> <cpu.full> -> one line of JSON
|
||||
score.py poly <gpu.full> <cpu.full> <top.txt> [out.tsv] -> per-step TSV (stdout or file) + summary JSON on stderr
|
||||
score.py strata <gpu.full> <cpu.full> <pos.tsv> <first_pos> [out.tsv] (pos.tsv rows whose position >= first_pos, in order)
|
||||
|
||||
Q for an id in P's top 20 that the engine did not print: the engine's rest mass spread evenly over those ids plus
|
||||
the rest bucket (an upper bound on each missing id's probability is the engine's 20th probability; the spread is
|
||||
used, and the number of such ids is reported as 'missing').
|
||||
T1 gate: argmax equal at every position with gap >= 0.5. T2 gate: mean KL <= 1.5 x floor (full-vocab) on the positions."""
|
||||
import json, os, sys
|
||||
import numpy as np
|
||||
|
||||
V = int(os.environ.get('US2_VOCAB', 248320)) # Qwen 248320; DeepSeek V4 Flash 129280; GLM 5.3 Flash 154880
|
||||
|
||||
def load_full(path):
|
||||
a = np.fromfile(path, dtype=np.float32)
|
||||
assert a.size % V == 0, (path, a.size)
|
||||
return a.reshape(-1, V).astype(np.float64)
|
||||
|
||||
def logsoftmax(row):
|
||||
m = row.max(); return row - (m + np.log(np.exp(row - m).sum()))
|
||||
|
||||
def topk_dist(lp, k=20):
|
||||
idx = np.argpartition(-lp, k)[:k]; idx = idx[np.argsort(-lp[idx])]
|
||||
return idx, np.exp(lp[idx])
|
||||
|
||||
def kl_bucketed(p_idx, p_prob, q_map, q_rest):
|
||||
"""P over its top-20 + rest; Q from a dict id->prob plus its rest mass."""
|
||||
missing = [i for i in p_idx if int(i) not in q_map]
|
||||
share = q_rest / (len(missing) + 1) if missing else q_rest
|
||||
kl = 0.0; q_used = 0.0
|
||||
for i, p in zip(p_idx, p_prob):
|
||||
q = q_map.get(int(i), share); q_used += q
|
||||
kl += p * np.log(p / max(q, 1e-300))
|
||||
p_rest = max(1.0 - p_prob.sum(), 1e-300); q_rest_b = max(1.0 - q_used, 1e-300)
|
||||
kl += p_rest * np.log(p_rest / q_rest_b)
|
||||
return kl, len(missing)
|
||||
|
||||
def floor(gpu, cpu):
|
||||
n = min(len(gpu), len(cpu)); kls = []; kl_b = []; agree = 0
|
||||
for s in range(n):
|
||||
lp = logsoftmax(gpu[s]); lq = logsoftmax(cpu[s])
|
||||
kls.append(float((np.exp(lp) * (lp - lq)).sum()))
|
||||
agree += int(lp.argmax() == lq.argmax())
|
||||
pi, pp = topk_dist(lp); qi, qp = topk_dist(lq)
|
||||
k, _ = kl_bucketed(pi, pp, dict(zip(map(int, qi), qp)), 1.0 - qp.sum()); kl_b.append(k)
|
||||
return dict(steps=n, kl_full_mean=float(np.mean(kls)), kl_full_p99=float(np.percentile(kls, 99)),
|
||||
kl_top20_mean=float(np.mean(kl_b)), top1_agree=agree / n)
|
||||
|
||||
def read_engine(kind, path, first_pos=0):
|
||||
"""-> list of (engine_argmax, {id: prob}) per scored step, in order."""
|
||||
out = []
|
||||
for line in open(path):
|
||||
if kind == 'poly':
|
||||
if not line.startswith('top '): continue
|
||||
pairs = [t.split(':') for t in line.split()[1:]]
|
||||
m = {int(i): float(p) for i, p in pairs}
|
||||
else:
|
||||
f = line.rstrip('\n').split('\t')
|
||||
if len(f) < 9 or int(f[0]) < first_pos: continue
|
||||
m = {int(t.split(':')[0]): float(np.exp(float(t.split(':')[1]))) for t in f[8:]}
|
||||
top = max(m, key=m.get)
|
||||
out.append((top, m))
|
||||
return out
|
||||
|
||||
def score(gpu, cpu, eng, out, label):
|
||||
n = min(len(gpu), len(eng))
|
||||
if len(eng) != len(gpu): print(f'note: {len(gpu)} reference steps, {len(eng)} engine steps; scoring {n}', file=sys.stderr)
|
||||
fl = floor(gpu[:n], cpu[:n])
|
||||
rows = []; kls = []; agree = 0; t1_pos = 0; t1_fail = []; overlaps = []; missing_total = 0
|
||||
for s in range(n):
|
||||
lp = logsoftmax(gpu[s]); pi, pp = topk_dist(lp)
|
||||
lq = logsoftmax(cpu[s]); qi, qp = topk_dist(lq)
|
||||
f_full = float((np.exp(lp) * (lp - lq)).sum())
|
||||
f_b, _ = kl_bucketed(pi, pp, dict(zip(map(int, qi), qp)), 1.0 - qp.sum())
|
||||
cpu_agree = int(lq.argmax() == pi[0])
|
||||
gap = float(lp[pi[0]] - lp[pi[1]])
|
||||
e_top, q = eng[s]
|
||||
kl, miss = kl_bucketed(pi, pp, q, 1.0 - sum(q.values())); missing_total += miss
|
||||
ov = len(set(map(int, pi)) & set(q)) / 20
|
||||
a = int(e_top == int(pi[0])); agree += a; kls.append(kl); overlaps.append(ov)
|
||||
if gap >= 0.5:
|
||||
t1_pos += 1
|
||||
if not a: t1_fail.append((s, int(pi[0]), e_top, gap))
|
||||
rows.append(f'{s}\t{int(pi[0])}\t{gap:.4f}\t{e_top}\t{a}\t{ov:.2f}\t{kl:.6f}\t{miss}\t{cpu_agree}\t{f_full:.6f}\t{f_b:.6f}')
|
||||
out.write('step\tllama_argmax\tllama_top2_gap\tengine_argmax\tagree\ttop20_overlap\tkl_top20\tmissing\tcpu_agree\tfloor_kl_full\tfloor_kl_top20\n' + '\n'.join(rows) + '\n')
|
||||
s = dict(label=label, steps=n, top1_agree=agree / n, kl_top20_mean=float(np.mean(kls)), kl_top20_p99=float(np.percentile(kls, 99)),
|
||||
top20_overlap_mean=float(np.mean(overlaps)), missing_ids=missing_total, t1_positions=t1_pos, t1_failures=t1_fail,
|
||||
floor=fl, t2_ratio_vs_full_floor=float(np.mean(kls)) / fl['kl_full_mean'] if fl['kl_full_mean'] > 0 else None,
|
||||
t2_ratio_vs_top20_floor=float(np.mean(kls)) / fl['kl_top20_mean'] if fl['kl_top20_mean'] > 0 else None)
|
||||
s['T1'] = 'pass' if not t1_fail else 'FAIL'
|
||||
# T2 like for like: the engine prints its top 20, so its KL is the bucketed one; the floor used for the gate is the
|
||||
# same bucketed KL between the two reference runs. The full-vocabulary floor is reported beside it.
|
||||
s['T2'] = 'pass' if s['t2_ratio_vs_top20_floor'] is not None and s['t2_ratio_vs_top20_floor'] <= 1.5 else 'FAIL'
|
||||
print(json.dumps(s), file=sys.stderr)
|
||||
|
||||
if __name__ == '__main__':
|
||||
mode = sys.argv[1]
|
||||
if mode == 'floor':
|
||||
print(json.dumps(floor(load_full(sys.argv[2]), load_full(sys.argv[3]))))
|
||||
elif mode == 'poly':
|
||||
gpu, cpu = load_full(sys.argv[2]), load_full(sys.argv[3]); eng = read_engine('poly', sys.argv[4])
|
||||
out = open(sys.argv[5], 'w') if len(sys.argv) > 5 else sys.stdout
|
||||
score(gpu, cpu, eng, out, sys.argv[4])
|
||||
elif mode == 'strata':
|
||||
gpu, cpu = load_full(sys.argv[2]), load_full(sys.argv[3]); eng = read_engine('strata', sys.argv[4], int(sys.argv[5]))
|
||||
# <seq>.offset.txt beside the scored rows: the rows start at reference step k (a resumed read loses step 0)
|
||||
import os
|
||||
off_path = sys.argv[4].replace('.scored.tsv', '.offset.txt')
|
||||
k = int(open(off_path).read().strip()) if os.path.exists(off_path) else 0
|
||||
if k: print(f'note: engine rows start at reference step {k}', file=sys.stderr)
|
||||
out = open(sys.argv[6], 'w') if len(sys.argv) > 6 else sys.stdout
|
||||
score(gpu[k:], cpu[k:], eng, out, sys.argv[4])
|
||||
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Configuration A arms (CORRECTNESS-PLAN.md 3.4) on the A6000 VM: a fresh `strata --serve` per sequence, the whole
|
||||
sequence (prompt + reference answer) sent as one GEN 1 request, STRATA_LOGPOS scoring every position read through the
|
||||
verify windows (--short-read covers the sequence). strata-run.py <arm> [seq ...]
|
||||
arms: fp16 = --kv fp16, suffix drafter on (arm 1)
|
||||
t4 = fp16 + --suffix-draft 0 (arm 2; pos.tsv log-probabilities must equal arm 1's)
|
||||
int8 = --kv int8 (arm 3)
|
||||
int8str = --kv int8 --kv-resident 20480 --short-read 1024, the 31K sequence (arm 4; equals arm 3 on those rows)
|
||||
pf512 = fp16 + --prefill 512 --short-read 512 on the long set (arm 5, chunk effect)
|
||||
pin = fp16 + --expert-cache 24380 (the GPU expert cache pinned to one slot count; see below)
|
||||
pin2 = pin again, a second process (T0: the same bytes from the same placement)
|
||||
pint4 = pin + --suffix-draft 0 (T0: the window size, with the placement held)
|
||||
pincpu = pin + --pcie-frac 0 (every missed expert computed on the CPU, the AVX-2 kernels: the CPU tier arm)
|
||||
pingpu = pin + --pcie-frac 1 (every missed expert fetched over PCIe and computed on the GPU)
|
||||
On this VM the expert set does NOT fit the card even with --resident-experts (48 GB): the engine keeps 24380-24576
|
||||
GPU cache slots (--expert-cache auto, sized from the free VRAM at start, so it varies by a few hundred slots from one
|
||||
process to the next) and a 3.4-3.7 GiB complement in page-locked RAM, whose misses are split between PCIe (GPU
|
||||
arithmetic) and the CPU pool (--pcie-frac 0.55: 45 % on the CPU, which rounds an expert differently, docs/DETAILS.md
|
||||
#410). So the bits depend on the slot count: two processes with different counts differ (fp16 vs t4, 2026-10-18);
|
||||
the pin* arms hold the count (--expert-cache 24380 in max-blob units came out as every expert, 24576; with all of
|
||||
them on the card no decode miss happens and pin = pin2 = pint4 = pincpu = pingpu bitwise, 2026-10-18).
|
||||
cpu = fp16 + --expert-cache 16000 --pcie-frac 0: a fixed, smaller cache (about 13 % of the experts left in
|
||||
RAM), every miss computed on the CPU (AVX-2 kernels): the CPU tier arm, deterministic placement
|
||||
cpu2 = cpu again, a second process (T0: the CPU tier repeats)
|
||||
pcie = fp16 + --expert-cache 16000 --pcie-frac 1: the same placement, every miss fetched over PCIe and
|
||||
computed on the GPU (T0 against pin: a fetched expert equals a cached one) Writes strata/<arm>/<seq>.pos.tsv, .scored.tsv (rows aligned to the answer),
|
||||
.engine.log, .done.txt, command.sh."""
|
||||
import os, pathlib, subprocess, sys, time
|
||||
# Paths (the defaults are the homelab VM's; set them for another machine): US2_MODELS, the directory holding
|
||||
# qwen36/<file>.gguf (required); US2_BUILD, the UnbiasedStrata tree with build/bin (default: this script's
|
||||
# repository); US2_RESULTS, where results go (default ~/us2-results/correctness).
|
||||
def _models():
|
||||
m = os.environ.get('US2_MODELS')
|
||||
if not m:
|
||||
sys.exit('set US2_MODELS to the directory holding qwen36/')
|
||||
return pathlib.Path(m)
|
||||
BUILD = pathlib.Path(os.environ.get('US2_BUILD') or pathlib.Path(__file__).resolve().parents[2])
|
||||
ROOT = pathlib.Path(os.environ.get('US2_RESULTS') or pathlib.Path.home() / 'us2-results/correctness')
|
||||
sys.path.insert(0, str(BUILD / 'tools/qwen35'))
|
||||
from q36_harness import Eng
|
||||
EXE = str(BUILD / 'build/bin/strata')
|
||||
M = str(_models())
|
||||
BASE = ['--pack', f'{M}/pack-iq3-xxs', '--native', f'{M}/IQ3_XXS/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00001-of-00002.gguf',
|
||||
'--ple-gguf', f'{M}/IQ3_XXS/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00002-of-00002.gguf',
|
||||
'--expert-profile', f'{M}/pack-iq3-xxs/expert-profile.bin', '--resident-experts', '--prefill', 'auto',
|
||||
'--spec', '4', '--spec-min-p', '0.5', '--mtp', f'{M}/mtp', '--max-context', '65536', '--ple-io', 'mmap',
|
||||
'--prompt-cache', '0', '--adapt-every', '0', '--pcie-frac', '0.55']
|
||||
ARMS = {'fp16': (['--kv', 'fp16', '--short-read', '4096'], None),
|
||||
't4': (['--kv', 'fp16', '--short-read', '4096', '--suffix-draft', '0'], None),
|
||||
'int8': (['--kv', 'int8', '--short-read', '4096'], None),
|
||||
'int8str': (['--kv', 'int8', '--kv-resident', '20480', '--short-read', '1024'], {'d31k'}),
|
||||
'pf512': (['--kv', 'fp16', '--prefill', '512', '--short-read', '512'], {'d4k', 'd16k', 'd31k', 'r16k'}),
|
||||
'pin': (['--kv', 'fp16', '--short-read', '4096', '--expert-cache', '24380'], None),
|
||||
'pin2': (['--kv', 'fp16', '--short-read', '4096', '--expert-cache', '24380'], {'p00', 'p01', 'lru', 'puzzle', 'd4k'}),
|
||||
'pint4': (['--kv', 'fp16', '--short-read', '4096', '--expert-cache', '24380', '--suffix-draft', '0'], {'p00', 'p01', 'lru', 'puzzle', 'd4k'}),
|
||||
'pincpu': (['--kv', 'fp16', '--short-read', '4096', '--expert-cache', '24380', '--pcie-frac', '0'], None),
|
||||
'pingpu': (['--kv', 'fp16', '--short-read', '4096', '--expert-cache', '24380', '--pcie-frac', '1'], {'p00', 'p01', 'lru', 'puzzle', 'd4k'}),
|
||||
'cpu': (['--kv', 'fp16', '--short-read', '4096', '--expert-cache', '16000', '--pcie-frac', '0'], None),
|
||||
'cpu2': (['--kv', 'fp16', '--short-read', '4096', '--expert-cache', '16000', '--pcie-frac', '0'], {'p00', 'p01', 'lru', 'puzzle', 'd4k'}),
|
||||
'pcie': (['--kv', 'fp16', '--short-read', '4096', '--expert-cache', '16000', '--pcie-frac', '1'], {'p00', 'p01', 'lru', 'puzzle', 'd4k'})}
|
||||
arm = sys.argv[1]; only = set(sys.argv[2:])
|
||||
REF_TAG = 'flash-next'
|
||||
|
||||
def answer_path(p, seq, tag):
|
||||
"""The scored answer: the fixed one (<seq>.answer.ids, the real-text set) when it exists, else the reference
|
||||
model's own greedy answer <seq>.answer.<tag>.ids (a different file is a different model, so a different answer)."""
|
||||
fixed = p.parent / f'{seq}.answer.ids'
|
||||
return fixed if fixed.exists() else p.parent / f'{seq}.answer.{tag}.ids'
|
||||
flags, default_seqs = ARMS[arm]
|
||||
OUT = ROOT / 'strata' / arm; OUT.mkdir(parents=True, exist_ok=True)
|
||||
for p in sorted(ROOT.glob('inputs/*/*.prompt.ids')):
|
||||
seq = p.name[:-len('.prompt.ids')]
|
||||
if only and seq not in only: continue
|
||||
if not only and default_seqs and seq not in default_seqs: continue
|
||||
ans_path = answer_path(p, seq, REF_TAG)
|
||||
if not ans_path.exists(): print(f'{seq}: no answer ids', flush=True); continue
|
||||
prompt = list(map(int, p.read_text().strip().split(','))); ans = list(map(int, ans_path.read_text().strip().split(',')))
|
||||
pos = OUT / f'{seq}.pos.tsv'
|
||||
env = {'STRATA_LOGPOS': str(pos), 'STRATA_LOGPOS_TOPK': '20', 'STRATA_ROUTE_TAIL_SKIP': '0', 'STRATA_PREFILL_CPU_SHARE': '0',
|
||||
'STRATA_IQ_MT_MIN': '1', 'CUDA_MODULE_LOADING': 'EAGER'}
|
||||
args = BASE + flags
|
||||
# --short-read N sends a fresh read through the verify windows only when the WHOLE read is at most N tokens (one
|
||||
# part per text request: generate.cpp windows_ok); a longer read goes through the batched prompt path and writes
|
||||
# no LOGPOS rows. So a sequence longer than N is sent as two requests: the prompt alone (read batched, kept as a
|
||||
# conversation checkpoint: --prompt-cache 1), then prompt + answer, which resumes and reads only the answer through
|
||||
# the windows. That is also how a chat reaches the answer positions: the document through the prompt path, the
|
||||
# answer through the windows.
|
||||
short_read = int(args[args.index('--short-read') + 1])
|
||||
two_requests = len(prompt) + len(ans) > short_read
|
||||
if two_requests:
|
||||
i = args.index('--prompt-cache'); args[i + 1] = '1'
|
||||
with open(OUT / 'command.sh', 'a') as f:
|
||||
f.write(' '.join(f'{k}={v}' for k, v in env.items()) + f' {EXE} --serve ' + ' '.join(args) +
|
||||
(f' # GEN 1 $(cat {p}); then ' if two_requests else ' # ') + f'GEN 1 $(cat {p}),$(cat {ans_path})\n')
|
||||
t0 = time.time()
|
||||
try:
|
||||
e = Eng(EXE, args, env=env, log=str(OUT / f'{seq}.engine.log'))
|
||||
if two_requests:
|
||||
e.solo(prompt, 1)
|
||||
toks, done, ttft, wall = e.solo(prompt + ans, 1)
|
||||
e.send('QUIT'); e.p.wait(timeout=120)
|
||||
except SystemExit as ex:
|
||||
print(f'{p.parent.name}/{seq} {arm}: FAILED {ex}', flush=True); continue
|
||||
(OUT / f'{seq}.done.txt').write_text(done + '\n')
|
||||
# align: the rows whose target ids are the answer, in order
|
||||
rows = [l.rstrip('\n').split('\t') for l in open(pos)] if pos.exists() else []
|
||||
# a resumed read (two requests) starts after the prompt's last token, whose logits the first request consumed: the
|
||||
# rows then target answer[1:], so the match is tried from answer[k:] and k is written beside the rows (step offset)
|
||||
tg = [int(r[1]) for r in rows]
|
||||
start = k = None
|
||||
for k in range(4):
|
||||
a = ans[k:]
|
||||
start = next((i for i in range(len(tg) - len(a) + 1) if tg[i:i + len(a)] == a), None)
|
||||
if start is not None: break
|
||||
if start is None:
|
||||
print(f'{p.parent.name}/{seq} {arm}: {len(rows)} LOGPOS rows, answer not found in the targets; load {e.load_s:.0f} s', flush=True); continue
|
||||
(OUT / f'{seq}.scored.tsv').write_text('\n'.join('\t'.join(r) for r in rows[start:start + len(ans) - k]) + '\n')
|
||||
(OUT / f'{seq}.offset.txt').write_text(f'{k}\n')
|
||||
print(f'{p.parent.name}/{seq} {arm}: {len(rows)} rows, answer[{k}:] at row {start} (pos {rows[start][0]}), load {e.load_s:.0f} s, request {wall:.0f} s, {done}', flush=True)
|
||||
@@ -0,0 +1,284 @@
|
||||
// Standalone HIP INT8 QSA query-LDS-swizzle component probe.
|
||||
// Adapted from the cell-probability probe; input generation and full-byte dump are unchanged.
|
||||
// Build/link in the project with strata_kernels + hip::host (or its HIP runtime target).
|
||||
// Usage: gfx906_qsa_query_swizzle_probe [nq=32] [ctx=65536] [reps=20] [output.bin] [--masked-pages]
|
||||
// Output path may instead be supplied by STRATA_QSA_PROBE_OUT. It is required.
|
||||
// Run candidate environment settings in SEPARATE processes: the dispatcher caches them.
|
||||
// No prompt-attention entry point, architecture skip, model loading, or repository writes.
|
||||
#include "strata/kernels/qsa.hpp"
|
||||
#include "strata/kernels/qsa_decode_attn.hpp"
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cerrno>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
#include <limits>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
namespace k = strata::kernels;
|
||||
namespace {
|
||||
constexpr int64_t kBatch = 32;
|
||||
constexpr size_t kGuard = 64;
|
||||
constexpr uint64_t kSeed = 0x7161736150524f42ull;
|
||||
|
||||
[[noreturn]] void fail(const char* why) {
|
||||
std::fprintf(stderr, "qsa_query_swizzle_probe: %s\n", why);
|
||||
std::exit(2);
|
||||
}
|
||||
void ck(hipError_t e, const char* what) {
|
||||
if (e != hipSuccess) {
|
||||
std::fprintf(stderr, "%s: %s\n", what, hipGetErrorString(e));
|
||||
std::exit(2);
|
||||
}
|
||||
}
|
||||
#define HIP_CHECK(x) ck((x), #x)
|
||||
|
||||
// Fixed integer generator and exact binary fractions avoid library-dependent
|
||||
// normal distributions and never inspect the candidate environment setting.
|
||||
struct Rng {
|
||||
uint64_t state = kSeed;
|
||||
uint32_t next() {
|
||||
state ^= state >> 12;
|
||||
state ^= state << 25;
|
||||
state ^= state >> 27;
|
||||
return uint32_t((state * 2685821657736338717ull) >> 32);
|
||||
}
|
||||
size_t below(size_t n) { return size_t(next()) % n; }
|
||||
template <class T> void shuffle(std::vector<T>& v) {
|
||||
for (size_t n = v.size(); n > 1; --n) std::swap(v[n - 1], v[below(n)]);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T> struct Device {
|
||||
T* p = nullptr;
|
||||
explicit Device(size_t n) { HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&p), n * sizeof(T))); }
|
||||
explicit Device(const std::vector<T>& v) : Device(v.size()) {
|
||||
HIP_CHECK(hipMemcpy(p, v.data(), v.size() * sizeof(T), hipMemcpyHostToDevice));
|
||||
}
|
||||
~Device() { if (p) (void) hipFree(p); }
|
||||
Device(const Device&) = delete;
|
||||
Device& operator=(const Device&) = delete;
|
||||
};
|
||||
|
||||
uint64_t hash_bytes(uint64_t hash, const void* ptr, size_t bytes) {
|
||||
const auto* p = static_cast<const unsigned char*>(ptr);
|
||||
for (size_t i = 0; i < bytes; ++i) hash = (hash ^ p[i]) * 1099511628211ull;
|
||||
return hash;
|
||||
}
|
||||
template <class T> void hash_vector(uint64_t& hash, const std::vector<T>& v) {
|
||||
hash = hash_bytes(hash, v.data(), v.size() * sizeof(T));
|
||||
}
|
||||
int64_t positive(const char* text) {
|
||||
errno = 0;
|
||||
char* end = nullptr;
|
||||
const long long n = std::strtoll(text, &end, 10);
|
||||
if (errno || end == text || *end || n <= 0 || n > INT32_MAX)
|
||||
fail("nq, ctx, and reps must be positive int32 values");
|
||||
return int64_t(n);
|
||||
}
|
||||
const char* env(const char* name) {
|
||||
const char* value = std::getenv(name);
|
||||
return value ? value : "<unset>";
|
||||
}
|
||||
|
||||
std::vector<float> read_checked(const Device<float>& storage, size_t count) {
|
||||
std::vector<float> host(count + 2 * kGuard);
|
||||
HIP_CHECK(hipMemcpy(host.data(), storage.p, host.size() * sizeof(float), hipMemcpyDeviceToHost));
|
||||
for (size_t i = 0; i < host.size(); ++i) {
|
||||
if (i >= kGuard && i < kGuard + count) {
|
||||
if (!std::isfinite(host[i])) {
|
||||
std::fprintf(stderr, "nonfinite or unwritten output at float %zu\n", i - kGuard);
|
||||
fail("output check failed");
|
||||
}
|
||||
} else {
|
||||
uint32_t bits;
|
||||
std::memcpy(&bits, &host[i], sizeof(bits));
|
||||
if (bits != UINT32_MAX) fail("output guard changed");
|
||||
}
|
||||
}
|
||||
return std::vector<float>(host.begin() + kGuard, host.begin() + kGuard + count);
|
||||
}
|
||||
|
||||
int run(int64_t nq, int64_t ctx, int reps, const char* output, bool masked) {
|
||||
if (ctx < nq) fail("ctx must be >= nq (query positions are ctx-nq through ctx-1)");
|
||||
const char* lane = std::getenv("STRATA_ATTN_LANECELL");
|
||||
if (lane && lane[0] == '1') fail("unset STRATA_ATTN_LANECELL or set it to 0 for this probe");
|
||||
static_assert(sizeof(float) == 4 && std::numeric_limits<float>::is_iec559,
|
||||
"probe requires IEEE binary32 output");
|
||||
const k::QsaShapes s = k::qsa_real_shapes();
|
||||
// Match prefill.cpp: use the model's actual 4-cell page layout.
|
||||
if (s.n_head != 24 || s.n_head_kv != 2 || s.head_dim != 256 || s.page_size != 4)
|
||||
fail("unexpected model geometry");
|
||||
const int64_t hd = s.head_dim, nh = s.n_head, nkvh = s.n_head_kv, ps = s.page_size;
|
||||
const int64_t pages = (ctx + ps - 1) / ps, rows = pages * nkvh * ps;
|
||||
const int64_t cap = k::qsa_selection_width(ctx, s);
|
||||
const size_t count = size_t(nq) * size_t(nh * hd);
|
||||
Rng rng;
|
||||
std::vector<int8_t> kq(size_t(rows * hd)), vq(kq.size());
|
||||
std::vector<uint16_t> ks(size_t(rows * (hd / 64))), vs(ks.size());
|
||||
for (auto* v : {&kq, &vq})
|
||||
for (auto& x : *v) x = int8_t(int(rng.next() % 255) - 127);
|
||||
// Positive finite binary16 scales, directly encoded: [2^-8, 2^-5).
|
||||
for (auto* v : {&ks, &vs})
|
||||
for (auto& x : *v) x = uint16_t(0x1c00u + rng.next() % 0x0c00u);
|
||||
std::vector<int32_t> table(size_t(pages), 0);
|
||||
std::iota(table.begin(), table.end(), 0);
|
||||
rng.shuffle(table);
|
||||
const auto physical = table;
|
||||
if (masked)
|
||||
for (int64_t page = 1; page < pages; page += 3) table[size_t(page)] = -1;
|
||||
|
||||
// The decode kernel reads ids[c0+t] only for t<n_here, and returns before
|
||||
// reading IDs for empty chunks. Unused row slots are nevertheless zeroed;
|
||||
// a final 64-cell initialized guard also avoids an exact allocation end.
|
||||
// cap remains the actual row stride; no per-row padding is passed as cap.
|
||||
std::vector<int32_t> ids(size_t(nq * cap) + kGuard, 0);
|
||||
std::vector<int32_t> steps(size_t(nq * k::kStepCount), 0);
|
||||
std::vector<float> query(count);
|
||||
for (auto& x : query) x = float(int(rng.next() % 4096) - 2048) * (1.0f / 1024.0f);
|
||||
std::vector<int32_t> old_cells;
|
||||
for (int64_t i = 0; i < nq; ++i) {
|
||||
const int64_t pos = ctx - nq + i, nkv = pos + 1;
|
||||
const int64_t width = k::qsa_selection_width(nkv, s);
|
||||
k::qsa_step_fill(steps.data() + i * k::kStepCount, pos, s);
|
||||
int32_t* sel = ids.data() + i * cap;
|
||||
if (width == nkv) {
|
||||
std::iota(sel, sel + width, 0);
|
||||
} else {
|
||||
// Same selection pattern as qsa_prompt_attn_parity: a recent
|
||||
// 512-cell window plus a sorted older set drifting ~3% per query.
|
||||
constexpr int64_t recent = 512;
|
||||
const int64_t older = width - recent;
|
||||
if (int64_t(old_cells.size()) != older) {
|
||||
std::vector<int32_t> all(size_t(nkv - recent), 0);
|
||||
std::iota(all.begin(), all.end(), 0);
|
||||
rng.shuffle(all);
|
||||
old_cells.assign(all.begin(), all.begin() + older);
|
||||
} else {
|
||||
for (int64_t r = 0; r < older / 32; ++r) {
|
||||
const int32_t cell = int32_t(rng.below(size_t(nkv - recent)));
|
||||
if (std::find(old_cells.begin(), old_cells.end(), cell) == old_cells.end())
|
||||
old_cells[rng.below(size_t(older))] = cell;
|
||||
}
|
||||
}
|
||||
std::copy(old_cells.begin(), old_cells.end(), sel);
|
||||
std::iota(sel + older, sel + width, int32_t(nkv - recent));
|
||||
std::sort(sel, sel + width);
|
||||
}
|
||||
bool valid_page = false;
|
||||
for (int64_t c = 0; c < width; ++c) {
|
||||
if (sel[c] < 0 || sel[c] >= nkv || (c && sel[c - 1] >= sel[c]))
|
||||
fail("selection must be unique, sorted, and causal");
|
||||
valid_page |= table[size_t(sel[c] / ps)] >= 0;
|
||||
}
|
||||
// Restore a selected logical page if necessary, never allow an
|
||||
// all-masked query to make a vacuous zero-output equality check pass.
|
||||
if (!valid_page) {
|
||||
const size_t page = size_t(sel[0] / ps);
|
||||
table[page] = physical[page];
|
||||
}
|
||||
}
|
||||
size_t masked_selected = 0;
|
||||
for (int64_t i = 0; i < nq; ++i)
|
||||
for (int32_t c = 0; c < steps[size_t(i * k::kStepCount + k::kStepWidth)]; ++c)
|
||||
masked_selected += table[size_t(ids[size_t(i * cap + c)] / ps)] < 0;
|
||||
uint64_t input_hash = 14695981039346656037ull;
|
||||
hash_vector(input_hash, kq); hash_vector(input_hash, vq);
|
||||
hash_vector(input_hash, ks); hash_vector(input_hash, vs);
|
||||
hash_vector(input_hash, table); hash_vector(input_hash, ids);
|
||||
hash_vector(input_hash, steps); hash_vector(input_hash, query);
|
||||
|
||||
Device<int8_t> dk(kq), dv(vq);
|
||||
Device<uint16_t> dks(ks), dvs(vs);
|
||||
Device<int32_t> dtable(table), dids(ids), dsteps(steps);
|
||||
Device<float> dq(query), dout(count + 2 * kGuard);
|
||||
const uint64_t stride = k::qsa_decode_attn_scratch_floats(cap, s);
|
||||
Device<float> scratch(size_t(std::min(kBatch, nq)) * size_t(stride));
|
||||
k::QsaAttnPools pools;
|
||||
pools.k_q = dk.p; pools.v_q = dv.p; pools.k_scale = dks.p; pools.v_scale = dvs.p;
|
||||
pools.page_table = dtable.p;
|
||||
HIP_CHECK(hipMemset(dout.p, 0xff, (count + 2 * kGuard) * sizeof(float)));
|
||||
HIP_CHECK(hipMemset(scratch.p, 0xff, size_t(std::min(kBatch, nq)) * size_t(stride) * sizeof(float)));
|
||||
auto launch = [&] {
|
||||
for (int64_t t = 0; t < nq; t += kBatch)
|
||||
k::qsa_decode_attn_batch(dq.p + t * nh * hd, pools, dids.p + t * cap,
|
||||
dsteps.p + t * k::kStepCount, cap, s, scratch.p, dout.p + kGuard + t * nh * hd,
|
||||
std::min(kBatch, nq - t), nullptr);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
};
|
||||
launch();
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
const auto first = read_checked(dout, count);
|
||||
constexpr int warmups = 3;
|
||||
for (int i = 0; i < warmups; ++i) launch();
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
hipEvent_t begin = nullptr, end = nullptr;
|
||||
HIP_CHECK(hipEventCreate(&begin)); HIP_CHECK(hipEventCreate(&end));
|
||||
std::vector<float> times(size_t(reps), 0.0f);
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
// Excluded from event duration; the last timed invocation must also
|
||||
// overwrite every logical output element instead of inheriting it.
|
||||
HIP_CHECK(hipMemsetAsync(dout.p + kGuard, 0xff, count * sizeof(float), nullptr));
|
||||
HIP_CHECK(hipEventRecord(begin, nullptr));
|
||||
launch();
|
||||
HIP_CHECK(hipEventRecord(end, nullptr));
|
||||
HIP_CHECK(hipEventSynchronize(end));
|
||||
HIP_CHECK(hipEventElapsedTime(×[size_t(i)], begin, end));
|
||||
}
|
||||
const auto result = read_checked(dout, count);
|
||||
if (std::memcmp(first.data(), result.data(), count * sizeof(float)) != 0)
|
||||
fail("first and final invocation differ byte-for-byte within this process");
|
||||
const uint64_t output_hash = hash_bytes(14695981039346656037ull, result.data(), count * sizeof(float));
|
||||
std::FILE* file = std::fopen(output, "wb");
|
||||
if (!file) fail("cannot open output file");
|
||||
const size_t written = std::fwrite(result.data(), sizeof(float), count, file);
|
||||
const int close_status = std::fclose(file);
|
||||
if (written != count || close_status != 0) fail("cannot write complete output file");
|
||||
std::sort(times.begin(), times.end());
|
||||
const float median = reps % 2 ? times[size_t(reps / 2)]
|
||||
: 0.5f * (times[size_t(reps / 2 - 1)] + times[size_t(reps / 2)]);
|
||||
int device = 0;
|
||||
hipDeviceProp_t prop{};
|
||||
HIP_CHECK(hipGetDevice(&device)); HIP_CHECK(hipGetDeviceProperties(&prop, device));
|
||||
std::printf("device=%s arch=%s nq=%lld ctx=%lld cap=%lld page_size=%lld batch=%lld reps=%d warmups=%d\n",
|
||||
prop.name, prop.gcnArchName, (long long)nq, (long long)ctx, (long long)cap,
|
||||
(long long)ps, (long long)kBatch, reps, warmups);
|
||||
std::printf("QUERY_SWIZZLE=%s LANECELL=%s seed=%016llx masked_pages=%zu masked_selected=%zu\n",
|
||||
env("STRATA_GFX906_ATTN_QUERY_SWIZZLE"), env("STRATA_ATTN_LANECELL"), (unsigned long long)kSeed,
|
||||
size_t(std::count(table.begin(), table.end(), -1)), masked_selected);
|
||||
std::printf("INPUT_FNV1A64=%016llx OUTPUT_FNV1A64=%016llx output_floats=%zu output_bytes=%zu\n",
|
||||
(unsigned long long)input_hash, (unsigned long long)output_hash, count, count * sizeof(float));
|
||||
std::printf("PASS finite_written_guards_and_repeat median_ms=%.6f min_ms=%.6f max_ms=%.6f us_per_query=%.6f output=%s\n",
|
||||
median, times.front(), times.back(), double(median) * 1000.0 / double(nq), output);
|
||||
HIP_CHECK(hipEventDestroy(begin)); HIP_CHECK(hipEventDestroy(end));
|
||||
return 0;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
try {
|
||||
std::vector<const char*> args;
|
||||
bool masked = false;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (std::strcmp(argv[i], "--masked-pages") == 0) masked = true;
|
||||
else args.push_back(argv[i]);
|
||||
}
|
||||
if (args.size() > 4) fail("usage: probe [nq] [ctx] [reps] [output.bin] [--masked-pages]");
|
||||
const int64_t nq = args.size() > 0 ? positive(args[0]) : 32;
|
||||
const int64_t ctx = args.size() > 1 ? positive(args[1]) : 65536;
|
||||
const int reps = args.size() > 2 ? int(positive(args[2])) : 20;
|
||||
const char* output = args.size() > 3 ? args[3] : std::getenv("STRATA_QSA_PROBE_OUT");
|
||||
if (!output || !*output) fail("pass output.bin as fourth positional argument or set STRATA_QSA_PROBE_OUT");
|
||||
return run(nq, ctx, reps, output, masked);
|
||||
} catch (const std::exception& e) {
|
||||
std::fprintf(stderr, "qsa_query_swizzle_probe: %s\n", e.what());
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// Linux/x86 CUDA reproducer for #1975. Run "lazy" and "warm" as separate processes.
|
||||
// See bench/results/2026-10-11-rtx-5090-callback-affinity/README.md for the build command.
|
||||
#include <cuda_runtime_api.h>
|
||||
#include <sched.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
struct State {
|
||||
std::atomic<bool> done{false};
|
||||
cpu_set_t mask{};
|
||||
};
|
||||
|
||||
static void callback(void* p) {
|
||||
auto* s = (State*) p;
|
||||
sched_getaffinity(0, sizeof s->mask, &s->mask);
|
||||
s->done.store(true, std::memory_order_release);
|
||||
}
|
||||
|
||||
static void check(cudaError_t e) {
|
||||
if (e != cudaSuccess) {
|
||||
std::fprintf(stderr, "%s\n", cudaGetErrorString(e));
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
const bool warm = argc > 1 && std::strcmp(argv[1], "warm") == 0;
|
||||
cudaStream_t stream;
|
||||
check(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));
|
||||
State state;
|
||||
if (warm) {
|
||||
check(cudaLaunchHostFunc(stream, callback, &state));
|
||||
check(cudaStreamSynchronize(stream));
|
||||
}
|
||||
cpu_set_t host;
|
||||
CPU_ZERO(&host);
|
||||
CPU_SET(0, &host);
|
||||
if (sched_setaffinity(0, sizeof host, &host) != 0) {
|
||||
std::perror("sched_setaffinity");
|
||||
return 1;
|
||||
}
|
||||
std::vector<double> times;
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
state.done.store(false, std::memory_order_release);
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
check(cudaLaunchHostFunc(stream, callback, &state));
|
||||
while (!state.done.load(std::memory_order_acquire)) {
|
||||
asm volatile("pause");
|
||||
if (std::chrono::steady_clock::now() - start > std::chrono::seconds(5)) return 2;
|
||||
}
|
||||
times.push_back(std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - start).count());
|
||||
}
|
||||
std::sort(times.begin(), times.end());
|
||||
std::printf("%s: callback affinity:", warm ? "before pin warm-up" : "after pin lazy creation");
|
||||
for (int i = 0; i < CPU_SETSIZE; ++i)
|
||||
if (CPU_ISSET(i, &state.mask)) std::printf(" %d", i);
|
||||
std::printf("; median %.2f us, p95 %.2f us\n", times[100], times[190]);
|
||||
check(cudaStreamSynchronize(stream));
|
||||
check(cudaStreamDestroy(stream));
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
[
|
||||
{"d":"code","p":"Write a Python function that merges two sorted lists into one sorted list without using sort(). Include type hints and a short docstring."},
|
||||
{"d":"code","p":"Implement an LRU cache in Python using OrderedDict with get and put methods, and write three unit tests with pytest."},
|
||||
{"d":"code","p":"Write a JavaScript function debounce(fn, wait) and explain how it differs from throttle, with a small usage example."},
|
||||
{"d":"code","p":"Write a C++ class template for a fixed-capacity ring buffer with push, pop and size, using std::array. Mention thread-safety."},
|
||||
{"d":"code","p":"Show a Rust function that reads a file line by line, counts word frequencies in a HashMap and prints the top 5 words."},
|
||||
{"d":"code","p":"Write a Go HTTP handler that returns JSON {\"status\":\"ok\"} and a middleware that logs the request duration."},
|
||||
{"d":"code","p":"Write a SQL query that returns the top 3 customers by total order value per country from tables customers(id,country) and orders(id,customer_id,amount)."},
|
||||
{"d":"code","p":"Write a bash script that finds all files larger than 100 MB under /var/log, sorted by size, and prints them in human readable form."},
|
||||
{"d":"code","p":"Explain this Python error and how to fix it:\nTraceback (most recent call last):\n File \"app.py\", line 12, in <module>\n print(data['users'][0]['name'])\nKeyError: 'users'"},
|
||||
{"d":"code","p":"Refactor this function to be more readable:\ndef f(a):\n r=[]\n for i in range(len(a)):\n if a[i]%2==0:\n r.append(a[i]*a[i])\n return r"},
|
||||
{"d":"code","p":"Write a regular expression that matches ISO 8601 dates like 2026-10-11 and explain each part."},
|
||||
{"d":"code","p":"Write a TypeScript interface for a paginated API response and a generic fetch helper that validates the shape at runtime."},
|
||||
{"d":"math","p":"A train leaves a station at 9:15 and travels at 80 km/h. A second train leaves the same station at 10:00 on the same track at 120 km/h. At what time does the second catch the first? Show the steps."},
|
||||
{"d":"math","p":"Prove that the sum of the first n odd numbers is n squared, using induction."},
|
||||
{"d":"math","p":"Solve the system: 3x + 2y = 16 and x - y = 2. Then check the solution."},
|
||||
{"d":"math","p":"What is the probability of getting exactly two heads in five fair coin flips? Explain the formula you use."},
|
||||
{"d":"reason","p":"Three friends, Ann, Ben and Cara, each own exactly one of a cat, a dog and a parrot. Ann does not own the dog. Ben owns neither the cat nor the parrot. Who owns what? Explain your reasoning."},
|
||||
{"d":"reason","p":"I have a 3 liter jug and a 5 liter jug and unlimited water. How can I measure exactly 4 liters?"},
|
||||
{"d":"chat","p":"I have a job interview tomorrow for a junior data analyst role and I am nervous. Can you give me practical advice?"},
|
||||
{"d":"chat","p":"What are some good ways to learn a new language as an adult with only 30 minutes a day?"},
|
||||
{"d":"chat","p":"Recommend a weekly meal prep plan for someone who wants high protein, vegetarian meals on a budget."},
|
||||
{"d":"chat","p":"My laptop gets very hot and the fan is loud when I open many browser tabs. What can I check?"},
|
||||
{"d":"creative","p":"Write a short story (about 300 words) about a lighthouse keeper who discovers that the light attracts something other than ships."},
|
||||
{"d":"creative","p":"Write a poem about autumn rain in the style of a haiku sequence, five stanzas."},
|
||||
{"d":"creative","p":"Describe a bustling night market in a fantasy city, using all five senses."},
|
||||
{"d":"science","p":"Explain how a transformer neural network processes a sentence, from tokens to the next-token prediction, for a software engineer who has not studied machine learning."},
|
||||
{"d":"science","p":"Why is the sky blue and sunsets red? Explain Rayleigh scattering without heavy math."},
|
||||
{"d":"science","p":"Explain how CRISPR-Cas9 edits a gene, and name two ethical concerns."},
|
||||
{"d":"history","p":"Summarize the causes and consequences of the fall of the Western Roman Empire in a few paragraphs."},
|
||||
{"d":"history","p":"Compare the economic policies of the New Deal with those of the Reagan era."},
|
||||
{"d":"law","p":"Explain the difference between a trademark, a copyright and a patent, with one everyday example of each."},
|
||||
{"d":"business","p":"Draft a polite email to a customer whose order is delayed by two weeks, offering a 10 percent discount and a new delivery date."},
|
||||
{"d":"business","p":"Write a one-page project proposal outline for migrating a small company's file server to a cloud storage service."},
|
||||
{"d":"data","p":"Create a markdown table comparing PostgreSQL, MySQL and SQLite on concurrency, typical use cases, licensing and scaling."},
|
||||
{"d":"data","p":"Return a JSON object describing a fictional book with fields title, author, year, genres (array) and a nested publisher object. Only output JSON."},
|
||||
{"d":"tool","p":"You are an assistant with a tool get_weather(city, unit). The user asks: 'Do I need an umbrella in Hamburg tomorrow?' Write the tool call you would make as JSON and then explain what you would tell the user once you get the result."},
|
||||
{"d":"summ","p":"Summarize in three bullet points: Photosynthesis converts light energy into chemical energy. In the light-dependent reactions, chlorophyll absorbs photons and splits water, releasing oxygen and producing ATP and NADPH. In the Calvin cycle, these carriers drive the fixation of carbon dioxide into sugars. The rate of photosynthesis depends on light intensity, carbon dioxide concentration and temperature."},
|
||||
{"d":"fr","p":"Explique en français comment fonctionne un moteur à combustion à quatre temps, avec des phrases simples."},
|
||||
{"d":"de","p":"Schreibe eine kurze, freundliche E-Mail auf Deutsch, in der du einen Termin beim Zahnarzt von Dienstag auf Donnerstag verschiebst."},
|
||||
{"d":"es","p":"Dame una receta sencilla de tortilla española y explica los errores más comunes al hacerla."},
|
||||
{"d":"zh","p":"请用中文解释什么是区块链,并举一个日常生活中的例子。"},
|
||||
{"d":"ja","p":"日本語で、初心者向けにPythonのリスト内包表記を説明してください。"},
|
||||
{"d":"ru","p":"Объясни простыми словами, чем отличается процесс от потока в операционной системе."},
|
||||
{"d":"trivia","p":"Who wrote 'The Master and Margarita', and what is the novel about? Answer in a short paragraph."},
|
||||
{"d":"essay","p":"Write a balanced essay of about 350 words on whether remote work is better than office work for software teams."}
|
||||
]
|
||||
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compile the production host guard with mock HIP calls; no GPU or HIP SDK needed.
|
||||
|
||||
The helper and dispatch expression are extracted from their single production
|
||||
definition so this test cannot accidentally validate a copied implementation.
|
||||
Run from any directory with Python 3 and a C++17 compiler (CXX, default c++).
|
||||
"""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shlex
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
source = (ROOT / "src/kernels/cuda/qsa_decode_attn.cu").read_text()
|
||||
start = source.index("bool query_swizzle_gfx906_device() {")
|
||||
end = source.index("\n}\n", start) + 3
|
||||
guard = source[start:end]
|
||||
dispatch = re.search(r"^ const bool use_query_swizzle = .*;", source, re.MULTILINE)
|
||||
if dispatch is None or "if (use_query_swizzle) {" not in source:
|
||||
raise RuntimeError("production query-swizzle dispatch changed; update the test")
|
||||
|
||||
prefix = r'''
|
||||
#include "strata/kernels/gfx_arch.hpp"
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <initializer_list>
|
||||
#include <thread>
|
||||
using strata::kernels::gfx_arch_is;
|
||||
constexpr int hipSuccess = 0;
|
||||
struct hipDeviceProp_t { char gcnArchName[64]; int warpSize; };
|
||||
struct Mock {
|
||||
int device = 0, device_calls = 0, property_calls = 0, clear_calls = 0;
|
||||
bool fail_device = false, fail_properties = false;
|
||||
};
|
||||
thread_local Mock mock;
|
||||
int hipGetDevice(int* device) {
|
||||
++mock.device_calls;
|
||||
*device = mock.device;
|
||||
return mock.fail_device ? 1 : hipSuccess;
|
||||
}
|
||||
int hipGetDeviceProperties(hipDeviceProp_t* prop, int device) {
|
||||
++mock.property_calls;
|
||||
if (mock.fail_properties) return 1;
|
||||
static const char* names[] = {
|
||||
"gfx906", "gfx908", "gfx906:sramecc-:xnack-", "gfx9060",
|
||||
"gfx906", "", "gfx906-other", "gfx906"
|
||||
};
|
||||
if (device < 0 || device >= 8) return 1;
|
||||
std::strcpy(prop->gcnArchName, names[device]);
|
||||
prop->warpSize = device == 4 ? 32 : 64;
|
||||
return hipSuccess;
|
||||
}
|
||||
int hipGetLastError() { ++mock.clear_calls; return hipSuccess; }
|
||||
int checks = 0;
|
||||
void require(bool condition, const char* message) {
|
||||
++checks;
|
||||
if (!condition) { std::fprintf(stderr, "FAIL: %s\n", message); std::exit(1); }
|
||||
}
|
||||
'''
|
||||
|
||||
tests = r'''
|
||||
int main() {
|
||||
require(!active(false, false, 1), "opt-in off");
|
||||
require(!active(true, true, 1), "lane-cell wins");
|
||||
for (int mode : {0, 2, 3}) require(!active(true, false, mode), "other pool modes");
|
||||
require(mock.device_calls == 0 && mock.property_calls == 0, "inactive dispatch makes no HIP queries");
|
||||
require(active(true, false, 1), "gfx906 wave64 accepted");
|
||||
require(active(true, false, 1), "same-device cache accepted");
|
||||
require(mock.device_calls == 2 && mock.property_calls == 1, "ordinal checked each time, properties cached");
|
||||
mock.device = 1;
|
||||
require(!active(true, false, 1), "gfx908 rejected after device switch");
|
||||
require(!active(true, false, 1) && mock.property_calls == 2, "unsupported result cached");
|
||||
mock.device = 0;
|
||||
require(active(true, false, 1) && mock.property_calls == 3, "switch back refreshes properties");
|
||||
mock.device = 2;
|
||||
require(active(true, false, 1), "exact gfx906 name with feature suffix accepted");
|
||||
for (int device : {3, 4, 5, 6}) {
|
||||
mock.device = device;
|
||||
require(!active(true, false, 1), "lookalike name, wave32, or empty name rejected");
|
||||
}
|
||||
mock.device = 0;
|
||||
require(active(true, false, 1), "restore supported device");
|
||||
int properties = mock.property_calls, clears = mock.clear_calls;
|
||||
mock.fail_device = true;
|
||||
require(!active(true, false, 1), "current-device API error fails closed");
|
||||
require(mock.property_calls == properties && mock.clear_calls == clears + 1, "device error avoids property query");
|
||||
mock.fail_device = false;
|
||||
require(active(true, false, 1) && mock.property_calls == properties + 1, "device error invalidates cache");
|
||||
mock.device = -1;
|
||||
require(!active(true, false, 1), "negative ordinal fails closed");
|
||||
mock.device = 0;
|
||||
require(active(true, false, 1) && mock.property_calls == properties + 2, "invalid ordinal invalidates cache");
|
||||
mock.device = 7;
|
||||
mock.fail_properties = true;
|
||||
properties = mock.property_calls;
|
||||
clears = mock.clear_calls;
|
||||
require(!active(true, false, 1), "property API error cannot reuse another device's cached approval");
|
||||
require(!active(true, false, 1), "repeated property failure stays closed");
|
||||
require(mock.property_calls == properties + 2 && mock.clear_calls == clears + 2, "property errors remain retryable");
|
||||
mock.fail_properties = false;
|
||||
require(active(true, false, 1) && mock.property_calls == properties + 3, "property query recovers");
|
||||
mock.device = 0;
|
||||
require(active(true, false, 1), "parent thread caches ordinal zero");
|
||||
std::thread other([] {
|
||||
require(active(true, false, 1) && mock.property_calls == 1, "new thread independently queries the same ordinal");
|
||||
mock.device = 1;
|
||||
require(!active(true, false, 1), "other thread caches an unsupported ordinal");
|
||||
});
|
||||
other.join();
|
||||
properties = mock.property_calls;
|
||||
require(active(true, false, 1) && mock.property_calls == properties, "other thread cannot replace parent cache");
|
||||
std::printf("PASS query-swizzle host guard: %d checks (mock HIP, no GPU)\n", checks);
|
||||
}
|
||||
'''
|
||||
|
||||
program = prefix + guard + "\nbool active(bool query_swizzle, bool lane_cell, int kv_mode) {\n"
|
||||
program += dispatch.group(0) + "\n return use_query_swizzle;\n}\n" + tests
|
||||
with tempfile.TemporaryDirectory(prefix="qsa-swizzle-guard-") as directory:
|
||||
cpp = Path(directory) / "guard_test.cpp"
|
||||
binary = Path(directory) / "guard_test"
|
||||
cpp.write_text(program)
|
||||
command = shlex.split(os.environ.get("CXX", "c++"))
|
||||
command += ["-std=c++17", "-Wall", "-Wextra", "-Werror", "-pthread", "-I", str(ROOT / "include"),
|
||||
str(cpp), "-o", str(binary)]
|
||||
subprocess.run(command, check=True)
|
||||
subprocess.run([str(binary)], check=True)
|
||||
+29
-2
@@ -8,10 +8,11 @@ endif()
|
||||
# maintainers; gfx1101 (RX 7800 XT, #254) and gfx1200 (RX 9060 XT, #256) by their owners. gfx1102 (RX 7600) has the
|
||||
# same LDS limit and dot4 instruction and passed ctest (#192), but no model run has been reported yet. RDNA2 gfx1030 (RX 6800 / 6900) has the
|
||||
# same LDS limit and wave32 but an older dot4 instruction (v_dot4_i32_i8, hip_compat/intrinsics.hpp); a community
|
||||
# report ran it (#311), the maintainers have not.
|
||||
# report ran it (#311), the maintainers have not. gfx1151 (Ryzen AI Max / Strix Halo, Radeon 8060S, RDNA3.5) is the
|
||||
# same wave32 / 64 KiB LDS / sudot4 family as gfx1100, on a unified-memory APU; experimental.
|
||||
set(_strata_hip_validated gfx1100 gfx1201)
|
||||
set(_strata_hip_community gfx1101 gfx1200)
|
||||
set(_strata_hip_unvalidated gfx1012 gfx1102 gfx1030 gfx1031)
|
||||
set(_strata_hip_unvalidated gfx1010 gfx1011 gfx1012 gfx1102 gfx1103 gfx1030 gfx1031 gfx1032 gfx1034 gfx1150 gfx1151 gfx1152) # gfx1103: Radeon 780M iGPU, opt-in, WMMA kernels like gfx1100; gfx1152: Krackan, Radeon 860M / 840M (#1625), builds with the portable kernels, no card report yet
|
||||
# CMake hands HIP a ';' list, but a -DCMAKE_HIP_ARCHITECTURES typed by hand (or ROCm's own Windows tooling) may use
|
||||
# spaces, which foreach(IN LISTS) would otherwise treat as one element.
|
||||
string(REPLACE " " ";" _strata_hip_norm "${CMAKE_HIP_ARCHITECTURES}")
|
||||
@@ -42,6 +43,18 @@ endif()
|
||||
string(REPLACE ";" "," STRATA_HIP_ARCHS "${STRATA_HIP_ARCH_LIST}")
|
||||
|
||||
enable_language(HIP)
|
||||
# CMake caches CMAKE_HIP_FLAGS_<CONFIG> while it enables HIP, before it tests the compiler. A configure that stopped
|
||||
# there because HIP could not compile at all (Visual Studio 2026's <cmath> with the HIP SDK 7.2, a wrong ROCm path)
|
||||
# cached them empty, and every later configure of that build folder keeps them: setup's Release build then compiled
|
||||
# all kernels at -O0 (an RX 6800 decoded at 0.24-0.27 tok/s instead of 28). Empty ones get what CMake gives a fresh
|
||||
# build folder.
|
||||
foreach(_cfg IN ITEMS DEBUG RELEASE RELWITHDEBINFO MINSIZEREL)
|
||||
string(STRIP "${CMAKE_HIP_FLAGS_${_cfg}_INIT}" _strata_init)
|
||||
if("${CMAKE_HIP_FLAGS_${_cfg}}" STREQUAL "" AND NOT "${_strata_init}" STREQUAL "")
|
||||
set(CMAKE_HIP_FLAGS_${_cfg} "${_strata_init}" CACHE STRING
|
||||
"Flags used by the HIP compiler during ${_cfg} builds." FORCE)
|
||||
endif()
|
||||
endforeach()
|
||||
find_package(hip CONFIG REQUIRED)
|
||||
find_package(hipblas CONFIG REQUIRED)
|
||||
# Older distro hipBLAS has no workspace API. The compatibility shim uses
|
||||
@@ -50,6 +63,9 @@ set(STRATA_HIP_BLAS_TARGETS roc::hipblas)
|
||||
if(hipblas_VERSION VERSION_LESS "1.0")
|
||||
find_package(rocblas CONFIG REQUIRED)
|
||||
list(APPEND STRATA_HIP_BLAS_TARGETS roc::rocblas)
|
||||
else()
|
||||
# the prompt path's rocBLAS solution table (STRATA_ROCBLAS_TUNING, gfx103x) calls rocBLAS by name
|
||||
find_package(rocblas CONFIG QUIET)
|
||||
endif()
|
||||
find_package(hipblaslt CONFIG QUIET)
|
||||
|
||||
@@ -65,6 +81,12 @@ else()
|
||||
set(STRATA_HIPBLASLT_AVAILABLE OFF)
|
||||
message(STATUS "Strata: hipBLASLt not found; solution-table dispatch is unavailable")
|
||||
endif()
|
||||
if(TARGET roc::rocblas)
|
||||
set(STRATA_ROCBLAS_AVAILABLE ON)
|
||||
else()
|
||||
set(STRATA_ROCBLAS_AVAILABLE OFF)
|
||||
message(STATUS "Strata: rocBLAS CMake package not found; the rocBLAS solution table (gfx103x) is unavailable")
|
||||
endif()
|
||||
|
||||
# HIP's link step produces a PIE; make Strata and ggml objects PIC for the ROCm linker.
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
@@ -78,6 +100,11 @@ option(STRATA_GFX1012_PORTABLE_DOT "Use the portable signed-byte dot control on
|
||||
if(STRATA_GFX1012_PORTABLE_DOT)
|
||||
target_compile_definitions(strata_hip_runtime INTERFACE STRATA_GFX1012_PORTABLE_DOT=1)
|
||||
endif()
|
||||
# #313: the RDNA3 WMMA GEMM's intrinsics only compile for gfx11 targets and the host pass does not define
|
||||
# __gfx11xx__, so the build supplies the macro for gfx11 configs (the kernels also gate on the device at runtime)
|
||||
if(CMAKE_HIP_ARCHITECTURES MATCHES "gfx11")
|
||||
target_compile_definitions(strata_hip_runtime INTERFACE STRATA_WMMA_GFX11=1)
|
||||
endif()
|
||||
target_link_libraries(strata_hip_runtime INTERFACE hip::host)
|
||||
# The shim renames the CUDA runtime to HIP, force-included into every host and device source. On Windows the host
|
||||
# compiler is ROCm's clang++ too (tools/hip/build_windows.bat: CMake refuses to mix cl.exe with Clang HIP), which takes
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
# cmake/qwen36_attn_fixtures.cmake - the synthetic qwen35moe GGUFs at the engine's head_dim (256) and the oracle's
|
||||
# dumps of their attention layer, for qsa_dense_parity (Qwen3.6 step 3, docs/qwen36-port/step3-attn.md).
|
||||
#
|
||||
# cmake -DPYTHON=<python3 with numpy> -DSOURCE_DIR=<repo> -DOUT=<dir> -P cmake/qwen36_attn_fixtures.cmake
|
||||
#
|
||||
# Three fixtures, one per query-heads-per-KV-head the kernels are built for: g8 (16 / 2, Qwen3.6's ratio), g12
|
||||
# (24 / 2, Flash-Next's), g2 (4 / 2, the oracle's own GQA case). Each: <OUT>/<name>.gguf and <OUT>/<name>-dump/
|
||||
# with every seam of ref/qwen36.py on 40 tokens. Writes <OUT>/SKIP (and exits 0) when numpy or gguf-py is
|
||||
# missing, so the test that needs the files skips (77) instead of passing on nothing.
|
||||
file(MAKE_DIRECTORY "${OUT}")
|
||||
set(_synth "${SOURCE_DIR}/tools/qwen36_synth_gguf.py")
|
||||
set(_oracle "${SOURCE_DIR}/ref/qwen36.py")
|
||||
set(_text "dense attention over sixteen heads, G=8!") # 40 ASCII tokens (the fixture's vocabulary is the byte set)
|
||||
foreach(_case "g8;16,2;3" "g12;24,2;5" "g2;4,2;11")
|
||||
list(GET _case 0 _name)
|
||||
list(GET _case 1 _heads)
|
||||
list(GET _case 2 _seed)
|
||||
execute_process(COMMAND ${PYTHON} -I ${_synth} "${OUT}/${_name}.gguf" --heads ${_heads} --head-dim 256 --no-nextn
|
||||
--seed ${_seed}
|
||||
RESULT_VARIABLE _rc OUTPUT_VARIABLE _out ERROR_VARIABLE _err)
|
||||
if(NOT _rc EQUAL 0)
|
||||
message("${_out}${_err}")
|
||||
if(_err MATCHES "ModuleNotFoundError" OR _out MATCHES "gguf-py" OR _err MATCHES "gguf-py")
|
||||
message("qwen36_attn_fixtures: numpy or gguf-py is missing - skipping")
|
||||
file(WRITE "${OUT}/SKIP" "${_out}${_err}")
|
||||
return()
|
||||
endif()
|
||||
message(FATAL_ERROR "qwen36_attn_fixtures: ${_synth} ${_name} failed (${_rc})")
|
||||
endif()
|
||||
file(REMOVE_RECURSE "${OUT}/${_name}-dump")
|
||||
execute_process(COMMAND ${PYTHON} -I ${_oracle} "${OUT}/${_name}.gguf" --text "${_text}" --dump "${OUT}/${_name}-dump"
|
||||
RESULT_VARIABLE _rc OUTPUT_VARIABLE _out ERROR_VARIABLE _err)
|
||||
if(NOT _rc EQUAL 0)
|
||||
message("${_out}${_err}")
|
||||
message(FATAL_ERROR "qwen36_attn_fixtures: ${_oracle} on ${_name} failed (${_rc})")
|
||||
endif()
|
||||
endforeach()
|
||||
file(REMOVE "${OUT}/SKIP")
|
||||
message("qwen36_attn_fixtures: 3 fixtures and their dumps in ${OUT}")
|
||||
@@ -1,28 +0,0 @@
|
||||
# cmake/qwen36_block_fixtures.cmake - the oracle's dumps of the synthetic qwen35moe file on a verify window's worth of
|
||||
# tokens, for tests/cuda/qwen36_block_test.cpp (the plain block held to the dumps seam by seam).
|
||||
#
|
||||
# cmake -DPYTHON=<python3 with numpy> -DSOURCE_DIR=<repo> -DSYNTH=<dir with toy.gguf> -DOUT=<dir> -P cmake/qwen36_block_fixtures.cmake
|
||||
#
|
||||
# Writes <OUT>/o8/<seam>.f32 and manifest.txt (ref/qwen36.py --dump) for 8 tokens ("hello wo": the fixture's vocabulary is
|
||||
# the ASCII bytes). Exit 3 when numpy or the vendored gguf-py is missing (the SKIP marker, as qwen36_synth_fixtures.cmake).
|
||||
file(MAKE_DIRECTORY "${OUT}")
|
||||
if(EXISTS "${SYNTH}/SKIP" OR NOT EXISTS "${SYNTH}/toy.gguf")
|
||||
file(WRITE "${OUT}/SKIP" "no synthetic fixture in ${SYNTH}")
|
||||
message("qwen36_block_fixtures: no toy.gguf in ${SYNTH} - skipping")
|
||||
return()
|
||||
endif()
|
||||
file(REMOVE_RECURSE "${OUT}/o8")
|
||||
execute_process(COMMAND ${PYTHON} -I "${SOURCE_DIR}/ref/qwen36.py" "${SYNTH}/toy.gguf"
|
||||
--tokens 104,101,108,108,111,32,119,111 --dump "${OUT}/o8"
|
||||
RESULT_VARIABLE _rc OUTPUT_VARIABLE _out ERROR_VARIABLE _err)
|
||||
if(NOT _rc EQUAL 0)
|
||||
message("${_out}${_err}")
|
||||
if(_err MATCHES "ModuleNotFoundError")
|
||||
message("qwen36_block_fixtures: numpy or gguf-py is missing - skipping")
|
||||
file(WRITE "${OUT}/SKIP" "${_err}")
|
||||
return()
|
||||
endif()
|
||||
message(FATAL_ERROR "qwen36_block_fixtures: ref/qwen36.py failed (${_rc})")
|
||||
endif()
|
||||
file(REMOVE "${OUT}/SKIP")
|
||||
message("qwen36_block_fixtures: dumps in ${OUT}/o8")
|
||||
@@ -1,35 +0,0 @@
|
||||
# cmake/qwen36_oracle_dumps.cmake - the Qwen3.6 kernel fixture and the oracle's seam dumps for the GPU parity tests.
|
||||
#
|
||||
# cmake -DPYTHON=<python3 with numpy> -DSOURCE_DIR=<repo> -DOUT=<dir> -P cmake/qwen36_oracle_dumps.cmake
|
||||
#
|
||||
# Writes OUT/k.gguf with tools/qwen36_synth_gguf.py at the geometry the engine's CUDA GDN kernels are pinned to
|
||||
# (state 128, 2 k-heads / 4 v-heads: VPK 2 like the real 16 / 32), the real router shape (256 experts, top-8), the
|
||||
# shared expert at its real width (512) in Q8_0, and the weights the engine reads as BF16 already BF16-representable;
|
||||
# then runs ref/qwen36.py on the 11-token "hello world" sequence twice: OUT/o_f32 (F32 activations) and OUT/o_q8
|
||||
# (--act-quant q8: activations rounded to Q8 before every quantized matmul, as the engine's native MMVQ path does).
|
||||
# Every tensor llama.cpp names with cb() lands in those directories as <name>.f32 (docs/qwen36-port/oracle-crosscheck.md).
|
||||
#
|
||||
# Exit 3 (and OUT/SKIP written) when numpy or the vendored gguf-py is missing, so the tests that need the files skip.
|
||||
file(MAKE_DIRECTORY "${OUT}")
|
||||
set(_synth "${SOURCE_DIR}/tools/qwen36_synth_gguf.py")
|
||||
set(_oracle "${SOURCE_DIR}/ref/qwen36.py")
|
||||
set(_tokens "104,101,108,108,111,32,119,111,114,108,100")
|
||||
set(_step1 ${PYTHON} -I ${_synth} "${OUT}/k.gguf" --gdn 2,4,128 --experts 256,8 --shexp-ff 512 --quant-shexp q8_0 --bf16-exact --no-nextn)
|
||||
set(_step2 ${PYTHON} -I ${_oracle} "${OUT}/k.gguf" --tokens ${_tokens} --dump "${OUT}/o_f32")
|
||||
set(_step3 ${PYTHON} -I ${_oracle} "${OUT}/k.gguf" --tokens ${_tokens} --dump "${OUT}/o_q8" --act-quant q8)
|
||||
foreach(_name _step1 _step2 _step3)
|
||||
set(_cmd ${${_name}})
|
||||
execute_process(COMMAND ${_cmd} RESULT_VARIABLE _rc OUTPUT_VARIABLE _out ERROR_VARIABLE _err)
|
||||
if(NOT _rc EQUAL 0)
|
||||
message("${_out}${_err}")
|
||||
if(_err MATCHES "ModuleNotFoundError" OR _err MATCHES "gguf-py was not found")
|
||||
message("qwen36_oracle_dumps: numpy or gguf-py is missing - skipping")
|
||||
file(WRITE "${OUT}/SKIP" "${_err}")
|
||||
return()
|
||||
endif()
|
||||
message(FATAL_ERROR "qwen36_oracle_dumps: `${_cmd}` failed (${_rc})")
|
||||
endif()
|
||||
endforeach()
|
||||
file(REMOVE "${OUT}/SKIP")
|
||||
file(WRITE "${OUT}/tokens.txt" "${_tokens}\n")
|
||||
message("qwen36_oracle_dumps: k.gguf, o_f32/, o_q8/ in ${OUT}")
|
||||
@@ -1,27 +0,0 @@
|
||||
# cmake/qwen36_synth_fixtures.cmake - writes the synthetic qwen35moe GGUFs the Qwen3.6 geometry tests read.
|
||||
#
|
||||
# cmake -DPYTHON=<python3 with numpy> -DSOURCE_DIR=<repo> -DOUT=<dir> -P cmake/qwen36_synth_fixtures.cmake
|
||||
#
|
||||
# Exit 3 when numpy or the vendored gguf-py is missing (a trimmed third_party): the tests that need the files skip.
|
||||
cmake_policy(SET CMP0007 NEW) # keep the empty flag of "toy.gguf;" (cmake < 4 drops it and list(GET 1) fails)
|
||||
file(MAKE_DIRECTORY "${OUT}")
|
||||
set(_tool "${SOURCE_DIR}/tools/qwen36_synth_gguf.py")
|
||||
foreach(_case "toy.gguf;" "toy-nonextn.gguf;--no-nextn" "toy-fused-gate-up.gguf;--fused-gate-up"
|
||||
"toy-fused-qkv.gguf;--fused-qkv")
|
||||
list(GET _case 0 _name)
|
||||
list(GET _case 1 _flag)
|
||||
execute_process(COMMAND ${PYTHON} -I ${_tool} "${OUT}/${_name}" ${_flag}
|
||||
RESULT_VARIABLE _rc OUTPUT_VARIABLE _out ERROR_VARIABLE _err)
|
||||
if(NOT _rc EQUAL 0)
|
||||
message("${_out}${_err}")
|
||||
if(_err MATCHES "ModuleNotFoundError")
|
||||
message("qwen36_synth_fixtures: numpy or gguf-py is missing - skipping")
|
||||
# cmake -P cannot set the exit code directly: a FATAL_ERROR exits 1, so write the marker the test reads
|
||||
file(WRITE "${OUT}/SKIP" "${_err}")
|
||||
return()
|
||||
endif()
|
||||
message(FATAL_ERROR "qwen36_synth_fixtures: ${_tool} ${_flag} failed (${_rc})")
|
||||
endif()
|
||||
endforeach()
|
||||
file(REMOVE "${OUT}/SKIP")
|
||||
message("qwen36_synth_fixtures: 4 files in ${OUT}")
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,148 @@
|
||||
{#- ISTA-DASLab DeepSeek-V4.1-Flash-1017 GGUF chat template with the 1017 DSML tag spelling written out (" calls>", " invoke", " parameter"): the GGUF's own text spells them "tool_calls>"/"invoke"/"parameter" through a dsml_token variable, the model writes the spaced form, and llama.cpp selects its V4.1 parser on the literal "|DSML| calls>" (UnbiasedStrata, 2026-10-24) #}
|
||||
{%- if not add_generation_prompt is defined -%}
|
||||
{%- set add_generation_prompt = false -%}
|
||||
{%- endif -%}
|
||||
{%- if not thinking is defined -%}
|
||||
{%- if enable_thinking is defined -%}
|
||||
{%- set thinking = enable_thinking -%}
|
||||
{%- else -%}
|
||||
{%- set thinking = false -%}
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
{%- if not drop_thinking is defined -%}
|
||||
{%- set drop_thinking = true -%}
|
||||
{%- endif -%}
|
||||
{%- set dsml_token = '|DSML|' -%}
|
||||
{%- set thinking_start_token = '<think>' -%}
|
||||
{%- set thinking_end_token = '</think>' -%}
|
||||
{#- DeepSeek-V4.1: reasoning effort is an integer budget in [1, 100] or 'low'/'high'/'max' (50/75/100), default 'high'.
|
||||
It is rendered as a system prefix in thinking mode only. llama-server passes it as a string ("50"). -#}
|
||||
{%- set effort_levels = {'low': 50, 'high': 75, 'max': 100} -%}
|
||||
{%- set effort = namespace(value=75) -%}
|
||||
{%- if reasoning_effort is defined and reasoning_effort is not none and reasoning_effort != '' -%}
|
||||
{%- if reasoning_effort is string and reasoning_effort in effort_levels -%}
|
||||
{%- set effort.value = effort_levels[reasoning_effort] -%}
|
||||
{%- else -%}
|
||||
{%- set effort.value = reasoning_effort | int -%}
|
||||
{%- endif -%}
|
||||
{%- if effort.value < 1 or effort.value > 100 -%}
|
||||
{{- raise_exception('reasoning_effort must be an integer in [1, 100] or low/high/max, got ' + (reasoning_effort | string)) -}}
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
{%- set response_format_template = '## Response Format:\n\nYou MUST strictly adhere to the following schema to reply:\n' -%}
|
||||
{%- set has_tools = false -%}
|
||||
{%- set tools_header = '## Tools\n\nYou have access to a set of tools to help answer the user\'s question. You can invoke tools by writing a "<|DSML| calls>" block like the following:\n\n<|DSML| calls>\n<|DSML| invoke name="$TOOL_NAME">\n<|DSML| parameter name="$PARAMETER_NAME" string="true|false">$PARAMETER_VALUE</|DSML| parameter>\n...\n</|DSML| invoke>\n<|DSML| invoke name="$TOOL_NAME2">\n...\n</|DSML| invoke>\n</|DSML| calls>\n\nString parameters should be specified as is and set `string="true"`. For all other types (numbers, booleans, arrays, objects), pass the value in JSON format and set `string="false"`.\n\nIf thinking_mode is enabled (triggered by ' + thinking_start_token + '), you MUST output your complete reasoning inside ' + thinking_start_token + '...' + thinking_end_token + ' BEFORE any tool calls or final response.\n\nOtherwise, output directly after ' + thinking_end_token + ' with tool calls or final response.\n\n### Available Tool Schemas\n\n' -%}
|
||||
{%- set tools_footer = '\nYou MUST strictly follow the above defined tool name and parameter schemas to invoke tool calls.\n' -%}
|
||||
{%- set ns = namespace(system_prompt='', is_first_sp=true, has_tool_calls=false) -%}
|
||||
{%- set lead_system = messages and messages[0]['role'] == 'system' -%}
|
||||
{%- if lead_system -%}
|
||||
{%- set ns.system_prompt = messages[0]['content'] or '' -%}
|
||||
{%- endif -%}
|
||||
{%- if tools is defined and tools -%}
|
||||
{%- set has_tools = true -%}
|
||||
{%- set ts = namespace(schemas='') -%}
|
||||
{%- for tool in tools -%}
|
||||
{%- if tool['type'] == 'function' -%}
|
||||
{%- set ts.schemas = ts.schemas + (tool['function'] | tojson) + '\n' -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- if ns.system_prompt -%}
|
||||
{%- set ns.system_prompt = ns.system_prompt + '\n\n' + tools_header + ts.schemas + tools_footer -%}
|
||||
{%- else -%}
|
||||
{%- set ns.system_prompt = tools_header + ts.schemas + tools_footer -%}
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
{%- if response_format is defined -%}
|
||||
{%- if ns.system_prompt -%}
|
||||
{%- set ns.system_prompt = ns.system_prompt + '\n\n' -%}
|
||||
{%- endif -%}
|
||||
{%- set ns.system_prompt = ns.system_prompt + response_format_template + (response_format | tojson) -%}
|
||||
{%- endif -%}
|
||||
{{- bos_token -}}
|
||||
{%- set effort_prefix = 'Reasoning Effort: ' + (effort.value | string) + ' (range 1-100, the higher the value, the more thorough the reasoning)\n\n' if messages and thinking else '' -%}
|
||||
{%- if effort_prefix or lead_system or ns.system_prompt -%}
|
||||
{{- '<|System|>' + effort_prefix + ns.system_prompt -}}
|
||||
{%- endif -%}
|
||||
{%- set last_user_idx = namespace(value=-1) -%}
|
||||
{%- for message in messages -%}
|
||||
{%- if message['role'] == 'user' or message['role'] == 'developer' or (message['role'] == 'system' and loop.index0 > 0) -%}
|
||||
{%- set last_user_idx.value = loop.index0 -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- set state = namespace(in_user=false) -%}
|
||||
{%- for message in messages -%}
|
||||
{%- if message['role'] == 'tool' -%}
|
||||
{%- set ns.has_tool_calls = true -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- for message in messages -%}
|
||||
{%- if message['role'] == 'system' and loop.index0 > 0 -%}
|
||||
{%- set state.in_user = false -%}
|
||||
{{- '<|System|>' + (message['content'] or '') -}}
|
||||
{%- elif message['role'] == 'user' or message['role'] == 'developer' -%}
|
||||
{%- if state.in_user -%}
|
||||
{{- '\n\n' -}}
|
||||
{%- else -%}
|
||||
{{- '<|User|>' -}}
|
||||
{%- set state.in_user = true -%}
|
||||
{%- endif -%}
|
||||
{{- message['content'] or '' -}}
|
||||
{%- elif message['role'] == 'tool' -%}
|
||||
{%- if state.in_user -%}
|
||||
{{- '\n\n' -}}
|
||||
{%- else -%}
|
||||
{{- '<|User|>' -}}
|
||||
{%- set state.in_user = true -%}
|
||||
{%- endif -%}
|
||||
{{- '<tool_result>' + (message['content'] or '') + '</tool_result>' -}}
|
||||
{%- elif message['role'] == 'assistant' -%}
|
||||
{%- set state.in_user = false -%}
|
||||
{{- '<|Assistant|>' -}}
|
||||
{%- set is_after_last_user = loop.index0 > last_user_idx.value -%}
|
||||
{%- set keep_reasoning = thinking and ((not drop_thinking) or has_tools or is_after_last_user or ns.has_tool_calls) -%}
|
||||
{%- if keep_reasoning -%}
|
||||
{{- thinking_start_token -}}
|
||||
{%- if message['reasoning_content'] is defined and message['reasoning_content'] -%}
|
||||
{{- message['reasoning_content'] -}}
|
||||
{%- endif -%}
|
||||
{{- thinking_end_token -}}
|
||||
{%- else -%}
|
||||
{{- thinking_end_token -}}
|
||||
{%- endif -%}
|
||||
{%- if message['content'] is defined and message['content'] -%}
|
||||
{{- message['content'] -}}
|
||||
{%- endif -%}
|
||||
{%- if message['tool_calls'] -%}
|
||||
{{- '\n\n<|DSML| calls>\n' -}}
|
||||
{%- for tool in message['tool_calls'] -%}
|
||||
{%- set func = tool['function'] -%}
|
||||
{{- '<|DSML| invoke name="' + func['name'] + '">\n' -}}
|
||||
{%- set args = func['arguments'] -%}
|
||||
{%- if args is string -%}
|
||||
{%- set args = args | from_json -%}
|
||||
{%- endif -%}
|
||||
{%- for key, val in args.items() -%}
|
||||
{%- if val is string -%}
|
||||
{{- '<|DSML| parameter name="' + key + '" string="true">' + val + '</|DSML| parameter>\n' -}}
|
||||
{%- else -%}
|
||||
{{- '<|DSML| parameter name="' + key + '" string="false">' + (val | tojson) + '</|DSML| parameter>\n' -}}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- if not args -%}
|
||||
{{- '\n' -}}
|
||||
{%- endif -%}
|
||||
{{- '</|DSML| invoke>\n' -}}
|
||||
{%- endfor -%}
|
||||
{{- '</|DSML| calls>' -}}
|
||||
{%- endif -%}
|
||||
{{- '<|end▁of▁sentence|>' -}}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- if add_generation_prompt -%}
|
||||
{{- '<|Assistant|>' -}}
|
||||
{%- if thinking -%}
|
||||
{{- thinking_start_token -}}
|
||||
{%- else -%}
|
||||
{{- thinking_end_token -}}
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
8db93e483b34b15dbf63a0826601f1db2107a8cfea73774e7d21d8559e0a9568 *profile-2.00.bin
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
c8de062c5f3c71725ecf5328bd4ee02c71dca88478bf7f6b0f2ec258567ac6b6 *profile-2.25.bin
|
||||
BIN
Binary file not shown.
+26
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"mode": "project",
|
||||
"dir": "per-layer",
|
||||
"scale": 1.0,
|
||||
"layer_range": [
|
||||
4,
|
||||
44
|
||||
],
|
||||
"refusal_harmful_thinkoff": 2.0,
|
||||
"refusal_harmful_thinkon": 2.0,
|
||||
"refusal_harmless_thinkoff": 4.0,
|
||||
"refusal_harmless_thinkon": 6.0,
|
||||
"broken": 0,
|
||||
"kl_mean": 0.18598,
|
||||
"kl_max": 18.26549,
|
||||
"kl_p99": 3.143571,
|
||||
"decode_tps": 51.19,
|
||||
"vector_file": "Qwen3.8-Flash-Next-experimental-speed-projection.gguf",
|
||||
"base_model_gguf": "unsloth/Qwen3.8-Flash-Next-GGUF UD-Q2_K_XL",
|
||||
"base_model_sha256_shard1": "a4f3b21e77353999829f2f767e9ac21ce9c71d29a74f2cc9eda48c9bf23c8b86",
|
||||
"worktree_commit": "37e026e3b",
|
||||
"criterion_status": "PASS",
|
||||
"dirty_direction": false,
|
||||
"note": "projection ablation h -= s*(h.v)*v, v unit-normalized per layer. dir=per-layer",
|
||||
"branch": "cvec-hooks (github.com/Cudila/llama.cpp)"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
# experimental-speed-projection (EXPERIMENTAL, off by default)
|
||||
|
||||
`Qwen3.8-Flash-Next-experimental-speed-projection.gguf` is a 480 KB control vector for Qwen3.8-Flash-Next: one unit
|
||||
direction of 2,560 values per layer (`direction.1` .. `direction.47`, GGUF `controlvector` format). The JSON beside it
|
||||
is the configuration its authors selected and their scores.
|
||||
|
||||
**What it does.** Turned on, PolyStrata removes each direction from the residual stream after layers 4-44
|
||||
(`h -= (h . v) v` on every hyper-connection stream), the same operation as llama.cpp's `--cvec-mode project` in the
|
||||
package's patches. The package's own documentation describes the vector as a **refusal-direction projection**: the
|
||||
model declines far fewer requests (it reports 1 of 50 vs 50 of 50 on its test set), and removing refusals removes a
|
||||
safety behaviour - you are responsible for what the model writes with it on. It also shifts the model's predictions
|
||||
slightly on ordinary text (measured here: `bench/results/2026-09-27-esp/`). It is not an optimization in the engine:
|
||||
on the same text it costs 0.2-0.4% per token; a chat's speed with it on depends on the text the model writes.
|
||||
|
||||
**Turning it on.** `START-HERE.bat --setup` asks (default: off), or pass `--experimental-speed-projection on`. With it
|
||||
loaded, the web app's Sampling drawer and the API field `"experimental_speed_projection": false` switch it off per
|
||||
request. See `docs/DETAILS.md`, "Experimental speed projection".
|
||||
|
||||
**Origin and license.** A local package of the vector (the published original uses filenames containing "refusal";
|
||||
the bytes are the same), made from Qwen3.8-Flash-Next activations, so the Qwen Community License 1.0 of the model
|
||||
applies to it. Made for the original Qwen3.8-Flash-Next (not Swift 1.5).
|
||||
Binary file not shown.
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
Binary file not shown.
@@ -0,0 +1,436 @@
|
||||
{
|
||||
"qwen/Q2_0": {
|
||||
"arch": "qwen4exp",
|
||||
"tensors": 1224,
|
||||
"bytes": 66412853760,
|
||||
"expert_bytes": {
|
||||
"Q2_0": 33973862400
|
||||
},
|
||||
"experts_bpw": 2.25,
|
||||
"bpw": 3.003,
|
||||
"files": [
|
||||
"Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00001-of-00002.gguf",
|
||||
"Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00002-of-00002.gguf"
|
||||
],
|
||||
"repo": "ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF"
|
||||
},
|
||||
"qwen/IQ2_XS": {
|
||||
"arch": "qwen4exp",
|
||||
"tensors": 1224,
|
||||
"bytes": 68015068160,
|
||||
"expert_bytes": {
|
||||
"IQ1_M": 1101004800,
|
||||
"IQ2_S": 18271436800,
|
||||
"IQ2_XXS": 4757913600,
|
||||
"Q2_0": 11324620800
|
||||
},
|
||||
"experts_bpw": 2.348,
|
||||
"bpw": 3.075,
|
||||
"files": [
|
||||
"IQ2_XS/Qwen3.8-Flash-Next-GSQ-RCO-IQ2_XS-00001-of-00002.gguf",
|
||||
"IQ2_XS/Qwen3.8-Flash-Next-GSQ-RCO-IQ2_XS-00002-of-00002.gguf"
|
||||
],
|
||||
"repo": "ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF"
|
||||
},
|
||||
"qwen/IQ3_XXS": {
|
||||
"arch": "qwen4exp",
|
||||
"tensors": 1224,
|
||||
"bytes": 75828974080,
|
||||
"expert_bytes": {
|
||||
"IQ2_S": 5373952000,
|
||||
"IQ2_XS": 4849664000,
|
||||
"IQ2_XXS": 3892838400,
|
||||
"IQ3_S": 9371648000,
|
||||
"IQ3_XXS": 3853516800,
|
||||
"IQ4_NL": 8493465600,
|
||||
"Q2_0": 7077888000
|
||||
},
|
||||
"experts_bpw": 2.842,
|
||||
"bpw": 3.428,
|
||||
"files": [
|
||||
"IQ3_XXS/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00001-of-00002.gguf",
|
||||
"IQ3_XXS/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00002-of-00002.gguf"
|
||||
],
|
||||
"repo": "ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF"
|
||||
},
|
||||
"qwen/IQ3_S": {
|
||||
"arch": "qwen4exp",
|
||||
"tensors": 1224,
|
||||
"bytes": 83606638080,
|
||||
"expert_bytes": {
|
||||
"IQ2_S": 10747904000,
|
||||
"IQ3_S": 7208960000,
|
||||
"IQ3_XXS": 10918297600,
|
||||
"IQ4_NL": 18402508800,
|
||||
"IQ4_XS": 891289600,
|
||||
"Q2_0": 2123366400
|
||||
},
|
||||
"experts_bpw": 3.331,
|
||||
"bpw": 3.78,
|
||||
"files": [
|
||||
"IQ3_S/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf",
|
||||
"IQ3_S/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf"
|
||||
],
|
||||
"repo": "ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF"
|
||||
},
|
||||
"swift/Q2_0": {
|
||||
"arch": "qwen4exp",
|
||||
"tensors": 1224,
|
||||
"bytes": 66538928640,
|
||||
"expert_bytes": {
|
||||
"Q2_0": 33973862400
|
||||
},
|
||||
"experts_bpw": 2.25,
|
||||
"bpw": 3.008,
|
||||
"files": [
|
||||
"Swift-Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00001-of-00002.gguf",
|
||||
"Swift-Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00002-of-00002.gguf"
|
||||
],
|
||||
"repo": "ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF"
|
||||
},
|
||||
"swift/IQ2_XS": {
|
||||
"arch": "qwen4exp",
|
||||
"tensors": 1224,
|
||||
"bytes": 68141143040,
|
||||
"expert_bytes": {
|
||||
"IQ1_M": 1101004800,
|
||||
"IQ2_S": 18271436800,
|
||||
"IQ2_XXS": 4757913600,
|
||||
"Q2_0": 11324620800
|
||||
},
|
||||
"experts_bpw": 2.348,
|
||||
"bpw": 3.081,
|
||||
"files": [
|
||||
"Swift-Qwen3.8-Flash-Next-GSQ-RCO-IQ2_XS-00001-of-00002.gguf",
|
||||
"Swift-Qwen3.8-Flash-Next-GSQ-RCO-IQ2_XS-00002-of-00002.gguf"
|
||||
],
|
||||
"repo": "ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF"
|
||||
},
|
||||
"swift/IQ3_XXS": {
|
||||
"arch": "qwen4exp",
|
||||
"tensors": 1224,
|
||||
"bytes": 75955048960,
|
||||
"expert_bytes": {
|
||||
"IQ2_S": 5373952000,
|
||||
"IQ2_XS": 4849664000,
|
||||
"IQ2_XXS": 3892838400,
|
||||
"IQ3_S": 9371648000,
|
||||
"IQ3_XXS": 3853516800,
|
||||
"IQ4_NL": 8493465600,
|
||||
"Q2_0": 7077888000
|
||||
},
|
||||
"experts_bpw": 2.842,
|
||||
"bpw": 3.434,
|
||||
"files": [
|
||||
"Swift-Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00001-of-00002.gguf",
|
||||
"Swift-Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00002-of-00002.gguf"
|
||||
],
|
||||
"repo": "ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF"
|
||||
},
|
||||
"coder/IQ1_M": {
|
||||
"arch": "qwen4exp",
|
||||
"tensors": 1224,
|
||||
"bytes": 58397560320,
|
||||
"expert_bytes": {
|
||||
"IQ2_S": 5373952000,
|
||||
"IQ3_S": 3604480000,
|
||||
"IQ3_XXS": 5459148800,
|
||||
"IQ4_NL": 9201254400,
|
||||
"IQ4_XS": 445644800,
|
||||
"Q2_0": 1061683200
|
||||
},
|
||||
"experts_bpw": 3.331,
|
||||
"bpw": 4.01,
|
||||
"files": [
|
||||
"IQ1_M/Qwen3.8-Flash-Next-GSQ-RCO-IQ1_M-00001-of-00002.gguf",
|
||||
"IQ1_M/Qwen3.8-Flash-Next-GSQ-RCO-IQ1_M-00002-of-00002.gguf"
|
||||
],
|
||||
"repo": "ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-Coder-GGUF"
|
||||
},
|
||||
"unsloth/UD-IQ4_XS": {
|
||||
"arch": "qwen4exp",
|
||||
"tensors": 1224,
|
||||
"bytes": 93671559680,
|
||||
"expert_bytes": {
|
||||
"IQ3_S": 33882112000,
|
||||
"IQ4_NL": 20289945600,
|
||||
"IQ4_XS": 891289600,
|
||||
"Q8_0": 4456448000
|
||||
},
|
||||
"experts_bpw": 3.942,
|
||||
"bpw": 4.235,
|
||||
"files": [
|
||||
"UD-IQ4_XS/Qwen3.8-Flash-Next-UD-IQ4_XS-00001-of-00003.gguf",
|
||||
"UD-IQ4_XS/Qwen3.8-Flash-Next-UD-IQ4_XS-00002-of-00003.gguf",
|
||||
"UD-IQ4_XS/Qwen3.8-Flash-Next-UD-IQ4_XS-00003-of-00003.gguf"
|
||||
],
|
||||
"repo": "unsloth/Qwen3.8-Flash-Next-GGUF"
|
||||
},
|
||||
"unsloth/UD-Q4_K_XL": {
|
||||
"arch": "qwen4exp",
|
||||
"tensors": 1224,
|
||||
"bytes": 111323630080,
|
||||
"expert_bytes": {
|
||||
"Q4_K": 44354764800,
|
||||
"Q5_1": 27053260800,
|
||||
"Q5_K": 1153433600,
|
||||
"Q8_0": 4456448000
|
||||
},
|
||||
"experts_bpw": 5.101,
|
||||
"bpw": 5.033,
|
||||
"files": [
|
||||
"UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004.gguf",
|
||||
"UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00002-of-00004.gguf",
|
||||
"UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00003-of-00004.gguf",
|
||||
"UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00004-of-00004.gguf"
|
||||
],
|
||||
"repo": "unsloth/Qwen3.8-Flash-Next-GGUF"
|
||||
},
|
||||
"_roles": {
|
||||
"blk.N.attn_gate.weight": [
|
||||
"IQ3_S",
|
||||
"IQ4_XS",
|
||||
"Q2_0",
|
||||
"Q3_K",
|
||||
"Q4_K",
|
||||
"Q5_K",
|
||||
"Q6_K",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.attn_k.weight": [
|
||||
"IQ3_S",
|
||||
"IQ4_XS",
|
||||
"Q3_K",
|
||||
"Q4_K",
|
||||
"Q5_K",
|
||||
"Q6_K",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.attn_k_norm.weight": [
|
||||
"F32"
|
||||
],
|
||||
"blk.N.attn_output.weight": [
|
||||
"IQ3_S",
|
||||
"IQ4_XS",
|
||||
"Q4_K",
|
||||
"Q5_K",
|
||||
"Q6_K",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.attn_q.weight": [
|
||||
"IQ3_S",
|
||||
"IQ4_XS",
|
||||
"Q2_0",
|
||||
"Q3_K",
|
||||
"Q4_K",
|
||||
"Q5_K",
|
||||
"Q6_K",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.attn_q_norm.weight": [
|
||||
"F32"
|
||||
],
|
||||
"blk.N.attn_qkv.weight": [
|
||||
"IQ3_S",
|
||||
"IQ4_XS",
|
||||
"Q2_0",
|
||||
"Q3_K",
|
||||
"Q4_K",
|
||||
"Q5_K",
|
||||
"Q6_K",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.attn_v.weight": [
|
||||
"IQ4_XS",
|
||||
"Q3_K",
|
||||
"Q4_K",
|
||||
"Q5_K",
|
||||
"Q6_K",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.ffn_down_exps.weight": [
|
||||
"IQ4_NL",
|
||||
"Q2_0",
|
||||
"Q5_1",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.ffn_down_shexp.weight": [
|
||||
"IQ4_NL",
|
||||
"Q2_0",
|
||||
"Q4_0",
|
||||
"Q5_0",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.ffn_gate_exps.weight": [
|
||||
"IQ1_M",
|
||||
"IQ2_S",
|
||||
"IQ2_XS",
|
||||
"IQ2_XXS",
|
||||
"IQ3_S",
|
||||
"IQ3_XXS",
|
||||
"IQ4_XS",
|
||||
"Q2_0",
|
||||
"Q4_K",
|
||||
"Q5_K"
|
||||
],
|
||||
"blk.N.ffn_gate_inp.weight": [
|
||||
"BF16",
|
||||
"F32"
|
||||
],
|
||||
"blk.N.ffn_gate_inp_shexp.weight": [
|
||||
"BF16",
|
||||
"F32"
|
||||
],
|
||||
"blk.N.ffn_gate_shexp.weight": [
|
||||
"IQ3_S",
|
||||
"IQ4_XS",
|
||||
"Q2_0",
|
||||
"Q3_K",
|
||||
"Q4_K",
|
||||
"Q5_K",
|
||||
"Q6_K",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.ffn_up_exps.weight": [
|
||||
"IQ1_M",
|
||||
"IQ2_S",
|
||||
"IQ2_XS",
|
||||
"IQ2_XXS",
|
||||
"IQ3_S",
|
||||
"IQ3_XXS",
|
||||
"IQ4_XS",
|
||||
"Q2_0",
|
||||
"Q4_K",
|
||||
"Q5_K"
|
||||
],
|
||||
"blk.N.ffn_up_shexp.weight": [
|
||||
"IQ3_S",
|
||||
"IQ4_XS",
|
||||
"Q2_0",
|
||||
"Q3_K",
|
||||
"Q4_K",
|
||||
"Q5_K",
|
||||
"Q6_K",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.hc_attn_down.weight": [
|
||||
"BF16",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.hc_attn_inject.weight": [
|
||||
"BF16",
|
||||
"F32"
|
||||
],
|
||||
"blk.N.hc_attn_norm.weight": [
|
||||
"F32"
|
||||
],
|
||||
"blk.N.hc_attn_up.weight": [
|
||||
"BF16",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.hc_ffn_down.weight": [
|
||||
"BF16",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.hc_ffn_inject.weight": [
|
||||
"BF16",
|
||||
"F32"
|
||||
],
|
||||
"blk.N.hc_ffn_norm.weight": [
|
||||
"F32"
|
||||
],
|
||||
"blk.N.hc_ffn_up.weight": [
|
||||
"BF16",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.indexer.k_norm.weight": [
|
||||
"F32"
|
||||
],
|
||||
"blk.N.indexer.k_proj.weight": [
|
||||
"BF16"
|
||||
],
|
||||
"blk.N.indexer.q_norm.weight": [
|
||||
"F32"
|
||||
],
|
||||
"blk.N.indexer.q_proj.weight": [
|
||||
"BF16"
|
||||
],
|
||||
"blk.N.ple_conv1d.weight": [
|
||||
"F16",
|
||||
"F32"
|
||||
],
|
||||
"blk.N.ple_key.weight": [
|
||||
"BF16",
|
||||
"Q2_0",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.ple_norm_conv.weight": [
|
||||
"F32"
|
||||
],
|
||||
"blk.N.ple_norm_key.weight": [
|
||||
"F32"
|
||||
],
|
||||
"blk.N.ple_norm_query.weight": [
|
||||
"F32"
|
||||
],
|
||||
"blk.N.ple_value.weight": [
|
||||
"BF16",
|
||||
"Q8_0"
|
||||
],
|
||||
"blk.N.ssm_a": [
|
||||
"F32"
|
||||
],
|
||||
"blk.N.ssm_alpha.weight": [
|
||||
"BF16",
|
||||
"F32"
|
||||
],
|
||||
"blk.N.ssm_beta.weight": [
|
||||
"BF16",
|
||||
"F32"
|
||||
],
|
||||
"blk.N.ssm_conv1d.weight": [
|
||||
"F32"
|
||||
],
|
||||
"blk.N.ssm_dt.bias": [
|
||||
"F32"
|
||||
],
|
||||
"blk.N.ssm_norm.weight": [
|
||||
"F32"
|
||||
],
|
||||
"blk.N.ssm_out.weight": [
|
||||
"IQ3_S",
|
||||
"IQ4_XS",
|
||||
"Q3_K",
|
||||
"Q4_K",
|
||||
"Q5_K",
|
||||
"Q6_K",
|
||||
"Q8_0"
|
||||
],
|
||||
"output.weight": [
|
||||
"IQ4_XS",
|
||||
"Q5_K",
|
||||
"Q6_K",
|
||||
"Q8_0"
|
||||
],
|
||||
"output_hc_down.weight": [
|
||||
"BF16",
|
||||
"Q8_0"
|
||||
],
|
||||
"output_hc_norm.weight": [
|
||||
"F32"
|
||||
],
|
||||
"output_hc_up.weight": [
|
||||
"BF16",
|
||||
"Q8_0"
|
||||
],
|
||||
"per_layer_token_embd.weight": [
|
||||
"IQ4_NL"
|
||||
],
|
||||
"token_embd.weight": [
|
||||
"IQ3_S",
|
||||
"IQ4_XS",
|
||||
"Q3_K",
|
||||
"Q8_0"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<|im_start|>system
|
||||
You are a coding agent working in the user's repository. You can call tools to read files, search the code and run commands. Keep changes small and explain what you did.<|im_end|>
|
||||
<|im_start|>user
|
||||
The test `test_parse_duration` fails since yesterday's merge. Can you find out why and fix it?<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
I should run the failing test first to see the actual error message, then look at the function it tests.
|
||||
</think>
|
||||
|
||||
<tool_call>
|
||||
{"name": "run_command", "arguments": {"command": "python -m pytest tests/test_time_utils.py -k test_parse_duration -q"}}
|
||||
</tool_call><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
F [100%]
|
||||
=================================== FAILURES ===================================
|
||||
_____________________________ test_parse_duration ______________________________
|
||||
|
||||
def test_parse_duration():
|
||||
assert parse_duration("90s") == 90
|
||||
assert parse_duration("5m") == 300
|
||||
> assert parse_duration("1h30m") == 5400
|
||||
E ValueError: invalid duration: '1h30m'
|
||||
|
||||
tests/test_time_utils.py:14: ValueError
|
||||
1 failed, 11 deselected in 0.21s
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
Single units work but a combined value fails. Let me read the parser.
|
||||
</think>
|
||||
|
||||
<tool_call>
|
||||
{"name": "read_file", "arguments": {"path": "src/time_utils.py", "start_line": 1, "end_line": 40}}
|
||||
</tool_call><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
import re
|
||||
|
||||
_UNITS = {"s": 1, "m": 60, "h": 3600, "d": 86400}
|
||||
_PART = re.compile(r"^(\d+)([smhd])$")
|
||||
|
||||
|
||||
def parse_duration(text: str) -> int:
|
||||
"""Parse a duration like '90s', '5m' or '1h30m' into seconds."""
|
||||
text = text.strip().lower()
|
||||
if not text:
|
||||
raise ValueError("empty duration")
|
||||
m = _PART.match(text)
|
||||
if m is None:
|
||||
raise ValueError(f"invalid duration: {text!r}")
|
||||
return int(m.group(1)) * _UNITS[m.group(2)]
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
The regex is anchored at both ends and matches exactly one number-unit pair, so "1h30m" can never match. The docstring promises combined values. Let me check git history to see what the merge changed.
|
||||
</think>
|
||||
|
||||
<tool_call>
|
||||
{"name": "run_command", "arguments": {"command": "git log -p -n 1 -- src/time_utils.py | head -40"}}
|
||||
</tool_call><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
commit 4e1b9c2f7a0d (Merge branch 'cleanup-regex')
|
||||
Simplify duration parsing
|
||||
|
||||
-_PART = re.compile(r"(\d+)([smhd])")
|
||||
+_PART = re.compile(r"^(\d+)([smhd])$")
|
||||
@@ def parse_duration(text: str) -> int:
|
||||
- total = 0
|
||||
- pos = 0
|
||||
- for m in _PART.finditer(text):
|
||||
- if m.start() != pos:
|
||||
- raise ValueError(f"invalid duration: {text!r}")
|
||||
- total += int(m.group(1)) * _UNITS[m.group(2)]
|
||||
- pos = m.end()
|
||||
- if pos != len(text):
|
||||
- raise ValueError(f"invalid duration: {text!r}")
|
||||
- return total
|
||||
+ m = _PART.match(text)
|
||||
+ if m is None:
|
||||
+ raise ValueError(f"invalid duration: {text!r}")
|
||||
+ return int(m.group(1)) * _UNITS[m.group(2)]
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>assistant
|
||||
The cleanup merge replaced the loop over all number-unit pairs with a single anchored match, so only one unit per string is accepted now. I will restore the loop, which also rejects garbage between the parts.
|
||||
|
||||
<tool_call>
|
||||
{"name": "edit_file", "arguments": {"path": "src/time_utils.py", "old": "_PART = re.compile(r\"^(\\d+)([smhd])$\")", "new": "_PART = re.compile(r\"(\\d+)([smhd])\")"}}
|
||||
</tool_call><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
OK: 1 replacement in src/time_utils.py
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>assistant
|
||||
<tool_call>
|
||||
{"name": "edit_file", "arguments": {"path": "src/time_utils.py", "old": " m = _PART.match(text)\n if m is None:\n raise ValueError(f\"invalid duration: {text!r}\")\n return int(m.group(1)) * _UNITS[m.group(2)]", "new": " total = 0\n pos = 0\n for m in _PART.finditer(text):\n if m.start() != pos:\n raise ValueError(f\"invalid duration: {text!r}\")\n total += int(m.group(1)) * _UNITS[m.group(2)]\n pos = m.end()\n if pos != len(text):\n raise ValueError(f\"invalid duration: {text!r}\")\n return total"}}
|
||||
</tool_call><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
OK: 1 replacement in src/time_utils.py
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>assistant
|
||||
<tool_call>
|
||||
{"name": "run_command", "arguments": {"command": "python -m pytest tests/test_time_utils.py -q"}}
|
||||
</tool_call><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
............ [100%]
|
||||
12 passed in 0.19s
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>assistant
|
||||
All 12 tests in `tests/test_time_utils.py` pass again. The cause was the `cleanup-regex` merge: it anchored the pattern with `^...$` and replaced the loop with one `match`, so a duration with several parts such as `1h30m` was rejected. I restored the previous loop, which sums every number-unit pair and still raises `ValueError` for text between or after the parts (for example `1h x30m`). You may want to add a test for that rejection case so the next simplification does not drop it.<|im_end|>
|
||||
@@ -0,0 +1,125 @@
|
||||
"""Minimal GGUF v3 header reader - no ggml, no gguf-py.
|
||||
|
||||
Written because the `gguf` PyPI package cannot open this artifact: its `GGMLQuantizationType`
|
||||
enum has no member for type 42 (`Q2_0`), which is newer than the library. That is itself a P0.S6
|
||||
finding - the format this engine is specialized for is ahead of the standard tooling.
|
||||
|
||||
This is the reference implementation for `src/artifact/` (architecture §15: "GGUF v3 reader (mmap,
|
||||
no ggml dependency)"). It parses the header only; tensor data is never read.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import struct
|
||||
from typing import Any
|
||||
|
||||
GGUF_MAGIC = 0x46554747 # "GGUF" little-endian
|
||||
|
||||
# ggml_type values. 42 = Q2_0, the GSQ-RCO routed-expert encoding, absent from gguf-py as of 0.19.
|
||||
GGML_TYPES: dict[int, str] = {
|
||||
0: "F32", 1: "F16", 2: "Q4_0", 3: "Q4_1", 4: "Q4_2", 5: "Q4_3", 6: "Q5_0", 7: "Q5_1",
|
||||
8: "Q8_0", 9: "Q8_1", 10: "Q2_K", 11: "Q3_K", 12: "Q4_K", 13: "Q5_K", 14: "Q6_K",
|
||||
15: "Q8_K", 16: "IQ2_XXS", 17: "IQ2_XS", 18: "IQ3_XXS", 19: "IQ1_S", 20: "IQ4_NL",
|
||||
21: "IQ3_S", 22: "IQ2_S", 23: "IQ4_XS", 24: "I8", 25: "I16", 26: "I32", 27: "I64",
|
||||
28: "F64", 29: "IQ1_M", 30: "BF16", 31: "Q4_0_4_4", 32: "Q4_0_4_8", 33: "Q4_0_8_8",
|
||||
34: "TQ1_0", 35: "TQ2_0", 36: "IQ4_NL_4_4", 37: "IQ4_NL_4_8", 38: "IQ4_NL_8_8",
|
||||
39: "MXFP4", 40: "NVFP4", 41: "Q4_0_8_8", 42: "Q2_0",
|
||||
}
|
||||
|
||||
# GGUF metadata value type ids
|
||||
GGUF_META = {
|
||||
0: ("u8", 1), 1: ("i8", 1), 2: ("u16", 2), 3: ("i16", 2), 4: ("u32", 4), 5: ("i32", 4),
|
||||
6: ("f32", 4), 7: ("bool", 1), 8: ("string", None), 9: ("array", None),
|
||||
10: ("u64", 8), 11: ("i64", 8), 12: ("f64", 8),
|
||||
}
|
||||
|
||||
# ggml block geometry for the encodings this model uses: (block elements, bytes per block)
|
||||
# This is what makes a per-tensor byte count checkable, and it is the contract the kernels share.
|
||||
BLOCK_GEOMETRY: dict[str, tuple[int, int]] = {
|
||||
"F32": (1, 4), "F16": (1, 2), "BF16": (1, 2), "F64": (1, 8),
|
||||
"Q4_0": (32, 18), "Q4_1": (32, 20), "Q5_0": (32, 22), "Q5_1": (32, 24),
|
||||
"Q8_0": (32, 34), "Q8_1": (32, 36),
|
||||
"Q2_K": (256, 84), "Q3_K": (256, 110), "Q4_K": (256, 144), "Q5_K": (256, 176),
|
||||
"Q6_K": (256, 210), "Q8_K": (256, 292),
|
||||
"IQ2_XXS": (256, 66), "IQ2_XS": (256, 74), "IQ3_XXS": (256, 98), "IQ1_S": (256, 50),
|
||||
"IQ4_NL": (32, 18), "IQ3_S": (256, 110), "IQ2_S": (256, 82), "IQ4_XS": (256, 136),
|
||||
"IQ1_M": (256, 56), "Q2_0": (64, 18), "MXFP4": (32, 17), "NVFP4": (64, 36),
|
||||
}
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class TensorInfo:
|
||||
name: str
|
||||
shape: list[int]
|
||||
type_id: int
|
||||
type_name: str
|
||||
offset: int
|
||||
|
||||
@property
|
||||
def elements(self) -> int:
|
||||
n = 1
|
||||
for d in self.shape:
|
||||
n *= d
|
||||
return n
|
||||
|
||||
def expected_bytes(self) -> int | None:
|
||||
geom = BLOCK_GEOMETRY.get(self.type_name)
|
||||
if geom is None:
|
||||
return None
|
||||
block_elems, block_bytes = geom
|
||||
if self.elements % block_elems:
|
||||
return None
|
||||
return self.elements // block_elems * block_bytes
|
||||
|
||||
|
||||
class GGUFFile:
|
||||
def __init__(self, path: pathlib.Path):
|
||||
self.path = pathlib.Path(path)
|
||||
self.metadata: dict[str, Any] = {}
|
||||
self.tensors: list[TensorInfo] = []
|
||||
self.version = 0
|
||||
self.alignment = 32
|
||||
with self.path.open("rb") as fh:
|
||||
self._parse(fh)
|
||||
self.data_start = self._data_start
|
||||
|
||||
# ------------------------------------------------------------------ internals
|
||||
def _parse(self, fh) -> None:
|
||||
magic = struct.unpack("<I", fh.read(4))[0]
|
||||
if magic != GGUF_MAGIC:
|
||||
raise ValueError(f"{self.path.name}: not a GGUF file (magic {magic:#x})")
|
||||
self.version, n_tensors, n_kv = struct.unpack("<IQQ", fh.read(20))
|
||||
if self.version != 3:
|
||||
raise ValueError(f"{self.path.name}: GGUF v{self.version}, this reader handles v3")
|
||||
for _ in range(n_kv):
|
||||
key = self._str(fh)
|
||||
self.metadata[key] = self._value(fh)
|
||||
for _ in range(n_tensors):
|
||||
name = self._str(fh)
|
||||
(n_dims,) = struct.unpack("<I", fh.read(4))
|
||||
shape = list(struct.unpack(f"<{n_dims}Q", fh.read(8 * n_dims)))
|
||||
type_id, offset = struct.unpack("<IQ", fh.read(12))
|
||||
self.tensors.append(TensorInfo(name, shape, type_id,
|
||||
GGML_TYPES.get(type_id, f"type{type_id}"), offset))
|
||||
align = self.metadata.get("general.alignment")
|
||||
if isinstance(align, int) and align:
|
||||
self.alignment = align
|
||||
pos = fh.tell()
|
||||
self._data_start = (pos + self.alignment - 1) // self.alignment * self.alignment
|
||||
|
||||
def _str(self, fh) -> str:
|
||||
(n,) = struct.unpack("<Q", fh.read(8))
|
||||
return fh.read(n).decode("utf-8", "replace")
|
||||
|
||||
def _value(self, fh):
|
||||
(t,) = struct.unpack("<I", fh.read(4))
|
||||
name, size = GGUF_META[t]
|
||||
if name == "string":
|
||||
return self._str(fh)
|
||||
if name == "array":
|
||||
(et,) = struct.unpack("<I", fh.read(4))
|
||||
(count,) = struct.unpack("<Q", fh.read(8))
|
||||
ename, esize = GGUF_META[et]
|
||||
if ename == "string":
|
||||
return [self._str(fh) for _ in r
|
||||
@@ -0,0 +1,49 @@
|
||||
- **GPU (VRAM):** attention and DeltaNet mixers, the gated-residual weights, routers, shared experts, output head, the MTP
|
||||
draft layer, the KV cache (from 64K: only its most-read part, the rest streams from RAM), and an **expert cache** that fills the rest of VRAM with the most-used experts (it adapts to
|
||||
the conversation while you chat).
|
||||
- **RAM:** all 24,576 experts, pinned. The CPU computes the experts that are not on the GPU **in place**, at the same time
|
||||
as the GPU works on the cached ones (AVX-512 / AVX2 kernels, ggml's for the i-quants).
|
||||
- **SSD:** the 28.8 GB n-gram table, a few rows per token, read unbuffered past the OS cache (`--ple-io direct`, the
|
||||
default, made for SSDs; on a rotational disk `--ple-io ram` keeps the table in RAM, #605). A start-up probe warns when direct reads measure slow (under 15K rows/s) but never switches by itself (since 0.1.43.1; `STRATA_PLE_AUTO_MMAP=1` brings back the 0.1.42 switch to `--ple-io mmap`): the bar is calibrated for NVMe, a SATA SSD tops out at 10-14K rows/s with direct's 16 reads in flight, and on one (Linux, 77.8K-token prompt) mmap read 2.1K rows/s against direct's 14.4K (#2040), while on a Windows box with a slow mapped file mmap stalled prompts (#1984). The engine reads the table
|
||||
in the format the GGUF has it: IQ4_NL (the default table), Q4_0, Q5_0, Q5_1, Q8_0, FP8 (E4M3 with a scale) or BF16.
|
||||
Measured on 4,000 random rows against the checkpoint's own BF16 table, the mean per-row error is Q8_0 0.53%, FP8 2.64%,
|
||||
Q5_1 3.78%, Q5_0 4.25%, IQ4_NL 7.60%, Q4_1 7.80%, Q4_0 8.55% (a Q8_0 table is 54 GB, an IQ4_NL one 28.8 GB). On the Q2_0 model, 700 teacher-forced tokens, the mean KL against the BF16 table is 0.0117 (Q5_0), 0.0121 (Q5_1), 0.0125
|
||||
(Q8_0), 0.0128 (FP8), 0.0140 (Q4_0) and 0.0146 (IQ4_NL), with the perplexity within 1% of BF16's either way: any change to the
|
||||
table moves the 2-bit model by about 0.012, so the formats are hard to tell apart. Setup does not offer another table;
|
||||
it only changes which GGUF the engine is given.
|
||||
- **Speculation:** the model's own MTP layer drafts up to 3 tokens; one pass over all 48 layers checks them. 2.4-3.2
|
||||
tokens per pass on average. When the reply repeats the context (code edits, quoted text), **prompt lookup** (engine
|
||||
0.1.7) drafts up to 5 tokens from the earlier copy, but only where its measured acceptance and cost say it pays:
|
||||
code edits 6-11% faster, other text unchanged. The drafts are checked like the MTP's, so the output is the same.
|
||||
- **Prompts** are processed in chunks of up to 8,192 tokens (`--prefill auto`; 32,768 opt-in) with the experts
|
||||
streamed to the GPU over PCIe. Since engine 0.1.39b (#583) the streamed ring is sized in bytes for the pack (a
|
||||
native pack with bigger blobs gets fewer ring slots and keeps more cache slots) and `--prefill auto` picks the
|
||||
largest chunk that keeps that ring full. It only gives up ring slots where 0.1.39's rule held the chunk at 4,096
|
||||
tokens or less; from 6,144 on it keeps 0.1.39's ring and only looks for a bigger chunk beside it (shrinking the
|
||||
ring there measured slower: the Coder -12%), and a prompt that fits 0.1.39's chunk keeps 0.1.39's ring (one
|
||||
chunk: a smaller ring only slowed it). RTX 5070, 32K prompts against `STRATA_RING_BYTES=0`, 2-3 interleaved
|
||||
rounds: IQ3_XXS +18.5% at a 1,500-slot cache and +9% in another memory state, the Coder +3%, IQ3_S unchanged; 4K
|
||||
prompts unchanged (-0.7% to +1.1%, bit-identical). Q2_0 (a fixed `--prefill 2048`) is not affected. It changes
|
||||
the bits of a long prompt against 0.1.39 (the experts go through a different
|
||||
mix of cached and streamed groups). Measured quality, teacher-forced over the next 2,001 tokens of a long document
|
||||
against the FP16 prompt path (IQ3_XXS, `--prefill auto`): 8K prompt KL 0.042 (0.1.39: 0.054), top-1 agreement
|
||||
93.5% (92.2%); 32K prompt KL 0.020 (0.019), top-1 95.3% (95.0%) - the same band as before. `STRATA_RING_BYTES=0`
|
||||
restores 0.1.39's ring, loan and chunk choice.
|
||||
|
||||
The full story, with measurements, bottlenecks and what comes next: **[docs/paper/Strata-Paper.pdf](paper/Strata-Paper.pdf)**.
|
||||
|
||||
---
|
||||
|
||||
## Credits and licenses
|
||||
|
||||
Strata itself: [MIT](../LICENSE). The model files are not part of it; their licenses apply to them (below).
|
||||
|
||||
- Model: [Qwen/Qwen3.8-Flash-Next](https://huggingface.co/Qwen/Qwen3.8-Flash-Next) by the Qwen team; quantizations:
|
||||
[ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF](https://huggingface.co/ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF).
|
||||
The Coder: [ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-Coder-GGUF](https://huggingface.co/ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-Coder-GGUF)
|
||||
(Apache-2.0 per its card); its support in Strata came from @pjgmobile's PR #54.
|
||||
Swift 1.5: [ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF](https://huggingface.co/ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF)
|
||||
by UkisAI. Their licenses apply to the weights.
|
||||
- [llama.cpp / ggml](https://github.com/ggml-org/llama.cpp) (MIT): the i-quant formats, the GPU dot products and
|
||||
dequantizers transcribed in `src/kernels/cuda/iq_kernels.cu`, the CPU backend linked for the i-quant experts, the
|
||||
`mtmd` library behind the image encoder (`tools/vision/`), and `gguf-py` use
|
||||
@@ -0,0 +1,17 @@
|
||||
The lighthouse at the end of the northern breakwater had been automated for almost forty years, but the town still sent someone out to it every Thursday. Nobody remembered who had made the rule, and nobody had ever written it down. It was simply understood that on Thursday afternoon, when the ferry had left and the fish market had been hosed clean, one person would walk the length of the stone pier, unlock the iron door with the key that hung behind the counter of the harbour office, climb the hundred and twelve steps, and look.
|
||||
|
||||
For most of that time the person had been Margaret Hale, who ran the chandlery and claimed she needed the exercise. When her knees finally gave out, the key passed to her grandson Tomas, who was fourteen and considered the whole business a waste of a perfectly good afternoon. He said so, loudly, for the first three weeks. On the fourth Thursday a storm came in early from the west, and he found himself at the top of the tower watching a small sailing boat fight its way past the outer rocks with a torn jib and nobody visibly at the helm.
|
||||
|
||||
He did what his grandmother had told him to do, which was nothing dramatic. He wrote down the time, the direction of the wind, the name painted on the stern, and the fact that he could see only one person on deck. Then he walked back down the hundred and twelve steps, crossed the pier with his hood pulled tight, and told the harbour master, who telephoned the lifeboat station. The boat was towed in an hour later. Its skipper, a retired schoolteacher who had been sailing alone from the islands, had broken his wrist when the boom swung across and had been steering with his feet.
|
||||
|
||||
The story was in the local paper the following week, and Tomas was embarrassed by it, mostly because the photograph showed him in his school uniform. What stayed with him was something else. On the walk back along the pier that evening, the harbour master had told him that the automated light had worked perfectly the whole time. It had turned, it had flashed its pattern, and it had done exactly what it was built to do. The light could warn a boat away from the rocks, but it could not notice that a boat was in trouble. Only a person could do that, and only if a person was there to look.
|
||||
|
||||
People in the town sometimes talk about that rule now as though it had been a clever piece of planning, a deliberate safeguard against the limits of machines. Tomas does not think it was anything of the kind. He thinks it began because somebody missed the old keeper and could not quite bring themselves to stop going out to the tower, and that it continued because nobody wanted to be the one to end it. Habits are like that. They outlast their reasons, and every so often, without anyone planning it, they find a new one.
|
||||
|
||||
He is twenty-six now and works as an engineer on the offshore wind farm that you can see from the top of the lighthouse on a clear day: two hundred white turbines standing in rows on the horizon, each one watched by sensors that report vibration, temperature and blade pitch to a control room in another country. The systems are very good. They catch almost everything. He still goes out to the tower on Thursdays when he is home, climbs the steps, and looks.
|
||||
|
||||
Ask him why, and he will tell you a story that has nothing to do with lighthouses. In his second year on the wind farm, a monitoring system flagged a slow rise in the temperature of a gearbox on one of the turbines at the far end of the array. The rise was small, well inside the limits, and the software ranked it as low priority. It would have been looked at during the next scheduled visit, six weeks later. A technician on the maintenance boat, passing the turbine on another job, noticed that the nacelle sounded different, a faint grinding note under the usual hum, and asked the skipper to stop. When they opened the gearbox they found a bearing that was a few days from failing. Replacing it cost a morning. Replacing the gearbox after the bearing failed would have cost a month and the price of a small house.
|
||||
|
||||
The technician was not cleverer than the software. She had simply been there, close enough to hear, and curious enough to ask for the boat to stop. The data had shown the same problem; it had just not shown it loudly enough for anyone to care. Tomas thinks about that often. Every system he has worked on has been very good at measuring the things its designers expected to go wrong, and much less good at the things nobody expected. The gap between the two is where people still earn their keep, not by doing the machine's job better than the machine, but by noticing when the job itself has quietly changed.
|
||||
|
||||
So on Thursdays, when he can, he walks out along the pier. The stone is worn smooth in a line down the middle where generations of boots have gone the same way. The iron door still sticks in wet weather. The view from the top has changed more in the last ten years than in the hundred before, and he likes to see it for himself.
|
||||
@@ -0,0 +1,116 @@
|
||||
Strata lässt **[Qwen3.8-Flash-Next](https://huggingface.co/Qwen/Qwen3.8-Flash-Next)** auf einem normalen PC laufen.
|
||||
Das ist ein großes, kluges KI-Modell, das sonst meist einen Server braucht. Es chattet, schreibt Code, versteht
|
||||
Bilder und arbeitet mit deinen Apps und Coding-Agents zusammen. Nichts verlässt deinen PC.
|
||||
|
||||
## Wie schnell ist es?
|
||||
|
||||
Wir haben es auf zwei ganz normalen Gaming-PCs gemessen. Ein Token ist etwa ¾ eines Wortes.
|
||||
|
||||
- **Schreibt Antworten:** wie schnell die Antwort in einem kurzen Chat erscheint. 60 Tokens pro Sekunde sind
|
||||
schneller, als du lesen kannst.
|
||||
- **Liest deinen Prompt:** wie schnell es aufnimmt, was du schickst (hier ein Dokument, Code oder Chatverlauf mit
|
||||
32K Tokens).
|
||||
|
||||
<table>
|
||||
<tr><th>NVIDIA: RTX 5070 (12 GB), Ryzen 5 7600, 64 GB RAM</th><th>AMD: RX 9070 XT (16 GB), Ryzen 9 3900X, 47 GB RAM</th></tr>
|
||||
<tr><td>
|
||||
|
||||
| Größe | Schreibt Antworten | Liest deinen Prompt |
|
||||
| --- | ---: | ---: |
|
||||
| **Q2_0** | 94 Tokens/s | 2,650 Tokens/s |
|
||||
| **IQ2_XS** | 79 Tokens/s | 2,090 Tokens/s |
|
||||
| **IQ3_XXS** | 62 Tokens/s | 1,750 Tokens/s |
|
||||
| **IQ3_S** | 53 Tokens/s | 1,620 Tokens/s |
|
||||
| **Coder** | 55 Tokens/s | 2,180 Tokens/s |
|
||||
|
||||
</td><td>
|
||||
|
||||
| Größe | Schreibt Antworten | Liest deinen Prompt |
|
||||
| --- | ---: | ---: |
|
||||
| **Q2_0** | 60 Tokens/s | 1,160 Tokens/s |
|
||||
| **IQ2_XS** | 52 Tokens/s | 1,110 Tokens/s |
|
||||
| **Coder** | 44 Tokens/s | 1,420 Tokens/s |
|
||||
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
NVIDIA: Q2_0 mit Engine 0.1.36, die anderen Zeilen mit 0.1.26 (4K Antworten, 32K Prompts). Die vollständigen
|
||||
Tabellen stehen in [DETAILS.md](docs/DETAILS.md#speed-measured). Eine Karte mit mehr VRAM ist schneller: Eine
|
||||
RTX 3090 (24 GB) sollte etwa 100-140 Tokens pro Sekunde schreiben. Lange Chats un
|
||||
|
||||
Strata fait tourner **[Qwen3.8-Flash-Next](https://huggingface.co/Qwen/Qwen3.8-Flash-Next)** sur un PC normal. C'est
|
||||
un grand modèle d'IA, très capable, qui demande d'habitude un serveur. Il discute, écrit du code, lit des images et
|
||||
fonctionne avec vos applications et vos agents de code. Rien ne quitte votre PC.
|
||||
|
||||
## Quelle est sa vitesse ?
|
||||
|
||||
Nous l'avons mesurée sur deux PC de jeu ordinaires. Un token correspond à environ ¾ d'un mot.
|
||||
|
||||
- **Écrit les réponses :** la vitesse à laquelle la réponse s'affiche dans une courte discussion. 60 tokens par seconde, c'est plus rapide que votre lecture.
|
||||
- **Lit votre prompt :** la vitesse à laquelle il absorbe ce que vous envoyez (ici un document, du code ou un historique de discussion de 32K tokens).
|
||||
|
||||
<table>
|
||||
<tr><th>NVIDIA : RTX 5070 (12 Go), Ryzen 5 7600, 64 Go de RAM</th><th>AMD : RX 9070 XT (16 Go), Ryzen 9 3900X, 47 Go de RAM</th></tr>
|
||||
<tr><td>
|
||||
|
||||
| Taille | Écrit les réponses | Lit votre prompt |
|
||||
| --- | ---: | ---: |
|
||||
| **Q2_0** | 94 tokens/s | 2,650 tokens/s |
|
||||
| **IQ2_XS** | 79 tokens/s | 2,090 tokens/s |
|
||||
| **IQ3_XXS** | 62 tokens/s | 1,750 tokens/s |
|
||||
| **IQ3_S** | 53 tokens/s | 1,620 tokens/s |
|
||||
| **Coder** | 55 tokens/s | 2,180 tokens/s |
|
||||
|
||||
</td><td>
|
||||
|
||||
| Taille | Écrit les réponses | Lit votre prompt |
|
||||
| --- | ---: | ---: |
|
||||
| **Q2_0** | 60 tokens/s | 1,160 tokens/s |
|
||||
| **IQ2_XS** | 52 tokens/s | 1,110 tokens/s |
|
||||
| **Coder** | 44 tokens/s | 1,420 tokens/s |
|
||||
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
NVIDIA : Q2_0 avec le moteur 0.1.36, les autres lignes ave
|
||||
|
||||
Strata を使うと、**[Qwen3.8-Flash-Next](https://huggingface.co/Qwen/Qwen3.8-Flash-Next)** を一般的な PC で動かせます。
|
||||
通常はサーバーを必要とする大規模で高性能な AI モデルで、チャットやコードの生成、画像の読み取りができます。
|
||||
アプリやコーディングエージェントとも連携でき、データは PC の外に送信されません。
|
||||
|
||||
## どのくらい速い?
|
||||
|
||||
一般的なゲーミング PC 2 台で速度を測定しました。英語の場合、1 トークンはおよそ ¾ 語に相当します。
|
||||
|
||||
- **生成速度:** 短いチャットで回答を生成する速度です。毎秒 60 トークンなら、人が読むよりも速く文章が表示されます。
|
||||
- **プロンプトの読み込み:** 入力した内容を読み込む速度です。ここでは、文書やコード、チャット履歴など 32K トークン分を読み込ませています。
|
||||
|
||||
<table>
|
||||
<tr><th>NVIDIA: RTX 5070 (12 GB), Ryzen 5 7600, 64 GB RAM</th><th>AMD: RX 9070 XT (16 GB), Ryzen 9 3900X, 47 GB RAM</th></tr>
|
||||
<tr><td>
|
||||
|
||||
| モデルサイズ | 生成速度 | プロンプトの読み込み |
|
||||
| --- | ---: | ---: |
|
||||
| **Q2_0** | 94 tokens/s | 2,650 tokens/s |
|
||||
| **IQ2_XS** | 79 tokens/s | 2,090 tokens/s |
|
||||
|
|
||||
|
||||
Strata 能在普通电脑上运行 **[Qwen3.8-Flash-Next](https://huggingface.co/Qwen/Qwen3.8-Flash-Next)**。这是一个又大又聪明的
|
||||
AI 模型,通常要用服务器才能跑。它能聊天、写代码、看图片,还能配合你的应用和编程智能体一起工作。所有数据都留在你的电脑上。
|
||||
|
||||
## 速度有多快?
|
||||
|
||||
我们在两台普通的游戏电脑上做了测试。一个 token 大约相当于 ¾ 个英文单词。
|
||||
|
||||
- **写回答:** 短对话中回复出现的速度。每秒 60 个 token 已经比你的阅读速度还快。
|
||||
- **读提示:** 读入你发送内容的速度(这里是一份 32K token 的文档、代码或聊天记录)。
|
||||
|
||||
<table>
|
||||
<tr><th>NVIDIA:RTX 5070(12 GB)、Ryzen 5 7600、64 GB 内存</th><th>AMD:RX 9070 XT(16 GB)、Ryzen 9 3900X、47 GB 内存</th></tr>
|
||||
<tr><td>
|
||||
|
||||
| 规格 | 写回答 | 读提示 |
|
||||
| --- | ---: | ---: |
|
||||
| **Q2_0** | 94 tokens/s | 2,650 tokens/s |
|
||||
| **IQ2_XS** | 79 tokens/s | 2,090 tokens/s |
|
||||
| **IQ3_XXS**
|
||||
@@ -0,0 +1 @@
|
||||
{"version": "v1", "seg_tokens": 1000, "segments": [{"name": "code", "ids": [12237, 85286, 54802, 19913, 343, 18, 4108, 6396, 471, 874, 50285, 980, 11, 874, 50285, 1644, 2195, 88, 13, 271, 34447, 1521, 279, 1510, 13985, 1644, 63, 5187, 1828, 6129, 4021, 1724, 411, 35426, 25, 1141, 1510, 21563, 2581, 42750, 1954, 900, 63, 198, 8746, 682, 874, 4314, 364, 913, 220, 19, 17, 27718, 48, 17, 62, 15, 63, 681, 864, 369, 24733, 1056, 279, 6522, 13, 2844, 369, 4924, 264, 387, 15, 782, 21, 198, 64919, 471, 279, 3443, 411, 4560, 369, 26208, 364, 369, 8047, 314, 279, 5129, 5224, 286, 13, 271, 1919, 369, 279, 5604, 7873, 364, 1510, 3431, 53683, 20123, 14, 63, 318, 77646, 16137, 16, 20, 25, 328, 21563, 19913, 343, 18, 6396, 318, 76, 2117, 11, 198, 2083, 50285, 980, 23285, 61406, 1049, 68434, 279, 4108, 1132, 26, 15167, 795, 369, 2496, 1301, 13, 198, 12237, 198, 1445, 1259, 20409, 548, 1120, 31144, 271, 464, 795, 8588, 198, 464, 51372, 198, 464, 1968, 198, 1445, 18904, 1120, 5586, 271, 21563, 19913, 47540, 283, 220, 15, 87, 19, 21, 20, 20, 19, 22, 19, 22, 220, 653, 328, 21563, 19913, 1, 2545, 12692, 1068, 271, 2, 50285, 980, 1756, 2663, 13, 220, 19, 17, 283, 1167, 17, 62, 15, 11, 279, 34100, 48, 12, 7146, 46, 69764, 17830, 517, 10845, 11, 26334, 494, 50285, 1644, 2195, 88, 430, 314, 220, 15, 13, 16, 24, 13, 198, 21563, 2581, 24973, 25, 6249, 18078, 11, 592, 60, 283, 313, 198, 262, 220, 15, 25, 328, 37, 18, 17, 487, 220, 16, 25, 328, 37, 16, 21, 487, 220, 17, 25, 328, 48, 19, 62, 15, 487, 220, 18, 25, 328, 48, 19, 62, 16, 487, 220, 19, 25, 328, 48, 19, 62, 17, 487, 220, 20, 25, 328, 48, 19, 62, 18, 487, 220, 21, 25, 328, 48, 20, 62, 15, 487, 220, 22, 25, 328, 48, 20, 62, 16, 487, 198, 262, 220, 23, 25, 328, 48, 23, 62, 15, 487, 220, 24, 25, 328, 48, 23, 62, 16, 487, 220, 16, 15, 25, 328, 48, 17, 9802, 487, 220, 16, 16, 25, 328, 48, 18, 9802, 487, 220, 16, 17, 25, 328, 48, 19, 9802, 487, 220, 16, 18, 25, 328, 48, 20, 9802, 487, 220, 16, 19, 25, 328, 48, 21, 9802, 487, 198, 262, 220, 16, 20, 25, 328, 48, 23, 9802, 487, 220, 16, 21, 25, 328, 59865, 17, 62, 5955, 50, 487, 220, 16, 22, 25, 328, 59865, 17, 6645, 50, 487, 220, 16, 23, 25, 328, 59865, 18, 62, 5955, 50, 487, 220, 16, 24, 25, 328, 59865, 16, 1063, 487, 220, 17, 15, 25, 328, 59865, 19, 1548, 43, 487, 198, 262, 220, 17, 16, 25, 328, 59865, 18, 1063, 487, 220, 17, 17, 25, 328, 59865, 17, 1063, 487, 220, 17, 18, 25, 328, 59865, 19, 6645, 50, 487, 220, 17, 19, 25, 328, 40, 23, 487, 220, 17, 20, 25, 328, 40, 16, 21, 487, 220, 17, 21, 25, 328, 40, 18, 17, 487, 220, 17, 22, 25, 328, 40, 21, 19, 487, 198, 262, 220, 17, 23, 25, 328, 37, 21, 19, 487, 220, 17, 24, 25, 328, 59865, 16, 1203, 487, 220, 18, 15, 25, 328, 19278, 16, 21, 487, 220, 18, 16, 25, 328, 48, 19, 62, 15, 62, 19, 62, 19, 487, 220, 18, 17, 25, 328, 48, 19, 62, 15, 62, 19, 62, 23, 487, 220, 18, 18, 25, 328, 48, 19, 62, 15, 62, 23, 62, 23, 487, 198, 262, 220, 18, 19, 25, 328, 51, 48, 16, 62, 15, 487, 220, 18, 20, 25, 328, 51, 48, 17, 62, 15, 487, 220, 18, 21, 25, 328, 59865, 19, 1548, 43, 62, 19, 62, 19, 487, 220, 18, 22, 25, 328, 59865, 19, 1548, 43, 62, 19, 62, 23, 487, 220, 18, 23, 25, 328, 59865, 19, 1548, 43, 62, 23, 62, 23, 487, 198, 262, 220, 18, 24, 25, 328, 28463, 11361, 19, 487, 220, 19, 15, 25, 328, 35125, 11361, 19, 487, 220, 19, 16, 25, 328, 48, 19, 62, 15, 62, 23, 62, 23, 487, 220, 19, 17, 25, 328, 48, 17, 62, 15, 487, 198, 92, 271, 2, 54802, 19913, 10836, 869, 913, 13746, 198, 21563, 19913, 57818, 283, 313, 198, 262, 220, 15, 25, 3376, 84, 23, 487, 220, 16, 681, 220, 16, 25, 3376, 72, 23, 487, 220, 16, 681, 220, 17, 25, 3376, 84, 16, 21, 487, 220, 17, 681, 220, 18, 25, 3376, 72, 16, 21, 487, 220, 17, 681, 220, 19, 25, 3376, 84, 18, 17, 487, 220, 19, 681, 220, 20, 25, 3376, 72, 18, 17, 487, 220, 19, 681, 198, 262, 220, 21, 25, 3376, 69, 18, 17, 487, 220, 19, 681, 220, 22, 25, 3376, 2554, 487, 220, 16, 681, 220, 23, 25, 3376, 889, 487, 2168, 681, 220, 24, 25, 3376, 1595, 487, 2168, 681, 198, 262, 220, 16, 15, 25, 3376, 84, 21, 19, 487, 220, 23, 681, 220, 16, 16, 25, 3376, 72, 21, 19, 487, 220, 23, 681, 220, 16, 17, 25, 3376, 69, 21, 19, 487, 220, 23, 681, 198, 92, 271, 2, 50285, 980, 2424, 16547, 364, 279, 3107, 56373, 411, 1558, 5533, 25, 318, 4425, 5255, 11, 5639, 791, 2424, 8, 198, 2, 1061, 369, 1092, 3520, 264, 791, 2308, 3677, 4763, 1698, 1716, 470, 11, 321, 424, 369, 279, 4954, 279, 61369, 4191, 13, 198, 38637, 57038, 83072, 25, 6249, 16793, 11, 13992, 18078, 11, 514, 4891, 283, 313, 198, 262, 328, 37, 18, 17, 763, 318, 16, 11, 220, 19, 681, 328, 37, 16, 21, 763, 318, 16, 11, 220, 17, 681, 328, 19278, 16, 21, 763, 318, 16, 11, 220, 17, 681, 328, 37, 21, 19, 763, 318, 16, 11, 220, 23, 681, 198, 262, 328, 48, 19, 62, 15, 763, 318, 18, 17, 11, 220, 16, 23, 681, 328, 48, 19, 62, 16, 763, 318, 18, 17, 11, 220, 17, 15, 681, 328, 48, 20, 62, 15, 763, 318, 18, 17, 11, 220, 17, 17, 681, 328, 48]}, {"name": "docs", "ids": [12, 2972, 48213, 318, 18232, 1354, 188912, 6326, 321, 24167, 6738, 6311, 382, 11, 27Line truncated
|
||||
Binary file not shown.
@@ -0,0 +1,761 @@
|
||||
# A770 decode optimization specification
|
||||
|
||||
## Objective and completion criteria
|
||||
|
||||
Achieve **at least 20 generated tokens/second in decode on the local Intel Arc
|
||||
A770 running PolyStrata**, with reproducible benchmark evidence and correct output.
|
||||
This specification describes the next optimization campaign; it does not claim
|
||||
that the target has already been met.
|
||||
|
||||
Completion requires:
|
||||
|
||||
1. Run the same Qwen3.8-Flash-Next Coder IQ1_M pack, tokenizer and MTP artifacts
|
||||
used for the existing measurements, on the A770 alone.
|
||||
2. Preserve the current 131,072-token context capacity and INT8 KV configuration
|
||||
for the primary comparison. Label shorter-context experiments separately.
|
||||
3. Demonstrate >=20 tok/s median engine decode throughput across at least three
|
||||
warmed repetitions of the representative coding workload, generating at least
|
||||
256 tokens per repetition unless the model reaches a natural stop first.
|
||||
Report shorter natural-stop samples separately rather than substituting them
|
||||
for the sustained-throughput gate.
|
||||
4. Count reasoning tokens consistently with the previous engine measurements.
|
||||
Report final-answer content and finish reason as well as speed. A repeated
|
||||
garbage stream, an artificial repetitive-token workload, or a cached response
|
||||
is not a valid success measurement.
|
||||
5. Pass the correctness gates below, including a final `41` for the original
|
||||
arithmetic regression prompt and executed tests for a generated coding answer.
|
||||
6. Make the selected implementation and run configuration reproducible from the
|
||||
recorded source revision, build options and config. Kernel microbenchmarks,
|
||||
expected gains, or a single favorable request do not close the decode goal.
|
||||
|
||||
## Verified baseline and hardware
|
||||
|
||||
- Worktree: a local PolyStrata v0.1.40.3 checkout.
|
||||
- Current source baseline: `501f675727ae8a54abed3ec467de1cbfbecd03ea`, branch
|
||||
`a770-speed-upstream`, based on upstream `main` at `fb58e0d` when last checked.
|
||||
- Existing upstream work: correctness PR #1602 and draft performance PR #1710.
|
||||
- Engine binary: `build-sycl/strata`; reports engine 0.1.41.
|
||||
- GPU: Intel Arc A770, PCI `0000:06:00.0`, device id `56a0`, `xe` driver,
|
||||
`ONEAPI_DEVICE_SELECTOR=level_zero:1`. B580 at `level_zero:0` drives the display
|
||||
and is outside this single-A770 benchmark.
|
||||
- CPU: Ryzen 5 5600, six cores/twelve threads, AVX2; approximately 31 GiB RAM.
|
||||
- A770 is behind the chipset's PCIe 3.0 x4 connection. Engine transfer probes
|
||||
measured 1.7-1.8 GB/s. Do not infer the loaded link from the GPU endpoint's
|
||||
idle sysfs speed alone; record the upstream bridge and the measured transfer.
|
||||
- Build/runtime: oneAPI 2026.1 inside `strata-sycl-dev`.
|
||||
|
||||
Measured progress, not estimates:
|
||||
|
||||
| Configuration | Warm decode | Notes |
|
||||
| --- | --- | --- |
|
||||
| Pinned mirror, 4.46 GiB VRAM experts | about 2.5 tok/s | Most missing experts read by GPU over PCIe |
|
||||
| CPU misses, larger cache and tuned prompt reservation | about 9-11 tok/s | Same context capacity |
|
||||
| Fast router plus borrowing and paired mapped transfers | 13.5, 11.9, 12.3 tok/s | 546 input tokens, 128 generated, no prefix reuse |
|
||||
| Same final configuration, short warm prompt | 11.4 tok/s | 73 input tokens, 128 generated |
|
||||
|
||||
The final configuration had 4,717 expert slots, approximately 8.98 GiB in VRAM
|
||||
and 15.08 GiB of resident RAM experts. Existing runs did not test a full 128K
|
||||
prompt. The fast router's isolated 256-expert/top-10 timing improved from
|
||||
395.47 to 118.62 microseconds per call, with bitwise matching results.
|
||||
|
||||
Artifacts from the earlier campaign live in a temporary directory:
|
||||
`a770-speed-results.json`, `a770-tuning-round2-results.json`,
|
||||
`a770-tuning-round3-results.json`, `a770-tuning-round4-results.json`,
|
||||
`a770-tuning-paired-results.json`, their config files, and engine logs.
|
||||
They are useful historical evidence, but temporary paths are not durable
|
||||
deliverables for a completed optimization.
|
||||
|
||||
## Scope and constraints
|
||||
|
||||
- Optimize the current SYCL engine rather than changing model weights or swapping
|
||||
to an unrelated inference engine. Keep the >4 GiB kernel-address build fix.
|
||||
- Preserve BF16 weight interpretation, FP32 accumulation contracts, routing
|
||||
semantics, MTP verification and the payload checksum. Faster FP16 arithmetic
|
||||
is a separate numerical experiment, not a silent BF16 replacement.
|
||||
- Keep an old/reference path selectable for every new dispatch. Default changes
|
||||
require parity and served-output validation.
|
||||
- Tune per kernel and per architecture. Do not globally change subgroup 32 to 8
|
||||
or 16 while CUDA-shaped shuffle and reduction code still assumes 32 lanes.
|
||||
- Avoid executing another repository's build scripts while studying it; port
|
||||
selected techniques with their license notices and tests.
|
||||
- No automatic commits, pushes, PR updates or changes to the user's normal run
|
||||
config are implied by this specification. Keep experimental configs separate.
|
||||
- Record CPU/RAM contention, available RAM, swap activity and GPU clocks before
|
||||
each full-model test. Ask before closing newly opened user applications.
|
||||
|
||||
## Work package 1: reliable event-based measurements
|
||||
|
||||
### Problem
|
||||
|
||||
The original base stage profiler wrote zero timestamps. The experimental port
|
||||
uses a host thread continuously updating a host USM clock word while the GPU
|
||||
reads it uncached. Review flagged the atomic-host/non-atomic-device clock access
|
||||
as lacking a correctness-guaranteed synchronization contract. Enabled runs also
|
||||
reported `layer ... rang but its payload never arrived whole`; the causal link
|
||||
between these facts is unproven.
|
||||
|
||||
### Initial implementation
|
||||
|
||||
Add an isolated SYCL event benchmark for the BF16 projection family. Its queue
|
||||
must share the chosen device/context and have both `in_order` and
|
||||
`enable_profiling`. Device memory and launches must use that same queue.
|
||||
|
||||
Measure a warmed batch using device event timestamps, with native queue marker
|
||||
kernels delimiting the batch if the public launcher does not return its kernel
|
||||
event. Wait only after all measured submissions are enqueued. Report this as a
|
||||
**device queue span**, including any inter-command scheduling gaps; do not label
|
||||
it a pure per-kernel execution duration. Also report host wall time and the
|
||||
empty-marker span so that marker overhead and submission starvation are visible.
|
||||
|
||||
The initial benchmark must not enable `STRATA_VERIFY_PROFILE`, start a host
|
||||
clock writer, record a command graph, or query an event while it is still pending.
|
||||
Require nonzero and monotonically ordered start/end timestamps; otherwise fail
|
||||
with a useful diagnostic rather than print a zero or wrapped duration.
|
||||
|
||||
### Subsequent integration
|
||||
|
||||
For eager diagnostic launches, collect each operation's returned `sycl::event`
|
||||
in a bounded host-side collection and query profiling start/end only after
|
||||
completion. Label eager timings separately from captured-graph production rates.
|
||||
Do not assume recording-time node events contain timestamps for each replay of
|
||||
a command graph. A graph-node profiler needs a supported replay profiling API;
|
||||
otherwise benchmark constituent kernels separately and validate whole-window
|
||||
time with normal uninstrumented graph replay.
|
||||
|
||||
The unsafe host-clock profiler must remain disabled in every speed acceptance
|
||||
run. Replacing it must remove the busy writer and retain clear behavior when
|
||||
profiling is unavailable. Profiling instrumentation must be opt-in and must not
|
||||
alter the synchronization of the ordinary expert-pool path.
|
||||
|
||||
### Output schema
|
||||
|
||||
Every benchmark row must include: source revision, device name and PCI identity
|
||||
when available, queue mode, compiler/backend options, family, implementation,
|
||||
N/K/T dimensions, input/output leading dimensions, repeat count, warm-up count,
|
||||
device-span median/minimum, host wall time, empty-marker cost, effective weight
|
||||
bandwidth, correctness result and output hash. Do not turn absence of data into
|
||||
a passing or faster result.
|
||||
|
||||
## Work package 2: existing few-token BF16 projection paths
|
||||
|
||||
### First comparison
|
||||
|
||||
Compare the default `bf16_gemv_fp32_mmvf_multi` path with
|
||||
`STRATA_MMVF_ROWS=1`. The latter is already implemented in
|
||||
`sycl/src/kernels/cuda/native_bf16.dp.cpp`; its selector is cached on first use.
|
||||
Run each mode in a separate process, setting the environment before any launch.
|
||||
Do not change `setenv` between measurements in one process and assume the cached
|
||||
selector will change.
|
||||
|
||||
For each mode, compare against one independent single-token MMVF call per output
|
||||
column. Check exact output bits where that is the implementation's contract.
|
||||
Use an FP64 CPU oracle for a bounded subset as a second check; the oracle does
|
||||
not replace the bitwise old/new comparison.
|
||||
|
||||
### Shape matrix
|
||||
|
||||
Interpret shapes as `[N output rows, K input columns]`, applied to T activation
|
||||
vectors. Use T in `{1, 2, 3, 4, 6, 8}` and at least:
|
||||
|
||||
| N | K | Purpose |
|
||||
| ---: | ---: | --- |
|
||||
| 4 | 10240 | Hyper-connection inject; few output rows |
|
||||
| 320 | 10240 | Hyper-connection down |
|
||||
| 10240 | 320 | Hyper-connection up |
|
||||
| 256 | 2560 | Coder router |
|
||||
| 2560 | 2560 | Dense projection |
|
||||
| 10240 | 2560 | Wide dense projection |
|
||||
|
||||
Include padded even `ldx` and `ldy`, a non-full output tile (for example N=65),
|
||||
zero-size/no-op or rejected shapes according to the public API, guard regions,
|
||||
finite random data, all-zero inputs and scale-extreme finite data. Record which
|
||||
shapes actually select the row kernel; N<64 currently falls back.
|
||||
|
||||
Only move a winner into the engine when a matched-config A/B run shows a useful
|
||||
improvement. If the row kernel helps a narrow class and regresses another, use a
|
||||
shape-specific dispatch rather than a global new default.
|
||||
|
||||
## Work package 3: targeted register and subgroup tuning
|
||||
|
||||
Investigate 128- versus 256-GRF compilation on register-heavy A770 kernels,
|
||||
preserving the existing backend options including
|
||||
`-ze-opt-greater-than-4GB-buffer-required` and correctly rounded divide/sqrt.
|
||||
Confirm the actual emitted compile option and reject unsupported options.
|
||||
|
||||
Candidate subgroup sizes are 8/16/32 only where the reduction and work-group
|
||||
geometry can be adapted. Initial targets: BF16 projection rows, GDN recurrence,
|
||||
hyper-connection down/up and quantized dense MMVQ. Record register spills or ISA
|
||||
evidence when toolchain dumps are available. More registers can reduce occupancy;
|
||||
an accepted flag alone is not evidence of a speed improvement.
|
||||
|
||||
Evaluate one variable at a time first. Then evaluate combined winners. Each
|
||||
matrix must include the two-to-four-token regime used by the actual verifier,
|
||||
not only large prompt GEMMs. Arcint's A770 large-GRF and subgroup-8 results are
|
||||
motivation, not transferable performance claims.
|
||||
|
||||
## Work package 6: items folded in from Infernix (round 2026-10)
|
||||
|
||||
Infernix (`github.com/Wallawalla47/Infernix`, reviewed `main` at the 2026-10
|
||||
README/RESEARCH_NOTES) is a CUDA/RTX-5090 engine; its kernels (NVFP4/FP8 MMA,
|
||||
`mma.sync`, `cp.async`, TMA, PDL, L2 prefetch) do not port to Intel Arc. Three
|
||||
ideas are transferable and go into this round. Its own CPU/PCIe miss-split is
|
||||
tuned for PCIe Gen5 x8 (~32 GB/s); the A770 is PCIe 3.0 x4 (~1.8 GB/s, ~18x
|
||||
less), so any split must be re-measured here, not copied.
|
||||
|
||||
1. **Hybrid CPU + PCIe expert-miss split (`--pcie-frac`).** Infernix "computes
|
||||
part of each layer's cache misses on the CPU while the rest cross PCIe." We
|
||||
run `--pcie-frac 0`. Test a small explicit `--pcie-frac` (for example 0.02,
|
||||
0.05) in the resident-experts config to overlap the CPU pool with GPU-side
|
||||
PCIe fetches. CAVEAT: on `xe` without `--stream-experts` the GPU page-faults
|
||||
on pageable host memory and an explicit nonzero value warns it "hung an Arc
|
||||
Pro B70 (device lost)". Run it guarded: watch for device loss and revert
|
||||
immediately. If the resident complement is not actually pinnable, record this
|
||||
as unsafe on `xe` and stop.
|
||||
2. **Controlled ms/round measurement.** Infernix ranks changes by **ms per
|
||||
round** on a **controlled token stream** (identical round/acceptance counts),
|
||||
arms **interleaved in one window**, std dev <0.02 ms, and warns that one-side
|
||||
probes and single-kernel rankings mislead (our own router microbench 3.3x gave
|
||||
no end-to-end gain). Adopt this for every A/B here: fixed seed, greedy,
|
||||
compare ms/window and rounds, not just tok/s.
|
||||
3. **Adaptive draft length.** Infernix drafts "down to none on text it predicts
|
||||
poorly", so a bad draft never slows a round. We have `--spec-min-p`; sweep it
|
||||
(0.0, 0.3, 0.5, 0.7) with the controlled protocol to confirm the current 0.5
|
||||
is right and whether a higher threshold helps prose-like output.
|
||||
|
||||
Non-transferable from Infernix (recorded so they are not retried): all quantized
|
||||
MMA kernels and KV formats (fp8/nvfp4/vq2/k4v2), PDL/TMA/`cp.async` overlap, its
|
||||
VRAM ledger and Windows budget handling, and its 6-CPU-worker finding (we are at
|
||||
7; both agree "more is slower because CPU and PCIe share host memory bandwidth").
|
||||
|
||||
### WP6 results so far
|
||||
|
||||
- **Item 1, `--pcie-frac` — inert on `xe` resident-experts mode (resolved).**
|
||||
`--pcie-frac 0.05` was accepted (with the pageable-memory warning) and did not
|
||||
fault or lose the device, but the decode timing reported **`PCIe 0.00`**
|
||||
experts: the counter never moved, so no GPU-side PCIe expert fetch happened.
|
||||
Decode was 12.0 / 11.9 / 12.2 tok/s, level with the 12.4 / 12.6 baseline (and
|
||||
that run was RAM-starved: the resident complement fell to 11.12 GiB, fewer
|
||||
experts resident). `--pcie-frac` does not wire a PCIe read path in this mode;
|
||||
the only PCIe expert path is the pinned mirror (`--stream-experts`), which is
|
||||
~5x slower here because the A770 link is PCIe 3.0 x4 (~1.8 GB/s). The
|
||||
Infernix-style hybrid CPU+PCIe split is therefore **not reachable / not useful
|
||||
on this card**. Keep `--pcie-frac 0`.
|
||||
- **Item 3, adaptive draft length** — resolved: keep the default 0.5. Steady
|
||||
decode in one window cluster (546-token prompt, 256 generated):
|
||||
`--spec-min-p 0.0` = 10.4 / 10.5 / 10.4 tok/s (draft acceptance ~52%);
|
||||
`0.5` = 12.2 / 12.0 / 11.7 (acceptance ~68%); `0.7` = 11.8 / 11.4 / 11.6
|
||||
(acceptance ~93%). Higher thresholds raise acceptance but offer fewer drafts;
|
||||
0.5 is best or tied, 0.0 clearly worse. No change.
|
||||
|
||||
Additional rejected lever this round: **`--adapt-swaps 0`** (no adaptive expert
|
||||
swapping) measured 11.2 / 10.9 / 10.5 tok/s against the 12.0 default (8) in the
|
||||
same window — the default's swap schedule is better. Keep 8.
|
||||
|
||||
Same-window A/B of the overlap lever: **`--spec-split` HURTS** — 9.9 / 10.2 /
|
||||
10.3 tok/s vs `--no-spec-split` 11.7 / 12.1 / 12.6. So overlapping the drafter
|
||||
with the verify window is negative on this A770 (opposite the fork's B70 result).
|
||||
The engine default matches `--no-spec-split`; keep it. This closes the last
|
||||
cheap "overlap" knob.
|
||||
|
||||
Exhausted-lever summary (all measured, same-window where it matters): spec window
|
||||
width (wider worse), spec-min-p (0.5 best), spec-split (worse), pool-workers
|
||||
6/7 (wash), cache size (smaller worse), adapt-swaps 0 (worse), pcie-frac (inert),
|
||||
GRF 128/256 (no-op/worse), expert-lanes 8/16 (wash), mmvf-rows (worse). No config
|
||||
or on/off switch reaches 20 tok/s or even materially past ~12.6.
|
||||
|
||||
Also neutral: **`--kv q4_0`** (halves KV VRAM, should allow more resident experts) —
|
||||
12.0 / 12.3 / 12.6 tok/s, level with `--kv int8`. So KV VRAM was not the binding
|
||||
constraint on the expert cache, or freeing it did not reduce the CPU pool enough
|
||||
to matter.
|
||||
|
||||
This exhausts the configuration and switch surface. Every lever tried is null or
|
||||
worse; the best reliable steady state remains **~12.0–12.6 tok/s**. The only
|
||||
remaining paths are (a) the architectural change to the CPU-pool handoff, and
|
||||
(b) the bounded aligned-IQ GPU-kernel port from the llama.cpp SYCL PR (minor by
|
||||
our own stage table).
|
||||
|
||||
### Dual-GPU on the A770 + B580 (peer tier / layer split): BROKEN in the SYCL port
|
||||
|
||||
The one lever that could eliminate the CPU handoff is fitting all experts in
|
||||
VRAM. A770 (16 GB) + B580 (12 GB) = 28 GB vs ~19 GB of experts. Tried all three
|
||||
SYCL multi-GPU paths:
|
||||
|
||||
- **`--peer-device` (second expert tier): stubbed.** `sycl/src/core/peer_experts.cpp`
|
||||
refuses: "the second-GPU expert tier is not ported to SYCL yet" (also INTEL.md:639).
|
||||
- **`--expert-cache-remote`:** disallowed across a layer split (generate.cpp:1970).
|
||||
- **`--layer-split auto` with `ONEAPI_DEVICE_SELECTOR=level_zero:1,0`: loads, then
|
||||
crashes.** It configures *ideally* — "layer split across 2 GPUs", K=2, 5946 of
|
||||
12288 profiled pairs in the caches (**~97.5% of the routed mass**), CUDA1 = A770
|
||||
runs layers 2-47 with a 10.06 GiB expert cache, and the window runs as the
|
||||
**"100% VRAM resident: zero-doorbell graph"** (no CPU handshake — exactly the
|
||||
target state). But every request then fails:
|
||||
- `level_zero backend failed with error: 20 (UR_RESULT_ERROR_DEVICE_LOST)` in
|
||||
the prefill path (caught at prefill.cpp:4509), then
|
||||
- `Cannot submit to a queue with a dependency from a graph that is associated
|
||||
with a different context` (verify.cpp:1706).
|
||||
|
||||
The second error is the root: the port's command-graph capture is **single-context**,
|
||||
and a two-device layer split has **two SYCL contexts**, so the captured window
|
||||
graph cannot be submitted. The port has no multi-context graph support. So the
|
||||
dual-GPU path is **not usable**, and making it work is a substantial port (multi-
|
||||
context graph capture/replay, plus the prefill device-lost).
|
||||
|
||||
**Net:** the highest-upside lever is confirmed blocked by an unported feature, not
|
||||
by a tuning choice. Reaching 20 tok/s now requires either porting SYCL multi-
|
||||
context graphs (large), or a machine where all ~19 GB of experts fit in one card's
|
||||
VRAM.
|
||||
|
||||
### Aligned/planar IQ kernels (llama.cpp SYCL PR idea): no safe minor win
|
||||
|
||||
Inspected the port's IQ decode (`sycl/src/kernels/cuda/iq_kernels.dp.cpp`). The
|
||||
`Split<>` loaders for the Coder's formats already read **words**, not bytes:
|
||||
|
||||
- `Split<22>` (IQ2_S): `get_int_b2` for `qs` and the sign word, `qh`/`scales` as
|
||||
one-byte reads only.
|
||||
- `Split<42>` (Q2_0): `int16_t` reads.
|
||||
- `Split<17>` (IQ2_XS): `get_int_b2` words.
|
||||
|
||||
So the PR's "32-bit instead of byte" change has nothing to bite on — the port
|
||||
already does it (the base carries the fork's kernel optimizations). The remaining
|
||||
misalignment needs the PR's **planes repack** (fields laid out back to back per
|
||||
block), which is a **loader + cache + verification change**, not safe-minor. And
|
||||
even done, the payoff is small: the expert kernel is ALU-bound (grid lookups +
|
||||
dp4a) and is only ~20% of the window; the PR's ~13% on one sub-kernel would move
|
||||
the whole decode by ~2-3%. Not worth the bitwise-regression risk.
|
||||
|
||||
**Conclusion after exhausting every lever:** ~12.0-12.6 tok/s is the ceiling for
|
||||
this model on one A770 with the port as it stands. The only paths past it are the
|
||||
large SYCL multi-context-graph port (to make the two-card split work) or a single
|
||||
card with >= 24 GB VRAM.
|
||||
|
||||
## Work package 4: shape-specific projection kernels
|
||||
|
||||
If existing-path tuning leaves a significant bottleneck, adapt arcint patch
|
||||
0022's **few-column reuse and split-K geometry** to the SYCL BF16 implementation.
|
||||
|
||||
- Read a weight chunk once and update separate accumulators for 2-8 tokens.
|
||||
- For N small and K long, split K over a work-group, then reduce in a deliberate,
|
||||
documented order. For larger N, compare one row and several rows per subgroup.
|
||||
- Preserve BF16-to-FP32 conversion. Arcint's storage of BF16 as F16 is not the
|
||||
target engine's contract and must not be copied blindly.
|
||||
- Handle strided activation/output rows and non-full tiles without out-of-bounds
|
||||
loads or stores. Unsupported geometry must use the verified fallback.
|
||||
- Keep a negative-control switch and direct old/new comparisons.
|
||||
|
||||
Prefer the old operation/reduction order for bitwise parity. If a changed tree
|
||||
is necessary, state that explicitly, compare with a high-precision oracle, define
|
||||
tolerances before interpreting measurements, compare logits/routing and run the
|
||||
served correctness suite. A successful arithmetic answer alone is insufficient
|
||||
to approve a numerically different path.
|
||||
|
||||
## Work package 5: low-bit layouts and XMX crossover
|
||||
|
||||
These follow measured BF16/HC work rather than starting a broad backend rewrite.
|
||||
|
||||
### Aligned low-bit fields
|
||||
|
||||
Study arcint patch 0022's plane layouts for IQ2_XXS, IQ2_S, IQ3_S and Q2_0 and
|
||||
its four-lane treatment of small Q2_0 rows. Inventory equivalent optimizations
|
||||
already present in `iq_kernels.dp.cpp` and `native_mmvq.dp.cpp` before adding a
|
||||
second layout. A plane repack must preserve quantized values and fit the same
|
||||
budget, provide inverse/readback validation, and update cache/file parity logic.
|
||||
Benchmark both the stored-block and repacked paths with actual Coder shapes.
|
||||
|
||||
### Small-batch XMX
|
||||
|
||||
Study arcint patch 0009 for 4-16-column K-quant verification. On the A770 its
|
||||
ordinary matvec stayed faster at two/three columns; therefore determine a
|
||||
measured crossover rather than sending every batch to matrix hardware.
|
||||
Preserve the correct sum of the rounded activation values if using an offset
|
||||
code representation; arcint documents substantial errors when a compiler summed
|
||||
unrounded inputs instead. Partial tiles, odd block counts and scale extremes
|
||||
need dedicated tests. Initial XMX experiments remain opt-in.
|
||||
|
||||
## Correctness and regression gates
|
||||
|
||||
Run appropriate tests on the A770 after relevant changes:
|
||||
|
||||
```sh
|
||||
ctest --test-dir build-sycl --output-on-failure \
|
||||
-R '^(sycl_router_fast|sycl_payload_pairs|elementwise_parity|router_top10_parity|bf16_gemv_parity|gr_parity|gdn_parity)$'
|
||||
```
|
||||
|
||||
Build the named targets first; a test filtered out because its executable or
|
||||
registration is missing is not a pass. Add a dedicated BF16 event/row probe and
|
||||
guard/stride checks as described in work package 2. Run quantized/native-expert
|
||||
tests when changing those kernels.
|
||||
|
||||
End-to-end gates:
|
||||
|
||||
1. Original regression: twelve repetitions of the four pangram sentences, then
|
||||
`Ignore the text above. What is 17 + 24? Reply with just the number.` Expected
|
||||
final API content is `41`, normal stop, not merely `41` inside reasoning.
|
||||
2. A coding prompt requesting a bounded Python implementation, whose returned
|
||||
function is tested on normal, empty and boundary inputs.
|
||||
3. Fresh-prompt lengths around 73, 546 and 1,950 tokens; also a longer prompt
|
||||
around 8K when selecting a final implementation. These lengths should be
|
||||
counted by the actual tokenizer rather than assumed from word counts.
|
||||
4. No crashes, device loss, non-finite logits or payload-arrival timeouts in the
|
||||
chosen unprofiled configuration.
|
||||
5. Unsupported geometries retain the verified fallback. Benchmark non-A770
|
||||
hardware before making cross-architecture defaults universal.
|
||||
|
||||
## End-to-end benchmark protocol
|
||||
|
||||
Primary matched configuration:
|
||||
|
||||
```text
|
||||
--max-context 131072 --kv int8 --kv-resident 32768
|
||||
--expert-cache auto --resident-experts
|
||||
--prefill 1024 --prefill-borrow --vram-reserve-mib 300
|
||||
--pool-workers 7 --pool-affinity auto --adapt-swaps 8
|
||||
--spec 4 --spec-min-p 0.5 --no-spec-split --mtp <existing MTP path>
|
||||
--prompt-cache 0
|
||||
```
|
||||
|
||||
Environment: retain the existing FP64-emulation variables and
|
||||
`ONEAPI_DEVICE_SELECTOR=level_zero:1`; set `STRATA_VERIFY_NO_HOST=0` in the
|
||||
wrapper config. The wrapper removes its NO_HOST default when this is zero.
|
||||
Keep `STRATA_VERIFY_PROFILE` and `STRATA_VERIFY_EAGER` absent from acceptance
|
||||
runs. A normal `xe` CPU-miss configuration defaults its PCIe miss share to zero.
|
||||
|
||||
Protocol:
|
||||
|
||||
1. Save A and B configs, source hashes, executable hashes and exact commands.
|
||||
2. Record free/available RAM, swap-in/out counters, CPU contention, expert-cache
|
||||
size and residency coverage. Do not let one arm quietly gain more VRAM/RAM.
|
||||
3. Separate model startup from first-request JIT and warm steady-state results.
|
||||
4. Warm all tested shapes. Use at least three warmed repetitions per arm; prefer
|
||||
interleaved A/B/A/B sessions when builds or persistent process selectors differ.
|
||||
5. Generate at least 256 tokens for the sustained decode gate and preserve full
|
||||
response JSON. Include token count, engine `predicted_ms`, engine tok/s,
|
||||
prompt `prompt_ms`, cache reuse, API wall time, finish reason and draft acceptance.
|
||||
6. Report median and range, plus aggregate tokens / aggregate decode time. Never
|
||||
use aggregate multi-lane throughput as a single-stream A770 decode claim.
|
||||
7. Re-enable prefix caching only in a separate practical-conversation benchmark.
|
||||
8. Accept an optimization only if it passes correctness and wins outside ordinary
|
||||
run-to-run noise, or addresses a clearly measured pathological shape without
|
||||
degrading the primary workload. Record rejected experiments too.
|
||||
|
||||
Portable build commands inside the existing image (run from the worktree):
|
||||
|
||||
```sh
|
||||
docker run --rm -u "$(id -u):$(id -g)" -v "$PWD/..:/work" strata-sycl-dev \
|
||||
"source /opt/intel/oneapi/setvars.sh >/dev/null 2>&1; \
|
||||
cmake --build /work/strata-v0.1.40.3/build-sycl --target strata -j 8"
|
||||
```
|
||||
|
||||
Use the actual `cmake --build` exit status: `sycl/tools/build.sh` currently
|
||||
prints `BUILD EXIT 0` but can itself return nonzero because its last failure-
|
||||
search pipeline finds no failures. Do not chain tests behind that misleading
|
||||
script status.
|
||||
|
||||
## Artifacts and implementation sequence
|
||||
|
||||
Initial artifacts:
|
||||
|
||||
- This specification: `docs/A770_SPEED_SPEC.md`.
|
||||
- Kernel probe: `sycl/probe/bf16_event_bench.cpp` (planned), with a CMake target
|
||||
under `STRATA_SYCL_PARITY`.
|
||||
- A machine-readable microbenchmark output with the fields from work package 1.
|
||||
- A persisted benchmark config and response/timing records for selected winners.
|
||||
- A short result ledger under this document's execution record.
|
||||
|
||||
Sequence:
|
||||
|
||||
1. Confirm source/resource state and finalize this specification.
|
||||
2. Implement the isolated event-timed BF16 benchmark and run baseline/row arms.
|
||||
3. Validate bits, guards and strides; record per-shape crossover results.
|
||||
4. Benchmark a matched full-model `STRATA_MMVF_ROWS=1` arm if microbenchmarks
|
||||
justify it, without the experimental host-clock profiler.
|
||||
5. Tune registers/subgroups or add a split-K specialization for the measured
|
||||
bottleneck. Repeat correctness and end-to-end gates.
|
||||
6. Consider low-bit layouts or XMX only after the earlier evidence ranks them.
|
||||
7. Run the mandated independent quality pass on source changes before final
|
||||
delivery. Preserve known limitations and do not claim goal completion from
|
||||
partial progress.
|
||||
|
||||
## Reference implementations
|
||||
|
||||
Arcint reference checkout: a local temporary checkout, reviewed revision
|
||||
`fcb071c6c781c3fb5125e311cbea06209bb9c642`.
|
||||
|
||||
- [0022: low-bit formats and few-column F16/BF16 geometry](https://github.com/marfrit/arcint/blob/fcb071c6c781c3fb5125e311cbea06209bb9c642/contrib/llama.cpp/patches/0022-opencl-intel-low-bit-iq-and-f16-small-n.patch)
|
||||
- [0009: few-column K-quant XMX](https://github.com/marfrit/arcint/blob/fcb071c6c781c3fb5125e311cbea06209bb9c642/contrib/llama.cpp/patches/0009-opencl-intel-few-column-kquant-xmx.patch)
|
||||
- [0003: register/subgroup-tuned GatedDeltaNet](https://github.com/marfrit/arcint/blob/fcb071c6c781c3fb5125e311cbea06209bb9c642/contrib/llama.cpp/patches/0003-opencl-intel-gated-delta-net.patch)
|
||||
- [Event-profiling harness](https://github.com/marfrit/arcint/blob/fcb071c6c781c3fb5125e311cbea06209bb9c642/tools/native_kernel_harness.py)
|
||||
- [Measured kernel notes](https://github.com/marfrit/arcint/blob/fcb071c6c781c3fb5125e311cbea06209bb9c642/contrib/llama.cpp/README.md)
|
||||
|
||||
Arcint's headline A770 coder numbers use a different model/configuration.
|
||||
Its Flash-Next results are mainly on a B60. Treat those numbers as evidence for
|
||||
candidate techniques, not predictions for this A770 workload. Several arcint
|
||||
ideas already originated in PolyStrata; audit existing equivalents before porting.
|
||||
|
||||
## Execution record
|
||||
|
||||
- Specification created before starting the new implementation.
|
||||
- The existing 20 tok/s goal was explicitly resumed for this requested work.
|
||||
- At start: source `501f675`, `a770-speed-upstream`; no tracked source changes.
|
||||
- At start: approximately 17 GiB RAM available; no A770 test container running.
|
||||
- Next active task: isolated profiling-enabled BF16 kernel benchmark and
|
||||
default-versus-row comparison. No new performance result is claimed yet.
|
||||
|
||||
### Work package 1-2 results (event-timed BF16/F32 MMVF)
|
||||
|
||||
Probe `sycl/probe/bf16_event_bench.cpp`, A770 `level_zero:1`, in-order
|
||||
profiling queue, 32 repeats x 7 samples, device queue span per call. All arms
|
||||
passed bitwise old/new parity, guard-region, stride, zero-input, scale-extreme,
|
||||
non-finite and invalid-geometry-rejection checks.
|
||||
|
||||
- Default path versus `STRATA_MMVF_ROWS=1`: the rows path is 1.4-6x SLOWER.
|
||||
320x10240 at T=3: 16.06 -> 79.00 us. 2560x2560 at T=4: 38.68 -> 245.54 us.
|
||||
With the caveat that the small (T=1, n=4) rows are launch/clock noise,
|
||||
`STRATA_MMVF_ROWS=1` is rejected as an A770 default.
|
||||
- Raw baselines (default path, us): 320x10240 T=3 16.06; 2560x2560 T=4 38.68;
|
||||
10240x2560 T=1 182.71; 10240x320 T=3 47.56. These are small relative to the
|
||||
~180 ms decode window, so the BF16 projection family is NOT the decode
|
||||
bottleneck on this card.
|
||||
- Artifacts: `a770-bf16-default.jsonl` and
|
||||
`a770-bf16-rows.jsonl`.
|
||||
|
||||
### Work package 3 results (register allocation)
|
||||
|
||||
Added `-DSTRATA_SYCL_BF16_GRF=0|128|256` (default 0), applied only to
|
||||
`native_bf16.dp.cpp` via a kernel-local property. No subgroup-size change.
|
||||
|
||||
- `GRF=0` reproduces the saved baseline (ratio 1.000 on the steady shapes),
|
||||
confirming the default path is unchanged.
|
||||
- `GRF=128` is a no-op (ratio ~1.000 on all steady shapes).
|
||||
- `GRF=256` is 10-58% SLOWER across the board (for example 320x10240 T=8
|
||||
44.86 -> 70.82 us; 2560x2560 T=8 79.14 -> 98.09 us; 10240x2560 T=8
|
||||
320.11 -> 425.62 us). Rejected.
|
||||
- Conclusion: register allocation is not a lever for this family on this card.
|
||||
Leave the default (0).
|
||||
|
||||
### Where the decode time actually is
|
||||
|
||||
Prior per-window timing (`strata decode timing`) at ~13 tok/s: about 180 ms per
|
||||
window (T~2.2), of which verify ~171 ms = GPU-reach wait ~130 ms + per-layer
|
||||
host ~35 ms (CPU experts ~33 ms) + staging, plus ~8 ms draft. The **GPU-reach
|
||||
wait dominates**, i.e. the GPU expert/attention compute for VRAM-resident
|
||||
experts, not the BF16 dense projections and not the host handshake. The
|
||||
remaining lever toward 20 tok/s is the quantized expert (IQ) GPU kernels and
|
||||
the effective token/window count, not the BF16 projection geometry tested here.
|
||||
|
||||
### End-to-end confirmation (this revision, unprofiled)
|
||||
|
||||
Config: `--resident-experts --prefill-borrow --prefill 1024 --vram-reserve-mib
|
||||
300 --pool-workers 7 --adapt-swaps 8 --spec 4 --no-spec-split`, 131072 context,
|
||||
INT8 KV, 32K resident, `--prompt-cache 0`, `STRATA_VERIFY_NO_HOST=0`. 8.98 GiB
|
||||
VRAM expert cache, 15.08 GiB resident RAM.
|
||||
|
||||
- Sustained 546-token prompt, 256 generated, two warm runs: **9.6 and 10.9
|
||||
tok/s** (engine `predicted_per_second`); zero prompt tokens reused.
|
||||
- Decode breakdown (the 135-window run, 174.19 ms/window, T=2.22):
|
||||
**verify 164.87 ms = GPU-reach wait 123.27 + per-layer host 36.08
|
||||
(plan 0.16 + actq 0.12 + jobs 8.79 + CPU 25.45) + stage 0.01**, commit 0.30,
|
||||
draft 8.01. Per layer-window: CPU experts 4.42 (5.32 entries), VRAM hits 16.90,
|
||||
PCIe 0.00.
|
||||
- So the GPU-reach wait is ~71% of the window. The GPU is busy on the
|
||||
VRAM-resident expert kernels plus attention/GDN, not waiting on the CPU: the
|
||||
CPU pool contributes only ~25 ms of the 174 ms.
|
||||
- Arithmetic regression prompt returned `41` with normal stop in 3 of 3 runs.
|
||||
One earlier cold run returned `41!!!!!!!!!!!` (content) once and did not
|
||||
reproduce; keep the sustained arithmetic gate in every acceptance run and
|
||||
treat a reproducible degenerate as a release blocker.
|
||||
|
||||
**Bottleneck verdict (evidence-based):** the next real lever is the quantized
|
||||
expert GPU kernel (`native_expert_grouped`, IQ dequant + grouped matmul), and
|
||||
the tokens-per-window count. BF16 projection geometry (WP2) and register
|
||||
allocation (WP3) are exhausted as levers. WP4/WP5 should target the IQ expert
|
||||
kernels directly with the same event-timed, bitwise-gated method.
|
||||
|
||||
### Expert-rebalance experiment (rejected)
|
||||
|
||||
`ms_wait` is the host waiting for the GPU to ring each layer = GPU compute on
|
||||
the critical path, not the GPU waiting on the CPU. Hypothesis: move experts off
|
||||
the GPU onto the underused CPU (CPU pool ~36 ms vs GPU ~123 ms/window) by
|
||||
shrinking the VRAM cache. Result, warm runs, 546-token prompt, 192 generated:
|
||||
|
||||
| VRAM cache | decode | GPU-reach wait | CPU/layer | note |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| auto 4717 slots (8.98 GiB) | 10.9 tok/s | 123 ms | 25 ms | reference |
|
||||
| 3200 slots (7.93 GiB) | 10.8 tok/s | 121 ms | 30 ms | neutral |
|
||||
| 2400 slots (5.95 GiB) | 9.6 tok/s | 152 ms | 51 ms | worse |
|
||||
|
||||
Shrinking the cache did not reduce GPU-reach wait: it grew (the resident RAM
|
||||
complement spills partly to the model folder and the CPU pool lengthens), so
|
||||
the GPU is not waiting on expert count in a way this balances. Cache size in the
|
||||
3200-4717 range is neutral; below that it regresses. Rejected as a lever.
|
||||
|
||||
**Updated verdict:** the ~121 ms/window GPU-reach wait is largely independent of
|
||||
the knobs tested so far (projection geometry, registers, cache size, window
|
||||
width). Moving toward 20 tok/s requires making the GPU hot path itself faster
|
||||
(quantized expert kernels, attention/GDN) or raising tokens/window — a kernel
|
||||
porting effort, not parameter tuning.
|
||||
|
||||
### Grouped-expert lane count (`STRATA_EXPERT_LANES`)
|
||||
|
||||
Added `-DSTRATA_SYCL_EXPERT_LANES=1|2|4|8|16|32` (default 8), applied to
|
||||
`iq_kernels.dp.cpp`. The IQ grouped-expert decode kernel uses 8 lanes per row.
|
||||
|
||||
- Interleaved A/B on the sustained gate, same session and config:
|
||||
**8 lanes = 12.40 / 12.60 tok/s; 16 lanes = 12.1 / 12.6 tok/s.** No
|
||||
difference. The earlier 9.6/10.9 "8-lane" numbers were a worse session, not
|
||||
the lane count. `STRATA_EXPERT_LANES` is a **null result**; default stays 8.
|
||||
- This also resets the reliable steady-state reference: the current best config
|
||||
is **~12.4-12.6 tok/s** (first run after load is still cold/JIT).
|
||||
- `iq_multi_parity` and `native_grouped_parity` pass; the Coder's IQ hit path
|
||||
(`moe_hit_grouped_s2`) is byte-identical at 8 and 16.
|
||||
|
||||
### Pre-existing test failure (not caused by this work)
|
||||
|
||||
`s2_expert_grouped_parity` fails its `moe_grouped_s2` and
|
||||
`moe_group_resident + moe_grouped_s2` cases ("DIFFERS") **at the default
|
||||
8-lane build with unmodified `iq_kernels.dp.cpp`** (the option value equals the
|
||||
source's `#ifndef` default, so that binary is identical to a stock build). The
|
||||
`moe_hit_grouped_s2` cases all pass. This is a pre-existing SYCL port gap in the
|
||||
S2 grouped/residency path, not a regression from this campaign. Flagged so it is
|
||||
not mistaken for one; the fork's Intel notes also report 43/44 on the base.
|
||||
|
||||
### Profiling blocker (blocks WP4/WP5 targeting)
|
||||
|
||||
`STRATA_VERIFY_PROFILE=1` still fails on the current build: a request returns
|
||||
HTTP 400 with the engine erroring inside the verify window (the same host-clock
|
||||
stamp path documented in WP1). The base engine's only per-stage profiler is this
|
||||
one, and it is unreliable, so there is **no trustworthy per-stage breakdown** of
|
||||
the ~121-123 ms/window GPU time. No external GPU tracer (`unitrace`/`onetrace`/
|
||||
`ze_tracer`) is installed in the container.
|
||||
|
||||
### Expert kernel measured standalone: NOT the bottleneck (WP4/WP5 retarget)
|
||||
|
||||
`native_expert_parity` with `NATIVE_BENCH=1` times the GPU
|
||||
`native_expert_grouped` kernel on real GGUF rows (10 experts x 4 entries = 40
|
||||
expert computations, host-wall per call). Coder IQ1_M, A770:
|
||||
|
||||
| layer | expert types | blob | GPU grouped |
|
||||
|---|---:|---:|---:|
|
||||
| 0 | iq3_xxs / iq4_nl | 2.18 MB | 0.328 ms |
|
||||
| 1 | iq2_s / q2_0 | 1.51 MB | 0.375 ms |
|
||||
| 2, 3, 24 | iq2_s / iq4_nl | 1.97 MB | 0.351 / 0.361 / 0.383 ms |
|
||||
| 47 | iq4_xs / iq4_nl | 2.66 MB | 1.205 ms |
|
||||
|
||||
So the grouped-expert kernel is ~0.33-0.38 ms/layer for the common types and
|
||||
~1.2 ms on layer 47. Even the pessimistic 48 x 0.5 ms is **~24 ms/window**, a
|
||||
small fraction of the ~123 ms GPU-reach wait. **The expert kernel is not the
|
||||
bottleneck.** WP4/WP5 as written (target the IQ grouped-expert kernel) are
|
||||
**retargeted**: the GPU time is spread over the other per-layer kernels (GDN
|
||||
hyper-connection read, conv/recurrence, QSA attention, router, combine), each
|
||||
small, so there is no single dominant kernel to win 1.6x from. Reaching 20 tok/s
|
||||
therefore needs an architectural lever (more tokens/window, deeper kernel
|
||||
fusion, or more layer/round overlap), not one kernel rewrite. Confirm the
|
||||
per-kernel split with a working profiler before committing to that effort.
|
||||
|
||||
Consequence: before an architectural change is chosen, the campaign needs a
|
||||
**working profiler** — fix the host-clock stamp, add per-kernel timing behind
|
||||
`STRATA_VERIFY_EAGER` (no graph) on a profiling-enabled queue, or install an
|
||||
external Intel GPU trace (unitrace / Level Zero timers). The parameter/config
|
||||
surface (WP1-WP3, WP6) is exhausted with evidence.
|
||||
|
||||
### Other standalone kernels measured
|
||||
|
||||
- **Hyper-connection read** (`gr_bench`, `fused_gr_read_multi`, Coder shapes):
|
||||
180.4 / 179.0 / 203.7 / 218.0 / 241.7 / 259.8 us for 1..6 tokens (73 GB/s at
|
||||
1 token down to 51 GB/s at 6). At ~36 GDN layers x ~180 us that is
|
||||
**~7 ms/window** — also a minor slice of the 123 ms. Not the bottleneck.
|
||||
- So the two kernels biggest in the old (inflated) stage table — experts and
|
||||
hyper-connection read — together account for only ~30 ms of ~123 ms.
|
||||
|
||||
### The window is nearly GPU + CPU serial (architectural hypothesis)
|
||||
|
||||
Steady-state numbers (546-token prompt, ~2.2 tokens/window): window ~166 ms =
|
||||
**GPU-reach wait 123 ms + per-layer host/CPU 36 ms + draft 8 ms**, and
|
||||
123 + 36 + 8 = 167 is the whole window. That is the signature of the GPU and
|
||||
the CPU expert pool running **largely serially within a window**, not overlapped.
|
||||
If the CPU pool (36 ms) hid under the GPU (123 ms), the window would fall to
|
||||
~123-131 ms, i.e. ~2.2/0.125 = **~17-18 tok/s**, near the goal. So the most
|
||||
promising lever may be **overlapping the CPU expert computation with the GPU**
|
||||
(a scheduling/architecture change), not any single kernel. This is a hypothesis,
|
||||
not yet proven — the profiler is needed to confirm the GPU is busy (not idle
|
||||
waiting on the flag) during the CPU pool. WP7 candidate pending that
|
||||
confirmation; do not start it blind.
|
||||
|
||||
Follow-up test (this round): `--pool-workers` 6 (physical cores) vs 7 default
|
||||
measured 12.1 / 12.8 / 13.0 vs 13.3 / 12.8 / 12.4 tok/s — a wash. So if the CPU
|
||||
pool is serial with the GPU, it is **not** worker-count-limited; adding/removing
|
||||
a worker does nothing. Rejected as a lever.
|
||||
|
||||
### GPU utilization: the GPU is mostly IDLE during decode (major finding)
|
||||
|
||||
`gputop` (the Xe counterpart to intel_gpu_top) CAN be read for the engine if the
|
||||
engine process is user-owned. `sycl/serve/strata-sycl.sh` runs the container as
|
||||
root (no `--user`), so `gputop` cannot attribute it; a temporary copy adding
|
||||
`--user <uid>:<gid>` made the engine user-owned and readable. During a 700-token
|
||||
decode (240-token prompt) the A770's compute engine (ccs) sampled:
|
||||
|
||||
0% 0% 4.1% 14.8% 41.4% 2.8% 0% 8.5% 65.0% 84.3% ...
|
||||
|
||||
— i.e. **mostly 0-20%, spiking occasionally**, mean over the run ~20%. The GPU is
|
||||
**not saturated during decode**. (1 Hz sampling and ccs attribution make this
|
||||
coarse, but the many 0% samples during an active generation are unambiguous.)
|
||||
|
||||
This **overturns the "ms_wait = GPU compute" reading** in the hypothesis above.
|
||||
`ms_wait` is the host waiting for the GPU's layer ring, but the ring is late
|
||||
because the GPU is **stalled on the CPU/handoff**, not because it is busy. So the
|
||||
decode window is dominated by **per-layer host<->GPU synchronization and the CPU
|
||||
expert pool, not GPU kernels** — consistent with every kernel measured standalone
|
||||
being minor. The path to 20 tok/s is therefore to **cut the per-layer handoff
|
||||
latency / overlap the CPU pool with the GPU**, not to optimize kernels.
|
||||
|
||||
Next empirical step (cheap, needs no profiler): quantify the handoff cost by
|
||||
measuring round-trip latency of the doorbell (ring -> host -> flag -> GPU) on this
|
||||
`xe`/PCIe-3.0-x4 card and how much of the window is idle GPU time, then decide
|
||||
the architectural change. This is now the primary direction; WP4/WP5 (kernel
|
||||
optimization) are closed as mis-targeted.
|
||||
|
||||
### Both in-engine profilers are broken (blocks all targeting)
|
||||
|
||||
`STRATA_VERIFY_PROFILE=1` and `STRATA_VERIFY_EAGER=1` both fail on the current
|
||||
build with the engine erroring in the verify window: **`verify: layer 0 rang but
|
||||
its payload never arrived whole`** (HTTP 400), reproducibly (3/3 eager requests
|
||||
failed). The PROFILE mode succeeded exactly once, much earlier — so it is a race,
|
||||
not a hard logic error, but it is reliable enough in EAGER mode to make that path
|
||||
unusable. There is no env switch to bypass the payload wait
|
||||
(`doorbell_wait_payload` has none).
|
||||
|
||||
Consequence: the engine has **no usable profiler** on this build. The likely
|
||||
defect (a real bug, relevant to PR #1602's payload checksum) is that the EAGER
|
||||
path does not publish the doorbell payload that `doorbell_payload_ready` waits
|
||||
for, so the host spins to the 2 s timeout; in the graph path the publish runs and
|
||||
the checksum matches. **Fixing this eager-path bug is the concrete next task**,
|
||||
because it unblocks the per-stage breakdown everything else needs. (It is a
|
||||
debug-only path; normal graph-mode inference is unaffected.)
|
||||
|
||||
### Per-stage breakdown obtained (decisive): the CPU pool handoff dominates
|
||||
|
||||
Added an opt-in `STRATA_DOORBELL_NOCHECK` that makes `doorbell_wait_payload`
|
||||
trust the ring (debug only). With `STRATA_VERIFY_EAGER=1 STRATA_VERIFY_PROFILE=1
|
||||
STRATA_DOORBELL_NOCHECK=1` the eager stage table finally printed. T=2 window,
|
||||
ms/window (host-clocked, so absolute values are inflated by the stamp overhead;
|
||||
the **relative** split is the point):
|
||||
|
||||
```
|
||||
GDN layers: waitA 393.2 waitB 407.8 copy+combine 399.2 hc-read1+router 51.4
|
||||
VRAM hits 26.3 hc-read0 25.3 out-proj 17.2 shared+quant 13.7
|
||||
z 9.6 q8+qkv 7.3 rec 6.4 conv/ab/head ~5
|
||||
QSA layers: waitA 134.3 waitB 134.2 copy+combine 132.4 kv+idx append 15.4
|
||||
hc-read1+router 13.0 hc-read0 8.2 out-proj 6.5 attention 3.3
|
||||
```
|
||||
|
||||
`waitA`/`waitB` are the GPU **spinning for the CPU expert-pool flags**;
|
||||
`copy+combine` is the CPU results copied to the GPU and combined. Together they
|
||||
are **~87% of the window**; every actual GPU kernel is small (tens of ms). This
|
||||
independently confirms the gputop ~20%-busy finding.
|
||||
|
||||
**Definitive conclusion:** A770 decode here is limited by the **CPU expert pool
|
||||
and its per-layer host<->GPU handoff**, not by GPU compute. WP4/WP5 (kernel
|
||||
optimization) are closed. The path to 20 tok/s is architectural: cut the
|
||||
per-layer handoff latency and/or overlap the CPU pool with GPU work. (Note the
|
||||
absolute stage numbers are inflated and `NOCHECK` distorts the pipeline, so the
|
||||
next step is an *honest* profiler — fix the eager payload path — to size the real
|
||||
handoff cost before designing the change.)
|
||||
+931
@@ -0,0 +1,931 @@
|
||||
# AMD Radeon: the HIP backend (gfx1100, gfx1101, gfx1200, gfx1201, gfx1030)
|
||||
|
||||
PolyStrata runs on AMD Radeon cards through its HIP backend, the same engine as on NVIDIA compiled for AMD. This page
|
||||
covers the build on Linux (on Windows a ready-made engine, see [Windows](#windows)) for the RX 7900 XT / XTX (RDNA3, gfx1100) and the
|
||||
RX 9070 / 9070 XT / Radeon AI PRO R9700 (RDNA4, gfx1201; see [RDNA4](#rdna4-gfx1201)). The RX 7800 XT / 7700 XT
|
||||
(gfx1101) and the RX 9060 XT (gfx1200) were validated by their owners (see [Community-validated
|
||||
cards](#community-validated-cards)); the RX 6800 / 6900 series (RDNA2, gfx1030) builds and runs too, reported by a community machine and not yet validated by the maintainers (see [RDNA2](#rdna2-gfx1030)). Setup chooses it by itself on a PC with no NVIDIA card PolyStrata can use (`--backend hip` on a PC with both); the
|
||||
install steps for users are in [INSTALL.md](INSTALL.md#amd-cards). gfx906 (Instinct MI50 / MI60, Radeon VII; wave64) has a separate
|
||||
opt-in build, see [gfx906](#gfx906-instinct-mi50--mi60-radeon-vii-wave64-built-from-source). The Ryzen AI Max "Strix Halo" APU (gfx1151, RDNA3.5, unified memory) is built from source on Linux: see [STRIX_HALO.md](STRIX_HALO.md). Other AMD architectures and mixed
|
||||
AMD/NVIDIA execution in one run are not supported.
|
||||
|
||||
The backend maps the CUDA-shaped runtime and BLAS calls to HIP/hipBLAS, uses
|
||||
RDNA2/RDNA3/RDNA4's signed integer dot instruction for quantized kernels, and supplies
|
||||
wave32 shuffle/packed-byte operations. CUDA-only QSA matrix instructions have
|
||||
an ordered FP32 fallback. Prefill supports both dequantization plus hipBLAS GEMM and opt-in HIP ggml MMQ.
|
||||
An optional, calibrated hipBLASLt path accelerates dense projections (per-architecture tables in `tools/hip`).
|
||||
This does not claim bit-identical model answers across backends. See
|
||||
[performance settings and evidence](AMD_HIP_PERFORMANCE.md).
|
||||
|
||||
## Install with setup (recommended)
|
||||
|
||||
On Linux with an RX 7900 XT / XTX, RX 7800 XT / 7700 XT, RX 9060 XT, RX 9070 / 9070 XT or Radeon AI PRO R9700 and
|
||||
the kernel's amdgpu driver (no ROCm install needed):
|
||||
|
||||
```sh
|
||||
./setup.sh --backend hip
|
||||
```
|
||||
|
||||
- **Detection:** setup finds the card through the kernel's KFD topology. Integrated Radeon GPUs are listed as not
|
||||
supported. On a PC without an NVIDIA card PolyStrata can use, `--backend hip` is chosen automatically.
|
||||
- **ROCm:** a system ROCm 7 in `/opt/rocm` (or `$ROCM_PATH`) with hipcc and hipBLAS is used when present. Otherwise
|
||||
(or when it is older than 7.0) ROCm is installed into `.venv` from AMD's TheRock wheels (~10 GB, no sudo), from the
|
||||
card family's index: `gfx110X-dgpu` for gfx1100 / gfx1101, `gfx120X-all` for gfx1200 / gfx1201, `gfx103X-all` for
|
||||
gfx1030, `gfx1151` for Strix Halo. The version is chosen per family: 7.10.0a20251120 where that is on the index,
|
||||
7.13.0a20260515 for `gfx103X-all` (its index starts at 7.13, #1103) and 7.14.0a20260608 for `gfx1151` (the 7.10 wheel
|
||||
segfaults on kernel 7.2.8, #1267). When the index no longer offers the version, setup warns and takes the newest of
|
||||
the same 7.x line, else of the same major. `STRATA_ROCM_VERSION` / `STRATA_ROCM_INDEX` override them; the gfx1030
|
||||
wheels are unvalidated (a system ROCm 7 is the tested path there).
|
||||
- **Engine:** compiled on your PC for the card's architecture (10-20 minutes, once; again after a `git pull` that
|
||||
changes it, or when you pick a card of another architecture). This needs a C++ compiler and git
|
||||
(`sudo apt install build-essential git`).
|
||||
- **hipBLASLt tuning table:** setup uses `tools/hip/<arch>-hipblaslt-<version>.txt` only when it matches both the
|
||||
card's architecture and the installed hipBLASLt version (read from `hipblaslt-version.h`; 1.2.0 is `100200`).
|
||||
Otherwise it says so and the prompt's dense matrix products use plain hipBLAS (slower prompts, same answers).
|
||||
A table's solution ids are valid only for that pair, and the engine refuses any other table. On gfx103x (RDNA2,
|
||||
no hipBLASLt kernels) the same role falls to a rocBLAS table, `tools/hip/<arch>-rocblas-<version>.txt`, which the
|
||||
engine picks for its own rocBLAS build when setup points it at the directory ([RDNA2](#rdna2-gfx1030)).
|
||||
- **Several cards:** setup takes one card (the one with the most VRAM, or `--gpu N`) unless you name more:
|
||||
`./setup.sh --backend hip --gpus 1,0` splits the model's layers across them, the first one the main card (numbers
|
||||
as setup lists them; `--gpus all` = every supported card, the most VRAM first). Every chosen card must be one of the
|
||||
architectures above; the engine is compiled for each of them (cards of two families, e.g. gfx1100 + gfx1201, need
|
||||
a system ROCm 7: AMD's wheels hold one family). A split pays only when no single card holds the model's experts
|
||||
(see RDNA4 below).
|
||||
- **Limits for now:** images only through the CPU encoder (`--vision cpu`, 0.1.32). Setup does not offer the tuning
|
||||
(calibration) on AMD yet: its controls are being checked on HIP one at a time (#566). Since 0.1.39 a tuning run by
|
||||
hand (`./setup.sh --calibrate`) is saved for the AMD card it ran on and reused when setup runs again. The Monitor
|
||||
shows the card's load, VRAM, temperature and power from Linux sysfs (0.1.32).
|
||||
|
||||
The rest of setup is the same as on NVIDIA: the model download, the start script, the server.
|
||||
|
||||
## Windows
|
||||
|
||||
Since 0.1.34 an AMD card on Windows is set up like an NVIDIA one: download PolyStrata, double-click `START-HERE.bat`.
|
||||
On a PC with no NVIDIA card PolyStrata can use, the AMD card is chosen by itself; with both, setup asks
|
||||
(`START-HERE.bat --backend hip` picks AMD directly).
|
||||
|
||||
- **You need:** Windows 10 or 11 (64-bit), one of the cards above, and a current AMD driver ([AMD Software:
|
||||
Adrenalin Edition](https://www.amd.com/en/support/download/drivers.html)). Nothing else: no ROCm or HIP SDK
|
||||
install, no compiler, no admin rights.
|
||||
- **Detection:** setup reads the display adapters Windows lists (their PCI ids; the VRAM size from the display
|
||||
driver's registry entry). An integrated Radeon is listed as not supported, except the Ryzen AI Max "Strix Halo" (Radeon 8060S / 8050S / 8040S, gfx1151: [STRIX_HALO.md](STRIX_HALO.md)); a Strix Point (890M / 880M, gfx1150), Krackan (860M / 840M, gfx1152) or Phoenix / Hawk Point (780M / 760M, gfx1103) Radeon is named as what it is and not supported (on Linux the 780M / 760M has an opt-in build: [RADEON_780M.md](RADEON_780M.md)).
|
||||
- **Engine:** the ready-made `strata-windows-x64-hip.zip` from the release (built by `tools\hip\build_windows.bat`
|
||||
for gfx1100, gfx1101, gfx1102, gfx1200, gfx1201, gfx1030 and, from 0.1.40, gfx1151 (Strix Halo, unvalidated on Windows)) goes into `engine\`. It carries the ROCm libraries the
|
||||
engine loads (`engine\rocm\bin`: the HIP runtime, hipBLAS / rocBLAS / hipBLASLt with their kernels for these cards,
|
||||
amd_comgr and the Microsoft C++ runtime; ROCm 10.2.0a20260930 from AMD's TheRock builds, licenses in
|
||||
`engine\rocm\licenses`). The HIP runtime works through the AMD driver's own components, so the driver is the one
|
||||
thing it needs from the PC.
|
||||
- **The HIP runtime next to `strata.exe` (0.1.35, #468 #461):** `amdhip64_7.dll` and `amd_comgr.dll` are also put in
|
||||
`engine\` (setup copies them there on every start). Windows looks in the program's folder before System32, where
|
||||
some AMD drivers install their own `amdhip64_7.dll`; with that one, the bundled libraries crashed on the first
|
||||
prompt (an access violation, or `hipErrorInvalidDeviceFunction`). The engine's log names the runtime it loaded
|
||||
(`strata generate: HIP runtime ...`).
|
||||
- **Before the ~60 GB model download** setup runs `engine\strata-device.exe --list-devices` (with `engine\rocm\bin` on
|
||||
the PATH): if the HIP runtime does not see the card, setup stops there and points to the driver. It also gives the
|
||||
card's HIP number: with an integrated Radeon that is device 1, not 0 (#325). From then on setup lists the AMD cards
|
||||
as HIP numbers them, so `--gpu N` and the config's `"gpu"` are HIP numbers.
|
||||
- **Differences from Windows-on-NVIDIA and Linux-on-AMD:** no images yet (the CPU image encoder is Linux-only for
|
||||
now), one card per model (`--gpus` is Linux-only for now), no calibration.
|
||||
- Two Windows-only engine details (#247, #325): hipBLAS can return success and still leave `hipErrorInvalidValue`
|
||||
set after some BF16/FP16 GEMMs (seen on gfx1201); the engine clears that one stale error after a GEMM that
|
||||
succeeded, on Windows only. `hipHostGetDevicePointer` returns the host pointer itself on Windows: kernels read
|
||||
mapped memory through it correctly, but a device-to-device copy into it does not land, which is why
|
||||
`tests/hip/handoff` times out there (the engine does not use that copy; `tests/hip/mapped_alias` reports it).
|
||||
- Two more (#380, #377, by BlueKingMuch, measured on an RX 6800 that drives the desktop): `hipMemGetInfo` on Windows
|
||||
does not subtract what the desktop and other programs hold on the card, so `--expert-cache auto` filled the card
|
||||
past what Windows keeps in VRAM and decode fell from 41 to 30 tok/s. The engine now lowers that free figure by
|
||||
what Windows' video memory budget for the process withholds (logged once: `strata: Windows budgets N of this
|
||||
card's M MiB ...`; `STRATA_WDDM_BUDGET=0` turns it off). And the PCIe probe times its copies on the host clock
|
||||
there, since HIP's events read impossible speeds (3,300-26,000 GB/s), so a slow link now gets a smaller
|
||||
`pcie_frac` as on NVIDIA.
|
||||
|
||||
**What is validated (0.1.34):** #325's author ran the engine of this port on an RX 9070 XT (Windows 11, ROCm
|
||||
10.2.0a20260930 in `.venv`, compiled on the PC): Coder IQ1_M at 32K, 29.2 tok/s decode, ~181 tok/s prefill,
|
||||
correct answers; ctest 42 of 46. The maintainers have no Windows AMD card: the release zip was built on an NVIDIA PC,
|
||||
and checked there on the Ryzen CPU's integrated Radeon (gfx1036, a test build of the same tree): with only the zip's
|
||||
libraries on the PATH, `strata-device` lists the card and a hipBLAS BF16 GEMM matches the CPU; the HIP ctest passes
|
||||
52 of 56, the 4 failures the same as on the RX 9070 XT (`hip_handoff`, and three tests that need a pack fixture).
|
||||
The ready-made zip itself has not run a model on a discrete card yet - please report.
|
||||
|
||||
**Reporting a Windows AMD run** (an issue, or on #325): your card and driver version (AMD Software > System), then
|
||||
|
||||
```bat
|
||||
engine\strata-device.exe --list-devices
|
||||
engine\strata-device.exe --selftest
|
||||
```
|
||||
|
||||
(from the PolyStrata folder, after `set PATH=%CD%\engine\rocm\bin;%PATH%`), the end of `strata-<model>.log`, and the
|
||||
speed lines the server window prints for a first answer.
|
||||
|
||||
**Building it yourself:** `tools\hip\build_windows.bat` (Visual Studio 2022 Build Tools with the C++ workload, Python,
|
||||
git; no admin, no AMD GPU) installs ROCm from AMD's TheRock wheels into `.rocm-win`, builds, and packages
|
||||
`dist\strata-windows-x64-hip.zip`; `START-HERE.bat --backend hip --prebuilt dist\` installs that one.
|
||||
`tools\hip\build_windows.bat tests` also builds the HIP tests (`ctest` in `build-hip-win`, with
|
||||
`.rocm-win\Lib\site-packages\_rocm_sdk_devel\bin` on the PATH). `STRATA_HIP_ARCHS` picks other architectures.
|
||||
|
||||
## Build
|
||||
|
||||
Requirements: a working ROCm driver/runtime, HIP development headers and
|
||||
compiler, hipBLAS and (for tuned dense prefill) hipBLASLt development files, CMake 3.24+, a C++20 host compiler, and Git.
|
||||
The model still needs sufficient system RAM and fast SSD storage for its PLE
|
||||
table. VRAM occupancy alone is not a throughput measurement.
|
||||
|
||||
```sh
|
||||
cmake -S . -B build-hip \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF \
|
||||
-DCMAKE_HIP_ARCHITECTURES=gfx1100
|
||||
cmake --build build-hip --target strata -j2
|
||||
```
|
||||
|
||||
`CMAKE_HIP_ARCHITECTURES` is `gfx1100`, `gfx1101`, `gfx1200`, `gfx1201`, or a list such as `"gfx1100;gfx1201"`
|
||||
(one binary for both). gfx1102 (the same wave32, 64 KiB LDS and dot4 instruction) builds with a warning: it passed
|
||||
ctest (#192), and one RX 7600 XT (16 GB, i7-13700K, 64 GB) ran Swift IQ3_XXS over 146 requests up to 51K context at about 43 tok/s decode (28-50) and 250-300 tok/s prompt (#942); setup accepts it (unvalidated, #938); so does gfx1030 (RDNA2: the older `v_dot4_i32_i8`, a community run in #311). At startup the engine and `strata-device` compare each GPU they use
|
||||
(`gcnArchName` up to the `:` feature suffix) with the architectures the binary was compiled for, and require
|
||||
wave32. A binary carried to another card stops with the card's name, its architecture and the build's list,
|
||||
instead of failing later with "invalid device function".
|
||||
|
||||
If CMake cannot find the HIP compiler, add
|
||||
`-DCMAKE_HIP_COMPILER=/path/to/rocm/llvm/bin/clang++`. On the Fedora-family test
|
||||
host this was `/usr/lib64/rocm/llvm/bin/clang++`. Use the compiler and libraries
|
||||
from the same ROCm installation. Do not enable both GPU backends in one build.
|
||||
|
||||
Native IQ experts are enabled by default. CMake fetches the llama.cpp revision
|
||||
pinned by this repository. For an offline build, point `STRATA_GGML_DIR` at a
|
||||
checkout of that exact revision; using an arbitrary newer checkout changes the
|
||||
dependency being tested.
|
||||
|
||||
## Opt-in chunked prompt GDN on gfx11
|
||||
|
||||
`STRATA_GDN_CHUNKED=1` runs the prompt's gated DeltaNet recurrence in 16-token chunks on the gfx11 matrix cores,
|
||||
with FP16 operands and FP32 accumulation, and fuses the output norm. It is off by default: rounding differs from
|
||||
the token-by-token FP32 recurrence. The CUDA switch of the same name uses a separate FP32 implementation.
|
||||
|
||||
The HIP path accepts gfx1100, gfx1101, gfx1102, gfx1150 and gfx1151, and prompt chunks of at least 64 tokens.
|
||||
Other cards, shorter chunks, an output row stride not divisible by eight, and `STRATA_GDN_REC_HEADS` use the
|
||||
existing recurrence. Runtime measurements and numerical checks were run on gfx1151 only; building for another
|
||||
target does not validate its speed or answers. The synthetic test compares the FP16 output and carried FP32 state
|
||||
against the existing recurrence, and short cases against a double-precision CPU calculation. It covers partial
|
||||
chunks, padded rows, weak decay and a split request; the off/default tests require identical output and state bits.
|
||||
It does not establish model answer equivalence.
|
||||
|
||||
`STRATA_GDN_CHUNKED=2`, which on CUDA skips the SM-count test, is the same as 1 here.
|
||||
|
||||
Measured on a Ryzen AI Max+ 395 (gfx1151, ROCm 7.14.1), UD-IQ4_XS. One layer's recurrence and norm take 1.60x less time than
|
||||
gfx1151's default kernels at 16K and 32K tokens (`hip_gdn_chunked --bench` against `--bench-default`, three runs each: 20.92 ->
|
||||
13.11 ms at 16K, 42.14 -> 26.30 ms at 32K). A whole prompt: the same binary with only this switch changed, a fresh engine per
|
||||
side, 11 pairs in alternating order after a discarded one, the engine's `prompt_ms`, every prompt read in full (no reused
|
||||
tokens). Each engine reads a discarded 4K prompt first, because the first prompt after a start varies more (on those first
|
||||
prompts the same pairs gave 95% intervals of [1.004, 1.032] and [0.981, 1.015]); the prompts follow each other once
|
||||
`/proc/vmstat`'s page-migration and direct-reclaim counters have stood still for 3 s, and a pair in which either prompt still
|
||||
met page migration or direct reclaim was dropped and measured again (3 of the 69 pairs, all 32K with the switch on; kept in, 32K
|
||||
gives 1.020 and 1.015). "Section 5" is the nine variables of `STRIX_HALO.md` section 5 (with `STRATA_PF_SWITCH_MIN_T=2048`);
|
||||
"defaults" is the engine without them (section 4's gfx1151 defaults stay). Times are medians; the ratio is the geometric mean of
|
||||
the 11 off / on ratios with a 95% bootstrap interval; "faster" counts the pairs in which the switch was faster:
|
||||
|
||||
| tokens | arm | off -> on | off / on | faster |
|
||||
|---:|---|---:|---:|---:|
|
||||
| 4,096 | section 5 | 3.703 -> 3.641 s | 1.018 [1.016, 1.020] | 11 of 11 |
|
||||
| 4,096 | defaults | 5.914 -> 5.829 s | 1.014 [1.010, 1.017] | 10 of 11 |
|
||||
| 32,768 | section 5 | 26.157 -> 25.589 s | 1.021 [1.020, 1.023] | 11 of 11 |
|
||||
| 32,768 | defaults | 44.082 -> 43.479 s | 1.015 [1.012, 1.017] | 11 of 11 |
|
||||
| 128,000 | section 5 | 107.149 -> 104.866 s | 1.021 [1.020, 1.023] | 11 of 11 |
|
||||
| 128,000 | defaults | 193.439 -> 191.055 s | 1.014 [1.012, 1.016] | 11 of 11 |
|
||||
|
||||
So about 2% on top of section 5 and about 1.5% on the defaults. At 36 gated-DeltaNet layers the layer figures predict about
|
||||
0.56 s for a 32K prompt; 0.57 s (section 5) and 0.60 s (defaults) were measured.
|
||||
|
||||
First-token KL against the same run without the switch, 12 prompts of 1.5K-24K tokens: UD-IQ4_XS 0.0067 mean (0.044 max) on the
|
||||
defaults and 0.0039 (0.027) on top of section 5; UD-Q4_K_XL 0.0063 (0.043) and 0.0040 (0.014); the same top token in all of
|
||||
them (across the 12 prompts the first token takes only two distinct values). Section 5's switches alone are 0.0068 (IQ4_XS) and
|
||||
0.0031 (Q4_K_XL) against the defaults, a different change that is listed for scale and not as a limit for this one. Only the
|
||||
first generated token was compared: a long generation and perplexity were not measured.
|
||||
|
||||
Build and run these checks in the HIP build directory:
|
||||
|
||||
```sh
|
||||
cmake --build build-hip --target hip_gdn_chunked hip_gdn_rec_head
|
||||
ctest --test-dir build-hip -R 'hip_gdn_(chunked|rec_head)' --output-on-failure
|
||||
for i in 1 2 3; do ./build-hip/hip_gdn_chunked --bench-default; ./build-hip/hip_gdn_chunked --bench; done
|
||||
```
|
||||
|
||||
Each benchmark run reports the GPU-event median of seven runs after two warmups, the same nonzero initial state every run:
|
||||
`--bench` this path, `--bench-default` gfx1151's default kernels (`STRATA_GDN_PP=2`, `STRATA_GDN_NOY=1`). The switch is read
|
||||
once per process, so the two are separate runs. It times one layer's recurrence and norm, not a whole prompt.
|
||||
|
||||
## Model and serving configuration
|
||||
|
||||
Prepare a supported model pack and its MTP runtime using the existing tools.
|
||||
For OrcaRouter IQ3_XXS, follow [the explicit compatibility conversion](ORCA.md);
|
||||
this backend does not change quantization, model licenses, or tokenizers.
|
||||
Add `--experts-bin` to the `tools/iq_pack.py` command: mmap requires the pack's
|
||||
`experts.bin`, which the default native packing command does not emit. This
|
||||
consumes additional disk space. Original GSQ-RCO IQ3_XXS uses shard 2 for PLE;
|
||||
Orca uses shard 1. Keep each model's own pack and tokenizer together.
|
||||
|
||||
Use `build-hip/strata` as the executable in the server JSON. Select the AMD
|
||||
device with `ROCR_VISIBLE_DEVICES`/`HIP_VISIBLE_DEVICES` if necessary. Start with
|
||||
a modest context and prefill chunk size before measuring larger workloads.
|
||||
Keep the PLE file on an SSD. Do not assume a configured context length proves
|
||||
successful full-window inference.
|
||||
|
||||
Large pinned host allocations can fail on ROCm even when ordinary RAM is
|
||||
available. The existing `--mmap-experts` path avoids allocating the full pinned
|
||||
expert arena; it still depends on OS file-cache residency and may stall on
|
||||
storage reads. It does not make SSD access equivalent to RAM.
|
||||
|
||||
Starting args for the original GSQ-RCO IQ3_XXS model (replace the paths):
|
||||
|
||||
```sh
|
||||
build-hip/strata --serve \
|
||||
--pack packs/iq3xxs \
|
||||
--native /path/to/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00001-of-00002.gguf \
|
||||
--ple-gguf /path/to/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00002-of-00002.gguf \
|
||||
--mmap-experts --expert-profile data/expert-profile.bin --expert-cache auto \
|
||||
--prefill 512 --spec 4 --spec-min-p 0.5 --mtp mtp/rt \
|
||||
--max-context 4096 --kv int8 --pool-workers 15 \
|
||||
--adapt-every 0 --pcie-frac 0 --vram-reserve-mib 1024
|
||||
```
|
||||
|
||||
`--serve` is the engine's internal token protocol. For a browser or OpenAI API,
|
||||
put these args in the `args` array of the [server JSON example](ORCA.md#local-server),
|
||||
set `exe` to `build-hip/strata`, and use the matching pack's `tokenizer` directory.
|
||||
Launch with `.venv/bin/python -m serve.server --engine strata --config strata-hip.json --port 8080`.
|
||||
The worker count above was used on a 16-core CPU; measure it for your CPU.
|
||||
The 4K context is a smoke-test starting point, not a model limit. The expert cache
|
||||
sizes itself automatically and leaves 1 GiB of VRAM headroom.
|
||||
|
||||
**The card also drives a Linux desktop (#560 #516):** keep more VRAM free than the default 700 MiB, e.g.
|
||||
`./setup.sh --vram-reserve-mib 3072`. With the cache filling the card, the desktop's next VRAM need makes amdgpu move
|
||||
GPU memory to system RAM (GTT), the OOM killer then ends KWin/plasmashell or `systemd-oomd` ends apps, or the
|
||||
compositor fails with "Failed to pin framebuffer with error -12".
|
||||
|
||||
The installer supports this backend (see "Install with setup" above). Images run through the CPU encoder for now (`--vision cpu`).
|
||||
Setup installs one AMD card, or several with `--gpus` (the engine's layer split; see RDNA4 below).
|
||||
|
||||
**Opt-in switches for RDNA2 prompts and hangs (0.1.40, off by default):** `STRATA_DENSE_MMQ=1` (#820, HIP) runs the
|
||||
prompt's dense GGUF projections through the int8 MMQ kernels instead of dequantize + hipBLAS: on the RX 6900 XT a 4K
|
||||
prompt read 436 -> 757 tok/s (greedy text diverges from the default after a few dozen tokens: the q8_1 activation
|
||||
rounding). `STRATA_HIP_ADAPT_KERNEL_COPY=1` (#884) copies the adaptive tier's swaps with a kernel instead of the SDMA
|
||||
engine, a workaround for the gfx1030 hang seen with the MMQ prompt path and adaptive swaps (untested on the reporter's
|
||||
machine). Windows HIP: the doorbell kernels fence their store (#697), and the shared-expert fork is off on HIP (#816).
|
||||
|
||||
**The shared-expert stream fork (`STRATA_SH_STREAM`):** it is off by default on HIP, except for the gfx1151 table, and
|
||||
that default stays. The measurements disagree by platform. 2x RX 6900 XT on Linux (#1272): turning it off costs 5-13%
|
||||
of decode (one card 47.5 / 46.9 / 48.3 -> 50.5 / 48.5 / 51.3 tok/s with it on). RX 6800 on Windows (#816,
|
||||
`bench/results/2026-10-04-community-rx-6800-windows`): on was 12-22% slower. 4x R9700: fork off was 13-45% faster.
|
||||
Linux RX 6000 users can try `STRATA_SH_STREAM=1`; the output is identical either way. Since the same card goes
|
||||
both ways on different PCs, `./setup.sh --calibrate` measures it on yours (off against on, a restart each) and writes
|
||||
`STRATA_SH_STREAM=1` into the config's `"env"` only when it wins by more than 3%; a later calibration that finds it no
|
||||
longer faster removes it again.
|
||||
|
||||
**The draft's side stream (`STRATA_MTP_SIDE_STREAM`):** HIP does not use the MTP drafter's branch stream, and since
|
||||
0.1.40.2 it does not create it (#1240: an R9700 lost prompt speed with it). gfx103x is the exception and creates it: on
|
||||
an RX 6800 under Windows (`STRATA_HIP_PROMPT_F16=1`, IQ3_XXS, two runs each) a 7.9K-token prompt reads at 798-808 tok/s
|
||||
with the stream and 584-596 without, and a 30.4K-token one at 855-863 against 553-600; `STRATA_PREFILL_TIMING=1` puts
|
||||
the whole difference in the "wait copy" phase (3,081 -> 75 ms and 12,642 -> 288 ms). Decode and the output are the same.
|
||||
`STRATA_MTP_SIDE_STREAM=0` turns it off on gfx103x, `=1` creates it on another HIP card. Measured on one card and one
|
||||
OS; a Linux gfx103x number is welcome.
|
||||
|
||||
**Long prompts on a big card: check the lend-coverage line (#1389, measured by the reporter on an RX 7900 XTX, gfx1100,
|
||||
v0.1.40.2, 50 GB RAM).** With `--resident-experts` the prompt path borrows cache slots, and the experts of those slots
|
||||
must also sit in RAM. After the first request of a start the engine prints
|
||||
`FileExpertSource: N of M of the prompt path's lendable slots keep their experts in RAM too`. When N is not M, the
|
||||
experts not covered are read from the pack during the prompt (now also a `WARNING` line). A 74K prompt routes through
|
||||
nearly all experts, so the misses repeat: the reporter saw `wait copy` at 0.2% and 2,583 tok/s with 6201 of 6201, and
|
||||
36.8% and 1,810 tok/s with 5093 of 6202 (same binary, only the start differed). Short prompts (25K) read the same either
|
||||
way. The resident set is sized from `MemAvailable` at start, minus `STRATA_RESIDENT_HEADROOM_GIB` (default 4, in GiB; the
|
||||
`--resident-experts` switch and `--resident-budget-gib` read it). If the line is short, lower the headroom a little and
|
||||
restart; if the machine then swaps or stalls, raise it again. Re-check the line after a ROCm update: the reporter's newer
|
||||
runtime kept about 1 GiB more host RAM, which moved the best value from 8 to 7. Other levers from the same report (his
|
||||
numbers, not re-measured here): `STRATA_PF_FUSED=1 STRATA_PF_GEMM=1 STRATA_PF_SWITCH_MIN_T=4096` 925 -> 1,092 tok/s,
|
||||
`--resident-experts` 1,092 -> 2,503 tok/s, `--prefill auto:32768` +23% at 74K. The engine uses a hipBLASLt tuning table
|
||||
only when its version matches the installed library; otherwise it prefills on plain hipBLAS (about 45% slower for a 131K
|
||||
prompt), so keep the table and the library paired. Not worth trying (measured flat): `--kv-resident` changes, a prefill
|
||||
chunk above 32768, `--spec` above 4.
|
||||
|
||||
## Exact long-prompt QSA scorer (gfx1100 opt-in, gfx12 default)
|
||||
|
||||
`STRATA_SCORES_THREAD=1` at engine startup enables a HIP port of #1825's score kernel on gfx1100, for batches of
|
||||
at least 64 queries with at least 16,385 live index blocks. On gfx12 (RDNA4) it is on by default for those batches and
|
||||
`STRATA_SCORES_THREAD=0` turns it off (0.1.45): on an R9700 `qsa_scores_gfx1100_parity --full` compares 223,664,777 scores and
|
||||
11,895,800 ids bitwise equal to the warp scorer, the scorer stage with 256 queries is 3.6x faster at 131K and 4.0x at 240K, and a
|
||||
fresh prompt of 131K tokens reads 8.7% faster (4 of 4 pairs) and one of 230K tokens 16.4% faster (3 of 3), with the same answer tokens and byte-identical `exact_pp` residual dumps at 70K and 131K tokens (prompts under 65K cells never reach the bound). The default, short-prompt and decode paths keep the
|
||||
existing scorer. On one RX 7900 XTX / 7950X3D / ROCm 10.0.0, three paired runs of a tuned 0.1.40.3 engine reduced
|
||||
fresh one-token request time by 10.45% at 130,978 prompt tokens and 22.64% at 239,906; one same-binary current-main
|
||||
pair measured 12.85% and 21.71%. Cached follow-ups did not show a repeatable large gain, and a two-task coding pilot
|
||||
was 3.27% slower overall. This is opt-in, not a general coding-speed recommendation. The
|
||||
[report, per-run data and standalone score/ID check](../bench/results/2026-10-11-gfx1100-qsa-scores/README.md)
|
||||
give the settings, exact-parity checks and limits. `STRATA_SCORES_THREAD_TRACE=1` prints an engagement line.
|
||||
|
||||
## Deep contexts: the prompt's top-k selection (0.1.45, #1749)
|
||||
|
||||
Past ~135K cells (and from ~90K cells on a prompt read) the prompt's top-k selection runs the wide kernel, as on CUDA, instead of the four-pass
|
||||
reference radix that every deep context on HIP paid; the same ids (`qsa_select_bench` compares them with the reference). On an R9700 the
|
||||
selection of a 256-query batch is 0.29 -> 0.21 ms at 98K, 1.16 -> 0.49 ms at 262K and 22.0 -> 0.93 ms at 524K; a fresh prompt reads 1.3% faster at
|
||||
230K tokens and 34% faster at 500K (716 -> 962 tok/s; 1,284 tok/s with the exact scorer above, 79% in all), with the same answer tokens.
|
||||
`STRATA_TOPK_OLD=1` runs the original kernel, `STRATA_TOPK_STREAM=0` the register kernel in the 90K-135K band.
|
||||
|
||||
## Linux: verify timeouts while the kernel reclaims host memory (experimental workarounds)
|
||||
|
||||
A `verify: timed out at layer N` or "no progress for 60 s" message does not by itself mean a kernel or handshake bug. Two
|
||||
community reports found the same mechanism: the GPU's queues are suspended while the kernel reclaims host pages the GPU
|
||||
has pinned through a KFD userptr, and a restore that keeps returning `-EAGAIN` leaves them suspended for tens of seconds.
|
||||
Each report is one machine, one workaround, and the cause is not confirmed on either; neither is a default or a general
|
||||
speed claim, and neither is known to matter on Windows or on other ROCm versions.
|
||||
|
||||
- **Paged host allocations (#750, two Radeon AI PRO R9700, ROCm 7.2):** tracing correlated a timeout with about 31 s of
|
||||
USERPTR queue suspension on both cards. ROCr uses USERPTR for paged host allocations unless `HSA_USERPTR_FOR_PAGED_MEM=0`.
|
||||
With it in the server JSON `env`, five paired runs gave the same outputs and the same median (7 requests: 16.65 s against
|
||||
16.63 s), without the 29.8 s and 42.2 s outliers; solo requests were a little slower (3.55 s to 3.69 s).
|
||||
- **`--mmap-experts` (#920, RX 6800 gfx1030, ROCm 7.2.4, 31 GiB RAM, IQ3_XXS):** every run stalled until
|
||||
`GPU_PINNED_MIN_XFER_SIZE=1048576` was in the `env`, and none has since. HIP pins the pageable source pages of large
|
||||
copies, here the mapped expert file. (The engine already sets this variable for `STRATA_ARENA_MMAP=1`.)
|
||||
|
||||
```json
|
||||
"env": { "GPU_PINNED_MIN_XFER_SIZE": "1048576" }
|
||||
```
|
||||
|
||||
Change one setting at a time with the rest of the configuration the same, restart the engine so the runtime reads it, and
|
||||
remove it to go back to the default. Check free RAM and the driver's GTT limit before large-context tests. If the engine
|
||||
runs in a systemd unit, limit it with `MemoryMax`, never `MemoryHigh`: `MemoryHigh` counts the page cache that
|
||||
`--mmap-experts` reads from, and a 16K prompt stalled in `pread` for 8 minutes under it. In a report, give the runtime and
|
||||
kernel versions, whether reclaim coincides with KFD queue eviction, and paired timings.
|
||||
|
||||
## RDNA4 (gfx1201)
|
||||
|
||||
The RX 9070 / 9070 XT and the Radeon AI PRO R9700 run the same kernels as gfx1100: wave32, 64 KiB of LDS per
|
||||
workgroup, the signed dot4 instruction (`v_dot4_i32_iu8` through `__builtin_amdgcn_sudot4`) and a 100 MHz wall
|
||||
clock. The first report and patch came from doplxyz (#178). Validated on 2026-09-30 on doplxyz's test machine:
|
||||
an RX 9070 XT 16 GB and a Radeon AI PRO R9700 32 GB (both gfx1201), a Ryzen 9 3900X (16 threads, no AVX-512),
|
||||
47 GB RAM, Ubuntu 24.04 in a KVM/VFIO guest.
|
||||
|
||||
- **Build:** complete HIP build with tests (`-DCMAKE_HIP_ARCHITECTURES=gfx1201 -DSTRATA_BUILD_TESTS=ON
|
||||
-DSTRATA_PREFILL_MMQ=ON`), with the system ROCm 7.14 (hipBLASLt 1.4.1) and with setup's own path: TheRock
|
||||
7.10.0a20251120 wheels from `gfx120X-all` (hipBLASLt 1.2.0) and `build_engine_hip`.
|
||||
- **ctest** (all 45 registered tests, R9700): 42 pass, `hip_prefill_hipblaslt_gemm` skips (no table), and two
|
||||
fail for reasons outside the GPU: `ple_parity` needs the Q2_0 model fixture, `expert_multi_test` needs an
|
||||
AVX-512 CPU. `hip_handoff` needed the volatile ring store: on gfx1201 a plain store to mapped pinned memory
|
||||
stays in the GPU's L2 until the stream is synchronized.
|
||||
- **Arch check:** a gfx1100-only build stops on the gfx1201 card at startup with the message above (engine and
|
||||
`strata-device`).
|
||||
- **End to end** (Coder IQ1_M, setup's arguments: `--expert-cache auto --prefill auto --spec 4 --spec-min-p 0.5`,
|
||||
MTP, `--kv int8`, `--max-context 32768`; 128 greedy tokens, system ROCm 7.14, no hipBLASLt table). The answers
|
||||
are coherent and the same on both cards. The live server smoke (`serve/server.py`: web page, models, props,
|
||||
chat, prefix reuse, streaming, the Anthropic endpoint, a sampled code answer) passed 9/9 on each card.
|
||||
|
||||
| card | expert cache | peak VRAM | 4K prompt | 4K decode | 16K prompt | 16K decode |
|
||||
|---|---|---|---|---|---|---|
|
||||
| Radeon AI PRO R9700 32 GB | 12,288 slots, 23.4 GiB | 29.7 GiB | 982 tok/s | 45.5 tok/s | 1,402 tok/s | 48.3 tok/s |
|
||||
| RX 9070 XT 16 GB | 4,931 slots, 9.4 GiB | 15.6 GiB | 782 tok/s | 30.8 tok/s | 1,235 tok/s | 35.4 tok/s |
|
||||
| R9700, TheRock 7.10 wheels | 12,288 slots | | 957 tok/s | 44.2 tok/s | 1,284 tok/s | 43.9 tok/s |
|
||||
|
||||
The engine's resident memory was about 26 GB in every run. Since 0.1.31 `__byte_perm` is one `v_perm_b32` and the
|
||||
packed byte subtracts/compare work on four lanes at once (#262, ttio2tech): decode +15% on the R9700 (46.0 -> 53.0
|
||||
tok/s on a 4K prompt, 52.0 -> 60.5 warm) and +5-7% on the 9070 XT, prompts unchanged, the same tokens.
|
||||
- **hipBLASLt:** the validation above used hipBLASLt 1.4.1. A table calibrated on the R9700 at the engine's shapes
|
||||
with that version (0.98-1.76x per GEMM over hipBLAS) changed the end-to-end prompt speed by 0-3%, within noise,
|
||||
so none was shipped for it: there the plain hipBLAS path is already close (a table I calibrated on my own R9700
|
||||
with 1.4.1 measured the same: 1.15x per GEMM, +1% prompt - see "Tuning table" below). For hipBLASLt 1.5.0 (ROCm
|
||||
10.2.0a nightly) `tools/hip/gfx1201-hipblaslt-100500.txt` is shipped (see "Tuning table" below); on one R9700 it
|
||||
measured +3.9% prompt speed on 4,210-token prompts (1,590 vs 1,531 tok/s), a modest gain.
|
||||
With the hipBLASLt 1.2.2 of a system ROCm 7.2.4 the plain path is far off, and `tools/hip/gfx1201-hipblaslt-100202.txt`
|
||||
is shipped for it (24 of the gfx1100 table's 26 shapes; setup uses it only with that exact version): on an R9700
|
||||
with the full IQ3_XXS, `--kv int8 --kv-resident 32768`, a fresh 32K prompt read at 638 -> 1,177 tok/s and a 7K one
|
||||
at 656 -> 1,164 tok/s with it, decode unchanged. `hip_prefill_hipblaslt_gemm` passes with it.
|
||||
- **Both cards in one run (layer split, engine 0.1.30):** the config's `"backend": "hip", "gpu": [1, 0]` (R9700
|
||||
first) runs through `serve/server.py` (setup writes it with `--gpus 1,0` since 0.1.31). Auto split put layers 0-27 on the R9700 and
|
||||
28-47 on the 9070 XT. With every expert on the GPUs the split gives exactly the tokens of the R9700 alone (4K and
|
||||
16K prompts); checkpoints on the split (second turn, rewind, a prompt sharing a prefix, a cancelled prompt
|
||||
retried) give exactly the tokens of a fresh read. The conversation cache refuses a split at start (exit 2).
|
||||
On this pair the split does not pay: the R9700 alone already holds all 12,288 expert pairs.
|
||||
|
||||
| run (the same session, warm) | 4K prompt | 16K prompt | decode |
|
||||
|---|---|---|---|
|
||||
| R9700 alone | 1,794 tok/s | 1,804 tok/s | 51-52 tok/s |
|
||||
| R9700 + 9070 XT, auto split | 1,384 tok/s | 1,906 tok/s | 42-43 tok/s |
|
||||
| RX 9070 XT alone | 1,016 tok/s | 1,519 tok/s | 38-40 tok/s |
|
||||
|
||||
A split is worth it when no single card holds the model's experts. Since 0.1.31 a split pins the whole expert
|
||||
arena on Linux (the 8 GiB cap is for Windows/WSL2 only, #253): with an expert cache of 1,500 on the R9700 (most
|
||||
experts streamed) the split read a 16K prompt at 1,803 tok/s instead of 1,287, with the same tokens in 5 + 5
|
||||
starts. `"split_skip_if_fits": true` in the config (0.1.31, opt-in) runs such a pair on the first card alone when it
|
||||
holds every profiled expert: with the R9700 first, 4K prompts 1,776 tok/s (split: 1,244) and decode ~60 tok/s
|
||||
(split: ~51), the tokens of the R9700 alone (docs/MULTI_GPU.md).
|
||||
- **Speed switches (engine 0.1.32, measured on the R9700 / 9070 XT with the Coder IQ1_M pack):**
|
||||
- the MoE router (`router_top10`) runs a HIP kernel without its serial FP64 sum and block barriers by default: the
|
||||
same ids and weights bit for bit (`hip_router_fast` checks 65,536 rows), 39 -> 9-12 us per call, the same greedy
|
||||
tokens (5 + 5 starts). Decode: 62.4 -> 70.0 tok/s on the R9700 and +4% on the 9070 XT in one A/B here (ROCm 10.2
|
||||
nightly); a user's repeated A/B/A/B with setup's TheRock 7.10 wheels and an i5-12600K measured +1-4%, inside a
|
||||
12-20% run-to-run spread (#432) - how much it gains depends on how much of decode the router is on that setup.
|
||||
`STRATA_HIP_ROUTER_OLD=1` runs the portable kernel.
|
||||
- `STRATA_HIP_WMMA=1` (opt-in, gfx12 only, int8 KV): the prompt path's QSA attention on RDNA4 matrix cores (the engine prints a one-line hint about it at start on gfx12 with `--kv int8`; it never enables it, because the output bits change; setting the variable to anything, 0 included, silences the hint)
|
||||
(`v_wmma_f32_16x16x16_f16`, FP16 hi + lo halves like the CUDA tensor-core kernel; `hip_prompt_attn_wmma` bounds it
|
||||
against the FP32 kernel and FP64). 7.2-7.5x the portable kernel; R9700 prompts 4K 1,784 -> 2,427 tok/s, 16K
|
||||
1,797 -> 2,700 (a user with TheRock 7.10: +29-34%, #432). Not bitwise: greedy text differs from token ~50 on, as with the CUDA tensor-core attention. With it
|
||||
the prompt path's expert ring is 96 slots (as STRATA_PREFILL_RING=96): with the default 384 the 9070 XT's 4K
|
||||
prompts fell to 718 tok/s; with 96 they gain (1,017 -> 1,211; 16K 1,518 -> 2,032). PR #329
|
||||
(bsorensen110) contributed an equivalent gfx12 WMMA kernel of the same speed (within 1%); this one also masks KV
|
||||
pages that KV streaming has not made resident, as the decode kernel does. On my R9700 (engine 0.1.40,
|
||||
IQ3_S at 431072 ctx, `--kv int8`, the gfx1201 hipBLASLt 1.4.1 table below, which names the machine, GPU idle):
|
||||
fresh prompts of 4,210 and 8,830 tokens - the longest prompt I measured there is 8,830 tokens, the 431072 ctx is
|
||||
what the model runs at, not what these prompts reach - three matched trials each, the first fresh prompt after
|
||||
each start left out: 1,571 -> 2,064 and 1,568 -> 2,065 tok/s at 8,830 tokens (+31.4 and +31.7%) and 1,699 ->
|
||||
1,990 at 4,210 (+17.1%), medians 1,571 -> 2,064 and a 1.27x geometric mean over those three. decode
|
||||
89.8 -> 86.9 tok/s, unchanged. `STRATA_SELECT_WMMA=1` on top changed nothing at those lengths (2,026 tok/s);
|
||||
its +1.5% is a 16K/262K-ctx number. `hip_prompt_attn_wmma` passes on that card.
|
||||
- The prompt path's QSA top-k picks its kernel by the blocks a query actually has, not the cache's capacity (#337,
|
||||
bsorensen110): the same ids, on by default with AMD (NVIDIA keeps its capacity rule: there the 64K prompts read
|
||||
1-3% slower with it). `STRATA_SELECT_WMMA=1` (opt-in, gfx12) adds #337's
|
||||
matrix-core block scorer; it selects slightly differently (254 of 256 queries the same) and gained +1.5% on 16K
|
||||
prompts at a 262K context on the R9700.
|
||||
- `STRATA_PF_FUSED=1` (opt-in, gfx1200 / gfx1201, the native IQ packs, #1277): the prompt's experts run on int8
|
||||
matrix-core kernels (`v_wmma_i32_16x16x16_iu8`: the gfx11 kernels with gfx12's lane layout) instead of MMQ. Earlier
|
||||
engines ignored the flag on RDNA4 (MMQ stayed, no banner); now the engine prints `strata: prompt experts on the fused
|
||||
int8 kernels (STRATA_PF_FUSED=1, #136)` once, at the first prompt. It is not an arch default: it rounds differently
|
||||
from MMQ, and those defaults hold only bit-identical switches. `STRATA_PF_FUSED_NATIVE=0` keeps MMQ with the flag set
|
||||
(for an A/B). R9700 (gfx1201, ROCm 7.14, Coder IQ1_M pack), prompt time as the server reports it, alternating
|
||||
starts per arm: 4K 1,612 -> 1,353 ms (+19.1%), 16K 5,579 -> 5,147 ms (+8.4%), 32K 11,890 -> 10,962 ms (+8.5%); a
|
||||
second run of 3 starts per arm gave +12% to +16% at 4K (it depends on the start) and +8.3% at 16K; the
|
||||
kernels alone are 1.48x / 1.20x / 1.14x MMQ's at 4K / 16K / 32K. Quality: first-token KL against the FP16 prompt path
|
||||
at 4K (48 prompts) is 1.10x MMQ's, which that sample cannot tell apart from MMQ's; top-1 agreed on 48 of 48 (every
|
||||
prompt's top token was the same one, so that check says little); 4 of 4 long-context retrieval checks passed.
|
||||
0.1.42 re-check on an R9700 (Linux, ROCm 7.14), 12 prompts of 1.5K-24K tokens, first-token KL against the FP16 prompt path (MMQ / fused): IQ3_S 0.00332 / 0.00284, top-1 12 of 12 for both; IQ3_XXS 0.00335 / 0.00452 on one sample and 0.00344 / 0.00323 on a second (24 prompts pooled: 0.00340 / 0.00388, top-1 24 of 24 for both); the Q2_0 pack does not take these kernels on gfx12 (output bit-identical to MMQ). Because the IQ3_XXS pool is not at or below MMQ's, the flag stays opt-in. Measured on Linux only.
|
||||
gfx1200 builds the same kernels and was not run; Windows and K-quant packs (`STRATA_PF_FUSED_KQ=1`) were not measured.
|
||||
- **Known:** rarely (about 1 start in 10) a HIP run's greedy output differs from another start's at some token, on
|
||||
one card or two and on engine 0.1.29 as well; not yet explained.
|
||||
- **Not validated:** images, long contexts beyond 16K, answer-quality benchmarks.
|
||||
|
||||
## strata-poly on AMD (beta)
|
||||
|
||||
The four smaller models of PolyStrata's own engine (Qwen3.6, Ornith 1.5, Gemma 4, Tiel Coder) and GLM 5.3 Flash
|
||||
run through `strata-poly`, which is CUDA-shaped code; since 0.1.42-poly.4 it compiles for an AMD card through the
|
||||
same `hip_compat` headers as the main engine, with the CUDA driver's virtual memory calls mapped onto HIP's
|
||||
(`hip_compat/cuda.h`). Linux only: there is no ready-made AMD engine, and setup refuses these models on an AMD
|
||||
card under Windows.
|
||||
|
||||
- Install as for NVIDIA: `./setup.sh --family qwen36` (or `lfm25`, `ornith`, `gemma4`, `tiel`, `glm`, `deepseek`).
|
||||
Setup compiles the engine for the card into `engine-poly/` (`build_engine_poly_hip`), with ROCm from a system
|
||||
install or AMD's wheels in `.venv`, as for the main engine, and compiles again after a `git pull` that changed the
|
||||
engine.
|
||||
- Images stay off: the image encoder is a CUDA program.
|
||||
- The attention caches take their VRAM at load on an AMD card (`--kv-whole`; setup writes it into the config and
|
||||
adds it to an older one on update). On NVIDIA they grow with the conversation, and the expert cache gives VRAM
|
||||
up to them as it grows; on ROCm the VRAM that `hipMemUnmap` and `hipMemRelease` give back never returns to the
|
||||
free pool (an RX 7600 showed 48 MiB free after releasing 1 GiB, [#13](https://github.com/VecSzn/PolyStrata/issues/13)), so a long prompt was refused
|
||||
with "no VRAM for the attention cache". With the caches whole, 32K of context fits on 8 GB beside 4,592 of
|
||||
Qwen3.6's 10,496 experts (4.4 GiB).
|
||||
- Measured by the port's author on an RX 7600 (gfx1102, 8 GB; Ryzen 5 5600X, 30 GB of RAM) with the README's
|
||||
benchmark, `--kv-whole` on ([#13](https://github.com/VecSzn/PolyStrata/issues/13)):
|
||||
|
||||
| Model | Short chat, writes | After a 32K prompt, reads / writes |
|
||||
| --- | --- | --- |
|
||||
| Qwen3.6-35B-A3B UD-Q2_K_XL | 74 tokens/s | 481 / 53 tokens/s |
|
||||
| Ornith 1.5 APEX-I-Mini | 40 tokens/s | 444 / 43 tokens/s |
|
||||
|
||||
The first tokens after a load come slower while the expert cache fills (the port's own steady-state figures
|
||||
were 64 and 35 tokens/s, with 5,125 and 4,517 experts in VRAM). Gemma 4, Tiel Coder and GLM have not been tried
|
||||
on an AMD card, and setup warns so.
|
||||
- The same greedy tokens as on CUDA are not promised across backends, as above, and the card's experts and the
|
||||
CPU's do not give the same ones on either: with every expert on the CPU (`--no-gpu-experts`) a greedy answer
|
||||
parts from the card's after 15 to 50 tokens on the RX 7600, and after 11 to 70 on an RTX 5090 (Qwen3.6
|
||||
UD-Q2_K_XL and UD-Q3_K_M, a 24-token and a 1.2K-token prompt, 256 tokens, mean KL of the top 40 before the
|
||||
parting 0.0001 to 0.005; each side gives itself the same tokens in a second round). The two sum an expert's
|
||||
products in a different order, and a near tie goes the other way. On CUDA the port changes nothing: the same
|
||||
tokens and speed as before on an RTX 5090.
|
||||
|
||||
## Community-validated cards
|
||||
|
||||
Run by their owners, not on the maintainers' machines; setup accepts them like gfx1100 / gfx1201. setup ships a
|
||||
hipBLASLt table for gfx1200 (the numbers below); gfx1101 has none (make one with [Tuning table](#tuning-table)
|
||||
and compare the prompt speed with and without it).
|
||||
|
||||
- **gfx1101, RX 7800 XT 16 GB** (jhohertz, #254; engine 0.1.29, Ryzen 9 5950X, 121 GiB RAM, system ROCm with
|
||||
hipBLASLt 1.4.1): `./setup.sh --backend hip` detected the card and compiled the engine; `strata-device --selftest`
|
||||
passed; ctest 30/32 (`ple_parity` needs the Q2_0 fixture, `platform_memory_test` the memlock limit). Coder IQ1_M,
|
||||
64K context, MTP, with a table the owner calibrated: fresh prompts of 4K-9K tokens at 898-953 tok/s, decode
|
||||
38-44 tok/s (128 tokens).
|
||||
- **gfx1200, RX 9060 XT 16 GB** (Efeisot, #256 after #176; engine 0.1.29, Ryzen 9 7950X, 64 GiB RAM, ROCm 7.2 with
|
||||
hipBLASLt 1.2.2): ctest 32/32 (without `ple_parity` and `platform_memory_test`). Coder IQ1_M, greedy, MTP
|
||||
`--spec 4 --spec-min-p 0.5`, with a table the owner calibrated:
|
||||
|
||||
| prompt | prompt speed | decode |
|
||||
|---|---|---|
|
||||
| 2,374 tokens | 540 tok/s | 27.1 tok/s (0.69 draft acceptance; 31.0 at 1.00) |
|
||||
| 65K (`--kv int8 --kv-resident 65536 --prefill 16384`) | 748-753 tok/s | 26-40 tok/s by acceptance |
|
||||
| 130K (the same flags) | 725 tok/s | - |
|
||||
|
||||
Greedy output was the same across runs. For comparison, llama.cpp's HIP build measured 20 tok/s decode and
|
||||
450 tok/s prompt on that card.
|
||||
|
||||
Since 0.1.38 setup ships that table (`tools/hip/gfx1200-hipblaslt-100202.txt`). On engine 0.1.31, one binary (ctest
|
||||
37/37, without `ple_parity` and `platform_memory_test`), prompts of repeated code blocks, prefill 2560 for
|
||||
the short prompt and 16384 with `--kv int8 --kv-resident 65536` otherwise, two runs each - prompt speed
|
||||
with the table vs plain hipBLAS (no table):
|
||||
|
||||
| prompt | with the table | plain hipBLAS | gain |
|
||||
|---|---|---|---|
|
||||
| 2,374 tokens | 597-599 tok/s | 396-398 tok/s | 1.50x |
|
||||
| 65,045 tokens | 754-757 tok/s | 380 tok/s | 1.99x |
|
||||
| 130,091 tokens (the same flags) | 719 tok/s | 363-370 tok/s | 1.98x |
|
||||
|
||||
## RDNA2 (gfx1030)
|
||||
|
||||
The RX 6800 / 6800 XT / 6900 XT / 6950 XT run the same kernels: wave32 and 64 KiB of LDS per workgroup. The one
|
||||
difference is the dot instruction: RDNA2 has no `v_dot4_i32_iu8` (gfx11 and newer), so
|
||||
`dp4a` uses the plain signed `v_dot4_i32_i8` through `__builtin_amdgcn_sdot4`, which compiles to a single
|
||||
`v_dot4c_i32_i8` (same signed x signed byte products, modulo 2^32). There is no WMMA; the QSA scorer takes the
|
||||
same ordered FP32 fallback as gfx1100. CMake lists gfx1030 as unvalidated (the build warns) until a maintainer has
|
||||
run it; the report below is from a community machine: an RX 6900 XT 16 GB (gfx1030), an i7-13700KF (8 P-cores and
|
||||
8 E-cores, AVX2, no AVX-512), 63 GB RAM, NixOS, ROCm 7.2.3 from nixpkgs (clang 22, hipBLAS 3.2).
|
||||
|
||||
- **Build and tests** (engine 0.1.26): a complete HIP build for gfx1030, made by hand with cmake and ROCm's own
|
||||
`clang++` (the nixpkgs ROCm is not an `/opt/rocm` tree, so setup's `build_engine_hip` was not exercised; the
|
||||
binary was placed in `engine/` for setup to use). All 28 registered ctest tests pass on the card, including
|
||||
`hip_device_selftest`. An engine 0.1.30 build of this branch configures, builds and runs clean on the same card;
|
||||
the speeds below are measured on it.
|
||||
- **End to end** (Swift 1.5 IQ3_XXS, `--context 131072` with `--kv-resident 32768 --adapt-every 1
|
||||
--vram-reserve-mib 1024`, 200 greedy tokens): 38-42 tok/s decode with the default 15 CPU pool workers (one per
|
||||
physical core except the host thread; 8 workers: 36; 24 = every logical core: 27), consistent even with the
|
||||
131,072-token context full.
|
||||
- **Prefill** (the same 15-worker configuration): 246 tok/s on a 2,000-token prompt, 330-339 tok/s at the auto
|
||||
8,192-token chunk (7,997 and 15,967 tokens; time to first token 8.9 and 48.3 s), 133 tok/s on a 522-token
|
||||
prompt - short prompts are fixed overhead (19-25 tok/s on 34 tokens). Decode after a 16K prefill holds at
|
||||
45.5 tok/s.
|
||||
- **16 GB card:** the expert cache holds 6,310 slots (10.2 GiB) at 16K context and 5,247 slots at 131,072, where
|
||||
setup keeps the KV cache in VRAM because IQ3_XXS needs about 60 GB of RAM plus the cache to stream it. The
|
||||
`--pcie-frac 0` and `--adapt-every 0` of the 7900 XTX configuration in
|
||||
[AMD_HIP_PERFORMANCE.md](AMD_HIP_PERFORMANCE.md) cost 8.6 and 13.6 tok/s here (30 with the defaults): keep the
|
||||
defaults on a 16 GB card.
|
||||
- **hipBLASLt:** ROCm's hipBLASLt ships no gfx1030 kernels, so there is no table and the plain hipBLAS path runs.
|
||||
- **Prompt GEMMs in FP16 (#835):** rocBLAS on gfx1030 has tuned kernels for FP16-in / FP16-out GEMMs only; the prompt
|
||||
path's FP16-in / FP32-out and BF16 products ran generic kernels about 6.6x slower (5.6 and ~5.3 TFLOPS against 37.7 at
|
||||
N = 10240, T = 7313, K = 2560). `STRATA_HIP_PROMPT_F16=1` (opt-in, off by default; the engine prints a tip on gfx103x) runs the 16-bit prompt GEMMs FP16 in and out;
|
||||
unset is the old path. `STRATA_DBG_NAN=1` also counts the non-finite FP16 outputs (a sum past 65504). The output is not bit-identical to it (an FP16 rounding of each GEMM's output replaces the BF16 rounding of
|
||||
the BF16 GEMMs' activations); what the distribution check showed and did not show is in
|
||||
[bench/results/2026-10-04-rdna2-fp16-prompt](../bench/results/2026-10-04-rdna2-fp16-prompt/README.md). FP16 ends at
|
||||
65504: `STRATA_F16_RANGE=1` prints, per prompt, the largest value that entered or left FP16 and how many were beyond
|
||||
the range (466K tokens there: outputs peak at 410, activations at 112, none beyond; the image writers saturate, a GEMM
|
||||
output beyond the range would be Inf and is what the counter is for). Measured on a
|
||||
second community machine - 2x RX 6900 XT 16 GB (one card for these numbers), Ryzen 5 5600X (6 cores, AVX2), 128 GB,
|
||||
Ubuntu 26.04, ROCm 10.0.0, engine 0.1.39 built by hand with `-DSTRATA_PREFILL_MMQ=ON` as setup does, GSQ-RCO IQ3_S:
|
||||
a 9.4K / 34.7K / 105.8K-token prompt reads at 744 / 915 / 926 tok/s instead of 439 / 466 / 461; decode is unchanged.
|
||||
On that machine the HIP ctest passes 60 of 65 with and without this change: 2 skipped (`hip_prompt_attn_wmma`, no
|
||||
matrix cores; `hip_prefill_hipblaslt_gemm`, no hipBLASLt table) and 3 that fail for reasons outside the engine
|
||||
(`ple_parity` needs a Q2_0 PLE file that is not on that machine, `expert_multi_test` refuses the CPU without AVX-512,
|
||||
`platform_memory_test` cannot `mlock` at the shell's default `ulimit -l`).
|
||||
- **The verifier's hyper-connection read as one persistent kernel:** `STRATA_HC_PERSIST=1` (opt-in, HIP, 32-lane
|
||||
waves) runs the read of 1-8 tokens as one kernel of 80 blocks with two grid barriers instead of three launches; a
|
||||
start-up run per token count with a barrier timeout decides where it is resident, and one `strata hc:` line per card
|
||||
says so. On 2x RX 6900 XT (ROCm 10.0, layer split): the read 1.35-2.10x, ms per verify window -4.2 % / -2.8 % at
|
||||
4K / 32K (6 rounds), not bit-identical (as close to a double-accumulation reference as the default read):
|
||||
[bench/results/2026-10-12-hc-persist-gfx1030](../bench/results/2026-10-12-hc-persist-gfx1030/README.md). Other
|
||||
RDNA cards are untested; the `strata hc:` line and a `STRATA_DECODE_TIMING` run from one are welcome. Not offered on gfx11 and
|
||||
gfx12 (RDNA3, RDNA4): the barrier timeout needs `s_memrealtime`, which gfx1100 and gfx1200 / gfx1201 do not have, and an R9700 (#2226 thread) measured the
|
||||
read +0.7 % / +1.0 % per window slower than the default one; the start-up line says so. A barrier that times out at run time
|
||||
(never seen in a working run) leaves the partial outputs of that read in place and every later persistent read of the
|
||||
process aborts at once, without a log line; the opt-in is for measurement on gfx103x until that is closed.
|
||||
- **Prompt GEMMs as SGEMMs (engine 0.1.39 + `Gemm::rdna2_sgemm`):** the rocBLAS in setup's ROCm (10.2.0a20260930)
|
||||
has tuned gfx1030 kernels for FP16 -> FP16, int8 and FP32 -> FP32 only. The prompt path's dense GEMMs take FP16 or
|
||||
BF16 inputs and write FP32 (rocBLAS's HS / BS types), which run its fallback kernels at about 5 TFLOPS. With
|
||||
`STRATA_RDNA2_SGEMM=1` (opt-in; `=all` forces it on any AMD card) the engine widens both inputs to FP32 (exact) and runs SGEMM,
|
||||
which accumulates in FP32 like the native call (`src/prefill/gemm.cu`; N < 64 keeps the native call). The author ran it
|
||||
as the gfx103x default; here it is a switch because it is not bit-identical to the native call (below). Measured on an RX 6800 16 GB over OCuLink (PCIe 4.0 x4, 7.1 GB/s), Ryzen 7 8845HS, 28.8 GB RAM, Windows 11,
|
||||
Coder IQ1_M with setup's arguments (64K context, MTP), fresh 12K-token prompts, 4 per arm, A/B in one binary:
|
||||
|
||||
| | native GEMMs | SGEMM route |
|
||||
|---|---|---|
|
||||
| prompt | 312 tok/s | 452 tok/s |
|
||||
| prompt GPU timeline (`STRATA_PREFILL_TIMING`) | 37.2 s | 25.5 s |
|
||||
| of which gdn / qsa proj / hc read | 9.4 / 3.6 / 3.85 s | 2.8 / 1.4 / 2.84 s |
|
||||
| decode | 29-34 tok/s | 29-35 tok/s |
|
||||
|
||||
The exact calls on the card (opA = T, opB = N, FP32 out): N 10240 x T 8192 x K 2560 86.7 -> 27.7 ms including
|
||||
the widening; N 320 x T 8192 x K 10240 (BF16) 10.9 -> 7.5 ms. Against a float64 reference on random inputs in
|
||||
[-1, 1], the SGEMM route is as close as or closer than the native call on all 10 FP16 / BF16 shapes checked; the
|
||||
two differ by at most 4.3e-6 of the largest output. A 9-task code-repair benchmark (the model patches seeded bugs
|
||||
in a browser game until 38 browser checks pass) solved 9/9 on the first try with both, model time 458 -> 374 s.
|
||||
With the switch on and `STRATA_HIP_PROMPT_F16` unset the SGEMM route runs; with `STRATA_HIP_PROMPT_F16=1`
|
||||
the FP16 route above runs first and the SGEMM route takes the products it leaves (`beta != 0`). Same RX 6800, one
|
||||
session, fresh 12K-token prompts: native 310, SGEMM 439, FP16 (#835) 494 tok/s; `STRATA_F16_RANGE=1` on the Coder
|
||||
IQ1_M peaked at 105.3 (activations) and 424.8 (FP16 outputs) with nothing beyond 65504, and the repair benchmark
|
||||
solved 9/9 on the first try with both (model time 374 s SGEMM, 307 s FP16). The SGEMM route is the slower of the
|
||||
two; no value passes through FP16, so it has no 65504 limit to stay under. It is not bit-identical to the native
|
||||
call (at most 4.3e-6 of the largest output apart), which can flip a near-tied greedy token like any such change.
|
||||
- **rocBLAS solution table** (for the `STRATA_HIP_PROMPT_F16=1` route above; with it off, nothing runs through the
|
||||
table): rocBLAS picks the kernel for each of those FP16 GEMMs from its own table by shape, and
|
||||
on gfx1030 that pick is far from the best kernel the library holds for some shapes: the GDN input projection
|
||||
(N = 10240, K = 2560) below about 1,150 tokens runs at 5 TFLOPS where the best of rocBLAS's own 237 solutions for the
|
||||
same shape runs at 32-38 (7x; the kernel choice flips at T = 1152). `tools/hip/tune_rocblas` enumerates the library's
|
||||
solutions per shape and token bucket, checks each against the default kernel's output and writes the winners as
|
||||
`tools/hip/<arch>-rocblas-<version>.txt`; the engine reads the table through `STRATA_ROCBLAS_TUNING` (a file, or
|
||||
the directory, from which it takes the file of its own rocBLAS build) and runs those solutions in place of rocBLAS's
|
||||
choice, the default kernel for every shape without a row. Solution indices are valid for one architecture and one
|
||||
rocBLAS build (the full version string, `5.6.0.8d1ae90e` for ROCm 10.0.0's), and the engine refuses any other
|
||||
table. Shipped: `gfx1030-rocblas-5.6.0.8d1ae90e.txt` (ROCm 10.0.0, the `/opt/rocm` setup installs on Ubuntu), measured
|
||||
on an RX 6900 XT. Other gfx1030 cards (RX 6800 / 6800 XT / 6950 XT, Radeon PRO W6800 / V620) run it as well - the
|
||||
indices are valid on every gfx1030 - but have fewer CUs or other clocks, so their own table may pick differently;
|
||||
`tune_rocblas` makes one in about 5 minutes ([Tuning table](#tuning-table)), and a report of what it changed is welcome. Setup
|
||||
points the engine at the directory when a table for the card's architecture exists, and the engine's log says
|
||||
`rocBLAS tuning enabled (... rows ...)` or why not. Measured on the 2x RX 6900 XT machine above (one card, #835 +
|
||||
this, `STRATA_PREFILL_TIMING=1`, temperature 0, the same answers with and without): a 799-token prompt's GPU time
|
||||
3,329 -> 2,985 ms (the GDN projections 443 -> 177 ms, `hc read` 270 -> 77), 495 tokens 2,477 -> 2,139 ms (365 ->
|
||||
146), 8,874 tokens 11,978 -> 11,459 ms (the 682-token tail chunk's projections, `hc read` 1,200 -> 898); a
|
||||
1,108-token prompt did not change (3,391 -> 3,395 ms): its GDN time fell 598 -> 201 ms and the whole saving
|
||||
reappeared as `wait copy`, the experts' PCIe transfer, which bounds that prompt. Per-run lines and the tuner's
|
||||
summary: [bench/results/2026-10-05-rdna2-rocblas-table](../bench/results/2026-10-05-rdna2-rocblas-table/README.md). Decode does not use these GEMMs and is unchanged. See [Tuning
|
||||
table](#tuning-table) for making a table for another rocBLAS build.
|
||||
- **QSA block scores on the FP32 tiled scorer (`STRATA_SELECT_SIMT=1`, opt-in, as on CUDA below sm_80):** without
|
||||
matrix cores the prompt path's QSA selection scores every (query, KV block) pair on the warp kernel, the one prompt
|
||||
term that grows with the context. The switch runs the FP32 tiled scorer instead (FP32 in another summation order:
|
||||
not bitwise the warp kernel, so off by default), tiled 32/128/16/8 on gfx103x. `qsa_select_bench`, 256 queries:
|
||||
2.69 -> 0.587 ms at 128K (the original 32/64/32/4 tiling: 0.695), 0.67 -> 0.169 ms at 32K; FP64 gate passed,
|
||||
selections identical 256/256. Every tiling gives the same bytes (each score is one fmaf chain over k in order), and
|
||||
the fastest tiling was the same with 60 and 72 of the card's 80 CUs (`HSA_CU_MASK`). On the 2x RX 6900 XT split
|
||||
(0.1.40.3, IQ3_S, `--kv int8 --kv-resident 32768`, two cold starts per arm, ABBA) a 128K-token prompt reads 1,735 ->
|
||||
1,861 and 1,727 -> 1,858 tok/s (+7.4%), 32K +0.8%; decode is not affected (the text changes with the scores' order,
|
||||
so its speed is not compared). Measurements:
|
||||
[bench/results/2026-10-07-rdna2-qsa-select-simt](../bench/results/2026-10-07-rdna2-qsa-select-simt/README.md).
|
||||
- **File-tier cache rule on gfx906 (`STRATA_FILE_CACHE_OLD_RULE`):** on an MI50 ROCm queues are suspended while the kernel reclaims around the process's HMM-tracked arena (#1752, KevinX8: stalls, prompt 46 -> 360 tok/s once the file tier stops churning the page cache). The gfx906 backend therefore keeps the old rule (the file cache is used only when the room left is at least the bytes read from the files); other HIP cards keep the current rule. `STRATA_FILE_CACHE_OLD_RULE=1` forces the old rule on any Linux build, `=0` the current one.
|
||||
- **Windows** (the report above): setup's ready-made Windows engine 0.1.39 runs the RX 6800 beside a 780M iGPU
|
||||
(HIP numbers the RX 6800 1; setup points the engine at it), and `tools/hip/build_windows.bat` with
|
||||
`STRATA_HIP_ARCHS=gfx1030` builds a working engine from the `gfx103X-all` 10.2.0a20260930 wheels.
|
||||
- **gfx1031** (RX 6700 XT, #524): setup knows it (the `gfx103X-all` wheels, unvalidated); its reporter runs it daily
|
||||
on one card. More reports: an RX 6700 XT 12 GB run as gfx1030 on ROCm 7.2.4 (#1027: IQ2_XS, decode 30-32 tok/s, prompt about 300 tok/s, 6 of 6
|
||||
needles), and an RX 6800M 12 GB on Windows with a self-built engine (#915, #1078: Q2_0, decode 9-27 tok/s, prompt 50-114 tok/s; the
|
||||
experts stream from disk with 31 GB of RAM). The ready-made Windows zip has no gfx1031 code unless it is built with it: `STRATA_HIP_ARCHS=gfx1031`
|
||||
in `tools\hip\build_windows.bat` (the default list has it from 0.1.40.2 on).
|
||||
- **gfx1150** (Radeon 890M, Ryzen AI 9 HX PRO 370, Strix Point, #1217): builds and runs from 0.1.40.2 as an unvalidated target (CMake warns; the
|
||||
device code already covers it: the WMMA guards and `gfx_arch_is_gfx11_wmma()` include it). One community machine: MINISFORUM N5 PRO, 96 GB DDR5-5600, GTT
|
||||
raised to 64 GiB (`ttm.pages_limit=16777216 ttm.page_pool_size=16777216`), TheRock ROCm 7.14.1 for gfx1150, an unprivileged LXC container, IQ3_XXS: chat and
|
||||
tool calls work, decode 15-19 tok/s, the HIP ctest passes apart from tests that need files a public checkout lacks.
|
||||
Prompts read at about 125-130 tok/s on plain hipBLAS and 1.5-1.7x faster with `tools/hip/gfx1150-hipblaslt-100401.txt` (ROCm 7.14.1's
|
||||
hipBLASLt; 3.6K tokens 124 -> 216 tok/s, 7K 130 -> 226 tok/s, decode unchanged):
|
||||
[bench/results/2026-10-07-community-gfx1150](../bench/results/2026-10-07-community-gfx1150/README.md).
|
||||
Setup does not install for it yet (an integrated Radeon other than Strix Halo is named and not supported): build by hand with `-DCMAKE_HIP_ARCHITECTURES=gfx1150`
|
||||
and point `STRATA_HIPBLASLT_TUNING` at the table yourself.
|
||||
- **gfx1152** (Radeon 860M / 840M, Ryzen AI 300 "Krackan", #1625): in CMake's unvalidated list like gfx1150, so
|
||||
`-DCMAKE_HIP_ARCHITECTURES=gfx1152` builds with a warning. It runs the portable kernels (the matrix-core guards name
|
||||
gfx1150 and gfx1151 only), no card has reported on it, and setup does not install for it (an integrated Radeon other
|
||||
than Strix Halo is named and not supported). A report from a real 860M is welcome.
|
||||
- **gfx1032** (RX 6600/6600 XT): unvalidated; built with `STRATA_HIP_ARCHS=gfx1030;gfx1032` and ran under Windows as
|
||||
the *helper* expert GPU of an RX 6800 ([SECOND_GPU.md](SECOND_GPU.md)), 3.4-3.8k expert slots in its 8 GB and
|
||||
+8-18% decode over the 6800 alone. Its 14 WGP make a helper row about 2-3x the 6800's cost, so it pays as a
|
||||
cache tier for the CPU pool, not as a compute peer. No report of it as a primary card.
|
||||
- **Not validated:** setup's own build path and the
|
||||
`gfx103X-all` wheels on gfx1030, images, answer-quality benchmarks. RDNA1 (gfx1012, RX 5500 XT) builds by hand:
|
||||
[OLDER_GPUS.md](OLDER_GPUS.md#amd-building-gfx906-and-gfx1012).
|
||||
|
||||
## gfx906 (Instinct MI50 / MI60, Radeon VII): wave64, built from source
|
||||
|
||||
gfx906 is wave64 and has no WMMA and no packed byte arithmetic, so the wave32 backend above refuses it. A separate opt-in build compiles the CUDA sources as HIP through a small compat layer
|
||||
(`include/strata/platform/hip_compat/`), with a CUDA warp mapped to a logical half of the 64-lane wavefront
|
||||
(32-wide shuffles, a ballot of its own half). The hot kernels have wave64 layouts of their own (below). Setup does
|
||||
not build it yet: build by hand, and run `serve/server.py` with a config as on any other card.
|
||||
|
||||
**Community-tested, opt-in (0.1.42).** The gfx906 build is maintained with its users: we have no gfx906 card, so what is here was measured by community members on their MI50s (the attention switches `STRATA_GFX906_ATTN_QUERY_SWIZZLE=1` and `STRATA_GFX906_ATTN_REDUCE12=1`, PRs #1661 and #1718 by 0FL01, are off by default and compiled only into this build) and the engine here is checked to compile for gfx906, nothing more. Nothing in it changes the builds for other cards. A wave32 card seen by this build is refused at start with a message (#1728). Please report how it runs on your card.
|
||||
|
||||
**ROCm.** AMD's current ROCm releases no longer ship gfx906 libraries. The build and the measurements below used
|
||||
HIP 7.14 from the community image [`mixa3607/rocm-gfx906:7.14-complete`](https://hub.docker.com/r/mixa3607/rocm-gfx906)
|
||||
(rocBLAS/hipBLAS with gfx906 kernels), on the kernel's amdgpu driver (Ubuntu 24.04, kernel 6.8). hipBLASLt is not
|
||||
used.
|
||||
|
||||
```sh
|
||||
# inside the image, with this checkout at /src and llama.cpp at the pinned commit in third_party/llama.cpp
|
||||
apt-get update && apt-get install -y cmake ninja-build git python3 build-essential
|
||||
cmake -S . -B build-906 -G Ninja -DSTRATA_HIP_GFX906=ON -DCMAKE_HIP_ARCHITECTURES=gfx906 \
|
||||
-DSTRATA_GGML_DIR=/src/third_party/llama.cpp \
|
||||
-DCMAKE_C_COMPILER=/opt/rocm/llvm/bin/clang -DCMAKE_CXX_COMPILER=/opt/rocm/llvm/bin/clang++
|
||||
ninja -C build-906 strata
|
||||
```
|
||||
|
||||
`STRATA_HIP_GFX906` turns on the CUDA targets and refuses `STRATA_ENABLE_HIP` (one HIP build at a time). Run the
|
||||
container with `--device=/dev/kfd --device=/dev/dri --group-add video --ipc=host --ulimit memlock=-1`; on some boards
|
||||
`HSA_OVERRIDE_GFX_VERSION=9.0.6` is needed for the runtime to accept the card.
|
||||
|
||||
**What differs from the CUDA build** (all under `STRATA_HIP_GFX906`; each A/B switch restores the CUDA layout):
|
||||
|
||||
| | gfx906 | switch |
|
||||
|---|---|---|
|
||||
| grouped native experts | mode 7: signs as `dp4a(g ^ m, u) - dp4a(m, u)` (no byte SIMD), grids and activations in LDS, one weight load per group; the IQ formats only (Unsloth's K-quant / Q5_1 / Q8_0 experts take the CUDA layout) | `STRATA_EXP_MODE=2` (previous AMD layout) |
|
||||
| MMVQ | one wavefront per row, 64-lane butterfly, no LDS | `STRATA_MMVQ_WAVE=0` |
|
||||
| router top-10 | one wavefront, register argmax | - |
|
||||
| verify-window routing (256-expert router) | the window's tokens in one multi-column BF16 projection + one top-k, ~3 ms of a ~55 ms window | `STRATA_ROUTE_PER_TOKEN=1` |
|
||||
| hyper-connection read | norm loads in flight, 8 lanes per row for `up` | `STRATA_GR_FAST=0` |
|
||||
| `gr_down_multi`, opt-in | split along K (8 rows x 5 slices of 2048), ~3% per window; sums in another order than the single-token read, so off by default | `STRATA_GR_SPLIT=1` |
|
||||
| IQ4 table lookup | llama.cpp's `v_perm_b32` sequence (HIP's `__byte_perm` is a scratch array) | - |
|
||||
| QSA prompt attention | the FP32 kernel (no tensor cores / WMMA) | - |
|
||||
|
||||
Every switch above was checked bitwise against the layout it replaces: the parity tests on synthetic data,
|
||||
`native_expert_bench` on real GGUF rows (one mode against another), and the greedy text of a fixed request.
|
||||
|
||||
**Measured** on 2x Instinct MI50 16 GB (85 W power limit each, PCIe 3.0 x16 both, peer access between them),
|
||||
Xeon E5-2666 v3 (10 cores, AVX2), 32 GB DDR4, SATA SSD; Coder IQ1_M (`--native` pack), 131,072-token context,
|
||||
`--kv int8 --kv-resident 32768`, `--layer-split 27`, `--prefill 4096`, MTP `--spec 4 --spec-min-p 0.5`,
|
||||
`--pcie-frac 0`, `STRATA_ARENA_MMAP=1`. Measured on the port this build was cut from (builds on the 0.1.30 and 0.1.33 bases, the same
|
||||
kernels, plus the layer-split weight trim and the mapped arena, which are separate pull requests):
|
||||
|
||||
- all 12,288 experts held in VRAM across the two cards;
|
||||
- a 17,043-token agent prompt (Claude Code's first request, tools included) read in 43.5 s (392 tok/s), decode
|
||||
on it 57.7-59.3 tok/s;
|
||||
- 25 GB of the 32 GB RAM available while serving;
|
||||
- six repeats of that request with a 6,000-token output cap and a 900-second two-client load test run six times
|
||||
(407 requests, 202,940 tokens): no stalls, no errors, no GPU faults.
|
||||
|
||||
For comparison on the same machine: llama.cpp (3cf0325, ROCm) on the same Coder IQ1_M measured 26.9 tok/s `tg128`.
|
||||
|
||||
**Not done:** setup.py detection and an automatic build, Windows, images (`--vision`), MI60 and Radeon VII (the
|
||||
same gfx906 ISA; not run), a single-card run, the tensor-split experiment (the halves of every layer on two cards;
|
||||
it works but is not part of this build).
|
||||
|
||||
## Tuning table
|
||||
|
||||
A hipBLASLt table holds solution ids that are valid only for one GPU architecture and one hipBLASLt version, so it
|
||||
is calibrated on the card with the ROCm the engine runs with. The shipped gfx1100 table's rows are the engine's
|
||||
dense GEMM shapes; to calibrate them for another card or version (a few minutes):
|
||||
|
||||
```sh
|
||||
cmake --build build-hip --target tune_hipblaslt
|
||||
CASES=$(awk 'NR>2 {printf " --case %s,%s,%s,%s,%s", $1, $5, $2, $3, $4}' tools/hip/gfx1100-hipblaslt-100200.txt)
|
||||
./build-hip/tune_hipblaslt $CASES --tuning-out table.txt
|
||||
```
|
||||
|
||||
The file's second line names the architecture and version (`STRATA_HIPBLASLT_TUNING_V1 gfx1201 100401`); save it
|
||||
as `tools/hip/<arch>-hipblaslt-<version>.txt` for setup, or point `STRATA_HIPBLASLT_TUNING` at it. Compare the
|
||||
prompt speed with and without it before keeping it.
|
||||
|
||||
Shipped tables:
|
||||
|
||||
- `gfx1100-hipblaslt-100100.txt`, `gfx1100-hipblaslt-100200.txt`: RX 7900 XTX.
|
||||
- `gfx1100-hipblaslt-100401.txt`: RX 7900 XTX, calibrated with the packaged ROCm 10.0.0
|
||||
(`rocm/dev-ubuntu-24.04:10.0.0-full`, hipBLASLt 1.4.1) on a Ryzen 7 9800X3D, over the 26 dense GEMM
|
||||
geometries of the shipped gfx1100 table. Without it, that stack reads a prompt through plain hipBLAS: on
|
||||
Swift 1.5 IQ3_XXS at 262144 ctx, fresh-prompt prefill measured 682 -> 1,038 tok/s at 1.7K tokens and
|
||||
857 -> 1,524 tok/s at 6.5K (medians of 3, decode unchanged), with `hip_prefill_hipblaslt_gemm` reporting
|
||||
`fallbacks=0`. setup uses it only when the installed hipBLASLt reports 1.4.1.
|
||||
The 43-row revision adds the two geometries the 26 dense ones do not reach, calibrated with
|
||||
`tune_hipblaslt` from the same tree and the engine's 32 MiB workspace: `f16 1280 2560 1280` (the
|
||||
small-T expert GEMM, T=8..999) and `bf16 10240 2560 10240`. A prompt on Qwen3.8-Flash-Next GSQ-RCO
|
||||
IQ2_XS at 192000 ctx otherwise falls back on the expert GEMM for nearly every launch:
|
||||
`STRATA_HIPBLASLT_VERBOSE=1` reported 642 fallbacks over 642 distinct T values (1..1873) with the
|
||||
26-row table. Adding the rows measured 711 -> 938 tok/s (+31.9 %, mean of 3 interleaved pairs:
|
||||
+36.0 / +32.4 / +27.6 %) at a 3151-token prompt, decode unchanged (58.6 -> 60.6 tok/s, inside this
|
||||
box's 2.3 % run drift), and `fallbacks=0`. The lookup takes the nearest T bucket for a matching
|
||||
geometry, so the buckets cover the whole small-T range rather than one row per T.
|
||||
- `gfx1100-hipblaslt-100500.txt`: RX 7900 XTX (gfx1100, 24 GB), calibrated with a ROCm 10.2.0a20261003 nightly
|
||||
SDK (`libamdhip64.so.7.17.26392`, hipBLASLt 1.5.0, version number 100500). Same 16 dense GEMM geometries at
|
||||
T=4096 and T=8192 as the other gfx1100 tables (32 rows), calibrated with `tune_hipblaslt` run against that
|
||||
library. On this ROCm the engine refuses the 100100/100200 tables (version mismatch) and prefills on plain
|
||||
hipBLAS; with this table a 0.1.38-lineage nightly engine prefills a 131071-token prompt at 1687 tok/s vs 926
|
||||
without it (median of 3 clean runs each, greedy; decode unchanged). Per-run data and the calibration command:
|
||||
the `2026-10-04-community-rx7900xtx-hipblaslt-100500` folder of PR #745.
|
||||
- `gfx1201-hipblaslt-100500.txt`: Radeon AI PRO R9700 (gfx1201, 32 GB), calibrated with ROCm 10.2.0a20260914
|
||||
(AMD's `gfx120X-all` nightly, hipBLASLt 1.5.0, library build `d3164197`). 16 dense GEMM geometries at T=4096 and
|
||||
T=8192, 32 rows. setup uses it only when the installed hipBLASLt reports 1.5.0 (it is found in `/opt/rocm`
|
||||
when that is a system ROCm 7 or newer). The version number is the only thing the engine can check, so another
|
||||
1.5.0 build could number its solutions differently. `hip_prefill_hipblaslt_gemm` (with `STRATA_HIPBLASLT_TUNING`
|
||||
set) is a smoke test: it refuses a table for another architecture or version and checks that one BF16 and one
|
||||
F16 row exist and agree with hipBLASEx, which covers 2 of the 32 rows. It does not prove that a solution id is
|
||||
valid: the engine falls back to hipBLASEx for an id the library rejects, and the test still passes. Run it with
|
||||
`STRATA_HIPBLASLT_VERBOSE=1` and look for `fallbacks=0` in its summary line, and recalibrate with
|
||||
`tune_hipblaslt` before using this table with a different 1.5.0 build.
|
||||
- `gfx1151-hipblaslt-100400.txt`: Radeon 8060S (Ryzen AI Max+ 395, gfx1151, 128 GB; Fedora 44, kernel 7.2.8),
|
||||
calibrated with the ROCm 7.14.0a20260608 wheels that setup installs for gfx1151 since 0.1.40.2 (#1267): their
|
||||
hipBLASLt is 1.4.0 (version number 100400), so neither `gfx1151-hipblaslt-100401.txt` nor `-100500.txt` applied and
|
||||
setup's engine read the prompt through plain hipBLAS. The same 90 rows as the 100401 table (its geometries, the
|
||||
prompt shapes at `--prefill 16384` included), calibrated with `tune_hipblaslt --workspace-mib 32` and that table's
|
||||
cases: 3.1x to 14.1x faster than plain hipBLAS per shape (median 6.2x). With `STRATA_HIPBLASLT_TUNING` set,
|
||||
`hip_prefill_hipblaslt_gemm` passes (`launches=4 fallbacks=0`), `hip_prefill_hcd_exact_parity` passes (solutions
|
||||
1176 / 1177 at 9 chunk sizes, 0 outputs differ, `fallbacks=0`), and the HIP ctest passes 61 of 62 (`ple_parity`
|
||||
needs the Q2_0 model fixture). setup uses it only when the installed hipBLASLt reports 1.4.0. The prompt speed
|
||||
of a whole model with this table is not measured yet.
|
||||
|
||||
- `gfx1150-hipblaslt-100401.txt`: Radeon 890M (gfx1150, Strix Point APU, 16 CUs), calibrated with AMD's TheRock ROCm 7.14.1 for
|
||||
gfx1150 (hipBLASLt 1.4.1 `cd957402`, version number 100401) and the engine's 32 MiB workspace. The 16 dense GEMM geometries a
|
||||
Qwen3.8-Flash-Next prompt logs on that card (the same 16 as the gfx1201 100500 table) at T = 64, 128, ..., 16384: 144 rows. Two
|
||||
`tune_hipblaslt` passes back to back; each row keeps the solution with the lowest median of all six repetitions, because one
|
||||
repetition stalled now and then (a 100 ms call read up to 1.6 s) and the tool's mean-of-three picks differed in 26 rows between
|
||||
the passes. Every row beats plain hipBLAS, 1.55-22.6x per GEMM (geometric mean 4.5x), and `STRATA_HIPBLASLT_VERBOSE=1` reported
|
||||
no fallbacks over prompts of 28-7,880 tokens. Setup does not use it (it does not install for gfx1150): point
|
||||
`STRATA_HIPBLASLT_TUNING` at it. Measurements and the per-row timings:
|
||||
[bench/results/2026-10-07-community-gfx1150](../bench/results/2026-10-07-community-gfx1150/README.md).
|
||||
- `gfx1103-hipblaslt-100401.txt`: Radeon 780M (gfx1103, RDNA3, 12 CUs, unified memory), calibrated with ROCm 10.1
|
||||
(`rocm/dev-ubuntu-24.04:10.1.0-full`, hipBLASLt 1.4.1, version number 100401) and the engine's 32 MiB workspace. The
|
||||
16 dense GEMM geometries a Qwen3.8-Flash-Next prompt logs on the card at T = 64, 128, ..., 16384: 144 cases, two
|
||||
`tune_hipblaslt` passes back to back, each row the solution with the lowest median of all six repetitions. One row
|
||||
is left out (`bf16 N=1 K=2560 T=64`: no candidate beat plain hipBLAS at 0.04 ms), so the table has **143 rows**,
|
||||
1.05-23.30x per GEMM, geometric mean 4.95x. Without it the engine prefills on plain hipBLAS: a 4K prompt on Q2_0
|
||||
read 90 tok/s, 187 with the table and 277 with the WMMA opt-ins (one 780M; 32K context, MTP). The merged table
|
||||
prefilled the 4K prompt at 187.2 tok/s. A context ladder to 131K (shipping configuration, fresh prompts) puts the
|
||||
full 128K read at 198-221 tok/s, its last ~14K at ~206, and decode at ~10 tok/s at that depth; the numbers are in
|
||||
the report folder. `hip_prefill_hipblaslt_gemm` reports `fallbacks=0`;
|
||||
`hip_prefill_hcd_exact_parity` skips, because the table picks no 1176 / 1177 for the HC down GEMM (the skip the
|
||||
gfx1150 table gets too). Setup installs for gfx1103 only with `STRATA_EXPERIMENTAL_GFX1103=1` and then uses the
|
||||
table when the installed hipBLASLt reports 1.4.1. Measurements:
|
||||
[bench/results/2026-10-12-community-gfx1103](../bench/results/2026-10-12-community-gfx1103/README.md).
|
||||
|
||||
Calibrated on my PC and kept in this checkout, not shipped: `gfx1201-hipblaslt-100401.txt`, a Radeon AI PRO
|
||||
R9700 (gfx1201, 32 GB, 1002:7551) on a Ryzen 9 9950X3D with 62 GiB RAM, CachyOS (kernel 7.3.0-rc6-1-cachyos-rc,
|
||||
`linux-firmware-amdgpu 20260916`, the kernel's amdgpu driver), system ROCm `rocm-gfx120x-bin 10.1.0` (hipBLASLt
|
||||
1.4.1, HIP 7.16.26385, clang 24.0.0), Python 3.14.7 in setup's own venv, engine 0.1.40 compiled there for gfx1201,
|
||||
the model files on a 4 TB NVMe (btrfs), IQ3_S at 131072 ctx with `--kv int8`, the GPU idle. `tune_hipblaslt` over
|
||||
the 32 geometries of `gfx1201-hipblaslt-100500.txt`: 1.15x geometric mean per GEMM over hipBLAS - 1.55-1.68x at
|
||||
N=512/640 K=2560, 0.99-1.13x at N=10240/12288 K=2560. End to end with `tools/hip/bench_prefill.py` over two
|
||||
server starts, fresh prompts of 4,210 and 8,830 tokens, three matched trials each - the first fresh prompt after
|
||||
each start is left out, it is cold (949 and 1,423 tok/s there): 1,606 -> 1,613, 1,701 -> 1,726 and 1,605 -> 1,610
|
||||
tok/s (+0.5, +1.5, +0.4%), medians 1,606 -> 1,613 and a 1.008x geometric mean over those three, decode
|
||||
87.1 -> 85.1 tok/s - within noise, as the R9700 paragraph above found. `hip_prefill_hipblaslt_gemm` passes with it: `tuning enabled (30 rows, gfx1201,
|
||||
version 100401)`, `launches=4 fallbacks=0`.
|
||||
|
||||
Two rows were dropped from that table: bf16 N=10240 K=320 ldy=10240 at T=4096 and at T=8192. At T=8192 hipBLAS was
|
||||
faster in five separate `tune_hipblaslt` runs - 0.609-0.619 ms against 0.648-0.677 ms for the best of the 16
|
||||
hipBLASLt candidates (0.90-0.95x), with four different winning solution ids, all slower than hipBLAS. Dropping only
|
||||
the T=8192 row does not send that call back to hipBLAS: `closest()` matches dtype/N/K/ldy and takes the nearest T
|
||||
bucket, so T=8192 would run the T=4096 row; both rows go or neither.
|
||||
|
||||
Two calibration notes from my machine. The first case of a fresh `tune_hipblaslt` process times its hipBLAS
|
||||
baseline while the clocks are still ramping: that T=4096 shape read 0.31-0.63 ms across five runs while the case
|
||||
timed right after it held 0.606-0.619 ms every time, so time a heavy case first and read the later ones. And the
|
||||
first fresh prompt after the model loads is not a measurement: it gave 949 and 1,423 tok/s in the two arms of that
|
||||
A/B, while the three trials after it differed by 0.4-1.5%.
|
||||
|
||||
### rocBLAS table (gfx103x)
|
||||
|
||||
On RDNA2 the prompt GEMMs run through rocBLAS in FP16 (#835), and hipBLASLt has no gfx1030 kernels; the rocBLAS table
|
||||
does for rocBLAS what the one above does for hipBLASLt (the [RDNA2 section](#rdna2-gfx1030) has the measurements). A
|
||||
table is valid for one architecture and one rocBLAS build - the full version string, tweak hash included - so it is
|
||||
calibrated on the card with the rocBLAS the engine loads (`lib_dirs` in the run configuration; `/opt/rocm/lib` is
|
||||
rocBLAS 5.6.0.8d1ae90e on ROCm 10.0.0, while Ubuntu's own `librocblas5` package is a 5.1 build):
|
||||
|
||||
```sh
|
||||
cmake --build build-hip --target tune_rocblas
|
||||
LD_LIBRARY_PATH=/opt/rocm/lib ./build-hip/tune_rocblas --tuning-out table.txt # 14 shapes x 8 token buckets, ~5 min
|
||||
```
|
||||
|
||||
The tool times rocBLAS's default kernel and every solution the library lists for each shape at T = 256 ... 8192 (the
|
||||
engine's dense GEMM shapes; `--case T,N,K,ldy` adds one, `--tokens` changes the buckets), checks the fastest ones
|
||||
against the default kernel's output (within FP16 rounding, no write outside the N x T result) and that they also run at
|
||||
smaller, odd token counts, and writes one row per shape and bucket: the winning solution index where it beats the
|
||||
default by `--min-gain` (1.05), `default` otherwise - a `default` row is what keeps a neighbouring bucket's solution from
|
||||
reaching token counts where rocBLAS's own choice measured best. The file's header names the architecture and version
|
||||
(`STRATA_ROCBLAS_TUNING_V1 gfx1030 5.6.0.8d1ae90e`); save it as `tools/hip/<arch>-rocblas-<version>.txt` (the version
|
||||
with trailing dots dropped) for setup, or point `STRATA_ROCBLAS_TUNING` at the file. `STRATA_ROCBLAS_VERBOSE=1` prints
|
||||
the solution picked for each shape and a `tuned_launches=... fallbacks=...` summary at exit; a solution rocBLAS refuses
|
||||
at run time (status 11 once while it sets up its workspace is normal) falls back to the default kernel for that call, and
|
||||
after three refusals for good. `hip_prefill_rocblas_gemm` (with `STRATA_ROCBLAS_TUNING` set; skips otherwise) is the
|
||||
smoke test: it refuses a table for another architecture or build and checks Gemm's FP16 route against hipBLASEx on the
|
||||
table's first two shapes.
|
||||
|
||||
## Original backend validation (PR #94)
|
||||
|
||||
The following is historical validation of the original backend, not a fresh
|
||||
test count for this replacement. Current build/test evidence and performance
|
||||
limits are recorded in [AMD_HIP_PERFORMANCE.md](AMD_HIP_PERFORMANCE.md).
|
||||
|
||||
Tested against upstream `c1e903310f211e6630780c3bd2038778c071c68d` (0.1.20),
|
||||
with pinned llama.cpp `3cf03257f219afbe7334045ff7c6a06ac68c627d`.
|
||||
The host has an RX 7900 XTX (24 GiB), Ryzen 9 7950X3D, 64 GiB system RAM,
|
||||
and Fedora-family Linux with ROCm 7.1.52802 / Clang 20. The original model used
|
||||
for the smoke check was on mechanical RAID0; cold page faults were slow. Keep
|
||||
latency-sensitive data on SSD and measure warm residency separately.
|
||||
|
||||
- Complete HIP Release build, including the executable and parity targets.
|
||||
- All 25 tests selected by the command below passed on 2026-09-29.
|
||||
- Intrinsic parity includes signed packed-byte dot products and overflow.
|
||||
- CPU/GPU mapped-memory handoff covers delayed publication, changing payloads,
|
||||
and repeated graph replay in both directions.
|
||||
- GR coverage includes the maximum eight-token fused batch and graph replay
|
||||
after inputs change. Native QSA checks the scalar HIP fallback.
|
||||
- Q8_K quantization is byte-exact against the existing reference. HIP's
|
||||
`__fmul_rn` can become ordinary multiplication; disabling contraction in
|
||||
`quantize_act.cu` preserves the separately rounded product before the magic
|
||||
rounding bias is added. CUDA's compile flags remain unchanged.
|
||||
- The mmap regression covers canonical and differing native layer sizes,
|
||||
truncated/oversized files, lookup bounds, and reopening after errors.
|
||||
- CUDA 13 / GCC 15 / sm_89 executable build passed; GR, sampler, quantization,
|
||||
and mmap tests passed on the same tree. This is a regression check, not a
|
||||
claim of complete CUDA inference validation.
|
||||
- CPU-only `strata-plan` build passed without either GPU backend.
|
||||
- Real GSQ-RCO IQ3_XXS server smoke with mmap, the shipped expert profile,
|
||||
automatic GPU cache, and MTP passed arithmetic, executable Python addition,
|
||||
system-marker recall, and 1,170-token batched-prefill recall. All four requests
|
||||
ended normally with correct answers; one engine process served them all.
|
||||
The cache held 11,142 experts (18.08 GiB), with 874 MiB of VRAM free after
|
||||
startup. These short checks do not establish a throughput or quality benchmark.
|
||||
|
||||
Build all targets before running the registered focused checks:
|
||||
|
||||
```sh
|
||||
cmake --build build-hip -j2
|
||||
ctest --test-dir build-hip --output-on-failure --timeout 60 \
|
||||
-E '^(ple_parity|platform_memory_test)$'
|
||||
```
|
||||
|
||||
`ple_parity` requires an external model fixture. `platform_memory_test` requests
|
||||
256 MiB of locked memory; the test shell's 8 MiB memlock limit prevented that
|
||||
test from passing. These are explicit exclusions, not skipped tests counted as
|
||||
passes. Additional unpublished upstream fixture suites are not covered.
|
||||
|
||||
The published performance table explicitly identifies the measured development
|
||||
snapshot; it must not be read as a benchmark of every subsequent rebase. Vision, long-context stress, broad answer-quality
|
||||
equivalence, other AMD cards, and mixed-vendor inference are not validated here.
|
||||
@@ -0,0 +1,145 @@
|
||||
# RX 7900 XTX support and performance evidence
|
||||
|
||||
This opt-in Linux `gfx1100` backend supersedes the initial support in
|
||||
[PR #94](https://github.com/Niko1221/Strata/pull/94). It retains HIP runtime and
|
||||
wave32 integer-dot compatibility, native mmap layout validation, and MTP, then
|
||||
adds HIP MMQ, optional calibrated dense hipBLASLt GEMM, native prefill batching,
|
||||
and the host-memory / SSD paths used by the measured configuration. HIP blocking
|
||||
expert uploads use one reusable pinned staging buffer, including prompt-cache
|
||||
refills, to avoid repeated pageable-source registrations.
|
||||
|
||||
## Reproduce the configuration
|
||||
|
||||
Build instructions are in [AMD_HIP.md](AMD_HIP.md). Use the repository-pinned
|
||||
llama.cpp dependency; do not silently substitute another revision. Build with
|
||||
`STRATA_PREFILL_MMQ=ON` and use these runtime variables for the measured arm:
|
||||
|
||||
```sh
|
||||
export STRATA_PREFILL_MMQ=1
|
||||
export STRATA_HIPBLASLT_TUNING="$PWD/tools/hip/gfx1100-hipblaslt-100100.txt"
|
||||
export STRATA_PREFILL_RING=96
|
||||
export STRATA_IO_THREADS=32
|
||||
```
|
||||
|
||||
The supplied table is calibrated for gfx1100 and hipBLASLt version 100100.
|
||||
It is not a universal ROCm tuning table. The runtime guards architecture,
|
||||
library version and actual shape/stride/workspace requirements, falling back
|
||||
when a table entry is unavailable or incompatible. HIP MMQ is opt-in at runtime. Default CUDA selection is preserved.
|
||||
|
||||
Measured engine configuration: Orca Flash Next IQ3_XXS, native pack plus matching
|
||||
GGUF/tokenizer/template, `--mmap-experts --resident-cpu-experts`, fixed ranked
|
||||
`--expert-profile`, `--expert-cache auto`, `--prefill 8192`, `--spec 4`,
|
||||
`--spec-min-p 0.5`, matching MTP runtime, `--max-context 262144`, `--kv int8`,
|
||||
`--kv-resident 32768`, `--pool-workers 15`, `--adapt-every 0`, `--pcie-frac 0`,
|
||||
and `--vram-reserve-mib 1024`. Keep PLE on SSD.
|
||||
|
||||
`--resident-cpu-experts` copies the complement of the static GPU cache to ordinary
|
||||
RAM. It requires mmap and a fixed expert profile. The slots the prompt path may
|
||||
borrow keep their experts in RAM too as far as the budget below allows (the rest
|
||||
use the mapped fallback while borrowed and for their refill), and adaptive swaps
|
||||
(`--adapt-every`) exchange experts between VRAM and the RAM copy without reading
|
||||
the file. The copy is pageable; `--resident-experts` (CUDA, chosen by setup)
|
||||
page-locks it and uses 4 GiB of headroom. Allocation needs sufficient available RAM;
|
||||
on Linux this option requires readable standard cgroup-v2 mounts. For each
|
||||
finite cgroup ancestor, the guard credits only `inactive_file` after subtracting
|
||||
`file_dirty` and `file_writeback`, capped by current usage; it remains bounded by
|
||||
the ancestor limit and host `MemAvailable`, with 8 GiB headroom. This accounts
|
||||
for reclaimable clean file cache but cannot reserve memory against concurrent
|
||||
system or process allocations.
|
||||
The POSIX PLE path issues direct reads through a configurable worker pool.
|
||||
|
||||
Use a dedicated idle server, restart it between arms, and capture its engine log:
|
||||
|
||||
```sh
|
||||
python3 tools/hip/bench_prefill.py \
|
||||
--model MODEL_NAME --url http://127.0.0.1:8080 \
|
||||
--engine-log /path/to/engine.log --label candidate --output candidate.json
|
||||
```
|
||||
|
||||
The script uses the same synthetic source prompts and request order as the
|
||||
reported measurements: a small warmup, then 140/280/140/280 functions, with one
|
||||
follow-up after each fresh prompt. It enforces zero reused tokens for the fresh
|
||||
prompts and records prefill, decode, wall time and stop reason. It requires the
|
||||
unbuffered log to contain exactly one completed timing record per request. The
|
||||
128-token output cap is intentional for throughput measurement, not task success.
|
||||
Never use cancelled-request timing lines as throughput evidence.
|
||||
|
||||
## Final revision benchmark
|
||||
|
||||
Measured on 2026-09-29, source revision `9568e78da663e6b224ab96d57baf450717b36e73`.
|
||||
HIP executable SHA-256: `705f5925a788bc227bad72abfb5466032e0879d752fea9afc3eb32051b35182b`.
|
||||
The control and candidate below were both measured anew in this session; no
|
||||
historical benchmark values are mixed into the table. The control binary SHA-256
|
||||
is `4522d4937ca4a41ca294d31b60df8c2bc4df5b7a6caf65eaad10c036e08491f7`;
|
||||
its source was an existing local runtime snapshot rather than a clean upstream commit.
|
||||
Both arms use an RX 7900 XTX 24 GiB / gfx1100, Ryzen 9 7950X3D,
|
||||
64 GiB installed RAM, Fedora-family Linux, ROCm 7.1 and a 272 W GPU cap.
|
||||
Other model services are stopped for measurement and restored afterward.
|
||||
Sampling: temperature 0, top-k 1, top-p 1, min-p 0, seed 42, reasoning disabled.
|
||||
|
||||
| Fresh request, execution order | Control prefill t/s | Candidate prefill t/s | Candidate output t/s | Candidate request wall time |
|
||||
| --- | ---: | ---: | ---: | ---: |
|
||||
| 4,210 tokens, first use | 240.0 | 447.5 | 55.5 | 11.729 s |
|
||||
| 8,830 tokens, first use at this size | 484.8 | 873.7 | 55.7 | 12.420 s |
|
||||
| 4,210 tokens, warmed | 457.2 | 901.1 | 56.7 | 6.937 s |
|
||||
| 8,830 tokens, warmed | 478.9 | 966.5 | 59.2 | 11.314 s |
|
||||
|
||||
Each request generated exactly 128 tokens and finished at the intentional length
|
||||
cap. All four fresh prompts had zero reused KV tokens. Fresh-prompt prefill was
|
||||
1.80–2.02x the freshly measured existing AMD runtime; fresh-request wall time was
|
||||
40–46% lower. This is a comparison with our existing HIP runtime, not unmodified
|
||||
upstream, which does not provide this backend. The candidate also completed four
|
||||
cached follow-ups in 2.95–3.26 seconds. Those follow-ups are not apples-to-apples
|
||||
prefill comparisons: cache reuse differs with generated text and checkpoint
|
||||
selection. Full sanitized measurements are in
|
||||
[the fresh-run JSON](benchmarks/2026-09-29-gfx1100.json).
|
||||
|
||||
Before this revision, an intermediate package missing the HIP upload staging
|
||||
buffer stalled on the 8,830-token request and was rejected. Restoring staging
|
||||
allowed the complete sequence above to finish. That failed attempt is not
|
||||
included in the throughput table. No watchdog limit was raised to obtain these
|
||||
results.
|
||||
|
||||
Zero KV reuse is not equivalent to a cold filesystem cache. First-use speed
|
||||
and warmed speed are reported separately. Individual observations do not
|
||||
establish confidence intervals or a general rate at every context length.
|
||||
|
||||
## Correctness and quality limits
|
||||
|
||||
Both HIP and CUDA executables built from the measured source revision. CUDA was
|
||||
compile-checked, not performance-tested by this run. The selected HIP CTest suite
|
||||
passed **29/29** with the tuning table enabled, including expert-upload readback,
|
||||
asynchronous handoff, QSA, MMQ, Lt GEMM, KV streaming and PLE reading. The excluded
|
||||
`ple_parity` requires an external fixture; `platform_memory_test` requires a
|
||||
larger locked-memory limit than the test account provides. Separately, three
|
||||
real IQ3_XXS PLE matrix graph replays passed, and the POSIX direct-file test passed
|
||||
queued reads, short EOF, wake, close/drain and reopen checks.
|
||||
|
||||
Development checks passed eight MMQ numerical comparisons, four actual Lt GEMM
|
||||
comparisons, and native QSA/indexer/embedding parity including tail states,
|
||||
chunk continuation and image overrides. Real quantized MMQ relative L2 error
|
||||
was approximately 0.0026 against raw-FP32/dequantized-weight reference, reflecting
|
||||
Q8 activation arithmetic; this is not bitwise numerical equivalence.
|
||||
|
||||
End-to-end coding quality is not established by these numerical checks or capped
|
||||
throughput requests. Validate completed tasks with independent runtime tests; this
|
||||
contribution makes no broad answer-quality or agentic-reliability claim.
|
||||
|
||||
The changes do not claim better model reasoning, verified full-context behavior,
|
||||
end-to-end vision validation, Windows HIP, other AMD architectures, or mixed
|
||||
AMD/NVIDIA execution. Existing CUDA multi-GPU code remains present but is not
|
||||
validation of HIP multi-GPU support.
|
||||
|
||||
## Attribution and rejected experiments
|
||||
|
||||
The measurements above were taken before this backend was rebased onto engine 0.1.24. The PR's own batched
|
||||
embedding gather and QSA indexer append (adapted from
|
||||
[PR #108](https://github.com/Niko1221/Strata/pull/108), commit
|
||||
`acd487233c0bbe2217a6881c5bb43f8a283b0de5`) were dropped in the rebase: 0.1.24 already does both on every
|
||||
backend, bit-exact (C-2, C-4). #108's optional GDN parallel/split path is not included. Existing upstream MMQ orchestration is retained and enabled for
|
||||
HIP with AMD architecture identification and the correct backend compilation.
|
||||
|
||||
Static 16K chunks, expanded FP16 expert tuning, and a 192-slot ring did not offer
|
||||
a consistent end-to-end win in the evaluated workload. The table includes only
|
||||
the selected 30 dense-shape rows. Microkernel speedups alone were not sufficient
|
||||
to select a configuration. No increase in GPU power cap was used.
|
||||
+2009
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,114 @@
|
||||
# Batched DMA submission (experimental)
|
||||
|
||||
With `--pcie-mode dma`, `STRATA_DMA_BATCH=1` submits a verifier group's independent
|
||||
expert uploads through `cudaMemcpyBatchAsync` on CUDA 13.0 or later. The default
|
||||
is `0`, retaining the existing per-expert copies. The normal kernel-copy mode
|
||||
is unchanged. This is an experiment to reduce host submission overhead, not a
|
||||
demonstrated increase in model tokens per second.
|
||||
|
||||
`STRATA_DMA_BATCH=2` also sets CUDA 13.4's
|
||||
`cudaMemcpyFlagPreferOverlapWithCompute`. It is a scheduling hint, not a
|
||||
guarantee of overlap. On CUDA 13.0–13.3 this mode behaves like `1`. Older CUDA
|
||||
builds and HIP retain individual copies. A single upload or a group larger than
|
||||
128 also uses individual copies.
|
||||
|
||||
The sources must be immutable pinned host blobs, and destinations must be
|
||||
disjoint. `expert_source.cpp` already restricts the DMA group to pinned experts.
|
||||
The helper resolves device-visible aliases for registered host allocations;
|
||||
Windows registered host pointers need not equal their GPU aliases. No extra
|
||||
VRAM or weight conversion is introduced. All copies remain on the existing
|
||||
stream, before the callback that signals flag B. A submission error fails the
|
||||
engine rather than signalling readiness for stale weights.
|
||||
|
||||
## Tests
|
||||
|
||||
With the normal CUDA build and `STRATA_BUILD_TESTS=ON`:
|
||||
|
||||
```sh
|
||||
cmake --build build --target dma_batch_parity
|
||||
ctest --test-dir build -R dma_batch --output-on-failure
|
||||
```
|
||||
|
||||
The test checks bytes and cross-stream event ordering for 0, 1, 4, 17, 64, 128,
|
||||
and 129 uploads, at 37 bytes, 4 KiB and 2 MiB per upload, in all three modes.
|
||||
Windows also runs the same cases with `VirtualAlloc` plus `cudaHostRegister`.
|
||||
It prints interleaved diagnostic timings separately for submission and total
|
||||
transfer time. These times overlap; they must not be added. On Windows it also
|
||||
reports submitting-thread cycles using `QueryThreadCycleTime`. Cycle counts
|
||||
are neither whole-process CPU utilization nor an energy measurement.
|
||||
|
||||
The 63-case matrix passed with both host allocation methods on CUDA 13.4 and
|
||||
13.0, and with the individual-copy fallback on CUDA 12.6, all using the same
|
||||
RTX 4070 Laptop and driver 616.56. This checks the older-toolkit fallback;
|
||||
it is not a HIP runtime test.
|
||||
|
||||
## Initial measurement
|
||||
|
||||
RTX 4070 Laptop 8 GB, Ryzen 9 7940HS, 64 GB DDR5-5600, Windows, CUDA 13.4:
|
||||
16 independent registered-host uploads of 2 MiB each, five measured repetitions
|
||||
after warmup, alternating mode order:
|
||||
|
||||
| Path | Median host submission | Median total transfer |
|
||||
| --- | ---: | ---: |
|
||||
| Individual copies | 0.0936 ms | 2.5589 ms |
|
||||
| Batch | 0.0162 ms | 2.5248 ms |
|
||||
| Batch with overlap hint | 0.0155 ms | 2.5206 ms |
|
||||
|
||||
Batch submission latency fell 82.7%; total transfer latency fell only 1.3%.
|
||||
Submission latency is measured wall time around the API calls, not whole-process
|
||||
CPU utilization or energy consumption. The initial full-model screen on Swift
|
||||
1.5 IQ3_XXS at 64K allocated context did not establish a generation-speed gain:
|
||||
one coding request measured 30.3 tokens/s with individual DMA and 30.0 with
|
||||
batching. Its generated lengths differed, so total task times cannot isolate
|
||||
the transfer change. This evidence does not justify changing the default.
|
||||
|
||||
A separate CUDA 13.4 repetition with submitting-thread cycle measurements gave
|
||||
449,824 cycles for individual copies and 67,939 for the batch, about 84.9% fewer.
|
||||
Submission wall time was 0.1127 vs 0.0170 ms, while total transfer time was
|
||||
2.5584 vs 2.5309 ms (about 1.1% lower). These are separate runs from the initial
|
||||
table, not measurements to combine into a larger speedup.
|
||||
|
||||
## Model comparison on the isolated patch
|
||||
|
||||
An A-B-B-A comparison used only this patch on v0.1.39, with `--pcie-mode dma`.
|
||||
Each fresh engine ran the same nine requests, including tool use, prompt reuse
|
||||
and an independently checked interval-merging implementation. The coding request
|
||||
used high reasoning, seed 4242, temperature 1, top-p 0.95, top-k 20 and a
|
||||
3,072-token output limit. Context allocation was 65,536, INT8 KV with 20,480
|
||||
resident cells, 1,040 cached experts, 7 workers plus the caller, PCIe fraction
|
||||
0.35, and MTP 5 with English drafting and min-p 0.5.
|
||||
|
||||
| Run | Batch mode | Code decode tok/s | Output tokens including reasoning | Request wall time |
|
||||
| --- | ---: | ---: | ---: | ---: |
|
||||
| A1 | 0 | 29.7 | 928 | 32.98 s |
|
||||
| B1 | 1 | 31.4 | 1,478 | 48.86 s |
|
||||
| B2 | 1 | 30.3 | 1,314 | 45.12 s |
|
||||
| A2 | 0 | 30.2 | 1,078 | 37.45 s |
|
||||
|
||||
All 36 requests passed. All four implementations passed 155 independent cases
|
||||
and generator, invalid-input and non-mutation checks. Outputs differed even
|
||||
between the two controls, and draft acceptance also differed. These runs do
|
||||
not isolate a model speedup or show better time to a verified answer. The
|
||||
byte-parity tests establish transfer correctness, not deterministic generated
|
||||
text or general agent reliability.
|
||||
|
||||
A fifth run with batching enabled passed the same nine requests plus a
|
||||
57,750-token prompt, auxiliary-call restoration, and three 1,024-square image
|
||||
color checks including image-state restoration. An OpenAI-compatible HTTP
|
||||
smoke request also passed. The long prompt read took 78.414 seconds; restoring
|
||||
57,745 tokens after the side call reduced prompt processing to 0.301 seconds.
|
||||
This validates the existing state cache with the patch, not a new cache speedup.
|
||||
The five clean-patch runs passed 53 recorded requests plus the HTTP check.
|
||||
Observed free physical VRAM stayed at least 347 MiB via NVML, and available
|
||||
system RAM stayed above 4.30 GiB. The engine's separate CUDA free-memory warning
|
||||
reported zero, so the NVML figure must not be read as a verified WDDM budget.
|
||||
Linux and HIP runtime validation remains untested.
|
||||
|
||||
## Design reference
|
||||
|
||||
The batching idea follows NVIDIA NCCL's
|
||||
[copy-engine implementation](https://github.com/NVIDIA/nccl/blob/12df1a11afad322be5a204a2db890161cbf8131d/src/ce_coll.cc)
|
||||
and the [CUDA `cudaMemcpyBatchAsync` contract](https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__MEMORY.html).
|
||||
The helper and tests here are new;
|
||||
no NCCL source was transplanted. NCCL's multi-GPU performance claims are not
|
||||
used as predictions for this single-GPU path.
|
||||
@@ -0,0 +1,617 @@
|
||||
# Several requests at once (batch slots)
|
||||
|
||||
By default PolyStrata serves **one request at a time**: the others wait in the server's queue. With `"parallel": N`
|
||||
(the engine's `--batch N`, also spelled `--slots N`) the engine keeps up to N conversations open and decodes them
|
||||
**together**: every verify window then carries one token of each conversation, so the dense weights, the shared
|
||||
expert, the head and every routed expert two conversations share are read once per window for all of them.
|
||||
Combined with a layer split across several GPUs and `--batch-groups`, the cards also work on different
|
||||
conversations at the same time instead of waiting for each other.
|
||||
|
||||
It is opt-in and changes nothing when the options are absent (#465; the engine part is PR #559).
|
||||
|
||||
Most of this page is about the Strata project's engine, which runs Qwen3.8-Flash-Next. The other eight models run on
|
||||
strata-poly, which does the same since 0.1.44.1-poly.6 with fewer options: see
|
||||
[The strata-poly models](#the-strata-poly-models).
|
||||
|
||||
Qwen3.6-35B-A3B also runs on the Strata project's own engine (setup's `--family qwen36-strata`), which has the
|
||||
same option there (`"parallel": N`, `--batch N`, `--batch-mtp`, up to 8 slots, the same engine protocol and the
|
||||
same server): its numbers, what a slot costs and where setup recommends it are in [QWEN36.md](QWEN36.md).
|
||||
|
||||
## The strata-poly models
|
||||
|
||||
`"parallel": N` in the model's config (`strata-<model>.json`), or `--parallel N` when you run setup, works for
|
||||
GLM 5.3 Flash, DeepSeek V4 Flash, LFM2.5, Qwen3.6, Ornith 1.5, Gemma 4, Tiel Coder and MiniCPM-V too, up to 8. The
|
||||
server drives it the way it drives the Strata project's engine (below), with the same lines:
|
||||
|
||||
- A request alone writes on its own and guesses ahead as always, so one user sees no change.
|
||||
- When a second one comes, the first goes on in a batch slot from where it was, nothing read again, and the two
|
||||
write together, a token each at a time, without guesses. Each slot has its own position, recurrent state and
|
||||
attention rows; the dense weights and every routed expert two requests both use are read once for both.
|
||||
- A request's prompt is read the usual way, with the conversation cache, and copied into its slot on the card.
|
||||
While a prompt is read the slots go on writing, for half the time each piece of the prompt took, and a long read
|
||||
gives way to a much shorter request at its next piece (`BYIELD`).
|
||||
- Left alone again, a request goes back to writing on its own with guesses, also without reading anything again.
|
||||
|
||||
Where it pays depends on the card. On the RTX 4070 laptop (8 GB) most experts of Qwen3.6 run on the CPU, and
|
||||
different requests route to different experts, so the CPU does each request's own: three chats of 150 tokens with
|
||||
UD-Q3_K_M came at 105 tokens/s together, and at 79 one after the other. A card that holds every expert of the model
|
||||
gains more. On an RTX 5090 with Qwen3.6 UD-Q4_K_M, chats of 300 tokens through the server:
|
||||
|
||||
| Chats at once | Tokens/s, all together |
|
||||
| ---: | ---: |
|
||||
| 1 (with guesses) | 312-333 |
|
||||
| 2 | 315-324 |
|
||||
| 3 | 381-389 |
|
||||
| 4 | 428-430 |
|
||||
|
||||
Each slot's attention rows take VRAM from the expert cache as its conversation grows, as the first conversation's
|
||||
do. A model split across cards (`"layer_split"`) runs its slots card after card.
|
||||
|
||||
Check it on your PC with the engine alone: `strata-poly --model M.gguf --batch 3 --check-batch 3 --tokens ID,ID,...`
|
||||
answers three prompts (the given one, and it without its first one and two tokens) one after the other and then
|
||||
together, and says for each how many tokens came out the same. To compare token by token, keep the expert cache
|
||||
fixed and leave guesses and the tail skip out: `--expert-swaps 0 --cpu-share 0 --window 1 --tail-skip 0`. On the
|
||||
laptop every token matched for Qwen3.6, Gemma 4 and LFM2.5 with 2 to 4 sequences and prompts of 19 to 3,000 tokens,
|
||||
and on the RTX 5090 for Qwen3.6, MiniCPM-V, LFM2.5, DeepSeek V4 Flash and GLM 5.3 Flash with 3 sequences after
|
||||
prompts of 64 and 3,000 tokens. Through the server on the laptop, with the same four options in the run config,
|
||||
three chats at once gave the text each gave alone, to the character.
|
||||
|
||||
Without those options the text of a chat answered together can part from the one it gets alone after a few dozen
|
||||
words, and so can two runs of the same chat alone. On the laptop that happened with the run config as setup writes
|
||||
it, and with the expert cache fixed but guesses on. The tail skip (Qwen3.6's default 6) leaves out an expert outside
|
||||
VRAM only where no token of the call ranks it high, so with it a request's text also depends on the others written
|
||||
with it.
|
||||
|
||||
Not there yet: guesses inside a slot (`--batch-mtp` in the Strata project's engine), `--batch-groups`, and the other
|
||||
options of the table below, which are that engine's.
|
||||
|
||||
## Turning it on
|
||||
|
||||
One GPU: add `"parallel": 2` to the model's config (`strata-<model>.json`) and restart, or run setup with
|
||||
`--parallel 2`. Setup recommends it only where it does not cost speed (below); any number you ask for is kept as
|
||||
asked, with a note when it is more than setup would recommend.
|
||||
|
||||
```
|
||||
"parallel": 2
|
||||
```
|
||||
|
||||
With MTP (`--mtp` and `--spec`), `--batch-mtp` (in the config's `args`, or `STRATA_BATCH_MTP=1` in the server's
|
||||
environment) lets each batch slot verify one MTP proposal per window. It is opt-in; without it the batch behaviour
|
||||
described below is exactly the one without MTP. It needs VRAM per slot for the draft state and buffers, so check the
|
||||
engine's free-memory log before using it on a smaller card. If it cannot run (one slot, no `--mtp`, a layer split with
|
||||
`--batch-groups` above 1 or with helper-GPU expert caches or `--remote-expert-opt`, a layer split with two stages on one
|
||||
GPU) the engine says so and batches as usual. RTX PRO 5000 owners measured +31% to +39% total throughput with 2 to 4
|
||||
clients on one GPU (a RX R9700 run too).
|
||||
|
||||
**With a layer split** (e.g. `"layer_split": "24"` on two GPUs, `"parallel": 2`, `--spec 4 --mtp ...`) it works the
|
||||
same way, with the slot drafters on the **last stage's GPU** (where the solo drafter and the head are): each slot gets a
|
||||
drafter that shares the solo drafter's weights and owns only its K/V ring and buffers (the engine logs `--batch-mtp: N
|
||||
slot drafters on CUDAk (X MiB ... each)` at start; the K/V ring of each also keeps a pinned-RAM copy, as the solo
|
||||
drafter's does). A window carries two rows per active slot (its token and its proposal) through every stage, so at most
|
||||
four slots are in one window; more slots (`--batch` up to what fits) rotate through. The windows run through the stages
|
||||
one after the other (`--batch-groups 1`): on 0.1.41 a layer split with `--batch` 2 or more pipelines the slots in groups
|
||||
by default, and the pipelined path does not run the slots' MTP drafts, so with `--batch-mtp` and no `--batch-groups` the
|
||||
engine (0.1.43.1) pipelines and leaves `--batch-mtp` off, and says so (0.1.42/0.1.43 ran one serial group with it: 4 streams on 2x A4000 aggregated 63.9 tok/s against 91.8 pipelined, 85.8 pipelined without `--batch-mtp`; #2038). `--batch-groups 1` or `STRATA_BATCH_MTP_SERIAL=1` keeps `--batch-mtp` with serial windows, which is the better choice for about two streams as measured below; `--batch-groups G` (G above 1) or `--batch-groups auto` given on the command line
|
||||
keeps the pipeline and turns `--batch-mtp` off. Only a layer split of two stages on two GPUs has been run.
|
||||
|
||||
Measured on a layer split of 2x RTX 3080 20 GB (220 W cap) with a Xeon E5-2696 v4, UD-Q4_K_XL, `"layer_split": "23"`,
|
||||
`"parallel": 2`, `--spec 4`: two concurrent greedy decodes of 300 tokens, the two streams' tok/s added, median of
|
||||
the measurements (10 rounds of two streams after each restart of the engine, 20 measurements per restart). The
|
||||
engine was 0.1.41 with the rest of our production stack on it (the shared KV pool, and the adaptive expert tier
|
||||
running in batch windows in the first two arms; the pipelined path of the third never adapts in windows), so this is
|
||||
`--batch-mtp` on top of that, not this change alone on main.
|
||||
|
||||
| arm | aggregate tok/s | restarts, measurements | per window |
|
||||
| --- | --- | --- | --- |
|
||||
| `--batch-mtp`, one group | **89.2** | 3, 60 | 3.3 rows, 34.6 ms, 66-67% of the proposals accepted |
|
||||
| no `--batch-mtp`, one serial group | 77.3 | 2, 40 | 2.0 rows, 23.7 ms |
|
||||
| no `--batch-mtp`, `--batch-groups` unset (the 0.1.41 default: two pipelined groups of one slot) | 77.7 | 1, 20 | one row per group step |
|
||||
|
||||
That is +15.4% for `--batch-mtp` against serial windows without it (95% bootstrap interval of the ratio of medians
|
||||
+12.5% to +17.9%) and +14.8% against the pipelined default; the two arms without it tie. One stream alone decodes the
|
||||
same with and without it (81.7 and 82.0 tok/s), and the two slot drafters cost 35 to 110 expert-cache slots on the
|
||||
last GPU (50 MiB of private state each).
|
||||
|
||||
The pipelined default is better in one place: a new prompt of about 48k tokens arriving while one stream decodes was
|
||||
read at 2508 tok/s with pipelined groups and 1217 tok/s in serial windows, and the decoding stream finished sooner
|
||||
(25.0 against 18.0 tok/s over its whole run); `--batch-mtp` does not change that. So it pays where concurrent decodes
|
||||
dominate; with long reads arriving beside decodes the pipelined groups can be the better choice. Not measured: more
|
||||
than two stages (the report on #1253 found no gain at four stages), more than two slots, sampled decoding, an
|
||||
upstream-main binary (the pipelined arm is our build, started with the flags 0.1.41 resolves to).
|
||||
|
||||
Our measurement of `--batch-mtp` on a layer split with 2x R9700 and all experts in VRAM: 80.2 -> 62.7 tok/s (-21.9%, 0/5 pairs faster) against the pipelined default, so it pays only when the experts do not all fit in VRAM.
|
||||
|
||||
Earlier, on engine 0.1.40.3 with this change and the same two cards, two concurrent streams: UD-Q4_K_XL 39.9 to 43.5
|
||||
tok/s without and 44.5 to 51.3 with `--batch-mtp` (2 runs per arm), and a small Coder IQ1_M test model with all
|
||||
experts in VRAM 84.0 without and 101.2 with it, the greedy text of both streams identical.
|
||||
|
||||
Text: with the same expert cache on both arms (the slot drafters take VRAM, so the cache differs unless the
|
||||
reserve is adjusted) and `--pcie-frac 0`, `--adapt-every 0`, the greedy text with `--batch-mtp` was equal to the text
|
||||
without it for 5 short prompts in all 6 comparisons (one restart per arm). That is text equality, not a bit-exactness
|
||||
proof, and a 25k-token prompt read while the other stream decodes was not repeatable between two identical streams
|
||||
of the same arm.
|
||||
|
||||
With a layer split, the engine options go into the config's `args`:
|
||||
|
||||
```
|
||||
"args": [ ..., "--batch", "8", "--batch-groups", "4", "--trim-stage-weights" ],
|
||||
"layer_split": "12,24,36"
|
||||
```
|
||||
|
||||
| Option | What it does |
|
||||
| --- | --- |
|
||||
| `"parallel": N` / `--batch N` / `--slots N` (2..8 normally; with a layer split up to 8 per group, see below) | up to N conversations have batch slots; more requests wait for a free slot. Each slot gets its own state (a session carved like the stage's own: GDN recurrence, QSA K/V and indexer, PLE history) on every GPU of the split. With grouped MTP, more than 8 slots can rotate through eight-row windows if memory permits. |
|
||||
| `--batch-groups G` | with a layer split (default: auto, below): the N slots in G groups that flow through the GPUs as a pipeline (GPU k runs one group while GPU k+1 runs another). G must divide N. 1 = all slots in one window, GPU after GPU. |
|
||||
| `--batch-groups auto` | the default on a layer split since 0.1.41 (give no `--batch-groups`): the engine pipelines one group per GPU stage (the most that divide the slots; 8 slots on 4 GPUs = 4 groups of 2) and says so (`INFO batch_groups=G`). `--batch-groups 1` turns it off (all slots in one window, GPU after GPU). Measured, 8 clients, total tok/s against one group: 4 x R9700 166 against 86, 2 GPUs 109 against 78, 3 GPUs 110 against 78. With `--adapt-async 1` and no `--batch-groups` the default is one group (the adaptive tier between batch windows does not run in pipelined groups) and the log says so; with `--batch-mtp` and no `--batch-groups` the pipeline wins and `--batch-mtp` is left off (`--batch-groups 1` or `STRATA_BATCH_MTP_SERIAL=1` keeps it); `--batch-groups G` or `--batch-groups auto` given with `--batch-mtp` pipelines the groups and turns `--batch-mtp` off, and given with `--adapt-async 1` pipelines the groups and turns `--adapt-async` off (the pipelined path does not adapt). |
|
||||
| `--trim-stage-weights` | with an **explicit** `--layer-split` (e.g. `12,24,36`, not `auto`): every GPU loads only the dense weights of its own layers instead of the whole model's (the same as `STRATA_STAGE_TRIM=1`, PR #639). The VRAM this frees goes to the expert cache. Useful without `--batch` too. |
|
||||
|
||||
The engine never refuses a count it cannot run: it says so in its log and runs what it can - at most 8 slots without a
|
||||
layer split (a window holds 8 rows; with a layer split and pipelined groups, 8 per group), as many as fit in VRAM, or none (one request at a time) when not two fit. The server reads
|
||||
the count the engine reports (`INFO batch_slots=N`), and `GET /v1/status` says it (`concurrency.serving`).
|
||||
|
||||
## More than 8 slots on a layer split, and the opt-in admission and decode switches
|
||||
|
||||
(From havok2-htwo's patch series, PR #2364.)
|
||||
|
||||
**More than 8 slots.** With a layer split a pipelined window holds at most 8 rows, but each group of the pipeline is its
|
||||
own window, so `--batch 16` on 4 GPUs runs 4 groups of 4 slots (`--batch-groups auto`), `--batch 32` runs 4 groups of 8.
|
||||
Until 0.1.44.1 the engine cut such a request down to 8 slots and said so; it now runs what is asked for, as many slots
|
||||
as fit in VRAM and at most 8 per group (`INFO batch_slots=N`). `--batch-mtp` keeps its limit (rows per window are
|
||||
doubled by the proposals). Nothing changes for 8 slots or fewer. Every slot of a 16-slot pipelined batch decodes
|
||||
exactly the tokens it decodes alone (`tools/batch_test.py --n 16`, which now takes up to 32 prompts).
|
||||
|
||||
**Opt-in switches** (environment of the engine, i.e. `"env"` in the config; none is on by default). Each one changes
|
||||
how the work is scheduled or copied, not what is computed; the identity gates and `tools/batch_test.py` are in
|
||||
`phaseA-tests/review-havok.md`.
|
||||
|
||||
| Switch | What it does |
|
||||
|---|---|
|
||||
| `STRATA_SLOT_COPY_DIRECT=1` | an admission (and a slot's resume) copies the running state and the QSA K/V device to device, instead of through host images |
|
||||
| `STRATA_SLOT_COPY_BATCHSYNC=1` | with the above: queue the ~116 copies and synchronize each device once |
|
||||
| `STRATA_SLOT_CKPT_MOVE=1` | the admission's turn checkpoint moves into the slot (no 112 MB copy); it also keeps the dropped checkpoints' storage, as `STRATA_CKPT_POOL` does; a session SAVE or parked conversation taken right after an admission lacks the moved checkpoint (the slot holds it) |
|
||||
| `STRATA_CKPT_POOL=1`, `STRATA_CKPT_THREADS=1` | a checkpoint is saved into the vectors of a dropped one; a split's stage parts are saved at once |
|
||||
| `STRATA_ADMIT_MERGE_FIRST=1` | an admission reads its last prompt tokens and its first token in one window (all experts resident only) |
|
||||
| `STRATA_PIPE_BYIELD_NODRAIN=1` | a BYIELD that reaches a pipelined batch is dropped without draining the groups |
|
||||
| `STRATA_BATCH_SELF_COMMIT=1` | a one-row-per-slot window advances the GDN state itself, no commit graph |
|
||||
| `STRATA_QSA_SLOTS=1` | a window's QSA block scores, top-k and attention run as one launch over its rows |
|
||||
| `STRATA_HANDOFF_PIPE=P` | a layer split hands a prompt chunk to the next card in P pieces (2..16), gated by events, on a persistent thread |
|
||||
| `STRATA_ADMIT_SHORT_FIRST=N` (server) | a new prompt of at most N tokens takes the control lines before longer ones (a longer one that waited `STRATA_ADMIT_MAX_WAIT_S`, default 30, counts as short) |
|
||||
| `STRATA_TRACE=1` | one line per admission with its phases (drain, prompt, first window, slot copy, checkpoint copy) |
|
||||
| `STRATA_MMQ_DIRECT=1`, `STRATA_MMQ_GROUP_SORT=1` | CUDA, needs the build option `-DSTRATA_MMQ_TAB=ON`: the prompt MMQ reads resident experts in their cache slots; full MMQ groups sorted by row count (docs/DETAILS.md) |
|
||||
|
||||
Measured (4x R9700 32 GB, HIP, IQ3_S all experts resident, layer split 12,25,37, 3 interleaved rounds per arm, 0.1.44.1
|
||||
with 8 slots against the same build with 16 slots and the switches above; aggregate output tok/s, TTFT p50 in seconds):
|
||||
|
||||
| users (prompt) | 0.1.44.1, 8 slots | 16 slots, no switch | 16 slots, all switches |
|
||||
|---|---|---|---|
|
||||
| 8 (147 tokens) | 209 / 2.70 s | 209 / 2.72 s | 251 / 1.82 s |
|
||||
| 16 (147 tokens) | 208 / 20.6 s | 252 / 5.4 s | 324 / 2.0 s |
|
||||
| 16 (1.2K tokens) | 145 / 23.9 s | 167 / 10.6 s | 204 / 5.3 s |
|
||||
| 16 agents x 3 turns, follow-up TTFT | 50 tok/s / 21.2 s | 53 / 7.1 s | 56 / 5.7 s |
|
||||
|
||||
One user alone is unchanged (73-74 tok/s). Each slot's session takes VRAM from the expert cache, so on a card or split
|
||||
where the experts do not all fit, 16 slots cost the single-user speed (see docs above on what a slot costs).
|
||||
|
||||
|
||||
### What a slot costs, and what setup recommends
|
||||
|
||||
Every slot's session takes VRAM that the expert cache would otherwise hold: 0.56 GiB at a 32K context with 8-bit
|
||||
KV, more with a longer context unless the KV cache streams (`--kv-resident`: then only the attention's 32K window
|
||||
stays in VRAM, and each slot's whole KV cache takes pinned RAM - 1.6 GB at 128K). On a card whose experts mostly run
|
||||
on the CPU, a batch also reads about as many distinct experts as the requests one by one (different conversations
|
||||
route to different experts), so the gain is in **latency** (nobody waits for a whole answer), and a request alone
|
||||
runs slower (the smaller expert cache): 11-24 % on a 12 GB card, see the measurements below.
|
||||
|
||||
So setup recommends `"parallel"` **only where the experts mostly fit in VRAM**: the expert cache (each card's VRAM
|
||||
less ~5 GB, every card of a layer split counted) must still hold at least half of the model's experts beside the
|
||||
slots, and the slots may take at most a fifth of it, up to 4 slots. With Q2_0 at 32K that is 3 slots on a 24 GB
|
||||
card, 4 from 32 GB or on a split such as 2 x 16 GB; IQ3_S needs 32 GB or a split. Everywhere else (any 12 or 16 GB
|
||||
card alone) it stays at one at a time and setup says: "parallel N reduces waiting for several users but costs
|
||||
about 10-25% speed per request on this card". `--parallel N` is honoured as asked either way.
|
||||
|
||||
## How the server uses the slots
|
||||
|
||||
- **One request alone** runs on the usual solo path (verify windows with MTP drafts): the fastest single stream.
|
||||
- **When a second request arrives**, the first is stopped (`STOP`) and continues in a batch slot with its prompt
|
||||
plus what it generated so far - the engine's prompt cache holds exactly that, so nothing is read again - and the
|
||||
new request is admitted next to it. By default, a request in a slot decodes **without MTP drafts** (one token per window).
|
||||
With `--batch-mtp`, each slot verifies one MTP proposal alongside its current token.
|
||||
- **A request left alone in a slot** (the others finished, nobody waits) goes back to the solo path: the slot is
|
||||
stopped, the engine copies its sessions back and decodes with MTP drafts again (at most twice per request; with
|
||||
`--prompt-cache 0` it stays in the slot; `STRATA_PARALLEL_SOLO=0` turns it off). The draft layer's own K/V was
|
||||
built for another conversation then, but measured it accepted as many drafts (140 of 172) as a draft layer that
|
||||
read the conversation (140 of 173).
|
||||
- **More requests than slots** wait for a free one (`/metrics` -> `live.slots` shows each slot: idle, reading or
|
||||
decoding, its tokens and tok/s; `live.running` the requests in flight).
|
||||
- **Each admission** reads the request's prompt through the usual prompt path (prompt cache and conversation
|
||||
checkpoints included) and produces its first token there; the state is then copied into the slot. Admissions
|
||||
are taken one at a time, and **the slots decode between the prompt's chunks**: after each chunk (`--prefill`,
|
||||
2048-8192 tokens) they decode for half as long as the chunk took (`STRATA_BATCH_DECODE_SHARE`, default 0.5), so
|
||||
a long prompt slows the others down instead of stopping them. The chunks are the ones one uninterrupted read
|
||||
takes, so the prompt's arithmetic is unchanged.
|
||||
- **A long prompt gives way to a short one** (#656's cooperative preemption): when a request with a prompt under
|
||||
half as long is waiting, the server sends `BYIELD`; at its next chunk boundary the long read stops, the part read
|
||||
so far is copied into a slot, the short request is admitted, and the long one then goes on from its slot with the
|
||||
same chunks (at most twice per request).
|
||||
- **Each slot is a conversation cache.** A finished slot keeps what it holds (the prompt, the answer, and the
|
||||
checkpoint at the prompt's last turn boundary); the next turn of that conversation goes to that slot and the
|
||||
engine copies its state back (50-60 ms for a short conversation) instead of reading the history again - also for
|
||||
a client that drops the reply's thinking from the history (the checkpoint matches up to the new turn). A new
|
||||
conversation takes an empty slot, else the one used longest ago.
|
||||
- Slots are assigned so that consecutive requests land in different pipeline groups (`--batch-groups`).
|
||||
- A client that disconnects stops its slot (`BSTOP`); the others go on.
|
||||
|
||||
## Reading a prompt beside pipelined groups (experimental, opt-in)
|
||||
|
||||
With a layer split and `--batch-groups` above 1 a prompt is read in one run: every decoding slot stops until it is
|
||||
read, however long it is (#1906). One GPU does not have this problem: there the slots decode between the prompt's
|
||||
chunks for `STRATA_BATCH_DECODE_SHARE` x the chunk's time.
|
||||
|
||||
`STRATA_PIPED_CONCURRENT=1` reads a prompt on a thread of its own while the slot groups keep decoding through the
|
||||
pipeline, instead of stopping them: the prompt's chunks and the slots' windows run on the same GPUs at once, on their
|
||||
own streams (the windows' at the device's highest priority on CUDA; `STRATA_PIPED_CONCURRENT_PRIO=0` keeps the default),
|
||||
so the slots never wait for the read and the read is one run with no drain inside it.
|
||||
|
||||
- The prompt's K/V goes to the main sessions and the slots' to their own, so they do not touch each other's state. The
|
||||
n-gram (PLE) table both of them read is locked. The adaptive VRAM tier stands still during the read: its round lands
|
||||
before the read and none starts while it runs.
|
||||
- The VRAM expert slots the prompt path borrows are lent before the read and refilled after it, with nothing in flight;
|
||||
in between the slots' windows compute those experts on the CPU.
|
||||
- The slots' doorbells are served on a thread of their own during the read, which makes no CUDA call. A CUDA call can
|
||||
wait for the driver's lock while its holder waits for the GPU - a free, or the module the first kernel of a new shape
|
||||
loads - and a window on that GPU waits for its doorbell (issue #31's pattern: two such hangs were found and read from
|
||||
the engine's stall dumps while this was built). The MTP drafter's prompt buffers and the prompt path's pinned upload
|
||||
slots are sized before the read, so its thread allocates and frees nothing. Between windows the doorbell thread waits
|
||||
for the next launch, which wakes it (a timed sleep is a whole timer tick on Windows, up to 15.6 ms). A window that
|
||||
will not finish is still found (its graph ended with a layer still to ring, or no layer rang for 20 s), and the stall
|
||||
watchdog stays on for the whole read.
|
||||
- A waiting shorter request takes over at the read's next chunk (`BYIELD`), also when no slot decodes: the run ends
|
||||
there, the pipeline is drained and the part read waits in a slot, as off the pipeline. A read nobody waits for is not cut.
|
||||
- Off, said once, where the read's thread would allocate or free (`STRATA_PREFILL_HELP=1`, `STRATA_SPLIT_MTP_BATCH=1`),
|
||||
where serving a doorbell makes a CUDA call (`--pcie-mode dma`, `STRATA_FS_SLOTS`, the helper caches
|
||||
`--expert-cache-device1..3`), and with an expert source that hands out buffers it recycles (the GGUF in place, an
|
||||
unbuffered source, `STRATA_IO_PREFETCH`): the experts come from the RAM arena or the mapped file. A prompt with
|
||||
pictures is read the usual way.
|
||||
|
||||
One log line per read (`strata batch: read N tokens on a thread of its own in X ms (concurrent, to Q of T); the slots
|
||||
decoded R rows meanwhile (S rows/s; stage k: W windows, H ms host each)`). Built for CUDA and HIP (HIP keeps the default
|
||||
stream priority, and is not run on a GPU here); SYCL does not have it.
|
||||
|
||||
Measured on 2x RTX 5090 (Swift 1.5 IQ3_S, split 25, `--batch 6 --batch-groups 2`, resident experts, k8v4, 262K,
|
||||
`--kv-resident 32768`, the engine-default decode share): main (`a0116b27`) against this mode, a fresh engine per arm in
|
||||
the order main, this mode, this mode, main (`tools/piped_read_join_bench.py`; the fixed-prompt rows send the same four
|
||||
stream prompts every run, so the streams' answers and work are the same):
|
||||
|
||||
| | main | `STRATA_PIPED_CONCURRENT=1` |
|
||||
| --- | ---: | ---: |
|
||||
| 64K + 32K cold prompts beside four streams: longest stop of a stream | 11.9 s | 0.77-0.84 s |
|
||||
| ... the streams' tokens meanwhile | 289-291 | 1,411-1,679 |
|
||||
| ... the prompts' TTFT | 6.8 / 5.8-5.9 s | 8.1-8.2 / 8.2-8.3 s |
|
||||
| the same with fixed stream prompts: the streams' rate while the prompts are read | 2-3 tok/s | 85-92 tok/s |
|
||||
| ... the streams finish at | 26.1-27.1 s | 24.6-25.3 s |
|
||||
| ... GPU utilization while the prompts are read | 75-86% | 85-91% |
|
||||
| a one-line question 1 s into a cold 45K read, nothing decoding: its TTFT | 5.7-5.9 s | 1.9 s |
|
||||
| ... and the 45K prompt's own TTFT | 6.2-6.4 s | 7.4-7.5 s |
|
||||
|
||||
The joining prompts pay for the GPU time the streams now get. Over a whole run with the same work, the streams
|
||||
finished 5-8% sooner (6.4% on average); with prompts that change from run to run (the bench's), the run's token rate
|
||||
varies more than that between runs. Between windows the doorbell thread first slept 50 us, which is a whole timer
|
||||
tick on Windows: the same build with `STRATA_TEST_BELL_SLEEP_US=50` gave the streams 64-67 tok/s during the reads
|
||||
instead of 85-92.
|
||||
|
||||
The same randomised load (`soak`: three streams, cold joins of 4-64K, short questions, follow-ups of earlier joins,
|
||||
clients leaving mid-read and mid-answer; 5 minutes, the same seed) on main and in this mode: 167 and 180 requests
|
||||
answered; the longest gap inside a stream 9.8 and 1.0 s (90th percentile 8.5 and 0.7 s); the joins' TTFT median 3.8
|
||||
and 4.6 s. A request that comes during a read still waits for it, unless its prompt is under half as long (`BYIELD`).
|
||||
|
||||
A 16 GB card on each side (`--vram-reserve-mib 16600 --kv-resident 16384`, the same flags otherwise):
|
||||
|
||||
| | main | this mode |
|
||||
| --- | ---: | ---: |
|
||||
| fixed stream prompts, 64K + 32K joining: the streams' rate while the prompts are read | 0.9 tok/s | 52.9 tok/s |
|
||||
| ... the streams finish at | 70.6 s | 63.8 s |
|
||||
| ... the prompts' TTFT | 9.5 / 10.1 s | 15.8 / 21.1 s |
|
||||
| a one-line question 1 s into a cold 45K read: its TTFT | 7.3 s | 3.8 s |
|
||||
| the 45K prompt read alone | 7.33 s | 7.25 s |
|
||||
|
||||
A weaker host as well (16 GB cards, the experts from the mapped file, AVX2 expert kernels, 6 pool workers), in #1906's
|
||||
shape (`--batch 2 --batch-groups 2`): one stream decoding while another's cold prompt is read:
|
||||
|
||||
| cold prompt | main: the stream's longest stop / tok/s meanwhile / the prompt's TTFT | this mode |
|
||||
| --- | ---: | ---: |
|
||||
| 64K | 11.1 s / 2.4 / 10.9 s | 0.41 s / 25.7 / 11.7 s |
|
||||
| 127K | 20.3 s / 1.5 / 19.9 s | 0.64 s / 32.7 / 20.7 s |
|
||||
|
||||
So the cost is the joining prompt's: +4-7% beside one stream, +20-45% beside four on these cards, and +67-109% beside
|
||||
four on 16 GB cards, where the streams' windows take a larger share of the GPU.
|
||||
|
||||
**Checked:** with the variable unset this build gives main's tokens (six greedy answers' SHA-256 equal in two engine
|
||||
starts each, `--prompt-cache 0 --adapt-swaps 0 --pcie-frac 0`) at main's speed. In this mode, 25 minutes of the
|
||||
randomised load above (also on `--batch 2`): about 760 requests, 340 concurrent reads and 88 give-ways, with no hang, no
|
||||
error and no stall report.
|
||||
|
||||
**Text equality** (`batch_interleave_test.py --long 40000` with its exact settings, `--batch 4 --batch-groups 2`, no
|
||||
conversation cache): this test is not reproducible run to run on this PC even for main (A differed from its solo tokens
|
||||
at token 142 in one run of two). In this mode every request equaled its solo tokens in two runs of three - D giving way
|
||||
at its first chunk (`YIELDED 2 2048`), E admitted meanwhile, D going on and A going back to the solo path included,
|
||||
which main does not do on this path (D never gives way there); the third run had B off at token 74, a near tie that
|
||||
flips on main as well. Greedy only; other GPU pairs, three or more stages and sampled decoding not measured.
|
||||
|
||||
## A prompt read beside pipelined groups (opt-in)
|
||||
|
||||
With a layer split and `--batch-groups` above 1 a prompt is read in one run: every decoding slot stops until it is read,
|
||||
however long it is, `STRATA_BATCH_DECODE_SHARE` does not apply and no `BYIELD` is taken (`batch_read_piece` returns 0
|
||||
for the pipelined groups; #1906). One GPU does not have this problem: there the slots decode between the prompt's chunks
|
||||
for `STRATA_BATCH_DECODE_SHARE` x the chunk's time. These variables give the pipelined groups the same choice:
|
||||
|
||||
- `STRATA_PIPED_READ_PIECE=N`: a prompt read on the pipelined groups goes in pieces of N tokens, rounded down to whole
|
||||
chunks (at least one, at most 32), so a piece reads exactly the chunks a single run would, the two stages stay
|
||||
overlapped inside it and only the piece's end drains the pipeline. Between two pieces the slot groups decode through
|
||||
the pipeline for `STRATA_BATCH_DECODE_SHARE` x the piece's time, at most `STRATA_PIPED_DECODE_MAX_MS` and at least
|
||||
`STRATA_PIPED_DECODE_MIN_MS`, and every group in flight finishes before the next piece, as before any prompt read.
|
||||
- At a piece's end the pipeline is drained, so a waiting request with a prompt under half as long can take over there
|
||||
(`BYIELD`, as between the chunks of a read off the pipeline): the part read waits in a slot and the read goes on from
|
||||
it after the short request is in. The pieces are also taken when no slot decodes, for this reason (off the pipeline
|
||||
the same read goes in `STRATA_BATCH_YIELD_CHUNKS` pieces then).
|
||||
- A read that starts within a second (plus the decode budget) of the previous such read's end - prompts arriving back to
|
||||
back - first gives the slots one decode budget (the same rule, from the previous read's last full piece); otherwise
|
||||
the slots would stop for both reads.
|
||||
|
||||
With the variables unset the read is one run as before. One log line per piece (`strata batch: piped read N tokens in X
|
||||
ms (to Q of T)`, with `, then the slots decoded R rows in Y ms` when slots decode), per give-way (`the prompt read gives
|
||||
way at Q of T tokens; slot S holds it`) and per lead-in (`a read right after a read: the slots decoded R rows in Y ms
|
||||
first`).
|
||||
|
||||
**What it trades.** Every piece ends by draining the pipeline, so a long read takes longer - also on an idle server,
|
||||
since the pieces are what lets a short request in - and the decoding streams get tokens where they had none. It is a
|
||||
latency choice, not a throughput gain: leave it off where throughput or the long prompt's own TTFT matters most, use it
|
||||
where a stream that stops for several seconds, or a short question stuck behind a long read, is worse than a long prompt
|
||||
that waits a little longer.
|
||||
|
||||
Measured on 2x RTX 5090 (Swift 1.5 IQ3_S, `--layer-split 25 --trim-stage-weights --batch 6 --batch-groups 2
|
||||
--resident-experts`, k8v4 KV, 262K context, `--kv-resident 32768`, `STRATA_ARENA_PIN_GIB=24`, Windows 11; a CUDA 13.0
|
||||
sm_120 build of this change on 0.1.43, "release" = 0.1.43 built the same way; a fresh engine for every run, all from one
|
||||
window, `tools/piped_read_join_bench.py`). Four streams decode greedy coding answers (thinking off, up to 2048 tokens)
|
||||
when cold prompts of this repository's own source text join. "Longest stop": the longest time any stream received no
|
||||
token, from the first prompt's arrival to the last one's first token + 1 s (client-side, SSE); "stream tokens": what the
|
||||
four streams received in that window; "token rate": the streams' tokens over the run's wall time.
|
||||
|
||||
Two cold prompts, 64K then 32K, arriving 6 s apart (`--scenarios two_joiners`; release and 32K pieces: median of 5 runs
|
||||
each, interleaved; 16K pieces: one run):
|
||||
|
||||
| arm | prompts' TTFT | longest stop of a stream | stream tokens | token rate |
|
||||
| --- | ---: | ---: | ---: | ---: |
|
||||
| release (one run per prompt) | 6.9 s / 6.1 s | 12.2 s | 289 | 173 tok/s |
|
||||
| `PIECE=32768 DECODE_MAX_MS=400` | 8.1 s / 8.5 s | 4.2 s | 527 | 166 tok/s |
|
||||
| `PIECE=16384 DECODE_MAX_MS=400` | 10.5 s / 12.0 s | 2.6 s | 793 | 154 tok/s |
|
||||
|
||||
The longest stop was 12.16-12.23 s for the release in all five runs and 4.19-4.22 s for 32K pieces in four; in the fifth
|
||||
the first 32K piece of the 64K prompt took 9.3 s instead of 3.95 s (one uninterrupted run before any slot decoded),
|
||||
which made that run's stop 9.5 s. The token rate varied 169-180 tok/s (release) and 136-174 tok/s (32K) between runs.
|
||||
|
||||
A short request behind a long read, nothing decoding (#1504's test, `--scenarios followup,read_alone --repeat 3`, median
|
||||
of 3): a one-line question sent 1 s after a cold 45K prompt, and the same 45K prompt read alone:
|
||||
|
||||
| arm | the question's TTFT | the 45K prompt's TTFT | the 45K prompt alone |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| release | 5.4 s | 6.0 s | 5.7 s |
|
||||
| `PIECE=32768 DECODE_MAX_MS=400` | 3.6 s | 7.3 s | 6.4 s |
|
||||
| `PIECE=16384 DECODE_MAX_MS=400` | 1.8 s | 8.0 s | 7.1 s |
|
||||
|
||||
With the variables unset this change ran as the release in the same window (the 45K read alone 5.66 vs 5.69 s, the two
|
||||
joiners' longest stop 12.2 s on both) and gave the same SHA-256 for six greedy answers under `--prompt-cache 0
|
||||
--adapt-swaps 0 --pcie-frac 0`. For reference, one RTX 5090 (the same model and flags without the split, 6 slots) with
|
||||
one cold 64K prompt joining four streams: `STRATA_BATCH_DECODE_SHARE=2.0` 2.4 s longest stop and 37.2 s TTFT, `=0` 14.0
|
||||
s and 13.8 s. Pieces of one chunk (`PIECE=8192`) cost the long prompt the most. Not measured: other GPU pairs, three or
|
||||
more stages, HIP and SYCL (built for CUDA only), sampled decoding, prompts with pictures.
|
||||
|
||||
## The VRAM expert tier keeps adapting in batch windows
|
||||
|
||||
Batch windows count which experts they route to, and every `--adapt-every` windows (default 4) the engine swaps the
|
||||
most-routed experts that are not in VRAM into the cache in place of the least-routed resident ones, the same rule the
|
||||
solo path uses (`--adapt-swaps` and `--adapt-decay` apply too; on a layer split every GPU's cache adapts). It runs when the
|
||||
tier is not the whole model and both `--adapt-every` and `--adapt-swaps` are above 0. By default the round runs beside the
|
||||
window's commit and drafts and has landed before the next window starts. It stands still while a long prompt is read
|
||||
between decoding windows (the prompt may hold a loan of cache slots). The `strata batch:` log line shows the rounds and swaps, each stage's
|
||||
GPU-reach wait and pool time, and how many routed entries the VRAM tier, the PCIe share and the CPU served per window.
|
||||
Swaps move experts between the GPU and the CPU, which round differently, so greedy outputs can differ from run to run;
|
||||
`--adapt-every 1000000` keeps the tier fixed (as in the exactness settings below). The pipelined `--batch-groups` path
|
||||
does not adapt.
|
||||
|
||||
With `--adapt-async 1` (needs the resident RAM mode) the round does not hold a window up: each batch window moves the
|
||||
round on one step (table changes and uploads on the main thread, the copies on a helper thread and the cards' refill
|
||||
streams), as on the solo path. A request that arrives finishes the round in flight before it starts, and a prompt read
|
||||
between decoding windows does not move it. `--adapt-min-gain F` (default 1.5) raises the bar a swap must clear (the
|
||||
routing count of the expert coming in against the one going out), so fewer experts move per round; both tiers use it.
|
||||
The log line's `adapt wait` is the time the main thread spent on the tier per window (the blocking tier: waiting for
|
||||
its round).
|
||||
|
||||
Measured with the same setup as the `--batch-mtp` numbers above (2x RTX 3080 20 GB, UD-Q4_K_XL, `"layer_split": "23"`,
|
||||
`"parallel": 2`, `--batch-mtp`, engine 0.1.41 with our production stack; two concurrent greedy decodes, the streams'
|
||||
tok/s added, median of 20 measurements per restart):
|
||||
|
||||
| tier | aggregate tok/s | restarts | per window | routed entries served from VRAM |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `--adapt-async 1 --adapt-every 2` | **89.2** | 3 | 34.6 ms, adapt wait 0.2 ms | 92.1% |
|
||||
| blocking, `--adapt-every 2` | 74.7 | 1 | 41.4 ms, adapt wait 8.4 ms | 92.3% |
|
||||
| none, the cache frozen from a profile the tier had learned on the same prompts | 69.5 | 1 | 43.6 ms | 77.2% |
|
||||
| none, `--adapt-every 0` | 45.2 | 2 | 66-68 ms | 52.7% |
|
||||
|
||||
The switch changes the tier in the solo path as well (there is no switch for batch windows alone), so the table
|
||||
compares the tier as a whole, not "batch windows only": the solo decode speed moves the same way (81.7, 66.3, 69.0 and
|
||||
43.1 tok/s). The prompts are the benchmark's own, eight topics that repeat, which the tier learns quickly, so on a
|
||||
more varied workload the gain may be smaller (not measured). Upstream main runs no tier in batch windows, and this
|
||||
was not measured against an upstream binary.
|
||||
|
||||
## Exactness
|
||||
|
||||
A batch row's arithmetic is the single-token window's, so with greedy decoding **every conversation of a batch
|
||||
produces exactly the tokens it produces alone** - verified token by token for 8 concurrent conversations of 150
|
||||
tokens, with and without the pipeline (`tools/batch_test.py`), and on one RTX 5070 for 4 conversations, for a long
|
||||
prompt read while two others decode, for a prompt that gave way and went on, for a next turn continued from its
|
||||
slot (from all it holds, and from its turn checkpoint without the reply's thinking), and for a request stopped in
|
||||
its slot and continued on the solo path (`tools/batch_interleave_test.py`). These
|
||||
settings make the comparison exact:
|
||||
|
||||
- `STRATA_IQ_MT_MIN=1` (the multi-token CPU expert kernels for every group, as for the solo path's own
|
||||
exactness tests: by default an expert's rows round differently alone than in a group, so the output depends on
|
||||
how many rows of a window share an expert - which differs between a batch and a request alone),
|
||||
- `--pcie-frac 0`: the PCIe share of the missed experts is chosen per window from the window's misses, so the
|
||||
same expert can run on the GPU in one window and on the CPU in another, which rounds differently, and
|
||||
- `--adapt-every 1000000` (the VRAM tier fixed), and `--no-prefill-borrow` while a prompt is read beside decoding
|
||||
slots: their windows then see the expert cache without the slots the prompt borrowed (those experts run on the
|
||||
CPU).
|
||||
|
||||
With the default settings the outputs stay coherent but drift apart after some tokens, as two solo runs whose
|
||||
windows differ can. Measured on the RTX 5070 (Q2_0, 4 conversations of 200 tokens, `tools/batch_test.py` without
|
||||
the settings above): one equal to its solo run, the others apart from token 0, 99 and 174 - the first token already
|
||||
differed for one, because the adaptive VRAM tier had moved experts between the solo runs and the batch; all four
|
||||
texts read as well as their solo runs.
|
||||
|
||||
Sampled requests (temperature, top_p, top_k, min_p, seed) are drawn row by row with the solo window's
|
||||
counter-based draw (Philox(seed, position)).
|
||||
|
||||
## Limits (for now)
|
||||
|
||||
- By default, batch windows carry no MTP drafts: a conversation in a slot decodes one token per window (the solo
|
||||
path keeps its drafts, which is why a request alone is not put in a slot, and goes back to it when left alone).
|
||||
- `--batch-mtp` uses one proposal per slot. With a layer split it needs each stage on its own GPU, does not combine
|
||||
with `--batch-groups` above 1 (pipelined slot groups run no drafts, #1413) and has not been run with helper expert
|
||||
caches.
|
||||
- Repetition / frequency / presence penalties are not applied in batch windows.
|
||||
- A prompt shorter than one chunk is read in one piece (the slots wait for it); a read gives way only at a chunk
|
||||
boundary, and not for pictures.
|
||||
- Admissions are one at a time: two new long prompts are read one after the other.
|
||||
- `--batch-groups` needs every stage on its own GPU. A pipelined slot is a conversation cache again (0.1.41): a request left alone in its slot goes back to the solo path with its drafts, as on one GPU.
|
||||
- The slot sessions take VRAM (above) and, with KV streaming, pinned RAM.
|
||||
|
||||
## Measured
|
||||
|
||||
One RTX 5070 (12 GB), Ryzen 5 7600, 64 GB DDR5, Q2_0, 32K context, through the HTTP server: C different requests
|
||||
sent at once (an 800-word essay each, 256 tokens per answer, greedy, thinking off), median of 3 rounds:
|
||||
|
||||
| Concurrent | Setting | Total tok/s | vs one at a time | Per request tok/s | First token: median / last of the round |
|
||||
| ---: | --- | ---: | ---: | ---: | ---: |
|
||||
| 1 | one at a time (default; what setup recommends on this card) | 74.3 | - | 83.6 | 0.4 s / 0.4 s |
|
||||
| 1 | `"parallel": 2` | 67.3 | -9 % | 74.8 | 0.4 s / 0.4 s |
|
||||
| 1 | `"parallel": 4` | 57.9 | -22 % | 63.8 | 0.4 s / 0.4 s |
|
||||
| 2 | one at a time | 71.6 | - | 77.3 | 2.1 s / 4.1 s |
|
||||
| 2 | `"parallel": 2` | 61.0 | -15 % | 32.6 | 0.5 s / 0.9 s |
|
||||
| 2 | `"parallel": 4` | 54.6 | -24 % | 28.7 | 0.6 s / 0.7 s |
|
||||
| 4 | one at a time | 70.7 | - | 79.6 | 6.0 s / 11.2 s |
|
||||
| 4 | `"parallel": 2` | 61.2 | -13 % | 32.2 | 4.5 s / 9.3 s |
|
||||
| 4 | `"parallel": 4` | 63.1 | -11 % | 16.9 | 1.0 s / 1.8 s |
|
||||
|
||||
On this card the slots buy **waiting time, not speed**: the fourth of four requests starts after 1.8 s instead of
|
||||
11.2 s, but together they decode 11-24 % slower than one after the other, and a request alone loses 11 % (2 slots)
|
||||
or 24 % (4 slots), because the slots' sessions (0.56 GiB each) come out of the expert cache and most experts run
|
||||
on the CPU: a batch window over 4 conversations reads 24 CPU experts per layer against ~8 for one, so it costs about
|
||||
what the 4 tokens cost one after the other (`strata batch:` in the engine log: 54 ms per 4-row window, ~20 ms per
|
||||
1-row window). This is why setup leaves a 12 GB card at one at a time. Cards that hold most experts in VRAM, and a
|
||||
layer split, are where the slots also add speed (below).
|
||||
|
||||
A 4-GPU layer split (4 x 16 GB, PCIe Gen3), IQ3_S, `--batch 8 --batch-groups 4 --trim-stage-weights`, through
|
||||
the HTTP server, 400 tokens per answer, temperature 0.7 (PR #559):
|
||||
|
||||
| Concurrent requests | Per request | Total |
|
||||
| ---: | ---: | ---: |
|
||||
| 1 | 123 tok/s (solo path) | 120 tok/s |
|
||||
| 2 | 57 tok/s | 113 tok/s |
|
||||
| 4 | 51 tok/s | 205 tok/s |
|
||||
| 8 | 45 tok/s | 360 tok/s |
|
||||
|
||||
With the patches below on engine 0.1.38 and parking on, through the service: 8 requests at temperature 0 -> 369
|
||||
tok/s, at 0.7 -> 358 tok/s.
|
||||
|
||||
`--trim-stage-weights` alone raised the share of experts held in VRAM on that machine from 76-85 % to 84-100 %
|
||||
per card.
|
||||
|
||||
### One launch for all slots (opt-in)
|
||||
|
||||
In a batch window, QSA block scoring, top-k and decode attention ran as one launch per row, and the GDN recurrence
|
||||
(in the window and in the 1-row commit) as one launch per slot. Two switches run each of them as one launch for all
|
||||
rows, every row still reading its own slot's indexer keys, K/V pools and GDN state (passed by value as kernel
|
||||
params, so the graph captured per row layout stays valid):
|
||||
|
||||
| Switch | What it does |
|
||||
| --- | --- |
|
||||
| `STRATA_BATCH_ATTN_ROWS=1` | block scores, top-k and decode attention of all the window's rows (up to 8) in one launch each. Not with KV streaming (a slot with `kv_mode` 1 keeps the per-row launches). |
|
||||
| `STRATA_BATCH_GDN_GROUPS=1` | the GDN recurrence in the window, and the commit of 1-row groups, for all slots in one launch. The conv commits stay per slot. |
|
||||
|
||||
Both are off by default; off, the engine runs the same launches as before. On, the arithmetic per row is the same:
|
||||
4 concurrent prompts at temperature 0 gave the same bytes as without them, with `--batch 4` and `--batch 8`.
|
||||
|
||||
One RTX PRO 6000 Blackwell (96 GB), IQ3_S, all 24,576 experts in VRAM, `--kv int8`, 262144 context, `--mtp`,
|
||||
`--spec 4`, through the HTTP server: C different stories sent at once, 1024 tokens each, temperature 0.7, mean of
|
||||
2 rounds, total tok/s (engine a0116b2, same day):
|
||||
|
||||
| Concurrent | `--batch 4` | with both switches | `--batch 8` (reserve 6144 MiB) | with both switches |
|
||||
| ---: | ---: | ---: | ---: | ---: |
|
||||
| 1 | 179.2 | 179.4 | 186.6 | 179.7 |
|
||||
| 2 | 204.1 | 218.7 | | |
|
||||
| 3 | 243.2 | 276.6 | | |
|
||||
| 4 | 268.4 | 311.7 | 267.7 | 311.6 |
|
||||
| 6 | | | 297.7 | 354.8 |
|
||||
| 8 | | | 308.4 | 374.8 |
|
||||
|
||||
The window (`strata batch:` in the engine log) costs 14.3 ms for 4 rows and 24.6 ms for 8 rows without them, and
|
||||
12.2 ms and 19.9 ms with them: about 1.7-1.9 ms per added row instead of 2.4 ms.
|
||||
|
||||
## Together with conversation parking
|
||||
|
||||
`--conversation-cache-mib N --conversation-cache-slots K` (DETAILS.md) works with the layer split too: a request
|
||||
whose conversation was parked is restored on every stage before its admission, so an agent and its sub-agents, or
|
||||
several chats that alternate, come back without reading their history again. Measured on the same 4-GPU split,
|
||||
two long conversations alternating through the HTTP server: the first turns took 3.9 s and 5.7 s to the first token
|
||||
(their prompts read), the follow-ups 0.53 s and 0.46 s.
|
||||
|
||||
## Testing
|
||||
|
||||
Four scripts drive a built engine or a running server; each exits non-zero on a failure. `serve/test_parallel.py`
|
||||
tests the server's side with a scripted engine (no GPU).
|
||||
|
||||
| Script | What it checks |
|
||||
| --- | --- |
|
||||
| `tools/batch_test.py` | the same prompts alone (`GEN`) and together in the batch slots (`BGEN`): every slot's greedy tokens equal its solo tokens; prints the aggregate rate. `--batch-groups` in `--extra` tests the pipeline, `--keys "temperature=0.7"` the sampled rows. |
|
||||
| `tools/batch_interleave_test.py` | a long prompt read while two slots decode, a prompt that gives way (`BYIELD`) and goes on, and a next turn continued from its slot: each equal to its solo tokens. On a two-stage layer split with pipelined groups add `--batch 4 --batch-groups 2` to `--extra` (its 3 slots do not divide into two groups) and set `STRATA_PIPED_READ_PIECE`; run it without a conversation cache, or step 4 restores the prompt instead of reading it. |
|
||||
| `tools/parking_test.py` | a follow-up to a conversation decodes the same tokens whether its state stayed live or came back from the parking cache (with a layer split: every stage's image). |
|
||||
| `tools/early_close_test.py` | a client that stops reading a streamed answer early (alone, and with a second request running) does not leave its tokens to the next request (server). |
|
||||
|
||||
For exact comparisons pass `--pcie-frac 0 --adapt-every 1000000` (and the scripts set `STRATA_IQ_MT_MIN=1`):
|
||||
|
||||
```
|
||||
python3 tools/batch_test.py --exe engine/strata --config strata-<model>.json --batch 8 --n 8 \
|
||||
--extra "--layer-split 12,24,36 --trim-stage-weights --batch-groups 4 --pcie-frac 0 --adapt-every 1000000"
|
||||
python3 tools/batch_interleave_test.py --exe engine/strata --config strata-<model>.json \
|
||||
--extra "--pcie-frac 0 --adapt-every 1000000 --no-prefill-borrow"
|
||||
python3 tools/parking_test.py --exe engine/strata --config strata-<model>.json \
|
||||
--extra "--layer-split 12,24,36 --conversation-cache-mib 8192 --conversation-cache-slots 4 --pcie-frac 0"
|
||||
STRATA_KEY=<key> python3 tools/early_close_test.py http://127.0.0.1:8080
|
||||
```
|
||||
|
||||
For single-GPU `--batch-mtp`, use a model with `rt/draft_vocab.bin` to exercise admission with a
|
||||
shared draft-vocabulary head. This compares both slots' output against solo decoding:
|
||||
|
||||
```
|
||||
python3 tools/batch_test.py --exe engine/strata --config strata-<model>.json --batch 2 --n 2 --max-new 64 \
|
||||
--extra "--batch-mtp --pcie-frac 0 --adapt-every 1000000"
|
||||
```
|
||||
|
||||
## Engine protocol (`--serve`)
|
||||
|
||||
On top of `GEN` / `GENI`:
|
||||
|
||||
| Line | Direction | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `BGEN <slot> <max_new> [keys] <ids>` | in | read the prompt (as `GEN 1`), then continue in `<slot>` |
|
||||
| `BGENI <slot> <max_new> [keys] <file> <ids>` | in | the same with images |
|
||||
| `BADM <slot> <1/0>` | out | after the admission's `DONE`: 1 = it continues in the slot, 0 = it ended |
|
||||
| `BT <slot> <id>` | out | a token of that slot |
|
||||
| `BDONE <slot> <generated> <stop/length/cancel> <ms>` | out | the slot is free again (it keeps its conversation) |
|
||||
| `BSTOP <slot>` | in | end that slot at its next window |
|
||||
| `BYIELD <slot>` | in | the prompt being read gives way at its next chunk boundary; its part read waits in `<slot>` (the admission's own, or a free slot for a solo request) |
|
||||
| `YIELDED <slot> <tokens>` | out | before the `DONE cancel` of a read that gave way: the request is sent again later and goes on from there |
|
||||
| `INFO ... batch_slots=N` | out | the slots the engine runs (only with `--batch`) |
|
||||
|
||||
`tools/batch_test.py` drives the engine directly: the same prompts alone, then together, compared token by token,
|
||||
and the aggregate rate.
|
||||
@@ -0,0 +1,598 @@
|
||||
# Correctness plan: the two engines against llama.cpp at 3cf03257
|
||||
|
||||
_Results (step 12, run 2026-10-18 on the A6000 VM): `bench/unbiased/correctness/README.md` in git history at commit
|
||||
7551f138; the run directories were removed from the tree on 2026-10-19, and the harness moved from
|
||||
`bench/unbiased/correctness/scripts/` to `bench/correctness/`. The `bench/unbiased/...` paths below are as they were at the time._
|
||||
|
||||
PLAN.md step 11 (`PLAN.md:318`), written 2026-10-18. This is a plan: nothing in it has been run, no code was
|
||||
changed, and every line number was read from this tree, the submodule `third_party/llama.cpp` (HEAD
|
||||
`3cf03257`, "CUDA: enable sparse fa for qwen4 (#28770)") or the upstream checkout
|
||||
`~/Code/unbiasedstrata2/PolyStrata-v0.1.45-poly.1`. Step 12 (`PLAN.md:319`) runs what is signed off here and
|
||||
writes the results under `bench/unbiased/correctness/`.
|
||||
|
||||
Where a claim could not be settled by reading, it says so. Three such items matter for the run order and are
|
||||
listed in section 2.1 and section 5.3.
|
||||
|
||||
## 0. Scope
|
||||
|
||||
**Target.** Linux x86-64, one NVIDIA GPU of Pascal or newer, CUDA 12.x. The numbers and run lines below are
|
||||
the RTX 3090 pod's (`bench/unbiased/2026-10-17-3090pod-*-step6/server-command.sh`, `engine-info.txt`): 24 GB,
|
||||
driver 580.126.20, CUDA 12.8, a CPU without AVX-512.
|
||||
|
||||
**Configuration A: `strata`, Qwen3.8-Flash-Next GSQ-RCO IQ3_XXS.** Run line
|
||||
`bench/unbiased/2026-10-17-3090pod-flash-next-iq3xxs-step6/server-command.sh:9-12`: `--pack` (the expert pack
|
||||
from `tools/iq_pack.py`), `--native` shard 1, `--ple-gguf` shard 2, `--expert-profile`, `--expert-cache auto`,
|
||||
`--prefill auto`, `--spec 4 --spec-min-p 0.5`, `--mtp` (the draft layer from `tools/mtp_pack.py` and
|
||||
`tools/mtp_rt.py`), `--max-context 65536`, `--kv int8`, `--ple-io ram`, `--pool-workers 15`,
|
||||
`--kv-resident 32768`. On the pod 10,531 of 24,576 routed experts are in VRAM (`engine-info.txt`: "expert
|
||||
cache 10531 slots", 48 layers x 512 experts), so the other experts are computed on the CPU's AVX-2 kernels or
|
||||
streamed over PCIe (`pcie_frac=0.55`), and `STRATA_ROUTE_TAIL_SKIP=7` and the prefill CPU share are on by
|
||||
default (both printed in `engine-info.txt`).
|
||||
|
||||
**Configuration B: `strata-poly`, Qwen3.6-35B-A3B UD-Q3_K_M, and UD-IQ4_XS.** Run line
|
||||
`bench/unbiased/2026-10-17-3090pod-qwen36-ud-q3km-mtp-step6/server-command.sh:7-8`: `--model` (the Unsloth
|
||||
MTP file, draft block inside), `--max-context 32768`, `--expert-profile`, `--tail-skip 6`. On the pod every
|
||||
routed expert is in VRAM (`engine-info.txt`: `expert_slots=10496` = 41 layers x 256, including the draft
|
||||
block's), so `--tail-skip 6` has nothing to skip and no CPU expert runs in decode.
|
||||
|
||||
**Reference.** llama.cpp at the pinned commit, built from `third_party/llama.cpp` with CUDA on, run twice per
|
||||
sequence: all layers on the GPU and all on the CPU backend. The two reference runs against each other are the
|
||||
noise floor of "two correct implementations", which is how upstream frames every comparison it reports
|
||||
(`docs/QWEN36.md:33-35`, `tools/qwen35/kl.py:1-8`).
|
||||
|
||||
**What "the same" means here.** Three tiers, used by every check below:
|
||||
|
||||
| Tier | Statement | Where it is owed |
|
||||
| --- | --- | --- |
|
||||
| T0, bitwise | Two runs of the same engine write the same bytes | Wherever the engine claims it: draft on against draft off, a verify window against one token, streamed KV against resident KV, prompt chunks of different sizes with the CPU share off |
|
||||
| T1, argmax at a margin | At every position where llama.cpp's two likeliest tokens differ by 0.5 nats or more, the engine's argmax is llama.cpp's | Every engine-versus-llama.cpp comparison |
|
||||
| T2, distribution | Mean KL(llama.cpp GPU \|\| engine) over the answer's positions is at most 1.5x mean KL(llama.cpp GPU \|\| llama.cpp CPU) on the same positions | Every engine-versus-llama.cpp comparison; lossy options (int8 KV, Q8_0 KV) against the same engine's fp16 run |
|
||||
|
||||
Why these and not "the same token ids": section 3.6.
|
||||
|
||||
**Out of scope.** Pictures (`GENI`), batch slots (`--batch`), HIP, other quantizations, sampled decoding
|
||||
(the sampler is checked by `sampler_parity` alone, section 2.2), the front end's HTTP layer
|
||||
(`frontend/tests/`).
|
||||
|
||||
## 1. Kernel and code paths in use
|
||||
|
||||
### 1.1 What the engines take from the pinned llama.cpp
|
||||
|
||||
The engines call no `llama_*` function. They link `ggml-base` and `ggml-cpu` from the submodule
|
||||
(`CMakeLists.txt:1418`, `:1479`; `GGML_CUDA` forced off, `:1430`) and compile these ggml-cuda sources into
|
||||
their own libraries:
|
||||
|
||||
| Library | Sources from the submodule | `CMakeLists.txt` | Who calls it |
|
||||
| --- | --- | --- | --- |
|
||||
| `strata_mmq` (static) | `ggml-cuda/quantize.cu`; `template-instances/mmq-instance-{q2_0,iq2_xxs,iq2_xs,iq2_s,iq3_xxs,iq3_s,iq4_nl,iq4_xs,q8_0}.cu` | `:1568`, `:1585-1587`, `:1603-1605` | `strata`'s prompt path for routed experts (`src/prefill/moe_mmq.cu:404-460`) |
|
||||
| `strata_kq` (shared, `libstrata_kq.so`, opened at run time by `STRATA_MMQ_KQ=1`) | `mmq-instance-{q4_k,q5_k,q5_1,q6_k}.cu` | `:1595`, `:1685-1687` | `strata` prompt path for K-quant packs; not configuration A |
|
||||
| `strata_poly_mmq` (static) | `quantize.cu`; 18 instances `q4_0 q4_1 q5_0 q5_1 q8_0 q2_k q3_k q4_k q5_k q6_k iq1_s iq2_xxs iq2_xs iq2_s iq3_xxs iq3_s iq4_nl iq4_xs` | `:2016-2018`, `:2045-2046` | `strata-poly`'s prompt path for every quantized matrix of 32 rows or more (`src/poly/mmq.cu:83-119`) |
|
||||
| `strata_kernels`, `strata_kernels_cpu` | `third_party/ggml/ggml-common.h` (a copy; `third_party/ggml/VERSION.txt` says `3cf03257`, and `diff -q` against the submodule's copy is empty) | `:503`, `:1486` | Every "native" GPU kernel and the CPU expert kernels: the block layouts and codebook grids are llama.cpp's |
|
||||
|
||||
The decode-time dot products are transcriptions, not links: `src/kernels/cuda/iq_kernels.cu:3-6` says the
|
||||
`vec_dot_*_q8_1` functions, the dequantizers and the q8_1 quantizer are transcribed from
|
||||
`ggml-cuda/vecdotq.cuh`, `dequantize.cuh` and `quantize.cu` at the `VERSION.txt` commit;
|
||||
`include/strata/kernels/iq_kernels.hpp:1-7` says activations are q8_1 (32 values, fp16 scale and sum), "the
|
||||
llama.cpp CUDA contract". `src/kernels/cuda/native_mmvq.cu:3110-3130` dispatches Q3_K, Q4_K, Q5_K, Q6_K,
|
||||
Q8_0 and IQ4_XS to per-type kernels and the i-quants to `iq_mmvq`. The CPU side links ggml-cpu for single-token
|
||||
experts (`src/kernels/cpu/native_expert.cpp:1-3`: "the activation quantizers and the row dot products are
|
||||
ggml-cpu's") and uses its own AVX-2 multi-token kernels above a group size (`:125-142`, default
|
||||
`STRATA_IQ_MT_MIN=2`), whose arithmetic is ggml's "only the order of the float additions differs"
|
||||
(`src/kernels/cpu/iq_avx2.cpp:9-10`).
|
||||
|
||||
The native kernels are compiled with `--use_fast_math` to "match the pinned llama.cpp CUDA arithmetic
|
||||
contract" (`CMakeLists.txt:506-519`); ggml-cuda itself uses `-use_fast_math`
|
||||
(`third_party/llama.cpp/ggml/src/ggml-cuda/CMakeLists.txt:186`).
|
||||
|
||||
The submodule's branch (robertkarl/llama.cpp `UnbiasedStrata`; at the time of these checks the same change was a
|
||||
configure-time patch) carries tool-call parser changes only (`common/parsers/*`, `common/chat-auto-parser-generator.cpp`;
|
||||
UPSTREAM.md "Changes to llama.cpp"). They touch nothing the engines or the reference arithmetic use.
|
||||
|
||||
Both model architectures load at the pin: `qwen35moe` (`src/llama-arch.h:47`, graph
|
||||
`src/models/qwen35moe.cpp`) and `qwen4exp` (`src/llama-arch.h:48`, graph `src/models/qwen4exp.cpp`;
|
||||
`conversion/qwen4exp.py:16-19` names "Qwen/Qwen3.8-Flash-Next"). Q2_0, the pack's down-expert format in 30
|
||||
of 48 layers (`tests/data/native_experts/iq3_xxs.txt`), exists in the pin as `GGML_TYPE_Q2_0 = 42`
|
||||
(`ggml/include/ggml.h:432`) with an MMVQ dot (`ggml-cuda/mmvq.cu:43`, `vecdotq.cuh:733`) and an MMQ case
|
||||
(`ggml-cuda/mmq.cu:13-14`).
|
||||
|
||||
### 1.2 Configuration A: `strata` with the Flash-Next pack
|
||||
|
||||
A native pack never runs a per-token loop: every decode step is a verify window of T tokens through
|
||||
`Verifier::run` (`src/program/generate.cpp:15624`; `:6562` "a native pack runs verify windows only"), and
|
||||
`--spec 4` becomes a window of 6 because the suffix drafter adds 2 (`generate.cpp:2989-2992`; `--suffix-draft 0`
|
||||
keeps 4). The emitted token after each window row is the head's argmax; a draft is kept while it equals that
|
||||
argmax (`generate.cpp:15653`: `while (a < T - 1 && window[a + 1] == outv[a]) ++a;`), so the drafter decides
|
||||
which tokens get checked, never which are emitted (`include/strata/core/verify.hpp:1-8`,
|
||||
`include/strata/core/mtp.hpp:13-14`). The pack mixes formats: gate/up IQ2_XXS (9 layers), IQ2_XS (10),
|
||||
IQ3_XXS (6), IQ3_S (13), IQ2_S (10); down IQ4_NL (18) or Q2_0 (30). That is the checked-in layout
|
||||
`tests/data/native_experts/iq3_xxs.txt` (48 lines), and it matches the GGUF itself: the header of the local copy
|
||||
of shard 1 (`/Volumes/models/Qwen3.8-Flash-Next-GSQ-RCO/IQ3_XXS/`, sha256 `219ea929…` in its `SHA256SUMS`, read
|
||||
with the vendored `gguf-py`) gives the same gate/up and down type for every one of the 48 layers. The pod runs
|
||||
the same bytes (`server-command.sh:3-4`) and the pack keeps every quantized tensor in GGUF form
|
||||
(`tools/iq_pack.py`), so the pod pack's `native_experts.txt` is expected to match; one `diff` in step 12 records
|
||||
it. The rest of the file, from the same header: `general.architecture` is `qwen4exp`, 1,223 tensors in shard 1
|
||||
and one in shard 2 (`per_layer_token_embd.weight`, IQ4_NL, the PLE table); `token_embd` IQ3_S; routers,
|
||||
hyper-connection and indexer projections BF16 with F32 norms; attention and SSM projections a per-layer mix of
|
||||
IQ3_S, IQ4_XS, Q4_K, Q5_K, Q6_K; shared-expert gate/up IQ3_S, IQ4_XS, Q4_K, Q5_K, Q6_K and down IQ4_NL or Q2_0;
|
||||
`output.weight` Q5_K; `ple_conv1d` F16; no tensor named `mtp`, `nextn` or `draft`.
|
||||
|
||||
| Stage | `strata` path | llama.cpp path at the pin | Relation |
|
||||
| --- | --- | --- | --- |
|
||||
| Token embedding | Gather from the pack's embedding in mapped host memory (`engine-info.txt`: "token embedding IQ3_S"), `src/core/verify.cpp:1096-1099`, `src/core/native_head.cpp:206-210` | `get_rows` over the GGUF `token_embd` (IQ3_S in the file) | Same codebooks (`ggml-common.h`); the file's and the engine's embedding type agree (IQ3_S in both the header and `engine-info.txt`) |
|
||||
| Hyper-connections (4 residual streams, `include/strata/core/geometry.hpp:27`) | `fused_gr_read_multi`, `src/core/verify.cpp:1248` (attention and FFN halves; `fused_gr_read_persist` `:1247` under `STRATA_HC_PERSIST=1`), output mixer `:2123-2156`; the per-token `gr_read` in `src/core/layer.cpp` belongs to the non-native loop, which a native pack never runs | `src/models/qwen4exp.cpp` ("hyper-connections in place of every layer norm", `conversion/qwen4exp.py:19-24`); the lines were not located in this pass | Own kernels on both sides |
|
||||
| Gated DeltaNet layers | Decode: `gdn_ab_multi` `src/core/verify.cpp:1311`, `:1372`, `gdn_conv_ab_multi` `:1359`, `gdn_step_norm_multi` `:1412`; `include/strata/kernels/verify_kernels.hpp:1-74` says they are bitwise the `fused_gdn_*` single-token kernels. Prompt: `gdn_recurrence`, `src/prefill/prefill.cpp:3036` to `src/prefill/kernels.cu:2554` | `ggml_gated_delta_net` (`ggml/include/ggml.h:2652`), CUDA `ggml-cuda/gated_delta_net.cu:4-30`, all f32; fused on by force, `src/llama-context.cpp:232-234`; used at `src/models/qwen4exp.cpp:970` | Same recurrence in f32; different kernels and reduction order |
|
||||
| QSA attention, decode | Norm and rope `src/core/verify.cpp:1451`; block scores and top-k `:1545-1548`; `qsa_kv_resolve` `:1767` (`src/core/layer.cpp:954`); `qsa_decode_attn_batch` `:1737`, `:1777`; output gate `:1782` | `build_qsa_top_k` `src/models/qwen4exp.cpp:542` (`ggml_top_k` `:684`), `build_attn_qsa` `:693-764` unmasks the chosen cells and runs the dense `build_attn_mha`; flash attention kernel choice `ggml-cuda/fattn.cu:529-704` | Same selection rule in different code; attention over the same cells with different kernels |
|
||||
| QSA attention, prompt | `qsa_prompt_attn_batch`, `src/prefill/prefill.cpp:3259-3270`, tensor cores, "not bitwise equal" to the old path (`include/strata/kernels/qsa_prompt_attn.hpp:1-18`); selection `:3150-3160` (3xTF32) | MMA_F16 flash attention for a batch on sm_86 (`fattn.cu:626-652`) | Both tensor-core fp16 with f32 accumulation |
|
||||
| KV cache | `--kv int8`: int8 codes, one fp16 scale per 64 values (`generate.cpp:805-806`, `include/strata/kernels/kv_q8.hpp:1-12`), appended by `kv_append_q8_steps` `src/core/verify.cpp:1641-1643` (per token `:1662`); `--kv-resident 32768`: pages streamed from a pinned host copy, `kv_stream_resolve` inside `qsa_kv_resolve` (`src/core/layer.cpp:954-957`), `include/strata/kernels/kv_stream.hpp:1-20` | f16 by default (`common/arg.cpp:2434-2458`); q8_0 (one fp16 scale per 32 values, `ggml-common.h:255`) has a compiled vector kernel (`ggml/CMakeLists.txt:207`, `fattn.cu:470`) | Different int8 formats, so int8 KV has no llama.cpp twin. Streaming has none either; `kv_stream.hpp:8-9` says readers are unchanged, so streamed must equal resident bitwise |
|
||||
| Router, top-10 of 512 | `bf16_gemv_fp32_mmvf_multi` + `native_router_top10_multi`, `src/core/verify.cpp:1830-1832` | Router `mul_mat` + top-k in the graph (`src/models/qwen4exp.cpp`; line not located) | BF16 router weights both sides; f32 logits |
|
||||
| Routed experts, decode, VRAM tier | `native_expert_grouped`, `src/core/verify.cpp:1962-1971` to `src/kernels/cuda/iq_kernels.cu:4291-4480`; dots `vec_dot_iq3_xxs_q8_1` `iq_kernels.cu:191` and the other formats under `STRATA_GU_FMTS`/`STRATA_D_FMTS` `:647-655`; activations q8_1 by `quantize_q8_1_rows` `verify.cpp:1918-1920` | `ggml_cuda_mul_mat_id` `ggml-cuda/ggml-cuda.cu:1924-1930`: MMVQ with ids while n_tokens is at most the per-type cap (`mmvq.cu:197-207`: IQ3_XXS 7, IQ3_S 6, IQ2_S 7, Q2_0 8); dots `vecdotq.cuh:1172` (iq3_xxs), `:733` (q2_0); `quantize_q8_1` `quantize.cu:54-100` | Transcribed dots, same q8_1 activation contract; expert sums combined in strata's order |
|
||||
| Routed experts, decode, PCIe tier | The same GPU kernels on staged copies once the copy engine lands them (`verify.cpp:1960`); share of misses `(nmiss * pcie_num) >> 8`, `src/core/expert_source.cpp:3875` | n/a | Placement only; same arithmetic as the VRAM tier |
|
||||
| Routed experts, decode, CPU tier | `src/kernels/cpu/pool.cpp:732`, `:742` to `native_gu_rows` / `native_down_rows` `src/kernels/cpu/native_expert.cpp:144-248`, `:250-305`: ggml-cpu `vec_dot` for a group below `STRATA_IQ_MT_MIN` (default 2, `:125-142`), the AVX-2 multi-token kernels (`src/kernels/cpu/iq_avx2.cpp`) otherwise; activations Q8_K (`:113-123`) | CPU backend: `ggml_vec_dot_iq3_xxs_q8_K` `ggml/src/ggml-cpu/arch/x86/quants.c:3260`, `quantize_row_q8_K` `:505` (ref `ggml/src/ggml-quants.c:2768`, blocks of 256) | ggml's own code for a lone token; Q8_K (256-block) activations, so a CPU expert rounds like llama.cpp's CPU backend and unlike the GPU tier |
|
||||
| Tail skip, adaptive tier | A missed expert that every token of a window ranks 7th or lower is dropped, `src/core/expert_source.cpp:3850-3869`, default 7 in serve `generate.cpp:9375-9420`; the tier re-places experts every 4 rounds (`generate.cpp:677`, off when 0 `:9423`); `pcie_frac` refined in the first windows when not given (`:671-672`) | n/a | Approximations; section 1.4 says how to hold them |
|
||||
| Shared expert | `shared_expert_multi`, `src/core/verify.cpp:1917` (`src/kernels/cuda/shared_expert.cu`) | Dense `mul_mat` on the `shexp` tensors; MMVQ at one token | Gate/up IQ3_S, IQ4_XS, Q4_K, Q5_K or Q6_K and down IQ4_NL or Q2_0 by layer (shard-1 header); the K-quant ones take `native_mmvq`'s per-type kernels, so `mmvq_multi_parity` and `iq_parity` cover them |
|
||||
| Dense projections, decode | BF16: `bf16_gemv_fp32_mmvf_multi` `src/core/verify.cpp:1163`; quantized: `native_quantize_q8_1` + `native_mmvq` `:1166-1167` (`native_mmvq.cu:3110-3130`) | `mmvf` for BF16 (`ggml-cuda.cu:1844-1848`), MMVQ for quantized (`:1868-1870`) | Transcribed |
|
||||
| Dense projections, prompt | `src/prefill/gemm.cu:1042-1045` (BF16 `cublasGemmEx`), `:1109-1131` (dequantize to FP16, FP32 compute) | MMQ for quantized batches (`ggml-cuda.cu:1872-1874`, `mmq.cu:319`), cuBLAS for floats (`:1876`, `:1622-1670`) | Different: strata dequantizes quantized projections to FP16 for the prompt, llama.cpp runs int8 MMQ |
|
||||
| Routed experts, prompt | `src/prefill/prefill.cpp:3366-3383` picks MMQ (fused int8 is off by default on CUDA, `src/prefill/moe_fused_iq.cu:1386-1407`); `src/prefill/moe_mmq.cu:404-460` calls `mul_mat_q_case<T>` (`:442`), activations `quantize_scatter_mmq_q8_1_cuda` (`:384-395`, `quantize.cu:606`); CPU share of the chunk `prefill.cpp:185-215` | `ggml_cuda_mul_mat_id` MMQ branch `ggml-cuda.cu:1940-1943`, same instances, scatter quantizer `mmq.cu:233` | Same ggml kernel and quantizer; tile and stream-k choice may differ with the row count (`mmq.cuh:173`, `:346-351`) |
|
||||
| PLE (n-gram embeddings, one layer) | Rows on the host `src/core/verify.cpp:2682-2685`; key and value projections `:1152-1170`; post-ops and `ple_block` `:1194-1219`; needs `--ple-gguf` or "LAYER 1's PLE IS SILENTLY SKIPPED" (`generate.cpp:943`) | `src/models/qwen4exp.cpp` ("PLE n-gram hash embeddings on a single layer", `conversion/qwen4exp.py:19-24`); line not located | Own kernels both sides; a missing shard 2 is a silent difference |
|
||||
| Head and argmax | Native Q5_K head (`generate.cpp:838`), `native_mmvq` over the window's rows `src/core/verify.cpp:2177`; greedy `argmax_rows` `:2187` (or `sample_tokens` with `greedy = true`, `:2188-2193`), ties to the lowest index (`src/kernels/cuda/sampler.cu:114-118`) | Output `mul_mat` (MMVQ at one token, `vec_dot_q5_K_q8_1` `vecdotq.cuh:968`); logits f32 (`src/llama-context.h:295`); greedy keeps the first argmax (`src/llama-sampler.cpp:270-285`) | Same tie rule |
|
||||
| MTP draft layer | `src/core/mtp.cpp`: shared expert `:1099`, router `:1112-1116`, argmax `:1216`; weights Q8_0 dense and q2_0 experts from `tools/mtp_rt.py` and `tools/mtp_pack.py` (not the GGUF's: the converter drops the head, `conversion/qwen4exp.py:28-30`) | None for `qwen4exp` (`src/models/models.h:2382-2420` has no MTP graph) | Drafts only; the exact-match acceptance makes it invisible in the ids |
|
||||
|
||||
### 1.3 Configuration B: `strata-poly` with Qwen3.6-35B-A3B
|
||||
|
||||
Dispatch is one function, `Engine::lin()` (`src/poly/engine.cpp:2072-2104`): a quantized matrix with 32 rows
|
||||
or more (`kStageRows`, `src/poly/runtime.hpp:29`) goes to ggml's MMQ through `Mmq::quantize` and `mmq_->mul`
|
||||
when `Mmq::fits` (`src/poly/mmq.cu:40-59`); fewer rows go to `native_quantize_q8_1` + `native_mmvq`, at most 8
|
||||
columns per launch, each column bitwise the single-column result (`g_multi_exact = true`,
|
||||
`src/kernels/cuda/native_mmvq.cu:1342`). F32 and BF16 matrices use `gemv_kernel` below 32 rows and
|
||||
`gemm_small_kernel` or `cublasSgemm` above (`src/poly/kernels.cu:2179-2209`). Tensors stay in GGUF form when
|
||||
`native_mmvq` supports the type (`engine.cpp:1101-1102`, list `native_mmvq.cu:3074-3079`); F16 is converted
|
||||
to BF16 (`:1103`, `:1126-1128`). The UD-Q3_K_M file is not on this Mac, so its per-tensor types were not read;
|
||||
the local UD-IQ4_XS (no draft block, `docs/MODEL-FILES.md:15`) has attention, shared-expert and embedding
|
||||
tensors Q8_0, routers and norms F32, output Q6_K, gate/up experts IQ3_S, down experts IQ4_XS in 37 layers and
|
||||
Q6_K in 3. Step 12 records the UD-Q3_K_M types from the pod file with `tools/strata_inspect.py` before the run.
|
||||
|
||||
| Stage | `strata-poly` path | llama.cpp path at the pin | Relation |
|
||||
| --- | --- | --- | --- |
|
||||
| Token embedding | One row on the host with ggml `to_float`, `src/poly/engine.cpp:2021-2025` | `get_rows` | Same dequantizer |
|
||||
| Norm + activation quantization | `rms_norm_kernel` then `native_quantize_q8_1`, `src/poly/qwen35.cpp:456-465` (`kernels.cu:159`) | `rms_norm` f32, `quantize_q8_1` inside MMVQ (`quantize.cu:54-100`) | Same q8_1 contract |
|
||||
| Gated DeltaNet (30 of 40 layers) | `qwen35.cpp:279-299`; `conv4_silu` `kernels.cu:2673-2683`, `gdn_step` `:2699-2722`, f32 state (`engine.cpp:1798-1801`) | `ggml_gated_delta_net` at `src/models/qwen35moe.cpp:472`, `gated_delta_net.cu` f32 | Same recurrence, different kernels |
|
||||
| Full attention (10 of 40, head dim 256, 8 query heads per KV head) | Decode `attend()` `kernels.cu:2449-2550` (`attn_score_reg_kernel<8,2,q8>`, softmax, value kernels); prompt `attend_batch()` `:2568-2657`: cuBLAS fp16 GEMMs with f32 accumulation, online softmax with half weights | Flash attention: VEC at one token, MMA_F16 for a batch on sm_86 (`fattn.cu:626-652`) | Different kernels; both fp16 products, f32 sums |
|
||||
| KV cache | fp16 by default (`src/poly/engine.hpp:39-40`); `--kv q8_0` opt-in, int8 codes + one fp16 scale per 32 values (`qwen35.cpp:354-368`, `kernels.cu:516-584`), qwen35moe only (`engine.cpp:989-990`); under q8 the prompt path dequantizes blocks to fp16 first (`kernels.cu:2626-2631`) | f16 default; q8_0 kernels compiled | Same block size as llama.cpp's q8_0; byte layout equality not verified |
|
||||
| Router, top-8 of 256 | `lin(gate_inp)` F32 (`engine.cpp:2106`); `route_rows` softmax, top-8, renormalized (`kernels.cu:907`, `:2419-2432`; host copy `qwen35.cpp:478-496`) | `build_moe_ffn` in `src/llama-graph.cpp` (line not located) | Same rule; `poly_route_test` holds the GPU to the host copy |
|
||||
| Routed experts, decode, every expert in VRAM (the pod) | `moe_card()` `engine.cpp:2264-2285`: `native_mmvq_ids` gate/up, `swiglu_clamp_rows`, `native_quantize_q8_1`, `native_mmvq_ids` down, `moe_sum`; whole pass one CUDA graph when every layer is card-routed (`:2817-2839`) | `mul_mat_id` MMVQ with ids (`ggml-cuda.cu:1924-1930`; caps `mmvq.cu:197-207`: Q3_K 5, IQ3_S 6, IQ4_XS 8, Q6_K 8); fused gate+up MMVQ (`:1794-1821`); dots `vecdotq.cuh:891` (q3_K), `:918` (q4_K), `:1019` (q6_K), `:1357` (iq4_xs) | Transcribed dots; strata-poly sums experts in its own order |
|
||||
| Routed experts, decode, some experts on the CPU (smaller cards) | `moe()` `engine.cpp:2119-2234`; `src/poly/cpu_experts.cpp:163-229` through ggml-cpu `vec_dot` with Q8_K activations; `--tail-skip` drops low-ranked missing experts (`engine.cpp:2158-2169`) | CPU backend `arch/x86/quants.c:1766` (q3_K), `:4004` (iq4_xs) | Not exercised on 24 GB; relevant to the 1080 Ti rung |
|
||||
| Routed experts, prompt (32 rows or more) | `moe_rows()` `engine.cpp:2323-2606`: `Mmq::quantize` (ggml `quantize_mmq_q8_1_cuda`, `src/poly/mmq.cu:66-81`) and `mmq_->mul` (`:83-119`, `mul_mat_q_case<T>`), gate/up `:2528-2530`, down `:2536-2538` | `mul_mat_id` MMQ branch (`ggml-cuda.cu:1940-1943`) with the scatter quantizer (`quantize.cu:606`) | Same kernel templates; poly fills `mmq_args` itself (`mmq.cuh:1378-1386`) and picks the tile from the largest row count (`mmq.cu:40-59`) |
|
||||
| Prompts shorter than 32 tokens, and every prompt's last token | Decode kernels (`src/poly/main.cpp:399-414`) | One batch through MMVQ or MMQ by size | A chunk boundary moves which kernel a token meets (section 1.4) |
|
||||
| Shared expert | `qwen35.cpp:504-511`: `lin` on Q8_0 gate/up (`native_q8_0_mmvq` or MMQ q8_0), `swiglu_clamp`, `lin` down, sigmoid gate | `build_moe_ffn` shared path; `vec_dot_q8_0_q8_1` `vecdotq.cuh:851` | Same dots |
|
||||
| Dense attention and SSM projections (Q8_0 in the local file) | `native_q8_0_mmvq` / MMQ q8_0 through `lin()` | MMVQ / MMQ q8_0 | Same dots |
|
||||
| Head and argmax | `lin(output_)` always one token in `eval` (`engine.cpp:3047`), up to 8 in a window (`:3339`), Q6_K via `native_mmvq`; `most_likely` on the host, first index of the largest logit (`engine.cpp:3493-3496`, `main.cpp:98`) | `vec_dot_q6_K_q8_1`; first argmax (`llama-sampler.cpp:270-285`) | Same tie rule |
|
||||
| Draft block (MTP, 1 extra layer) | Found by `nextn_predict_layers` (`engine.cpp:887-901`), loaded by `load_drafter` (`:1753-1765`); `draft_input` `:3411-3433`, `block_attend` `:3451-3470` with the head over the first 131,072 rows (`src/poly/qwen35.hpp:28-30`); up to 3 guesses (`main.cpp:66-68`), suffix lookup up to the window (`:70-72`, `--lookup 3` default `:1152`); acceptance `main.cpp:516-529`: kept while `pick(logits_of(right)) == w[right+1]`, `pick` = `most_likely` at temperature 0 | `--spec-type draft-mtp` loads and runs the block (`common/arg.cpp:4236-4244`, `src/models/qwen35moe.cpp:106-138`, `:550`); without it the block's tensors are skipped (`qwen35moe.cpp:41`) | The reference runs without a draft; `engine.hpp:226-229` claims a kept token's logits equal `eval()`'s, so draft on must equal draft off bitwise (T0) |
|
||||
| Sampling | Defaults greedy (`main.cpp:79-86`, `:98`); `GEN` keys `:541-582`; the front end sends no keys at temperature 0 (`frontend/strata_context.cpp:330-343`) | `--temp 0` first argmax | Same |
|
||||
|
||||
### 1.4 Settings on the pod run lines that move the output
|
||||
|
||||
Each of these changes bits or ids on purpose. A comparison holds them still, and the table says how. A row marked
|
||||
"inert on 24 GB" is held anyway so the same command works on a smaller card.
|
||||
|
||||
| Engine | Setting | Default on the pod | Effect | Hold for a check |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| A | `STRATA_ROUTE_TAIL_SKIP` | 7 (serve, CUDA; `generate.cpp:9375-9420`) | Drops low-ranked missed experts, KL ~0.003-0.006 (`:9376-9377`) | `STRATA_ROUTE_TAIL_SKIP=0` |
|
||||
| A | `STRATA_PREFILL_CPU_SHARE` | auto for chunks under 1024 tokens (`engine-info.txt`; `generate.cpp:7812-7840`, `src/prefill/prefill.cpp:185-215`) | CPU computes some prompt experts with Q8_K rounding, mean KL ~0.004 (`engine-info.txt`) | `STRATA_PREFILL_CPU_SHARE=0`; `docs/DETAILS.md:1989` records first logits byte-identical across chunk splits with it off |
|
||||
| A | adaptive expert tier | every 4 rounds, 96 swaps (`generate.cpp:677`, `:707`) | Moves experts between GPU and CPU tiers, which round differently | `--adapt-every 0` (`:9423` disables the tier at 0; upstream used `--adapt-every 100000`, `docs/UNSLOTH_Q4.md:198`) |
|
||||
| A | `pcie_frac` | 0.55 then refined (`generate.cpp:671-672`) | Same arithmetic as the VRAM tier, but the split changes which experts are GPU-rounded | `--pcie-frac 0.55` explicitly, so it is not refined |
|
||||
| A | `STRATA_IQ_MT_MIN` | 2 (`native_expert.cpp:131`) | A CPU expert's rounding depends on how many window tokens share it (`docs/DETAILS.md:99-104`) | `STRATA_IQ_MT_MIN=1` |
|
||||
| A | suffix drafter | on, widens `--spec 4` to 6 (`generate.cpp:2989-2992`) | Changes window composition only | Leave on for the "draft on" arm; `--suffix-draft 0 --spec 4` is the T=4 arm |
|
||||
| A | prompt cache | 6 checkpoints (`generate.cpp:708-711`) | A resumed prefix carries the earlier run's prompt-path bits | `--prompt-cache 0` and one engine process per sequence |
|
||||
| A | `--kv int8`, `--kv-resident` | int8, 32768 | Lossy format; streaming claimed exact | Ladder: `--kv fp16` and resident first, then int8, then streamed (section 3.4) |
|
||||
| B | `--tail-skip 6` | inert on 24 GB (every expert resident) | On a smaller card drops missed experts | `--tail-skip 0` |
|
||||
| B | draft block and suffix lookup | on, window 8 (`engine.cpp:1687`), lookup 3 | Window composition only, claimed bitwise inert | Base arm `--no-draft --lookup 0 --window 1`; second arm defaults |
|
||||
| B | prompt cache | 6 checkpoints; a prompt that extends the engine's sequence resumes even at 0 (`src/poly/conversations.hpp:234`) | Which tokens share a chunk, so MMQ versus MMVQ and `attend_batch` versus `attend` (`conversations.hpp:106-127`, `main.cpp:399-414`) | One `--tokens` process per sequence, same `--prompt-batch` both arms |
|
||||
| B | expert placement | all resident on 24 GB | On a smaller card, `STRATA_FREEZE_EXPERTS=1` holds the split (`main.cpp:1094-1096`) | Set it anyway |
|
||||
| B | `--kv q8_0` | off | Lossy format | Ladder as for A |
|
||||
|
||||
## 2. Upstream's parity and bench programs
|
||||
|
||||
### 2.1 How they are built, and what cannot be
|
||||
|
||||
- `STRATA_BUILD_TESTS` defaults on only when both `tests/CMakeLists.txt` and `bench/micro` exist
|
||||
(`CMakeLists.txt:107-111`); `tests/CMakeLists.txt` is absent in this tree and upstream's, and `bench/micro`
|
||||
holds one file. `make build` configures with `-DSTRATA_BUILD_TESTS=OFF` (`Makefile:57`) and builds only
|
||||
`strata strata-poly strata_kq unbiased-strata` (`Makefile:49`, `:63`). Step 12 passes
|
||||
`CMAKE_EXTRA=-DSTRATA_BUILD_TESTS=ON` (`Makefile:60`) and names the test targets to `cmake --build`.
|
||||
- Most GPU parity programs sit inside `if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP)` (`CMakeLists.txt:320`)
|
||||
at `:850-1234` and are not gated by `STRATA_BUILD_TESTS`. Settled by reading the nesting: between `:320` and
|
||||
its `endif()` at `:1297` the only conditions around `:850-1234` are `STRATA_ENABLE_CUDA` and
|
||||
`STRATA_HIP_GFX906` (`:909`, `:921`, `:937`, `:953`, `:1011`, `:1025`, `:1063`); the first
|
||||
`STRATA_BUILD_TESTS` gate after `:850` is `:1237`. `enable_testing()` at `:589` sits inside
|
||||
`if(EXISTS tests/core/file_expert_source_test.cpp)` (`:588`), and that file exists. So the normal `make build`
|
||||
configure defines these targets; they are not built because `make build` names only its four targets.
|
||||
- The CUDA oracle block (`CMakeLists.txt:527-549`) cannot build: its 16 sources
|
||||
`bench/micro/native_*_parity.cpp` do not exist in either tree, so the one set of tests that would hold the
|
||||
`native_*` kernels to a pinned llama.cpp CUDA build (`:537-543`, `--selftest` at `:544`) is unavailable.
|
||||
Setting `STRATA_ORACLE_SOURCE_DIR` fails the configure on the missing files.
|
||||
- Also missing sources, skipped by `EXISTS` guards: `native_mmvq_multi` (`:1237-1242`),
|
||||
`graph_registry_test` (`:1273-1278`), `pinned_capture` (`:1285-1290`), `hit_cpu_order_parity`
|
||||
(`:1899-1902`).
|
||||
- `ple_parity` (`:1180-1183`) needs `bench/micro/ple_in.bin` and `ple_out.bin` (`:1178`), absent; it fails
|
||||
by construction, as `docs/Q8_KV.md:151` already records upstream.
|
||||
- `iq_parity` is registered only when a python3 with numpy is found (`:870-905`); the fixture generator is
|
||||
`tools/iq_fixture.py` over the vendored `gguf-py`, exit 3 (skip) when numpy is missing.
|
||||
- Many fixtures hard-code the old model's width: n_embd 2560, expert width 640
|
||||
(`src/kernels/native_expert_parity.cpp:47`, `tests/cuda/prefill_fused_iq_test.cpp:41`,
|
||||
`prefill_mmq_kquant_test` 1280x2560 / 2560x640). They test the kernels, not Qwen3.6's or Flash-Next's shapes
|
||||
(Flash-Next: `include/strata/core/geometry.hpp:25-49`; Qwen3.6: n_embd 2048, `tools/qwen35/parity.py:24`).
|
||||
- Two scripts that look like gates never fail: `tools/qwen35/parity.py` returns 0 after printing (`:108`),
|
||||
`tools/qwen35/kl.py` states a gate in its docstring ("KL within 1.5x of the floor", `:4`) and returns 0
|
||||
without testing it (`:96-102`); `compare_dumps.py` likewise. Step 12 applies the criteria from their output.
|
||||
|
||||
### 2.2 Programs covering a path in use
|
||||
|
||||
"Registered" means a CTest entry exists; "hand" means the target builds and is run by hand. Times are
|
||||
estimates from the registered timeouts and the fixture sizes, not measurements.
|
||||
|
||||
| Program (source) | Registration | Path covered (section 1) | Compares against | Needs | Time | Pass criterion |
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
| `iq_parity` (`src/kernels/iq_parity.cpp`) | `CMakeLists.txt:897-903` | A decode: GPU dequant and `native_mmvq` for IQ2_XXS, IQ2_XS, IQ2_S, IQ3_XXS, IQ3_S, IQ4_NL, IQ4_XS, Q2_0, Q3_K (`:29`); B decode: Q3_K, IQ4_XS, IQ3_S | gguf-py dequantized synthetic fixture; double-precision product | GPU, python3 + numpy | under a minute | dequant rel L1 < 1e-6, mmvq rel L1 < 2e-2, multi-column bitwise single-column (`:96-99`, `:112`) |
|
||||
| `iq_multi_parity` (`src/kernels/iq_multi_parity.cpp`) | `:950` | A decode: `iq_mmvq`, `native_expert_grouped` new vs old kernels, q8_1 quantizers | The engine's own previous kernels; GPU dequantizer as a gross-error guard | GPU | minutes | memcmp per output, finite, ref rel < 1e-2 (`:146`, `:158`, `:259`) |
|
||||
| `native_grouped_parity` (`src/kernels/native_grouped_parity.cpp`) | `:990` | A decode: grouped expert kernels and fused SwiGLU + q8_1, gate/up {16,17,18,21,22,23,29,42,12,13,8}, down {20,23,42,7,8} | v1 launches | GPU | minutes | bitwise, including rows it must not write (`:10-11`) |
|
||||
| `native_expert_parity` (`src/kernels/native_expert_parity.cpp`) | gated, `:1858-1883`; GGUF mode by hand | A decode: float ref vs CPU path vs GPU grouped path vs dequantizers; AVX-2 IQ3_XXS/IQ3_S/IQ2_S exact singleton vs ggml (`:103-119`) | ggml `to_float` float expert; ggml-cpu `vec_dot` | GPU, CPU; synthetic pairs are K-quant/Q8_0 (not the pack's formats) | 120 s timeout each | CPU and GPU rel L1 < 3e-2 vs float (`:396`); dequant rel < 1e-6; multi vs one memcmp (`:195`, `:199`, `:287`, `:344`) |
|
||||
| `iq_avx2_parity` (`src/kernels/cpu/iq_avx2_parity.cpp`) | gated, `:1550-1551` | A decode, CPU tier: every AVX-2 variant vs scalar, 1..8 tokens, gate/up {16,17,22,18,21,23}, down {20,42} | ggml-cpu `vec_dot` | CPU with AVX-2 (the pod) | minutes | rel <= 1e-5 vs ggml (`:250`); exact singleton memcmp for 16,17,18,21,22 (`:251-268`); multi-token rows bitwise the one-token rows (`:270-284`) |
|
||||
| `q8k_quant_parity` (`src/kernels/cpu/q8k_quant_parity.cpp`) | gated, `:1565-1566` | A CPU tier: Q8_K activation quantizer | ggml `from_float_ref` | CPU | seconds | byte for byte (`:1-4`) |
|
||||
| `prefill_fused_iq_test` (`tests/cuda/prefill_fused_iq_test.cpp`) | gated, `:1717-1720` | A prompt: MMQ for IQ3_XXS/IQ4_NL, IQ3_XXS/Q2_0, IQ4_XS/Q2_0 pairs (`:661-673`), and the fused kernels against it | double product of ggml-dequantized weights | sm_80+ GPU (exit 77 otherwise) | 600 s timeout | fused rms <= 2e-3, worst <= 3e-2 (`:408`); fused <= 1.5x MMQ rms (`:423`, `:631`). Note: MMQ itself is held to no absolute bound here (`:419` bounds the path without MMQ at rms 0.03) |
|
||||
| `prefill_mmq_scatter_test` (`tests/cuda/prefill_mmq_scatter_test.cpp`) | gated, `:1723-1726` | A prompt: scatter quantizer vs per-row | ggml per-row q8_1 bytes | GPU | 120 s | byte diff == 0 (`:86-88`) |
|
||||
| `prefill_mmq_kquant_test` (`tests/cuda/prefill_mmq_kquant_test.cpp`) | gated, `:1737-1741`, `STRATA_MMQ_KQ=1` | `strata` K-quant prompt path (not A, not B) | double product | GPU | 120 s | rel_l2 <= 0.04, max/rms <= 0.35 (`:141`) |
|
||||
| `mmvq_multi_parity` (`src/kernels/mmvq_multi_parity.cpp`) | `:915` | B decode: `native_mmvq` T columns vs T single columns, Q4_K, Q5_K, Q6_K, IQ4_XS, Q8_0 (no Q3_K, `:58-65`) | itself (negative control with exact mode off) | GPU | minutes | 0 differing bits in exact mode; control must differ (`:216-262`) |
|
||||
| `poly_expert_parity` (`src/poly/expert_parity.cpp`) | hand, `:2075-2079`; `poly_expert_parity MODEL.gguf` | B decode and prompt on the real file: `native_mmvq` and `cpu_experts` per (gate/up, down) type pair, experts 0, n/2, n-1; every matrix kind through `native_mmvq` and MMQ on a 40-token batch, 1 MiB of 0xFF past the weights (`:203-274`) | double product over ggml `to_float` (`:41-55`) | GPU, the model file | minutes per file | relative L2 < 0.05 CPU and GPU, two experts in one `native_mmvq_slots` launch bitwise one (`:187-194`); vec and mat < 0.05 (`:275`) |
|
||||
| `poly_route_test` (`src/poly/route_test.cu`) | hand, `:2094` | B router: `route_rows` softmax 256 experts top-8 with norm (`:115`), 4096 random rows with ties | host `route()` | GPU | seconds | picks identical except rounding ties (rel <= 4e-7, `:97`); weights rel < 1e-5 (`:104`) |
|
||||
| `poly_norm_q8_test` (`src/poly/norm_q8_test.cu`) | hand, `:2099` | B norm + q8_1 fused kernel, n includes 2048 | `axpy` + `rms_norm` + `native_quantize_q8_1` | GPU | seconds | bytes equal (`:51-55`) |
|
||||
| `poly_gemm_small_test` (`src/poly/gemm_small_test.cu`) | hand, `:2105` | B router and small F32 projections in a prompt chunk | host `fma` chain | GPU | seconds | memcmp (`:41`) |
|
||||
| `poly_attend_test` (`src/poly/attend_test.cu`) | hand, `:2110` | B attention kernels, but at dim 64, 32 heads, 8 KV heads (`:23`): LFM2's shape, not Qwen3.6's | the engine's other kernels; `attend_batch` vs `attend` | GPU | seconds | <= 1e-5 and bitwise alone vs on-card (`:66-70`); batch <= 4e-3 (`:96`) |
|
||||
| `poly_kv_q8_test` (`src/poly/kv_q8_test.cpp`) | gated, `:2136-2141` | B `--kv q8_0` store | host arithmetic | GPU | seconds | round trip within half_scale + 5e-4·x + 1e-3 (`:87`); codes and scales memcmp (`:139`, `:150`); ring memcmp (`:198`, `:207`) |
|
||||
| `poly_draft_race_test` (`src/poly/draft_race_test.cpp`) | hand, `:2083-2090` | B draft block: repeated reads with the block give the same guesses | run 1 of 8 | GPU, the model file | minutes | guesses equal, probs memcmp, state equal (`:94-100`); **SKIPs (exit 3) with every expert cached (`:84-88`), so it skips on the pod** |
|
||||
| `kv_q8_parity` (`src/kernels/kv_q8_parity.cpp`) | `:1188` | A int8 KV append and gather | host reference; the FP16 path | GPU | seconds | codes and scales bitwise (`:96`); gather bitwise (`:128`); int8 vs fp16 within 0.5 + 2·127/2048 + 1e-3 steps (`:138`) |
|
||||
| `kv_stream_parity` (`src/kernels/kv_stream_parity.cpp`) | `:1194` | A KV streaming: streamed vs resident attention, int8/fp16/q4_0, ring restore | resident path | GPU | seconds | memcmp (`:190`, `:232`) |
|
||||
| `kv_steps_parity`, `kv_window_parity` (`src/kernels/kv_steps_parity.cpp`, `kv_window_parity.cpp`) | `:1107`, `:1201` | A verify window: batched KV appends n = 1..8 and the catch-up window, graph replay, streamed layer | per-cell path | GPU | seconds | every pool byte memcmp (`:45`, `:124`); streamed attention memcmp resident (`:280`), ring (`:285`), slots (`:305`) |
|
||||
| `gdn_parity` (`src/kernels/gdn_parity.cpp`) | `:1038` | A GDN decode: recurrence, conv, norms; multi-token vs fused | `ref/gdn.py` reference; `fused_gdn_*` | GPU | seconds | rel <= 1e-5 (`:202-203`), conv and norms <= 1e-6 (`:299-300`, `:341`, `:374`), multi memcmp (`:451`, `:508`) |
|
||||
| `gdn_rec_parity` (`src/prefill/gdn_rec_parity.cu`) | `:966` | A GDN prompt recurrence (copies of the kernels, `:3-9`, not the live `src/prefill/kernels.cu`) | kh kernels; FP64 | GPU | minutes | bitwise; chunked < 1e-4 of max (`:880`) |
|
||||
| `rope_parity`, `elementwise_parity` (`src/kernels/rope_parity.cpp`, `elementwise_parity.cpp`) | `:1073`, `:1140` | A rope tables and rotation; silu, softplus, rms norm | float64 `ref/qsa.py`; host | GPU | seconds | rotation rel <= 1e-6 (`:147`, `:341`); <= 1e-6 / 1e-7 (`:116`, `:177`, `:290`) |
|
||||
| `qsa_parity`, `qsa_topk_parity`, `qsa_select_bench`, `qsa_prompt_attn_parity` (`src/kernels/qsa_*.cpp`) | `:1155`, `:1162-1164`, `:493-494`, hand `:427-432` | A QSA selection and attention, decode and prompt | host refs; FP64; the warp kernel | GPU | minutes | `qsa_parity` <= 1e-6 .. 1e-3 by stage (`:611`, `:733`, `:1117-1154`); top-k ids identical (`:1159-1161`); prompt attention err <= max(4x old, 1e-6·scale) (`:318`, `:326`) |
|
||||
| `native_multi_parity`, `router_top10_parity`, `route_window_parity` (`src/kernels/native_multi_parity.cpp`, `router_top10_parity.cpp`, `route_window_parity.cpp`) | `:1102`, `:1097`, `:1084` | A router: multi-token top-10 vs per token, combine vs host replay (2560-wide fixtures) | per-token kernels; host | GPU | seconds | memcmp ids and weights (`:85`, `:165`, `:176`); memcmp (`:48`, `:65`) |
|
||||
| `verify_parity`, `spec_verify_parity`, `verify_batch_parity` (`src/kernels/verify_parity.cpp`, `spec_verify_parity.cpp`, `verify_batch_parity.cpp`) | `:1015`, `:1054`, `:1218` | A head argmax and probabilities over vocab 248320 with ties, NaN, -inf; spec sampler; PLE batch snapshot | `sample_tokens` greedy; host `spec_prob.hpp` | GPU | seconds | id equal and p memcmp (`:93`); `out[t] == want` (`:233`); bitwise (`:69-72`) |
|
||||
| `sampler_parity` (`src/kernels/sampler_parity.cpp`) | `:1048`, `:1057`, `:1059` | A sampler chain, greedy fixtures: plain argmax, greedy over fixtures, greedy consumes no random number, penalties, logit bias (`:535-610`, `:645`, `:487-530`) | host reference | GPU | seconds | token equality (`:124`, `:512`, `:1185`, `:1261`); returns 1 on any failure (`:1427-1428`) |
|
||||
| `decode_cluster_parity` (`src/kernels/decode_cluster_parity.cpp`) | `:1067` | A greedy cluster sampler, QSA top-k cluster | one-block kernels | sm_90 (exits 0 below it: a skip on the pod) | seconds | bitwise (`:152-153`, `:230`, `:291`) |
|
||||
| `quantize_act_parity`, `dequant_wide_parity`, `pdl_parity`, `dma_batch_parity`, `batch_rows_parity` | `:1078`, `:932`, `:941`, `:958`, `:1223` | A: Q8_0 activation bytes; wide dequant; PDL; DMA batch; batch rows | host transcription; per-group; plain | GPU | seconds | bytes / bitwise |
|
||||
| `strata-poly --check-batch K` (`src/poly/main.cpp:968-1021`) | built in | B: K prompts alone then together, token by token | itself | GPU, model | minutes | returns 1 on a difference |
|
||||
| `poly_workers_test`, `poly_guesses_test` (`src/poly/workers_test.cpp`; `CMakeLists.txt:131-133`) | `:2125-2128`, `:131-133` | B thread pool; guess policy | fixed counts | CPU | seconds | counts; policy |
|
||||
|
||||
### 2.3 Paths in use that no in-tree program holds to an external reference
|
||||
|
||||
- Configuration A: hyper-connections (`gr_*`, only self-consistency and the old model's `gr_parity` family
|
||||
`:982-1124`), PLE (`ple_parity` cannot run), the QSA decode attention against anything but the engine's own
|
||||
older kernels, the Q5_K native head, the pack's embedding gather, the MTP draft layer's arithmetic (by design
|
||||
unobservable in the ids), MMQ for IQ3_XXS/Q2_0 pairs to an absolute bound (`prefill_fused_iq_test` bounds the
|
||||
fused kernel relative to MMQ), the PCIe tier's staging, the expert combine order, and the whole decode window
|
||||
against a per-token run at the pack's shapes (no T=1 path exists for a native pack, so the T0 claim of
|
||||
`verify.hpp:1-8` is only testable window-against-window).
|
||||
- Configuration B: attention at head dim 256 with 8 heads per group (`poly_attend_test` is dim 64), the GDN
|
||||
kernels (`gdn_parity` tests `src/kernels/cuda/gdn.cu`, not `src/poly/kernels.cu`), `moe_rows()`'s MMQ
|
||||
call with its own `mmq_args` (only `poly_expert_parity`'s 40-token batch at rel 0.05), the draft block's
|
||||
equality claim on 24 GB (`poly_draft_race_test` skips), the Q8_0 KV format's byte layout against llama.cpp's
|
||||
q8_0, `most_likely`, the host router `route()` (only the GPU copy is tested against it), the prompt-cache
|
||||
resume's chunking.
|
||||
- Both: nothing in the tree compares either measured engine's logits with llama.cpp's; `tools/qwen35` targets
|
||||
`strata-q36ref` and `strata-q36` (`src/qwen35/`), which refuse Q3_K experts (`docs/BACKENDS.md:1897`) and
|
||||
are not what the fork runs (`docs/MODEL-FILES.md:13-14`). The fork's own upstream comparison so far is one
|
||||
12-token greedy answer compared as text
|
||||
(`bench/unbiased/2026-10-17-3090pod-flash-next-iq3xxs-step6/upstream-compare/flash-next-upstream-compare/fork-greedy.json`).
|
||||
|
||||
### 2.4 `tools/qwen35` and other scripts
|
||||
|
||||
| Script | What it drives | What it compares | Usable here |
|
||||
| --- | --- | --- | --- |
|
||||
| `tools/qwen35/q36_llama_dump.cpp` | llama.cpp's API over a checkout (`:6-8` build line); `--model --tokens|--prompt --n --ngl --dump-layers --dump-logits --force --dump-full-logits`; the prompt in one `llama_decode` batch, then one token per step (`:130-147`); `--force` feeds the given ids (teacher forcing, `:108-109`, `:142`); `--dump-full-logits` writes f32 `[step][vocab]` (`:140`); `--ngl 0` is the CPU backend with op offload off (`:100`); `STRATA_DUMP_CTX` sets n_ctx and n_batch (default 4096, `:94-99`); `STRATA_DUMP_NGL` for partial offload (`:72-74`); layer outputs captured by name `l_out-N` (`:30-40`) | nothing; it is the reference side | Yes, for both models: it uses no model-specific code; `l_out-N` capture for `qwen4exp` needs a check that the graph names its layer outputs so |
|
||||
| `tools/qwen35/parity.py` | `strata-q36ref` vs the dump, 10 ChatML prompts (`parity_prompts.json`), `--n 64` | greedy ids up to llama.cpp's first `<|im_end|>` (`:75-80`), first divergence with both top-2 margins (`:83-86`), per-layer relative error (`:88-98`) | Not as is: `strata-poly` has no `--dump-logits`/`--dump-layers` file writers (section 3.7); the metric definitions are reused |
|
||||
| `tools/qwen35/kl.py` | the dump at `--ngl 99` and `--ngl 0`, the reference engine `--force`d on llama.cpp's answer (`:62-75`) | full-vocab KL in float64, top-1 agreement, ratio engine/floor (`:85-101`) | The metric and the floor; the driver needs a `--top-probs` reader for `strata-poly` and a `STRATA_LOGPOS` reader for `strata` |
|
||||
| `tools/qwen35/compare_dumps.py`, `q36_lgcmp.py` | two dump directories; two full-logit files | noise floor; max dlogit, KL, top-1 | `q36_lgcmp.py` compares the two llama.cpp runs directly |
|
||||
| `tools/qwen35/q36_harness.py` | `exe --serve` over the engine protocol (`:21-22`, `:56`, `:76`) | n/a | Sends the `GEN` lines for the `strata` side without the removed `serve/` package |
|
||||
| `tools/split_mtp_batch_parity.py` | an HTTP server | texts identical with and without the drafter (`:44-53`) | Text only, and a hard-coded model name (`:35`); superseded by the id comparisons below |
|
||||
| `docs/UNSLOTH_Q4.md:192-228` | `strata --serve` with `STRATA_LOGPOS` + `STRATA_LOGPOS_TOPK=20`, `--short-read` covering the positions, `--adapt-every 100000`; llama.cpp CPU build at `3cf0325` over `llama_get_logits_ith` | argmax agreement, top-5/10 overlap, KL over llama.cpp's top 20 + rest, perplexity; near-tie analysis by llama.cpp's top-2 gap (`:213-221`) | The procedure for configuration A, repeated with a CUDA reference added |
|
||||
| `docs/BACKENDS.md:1022-1051` | `strata-poly` vs llama.cpp, five chat prompts, greedy 64 | same ids (Qwen3.6 UD-Q3_K_M: 64, 64, 40, 64, 64 of 64), largest top-5 probability difference 0.10; "Two correct implementations do not write the same tokens for long" (`:1048`); llama.cpp's own GPU and CPU runs agree 17 of 50, 7 of 64, 15 of 64 on Ornith (`:1051`) | The script is not in the tree; the method is section 3.3 |
|
||||
|
||||
## 3. Teacher-forced greedy comparison against llama.cpp
|
||||
|
||||
### 3.1 The reference side
|
||||
|
||||
- **Build.** `third_party/llama.cpp` at `3cf03257` with `-DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=86`
|
||||
(the pod's card), targets `llama`, `ggml`, `ggml-base`, `ggml-cpu`, `ggml-cuda` and `llama-server`. The pod's
|
||||
existing build is `797de63` (`PLAN.md:57`) and is not used: a different commit is a different reference.
|
||||
- **Program.** `tools/qwen35/q36_llama_dump.cpp` compiled against that build (`:6-8`). It reads the same
|
||||
token ids both engines get (`--tokens`, no tokenizer), runs the prompt as one batch and the answer one token at
|
||||
a time, and with `--force` writes every step's full f32 logits (`--dump-full-logits`). Greedy is its own loop,
|
||||
first index of the maximum (`:133-136`), the same rule as `llama_sampler` (`src/llama-sampler.cpp:270-285`),
|
||||
`strata` (`sampler.cu:116`) and `strata-poly` (`engine.cpp:3493-3496`).
|
||||
- **Two runs per sequence.** `--ngl 99` (GPU: MMQ for the prompt batch, MMVQ for the steps, flash attention
|
||||
f16 KV) and `--ngl 0` (CPU backend: Q8_K activations). KL and top-1 between them is the floor
|
||||
(`tools/qwen35/kl.py:1-8`, `docs/QWEN36.md:33-35`).
|
||||
- **Flash-Next on 24 GB.** The IQ3_XXS shards are 47.0 GB + 28.8 GB (`docs/MODEL-FILES.md:12`): `--ngl 99`
|
||||
does not fit. The CPU run is the primary reference, as in `docs/UNSLOTH_Q4.md:194`; the GPU run uses
|
||||
`STRATA_DUMP_NGL=<n>` with as many whole layers as fit beside the compute buffers. A copy of the dump tool with
|
||||
llama-server's `--override-tensor "exps=CPU"` semantics (`common/arg.cpp:2750`, `tensor_buft_overrides`)
|
||||
would put every dense layer on the GPU and the experts on the CPU; that is a step-12 tool, listed in 5.3.
|
||||
The GSQ-RCO file's tensor set is the pinned loader's: every `create_tensor` of `src/models/qwen4exp.cpp:163-257`
|
||||
(plus the q/k/v, gate/up-experts and `ssm_a` helpers at `:218`, `:234`, `:252`) has its tensor in the shard-1
|
||||
header, and the header holds nothing the loader does not create, so `done_getting_tensors`
|
||||
(`src/llama-model-loader.cpp:1388-1398`, which throws on a count mismatch) is satisfied; the converter drops
|
||||
the MTP head (`conversion/qwen4exp.py:28-30`) and the file has no such tensor. What the header cannot show is
|
||||
op support for the types at load, which the first load shows.
|
||||
- **Qwen3.6 on 24 GB.** 17.1 GB fits with `--ngl 99` at n_ctx 4096. The Unsloth file's draft-block tensors are
|
||||
skipped without `--spec-type draft-mtp` (`src/models/qwen35moe.cpp:41`); the reference runs without a draft.
|
||||
- **Settings.** No chat template (ids are given), no BOS (Qwen adds none, `q36_llama_dump.cpp:12`), n_ctx and
|
||||
n_batch = `STRATA_DUMP_CTX` large enough for prompt + answer, defaults otherwise. If `llama-server` is used
|
||||
for anything, `/completion` with `"prompt": [ids]` passes ids through untouched
|
||||
(`tools/server/server-common.cpp:988-991`), with `"cache_prompt": false`, `"temperature": 0`, `"top_k": 1`
|
||||
set explicitly (GGUF `general.sampling.*` overrides unset values, `common/common.cpp:1217-1267`), `-fit off`.
|
||||
|
||||
### 3.2 Inputs
|
||||
|
||||
Sequences are prompt ids followed by llama.cpp's own greedy answer ids (the GPU run's), so both engines are
|
||||
scored on the same continuation, the one llama.cpp reached (`kl.py:62-64`). Per model:
|
||||
|
||||
| Set | Prompts | Tokens scored | Why |
|
||||
| --- | --- | --- | --- |
|
||||
| Short chat | the 10 of `tools/qwen35/parity_prompts.ids` (20-40 tokens each, ChatML, thinking off) for Qwen3.6; the same texts re-tokenized through the front end for Flash-Next (`llama-tokenize --ids`) | 128 answer tokens each, 1,280 per model | Decode kernels; matches upstream's own sets |
|
||||
| Code and reasoning | 2 prompts: an LRU cache in Python; a reasoning puzzle with thinking on (`docs/UNSLOTH_Q4.md:204-205`) | 400 and 324 | Long answers at low near-tie rates |
|
||||
| Long prompt | 3 documents of 4K, 16K and 31K tokens from this repository's docs (the step-6 smoke texts, `bench/unbiased/*-step6/smoke/`), each followed by its own 256-token greedy continuation | 768 | The prompt path (MMQ, batched attention, chunking) and the tail of the context: KV streaming on A needs more than 20,480 cells (`generate.cpp:811-813`), so the 31K prompt with `--kv-resident 20480` is the streamed case; B's context is 32768 |
|
||||
| Real text | the last 510 tokens of the 16K document, scored as prompt positions | 510 | Positions the model did not write itself (`docs/UNSLOTH_Q4.md:207-208`) |
|
||||
|
||||
Every id list is written to `bench/unbiased/correctness/inputs/` once and used by both engines and both
|
||||
reference runs.
|
||||
|
||||
### 3.3 Procedure for configuration B (`strata-poly`)
|
||||
|
||||
For each sequence, a fresh process per arm:
|
||||
|
||||
```
|
||||
strata-poly --model F --max-context 32768 --tail-skip 0 --no-draft --lookup 0 --window 1 \
|
||||
--tokens <prompt ids> --follow <answer ids> --max-new <len(answer)> --top-probs 20 \
|
||||
2> top.txt > ids.txt
|
||||
```
|
||||
|
||||
- `--follow` writes the given answer in place of the picks (`src/poly/main.cpp:334`, `:463-464`), so every
|
||||
step is scored on llama.cpp's token; `--top-probs 20` prints `top id:prob ...` per step from the same logits
|
||||
(`:927-940`, softmax over the full vocabulary, `%.6g`). `ids.txt` is the engine's own argmax per step.
|
||||
- The first step's distribution comes after the prompt path (chunks of `--prompt-batch` 1024 through MMQ and
|
||||
`attend_batch`, the last token alone through MMVQ and `attend`, `main.cpp:399-414`); every later step comes
|
||||
through the decode kernels. The long-prompt set therefore scores the prompt path at step 0 and the decode path
|
||||
after it.
|
||||
- Arm 2, the same command without `--no-draft --lookup 0 --window 1` (defaults: draft block, lookup 3, window
|
||||
8): `top.txt` must be byte-identical to arm 1's (T0). `--follow` keeps the sequence the same, so only the
|
||||
window composition differs, which `engine.hpp:226-229` says changes nothing.
|
||||
- Arm 3, `--kv q8_0` on arm 1's flags: T2 against arm 1, T1 against llama.cpp.
|
||||
- Arm 4, UD-IQ4_XS, arms 1 and 2 again. Arm 5 (smaller cards only, not the pod): `--vram-reserve-mib` large
|
||||
enough to push a third of the experts to the CPU, `STRATA_FREEZE_EXPERTS=1`, `--tail-skip 0`: scores the
|
||||
`cpu_experts` path (section 1.3).
|
||||
- Scoring: a script (section 5.3) reads `top.txt` and the reference's full logits, and per step writes the
|
||||
argmax agreement, llama.cpp's top-2 gap, top-20 overlap, and KL(llama GPU || engine) over llama.cpp's top 20
|
||||
plus one bucket for the rest (the engine prints 20 probabilities, so the rest is `1 - sum`), the same KL
|
||||
definition as `docs/UNSLOTH_Q4.md:198-200`; and the same for KL(llama GPU || llama CPU) from the two
|
||||
reference files (full vocab, `kl.py:85`).
|
||||
- `--prompt-batch` is left at 1024 in every arm; a run with `--prompt-batch 512` on the 16K document is one
|
||||
extra arm, scored at step 0 only, to show how far the chunk size alone moves the distribution (upstream's
|
||||
figure for `strata-q36`: KL 3.6e-3 to 4.2e-3, `docs/QWEN36.md:172-174`).
|
||||
|
||||
### 3.4 Procedure for configuration A (`strata`)
|
||||
|
||||
`strata` has no `--follow`; its teacher-forced hook is the serve path's `STRATA_LOGPOS` (`generate.cpp:12550-12562`):
|
||||
every token a request reads through the decode windows is scored against the prompt's own next token, and
|
||||
`Verifier::window_logprobs` (`src/core/verify.cpp:3072-3137`) appends one line per position: position, target
|
||||
id, log p(target), top id, log p(top), top == target, log p(`<|im_end|>`), log p(target) without that token, and
|
||||
with `STRATA_LOGPOS_TOPK=20` the 20 likeliest `id:logprob` pairs (`:3122-3134`). So the sequence (prompt + answer)
|
||||
is sent as one prompt, and the positions to score are read through the windows by setting `--short-read` to at
|
||||
least the sequence length (`generate.cpp:909`, `:2524`; default 64, `:748`); positions above `--short-read` go
|
||||
through the batched prompt path and are not scored.
|
||||
|
||||
Per sequence, a fresh engine process (the pod's run line with these changes), driven over the protocol by
|
||||
`tools/qwen35/q36_harness.py` or a 20-line replacement:
|
||||
|
||||
```
|
||||
STRATA_LOGPOS=pos.tsv STRATA_LOGPOS_TOPK=20 STRATA_ROUTE_TAIL_SKIP=0 STRATA_PREFILL_CPU_SHARE=0 STRATA_IQ_MT_MIN=1 \
|
||||
strata --serve --pack P --native S1 --ple-gguf S2 --expert-profile E --expert-cache auto --prefill auto \
|
||||
--mtp M --spec 4 --spec-min-p 0.5 --max-context 65536 --ple-io ram --pool-workers 15 \
|
||||
--prompt-cache 0 --adapt-every 0 --pcie-frac 0.55 --short-read 4096 --kv fp16
|
||||
GEN 1 <prompt ids + answer ids>
|
||||
```
|
||||
|
||||
- Arm 1 (above): fp16 KV, resident, drafts on. Scores the decode windows on every position of the short sets.
|
||||
`--max-new 1` style requests (`GEN 1`) so nothing free-running is scored.
|
||||
- Arm 2: `--suffix-draft 0` (T=4 windows): T0 against arm 1 on `pos.tsv` (the log-probabilities are printed to
|
||||
9 decimals, `verify.cpp:3119`; equality of those is the check, since the window composition is the only
|
||||
difference and `verify.hpp:1-8` claims per-token arithmetic is the single-token kernel's). If this fails with
|
||||
CPU experts in play even at `STRATA_IQ_MT_MIN=1`, rerun with `--expert-cache` sized so no expert misses
|
||||
(impossible for the whole model on 24 GB) or compare only positions whose experts all hit, from `--dump-routing`
|
||||
(`generate.cpp:864`); otherwise the claim is narrowed to the GPU tiers in the write-up.
|
||||
- Arm 3: `--kv int8`: T2 against arm 1, T1 against llama.cpp.
|
||||
- Arm 4: `--kv int8 --kv-resident 20480` on the 31K sequence with `--short-read 1024` (the last 1,024
|
||||
positions through the windows, the rest through the prompt path): T0 against arm 3 on those positions
|
||||
(`kv_stream.hpp:8-9`: readers unchanged).
|
||||
- Arm 5: the long-prompt set with `--short-read 512`: step-0 and the 510 real-text positions score the prompt
|
||||
path (MMQ experts, FP16 dense GEMMs, tensor-core attention) through the first windows after it. A second run
|
||||
with `--prefill 512` (a chunk the user names is not capped, `generate.cpp:617`) shows the chunk effect, as in
|
||||
`docs/DETAILS.md:1989`.
|
||||
- `STRATA_DUMP_FIRST_LOGITS` (`generate.cpp:14338-14346`) writes each request's first-window fp32 logits: it is
|
||||
the per-request probe when `pos.tsv` is not enough.
|
||||
- Scoring: the same script as 3.3 over `pos.tsv` (log-probabilities, top 20) and the reference files.
|
||||
`STRATA_LOGPOS_EXTRA`'s column is reported, not used in the gate.
|
||||
|
||||
### 3.5 Keeping prompt caching and the draft layer from changing results
|
||||
|
||||
- One process per sequence on both engines, `--prompt-cache 0` on `strata` (every request reads from 0,
|
||||
`generate.cpp:708-709`); on `strata-poly` a `--tokens` run has no earlier sequence to extend
|
||||
(`conversations.hpp:234` is the serve path's exact-extension resume).
|
||||
- Drafts: acceptance is exact match on both engines (`generate.cpp:15653`; `main.cpp:516-529`), and the
|
||||
teacher-forced hooks score the model's logits at every position regardless of what was drafted. The draft
|
||||
arms (B arm 2, A arms 1 vs 2) exist to show the T0 claim rather than to assume it.
|
||||
- The expert tiers on A are frozen (`--adapt-every 0`, fixed `--pcie-frac`, `STRATA_IQ_MT_MIN=1`,
|
||||
`STRATA_ROUTE_TAIL_SKIP=0`), so two runs of one arm are expected to be byte-identical; each arm is run twice
|
||||
on one short sequence to confirm it before the full set.
|
||||
- The front end is not in the loop: it would send `GEN <max_new>` with no sampling keys at temperature 0
|
||||
(`frontend/strata_context.cpp:330-343`), the same request the harness sends, and is covered by
|
||||
`frontend/tests/`.
|
||||
|
||||
### 3.6 Tolerated divergence, and why
|
||||
|
||||
- **Identical ids are not the criterion.** Both engines quantize activations to 8 bits at every matrix
|
||||
(q8_1 on the GPU, Q8_K on the CPU) as llama.cpp does, with different block sums and different reduction orders.
|
||||
Upstream measured llama.cpp against itself, GPU versus CPU, agreeing on 17 of 50, 7 of 64 and 15 of 64 greedy
|
||||
tokens on Ornith (`docs/BACKENDS.md:1051`), and `strata`'s own greedy run against its own teacher-forced rerun
|
||||
differing at 6% of positions (`docs/UNSLOTH_Q4.md:220-221`). A free-running greedy comparison measures where
|
||||
the first near-tie falls. The ids are still recorded (`ids.txt`, `pos.tsv` column 6) and reported in the
|
||||
`docs/BACKENDS.md:1024-1034` style, with the top-2 margins at the first divergence as `parity.py:83-86` prints them.
|
||||
- **T1, argmax at a margin of 0.5 nats.** Upstream's data: at every position where llama.cpp's top-2 gap is
|
||||
0.2 or more on short answers (695 of 695) and 0.5 or more after a 16K prompt (144 of 144, 254 of 254) the
|
||||
argmax agreed (`docs/UNSLOTH_Q4.md:213-217`), and the largest top-5 probability difference `strata-poly` showed
|
||||
against llama.cpp on Qwen3.6 was 0.10 (`docs/BACKENDS.md:1029`). A disagreement at 0.5 nats (a 62/38 split
|
||||
between the two candidates) is outside anything quantization rounding produced in those runs, so one such
|
||||
position is a finding, not noise. The gate is 100% at the margin; below the margin agreement is reported.
|
||||
- **T2, KL within 1.5x of the floor.** `kl.py:4` states the gate upstream intended; `docs/QWEN36.md:37-44`
|
||||
shows ratios of 0.3 to 1.0 on the picture check and `:172-174` ratios near 1.0 for the chunk size. The floor is
|
||||
measured on the same positions in the same run, so it absorbs the model's own near-tie density (the 16K sets
|
||||
have KL 0.035-0.061 against 0.0008-0.0016 for code, `docs/UNSLOTH_Q4.md:204-208`). Configuration A's CPU tier
|
||||
rounds like the CPU reference and its GPU tier like the CUDA reference, so A is expected between the two
|
||||
references; the gate uses the GPU reference as P and the CPU-vs-GPU KL as the floor.
|
||||
- **Lossy options.** int8 KV (A) and Q8_0 KV (B) change values by design (`kv_q8_parity.cpp:138` bounds
|
||||
the per-value step). They are gated the same way, with the engine's own fp16-KV arm in P's place: KL(fp16 arm
|
||||
|| int8 arm) at most 1.5x the floor, and T1 against llama.cpp holding. `docs/Q8_KV.md:40-58` (15 of 15
|
||||
identical 64-token greedy answers for q8_0) and `docs/DETAILS.md:2269` (int8 attention paths at KL 0.0016
|
||||
against a floor of 0.0012) say this is attainable.
|
||||
- **T0.** Byte equality where the engine claims it; no tolerance. A T0 failure that is within T2 is still a
|
||||
failure of the claim and is written up as such.
|
||||
- **Perplexity.** Reported per set (`pos.tsv` column 3 summed) as upstream does, not gated: it moves with
|
||||
near ties and quantization alike.
|
||||
|
||||
### 3.7 Localizing a divergence to a layer or kernel
|
||||
|
||||
Order: cheapest first, each step narrowing the set of kernels that can be wrong.
|
||||
|
||||
1. **Which arm.** The ladder (fp16 KV resident, draft off; then each option) names the option that introduced
|
||||
it. An arm-to-arm T0 failure names the window, KV streaming or the draft block directly.
|
||||
2. **Which tier (A).** `--dump-routing` (`generate.cpp:864`) gives each position's experts; the residency table
|
||||
says which tier computed them. Rerun the sequence with `--pcie-frac 0` (all misses on the CPU) and with
|
||||
`--pcie-frac 1.0` (all misses streamed to the GPU): a difference that follows the tier is in that tier's
|
||||
expert kernels, and `iq_avx2_parity` or `iq_parity` at the pack's exact (gate/up, down) pair is the next
|
||||
check. The `--native-*` toggles (`generate.cpp:822-832`, `:3673-3689`) switch each native kernel family
|
||||
back to the older path one at a time.
|
||||
3. **Which path (B).** `--no-gpu-experts` (`main.cpp:1138`) computes every routed expert with ggml-cpu's
|
||||
`vec_dot` and Q8_K activations, the CPU reference's arithmetic; a divergence that disappears is in the GPU
|
||||
expert kernels (then `poly_expert_parity MODEL.gguf` and `iq_parity` for that type). `--no-graphs`,
|
||||
`--prompt-batch 16` (every token through the decode kernels) and `--kv q8_0` off split the rest.
|
||||
4. **Which layer.** llama.cpp's side dumps every layer output for every position
|
||||
(`q36_llama_dump.cpp --dump-layers`, `[pos][layer][n_embd]` f32, `:111-123`). `strata-q36ref` writes the
|
||||
same format, `strata-poly` does not: `--dump-layers` prints one checksum line per stage (`engine.cpp:2056-2068`;
|
||||
stages `attn_in`, `attn`, `ffn_in`, `ffn`, `out_norm`) and changes the path while doing it (window 1, rows 1,
|
||||
no graphs, host routing: `:1595`, `:1794-1795`, `:2242`). For the prompt path `strata` writes R per layer
|
||||
with `STRATA_PREFILL_DUMP_R` / `_ALL` (`src/prefill/prefill.cpp:4631`, `:4644`); for the decode windows it
|
||||
has state hashes (`STRATA_STATE_HASH`, `generate.cpp:14490`) and window hashes (`--window-hashes`, `:956`),
|
||||
bitwise self-comparison only. A per-layer vector comparison against llama.cpp for `strata-poly` needs a
|
||||
small addition to `Engine::dbg()` that writes the vectors (step-12 decision; listed in 5.3), after which
|
||||
`parity.py:88-98`'s per-layer relative error applies. For Flash-Next the names differ: `qwen4exp` names each
|
||||
layer's output `l_last-N` (`src/models/qwen4exp.cpp:441-442`, "the layer output name that build_cvec and
|
||||
imatrix look for"), and that tensor is the four-stream hyper-connection residual `[n_embd, hc, tokens]`, with
|
||||
the single-stream FFN output as `ffn_out-N` (`:437`). The dump tool matches `l_out-` only
|
||||
(`q36_llama_dump.cpp:33`) and writes rows of `n_embd` (`:111-123`), so for Flash-Next it needs the name and
|
||||
the `hc` dimension (a step-12 edit, 5.3). On the engine side the matching dump is `--dump-layers`, which
|
||||
writes `(n_layers + 1) x hc x n_embd` floats per position (`generate.cpp:6701`) and is bisected against
|
||||
`l_last-<il>` (`:862`); it belongs to the per-token loop, so for a native pack only the prompt-path dumps
|
||||
above apply.
|
||||
5. **Which kernel.** With the layer known, the stage checksums (B) or the `--native-*` toggles and the
|
||||
component parities (A) point at one kernel; the kernel's parity program is run at that layer's exact shape and
|
||||
type, which for most of section 2.2 means editing a fixture size.
|
||||
|
||||
## 4. What a failure means, and the run order
|
||||
|
||||
| Check | A failure means | Action |
|
||||
| --- | --- | --- |
|
||||
| Section 2.1 configure and build of the test targets | The test inventory in 2.2 is not reachable from `make build`; the plan's coverage claims rest on upstream's runs | Fix the build (a fork change under `CMakeLists.txt`) before anything else; a test that cannot build is "uncovered", not "passed" |
|
||||
| Component parities (2.2) at the pack's / file's formats | A kernel in use differs from ggml's arithmetic beyond its own bound, in the fork's build of the same source upstream ships; since the sources are unmodified since the import commit (`UPSTREAM.md:10`), this is a toolchain or arch-flag difference (`CUDA_ARCHS` `61;75;86;89`, `Makefile:13`) or an upstream defect | A SEV-3 ticket with the program's output; the engine's measured numbers stand only under "same output as upstream PolyStrata" until the teacher-forced check passes or fails |
|
||||
| T0 (draft on vs off, window sizes, streaming) | A claimed exact path is not exact; speculation or streaming changes answers | The claim comes out of the README; the lossy option is gated as a lossy one (T2) instead, or turned off in the shipped run lines |
|
||||
| T1 at a margin | A wrong token at a position where the model is not near a tie: a kernel, a format conversion in the pack, a missing PLE shard, a wrong tensor, or a llama.cpp defect | Section 3.7 until one side is named; a divergence in llama.cpp is reported upstream with the ids; the README says nothing beyond "same output as upstream PolyStrata" until resolved (`PLAN.md:319`) |
|
||||
| T2 above 1.5x the floor with T1 holding | Systematic rounding worse than the reference's own CPU-vs-GPU spread: an activation quantizer, a reduction order, or a lossy default still on | Find the arm that raised it; if no arm isolates it, the kernel-level parities at the exact shape |
|
||||
| Reference GPU vs CPU floor itself far above upstream's figures (0.001-0.06 by set) | The reference build is not what upstream measured against (wrong commit, FA off, a type without a compiled kernel) | Fix the reference before judging the engines |
|
||||
|
||||
**Run order.** Each step is skipped by nothing before it failing, but its result is read in the light of it.
|
||||
|
||||
1. Configure with tests on; build the test targets and the pinned llama.cpp CUDA build; build the dump tool.
|
||||
Records which targets configure and build, against the reading in 2.1.
|
||||
2. The component parities whose formats are in use: `iq_parity`, `iq_avx2_parity`, `q8k_quant_parity`,
|
||||
`native_grouped_parity`, `iq_multi_parity`, `mmvq_multi_parity`, `prefill_fused_iq_test`,
|
||||
`prefill_mmq_scatter_test`, `kv_q8_parity`, `kv_stream_parity`, `kv_steps_parity`, `kv_window_parity`,
|
||||
`gdn_parity`, `gdn_rec_parity`, `qsa_parity`, `qsa_topk_parity`, `verify_parity`, `spec_verify_parity`,
|
||||
`sampler_parity`, `native_multi_parity`, `rope_parity`, `elementwise_parity`; for B: `poly_expert_parity`
|
||||
on both files, `poly_route_test`, `poly_norm_q8_test`, `poly_gemm_small_test`, `poly_kv_q8_test`,
|
||||
`poly_attend_test` (recorded as not at Qwen3.6's shape), `poly_draft_race_test` (recorded as SKIP).
|
||||
3. Reference runs for every sequence of 3.2, GPU and CPU, and the floor per set.
|
||||
4. Configuration B, arms 1 to 4 (3.3).
|
||||
5. Configuration A, arms 1 to 5 (3.4).
|
||||
6. `strata-poly --check-batch 4` on the short set (batching, outside the two configurations but one command).
|
||||
7. Write-up: per check a `result.md` with the criterion and the numbers; `docs/MODEL-FILES.md` gets a column.
|
||||
|
||||
Steps 4 and 5 are independent of each other and of step 2, but a step-2 failure at a format in use is the
|
||||
first thing to look at when 4 or 5 fails.
|
||||
|
||||
## 5. Machine time and files per check
|
||||
|
||||
### 5.1 Time on the RTX 3090 pod
|
||||
|
||||
Estimates; nothing was timed. Engine start-up from `engine-info.txt`: `strata` about 2.5 minutes to ready
|
||||
(the pinned 40 GB arena, the profile pre-fill), `strata-poly` 8 s. The reference's CPU run of Flash-Next reads
|
||||
76 GB of shards through the page cache; its speed depends on the pod's RAM, which is not recorded in this tree.
|
||||
|
||||
| Check | Runs | Time each | Total |
|
||||
| --- | --- | --- | --- |
|
||||
| Builds (5.3) | 1 | llama.cpp CUDA build 10-20 min; fork test targets 10-20 min on top of the engine build; dump tool seconds | under 1 h |
|
||||
| Component parities, A set (step 2) | 22 programs | seconds to a few minutes; `prefill_fused_iq_test` up to 10 min by its timeout | about 30 min |
|
||||
| Component parities, B set | 7 programs, `poly_expert_parity` on 2 files | seconds; `poly_expert_parity` minutes per file | 15 min |
|
||||
| Reference, Qwen3.6 | 18 sequences x 2 runs | GPU: prompt in one batch plus 128-256 single steps, under a minute; CPU: a few minutes for the short set, longer for the 16K and 31K prompts (n_batch = `STRATA_DUMP_CTX`) | 1-2 h, mostly the CPU runs of the long prompts |
|
||||
| Reference, Flash-Next | 18 x 2 | CPU: minutes per short sequence, tens of minutes for the long prompts; partial-GPU: similar | 3-5 h |
|
||||
| B arms 1-4 | 4 arms x 18 sequences (+ IQ4_XS: 2 x 18) | 8 s start + seconds per sequence | under 1 h |
|
||||
| A arms 1-5 | 5 arms x 18 sequences | 2.5 min start per process + seconds to a minute per sequence | 4-5 h, dominated by start-up; a `--serve` process reused per arm with `--prompt-cache 0` cuts it to under 1 h if the first repeat shows byte-identical results |
|
||||
| Scoring and write-up | | | 1 h |
|
||||
|
||||
Total: one pod-day, of which the engine time is small and the reference's CPU runs of Flash-Next are the
|
||||
largest block. The two engines never run at the same time as a reference run on the same card.
|
||||
|
||||
### 5.2 Files per check, under `bench/unbiased/correctness/`
|
||||
|
||||
| Path | Content |
|
||||
| --- | --- |
|
||||
| `README.md` | the pod, driver, CUDA, commits of the fork and of llama.cpp, the builds' sha256 |
|
||||
| `inputs/<set>/<seq>.prompt.ids`, `.answer.ids` | the id lists both sides get |
|
||||
| `reference/<model>/<seq>.gpu.full`, `.cpu.full` | f32 `[step][vocab]` from the dump tool, 254 MB each for 256 steps at V = 248,320; kept on the pod, with their sha256 and a derived `.top20.tsv` (ids and log-probabilities) committed |
|
||||
| `reference/<model>/floor.md` | KL and top-1, GPU vs CPU, per set |
|
||||
| `parity/<program>/command.sh`, `stdout.txt`, `stderr.txt`, `result.md` | the component parities, one directory each, with the exit code and the criterion |
|
||||
| `poly/<file>/<arm>/<seq>.top.txt`, `.ids.txt`, `command.sh` | 3.3's outputs |
|
||||
| `strata/<arm>/<seq>.pos.tsv`, `command.sh`, `engine.log` | 3.4's outputs |
|
||||
| `scores/<model>/<arm>/<set>.tsv`, `summary.md` | per position: llama.cpp top-2 gap, argmax equal, top-20 overlap, KL; per set the T1/T2 verdict |
|
||||
| `findings/<n>.md` | one per divergence: first diverging position, the inputs, both sides' top 20, which side is wrong once known |
|
||||
|
||||
### 5.3 What must be built or written, and what is undecided
|
||||
|
||||
- **On the pod:** llama.cpp `3cf03257` with CUDA (the submodule checkout, `-DGGML_CUDA=ON`,
|
||||
`-DCMAKE_CUDA_ARCHITECTURES=86`), the dump tool against it, the fork's test targets
|
||||
(`CMAKE_EXTRA=-DSTRATA_BUILD_TESTS=ON`), python3 with numpy for `iq_parity`'s fixture.
|
||||
- **New scripts (step 12, small):** a scorer reading `top.txt` / `pos.tsv` and the reference `.full` files
|
||||
(the metrics of `kl.py:85-101` and `docs/UNSLOTH_Q4.md:198-200`); a `GEN` sender for `strata --serve` if
|
||||
`tools/qwen35/q36_harness.py` needs more than its current arguments.
|
||||
- **Possible code changes, each a step-12 decision, not assumed here:** (a) a dump-tool variant with tensor
|
||||
overrides so Flash-Next's dense layers run on the GPU while the experts stay on the CPU, and with the capture
|
||||
name `l_last-` and the `hc` dimension for `qwen4exp` (3.7); (b) an `Engine::dbg()` that writes per-layer
|
||||
vectors for `strata-poly`, needed only if a B divergence has to be localized by layer; (c) a `poly_attend_test`
|
||||
case at head dim 256 with 8 heads per group, if the attention is the suspect.
|
||||
- **Settled by reading (2026-10-18), no run needed:** the `:850-1234` programs are defined without
|
||||
`STRATA_BUILD_TESTS` (2.1); `qwen4exp` names its layer outputs `l_last-N`, not `l_out-N` (3.7); the GSQ-RCO
|
||||
shard-1 header carries exactly the tensor set the pinned loader creates and no MTP tensor (3.1); the shard's
|
||||
per-layer expert types equal the checked-in layout `tests/data/native_experts/iq3_xxs.txt` for all 48 layers
|
||||
(1.2).
|
||||
- **Not settleable from this Mac:** the UD-Q3_K_M file's per-tensor types (the file is on the pod only; the
|
||||
local `/Volumes/models/qwen3.6/MTP/Qwen3.6-35B-A3B-UD-IQ4_XS-MTP.gguf` is a 1,067-byte pointer, and
|
||||
`docs/MODEL-FILES.md:14` should say so), the pod pack's `native_experts.txt` (one `diff` against the fixture
|
||||
on the pod), and op support at a real load of either file. Each is the first line of its check's `result.md`.
|
||||
@@ -0,0 +1,135 @@
|
||||
# DeepSeek V4 Flash (`strata-poly`)
|
||||
|
||||
`strata-poly`, the engine that runs GLM 5.3 Flash, also runs DeepSeek V4 Flash: llama.cpp's architecture
|
||||
`deepseek4`, read from Unsloth's GGUF. The server, the web app and the API are the ones the README describes.
|
||||
|
||||
It is early. This project has run it on one machine, with Linux and one NVIDIA card; a user runs it on Windows
|
||||
with a 24 GB card and 128 GB of RAM ([issue 21](https://github.com/VecSzn/PolyStrata/issues/21)).
|
||||
|
||||
## What it was measured on
|
||||
|
||||
| | |
|
||||
| --- | --- |
|
||||
| Graphics card | RTX 5090, 32 GB |
|
||||
| CPU | Xeon Platinum 8470Q, 25 vCPU of it (a cloud machine) |
|
||||
| RAM | 120 GiB |
|
||||
| Built with | CUDA 12.8 |
|
||||
| Model | `DeepSeek-V4-Flash-0731-UD-IQ2_XXS`, three files, 90.9 GB, from [unsloth/DeepSeek-V4-Flash-0731-GGUF](https://huggingface.co/unsloth/DeepSeek-V4-Flash-0731-GGUF) |
|
||||
| Context | 32K |
|
||||
|
||||
| | `strata-poly` | llama.cpp, 10 layers' experts on the card | llama.cpp, every expert on the CPU |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| Writes answers | 48 to 53 tokens/s | 25 to 28 tokens/s | 20 to 21 tokens/s |
|
||||
| Reads a prompt of 3,384 tokens | 1,003 tokens/s | 96 tokens/s | 56 tokens/s |
|
||||
| Reads a prompt of 10,398 tokens | 1,147 tokens/s | | |
|
||||
| Starts | 6 to 7 s with the files in the page cache | | |
|
||||
|
||||
All of it ran on the machine above, with 24 CPU threads. The engine's numbers are with the expert profile it
|
||||
writes as it runs; the first answers after a start without one came at 42 to 43 tokens/s. For llama.cpp a small
|
||||
program drives its library and its own `deepseek4` graph and writes greedy tokens, with the routed experts of the
|
||||
first layers in RAM, as `--n-cpu-moe` keeps them. The experts of ten layers are what its 32 GB card had room for
|
||||
beside the rest of the model at this context. That column is the faster of two runs; the other wrote 24 to 26
|
||||
tokens/s and read the prompt at 72.
|
||||
|
||||
The README's row is PolyStrata's own benchmark through the server, the test every model of this engine gets
|
||||
([BACKENDS.md](BACKENDS.md#a-prompt-of-30000-tokens)), as setup installs the model: a short chat written at 56
|
||||
tokens/s, and a prompt of 29,750 tokens read whole at 1,038 to 1,040, with the first token after 29 s and the
|
||||
answer after it written at 39 to 44: the second and third of three runs, as for the other models. The first, with
|
||||
no expert profile yet, wrote the short chat at 56.5.
|
||||
|
||||
With greedy sampling the engine and llama.cpp write the same tokens until two candidates are nearly tied: 8 of 8,
|
||||
64 of 64 and 10 tokens on three short prompts, 15 of 32 on the prompt of 3,384 tokens and all 32 on the one of
|
||||
10,398. Only the long prompts reach far enough back to use the compressed rows, the indexer's pick and the rows of
|
||||
128 positions, so those agree as well.
|
||||
|
||||
## What you need
|
||||
|
||||
- Linux and an NVIDIA card, RTX 20 or newer. It has run on 32 GB of VRAM only. About 11.5 GB go to the weights,
|
||||
the caches and the buffers before any expert, so setup stops and asks below 13.5 GB.
|
||||
- RAM for the experts the card does not hold. The files are mapped and those experts are read from them while the
|
||||
model answers, so they should stay in the OS file cache: about 62 GB of the 84 GB on a 32 GB card. Setup's
|
||||
estimate for that card is 72 GB of RAM. It has run with 120 GB only.
|
||||
- 91 GB of disk for the three files.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
./setup.sh --family deepseek
|
||||
```
|
||||
|
||||
Setup checks the PC and asks two things: the context, and whether to keep several conversations in RAM. There is
|
||||
one size so far, so it does not ask for one. Then it compiles the engine, downloads the three files, checks their
|
||||
SHA-256 and starts the model. The web app is at `http://127.0.0.1:8080`, and `./setup.sh` starts the model again
|
||||
without asking.
|
||||
|
||||
- You already have the files: `./setup.sh --family deepseek --gguf-dir /folder/with/the/files`, the three files
|
||||
under their names from Unsloth's repository.
|
||||
- The other options are GLM's ([GLM.md](GLM.md#install)).
|
||||
|
||||
On the test machine, with the files already on the disk, this took about four minutes: two for the compile, one and a
|
||||
half for the files' SHA-256.
|
||||
|
||||
Setup writes the run config `strata-dsv4-ud-iq2_xxs.json` and `run-dsv4-ud-iq2_xxs.sh` into the PolyStrata folder.
|
||||
No expert profile is shipped: the engine starts one at the first start and keeps it up to date.
|
||||
|
||||
## Long contexts
|
||||
|
||||
Setup offers contexts up to 128K; `--context` takes up to 1,048,576 (`./setup.sh --family deepseek --context 524288`),
|
||||
as does `--max-context` in the run config. A context token takes 6,880 bytes of VRAM, so on the 32 GB card even
|
||||
512K leaves the expert cache most of its room: 3.4 GB less than at 32K.
|
||||
|
||||
Two prompts made of this repository's documents, with three facts planted at 15%, 50% and 85% of them and three
|
||||
questions after them, through the server with thinking off:
|
||||
|
||||
| Context | Prompt | Read and answered in | Facts found |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| 128K | 116,473 tokens | 174 s | 3 of 3 |
|
||||
| 512K | 487,529 tokens | 1,923 s | 3 of 3 |
|
||||
|
||||
A prompt is read more slowly as it grows. The indexer scores every compressed row of its layers for every token, so
|
||||
its work grows with the square of the prompt, and the layers of 128 positions read more rows too. Near the end of
|
||||
the 487,529-token prompt the engine read about 150 tokens per second.
|
||||
|
||||
## How it differs from the other models
|
||||
|
||||
The engine and its options are GLM's ([GLM.md](GLM.md#how-it-uses-the-card)). What is DeepSeek V4's own:
|
||||
|
||||
- **The attention keeps little per token.** A token reads the last 128 positions in full, and the rest of the
|
||||
conversation as compressed rows: in 21 of the 43 layers one row for every 4 positions, of which an indexer picks
|
||||
the 512 the token reads, and in 20 others one row for every 128 positions, all of which it reads. The first two
|
||||
layers read the last 128 positions only. All 64 heads share one key row, which is also the value. A context token
|
||||
takes 6,880 bytes of VRAM, so a 128K context takes 0.7 GB more than 32K.
|
||||
- **The experts.** 43 layers, each with 256 routed experts of which a token uses 6, and one shared expert.
|
||||
The first three layers pick a token's experts by the token, from a table in the file. On the 32 GB card about
|
||||
2,840 of the 11,008 experts stay in VRAM at a 32K context.
|
||||
- **Four residual streams**, mixed by hyper-connections, as in GLM 5.3 Flash.
|
||||
- **Two layers converted at load.** In Unsloth's file the down experts of layers 26 and 42 are MXFP4, which no
|
||||
kernel here runs on the card. Every MXFP4 value in them is a small integer times a power of two that Q5_0 holds
|
||||
exactly, so the engine converts them once at load into 1.38 GiB of RAM each and runs them like the other layers.
|
||||
Before the conversion those two layers took more of a long prompt's time than the other 41 together.
|
||||
- **Reading a prompt** goes 1,024 tokens at a time, as for GLM. The attention of a batch takes 8 heads of a token
|
||||
at a time, so that the key rows they share are read once for all 8.
|
||||
- **Tool calls** come in DeepSeek's own format, DSML, which the server turns into OpenAI's and Anthropic's tool
|
||||
calls. Thinking is on unless a request turns it off; `"high"` adds the template's own instruction to think
|
||||
thoroughly.
|
||||
|
||||
## What is missing
|
||||
|
||||
- Other sizes in setup: of those in Unsloth's repository it offers only UD-IQ2_XXS. A user with 128 GB of RAM ran
|
||||
two more ([issue 21](https://github.com/VecSzn/PolyStrata/issues/21)).
|
||||
UD-IQ3_XXS (104 GB) wrote at 27 to 31 tokens/s and read 512K tokens 4.6% slower than UD-IQ2_XXS.
|
||||
UD-IQ4_XS (137 GB) is larger than that RAM: the rest is read from the disk as it is needed, and it wrote at 2 to
|
||||
3.4 tokens/s with 0.1.44.1-poly.6. llama.cpp b11706 with the experts on the CPU wrote at 8.6 with the same
|
||||
file, and strata-poly at 1.4 to 2.2 against llama.cpp's 9.5 to 10.6 with UD-Q4_K_XL (155 GB), the same
|
||||
prompt on the same PC. The draft model (dspark) slowed llama.cpp down there, to 2.0 to 4.4 tokens/s.
|
||||
- A way of running a file larger than the RAM that comes near llama.cpp's speed there (above).
|
||||
- Guessing ahead with a draft model. The repository has one for this model (`dspark`, 11 GB), which the engine does
|
||||
not run yet. Guesses still come from text the conversation repeats.
|
||||
- Windows, by this project: setup asks before it installs it there. A user ran UD-IQ2_XXS on Windows 10 with an
|
||||
RTX 5090 D v2 (24 GB) and 128 GB of RAM on the release's ready-made engine ([issue 21](https://github.com/VecSzn/PolyStrata/issues/21)): 29 to 36
|
||||
tokens/s after prompts of up to 10K tokens, 10K tokens read at 688 to 805. With the context set to 262,144,
|
||||
524,288 and 1,048,576 in the run config, one request each of 251,866, 503,920 and 1,008,128 tokens was read at
|
||||
393, 247 and 138 tokens/s, and the three facts planted in each were found.
|
||||
- AMD cards: the engine compiles for them, the model has not been tried on one.
|
||||
- Pictures. The model reads text only.
|
||||
- A faster indexer for long prompts: it runs on the card's ordinary cores, not its tensor cores.
|
||||
@@ -0,0 +1,180 @@
|
||||
# DeepSeek-V4.1-Flash-1017 (`strata-dsv41`)
|
||||
|
||||
DeepSeek-V4.1-Flash-1017 is llama.cpp's architecture `deepseek41`: 40 layers, 384 routed experts in each (6 a token),
|
||||
an n-gram table (Engram) read for every token, and a small draft model (DSpark). Neither of this fork's two engines reads
|
||||
it (`strata-poly` knows `deepseek4`, the V4 Flash of [DEEPSEEK.md](DEEPSEEK.md)), so it runs on a third, upstream
|
||||
Strata's `strata-dsv41` (`src/dsv41`, a port of Project Maya's `maya-ds4`, MIT; `third_party/project-maya/NOTICE.md`),
|
||||
imported unmodified from Strata v0.2.4 ([UPSTREAM.md](../UPSTREAM.md#deepseek-v41-engine-srcdsv41-from-strata-v024)).
|
||||
The server, the API and the fork's rules are the README's: no installer, no download at start, the front end in front.
|
||||
|
||||
It is early. The fork has run it on one machine (below) with the ISTA-DASLab 2.00 bpw set.
|
||||
|
||||
## The files
|
||||
|
||||
ISTA-DASLab's GSQ-RCO sets, [ISTA-DASLab/DeepSeek-V4.1-Flash-1017-GSQ-RCO-GGUF](https://huggingface.co/ISTA-DASLab/DeepSeek-V4.1-Flash-1017-GSQ-RCO-GGUF),
|
||||
revision `cb02422c900df489cea5833e8a92171224059b3c` (the one upstream v0.2.4 pins). Three sets share one Engram file; the
|
||||
drafter is Unsloth's.
|
||||
|
||||
| File | Size | What it is |
|
||||
| --- | ---: | --- |
|
||||
| `DeepSeek-V4.1-Flash-1017-GSQ-RCO-IQ1_M-0000{1..4}-of-00004.gguf` | 120.7 GB | the model at 1.75 bpw (1.69 measured by `--pack-info`: mostly IQ1_S tensors); the set the homelab unit runs since 2026-10-24 06:10 UTC |
|
||||
| `DeepSeek-V4.1-Flash-1017-GSQ-RCO-IQ2_XXS-0000{1..4}-of-00004.gguf` | 138.2 GB | the model at 2.00 bpw, the set first brought up |
|
||||
| `DeepSeek-V4.1-Flash-1017-GSQ-RCO-IQ2_XS-0000{1..4}-of-00004.gguf` | 155.2 GB | the model at 2.25 bpw |
|
||||
| `DeepSeek-V4.1-Flash-Engram-IQ4_NL.gguf` | 110.6 GB | the 4-bit Engram table, one file for all three sets; a few rows are read from it for every token, so it lives on NVMe |
|
||||
| `unsloth/DeepSeek-V4.1-Flash-1017-GGUF` `DSpark/dspark-DeepSeek-V4.1-Flash-1017-Q8_0.gguf` | 8.0 GB | the DSpark drafter |
|
||||
| `unsloth/DeepSeek-V4.1-Flash-1017-GGUF` `UD-Q8_K_XL/...-00001-of-00009.gguf` | 5.8 MB | metadata only: `pack_gguf.py --engram-meta` reads the Engram tensor shapes from it (its first shard is the header and nothing else) |
|
||||
|
||||
2.00 bpw: 138 + 111 + 8 = 257 GB on the disk the engine reads from. Upstream's quality numbers for the sets, from
|
||||
its own measurement (4,995 positions): 2.00 bpw KL 0.170, perplexity +15.5%; 2.25 bpw KL 0.107, +7.3%; 1.75 bpw KL 0.217,
|
||||
+21%, weaker on prose. ISTA-DASLab's card: 98.7% of the base model's task average kept at 2.00.
|
||||
|
||||
SHA-256 of every file is in the repository's `SHA256SUMS`-style listing in the Hugging Face tree; this fork checks each
|
||||
file with `sha256sum -c` before packing (the homelab's copies: `/mnt/ds4/dsv41/{IQ2_XXS,engram}/SHA256SUMS`).
|
||||
|
||||
## Preparing the pack
|
||||
|
||||
`strata-dsv41` reads a pack directory, not the shards: metadata files that point into the shards, the Engram and the
|
||||
drafter. `tools/dsv41/pack_gguf.py` writes it from the files in place (stdlib Python, no copy of the tensors), the plain
|
||||
recipe upstream's installer runs for these sets. Do not add `--skip-tensors` or `--dense-override`: upstream says that
|
||||
packs without an error and answers garbage.
|
||||
|
||||
```
|
||||
python3 tools/dsv41/pack_gguf.py --model /mnt/ds4/dsv41/IQ2_XXS \
|
||||
--shards DeepSeek-V4.1-Flash-1017-GSQ-RCO-IQ2_XXS-0000{1,2,3,4}-of-00004.gguf \
|
||||
--engram /mnt/ds4/dsv41/engram \
|
||||
--engram-meta /mnt/ds4/dsv41/meta/DeepSeek-V4.1-Flash-1017-UD-Q8_K_XL-00001-of-00009.gguf \
|
||||
--dspark-gguf /mnt/ds4/dsv41/dspark/dspark-DeepSeek-V4.1-Flash-1017-Q8_0.gguf \
|
||||
--dspark-noise-token 128799 --dspark-markov-rank 256 \
|
||||
--out /mnt/ds4/dsv41/IQ2_XXS/maya-ds4
|
||||
cp data/dsv41/profile-2.00.bin /mnt/ds4/dsv41/IQ2_XXS/maya-ds4/expert-profile.bin # profile-2.25.bin for IQ2_XS
|
||||
build/bin/strata-dsv41 --pack /mnt/ds4/dsv41/IQ2_XXS/maya-ds4 --pack-info # every file present
|
||||
python3 tools/dsv41/smoke.py --exe build/bin/strata-dsv41 --pack /mnt/ds4/dsv41/IQ2_XXS/maya-ds4 # 16 tokens; must name Paris
|
||||
```
|
||||
|
||||
The hot-expert profile upstream ships (`data/dsv41/profile-2.00.bin`, sha256 beside it) decides which experts are loaded
|
||||
into VRAM first; the engine updates it as it runs.
|
||||
|
||||
## Run
|
||||
|
||||
```
|
||||
build/bin/unbiased-strata --engine build/bin/strata-dsv41 \
|
||||
-m /mnt/ds4/dsv41/IQ2_XXS/DeepSeek-V4.1-Flash-1017-GSQ-RCO-IQ2_XXS-00001-of-00004.gguf \
|
||||
--host 0.0.0.0 --port 11434 --alias deepseek-v4.1-flash-1017-ista-iq2_xxs --sse-ping-interval 10 \
|
||||
--chat-template-file data/dsv41/chat_template-ista-1017.jinja --temp 1.0 --top-p 1.0 --min-p 0.0 --top-k 64 \
|
||||
-- --pack /mnt/ds4/dsv41/IQ2_XXS/maya-ds4 --max-context 131072 --dspark auto --gpus 0
|
||||
```
|
||||
|
||||
(`DS4_STORE_ZC=1 DS4_STORE_ZC_FRAC=100 DS4_READERS=16` in the environment on a slow CPU; see the measurements.)
|
||||
|
||||
- `-m` is shard 1: the front end reads the vocabulary and the chat template from it and no tensors. The pinned
|
||||
llama.cpp does not know `deepseek41`, so the vocabulary load takes the front end's `general.architecture` override path
|
||||
(USTRAT-6), as for any architecture it has not met.
|
||||
- Engine options are upstream's (`strata-dsv41 --help`): `--max-context`, `--dspark auto|on|off|none` (`auto`, never
|
||||
`off`: `off` still loads the drafter and its experts take VRAM), `--gpus`, `--vram-experts N` (how many experts to keep
|
||||
on the card; the engine sizes it from free VRAM by default), `--ssd-cache` (the RAM store for the experts beyond VRAM,
|
||||
sized by itself), `--expert-profile`, `--threads`. The latent KV cache is FP4 in the engine; there is no `--kv` type flag
|
||||
as `strata` has.
|
||||
- Thinking is on by default, from the template. `reasoning_effort` takes `low`, `medium`, `high` (the default), `max` or a
|
||||
number 1 to 100; `chat_template_kwargs.enable_thinking: false` turns it off. Tool calls are DSML
|
||||
(`<|DSML| calls>` ... `<|DSML| invoke name="...">`); the front end parses them with llama.cpp's
|
||||
`common/parsers/deepseek.cpp`, which carries PR 30817's V4.1 hunks ([UPSTREAM.md](../UPSTREAM.md)), and emits OpenAI
|
||||
`tool_calls`. The front end caps `top_k` at 64 (USTRAT-5); DeepSeek's recommended `top_k 0` is not reachable.
|
||||
- Not in this engine version: several requests at once and pictures (both ignored with a warning). The engine's `STAT` and
|
||||
`NOTE` lines are ignored by the front end.
|
||||
|
||||
## Where it goes
|
||||
|
||||
| | size | where |
|
||||
| --- | ---: | --- |
|
||||
| routed experts (15,360) | ~110 GB at 2.00 bpw | as many as fit in VRAM after the dense weights and the context; the rest on the CPU lane (`STRATA_DSV41_TQ_CPU=1`, ggml-cpu's i-quant dots on AVX2 or AVX-512), read from the RAM store or the model files |
|
||||
| attention and other dense weights | 16.8 GB | VRAM |
|
||||
| Engram | 110.6 GB | the SSD; a few rows a token |
|
||||
|
||||
The experts the card does not hold are read from the files while the model answers, so the OS file cache wants as much of
|
||||
them as the RAM allows. Upstream's measurements: RTX 5070 (12 GB) with 64 GB RAM 4.7 tokens/s; RTX 3060 (12 GB) with 46 GB
|
||||
RAM 7.2 tokens/s; four R9700 (32 GB each) 31 tokens/s; "under about 40 GB of RAM it is untested and slow".
|
||||
|
||||
## What it was measured on
|
||||
|
||||
| | |
|
||||
| --- | --- |
|
||||
| Graphics card | RTX A6000, 48 GB (Proxmox VM 220, passthrough) |
|
||||
| CPU | 12 vCPU of a Ryzen 7 1700 (AVX2, no AVX-512) |
|
||||
| RAM | 52 GiB configured, 50 GiB in the guest |
|
||||
| Disk | 420 GB NVMe (thin volume) for the shards, Engram, drafter and pack |
|
||||
| Built with | CUDA 12.x, `make build` (`STRATA_BUILD_DSV41=ON`, `CUDA_ARCHS` for sm_86), 0 warnings |
|
||||
| Model | IQ2_XXS set above, 2.00 bpw (the IQ1_M rows below say so) |
|
||||
| Context | 128K (`--max-context 131072`) |
|
||||
|
||||
Load: 35 s to healthy (the pack's files in the page cache or not; the RAM store reads its 28.8 GB in 9 s). VRAM: dense
|
||||
5.86 GB, 4,700 of 15,360 experts (40.86 GB), caches 0.12 GB, 581 MiB free. 10,660 experts on the CPU lane, in place in
|
||||
the files; the RAM store 41 GB (3,996 slots). DSpark stays unloaded under `--dspark auto` (the engine's rule: the experts
|
||||
are far more than the card holds, so its verify rounds would gain nothing).
|
||||
|
||||
Engine alone (`--ids ... --n 48`, caches dropped before each run), decode:
|
||||
|
||||
| setting | tok/s | CPU lane, experts a token | of the per-token time |
|
||||
| --- | ---: | ---: | --- |
|
||||
| default | 2.00 | 66 | CPU lane 482 ms; store hits 63%, waits for the disk 79 ms; 317 MB read a token |
|
||||
| `--ssd-cache 0` (page cache instead) | 1.99 | 66 | the same; 226 MB read a token |
|
||||
| `--ssd-cache 16` | 1.93 | 66 | store hits 50%, waits 109 ms |
|
||||
| `--mmap-experts off` (40 GB copied into RAM) | 1.95 | 66 | CPU lane 495 ms, no store |
|
||||
| `DS4_STORE_ZC=1` (GPU computes the store's experts over PCIe, 50% visible) | 2.59 | 39 | CPU lane 353 ms; GPU 23 experts a token from the store |
|
||||
| `DS4_STORE_ZC=1 DS4_STORE_ZC_FRAC=100` | 3.23 | 26 | CPU lane 258 ms; GPU 43 a token from the store |
|
||||
| the same with `DS4_READERS=16` | 3.34 | 25 | CPU lane 246 ms; waits 79 ms |
|
||||
| `DS4_STORE_ZC=1` with `--cpu-threads 12` | 2.14 | 44 | worse: the 12 vCPUs are 6 cores' SMT pairs |
|
||||
|
||||
So on this machine the critical path is the CPU lane, not the disk: a Ryzen 7 1700's AVX2 cores dequantize IQ1_M / IQ2
|
||||
rows at roughly 10 ms an expert, and the disk's share of the token is 60 to 80 ms (the NVMe reads random 8 MiB at 3.5 GB/s;
|
||||
the engine draws 230 to 340 MB a token). The zero-copy store is upstream's opt-in (slower than their CPU lane on a 5070 /
|
||||
PCIe 5.0 box, and the lane that takes an expert depends on timing, so answers are not bit-reproducible); here it moves
|
||||
two thirds of the CPU lane's work onto the A6000 over PCIe 3.0 x16 and is what the homelab unit runs with
|
||||
(`Environment=DS4_STORE_ZC=1 DS4_STORE_ZC_FRAC=100 DS4_READERS=16`).
|
||||
|
||||
Through the front end (first light, default store): a 42-token prompt read at 4.4 tok/s, 30 tokens written at 2.4 tok/s; a
|
||||
329-token prompt at 17.8 tok/s and the answer at 2.5 tok/s; a 389-token answer streamed at 3.1 tok/s. With the zero-copy
|
||||
store (the unit's setting): a 42-token prompt at 4.2 tok/s and 32 tokens at 4.5 tok/s; a 400-token streamed answer at
|
||||
6.9 tok/s (the store warm); a 319-token prompt at 18.4 tok/s and 85 tokens at 5.3 tok/s; the CPU lane took 2 to 3% of the
|
||||
expert uses. Healthy 50 s after start. Those prompt rates are a fixed cost of about 15 s a request, not a rate: see the
|
||||
depth table.
|
||||
|
||||
### Prompt depth, and the IQ1_M set
|
||||
|
||||
Through the front end (`stream: false`, thinking off, the unit's settings), the front end's `timings`; prompts are this
|
||||
repository's README, docs and sources, 200 tokens generated each. The IQ2_XXS and IQ1_M packs on the same VM, one after
|
||||
the other (IQ1_M: 5,395 experts in VRAM, the RAM store 4,676 slots of 8.7 MB; IQ2_XXS: 4,678 and 3,967 of 10.3 MB):
|
||||
|
||||
| prompt tokens | IQ2_XXS prefill | IQ1_M prefill | IQ2_XXS decode | IQ1_M decode |
|
||||
| ---: | ---: | ---: | ---: | ---: |
|
||||
| 22 (short question, 270-290 out) | 3 to 18 tok/s | 6.5 to 7.2 tok/s | 4.5 to 6.9 tok/s | 4.8 to 6.1 tok/s |
|
||||
| 9,064 | 196 tok/s (46 s) | 216 tok/s (42 s) | 3.8 tok/s | 6.4 tok/s |
|
||||
| 39,005 | 426 tok/s (92 s) | 473 tok/s (83 s) | 5.2 tok/s | 8.4 tok/s |
|
||||
| 82,037 | 496 tok/s (165 s) | | 5.9 tok/s | |
|
||||
|
||||
Prefill is about 15 s fixed plus ~1.3 ms a token (a chunk touches each needed expert once), so the rate climbs with
|
||||
depth up to the 8192-token chunk. A repeated-sentence filler prompt reads at 32 (492 tokens) to 427 tok/s (13.7K) with
|
||||
nearly every expert in VRAM; do not benchmark with one. Decode does not fall with depth: the latent cache is small and
|
||||
the token's cost is the expert fetch. The IQ1_M set fits 15% more experts on the card and in the store and decodes 60%
|
||||
faster at depth; ISTA's numbers put it at perplexity +21% against +15.5% for IQ2_XXS (weaker on prose).
|
||||
|
||||
## The chat template
|
||||
|
||||
The ISTA GGUF carries an older DeepSeek template: it spells the tool tags `<|DSML|tool_calls>`, `<|DSML|invoke`,
|
||||
`<|DSML|parameter` through a `dsml_token` variable, while the 1017 model writes `<|DSML| calls>`, `<|DSML| invoke`,
|
||||
`<|DSML| parameter` (a space, and `calls`). With the GGUF's template llama.cpp does not select its V4.1 parser (it looks
|
||||
for the literal `|DSML| calls>` in the template source) and a tool call came back as text in the content. DeepSeek's
|
||||
official template and Unsloth's port (upstream Strata's fixture) both use Jinja's `dict()`, which the pinned llama.cpp's
|
||||
minja does not have ("Callee is not a function: got Undefined (hint: 'dict')", the server exits). So
|
||||
`data/dsv41/chat_template-ista-1017.jinja` is the GGUF's own template with the five tag spellings written out as literals,
|
||||
nothing else changed; pass it with `--chat-template-file` before the `--`. With it: `finish_reason: tool_calls`, arguments
|
||||
`{"city":"Paris","unit":"c"}`, reasoning split into `reasoning_content`, thinking on by default.
|
||||
|
||||
|
||||
|
||||
## Tests
|
||||
|
||||
- `make test` (the front end against the fake engine) passes unchanged with the engine built in.
|
||||
- `iq_avx2_parity`: 0 failures after the swap to upstream's `iq_avx2.cpp` / `iq_avx512.cpp`, so `strata`'s and
|
||||
`strata-poly`'s CPU i-quant rows are what they were.
|
||||
- Upstream's engine tests (`ds4_tq_test`, `ds4_iq_test`, `ds4_slot_test`, `ds4_gg_bench`) build with
|
||||
`STRATA_BUILD_DSV41=ON`; they are not part of `make test` (they need a GPU, and `ds4_slot_test` a pack).
|
||||
+2297
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,59 @@
|
||||
# Avoid duplicate expert slots across helper and primary GPUs
|
||||
|
||||
## Why this helps
|
||||
|
||||
On a PC with two small GPUs, helper experts start out separate from the primary
|
||||
cache. Later, the adaptive primary cache can promote an expert that the helper
|
||||
already holds. Both cards then spend memory on the same expert.
|
||||
|
||||
We observed about 1,900-2,000 duplicate slots during sustained requests.
|
||||
This opt-in change keeps helper-owned experts out of primary promotion candidates,
|
||||
in both the server and command-line generation paths.
|
||||
|
||||
## Use
|
||||
|
||||
Set `STRATA_DISJOINT_ADAPT=1` before starting the engine. It is off by default.
|
||||
It leaves the existing peer-tier check and expert arithmetic unchanged.
|
||||
The check is live: each promotion candidate is asked of the helper's own cache (`RemoteExperts::holds`), so an expert
|
||||
the helper's tier swaps in or out later is followed (a mask copied at load would go stale). Needs the helper-share
|
||||
change (#854) for `holds`.
|
||||
|
||||
## Validation environment
|
||||
|
||||
- Two modified RTX 3080 20 GB cards; CUDA SM86, CUDA 13.1, Linux.
|
||||
- Intel Xeon E5-2686 v4 (18 cores / 36 threads), about 94 GiB usable RAM.
|
||||
- PCIe 3.0, no GPU peer-to-peer access; 17 expert-pool workers.
|
||||
- Qwen3.8-Flash-Next IQ3_S, 131,072-token context, INT8 KV,
|
||||
32,768 resident KV cells.
|
||||
- Medium thinking: 2,048-token reasoning cap, 8,192-token output cap.
|
||||
- Physical GPU power limits stayed at 250 W and 280 W. No power increase.
|
||||
- Historical performance tests used an isolated engine based on official
|
||||
v0.1.38 plus reviewed architectds/PolyStrata changes (best, 05c0f36).
|
||||
This PR contains only our change, ported to official main (99f3dbd).
|
||||
The historical timings are NOT a measured speedup of this pure-upstream port.
|
||||
|
||||
## Historical benefit
|
||||
|
||||
Same binary and helper capacity, six complete JSON tasks per arm:
|
||||
|
||||
| 32K cached request | Original | Ownership guard |
|
||||
| --- | ---: | ---: |
|
||||
| Generation | 81.5 tokens/s | 94.1 tokens/s |
|
||||
| Complete request | 12.997 s | 11.417 s |
|
||||
|
||||
Generation improved by 15.5%; request time fell by 12.2%.
|
||||
The tasks returned complete 100-record arrays and correct source facts.
|
||||
All 18 checks passed across the original, guarded, and larger-cache arms.
|
||||
The larger-helper arm is not included in the comparison above.
|
||||
These repetitive tasks do not represent all agent workloads.
|
||||
|
||||
## Validation and remaining work
|
||||
|
||||
- Standalone ownership test passes, including disabled, empty, unowned,
|
||||
owned, and out-of-range entries, plus candidate filtering.
|
||||
- Linux compile/link against pure official main (99f3dbd) passed. No engine
|
||||
was started and no production settings were changed.
|
||||
- Pure-upstream GPU performance and session/vision/cancellation regression
|
||||
checks still need to be run. Keep this PR as a draft until then.
|
||||
- Historical combined builds passed those safety checks, but that is not a
|
||||
substitute for validating this independent port.
|
||||
@@ -0,0 +1,206 @@
|
||||
# Resident expert exchange buffer rotation
|
||||
|
||||
When the resident RAM complement exchanges an expert with the GPU cache, the
|
||||
evicted expert lands in a temporary host buffer. The existing path then copies
|
||||
those bytes into the promoted expert's old RAM slot. Rotation removes that last
|
||||
host copy: the temporary buffer becomes resident, and the old RAM slot becomes
|
||||
the next temporary buffer.
|
||||
|
||||
## Enable
|
||||
|
||||
Rotation is **off by default**. Set `STRATA_EXCHANGE_ROTATE=1` before starting the
|
||||
engine with your existing arguments:
|
||||
|
||||
```bash
|
||||
export STRATA_EXCHANGE_ROTATE=1
|
||||
```
|
||||
|
||||
```powershell
|
||||
$env:STRATA_EXCHANGE_ROTATE = '1'
|
||||
```
|
||||
|
||||
Only the exact value `1` opts in. Set it to `0` or remove it to restore the copy
|
||||
path. This setting does not select resident RAM mode or change any preset.
|
||||
It applies only when the resident complement is fully pinned and GPU-mapped
|
||||
and the exchange buffers can also be pinned and mapped. Other layouts keep the
|
||||
copy path and log why rotation could not be enabled. Configurations without a
|
||||
resident complement do not use it. Layers may differ in expert block size (a
|
||||
GGUF with mixed quantizations per layer): see
|
||||
[Layers of different block sizes](#layers-of-different-block-sizes).
|
||||
|
||||
The startup diagnostic confirms activation:
|
||||
|
||||
```text
|
||||
FileExpertSource: exchange buffer rotation enabled: ...; no host commit memcpy
|
||||
```
|
||||
|
||||
Serving diagnostics report the cumulative rotated block count and avoided
|
||||
`memcpy` payload bytes. This counts the copied payload once, not read plus write
|
||||
traffic, and does not include the GPU transfers, which still occur.
|
||||
|
||||
## Ownership and synchronization
|
||||
|
||||
The original allocations own their memory until `FileExpertSource::close()`.
|
||||
Rotation updates slot ownership and keeps each host pointer paired with its GPU
|
||||
alias. Atomic slot IDs let background residency queries observe those immutable
|
||||
pairs. Compute readers and GPU transfers must still finish before the existing
|
||||
serialized commit; rotation adds no overlapping compute or new synchronization
|
||||
policy. Reserve the maximum exchange capacity before rotation starts: growing a
|
||||
live exchange arena is rejected because it can now hold resident experts.
|
||||
|
||||
## Layers of different block sizes
|
||||
|
||||
A swap exchanges two experts of the same layer, so the RAM slot the promoted
|
||||
expert leaves has exactly the size of the block the evicted one needs. Rotation
|
||||
therefore keeps its spare buffers per block size: an exchange of a layer takes
|
||||
a spare of that layer's size and hands back one of the same size, and every
|
||||
size keeps its number of spares for good. The first version required one size
|
||||
for all layers and fell back to the copy path on any other pack; Swift 1.5
|
||||
IQ3_S has seven sizes (1,510,400 to 2,662,400 bytes) and IQ3_XXS has nine
|
||||
too, so neither could rotate.
|
||||
|
||||
The exchange allocation holds one spare of every size per swap of a round:
|
||||
`--adapt-swaps` (at most 96) times the sum of the distinct sizes. With
|
||||
`--adapt-async 1` the second half of the buffers only stages copies and is
|
||||
kept in the largest size alone. On IQ3_S with `--adapt-swaps 80` that is
|
||||
1.06 GiB of page-locked RAM (1.26 GiB with `--adapt-async 1`), against 0.20
|
||||
and 0.40 GiB for the copy path's buffers. The startup line says how many sizes
|
||||
and how much:
|
||||
|
||||
```text
|
||||
FileExpertSource: exchange buffer rotation enabled: 80 buffers in 7 block sizes (largest 2662400 bytes, 1.06 GiB page-locked); no host commit memcpy
|
||||
```
|
||||
|
||||
With `--adapt-async 1` a rotated round also ends one verify window sooner:
|
||||
there are no bytes for the background job to move, so the ownership flip runs
|
||||
in the tick that sees the copies in.
|
||||
|
||||
`tests/core/exchange_storage_test.cpp` covers it without CUDA (three sizes,
|
||||
6,144 exchanges: bytes, aliases, a spare of another size or an expert of
|
||||
another layer refused, overlapping resident blocks refused).
|
||||
|
||||
### Measured: Swift 1.5 IQ3_S on an RTX 5090 with 64 GB (Windows 11)
|
||||
|
||||
Core i7-13700K, RTX 5090 32 GB, 64 GB DDR5, Windows 11, driver 617.42, CUDA
|
||||
13.0.88, engine 0.1.42 built from source with this change. Swift 1.5 IQ3_S,
|
||||
128K context, `--resident-experts` (31.4 GiB of experts page-locked in RAM,
|
||||
about 10,800 of 24,576 in VRAM), `--adapt-every 1 --adapt-swaps 80
|
||||
--adapt-decay 0.97`, `--spec 4`, `--pool-affinity p-cores`. In the first and third
|
||||
rows one binary ran both arms and only `STRATA_EXCHANGE_ROTATE` differs; in the
|
||||
second the off arm is the build before this change (the third row's binary also
|
||||
carried extra timers).
|
||||
|
||||
| Run | Rotation off | Rotation on |
|
||||
|---|---|---|
|
||||
| One 8K prompt, the same 1,500 forced tokens (`--spec-follow`), blocking tier, decode tok/s | 163.4, 165.1, 163.1, 161.6, 162.6 | 187.4, 188.7, 185.8, 184.9 |
|
||||
| `--serve`, 23 coding-agent turns (`tools/agent_turns_bench.py`'s turns, greedy, up to 400 new tokens), blocking tier, tok/s over all turns, three interleaved rounds | 147.8, 159.2, 158.4 | 175.2, 184.9, 172.8 |
|
||||
| The same turns with `--adapt-async 1`, one binary, two interleaved rounds | 166.0, 170.1 | 185.6, 182.5 |
|
||||
|
||||
In the first row, two runs of each arm that sized the expert cache alike (10,681
|
||||
slots) wrote the same `--window-hashes` file for all 434 windows: the same
|
||||
arithmetic, window by window. (`--expert-cache auto` sizes the cache from the
|
||||
free VRAM at start, and a run with another slot count places experts
|
||||
differently, so its hashes differ with or without rotation.) The tier swapped
|
||||
about 14,000 experts in such a run, 10,100 to 10,600 of them exchanges. In the serve rows the
|
||||
rotated arm was faster on 23 of 23 turns (blocking tier) and 22 of 23
|
||||
(`--adapt-async 1`). On this box the tier swaps about 30 experts per verify
|
||||
window all through a run (the cache holds 44% of the experts), so the copy
|
||||
path moved about 50 MiB of RAM per window on the decode thread; that is the
|
||||
time rotation removes. With `--adapt-async 1` the same copy ran on the
|
||||
background job, and the decode thread still lost about 1 ms per window (0.4 to 2.5 by request)
|
||||
while it ran; rotated, the tier's part of a window is 0.06 ms.
|
||||
|
||||
Not measured: Linux, AMD cards, a layer split, a pack with one block size on
|
||||
this machine (the code path for it is the one above with a single size).
|
||||
|
||||
## Tests
|
||||
|
||||
The ownership test can run without CUDA:
|
||||
|
||||
```bash
|
||||
g++ -std=c++20 -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer \
|
||||
-pthread -Iinclude tests/core/exchange_storage_test.cpp -o /tmp/exchange_storage_test
|
||||
/tmp/exchange_storage_test
|
||||
```
|
||||
|
||||
With an existing CUDA build configured:
|
||||
|
||||
```bash
|
||||
cmake --build build --target strata exchange_storage_test file_expert_source_test
|
||||
ctest --test-dir build -R '^(exchange_storage_test|file_expert_source_test)$' --output-on-failure
|
||||
./build/file_expert_source_test --rotation-gpu
|
||||
compute-sanitizer --tool memcheck --error-exitcode 71 ./build/file_expert_source_test --rotation-gpu
|
||||
```
|
||||
|
||||
The CPU test checks byte preservation, pointer/alias ownership, guards, invalid
|
||||
operations and concurrent residency queries across 12,304 exchanges. The CUDA
|
||||
fixture performs 64 exchanges in each of three modes: copy with pinned RAM,
|
||||
rotation with pinned RAM, and requested rotation with pageable RAM (fallback).
|
||||
It checks exact bytes, GPU alias reads, file fallback, capacity, and close/reopen.
|
||||
The GPU fixture is explicit; the ordinary CTest invocation does not run it.
|
||||
|
||||
On 2026-10-04, the clean patch on upstream
|
||||
`6f32ec070f23ced9f50e704d854d775da52591ab` built on Linux with GCC 15.2 and CUDA
|
||||
13.3 for an RTX 4090. Both CTest tests, the ASan/UBSan ownership test, and the
|
||||
CUDA fixture passed. Compute Sanitizer reported **0 errors**. AMD and Windows
|
||||
GPU execution were not tested for this patch.
|
||||
|
||||
## One native token-identical A/B
|
||||
|
||||
Measured on 2026-10-04 using the clean rotation build at
|
||||
`18a30ad775bce86e99a54e6dc552ccb72c66d16e`, on upstream
|
||||
`6f32ec070f23ced9f50e704d854d775da52591ab`. The model is the standard
|
||||
GSQ-RCO **Q2_0**, with its matching IQ4_NL PLE shard. Both shards were verified
|
||||
against the publisher's SHA-256 hashes at the pinned revision in the receipt.
|
||||
The native pack uses the existing `tools/iq_pack.py`; no compatibility conversion
|
||||
or Q8 PLE reader extension is needed.
|
||||
|
||||
Both arms used the same Release binary (GCC 13.3, CUDA 13.2), RTX PRO 6000
|
||||
Blackwell 96GB, Ryzen 9 7950X and 128GB installed RAM. A fresh engine per arm
|
||||
generated exactly 1,024 tokens after the same 1,024-token counting prompt.
|
||||
The context allocation was 40,960, with 12,000 GPU expert slots, a 16.19 GiB
|
||||
pinned/mapped resident complement, FP16 KV, greedy target-only decoding and
|
||||
zero offered drafts, reused prompt tokens or file-tier blob reads during
|
||||
generation. Only `STRATA_EXCHANGE_ROTATE` changed. Transfer completion is
|
||||
awaited before admission.
|
||||
|
||||
The GPU cache was deliberately capped at 12,000 slots (15.45 GiB) to exercise
|
||||
resident RAM exchanges. Q2 can fit entirely on this 96GB GPU; this is a storage
|
||||
path comparison, not the fastest full-GPU configuration. It does not change
|
||||
the project's presets or enable resident mode for existing users.
|
||||
|
||||
| Rotation | Decode tokens/s | Resident exchanges | Avoided host-copy payload | Output IDs |
|
||||
|---|---:|---:|---:|---|
|
||||
| `0` | 104.90 | 3,802 | 0 bytes | 1,024, identical |
|
||||
| `1` | 113.44 | 3,802 | 5,255,884,800 bytes | 1,024, identical |
|
||||
|
||||
Decode rates exclude startup and prefill. The observed throughput change was
|
||||
+8.1% in this one pair; repeated timing or a general speedup is not established.
|
||||
The out-of-vocabulary EOS sentinel `2147483647` forces the exact output length,
|
||||
so this is not a model-quality evaluation. Speculative-path token parity,
|
||||
AMD and Windows GPU execution remain untested.
|
||||
|
||||
The same Blackwell binary passed both CTest checks and the three-mode CUDA
|
||||
fixture; Compute Sanitizer reported 0 errors. The
|
||||
[receipt](../bench/results/exchange-rotation-ab.json) contains source, binary,
|
||||
model, pack and profile hashes, arguments, timings and diagnostics. The
|
||||
[raw IDs](../bench/results/exchange-rotation-token-ids.json) retain the input
|
||||
and both outputs. To check the token comparison without a model:
|
||||
|
||||
```bash
|
||||
python - <<'PY'
|
||||
import hashlib, json
|
||||
from pathlib import Path
|
||||
p = Path('bench/results')
|
||||
r = json.loads((p / 'exchange-rotation-ab.json').read_text())
|
||||
raw = (p / r['token_ids_file']).read_bytes()
|
||||
assert hashlib.sha256(raw).hexdigest() == r['token_ids_file_sha256']
|
||||
d = json.loads(raw)
|
||||
assert len(d['input']) == len(d['off']) == len(d['on']) == 1024
|
||||
assert d['off'] == d['on']
|
||||
for name, arm in zip(('off', 'on'), r['arms']):
|
||||
sha = hashlib.sha256(json.dumps(d[name], separators=(',', ':')).encode()).hexdigest()
|
||||
assert sha == arm['output_token_ids_sha256']
|
||||
print('1,024 identical output token IDs')
|
||||
PY
|
||||
```
|
||||
@@ -0,0 +1,107 @@
|
||||
# EXPDEC: the verify window's routed experts with the group's activations in shared memory (`STRATA_EXPDEC=1`, opt-in)
|
||||
|
||||
Opt-in: `STRATA_EXPDEC=1`. Unset (or `0`) the engine launches exactly the kernels it launched before. CUDA only; the
|
||||
output is bitwise the default kernels' (see "Bit for bit" below; `expdec_bench` checks it).
|
||||
|
||||
## What it changes
|
||||
|
||||
`native_expert_grouped` (`src/kernels/cuda/iq_kernels.cu`) computes a verify window's routed experts that are resident
|
||||
in VRAM: group g is one expert's blob, its entries are the window's rows that picked it (1 to T, T = the window's
|
||||
tokens). The default gate/up kernel (`native_gu_multi_kernel`) already decodes each weight part once per block and
|
||||
applies it to the group's entries (`row_dot_80_sub16<NC>`), but the apply re-reads each entry's q8_1 block from
|
||||
global memory with 9 scattered 4-byte loads (36-byte blocks: a warp's load touches 16-32 sectors). On an RTX 2080 Ti
|
||||
at a 131k decode that makes an extra entry cost about 60% of a whole expert (~1.6 us against ~2.6 us per expert and
|
||||
layer) although it reads nothing from DRAM.
|
||||
|
||||
`expdec_gu_kernel` (gate/up: IQ2_XXS, IQ2_XS, IQ3_XXS, IQ3_S, IQ2_S at n_embd 2560) and `expdec_down_kernel` (down:
|
||||
Q2_0 at n_ff 640; IQ4_NL with `STRATA_EXPDEC_D20=1`) instead:
|
||||
|
||||
- stage the group's entries (4 at a time, as the default) in shared memory in a layout where a call's 8 words are two
|
||||
16-byte loads with no bank conflicts (the block's two halves in separate planes), the fp16 block scale already a
|
||||
float (`__low2float(ds)`, the value `apply` computes); for IQ4_NL the words stay together and a call reads two
|
||||
8-byte loads;
|
||||
- compute R rows per lane (`STRATA_EXPDEC_R`, 1 or 2 for gate/up, default 1; `STRATA_EXPDEC_DR` 1/2/4 for down,
|
||||
default 4): the activation words are loaded once per R rows;
|
||||
- take `rb` rows per block instead of 16 (`STRATA_EXPDEC_RB` / `_DRB`; 0 = the most that keep `STRATA_EXPDEC_MINBLK`,
|
||||
default 800, blocks in the launch), so the staging is amortised over 35-140 KB of weights;
|
||||
- stage the IQ3_XXS and IQ3_S codebooks in shared memory too (the IQ2 ones already were);
|
||||
- gate/up `__launch_bounds__(256, STRATA_EXPDEC_MINB)`, default 4 (up to 64 registers, 4 blocks per SM like the
|
||||
default kernels; `2` allows 128).
|
||||
|
||||
Formats outside the list keep the default kernel for that role; `STRATA_OLD_IQ_MMVQ=1` turns EXPDEC off as it turns
|
||||
the multi kernels off. The down is behind `STRATA_EXPDEC_DOWN=1`: in the engine the Q2_0 down with EXPDEC was about
|
||||
10% slower than the default kernel although the micro-bench alone had it at 0.78x (the default down already keeps the
|
||||
group's h rows in shared memory), so by default EXPDEC takes the gate/up only.
|
||||
|
||||
The first time `STRATA_EXPDEC=1` meets a (role, format) the engine writes one line, e.g.
|
||||
`strata expdec: CUDA1 gate/up type 21: expdec_gu_kernel R 1 MINB 4, 16 rows per block, grid 80 x 10 (cap 10 groups), captured into a graph`
|
||||
(or `... not covered: the default kernel runs`).
|
||||
|
||||
API (`include/strata/kernels/iq_kernels.hpp`): `native_expert_set_expdec`, `native_expert_set_expdec_params` /
|
||||
`native_expert_expdec_params` (`NativeExpertExpdecParams`), `native_expert_expdec_takes`. The knobs are read from the
|
||||
environment at startup; captured graphs keep the kernels they captured.
|
||||
|
||||
## Bit for bit
|
||||
|
||||
For every (row, entry) the sum is the default kernel's tree - `row_dot_80_sub16` for gate/up (lane t of a 16-lane
|
||||
sub-warp: calls t, t+32, t+64 into `s`, t+16, t+48 into `s16`, `s = __fadd_rn(s, s16)`, butterfly xor 8-4-2-1),
|
||||
`row_dot_40_sub8` for IQ4_NL, `row_dot_20_sub16` for Q2_0: the same lane does the same calls in the same order, and
|
||||
`apply_u` is `apply` with the same integer and float operations in the same order on the same words (the q8_1 block
|
||||
read from shared memory instead of global). The group's entries are independent of each other, so how many are staged
|
||||
per pass does not matter; R rows per lane and `rb` rows per block only change which lane computes what. The FMA
|
||||
contraction of `s += d * sumi` is the same compiler decision on the same expression in both kernels. The bench
|
||||
confirms it: `identical` on every cell (10 format pairs x T 1-4 x 2 window shapes x every variant x 2 cards).
|
||||
|
||||
## Micro-bench: `expdec_bench`
|
||||
|
||||
Not in the default build: `cmake --build <dir> --target expdec_bench`.
|
||||
|
||||
```
|
||||
expdec_bench [reps=300] [device=-1] [groups=20] [pairs=all] [choices=def,dec,dec:r2,dec:b4,dec:r2:b4] [shape=real]
|
||||
```
|
||||
|
||||
Pairs: the model's 5 gate/up x 2 down formats or `21/20,16/42`. Choices: `def` (the reference) and
|
||||
`dec[:r<1|2>][:d<1|2|4>][:b<2|4>][:w<0|1>][:x<0|1>][:g<n>][:h<n>][:m<n>]` (rows per lane for gate/up and down, min blocks
|
||||
per SM, EXPDEC for the down too, also IQ4_NL, rows per block, min blocks; a missing field takes the engine's value).
|
||||
Shapes: `real` = every token picks 10 experts out of `groups` distinct ones (T=1: 10 groups x 1 entry; T=2: 20 x 1;
|
||||
T=4: 20 groups, 40 entries); `single` = 10 T groups of one entry; `both` also prints the per-expert / per-entry
|
||||
decomposition. One line per cell: `dev T shape gu/d choice all_us gu_us down_us GB/s pct identical|DIFFERENT` (the
|
||||
whole call, then the gate/up and down phases alone; memcmp of the output against `def`; exit 1 if anything differs).
|
||||
The blobs rotate over >= 96 MB so every call reads its weights cold from DRAM, as the decode does each layer.
|
||||
|
||||
Gate/up phase, us per call, synthetic blobs, 20 distinct experts (shape `real`); `dec` = the defaults above:
|
||||
|
||||
| card | format | T=1 def / dec | T=2 | T=3 | T=4 |
|
||||
|---|---|---|---|---|---|
|
||||
| RTX 2080 Ti | IQ3_S | 72 / 0.73x | 112 / 0.79x | 124 / 0.75x | 138 / 0.74x |
|
||||
| RTX 2080 Ti | IQ3_XXS | 61 / 0.79x | 95 / 0.84x | 107 / 0.79x | 119 / 0.77x |
|
||||
| RTX 2080 Ti | IQ2_XXS | 42 / 0.98x | 74 / 0.92x | 86 / 0.86x | 97 / 0.84x |
|
||||
| RTX 2080 Ti | IQ2_XS | 60 / 0.75x | 80 / 0.92x | 92 / 0.87x | 104 / 0.84x |
|
||||
| RTX 2080 Ti | IQ2_S | 62 / 0.75x | 83 / 0.92x | 96 / 0.86x | 109 / 0.84x |
|
||||
| RTX 3060 | IQ3_S | 74 / 1.09x | 144 / 0.99x | 154 / 0.89x | 174 / 0.87x |
|
||||
| RTX 3060 | IQ3_XXS | 78 / 0.89x | 132 / 0.92x | 143 / 0.90x | 162 / 0.82x |
|
||||
| RTX 3060 | IQ2_XXS / XS / S | 60-68 / 0.90-1.04x | 112-118 / 0.89-1.00x | 119-136 / 0.89-0.95x | 132-149 / 0.87-0.91x |
|
||||
|
||||
Per-expert / per-entry cost (us per layer call, RTX 2080 Ti, IQ3_S gate/up): 5.20 / 1.26 default, 3.73 / 0.64 with
|
||||
EXPDEC. Down Q2_0 with `w1` (EXPDEC for the down): 0.65-0.85x in the bench on both cards; down IQ4_NL 0.95-1.07x
|
||||
(no gain, hence the default kernel).
|
||||
|
||||
## In the engine
|
||||
|
||||
nsys of a 131k decode (layer split: RTX 3060 layers 0-15, RTX 2080 Ti layers 16-47 and the head, `--pipeline-windows
|
||||
2`, Windows, 96 verify windows), median kernel time per window, T = 1 / 2 / 3 / 4:
|
||||
|
||||
| | default | EXPDEC |
|
||||
|---|---|---|
|
||||
| RTX 2080 Ti, gate/up kernel | 1.60 / 2.58 / 3.51 / 4.16 ms | 1.42 / 2.07 / 2.75 / 3.20 ms (-11 / -20 / -22 / -23%) |
|
||||
| RTX 2080 Ti, gate/up slope per row | +0.86 ms | +0.60 ms |
|
||||
| RTX 3060, gate/up kernel | 0.77 / 1.43 / 1.97 / 2.23 ms | 0.80 / 1.21 / 1.83 / 1.84 ms |
|
||||
| RTX 2080 Ti, down Q2_0 with `STRATA_EXPDEC_DOWN=1` | - | ~10% slower than the default (hence off by default) |
|
||||
|
||||
End to end, same machine, a deterministic 131k bench (forced tokens and window sizes, 1024 tokens, B-A-B with the
|
||||
lever on / off / on): **+1.1%** decode tokens/s (+0.0 and +2.1 in the two B arms, no B below A), the text identical.
|
||||
The expert kernels are about 20% of the critical stage's time and EXPDEC takes about 20% of that, so the end-to-end
|
||||
figure is small by construction; the lever is cheap, bitwise and off by default.
|
||||
|
||||
Not done here: the weight side (the 8-9 two-byte loads per call and row of `Split<TG>::load`; a weight tile staged in
|
||||
shared memory with 16-byte loads would be the next step), and the T=1 flat cost.
|
||||
+302
@@ -0,0 +1,302 @@
|
||||
# GLM 5.3 Flash (`strata-poly`)
|
||||
|
||||
PolyStrata adds a second engine, `strata-poly`, that runs GLM 5.3 Flash. It sits beside `strata`, which still runs
|
||||
Qwen3.8-Flash-Next as before. The server, the web app and the API are the same for both: a run config names the
|
||||
engine it starts.
|
||||
|
||||
It is early. This project has built and run it on one machine, with Linux and one NVIDIA card, and on two RTX
|
||||
3080s; a user runs it on Windows with a 24 GB card and 128 GB of RAM ([issue 10](https://github.com/VecSzn/PolyStrata/issues/10)).
|
||||
|
||||
## What it was measured on
|
||||
|
||||
| | |
|
||||
| --- | --- |
|
||||
| Graphics card | RTX 5090, 32 GB |
|
||||
| CPU | Xeon Platinum 8470Q, 25 vCPU of it (a cloud machine), 24 threads used |
|
||||
| RAM | 120 GiB |
|
||||
| Built with | CUDA 12.8 |
|
||||
| Model | `GLM-5.3-Flash-GSQ-RCO-3.0bit-q4kattn.gguf`, 113.6 GB, from [neuralll/GLM-5.3-Flash-GSQ-RCO-3.0bit-Q4Kattn-GGUF](https://huggingface.co/neuralll/GLM-5.3-Flash-GSQ-RCO-3.0bit-Q4Kattn-GGUF) |
|
||||
| Context | 32K |
|
||||
|
||||
| | `strata-poly` | llama.cpp ([neurall's fork](https://github.com/neurall/llama.cpp)), stock settings |
|
||||
| --- | ---: | ---: |
|
||||
| Writes answers | 46 tokens/s after the prompt of 11,673 tokens and 62 to 66 after the one of 29,069, 62 to 65 for a 400-token answer to a short one | 26 tokens/s |
|
||||
| Reads a prompt of 3,059 tokens | 641 to 648 tokens/s | about 265 tokens/s |
|
||||
| Reads a prompt of 11,673 tokens | 760 to 817 tokens/s | |
|
||||
| Reads a prompt of 29,069 tokens | 740 to 782 tokens/s | |
|
||||
| Starts | about 7 s with the file in the page cache | |
|
||||
|
||||
Both ran on the machine above. Nothing here has been run on a smaller card.
|
||||
|
||||
The engine's numbers are two runs of the engine of 2ba29a383baf, with what setup gives it: the draft block, and
|
||||
the expert profile the repository ships after one run has added its counts. A cell has the higher of these and
|
||||
two runs of the build of 2026-10-06, which read the three prompts at 610 to 620, 788 to 802 and 733 to 742 tokens/s
|
||||
and wrote 47 to 51 after the long ones; the 400-token answer is that build's, and came at 64 to 65 from this one.
|
||||
The 29,069-token prompt starts like the 11,673-token one before it, so its first 10,240 tokens are not read
|
||||
again. An earlier build, measured the same way without the draft block, wrote 26.7 to 27.7 tokens/s and read the
|
||||
three prompts at 373, 334 and 312; [BACKENDS.md](BACKENDS.md#what-was-tuned) has what changed since. llama.cpp was
|
||||
not run again.
|
||||
|
||||
The README's row for 3.0BIT is PolyStrata's own benchmark through the server, the test every model of this engine
|
||||
gets ([BACKENDS.md](BACKENDS.md#a-prompt-of-30000-tokens)), with the engine of the ready-made release: a short chat
|
||||
written at 59 to 66 tokens/s, and a prompt of 29,154 tokens read whole at 820 to 824, with the first token after
|
||||
36 s and the answer after it written at 62 to 64. The build before read a prompt of 28,354 tokens there at 784 to
|
||||
785, and the engine of 2ba29a383baf one of 29,364 at 786 to 810, with the first token after 36.3 to 37.5 s, and
|
||||
wrote the short chat at 60 to 64 and the answer after the prompt at 61 to 62. Of the 29,069-token prompt in the
|
||||
table above only the last 18,829 tokens are read, the ones furthest into the context, which is the likely reason
|
||||
it comes out slower.
|
||||
|
||||
With greedy sampling the two write the same tokens until two candidates are nearly tied. The model's activations
|
||||
are quantized to 8 bits between layers, so a difference in rounding between two correct implementations can decide
|
||||
such a tie.
|
||||
|
||||
## What you need
|
||||
|
||||
- Linux and an NVIDIA card, RTX 20 or newer. It has only run on 32 GB of VRAM. About 12 GB go to the weights, the
|
||||
caches and the buffers before any expert, so setup stops and asks below 14 GB.
|
||||
- RAM for the experts the card does not hold. The file is mapped and they are read from it while the model answers,
|
||||
so they should stay in the OS file cache: about 86 GB of the 107 GB on a 32 GB card. Setup's estimate for that card
|
||||
is 96 GB of RAM. It has run with 120 GB only. In a container, the memory limit must leave about 8 GB above the
|
||||
model's files: with less, answers read experts from the disk, and the container may end the engine
|
||||
([MULTI_GPU.md](MULTI_GPU.md#the-strata-poly-models) has the pod it happened on). The engine says so at load.
|
||||
- 114 GB of disk for the model file, and 3 GB for its draft block.
|
||||
|
||||
## Sizes
|
||||
|
||||
| Size | What it is | Download | RAM beside a 32 GB card |
|
||||
| --- | --- | ---: | ---: |
|
||||
| `3.0BIT` | The whole model, 288 routed experts a layer: the 3-bit file from [neuralll](https://huggingface.co/neuralll/GLM-5.3-Flash-GSQ-RCO-3.0bit-Q4Kattn-GGUF). | 114 GB | 96 GB |
|
||||
| `UD-IQ2_XXS` | The whole model at about 2 bits: [Unsloth's](https://huggingface.co/unsloth/GLM-5.3-Flash-GGUF) quantization, in four files. Its experts are i-quants, which pass through the card faster and through the CPU more slowly than K-quants: it reads a prompt faster than `3.0BIT` and writes more slowly. | 102 GB | 82 GB |
|
||||
| `REAP50-Q3_K_M` | [REAP50](https://huggingface.co/patrickbdevaney/GLM-5.3-Flash-REAP50-GGUF) by patrickbdevaney: half of each layer's routed experts removed, the rest as 3-bit K-quants. Its card says what was removed and how it was checked. | 79 GB | 60 GB |
|
||||
|
||||
The RAM is setup's estimate: the experts the card does not hold, and 10 GB beside them. Without `--model` setup
|
||||
takes the first size whose estimate the PC meets.
|
||||
|
||||
The other two sizes on the machine above, measured like the table at the top, twice each with the engine of
|
||||
2ba29a383baf. Both files carry their own draft block.
|
||||
|
||||
REAP50-Q3_K_M writes a 400-token answer at 68 to 69 tokens/s, 52 to 55 after the prompt of 11,673 tokens and 71
|
||||
to 75 after the one of 29,069, and reads prompts of 3,059, 11,673 and 29,069 tokens at 1,038 to 1,043, 1,279 to
|
||||
1,285 and 1,253 to 1,257 tokens/s. The card holds 21.6 GiB of its experts, 1,939 of 6,192. By the README's test it
|
||||
reads 29,364 tokens at 1,289 to 1,292 tokens/s, with the first token after 22.8 to 22.9 s, and writes a short chat
|
||||
at 62. Against llama-server of the llama.cpp fork the file was made for, on a prompt of 1,678 tokens, the first 63
|
||||
tokens were the same; that was an earlier build, and it was not compared again.
|
||||
|
||||
UD-IQ2_XXS writes the 400-token answer at 49 tokens/s, 39 after the prompt of 11,673 tokens and 54 to 57 after
|
||||
the one of 29,069, and reads the three prompts at 805 to 812, 1,020 to 1,030 and 1,014 to 1,021. The card holds
|
||||
19.6 GiB of its experts, 2,768 to 2,771 of 12,384. By the README's test, in three runs in turn with the build
|
||||
before, it reads 29,364 tokens at 1,062 to 1,076 tokens/s, with the first token after 27.4 to 27.8 s, and writes a
|
||||
short chat at 50 to 51.
|
||||
|
||||
The build of 2026-10-06 wrote the 400-token answer at 61 tokens/s with REAP50-Q3_K_M and at 44 to 45 with
|
||||
UD-IQ2_XXS, and read the 29,069-token prompt at 1,207 to 1,209 and 973 to 983. An earlier build read it at 384
|
||||
tokens/s with REAP50-Q3_K_M and at 347 with UD-IQ2_XXS, and wrote 27 and 33.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
./setup.sh --family glm
|
||||
```
|
||||
|
||||
Setup checks the PC and asks three things: the size, the context, and whether to keep several conversations in
|
||||
RAM. Then it
|
||||
compiles the engine, downloads the model, checks its SHA-256 and starts it. For 3.0BIT it also downloads the model's
|
||||
draft block, 2.8 GB, once for every size that needs it. The web app is at
|
||||
`http://127.0.0.1:8080`. After that, `./setup.sh` starts the model again without asking.
|
||||
|
||||
- The compile needs g++ and the CUDA toolkit (12.8 or newer for an RTX 50 card). Setup offers to install what is
|
||||
missing. The ready-made `strata-poly` of a release is for Windows only.
|
||||
- You already have the GGUF: `./setup.sh --family glm --gguf-dir /folder/with/the/file`.
|
||||
- The other options are the README's: `--context`, `--port`, `--host`, `--api-key`, `--gpu`, `--gpus`,
|
||||
`--layer-split`, `--yes`, `--no-start`.
|
||||
The ones for the Qwen engine (`--kv`, `--vision`, `--low-ram`, `--parallel`, ...) are named and left out.
|
||||
|
||||
On the test machine, with the file already on the disk, this took about five minutes.
|
||||
|
||||
Setup writes the run config `strata-glm-3.0bit.json` and `run-glm-3.0bit.sh` into the PolyStrata folder, the engine into
|
||||
`engine-poly/`, and the tokenizer and the expert profile into the data folder. The profile starts as the counts in
|
||||
`data/expert-profile-glm.txt`, which come from the test runs here, and the engine updates it after an answer, every
|
||||
10 seconds at most, and when it stops.
|
||||
|
||||
A 64K or 128K context starts and answers, with an expert cache 0.8 or 2.6 GiB smaller. No long prompt has been read
|
||||
at those sizes.
|
||||
|
||||
## Without setup
|
||||
|
||||
Build the engine:
|
||||
|
||||
```
|
||||
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON
|
||||
cmake --build build --target strata-poly
|
||||
```
|
||||
|
||||
Write the tokenizer out of the GGUF once:
|
||||
|
||||
```
|
||||
python tools/strata_tokenizer.py --gguf /models/GLM-5.3-Flash-GSQ-RCO-3.0bit-q4kattn.gguf --out glm-tokenizer
|
||||
```
|
||||
|
||||
Then write a run config, `glm.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"exe": "build/strata-poly",
|
||||
"cwd": "/path/to/PolyStrata",
|
||||
"args": ["--model", "/models/GLM-5.3-Flash-GSQ-RCO-3.0bit-q4kattn.gguf",
|
||||
"--max-context", "32768",
|
||||
"--expert-profile", "glm.profile",
|
||||
"--conversation-cache-mib", "8192"],
|
||||
"tokenizer": "glm-tokenizer/tokenizer",
|
||||
"model_name": "glm-5.3-flash",
|
||||
"log": "glm-engine.log"
|
||||
}
|
||||
```
|
||||
|
||||
and start the server with it:
|
||||
|
||||
```
|
||||
python serve/server.py --engine strata --config glm.json --port 8095
|
||||
```
|
||||
|
||||
The web app is at `http://127.0.0.1:8095`, and the API is the one the README describes. Chat, thinking, tool
|
||||
calls and streaming were checked through `/v1/chat/completions`. `"enable_thinking": false` in
|
||||
`chat_template_kwargs` turns thinking off.
|
||||
|
||||
## How it uses the card
|
||||
|
||||
The model has 45 layers. 42 of them choose 8 of 288 experts for every token, which makes 12,096 experts and most
|
||||
of the file. The rest of the weights are always in VRAM.
|
||||
|
||||
- **The expert cache.** The experts used most often are kept in VRAM: about 2,470 of them, 19.2 GiB, on the 32 GB
|
||||
card at a 32K context with the draft block. `--expert-profile FILE` is where the engine keeps count of which ones are used. It reads the
|
||||
file at the start to choose, and writes it back when it stops. Without a profile it has no counts yet and keeps
|
||||
the same number of experts from every layer, so the second start is the one to measure.
|
||||
- **The cache follows the answer.** The choice at the start fits the average answer, and some answers badly: of
|
||||
the expert uses of a 400-token answer with code in it, 20% found their expert in VRAM. So while an answer is
|
||||
written, the engine counts which experts the last few hundred tokens used. The ones they keep choosing are copied
|
||||
into VRAM, each over a cached expert they chose less than half as often, up to 16 on their way at a time. For
|
||||
that answer the share went to 50% and the speed from 26.4 to 30.7 tokens/s. The cache stays as the last answer
|
||||
left it, so the next one starts from there. A prompt does not move it. `--expert-swaps 0` leaves the cache as it
|
||||
was loaded, and the same prompt then gets the same answer from the second request on: an expert's result
|
||||
differs in its last digits between the CPU and the card, and with swaps an expert can run on one in one run and
|
||||
on the other in the next. The first request can still differ, since the cache is sized once more before the
|
||||
second. A prompt of 32 tokens or more needs `--cpu-share 0` beside it: the CPU's share of such a call's experts
|
||||
follows the calls before.
|
||||
- **Writing an answer.** An expert that is not in VRAM runs on the CPU while the card runs its share. The CPU reads
|
||||
such an expert from memory, and on a PC with more than one NUMA node that memory is on the node whose CPU first
|
||||
read the file. The engine looks where the experts' pages are and keeps its CPU threads on that node: from the
|
||||
other node the same work took 30% longer on the machine above. `--any-node` turns that off.
|
||||
- **Guessing ahead.** While an answer is written, the engine guesses the next few tokens and puts the token it
|
||||
knows and up to three guesses through the model together. A guess counts only when it is the token the model
|
||||
picks itself, so the answer is the same with guessing and without. The guesses come from two places. An answer
|
||||
often repeats text the conversation already has, code it was asked to change or a passage it quotes: when the
|
||||
last few tokens match an earlier place, what followed there is the guess. And the model has a block made for
|
||||
guessing, one more layer that takes a token and what the model made of the token before it, and says what is
|
||||
likely to come next. The block is the model's, one for every size. Unsloth's files carry it. The 3.0BIT file
|
||||
leaves it out, so setup downloads the block alone for it, 2.8 GB out of Unsloth's files, and gives it to the
|
||||
engine as `--draft-model`. REAP50 has its own, pruned like its layers. A right guess saves less than a whole
|
||||
token, because its experts outside VRAM still run on the CPU: four tokens together take about three times as
|
||||
long as one. Measured on the 32 GB card with an earlier build, 600-token answers, twice each, in tokens/s:
|
||||
|
||||
| Answer | 3.0BIT without guesses | with | REAP50-Q3_K_M without | with |
|
||||
| --- | ---: | ---: | ---: | ---: |
|
||||
| plain text | 40 | 46 to 47 | 41 | 44 to 46 |
|
||||
| quotes from a document | 42 | 49 to 51 | 41 | 48 to 51 |
|
||||
| a 670-token file given back with one name changed | 42 | 51 to 52 | 42 | 50 to 59 |
|
||||
|
||||
Of 3.0BIT's guesses 87 to 98% were right. UD-IQ2_XXS gains little: its experts are i-quants, which the CPU
|
||||
computes more slowly, so a guessed token costs it nearly what a token costs. Three 200-token answers wrote 30.7,
|
||||
33.7 and 31.4 tokens/s with its block and 31.3, 30.9 and 31.4 without. `--no-draft` and `--lookup 0` turn the two
|
||||
sources off.
|
||||
- **Reading a prompt.** The prompt goes in up to 1,024 tokens at a time. For each layer the experts outside the
|
||||
cache are copied through a buffer in VRAM and run there. A larger batch reads faster and leaves less VRAM for the
|
||||
expert cache, so answers get slower: with an earlier build, which read the 11,673-token prompt at 334 tokens/s
|
||||
and wrote about 27, 4,096 at a time read it at 396 and wrote 18.5.
|
||||
|
||||
## Several conversations at once
|
||||
|
||||
The engine holds one conversation. A coding agent rarely sends just one: subagents and short side requests come in
|
||||
between the turns of the main one. Each switch used to make the engine read the whole prompt again.
|
||||
|
||||
`--conversation-cache-mib N` gives the engine N MiB of RAM to park conversations in. When another conversation
|
||||
needs the engine, the current one is copied to RAM. When it comes back it is copied in again and goes on where it
|
||||
stopped. Two conversations that start with the same text, a shared system prompt for one, share what is saved for
|
||||
that part.
|
||||
|
||||
Measured through the server with 8,192 MiB: a main conversation of 3,884 prompt tokens, a subagent of 3,323 and a
|
||||
short request took turns. Every later turn of the first two had 97.8 to 99.2% of its prompt cached and took 1.3 to
|
||||
3.9 s. The first turns, which read the prompt, took 13 s.
|
||||
|
||||
What it costs: a checkpoint is 153 MB of RAM, and a parked conversation takes 28 KB for each token. At the end of
|
||||
that run two parked conversations held 1.1 GB.
|
||||
|
||||
The API reports what was not read again as `usage.prompt_tokens_details.cached_tokens` (Responses:
|
||||
`input_tokens_details.cached_tokens`, Messages: `cache_read_input_tokens`), and the web app's Monitor has a
|
||||
Conversation cache card.
|
||||
|
||||
It is off by default, as it is in `strata`. Without it the engine still keeps the last conversation: a next turn
|
||||
goes on from where it stopped, and an edit goes back to the nearest checkpoint.
|
||||
|
||||
## Options
|
||||
|
||||
| Option | Default | What it does |
|
||||
| --- | ---: | --- |
|
||||
| `--model FILE.gguf` | | the model |
|
||||
| `--serve` | | take requests from the server (the server passes this) |
|
||||
| `--max-context N` | 8192 | tokens a conversation can hold |
|
||||
| `--threads N` | all usable | CPU threads for the experts that are not in VRAM |
|
||||
| `--vram-reserve-mib N` | a thirty-second of the card, 256 to 768, or a sixteenth, 512 to 1024, kept whole, when the PC's free RAM is within 4 GiB of the model's files; else half of it after the first request | VRAM left free beside the expert cache |
|
||||
| `--layer-split S` | the first card alone | the model's layers across the cards the engine sees: `auto` (by each card's free VRAM) or the first layer of each later card, as `20` or `20,30` ([MULTI_GPU.md](MULTI_GPU.md#the-strata-poly-models)) |
|
||||
| `--expert-profile FILE` | | expert use counts, read at the start and written back after an answer, every 10 seconds at most, and at the end |
|
||||
| `--no-gpu-experts` | | keep every routed expert on the CPU |
|
||||
| `--any-node` | | on a PC with several NUMA nodes, let the CPU threads run on any of them |
|
||||
| `--no-graphs` | | launch a token's kernels one by one, not as the CUDA graph a layer that is recorded at the first token |
|
||||
| `--expert-swaps N` | 64 | while an answer is written, experts on their way into VRAM at a time, each in place of a cached one the answer uses less; 0 = the cache stays as it was loaded |
|
||||
| `--window N` | 4; 8 for the other models | the most tokens that go through the model together while an answer is written: the known one and guesses after it: the draft block's three at most, and more than three only from a repeat of eight tokens or more; 1 = no guesses |
|
||||
| `--lookup N` | 3 | guess what followed an earlier repeat of the last N or more tokens; 0 = never |
|
||||
| `--no-draft` | | do not run the block that guesses ahead |
|
||||
| `--draft-model FILE.gguf` | | a file of the same model to take that block from, when `--model` has none; setup passes the one it downloaded |
|
||||
| `--draft-vocab N` | 131072 for Qwen3.6, Ornith and Tiel Coder, all of it for the others | the block guesses among the vocabulary's first N tokens; 0 = all |
|
||||
| `--kv-whole` | on an AMD card | give the attention caches VRAM for the whole context at load, not as the conversation grows; setup writes it for an AMD card, where ROCm keeps the VRAM the expert cache gives back ([AMD_HIP.md](AMD_HIP.md#strata-poly-on-amd-beta)) |
|
||||
| `--kv fmt` | fp16 | the K and V attention caches' format: `fp16` (default, unchanged) or `q8_0` (ggml Q8_0 blocks: one fp16 scale a 32-value block of int8 codes): half the KV VRAM, the same answers on the tested models ([Q8_KV.md](Q8_KV.md)) |
|
||||
| `--prompt-batch N` | 1024 | prompt tokens read at a time, 1 to 4096; about 1.4 MiB of VRAM each |
|
||||
| `--stage-mib N` | 2048 | VRAM the experts outside the cache pass through while a prompt is read |
|
||||
| `--stage-ahead N` | 1024 | from N tokens, a batch copies those experts before the layer has chosen, as does every batch of a prompt of N tokens or more that is read several at a time; 0 = never |
|
||||
| `--cpu-share F` | as the times say | in a batch of fewer tokens than `--stage-ahead`, the share of the experts outside VRAM that the CPU computes while the others are copied: the ones the fewest tokens chose; 0 = none |
|
||||
| `--prompt-cache N` | 6 | checkpoints kept of a conversation; 0 = only a next turn is not read again |
|
||||
| `--prompt-cache-every N` | 2048 | a checkpoint every N prompt tokens, besides the one at a prompt's end; 0 = none |
|
||||
| `--conversation-cache-mib N` | 0 | RAM for parked conversations; 0 = off |
|
||||
| `--conversation-cache-slots N` | 4 | parked conversations at most |
|
||||
| `--conversation-cache-min-tokens N` | 1024 | a shorter conversation is not parked |
|
||||
| `--conversation-cache-min-free-mib N` | 2560 | park only while this much physical RAM stays free |
|
||||
| `--eos-ids ID,ID,...` | from the GGUF | tokens that end a reply |
|
||||
| `--tail-skip N` | 0; setup gives Qwen3.6 6 | an expert outside VRAM that every token of a window ranks at place N+1 or later among its experts is left out: faster, and the answers move a little |
|
||||
| `STRATA_FREEZE_EXPERTS` | not set | hold the split of the routed experts between the card and the CPU still for the engine's whole run, so a greedy answer is a function of the request alone: same request, same answer, bit for bit. With guesses on (`--window` above 1 and a block or `--lookup`) the block's guesses and their windows still take their sizes from the machine's pace, which the freeze does not hold: on the cards measured so far it repeated with them on (RX 9060 XT, several thread counts and loads) and on one RTX 4070 laptop it did not — add `--window 1` for a repeat wherever the guesses are on. Measured cost: nothing measurable on the default path, 4-7% at a short prompt with the freeze set |
|
||||
|
||||
`strata-poly` with no arguments prints the list, with the options for running it without the server.
|
||||
|
||||
`--kv q8_0` is new: it stores the attention K and V caches as ggml Q8_0 blocks and is opt-in for the
|
||||
`qwen35moe` models. [Q8_KV.md](Q8_KV.md) has the format, the measured VRAM saving (46.88% at 131072), the
|
||||
fp16↔q8_0 parity on Tiel, Ornith and Occamy, and what was left alone (the `strata` engine, `glm5next`, Gemma 4,
|
||||
the default path).
|
||||
|
||||
## What is missing
|
||||
|
||||
- Other files of the model. The engine reads the layouts of four converters (neurall's llama.cpp fork,
|
||||
patrickbdevaney's, antirez's and Unsloth's), a model in several files, and the weight types llama.cpp's kernels
|
||||
have. Only the three sizes above have been run: setup offers no other.
|
||||
- A ready-made `strata-poly` off Windows, or for a driver older than CUDA 13's: setup compiles it there.
|
||||
- GLM on Windows, by this project: no PC with the RAM for it was at hand, and setup asks before it installs it
|
||||
there. A user ran 3.0BIT on Windows 10 with an RTX 5090 D v2 (24 GB) and 128 GB of RAM
|
||||
([issue 10](https://github.com/VecSzn/PolyStrata/issues/10)): 1,483 experts in VRAM, 26 to 30 tokens/s after
|
||||
a short prompt, 10K tokens read at 375 to 395. The context set to 1,048,576 in the run config loaded and
|
||||
answered, and one request of 557K tokens was read at 286 tokens/s with the three facts planted in it found.
|
||||
With 0.1.44.1-poly.5 a request of 1,002,452 tokens was read in 45.7 minutes (66.3 with poly.2), the three
|
||||
facts found, and from the second request after it the engine wrote at 25 to 30 tokens/s again.
|
||||
- Intel cards, and AMD cards on Windows. On Linux setup compiles the engine for an AMD card
|
||||
([AMD_HIP.md](AMD_HIP.md#strata-poly-on-amd-beta)), a beta tested with Qwen3.6 and Ornith on an RX 7600; GLM
|
||||
itself has not been tried on one, and setup says so. Two NVIDIA cards can share the model
|
||||
([MULTI_GPU.md](MULTI_GPU.md#the-strata-poly-models)): REAP50 has run on two 10 GB cards under Linux.
|
||||
- Pictures. The model's image input is not read.
|
||||
- Several requests decoded together (`"parallel"`). Requests wait their turn.
|
||||
- `--prompt-cache-root` and `--turn-token`. Checkpoints are taken by position.
|
||||
@@ -0,0 +1,81 @@
|
||||
# How does PolyStrata work?
|
||||
|
||||
Models like Qwen3.8-Flash-Next normally run on servers with hundreds of gigabytes of graphics memory. Your graphics
|
||||
card has 12-24 GB. PolyStrata makes it fit by **sharing the work across your whole PC** - the same idea as a kitchen, where
|
||||
the things you use all the time stay on the counter and the rest waits in the pantry. Back to the
|
||||
[README](../README.md#how-does-it-work).
|
||||
|
||||
## Who does what
|
||||
|
||||
<p align="center"><img src="media/how-it-works.svg" width="860" alt="The model's 24,576 experts: the busiest on the graphics card, all of them in RAM, a lookup table on the SSD"></p>
|
||||
|
||||
- **The model is a team of 24,576 small specialists ("experts"),** and each word it writes needs only 10 of them.
|
||||
So it doesn't have to have all of them on the graphics card at once.
|
||||
- **Your graphics card** does the part of the work needed for every word, and keeps the few thousand experts that
|
||||
are asked most often. It keeps learning which ones those are while you use it.
|
||||
- **Your RAM** holds every expert. When a word needs one the card doesn't have, **your processor** works on it -
|
||||
at the same time as the graphics card, so neither waits for the other.
|
||||
- **Your SSD** holds a big lookup table; the model only reads a few small rows of it per word.
|
||||
|
||||
The same in technical terms:
|
||||
|
||||
- **GPU (VRAM):** attention and DeltaNet mixers, the gated-residual weights, routers, shared experts, output head, the
|
||||
MTP draft layer, the KV cache (from 64K: only its most-read part, the rest streams from RAM), and an **expert
|
||||
cache** that fills the rest of VRAM with the most-used experts (it adapts to the conversation while you chat).
|
||||
More VRAM matters more than a faster GPU: every extra GB holds ~700 more experts, and every expert on the GPU is one
|
||||
the CPU does not have to compute.
|
||||
- **RAM:** all 24,576 experts, pinned. The CPU computes the experts that are not on the GPU **in place**, at the same
|
||||
time as the GPU works on the cached ones (AVX-512 / AVX2 kernels, ggml's for the i-quants). On a PC with little RAM
|
||||
and a big card, the [low-RAM mode](MODELS.md#a-big-graphics-card-and-little-ram) keeps in RAM only what the GPU does
|
||||
not hold.
|
||||
- **SSD:** the 28.8 GB n-gram table, read a few rows per token through the OS cache.
|
||||
|
||||
This works the same on NVIDIA (CUDA) and AMD (HIP) cards: the same engine, compiled for each.
|
||||
|
||||
## Guess, then check
|
||||
|
||||
<p align="center"><img src="media/guess-and-check.svg" width="860" alt="A small helper guesses the next words; the big model checks them all at once and keeps the right ones"></p>
|
||||
|
||||
- **Guess, then check.** A small, fast helper built into the model guesses the next few words, and the big model
|
||||
checks all the guesses in one go. It keeps the ones it agrees with and writes the next word itself - so one step
|
||||
often produces several words. The helper only guesses - the big model decides every word - so you get the same
|
||||
quality answer, 1.6-1.8x sooner.
|
||||
- In technical terms: the model's own MTP layer drafts up to 3 tokens; one pass over all 48 layers checks them, 2.4-3.2
|
||||
tokens per pass on average. When the reply repeats the context (code edits, quoted text), **prompt lookup** drafts
|
||||
up to 5 tokens from the earlier copy, but only where its measured acceptance and cost say it pays: code edits 6-11%
|
||||
faster, other text unchanged. The drafts are checked like the MTP's, so the output is the same.
|
||||
|
||||
## Reading long texts
|
||||
|
||||
**Long texts are read in big pieces** (up to 8,192 tokens - pieces of words - at a time), which is why a long
|
||||
document or code base is read at over 1,000 tokens per second. The experts of the next layer stream to the GPU over
|
||||
PCIe while the current layer's attention runs. After the first message, PolyStrata keeps the conversation and reads only
|
||||
what is new, so follow-ups start in seconds.
|
||||
|
||||
## More
|
||||
|
||||
The [details](DETAILS.md#how-it-works) explain every part and its numbers, and the
|
||||
[paper](paper/Strata-Paper.pdf) tells the whole story, with the measurements behind it.
|
||||
|
||||
## Credits
|
||||
|
||||
- PolyStrata is built on [Strata](https://github.com/Niko1221/Strata) by Niko1221 and its contributors. The Qwen
|
||||
engine, the installer, the server and the web app are that project's work. PolyStrata adds the engine for GLM 5.3
|
||||
Flash ([GLM.md](GLM.md)), whose file is from
|
||||
[neuralll](https://huggingface.co/neuralll/GLM-5.3-Flash-GSQ-RCO-3.0bit-Q4Kattn-GGUF).
|
||||
- Model: [Qwen3.8-Flash-Next](https://huggingface.co/Qwen/Qwen3.8-Flash-Next) by the Qwen team; compressed versions by
|
||||
[ISTA-DASLab](https://huggingface.co/ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF);
|
||||
[Swift 1.5](https://huggingface.co/ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF) by UkisAI; the experimental
|
||||
[UD-Q4_K_XL](https://huggingface.co/unsloth/Qwen3.8-Flash-Next-GGUF) by Unsloth (its support follows
|
||||
[eddoursul/Strata](https://github.com/eddoursul/Strata)). Their licenses apply to the model files.
|
||||
- Built with parts of [llama.cpp / ggml](https://github.com/ggml-org/llama.cpp) (MIT). Ideas from
|
||||
[Splash](https://github.com/incoai/splash), [ninfer](https://github.com/Neroued/ninfer) and
|
||||
[HyperQwen](https://github.com/syv-ai/HyperQwen). More in the [details](DETAILS.md#credits-and-licenses).
|
||||
- The AMD (HIP) backend: [AMD_HIP.md](AMD_HIP.md) names the contributors and the machines it was validated on.
|
||||
|
||||
## License
|
||||
|
||||
PolyStrata is open source under the [MIT License](../LICENSE). A few parts carry their own licenses: `third_party/ggml`
|
||||
(MIT, llama.cpp / ggml), the web app's font (SIL Open Font License 1.1) and the experimental speed projection's
|
||||
vector in `data/experimental-speed-projection` (Qwen Community License 1.0, from the model's activations). The
|
||||
models are not part of this repository; each model's own license applies to its files.
|
||||
+883
@@ -0,0 +1,883 @@
|
||||
# PolyStrata on an Intel Arc
|
||||
|
||||
PolyStrata's engine is CUDA. On an Intel Arc it runs as **PolyStrata's own engine, ported to SYCL** (`sycl/`, the
|
||||
section "The engine itself on Intel" below), behind the same PolyStrata server: OpenAI and Anthropic APIs, streaming,
|
||||
tool calls, MCP and the web app all unchanged. llama.cpp's SYCL backend is the comparison point in the tables (it
|
||||
runs the same GGUF at about a third of the speed).
|
||||
|
||||
Everything Intel-specific lives in `sycl/`; no shared file of upstream's is changed, so upstream merges stay clean.
|
||||
`sycl/setup_intel.py` and `sycl/serve/server_intel.py` wrap upstream's `setup.py` and `serve/server.py` from
|
||||
outside.
|
||||
|
||||
Written for and measured on an **Arc Pro B70 (32 GB)** running the Coder (IQ1_M) on Ubuntu 24.04, in a
|
||||
PCIe 3.0 x8 slot (the card trains at Gen3 x8 there; it can do Gen5 x16).
|
||||
|
||||
## What you get (2026-10-01)
|
||||
|
||||
| | NVIDIA (PolyStrata engine) | Intel Arc, PolyStrata SYCL port | Intel Arc, llama.cpp |
|
||||
|---|---|---|---|
|
||||
| models | all four | the Coder IQ1_M; the original IQ2_XS too (experts beyond VRAM in the host mirror: 58-64 tok/s) | the Coder (fits VRAM) |
|
||||
| model files | the same GGUFs | the same GGUFs + a native pack | the same GGUFs |
|
||||
| where the model lives | experts in RAM, hot ones on the card | every expert in VRAM (`--stream-experts`: no host copy), shard 2's lookup table read from the SSD by row | all of shard 1 on the card, shard 2 paged from disk |
|
||||
| RAM needed | 32-64 GB | little (23 GB is fine) | little (23 GB is fine) |
|
||||
| decode, Coder IQ1_M | 44-51 tok/s on an RTX 5070 | **78.2 tok/s** (19-token prompt, 256 greedy tokens), **75.7** after a 2,184-token prompt, 69 after 40K, 66.6 after 128K, 55.9 after 256K; 48-72 through the API | 23-25 tok/s |
|
||||
| prompt reading | ~1,870 tok/s | **790 tok/s** at 2,184 tokens, 1,117 at 40K, 888 at 128K, 757 at 256K | ~150 tok/s (424 at 105K) |
|
||||
| speculative decoding (MTP) | yes | yes (the base checkpoint's draft layer; 70-85% of drafts accepted on code) | no |
|
||||
| images | yes | not yet | not yet |
|
||||
| context | up to 262K | 256K measured, 56 tok/s decode there (`--kv-resident`: the KV in pinned host memory, the attended window in VRAM) | 131K measured ceiling |
|
||||
|
||||
Decode speed with speculative decoding depends on the text: code drafts well, prose less so (see "Speed depends
|
||||
on the text"). The SYCL numbers are greedy runs of the engine (as in "How to run it by hand" below, 256 new
|
||||
tokens) on engine 0.1.31-sycl (2026-10-01; 0.1.32-0.1.38-sycl reproduce them exactly);
|
||||
"Decode round 2" below lists what each change bought.
|
||||
|
||||
## Setup
|
||||
|
||||
On Ubuntu 24.04 or newer, from nothing. The Intel GPU driver (the `xe` or `i915` kernel driver and the compute runtime;
|
||||
[INTEL_ARC.md](INTEL_ARC.md), "What you need") is assumed: `ls /dev/dri` shows a `renderD128`.
|
||||
|
||||
1. **Docker, once.** The engine runs in a container, so the PC needs Docker and no oneAPI:
|
||||
|
||||
sudo apt install docker.io git
|
||||
sudo usermod -aG docker,render $USER
|
||||
|
||||
Log out and in again (or reboot) so the groups apply. `docker ps` must work without `sudo`; the `render` group lets
|
||||
the container open the GPU.
|
||||
2. **Get PolyStrata and build the engine** ("How to build it" below, about 10 minutes the first time).
|
||||
3. **Run setup:**
|
||||
|
||||
./setup.sh --backend sycl [setup.py's options, e.g. --model IQ3_S --context 32768 --port 8085]
|
||||
|
||||
`setup.sh` makes its own Python environment in `.venv`, so Ubuntu's "externally managed" system Python is not
|
||||
touched. **Do not run `python3 sycl/setup_intel.py` yourself:** it installs setup's packages into whichever Python runs
|
||||
it, and Ubuntu's refuses (`externally-managed-environment`). `./setup.sh --backend sycl` is the one command, for the
|
||||
first install and every later start.
|
||||
|
||||
Setup is upstream's `setup.py` with the Intel steps swapped in (`sycl/setup_intel.py` imports it and replaces those steps;
|
||||
setup.py itself is unchanged). The model choice, download, pack, tokenizer, MTP draft layer and the context and KV
|
||||
questions are setup's own. What changes:
|
||||
|
||||
- **GPU check:** the Arc is found in sysfs (vendor 8086 under `xe` or `i915`) and offered through setup's AMD
|
||||
path. That is the path that builds locally and has no images.
|
||||
- **Engine step:** it uses the SYCL build (`build-sycl-aot/strata` or `build-sycl/strata`, run in the `strata-sycl-dev`
|
||||
image by `sycl/serve/strata-sycl.sh`) instead of compiling CUDA or HIP.
|
||||
- **RAM rule:** this does not apply on an `xe` card. The CUDA engine keeps every expert in RAM; the port streams them from
|
||||
the GGUF into VRAM (`--stream-experts`), so RAM only decides the KV streaming. `--check` lists what fits by VRAM.
|
||||
- **The config:** it uses the container's paths and `"backend": "sycl"`. The VRAM reserve is 1,024 MiB up to
|
||||
32K and 2,048 MiB with 4,096-token prompt chunks above that, 300 MiB on a card under 12 GB; a
|
||||
`--vram-reserve-mib N` you give is kept as given. KV streaming (`--kv-resident 32768`) is on from
|
||||
64K up when the RAM holds the KV. A `model_switcher` or `sampling` block from an earlier config is kept.
|
||||
`run-<model>.sh` starts `sycl/serve/server_intel.py`.
|
||||
- **Arc A-series (`i915`, e.g. the A750 with 8 GB):** a different config, see "Arc A750 and the other Alchemist cards" below.
|
||||
- **Engine settings:** the config's `"env"` block reaches the engine. `strata-sycl.sh` forwards every variable starting with
|
||||
`STRATA_`, `ONEAPI_`, `UR_`, `IGC_`, `SYCL_` or `ZES_` into the container and sets `STRATA_VERIFY_DEVICE_PLAN=1`,
|
||||
`STRATA_VERIFY_NO_HOST=1` and `STRATA_STAGER_THREADS=12` unless the environment says otherwise (for example
|
||||
`"env": {"STRATA_VERIFY_NO_HOST": "0"}`).
|
||||
|
||||
If a future `setup.py` drops a step this relies on, it stops with a message instead of writing a wrong config.
|
||||
The models, packs and checkout must sit under the folder `strata-sycl.sh` mounts at `/work` (the one above the
|
||||
checkout, or `STRATA_SYCL_ROOT`). An earlier PolyStrata install on the same PC keeps its data folder in
|
||||
`~/.config/strata/settings.json`; pass `--data-dir <folder above the checkout>/PolyStrata-data` to put this one under the
|
||||
mount. A symlink to a folder outside the mount does not work in the container; a hard link does.
|
||||
|
||||
Then `run-<model>.sh` (or `./setup.sh --backend sycl` again) starts the model. The first start of a 30 GB model
|
||||
takes about two minutes. `--port N` and `--host 0.0.0.0` work as in upstream's setup.
|
||||
|
||||
## How to build it
|
||||
|
||||
The engine is built in Docker, in the `strata-sycl-dev` image (oneAPI 2026.1 compiler, oneMKL and Level Zero, from a
|
||||
community llama.cpp SYCL image), so the PC needs no oneAPI. From the checkout (its folder is called `PolyStrata` here; the
|
||||
folder above it is what the container mounts at `/work`):
|
||||
|
||||
cd PolyStrata
|
||||
docker build -t strata-sycl-dev sycl/tools # once: about 6 minutes, a 13 GB image
|
||||
H=$(basename "$PWD")
|
||||
|
||||
**Arc B-series** (Pro B70: `bmg-g31`; B580, B570 and Pro B60: `bmg-g21`; `ocloc ids bmg-g21` in the image lists the
|
||||
device ids). Ahead-of-time code, no compile at the first start:
|
||||
|
||||
docker run --rm -u $(id -u):$(id -g) -v "$PWD/..:/work" -e AOT=bmg-g31 -e REPO=/work/$H \
|
||||
-e BUILD_DIR=/work/$H/build-sycl-aot strata-sycl-dev "cd /work/$H && bash sycl/tools/build.sh strata"
|
||||
|
||||
**Arc A-series** (Alchemist: A750, A770, A580, A380): no `AOT=`. The code is compiled from SPIR-V at the first start
|
||||
(JIT, about a minute). Nobody has run an AOT build for these cards.
|
||||
|
||||
docker run --rm -u $(id -u):$(id -g) -v "$PWD/..:/work" -e REPO=/work/$H \
|
||||
-e BUILD_DIR=/work/$H/build-sycl strata-sycl-dev "cd /work/$H && bash sycl/tools/build.sh strata"
|
||||
|
||||
The build takes about 3 minutes and ends with `BUILD EXIT 0` and `errors: 0`. The binary is `build-sycl-aot/strata`
|
||||
(B-series) or `build-sycl/strata` (A-series); setup finds either one. Run the `docker build` again after pulling a
|
||||
PolyStrata update that changes `sycl/tools/Dockerfile`, and the `docker run` after every update of the engine (setup
|
||||
says when the engine is older than it needs).
|
||||
|
||||
## Things that matter on this GPU
|
||||
|
||||
- **`SYCL_CACHE_PERSISTENT` must be 0.** The persistent JIT cache segfaults on Xe2 during the first
|
||||
compile. The start script sets it; if you run llama-server by hand, do too.
|
||||
- **The whole model goes on the card** (`--n-gpu-layers 999`), except `per_layer_token_embd.weight`,
|
||||
the single 28.8 GB tensor of shard 2. `--override-tensor per_layer_token_embd=CPU` keeps it in host
|
||||
memory, mmapped and paged from the SSD by row, which is how the model's authors serve it. Host RSS
|
||||
stays around 2 GB.
|
||||
- **Thinking.** The model reasons before it answers. PolyStrata's web app has the setting; for an API
|
||||
client, put `{"reasoning_effort": "none"}` in `strata-<model>.shared-settings.json` next to the
|
||||
config, or send `chat_template_kwargs: {"enable_thinking": false}` per request. Without one of
|
||||
those a short `max_tokens` is spent entirely inside the think block and the answer looks empty.
|
||||
- **`/health` says 503 while loading**; the server polls `/props` instead.
|
||||
|
||||
## How much context fits
|
||||
|
||||
The architecture keeps this small: only every fourth layer is full attention (12 of 48); the other
|
||||
36 are gated-delta-net layers with a fixed-size recurrent state that does not grow with context.
|
||||
Per token, the 12 attention layers keep 2 KV heads x 256 x (K + V) at q8_0, plus the
|
||||
sparse-attention indexer's keys. **Measured: about 20 KiB per token** (VRAM grows 0.6 GB per 32k
|
||||
of context with everything else unchanged).
|
||||
|
||||
| context | VRAM in use, model loaded | headroom on 32 GB | status |
|
||||
|---|---|---|---|
|
||||
| 32,768 | 28.4 GB | 3.5 GB | measured, the default |
|
||||
| 65,536 | 29.0 GB | 2.9 GB | measured, loads |
|
||||
| 98,304 | 29.6 GB | 2.3 GB | measured, loads |
|
||||
| 131,072 | 30.3 GB | 1.5 GB | **measured, the practical ceiling**: a 104,798-token prompt (79% of the window) read in 247 s at 424 tok/s, then answered |
|
||||
| 163,840 | ~31.0 GB | ~0.9 GB | not attempted: under the 1.2 GB safety margin |
|
||||
| 262,144 | ~32.6 GB | none | **does not fit - asking for it took the host down** |
|
||||
|
||||
**Do not ask for more than fits.** On this driver a GPU allocation past VRAM does not fail: the xe
|
||||
driver evicts buffers into host RAM, the kernel runs out of memory, and the machine livelocks until
|
||||
its hardware watchdog resets it. A 262K request did exactly that on 2026-09-29, and llama.cpp's own
|
||||
"failed to fit params" check fired too late to prevent it. Compute the KV size first and leave
|
||||
1.5 GB free.
|
||||
|
||||
Prompt reading gets faster with size, because the work batches better: ~150 tok/s on a 2.7k-token
|
||||
prompt, 424 tok/s on a 105k-token one. So a full 128k window costs about five minutes to read,
|
||||
not fifteen.
|
||||
|
||||
## The engine itself on Intel: the SYCL port (`sycl/`)
|
||||
|
||||
Everything above runs the model through llama.cpp. This is the other half: PolyStrata's own engine - the 50 CUDA
|
||||
kernels and the host code that drives them (streams, events, graph capture, pinned memory) - built for the
|
||||
Arc with oneAPI. It is a migration of the tree, not a new backend: the engine has no backend seam to slot
|
||||
into.
|
||||
|
||||
**Layout.** `sycl/src` and `sycl/include` mirror the tree and hold only the files the port changes; the
|
||||
SYCL build (`sycl/CMakeLists.txt`) takes every other source from the original location. No upstream file
|
||||
is edited. `sycl/include/dpct/` is the vendored SYCLomatic helper library, so the port builds without the
|
||||
migration tool.
|
||||
|
||||
**How it was made, so it can be redone.**
|
||||
|
||||
1. `sycl/tools/Dockerfile` - the dev image: the llama.cpp SYCL image plus SYCLomatic (`dpct` 2025.3),
|
||||
ninja, and the CUDA 12.8 headers that `sycl/tools/get-cuda-headers.sh` pulls out of NVIDIA's pip wheels
|
||||
(dpct parses CUDA; it needs the headers, not the toolkit).
|
||||
2. `sycl/tools/migrate.sh` - writes a compilation database for the 86 CUDA-touching translation units and
|
||||
runs dpct over them. 85 migrate; dpct reports no line it could not migrate, and about 1,400 advisory
|
||||
notes.
|
||||
3. `sycl/tools/fixups.py` - what dpct got wrong or could not do, as an idempotent script with a reason per
|
||||
item. The ones that mattered:
|
||||
- CUDA's null stream means the default stream; dpct turned it into a null `sycl::queue*`. Every
|
||||
stream cast now goes through `strata::q_of()` (`sycl/include/strata/sycl_queue.hpp`).
|
||||
- `__ldg((const float*) p)` came out as `*p`, reading one byte of a float scale (two sites, s_gemv).
|
||||
- `__fadd_rn(a, b ? c : d)` lost its parentheses (two sites).
|
||||
- the ggml lookup tables were threaded through kernel parameters with the wrong table per template;
|
||||
they are plain `static const` arrays read from device code, as ggml-sycl does.
|
||||
- helper headers renamed since dpct 2025.3 (`entangle`, `chunked_partition`), graph introspection and
|
||||
`cudaGraphUpload` (no SYCL equivalents), `%globaltimer` (the stage profiler reads zeros).
|
||||
4. `sycl/tools/build.sh` - configure + build with icpx inside the image. Two compiler flags are load-bearing:
|
||||
`-fp-model=precise` (icpx defaults to a fast FP model) and `-cl-fp32-correctly-rounded-divide-sqrt`
|
||||
for the device compiler - the Arc's fp32 divide is not correctly rounded by default (OpenCL allows
|
||||
2.5 ulp), and PolyStrata's quantizers are byte-exact against ggml through `amax / 127`. Measured: without
|
||||
it `quantize_act_parity` has 303k mismatches, with it none.
|
||||
|
||||
**Where it stands (2026-09-29).** The whole tree builds and links: the `strata` binary and 22 kernel
|
||||
parity tests. On the B70, 19 of the 22 pass byte-for-byte or within their tolerances; the other three
|
||||
need model fixtures (`iq_parity`, `ple_parity`) or the tensor-core kernel below (`qsa_prompt_attn`).
|
||||
|
||||
| parity test | result |
|
||||
|---|---|
|
||||
| bf16_gemv, cvec, dequant_s2, elementwise, gdn, gr, kv_q4, kv_q8, kv_stream, qsa, quantize_act, rope, router_top10, s2_gemv, s2_gemv_q8, s_gemv, s_gemv_q8k, sampler, shared_expert | pass |
|
||||
| iq_parity, ple_parity | `ctest` generates the `iq_parity` fixtures into the build tree (`iq_parity_fixtures`, needs python3 with numpy; skipped without). `ple_parity` needs the Q2_0 shard 2 GGUF and the dense pack: configure with `-DSTRATA_PLE_GGUF=<shard 2 .gguf>` (and `-DSTRATA_PLE_FIXTURE_DIR=<dir with ple_in.bin and ple_out.bin>`); a missing input is a hard error, as in the CUDA build (#1795) |
|
||||
| qsa_prompt_attn_parity | needs the tensor-core kernel (below) |
|
||||
| kv_hybrid_parity (0.1.27, hybrid K8V4 KV) | appends, gathers and attention pass; its last step is that same tensor-core kernel |
|
||||
|
||||
**The engine end to end (2026-09-29, later the same day).** It generates. Prompt "Write a Python function
|
||||
that returns the n-th Fibonacci number", greedy, 64 tokens:
|
||||
|
||||
> `<think>` The user wants a Python function that returns the n-th Fibonacci number. Let me consider the
|
||||
> options: 1. **Recursive approach** - Simple but O(2^n) time complexity, very slow for large n. 2.
|
||||
> **Iterative approach** - O(n) time, O(1) ...
|
||||
|
||||
Measured on the same card, same 2,185-token prompt, 64 greedy tokens (AOT build, `--spec 2`,
|
||||
`--no-prefill-borrow`), against llama.cpp's SYCL build serving the same GGUF:
|
||||
|
||||
| | llama.cpp SYCL | PolyStrata SYCL port |
|
||||
|---|---|---|
|
||||
| prompt reading | 138-319 tok/s | **560 tok/s** (693 at 2,000 tokens, 180 at 300) |
|
||||
| decode, suffix drafter only (`--spec 2`) | 24.2-26.0 tok/s | 20.2-20.8 tok/s |
|
||||
| decode with the MTP draft layer (`--spec 4 --mtp`) | - | **42.7 tok/s** at the 2,185-token context (81% accepted, 2.9 tokens/round); 45.3 on a short prompt |
|
||||
|
||||
Prompt reading is where PolyStrata's design pays (oneMKL GEMM over dequantised experts, the whole model on
|
||||
the card). Decode is at ~80%: a speculative round costs ~53 ms whatever its size and the suffix drafter
|
||||
is accepted 9% of the time, so nearly every round yields one token; `--spec 4` (16.9 tok/s) was worse
|
||||
than `--spec 2` (20.8) for that reason. The kernels themselves run at 130-160 GB/s of weights on a card
|
||||
that streams 600 GB/s (`sycl/probe/bw.cpp`, incompressible data) - the same class llama.cpp reaches -
|
||||
and five variants of the hot Q6_K matvec (lanes per row, rows per warp, unroll, 16-byte loads, software
|
||||
pipelining; `mmvq_bench`) all landed in that band. The draft source was the lever: the base
|
||||
Qwen3.8-Flash-Next checkpoint's MTP layer (`tools/mtp_fetch.py fetch`, `mtp_pack.py --experts q2_0`,
|
||||
`mtp_rt.py`; 4.9 GB downloaded, 809 MiB of VRAM) drafts for the Coder fine-tune at 87% acceptance:
|
||||
3.4 tokens per 53 ms round, 45 tok/s, the same greedy tokens. The `mtp.cpp` path ran on the first try
|
||||
under the same flags.
|
||||
|
||||
Without AOT the runtime JIT-compiles every kernel on first use, ~47 s the first time a process runs;
|
||||
`SYCL_CACHE_PERSISTENT=1 SYCL_CACHE_DIR=<dir>` keeps that across runs (15 MB).
|
||||
|
||||
How to run it by hand (a greedy test run, the way every number in this section was measured; inside the
|
||||
`strata-sycl-dev` image, AOT build in `build-sycl-aot/`):
|
||||
|
||||
```
|
||||
STRATA_VERIFY_DEVICE_PLAN=1 STRATA_VERIFY_NO_HOST=1 \
|
||||
build-sycl/strata --pack <iq pack> --native <shard1> --ple-gguf <shard2> \
|
||||
--expert-profile data/expert-profile-coder.bin --expert-cache auto --stream-experts \
|
||||
--prefill auto --spec 4 --spec-min-p 0.5 --max-context 8192 --tokens <ids> --max-new 64 --greedy
|
||||
```
|
||||
|
||||
- `--stream-experts` (this port): no resident host copy of the experts; every one of the 12,288 goes from
|
||||
the GGUF into the VRAM cache through a small staging ring (`GgufExpertSource`). Upstream needs 32 GB of
|
||||
RAM for this model; with the flag the engine runs on 23 GiB.
|
||||
- `STRATA_VERIFY_DEVICE_PLAN=1`: the GPU plans each layer itself (upstream's E-6; off by default there).
|
||||
- `STRATA_VERIFY_NO_HOST=1` (this port): the host waits for the whole window graph instead of per-layer
|
||||
rings. Only valid with every expert resident, which is the case on a 32 GB card.
|
||||
- `--no-prefill-borrow`: the prompt path must not lend expert slots (a lent expert is served from the host
|
||||
behind a flag the GPU does not see reliably here; long prompts hung without it).
|
||||
|
||||
What the port had to get right beyond compiling (each is an entry in `sycl/tools/fixups.py` or a flag):
|
||||
|
||||
- **Host-mapped flags.** PolyStrata's decode is a GPU/CPU handshake through host-mapped memory. `volatile`
|
||||
device loads do not bypass the caches on Intel; system-scope atomics do, and they are the only thing
|
||||
measured to work (`sycl/probe/doorbell.cpp`, six variants). Host-to-device visibility *during* a kernel
|
||||
stays unreliable on this platform, which is why the all-resident path waits for the window instead.
|
||||
- **Bounded spins.** A device spin that never sees its flag is not a hang of one process: the xe driver
|
||||
times the queue out and resets the GT node by node - a window graph has 2,400 - and the card stays
|
||||
wedged until a reboot (twice). Every spin is capped (`kSpinMax`).
|
||||
- **32-lane sub-groups.** The kernels are written for warps; dpct pinned 134 of 289 launches, the rest
|
||||
would run at Xe2's default 16 (`-fsycl-default-sub-group-size=32`).
|
||||
- **Synchronous copies.** `cudaMemcpy` blocks; dpct's default-queue `memcpy` did not wait. With the
|
||||
streaming ring that filled the expert cache from overwritten buffers: non-deterministic residuals, NaN by
|
||||
layer 5. Found with the per-layer residual ladder (`STRATA_VERIFY_DEBUG=1` prints R after every layer).
|
||||
- `native_expert_parity` hand-ported: the GPU native expert kernel matches ggml's float reference on real
|
||||
IQ1_M rows (rel 1.1e-2, the same class as the CPU path).
|
||||
|
||||
Profiling: `sycl/tools/Dockerfile.unitrace` builds the dev image with Intel's unitrace; `unitrace -d` around
|
||||
the engine plus `sycl/rank_kernels.py` gives device time per kernel. `mmvq_bench` and `native_expert_parity
|
||||
NATIVE_BENCH=1` time the two hot kernel families in isolation (warm the clocks first: a 5 ms run measures
|
||||
the ramp, not the kernel).
|
||||
|
||||
**After the 0.1.25-0.1.27 merge (2026-09-30, same card, same flags, AOT).** Fibonacci prompt (19 tokens),
|
||||
64 greedy tokens: decode 46.5 tok/s (85% of drafts accepted). The 2,184-token prompt: 566 tok/s prompt,
|
||||
38.3 tok/s decode (77% accepted on that text); the draft layer's prompt pass is now upstream's batched one
|
||||
(38.6 ms for 2,184 tokens, from 105 ms for 19 before it). Parity: 19 of 22, byte-exact `quantize_act` back.
|
||||
|
||||
**Speed work, 2026-09-30 (after the 0.1.27 merge).** What moved the numbers, measured on the B70 with the
|
||||
same prompts as above (outputs identical before and after each change):
|
||||
|
||||
| change | effect |
|
||||
|---|---|
|
||||
| every window graph and the drafter's graphs captured at load (`STRATA_WARM_GRAPHS=0`: as before) | the first request no longer pays 250-290 ms of captures |
|
||||
| the commit graph left running while the drafter's round runs on its own queue (`Verifier::commit(wait=false)` + `commit_finish`) | decode 38.3 -> 43.0 tok/s at the 2,184-token context, 46.5 -> 49.8 short |
|
||||
| upstream 0.1.29 merged (GDN recurrence pipelining, the block-scores read, sampler) | 2,184-token prompt 765 -> 792 tok/s, decode at that context 43.1 -> 45.2 |
|
||||
| the draft layer's batched prompt pass takes prompts under 64 rows (it fell back to per-6-token graphs) | its prompt cost on 19 tokens 106 -> 16 ms |
|
||||
| one device module per kernel (`-fsycl-device-code-split=per_kernel`) | the first launch in the prompt path (the embedding gather) 245 -> 1 ms |
|
||||
| the expert dequant writes each thread's run of FP16 values as one vector store (it wrote them one 2-byte store at a time) | dequant per expert 0.085 -> 0.030 ms; prompt 496 -> 575 tok/s at 2,184 tokens, 720 -> 841 at 8,000 |
|
||||
| SWAR sign compare/subtract in the expert dots, a local-memory resident-plan kernel, a split-K fused down kernel (bit-identical to the single-token one) | parity-clean, no measurable decode change; kept |
|
||||
| the PLE row reader's default queue depth 16 -> 64 blocking O_DIRECT threads (`STRATA_IO_THREADS`; 128 and 256 change nothing: the drive tops out near 85k IOPS on the 27k random 4 KB reads a 2,184-token prompt needs) | the rows of that prompt 466 -> 330 ms |
|
||||
| a short first prompt chunk (`STRATA_PREFILL_FIRST`, default 256 tokens) so the GPU starts while the remaining rows are still being read | 2,184 tokens: 711 -> 765 tok/s, 8,000: 857 -> 986; time to first token about 150 ms less. The chunk boundary moves rounding in the expert GEMMs, so a long greedy continuation can diverge late (token 45 of 64 on the test prompt) |
|
||||
|
||||
Draft policy sweep (2,184-token prompt, 128 tokens): windows of 6 (`--spec 4`) at 41.6-43.5 tok/s; `--spec 2`
|
||||
33.6, `--spec 6` 35-37; `--spec-min-p` 0.3-0.7 within noise. Profiles (unitrace, `strata-sycl-dev:metrics` with
|
||||
Intel's metrics libraries and `dev.xe.observation_paranoid=0`): the expert dot kernels are ALU-bound (77% XVE
|
||||
active), the dense projections memory-latency bound (92-128 GB/s at 84-93% occupancy), a decode round is 80-85%
|
||||
kernel time and ~5 us of launch gap per node over 2,400-2,600 nodes.
|
||||
|
||||
**XMX.** oneMKL's FP16 GEMMs already run on the XMX units (30-60 TFLOP/s in `xmx_gemm_bench`); the prompt path is
|
||||
bound by the dequant that feeds them, not by the products. Two joint_matrix kernels were written and are correct
|
||||
but lose to the existing paths on this card, so both stay opt-in: `xmx_gemm_iq` (a fused dequant + GEMM straight
|
||||
from the quantized rows, 4-5x slower than dequant + oneMKL) and `qsa_prompt_attn_xmx` (the port of the mma.sync
|
||||
prompt attention; `qsa_prompt_attn_parity` passes at 1e-6 of scale, 3x slower than the FP32 fallback per chunk;
|
||||
`STRATA_PROMPT_ATTN_XMX=1`). Where the prompt time goes now (2,184 / 8,000 tokens): dequant 28% / 27%, GEMMs
|
||||
22% / 20%, the per-layer host grouping 9.5% / 9%, attention 7% / 14%, embeddings + PLE rows 13% / 5%.
|
||||
|
||||
A trap worth knowing: with a native pack `--prefill-until N` does not feed the rest of the prompt through the
|
||||
token loop (it is skipped for native packs), so the tokens after N are dropped and the model free-runs. Compare
|
||||
output tokens between paths, never only timings.
|
||||
|
||||
**An 80,000-token prompt (2026-09-30).** Where the time goes changes completely at this scale:
|
||||
|
||||
- **The VRAM plan.** `--expert-cache auto` fills the card down to `--vram-reserve-mib` *before* the KV state
|
||||
(about 1 GB in INT8 at 81,920 cells) and the prompt chunk buffers (about 2 GB at `--prefill 8192`) exist. With
|
||||
the 1,536 MiB default that put 30.95 of the B70's 32.6 GB in use, the driver started migrating buffers and the
|
||||
run never finished. `--max-context 81920 --kv int8 --vram-reserve-mib 3072 --prefill 4096` peaks at 28.8 GB.
|
||||
(80k ids also exceed Linux's 128 KB single-argument limit: `--tokens-file`.)
|
||||
- **Streamed experts.** The reserve costs cache slots (10,348 of 12,288 at 3 GB), and the prompt path streams the
|
||||
missing experts from the GGUF for every chunk. Two port bugs sat on this path and are fixed: the stream plan
|
||||
held `GgufExpertSource::blob()` pointers across ~1,900 reads of a 512-slot ring (so blobs were overwritten
|
||||
before they were copied: the 75 s / 1,065 tok/s measured first was computed partly with the wrong experts), and
|
||||
the stream-all walk hangs on this card in its first large chunk (the copy engine stops on a barrier). The stager
|
||||
threads now read the blobs themselves, and the port uses the per-layer routed-only walk (`STRATA_PREFILL_RING=8`
|
||||
upstream, the port's default; `STRATA_PREFILL_STREAM_ALL=1` restores the other for debugging).
|
||||
- **Correct result: 80,000 tokens in 101 s = 790 tok/s.** GPU time: expert down GEMM 26.0 s, attention 15.4 s,
|
||||
dequant 12.7 s, QSA block selection 9.3 s (0.2 s at 8k: it scans every block of the context per query), gate/up
|
||||
GEMM 8.9 s, gather 6.1 s, the per-layer grouping sync 5.2 s, GDN recurrence 4.8 s. The PLE rows are free at this
|
||||
scale (97.6% row-cache hits).
|
||||
- **Decode after such a prompt, and the fix.** Without lending cache slots to the prompt path (`--no-prefill-borrow`,
|
||||
which the port used from the start) the reserve evicts ~1,900 experts for good and decode after the prompt runs at
|
||||
2 tok/s. Borrowing lends ~940 slots to the prompt path and refills them in about a second afterwards: 80,000
|
||||
tokens in 75 s = **1,062 tok/s, decode 35-40 tok/s** after it, at `--vram-reserve-mib 2048 --prefill 4096`.
|
||||
It costs ~1 s on short prompts (2,184 tokens: 610 vs 792 tok/s), so the port borrows by default only above a
|
||||
32K context (`--prefill-borrow` / `--no-prefill-borrow` decide explicitly).
|
||||
|
||||
**Long contexts (2026-10-01, engine 0.1.32-sycl, setup's flags: `--kv-resident 32768 --vram-reserve-mib 2048
|
||||
--prefill 4096`, the prompt path borrowing cache slots - the default above 32K).** Same text repeated to length,
|
||||
then 256 greedy tokens:
|
||||
|
||||
| context | KV | prompt | decode after | peak VRAM | experts in the host mirror |
|
||||
|---|---|---|---|---|---|
|
||||
| 128K | int8 | 888 tok/s (144 s) | **66.6 tok/s** | 29.9 GB | none |
|
||||
| 128K | q4_0 | 848 tok/s (151 s) | 62.8 tok/s | 29.7 GB | none |
|
||||
| 128K | k8v4, KV in VRAM | **1,006 tok/s** (127 s) | **66.8 tok/s** | 30.7 GB | 103 (0.2 GB) |
|
||||
| 256K | int8 | 757 tok/s (338 s) | **55.9 tok/s** | 30.2 GB | none |
|
||||
| 256K | q4_0 | 737 tok/s (347 s) | 51.7 tok/s | 30.0 GB | none |
|
||||
| 256K | k8v4, KV in VRAM | 823 tok/s (311 s) | 52.2 tok/s | 30.9 GB | 865 (1.7 GB) |
|
||||
|
||||
Borrowing keeps every expert in VRAM (the prompt buffers live in lent cache slots, refilled after the prompt).
|
||||
Without it (`--no-prefill-borrow`) the buffers keep their own VRAM and ~1,000-2,300 experts move to the pinned host
|
||||
mirror: the prompt is 2-5% faster, decode after it 10-23% slower (0.1.31 without borrowing: 128K int8 934 / 59.5,
|
||||
q4_0 887 / 53.4, k8v4 1,026 / 54.4; 256K int8 784 / 48.7, q4_0 763 / 43.2, k8v4 838 / 42.3 tok/s).
|
||||
|
||||
KV streaming (`--kv-resident`) keeps the whole KV in pinned host memory and only the attended window in VRAM, so
|
||||
the KV pushes no experts out; setup.py turns it on from 64K up and keeps INT8 (the faster of the
|
||||
two at every size here). Without it the KV pushes experts out and decode after the prompt fell to 4-9 tok/s at
|
||||
128K-256K (2026-09-30). `--kv k8v4` does not support streaming yet: setup keeps its KV in VRAM, which pushes up to
|
||||
more experts out; those come from the pinned host mirror over PCIe (planned item 2), so decode holds at 42 tok/s at
|
||||
256K (it was 3.8 before the mirror). k8v4 reads prompts fastest (no streaming copies) and works through the FP32
|
||||
attention fallback (its dedicated prompt kernel is the XMX one below).
|
||||
|
||||
**XMX prompt attention v2.** 64-cell chunks, vector-packed K^T and V, hi+lo Q in one accumulator per scale group,
|
||||
one accumulator update per chunk: 1.4-1.5x faster than v1 and correct in all modes (`qsa_prompt_attn_parity`,
|
||||
and `kv_hybrid_parity` passes completely with it), but still ~2x slower than the FP32 fallback (13.4 vs 5.5 ms per
|
||||
chunk, INT8, 32K context). This attention is gather-bound: each query position selects its own ~2,000 cells, so
|
||||
the K/V fetch dominates and only 12 of the 16 matrix rows are real heads. Opt-in: `STRATA_PROMPT_ATTN_XMX=1`
|
||||
(64-cell chunks, 120 KB of local memory) or `=32`.
|
||||
|
||||
**XMX v2 in the full matrix, and why a grouped kernel is not next (2026-09-30).** With `STRATA_PROMPT_ATTN_XMX=1`
|
||||
(stage timing on, ~8-10% overhead) the long prompts run 23-33% slower than with the FP32 attention: 128K int8 666 vs
|
||||
960 tok/s, k8v4 596 vs 983; 256K k8v4 506 vs 752, int8 536 vs 718 (q4_0 does not use the XMX kernel). The obvious
|
||||
fix, gathering the union of neighbouring positions' cells once, depends on how much their selections overlap.
|
||||
Measured on the last chunk of an 80K prompt (first QSA layer, `STRATA_DUMP_SEL=<file>`): the union of 8 consecutive
|
||||
positions is 3.3x one position's 2,051 cells (16: 5.1x), and only 12% of a selection is shared by all 8. Grouping
|
||||
would cut the K/V gather to ~40% but multiply the arithmetic by 3-5x: at best 5-8 s of an 80K prompt. Not built.
|
||||
|
||||
**Serving the port (2026-09-30).** `serve/server.py --engine strata` runs the SYCL engine unchanged through
|
||||
`sycl/serve/strata-sycl.sh`, an `exe` that starts the binary inside the oneAPI runtime image with the serve pipes
|
||||
attached (paths in the config's `args` are the container's, the data root mounted at `/work`). A config:
|
||||
|
||||
```json
|
||||
{"engine": "strata", "exe": "<repo>/sycl/serve/strata-sycl.sh",
|
||||
"args": ["--pack", "/work/pack", "--native", "<shard 1>", "--ple-gguf", "<shard 2>",
|
||||
"--expert-profile", "data/expert-profile-coder.bin", "--expert-cache", "auto", "--stream-experts",
|
||||
"--prefill", "auto", "--spec", "4", "--spec-min-p", "0.5", "--mtp", "/work/mtp/rt",
|
||||
"--max-context", "32768", "--kv", "int8", "--vram-reserve-mib", "1024"],
|
||||
"sampling": {"temperature": 0.6, "top_p": 0.95, "top_k": 20, "repetition_penalty": 1.05}, ...}
|
||||
```
|
||||
|
||||
Measured through the OpenAI API with those sampling defaults: 36 tok/s decode on a first turn, 33 on a follow-up
|
||||
(which reuses the conversation's cached prompt), against 24-26 for llama.cpp on the same card. After the decode work
|
||||
(2026-10-01 build): 48-72 tok/s on a ~190-token answer, prompt included (the first request after a start is the slower
|
||||
one); 55-59 tok/s over 5,000-18,000-token answers on the 2026-09-30 build. The reserve matters:
|
||||
with `--stream-experts` there is no host copy of the experts, so any expert left out of VRAM is read from the SSD
|
||||
and computed on the CPU whenever it is routed. At 1,536 MiB the cache came up 128 experts short and decode fell to
|
||||
5-10 tok/s; 1,024 MiB fits all 12,288 with 2 GB of VRAM still free.
|
||||
|
||||
**Logprobs (2026-10-02).** `/v1/chat/completions` takes OpenAI's `"logprobs": true` and `"top_logprobs": 0..20`,
|
||||
streamed or not, through `sycl/serve/server_intel.py`; the reply carries `choices[0].logprobs.content[]` (`token`,
|
||||
`logprob`, `bytes`, `top_logprobs`), and with thinking on the thinking tokens under `reasoning_content`. The engine
|
||||
(the port only) gets `logprobs=K` on its GEN line and writes an `LP logprob id:logprob ...` line after each `T`
|
||||
line, from the verify window's head logits - the distribution the token was taken from, before temperature,
|
||||
penalties and sampling. Upstream's server ignores the lines, and an engine never asked writes none. Each token
|
||||
costs one 1 MB logits row copy when asked. Measured (IQ2_XS, "capital of France"): "Paris" at -0.0019 (p 0.998), the
|
||||
same answer and no measurable time without it. Not on `/v1/completions` or the Anthropic endpoint yet.
|
||||
|
||||
**The Monitor tab on Intel.** `sycl/serve/server_intel.py` is `serve/server.py` with two additions made at run
|
||||
time:
|
||||
|
||||
- **GPU readings.** When NVML has no card, it plugs `sycl/serve/xe_telemetry.py` into `serve/telemetry.py`'s
|
||||
`gpu_reader`. That reads the Arc through sysfs (temperature, power and its cap, the PCIe link the card
|
||||
trained at). Load and VRAM come from `/run/gpustat.json`: xe reports them per client in `/proc/*/fdinfo`,
|
||||
which only root can read, so a small root sampler writes them (`sycl/tools/gpustat.py`; install it with its
|
||||
`gpustat.service` as its header says).
|
||||
- **A Model menu.** A run config may name a `model_switcher` (an RPC taking `{"mode": m}`) for a host that swaps
|
||||
models on one card. The web app's header then gets a Model menu (`sycl/serve/web/switcher.js`, injected into
|
||||
the page).
|
||||
|
||||
**Speed depends on the text.** Decode with speculative decoding tracks how often the draft layer guesses right.
|
||||
The served engine at 32K context: 45-51 tok/s on the test prompt (continuing a Fibonacci function, 77-85%
|
||||
of drafts accepted), 30-39 tok/s on a chat answer with prose (55-72%); sampling and the repetition penalty cost
|
||||
nothing measurable. The engine used to abort at exit in serve mode (a queue wait in a destructor after the
|
||||
runtime's teardown began); it now exits directly once its requests are done.
|
||||
|
||||
**Planned (2026-09-30), in order.** Ranked by payoff on this card; the first three were taken first.
|
||||
|
||||
1. Expert dot products on XMX in integer mode: a decode window (up to 6 tokens) fits one INT8 DPAS (1-8 rows), the
|
||||
i-quant grids decode to small integers, the activations are already INT8. Today: scalar dp4a, ALU-bound (77%).
|
||||
**Parked**: three `joint_matrix` versions (opt-in `STRATA_EXPERT_XMX=1`, do not enable) were 1.4x and 2-3x slower
|
||||
than dp4a, and the third (B filled in place with `joint_matrix_apply`) hung the GPU. At 1-6 rows the grid decode
|
||||
and the packed-B layout cost more than the DPAS saves.
|
||||
2. Experts missing from VRAM read from pinned host memory over PCIe instead of the SSD (the 256K decode collapse).
|
||||
**Done**: at start-up every expert without a VRAM slot is read into a pinned host mirror (`STRATA_MIRROR_MIB`, by
|
||||
default free RAM less 4 GiB), and the device-built verify plan points the expert kernels straight at it. Before,
|
||||
that plan dropped non-resident experts, so output with misses was wrong. Forced test (`--expert-cache 8000`,
|
||||
1,879 experts / 3.6 GiB out of VRAM): decode 2.6 -> 40.9 tok/s (full cache 43.3), prompt 451 -> 640 tok/s
|
||||
(776), output tokens identical to the full-cache run. About 3.6 GiB of VRAM can go to context for ~6% of decode.
|
||||
3. KV streaming (`--kv-resident`) from 64K up: only the attended window of the KV in VRAM. **Done**: 256K decodes at
|
||||
31 tok/s (from 4-5).
|
||||
4. QSA block selection on XMX: every query against every pooled block, a dense product that grows with the context.
|
||||
5. The hot decode kernels re-tuned for Xe2's native 16-wide sub-groups (twice the registers per thread).
|
||||
**Tried, no gain**: SIMD16 builds of the multi-column mmvq and the wide Q6_K kernel (`STRATA_MMVQ_SG`: 16 all,
|
||||
1 IQ4_XS only, 2 short outputs only; default 32). Alone (`mmvq_sg_bench`) SIMD16 is up to 1.45x faster on IQ4_XS
|
||||
and 1.3x on the 640-row shared-expert projections, 10-25% slower on the large K-quant ones; in the engine no
|
||||
setting beats SIMD32 beyond run-to-run noise (SIMD32 itself lands at 39 or 45 tok/s). Output tokens identical.
|
||||
The same bench shows the real headroom: the dense decode kernels stream 100-280 GB/s of a 608 GB/s card
|
||||
(Q6_K, the most common type, ~146 GB/s at 2-4 columns).
|
||||
**Found and fixed: misaligned loads.** A Q6_K block is 210 bytes, so every block's `ql`/`qh` runs start only
|
||||
2-byte aligned, and the B70 splits a misaligned 16-byte load into pieces. The same weights repacked at a
|
||||
224-byte stride ran 2.3-4.7x faster (`q6k_align_bench`). Without changing the layout, the wide Q6_K kernel now
|
||||
does two aligned 16-byte loads and a shift (`load16_a2`; both stay inside the block) and takes every Q6_K
|
||||
shape and window width (it used to be gated to n_out >= 4096, 1-4 columns): 2560->10240 at 1/2/4/6 columns
|
||||
160/145/141/101 -> 493/432/331/273 GB/s, the 248K-row head 150 -> 407 GB/s at 1 column. Output tokens
|
||||
identical. **Coder decode 44.9 -> 54 tok/s** (2k prompt, greedy). `STRATA_MMVQ_A2=0` restores the old path.
|
||||
Still misaligned: IQ4_XS (136 B, 8-aligned, ~100 GB/s), IQ4_NL (18 B), Q8_0 (34 B); Q4_K/Q5_K are aligned
|
||||
but use 4-byte loads in the multi kernel (230-280 GB/s).
|
||||
|
||||
**Decode round 2 (2026-09-30), from a unitrace of 256 decoded tokens.** Each step measured on its own, 19-token prompt,
|
||||
256 tokens, two runs each, output tokens identical throughout:
|
||||
|
||||
| | decode |
|
||||
|---|---|
|
||||
| after the Q6_K alignment fix | 53.9 tok/s |
|
||||
| + `resident_plan` grouping in parallel (thread 0 alone took 73 us per layer, ~3.5 ms a round) | 57.1 |
|
||||
| + the GR down kernel reads the activations directly (the 60 KB SLM tile per group capped occupancy) | 58.7 |
|
||||
| + wide 16-byte-load kernels for Q4_K, Q5_K, IQ4_XS (codebook in registers) | 62.6 |
|
||||
| + wide kernels for Q8_0 (MTP dense, shexp down of layer 0) and IQ4_NL (shexp down); Q6_K's activation loads aligned | 65.6 |
|
||||
| + the GR down projection sliced by columns (each group stages one 128-column slice of xn, 4 lanes per row) + a fixed-order reduce | 70.6 |
|
||||
| + IQ4_NL expert dots (the down projection in 39 of 48 layers): codebook in registers, weights as aligned 4-byte loads, bitwise the same ints (2026-10-01) | 76.1 |
|
||||
| + GR norm per (token, stream), bitwise the same; aligned weight loads in the IQ3_XXS/IQ3_S/IQ2_S gate/up dots | **77.9** |
|
||||
|
||||
The last step changes the output: identical for 146 tokens, then a near-tie after a comma goes the other way (the new
|
||||
kernels sum in a different order). Q8_0 kernels 4-6x (189 -> 31 us at 2560 x 10240, 2 columns), IQ4_NL 640 -> 2560
|
||||
28 -> 6.6 us. The aligned-load helper only loads its second chunk when the address is unaligned, so it never reads a
|
||||
16-byte chunk without a needed byte and cannot cross a page at the end of an allocation. `STRATA_MMVQ_WIDE_32=0`
|
||||
restores the old Q8_0/IQ4_NL kernels. The sliced GR down kernel (GR read 108.6 -> 76.5 us at 6 tokens, sums equal to
|
||||
~1e-7) flips that near-tie back: its output is the original one. `STRATA_GR_DOWN_SLICED=0` restores the direct kernel.
|
||||
|
||||
Kernel level: IQ4_XS 107 -> 323 GB/s at 2 columns (61 -> 212 at 6), Q4_K/Q5_K 1.3-1.6x; the GR read 135 -> 110 us at
|
||||
6 tokens (bitwise equal). Switches to the old paths: `STRATA_PLAN_PARALLEL=0`, `STRATA_GR_DOWN_DIRECT=0`,
|
||||
`STRATA_MMVQ_WIDE_K=0`. (`iq_parity` reports 10 "missing fixture" failures with and without the change: the oracle
|
||||
fixtures are not in the port's tree.)
|
||||
|
||||
`STRATA_IQ3S_WIDE=1` (opt-in, 2026-10-10) reads the dense IQ3_S matrices (attn_q, attn_gate, ssm_out, attn_k, the
|
||||
shared experts' gate/up) with a wide kernel shaped like the Q4_K..IQ4_XS ones. unitrace, B70, IQ3_XXS, one card, T=1:
|
||||
worst attn_k 77 -> 123 GB/s, best attn_q 114 -> 307 GB/s; these matrices take 0.60 ms of kernel time per token
|
||||
instead of 1.36 ms. The greedy output parts from the default at token 198 of 256 (the sub-blocks are summed in
|
||||
another order). Measured again for 0.1.45 (B70, IQ3_S, stock-like config, 5 interleaved pairs): decode 33.39 -> 33.29 tok/s
|
||||
(-0.3%), 4K prompt 40.71 -> 40.79, so it stays opt-in; the gain the author reports is on two cards.
|
||||
|
||||
**Q6_K decode kernels (0.1.45, #2340 leadgtr7, #2207 Andy Slater).** The Q6_K wide kernel took its six-bit offset (v - 32)
|
||||
through a per-byte saturating subtract; it is now four integer ops (bitwise equal), and the Q4_K / Q5_K / IQ4_XS / Q6_K
|
||||
kernels load the Q8_1 activations as one dword-vector. No switch. mmvq_bench Q6_K, B70: 2560x10240 1 column 44.7 -> 26.5 us,
|
||||
4 columns 64.5 -> 46.2; A750: 2560x10240 4 columns 251 -> 102 us. End to end on the B70 (IQ3_S, 5 interleaved pairs, answers
|
||||
identical): decode 32.24 -> 33.37 tok/s on a story prompt (+3.5%), 39.11 -> 40.77 after a 4K prompt (+4.2%), prompt rate unchanged.
|
||||
`STRATA_MMVQ_LARGE_GRF` (default on for Arc A-series only, `=1` forces it on, `=0` off) launches the 2-8 column wide kernels with
|
||||
256 registers per thread, where they spilled at 128 (the same bytes are produced either way). `STRATA_Q6_PLANAR` (default on,
|
||||
`=0` off) converts the Q6_K output head and the MTP draft head to ql / qh / scales / d planes at load (same bytes, no VRAM change,
|
||||
bitwise equal): 2560x248320 on a B70 800 -> 662 us (1 column), 1230 -> 1020 us (4 columns); end to end it adds +0.3% on the B70
|
||||
(33.16 -> 33.25 tok/s, within noise) on top of the kernel changes above.
|
||||
|
||||
**Two-speed runs, explained (2026-09-30).** Identical greedy runs decode at either ~45 or ~39 tok/s. A per-gather
|
||||
trace of the PLE reader (`STRATA_PLE_TRACE=1`) shows the slow runs pay one 226 ms PLE read stall in the first
|
||||
decode round, after the window graphs are captured; every other read and round matches the fast runs. Prompt time
|
||||
plus decode time is the same in both modes (4.95-5.17 s): the stall lands either in the prompt's PLE wait or in the
|
||||
first decode round, so it is a once-per-process cost, not lost throughput. Ruled out: NVMe APST, the I/O scheduler
|
||||
(`none`), CPU starvation (93% idle during decode), I/O thread count. Compare runs on time to first token + decode.
|
||||
6. INT8 prompt GEMMs: experts dequantized to INT8, oneMKL/oneDNN INT8 on XMX (half the dequant bytes, 2x rate).
|
||||
7. Fewer graph nodes per decode round (~2,500 at ~5 us): norm+rope, scores+top-k, gate+quantize fused.
|
||||
8. Wider speculation (two draft branches per verify window): the kernels are latency-bound, so it is nearly free.
|
||||
9. A model bigger than VRAM: the original Qwen3.8-Flash-Next IQ2_XS (35.5 GB of experts; the same path suits Q2_0
|
||||
and Swift 1.5) on the B70 with 23 GB of RAM. ~24 GB of experts in VRAM, the rest (~10-12 GB) in the pinned host
|
||||
mirror the device plan reads over PCIe (item 2). The port has the IQ2_XS/IQ3_XXS/Q2_0 expert kernels. Open: whether
|
||||
a 10+ GB pinned mirror fits beside everything else in 23 GB, and decode with that share of experts on a Gen3 x8
|
||||
link (3.6 GB mirrored measured 40.9 tok/s; expect less). Needs the 68 GB download.
|
||||
**Done (2026-10-01)**: shard 1 downloaded (39.2 GB; shard 2 is byte-identical to the Coder's, so a hard link),
|
||||
a native pack (`tools/iq_pack.py`, 6 s), the original model's expert profile, the same MTP draft layer. 18,329 of
|
||||
24,576 experts in VRAM (24.6 GiB), 6,247 in the pinned host mirror (8.4 GiB, 9 s to fill), host RAM never below
|
||||
12 GB free. **Decode 50.8 tok/s** on the 19-token prompt and **60.6** after 2,184 tokens, prompt 549 tok/s;
|
||||
coherent, correct answers on both. Q2_0 and Swift 1.5 (similar size) should behave the same; IQ3_XXS/IQ3_S
|
||||
(43-50 GB of experts) would need 19-26 GB mirrored, more than 23 GB of RAM allows.
|
||||
|
||||
**Keeping up with upstream.** A merge of upstream `main` into `b70` leaves the copies in `sycl/` behind
|
||||
wherever upstream touched a file they mirror. They are refreshed by re-migration, not by hand (done for
|
||||
0.1.25-0.1.27, 2026-09-30):
|
||||
|
||||
1. Merge upstream into `b70`. No shared file should conflict: the Intel code is all in `sycl/`. Then check that
|
||||
`sycl/setup_intel.py --check` and `sycl/serve/server_intel.py --engine mock` still run against the new
|
||||
setup.py and server.py.
|
||||
2. Migrate the *old* upstream tree (a `git archive` of the pre-merge commit) with `migrate.sh` into
|
||||
`sycl-base`, and the merged tree into `sycl-new`; about 3 minutes each in the dev image.
|
||||
3. `sycl/tools/normalize.sh <dir> <commit>` on both: dpct's file names, the unchanged files, the
|
||||
message serials, then `fixups.py`. Two runs of dpct on the same source now differ only in the kernel
|
||||
name hashes it generates.
|
||||
4. For every file present in both: `git merge-file sycl/F sycl-base/F sycl-new/F`. Files upstream did not
|
||||
change are left alone. Copies dpct never produced (`verify.cpp`, `mtp.cpp`, `remote_experts.cpp`
|
||||
include no CUDA header directly) take upstream's diff by hand; new parity tests are copied in and
|
||||
listed in `sycl/CMakeLists.txt`.
|
||||
5. A fixup whose pattern upstream changed shows up as a compile error (the PTX gate became an `#elif`
|
||||
under upstream's `__HIPCC__` guard); extend the fixup, re-run it, rebuild.
|
||||
|
||||
**The 0.1.31 merge (2026-10-01).** Upstream 0.1.29 -> 0.1.31 (132 commits) by the steps above: 45 migrated files
|
||||
changed for real (27 more only in dpct's kernel-name hashes), 38 conflicts resolved, verify.cpp/mtp.cpp/
|
||||
conversation_state.cpp ported by hand. A symbol audit (the port's feature identifiers counted before and after) is
|
||||
part of the procedure now: it caught a dropped mirror hook and four doorbell waits that had lost their spin bound
|
||||
(upstream renamed the loops; `fixups.py` covers both spellings). What the merge needed beyond conflicts:
|
||||
|
||||
- **The expert kernels.** Upstream sends the i-quant experts to new multi kernels (one warp per row, 8 rows a
|
||||
group); the port's grid is sized for its own kernels (8 lanes a row, 32 rows a group), so only a quarter of each
|
||||
expert's rows were written and the output was end-of-text tokens. The port's kernels stay the default (they also
|
||||
serve upstream's new Q4_K/Q5_K/Q5_1/Q8_0 experts); `STRATA_EXPERT_SPLIT=1` runs upstream's, with their grid.
|
||||
- **Prompt-slot borrowing hung** in the first chunk of any prompt with it on (40K, 128K; GPU busy) - fixed after
|
||||
the 0.1.32 merge, see "Prompt-slot borrowing: the hang" below.
|
||||
- **Upstream's new tests found three dpct mistranslations from the first migration.** dpct writes `__fadd_rn(a, b)`
|
||||
as `a + b` without parentheses, so `__fadd_rn(sum, c ? x : y)` became `sum + c ? x : y` (replaced, not added): in
|
||||
the native QSA indexer's per-token pooled key (the decode path: blocks completed while generating got wrong
|
||||
pooled keys; prompt blocks come from the batched kernel and were right), in the native QSA scores (an opt-in
|
||||
path) and in the s2 activation rounding (every value 0; the Q2_0 s2 pack, unused here). Fixed, and `fixups.py`
|
||||
now parenthesises. `qsa_parity`'s batch-vs-sequential test passes; decode output after long prompts changed.
|
||||
- **Upstream's new kernels against the port's on the B70** (decode tok/s, Coder 19 / 2,184-token prompts, IQ2_XS
|
||||
19): port defaults 78.1 / 75.7 / 58.6; `STRATA_EXPERT_SPLIT=1` 65.6-69.5 / 67.2 / 49.1 (-11 to -16%);
|
||||
`STRATA_GR_V3=1` 73.2 / 72.4 (-4 to -6%). Both stay opt-in.
|
||||
- **Lanes per row of the port's expert kernels** (`STRATA_GU_LANES` / `STRATA_DOWN_LANES`, 4/8/16/32 at run time):
|
||||
gate/up 8 or 16 x down 4 or 8 all decode in 37.7-38.6 ms per verify round (2 runs each, Coder, both prompts); tok/s
|
||||
differences between them are draft acceptance (each split rounds differently). The default (8 / 8) stays.
|
||||
- **Speed after the merge:** Coder 78.2 / 75.7 tok/s (as before), IQ2_XS 58.6 / 64.2 (from 50.8 / 60.6).
|
||||
- **Still failing:** (`iq_multi_parity` on IQ2_XS: fixed later, see "Two model-specific bugs"), `s2_expert_grouped_parity` (the s2 path), `kv_hybrid_parity`'s last step
|
||||
(needs the unported tensor-core prompt kernel). `ple_parity` and `native_expert_parity` need model files.
|
||||
|
||||
**The 0.1.32 merge (2026-10-01).** Upstream 0.1.31 -> 0.1.32 (89 commits) by the same steps; the hash-only
|
||||
differences are now canonicalized before `git merge-file` (the port's kernel-name hashes are kept), which left 10
|
||||
files with real conflicts. What it needed:
|
||||
|
||||
- **Upstream's async commit** (`set_commit_async` / `wait_commit`) maps onto the port's own deferred commit
|
||||
(`commit(n, err, false)` + `commit_finish`); `wait_commit` is `commit_finish`.
|
||||
- **Upstream's new hyper-connection read variants** (split / staged, chosen per card by a bit-for-bit self-test at
|
||||
start) are not used by the port, which keeps its sliced down / split norm read; the self-test segfaulted on the
|
||||
B70, so on SYCL it runs only with `STRATA_HC_CHECK=1` (open). The port's split-norm kernel was renamed
|
||||
(`gr_norm_split_port_kernel`): upstream now has one of the same name.
|
||||
- Two kernel names collided after hash canonicalization (renamed), and fused_gr's per-block shared-memory query is
|
||||
a fixup now.
|
||||
- **Result:** every output identical to 0.1.31 (Coder 19 / 2,184-token prompts and IQ2_XS, 256 greedy tokens),
|
||||
same speeds (Coder 77.7-78.1 / 75.7 tok/s, IQ2_XS 58.5), 40K prompt 1,201 tok/s then 65.1 tok/s decode.
|
||||
`kv_hybrid_parity` and `qsa_prompt_attn_parity` pass (the tests now turn on the XMX prompt attention they
|
||||
check); `iq_multi_parity` (IQ2_XS) and `s2_expert_grouped_parity` as before.
|
||||
|
||||
**The 0.1.33 merge (2026-10-01).** Upstream 0.1.32 -> 0.1.33 (17 commits): no shared file conflicted (the Intel
|
||||
code is all in `sycl/`); six engine files changed upstream and were merged by the same re-migration (only those six:
|
||||
the other files dpct produced differently were left alone). Two conflicts: `--resident-cpu-experts` (upstream's new
|
||||
`resident_cpu_explicit` beside the port's `--stream-experts`) and the prompt attention's compute-capability check
|
||||
(the port keeps its XMX dispatch). `sycl/setup_intel.py` and `sycl/serve/server_intel.py` ran unchanged against the
|
||||
new setup.py and server.py. Every output identical (Coder, IQ2_XS, the 40K prompt with borrowing); `gr_parity` and
|
||||
`qsa_prompt_attn_parity` pass.
|
||||
|
||||
**Prompt-slot borrowing: the hang (fixed 2026-10-01).** From 0.1.31 on, a prompt that borrowed cache slots stopped
|
||||
in its first full chunk with the GPU at 100% and the host waiting on the compute queue. It was never a borrowing
|
||||
bug: borrowing is just the only way the Coder streams experts during a prompt (every expert is resident otherwise),
|
||||
and the streamed path's stager deadlocked. Its threads read experts into a ring of 16 page-locked buffers and, to
|
||||
reuse one, waited on the copy queue's event for the DMA that last read it (the CUDA form, `cudaEventSynchronize`).
|
||||
Under the Level Zero v2 adapter that event, once a host thread had waited on it, no longer released the other
|
||||
queue's barrier that also listed it, and the GPU waited forever - only once a layer streamed more than 16 experts
|
||||
(the ring wrapped). The v1 adapter (`SYCL_UR_USE_LEVEL_ZERO_V2=0`) and a 256-buffer ring both ran; so did a sync
|
||||
after every phase (`STRATA_PREFILL_SYNC=1`, kept as a debug switch). The fix: the copy queue writes a sequence
|
||||
number into page-locked host memory after each DMA and the stager polls it - no host thread waits on a queue's
|
||||
event. Output is bit-identical to the run without borrowing; borrowing is the default above 32K again.
|
||||
|
||||
**Two model-specific bugs found with Swift 1.5 (fixed 2026-10-01).** UkisAI's Swift 1.5 IQ2_XS (setup's `swift`
|
||||
family, the same GSQ-RCO layout) decoded token 0 forever: NaN logits from layer 13 on.
|
||||
|
||||
- **`--stream-experts` read the wrong shard.** Since upstream 0.1.31, `ExpertLayout::gguf_file` is per layer AND role
|
||||
(`3 * layer + role`; a shard boundary can fall inside a layer). The port's `GgufExpertSource` still indexed it by
|
||||
layer, so a layer in shard 2 was read from shard 1 at shard 2's offsets: garbage IQ1_M scales, infinities after the
|
||||
fp16 dequantization. The original model keeps every expert in shard 1 and never noticed; Swift's layers 13-47 are
|
||||
in shard 2. `STRATA_DBG_NAN=1` now also reports the experts' fp16 GEMM inputs (activations, dequantized gate/up).
|
||||
- **IQ2_XS products were garbage** (the long-failing `iq_multi_parity` IQ2_XS case): ggml's `vec_dot_iq2_xs` reads
|
||||
its four 16-bit codes through a `uint16_t*` to an `int2`, type punning the SYCL device compiler does not honour;
|
||||
the dequantizer, which reads the codes directly, was exact. The codes are extracted by shifts now (the dot and the
|
||||
expert kernels' `Split<17>`); the test checks against a CPU decode from ggml's tables too and passes. No model here
|
||||
uses IQ2_XS tensors, Swift included - this was not Swift's bug, only found on the way.
|
||||
|
||||
Swift 1.5 IQ2_XS after both: correct answers, 51-118 words of thinking on short questions, 48 tok/s raw decode.
|
||||
|
||||
**Load time (2026-10-02).** Starting a model is mostly the expert cache's fill from the GGUF (`--stream-experts`):
|
||||
the Coder's 23.4 GiB of experts took 64-76 s, the IQ2_XS's 24.9 GiB 91 s, because the fill read each expert's
|
||||
three slices, copied the blob and waited for the copy before the next read. It is a pipeline now: the slots are
|
||||
admitted in profile order first (the same placement), the reads go in file order by up to 8 threads into
|
||||
page-locked batches of 64, and a batch's copies run while the next one is read. Cold page cache: 76.2 s -> 18.8 s
|
||||
(0.33 -> 1.34 GB/s); a whole Coder start from the engine's launch to its first token 82 s -> 26 s, the IQ2_XS
|
||||
120 s -> 41 s (its 8.2 GB host mirror is ~9 s of the rest). Output identical. `STRATA_FILL_SERIAL=1` is the old fill.
|
||||
|
||||
**The stream-all prompt walk is back (2026-10-03).** It copies every expert the VRAM cache does not hold, layer by
|
||||
layer ahead of the compute, instead of only the routed ones. It hung on the B70 until the stager and PLE fixes of
|
||||
2026-10-02 and runs since. It now runs by default when the VRAM holds more than 90% of the (layer, expert) pairs;
|
||||
past that it would copy several times the routed experts (the IQ2_XS keeps a quarter of them in the RAM mirror: a
|
||||
2,184-token prompt fell from ~560 to 254 tok/s with it). `STRATA_PREFILL_STREAM_ALL=1` / `=0` force it on or off.
|
||||
Coder, outputs identical either way:
|
||||
|
||||
| prompt | routed-only | stream-all |
|
||||
|---|---|---|
|
||||
| 40K int8 | 1,106 tok/s | 1,160 |
|
||||
| 128K int8, KV streaming | 897 | 920 |
|
||||
| 128K k8v4 | 1,006 | 1,041 |
|
||||
| 256K int8, KV streaming | 760 | 780 |
|
||||
|
||||
Measured alongside: the 2,184-token prompt reads 784-799 tok/s on both the 0.1.35+PR and the 0.1.38 build (three
|
||||
runs each), so the 825 seen once on 0.1.35 was session variance, not a regression. The prompt path at 40K (Coder,
|
||||
GPU timeline): expert dequant 15.7%, expert GEMMs 23.4%, host grouping 6.5%, gather 5.7%, combine 2.4%, prompt
|
||||
attention 19.2%, QSA select 6.8%, DeltaNet recurrence 5.8%, hyper-connection reads 4.6%. Upstream's sm_90 cluster
|
||||
kernels (greedy sampler, QSA top-k) would save next to nothing here: the sampler reads ~6 MB a round against a 13 ms
|
||||
token. Q4_0 tensor-core prompt attention (#452) is not worth porting: the port's XMX prompt attention is 2-3x slower
|
||||
than the plain kernel it uses for every KV format.
|
||||
|
||||
**The 0.1.38 merge (2026-10-03).** Upstream 0.1.35 -> 0.1.38 (83 commits) merged the seven PRs the port had taken
|
||||
early, so their header forks in `sycl/include` are gone; the merge base for the 3-way merge was the port's own "main +
|
||||
PRs" migration. New in the port with it: the DeltaNet output norm without its dead FP32 store, two prompt-path
|
||||
fixes (the fused layout's buffers, the streamed walk's resident lookup), `STRATA_GR_DOWN_MAX4=1` (opt-in; neutral on
|
||||
the B70: 2,184-token prompt 793 vs 788 tok/s, decode 76.2 vs 76.3). Stubbed in the port: `--peer-device` (a second
|
||||
GPU as an expert-cache tier: upstream's code is CUDA calls; `open` refuses with a message) and the fused int8 prompt
|
||||
kernels (#136, part of the MMQ library the port does not build). Off on SYCL: the sm_90 thread-block-cluster greedy
|
||||
sampler and QSA top-k (no SYCL counterpart; the callers take the plain kernels). `STRATA_GDN_KEYHEAD=1` stays opt-in
|
||||
(still 8% slower here: 727 vs 788 tok/s). `qsa_prompt_attn_parity` now also tests upstream's Q4_0 tensor-core mode
|
||||
(#452), which the port does not have: those cases report "refused" (the int8 and fp16 XMX cases pass); a `--kv
|
||||
q4_0` prompt takes the older kernel, as before. Outputs identical (Coder, IQ2_XS, 40K); 128K int8 KV streaming
|
||||
892 / 66.8 tok/s.
|
||||
|
||||
**0.1.35 and seven open upstream PRs (2026-10-02).** Upstream main 0.1.33 -> 0.1.35 merged as before, then seven open
|
||||
PRs ported into `sycl/` ahead of upstream (one dpct run of main + all of them, 3-way merged into only the files they
|
||||
touch; `sycl/tools/merge_upstream.py`). Their header changes live in `sycl/include` until upstream merges them.
|
||||
|
||||
| PR | what | on the B70 |
|
||||
|---|---|---|
|
||||
| #385 (sergqwer) | stager: a buffer's first job of a generation waits for the previous DMA from it | race fix; same output |
|
||||
| #463 (constantindjonkam) | decode waits for an adaptive swap before reading the residency table | determinism fix |
|
||||
| #453 (architectds) | the drafter's batched K/V on the KV-streaming ring | 128K int8: 888 -> 895 tok/s prompt, 66.6 -> 67.0 decode |
|
||||
| #374 (sergqwer) | the first chunk's PLE rows read beside layer 0 | part of the 2,184-token prompt's 784 -> 825 tok/s |
|
||||
| #363 (BlueKingMuch) | the PCIe expert call: group stride, fused SwiGLU + q8_1 | IQ2_XS decode +1.7%; re-done on the port's lane kernels |
|
||||
| #407 (sergqwer) | `--adapt-tuned` (opt-in) | neutral here; stays opt-in |
|
||||
| #413 (BlueKingMuch) | DeltaNet recurrence per key head | bit-identical but 8% slower prompt here: off (`STRATA_GDN_KEYHEAD=1`) |
|
||||
|
||||
#374 needed two port fixes: its next-chunk read assumed every chunk is the full chunk length (the port's first chunk
|
||||
is 256 tokens: the second chunk's rows were read from the wrong place), and its host wait on the PLE upload's event,
|
||||
now inside the layer loop, deadlocked the prompt past ~4K tokens under the Level Zero v2 adapter (the stager's bug
|
||||
again): the upload is marked by a polled sequence number now. #413's gate is an NVIDIA SM-count rule and its parity
|
||||
test an SM-holding NVIDIA bench (not built). Outputs identical to 0.1.33 (Coder 19 / 2,184 tokens, IQ2_XS, 40K).
|
||||
|
||||
**Not ported yet (2026-10-01).**
|
||||
|
||||
- Three kernels carry inline PTX (`mma.sync` tensor-core matrix ops, `ldmatrix`, `cp.async`):
|
||||
`qsa_prompt_attn`, `qsa_select`'s block scores, `native_qsa_score`. The SYCL build takes the "older card"
|
||||
fallback the CUDA build uses below sm_80. `qsa_prompt_attn` also has an XMX version (`joint_matrix`, opt-in
|
||||
`STRATA_PROMPT_ATTN_XMX=1`): correct, but slower than the fallback (see "XMX prompt attention v2").
|
||||
- The ggml MMQ prefill path (`moe_mmq.cu`) needs llama.cpp's ggml-cuda sources; not built.
|
||||
- AOT device code is what runs: `AOT=bmg-g31 BUILD_DIR=.../build-sycl-aot` (the JIT build costs ~47 s of
|
||||
compiling on the first window).
|
||||
|
||||
## Arc A750 and the other Alchemist cards (`i915`, 2026-10-07)
|
||||
|
||||
Measured on an Arc A750 (8 GB, `i915`, PCIe 4.0) with the Flash-Next IQ3_XXS in a PC with 64 GB of RAM, a Ryzen 5 5600X
|
||||
(AVX2, no AVX-512). `./setup.sh --backend sycl` writes a different config for an `i915` card (and a 300 MiB VRAM reserve and
|
||||
`--draft-vocab en` for any card under 12 GB):
|
||||
|
||||
| | Arc Pro B70 (`xe`, 32 GB) | Arc A750 (`i915`, 8 GB) |
|
||||
|---|---|---|
|
||||
| experts | `--stream-experts`: from the GGUF into VRAM, the rest in a pinned RAM mirror | no `--stream-experts`: all of them in a RAM arena (39.97 GiB for IQ3_XXS), 406 of 24,576 in VRAM, the CPU computes the others |
|
||||
| `STRATA_VERIFY_NO_HOST` | 1 (the wrapper's default) | 0, written to the config's `"env"` |
|
||||
| `--vram-reserve-mib` | 1024 / 2048 | 300 |
|
||||
| `--ple-io` | `ram` (rotational-disk rule of setup) | `ram` |
|
||||
| FP64 | native | emulated: `IGC_EnableDPEmulation=1`, `OverrideDefaultFP64Settings=1`, `NEOReadDebugKeys=1` in `"env"` |
|
||||
| build | AOT `bmg-g31` | JIT (no `AOT=`) |
|
||||
|
||||
- **Why no `--stream-experts`.** The mirror is one pinned host allocation for everything the card does not hold (40 GB here). A
|
||||
single `sycl::malloc_host` above a few GB fails on the A750 (`STRATA_MIRROR_MIB` 3,000 worked, 8,192 and 24,000 did not, also
|
||||
with `memlock` unlimited and the relaxed-allocation-limit variables), and the engine then refuses to start with
|
||||
`24170 experts are neither in VRAM nor mirrored`. Without the flag the engine loads the GGUF's experts into an ordinary RAM
|
||||
arena and the CPU computes the experts that are not in the 0.67 GiB cache. That needs the RAM: about 43 GB for IQ3_XXS plus
|
||||
the 29 GB n-gram table with `--ple-io ram` (the table is not locked in the container, so it is reclaimable; do not give the
|
||||
container `--ulimit memlock=-1`, the locked table and the arena then do not fit in 64 GB and the PC swaps). Setup warns when the RAM is less than the model's.
|
||||
- **Why `STRATA_VERIFY_NO_HOST=0`.** With it set the GPU plans each layer itself and the CPU's experts are never asked for:
|
||||
the window hangs (the i915 log says `Fence expiration time out`) or, if the pool is refused, the engine says
|
||||
`REFUSED: ... neither in VRAM nor mirrored`. It is the switch of the B70's case, where every expert the card lacks is in the mirror.
|
||||
The engine takes a value of `0` (or empty) as "off", and `strata-sycl.sh` does not pass such a value on.
|
||||
- **FP64.** An Alchemist has no FP64 hardware. One kernel on the sampled path declares `double`, and the SYCL runtime refuses it at
|
||||
its first launch (`'double' is not supported in 'Intel(R) Arc(TM) A750 Graphics' device`, the engine dies on the first request
|
||||
that has a temperature). With the three variables above the driver emulates it; the cost is the sampler's tail
|
||||
(see "FP64." in the B70 section).
|
||||
- **The first request after a start used to return `!!!!!` (token 0) or crash the engine.** The GPU waits for the CPU's experts at
|
||||
every layer in a spin that is bounded (`strata::kSpinMax`, `sycl/include/strata/sycl_doorbell.hpp`): a spin that never ends
|
||||
hangs the driver. The bound was 20,000 reads, a few tens of milliseconds, which is enough when nothing is waited for (the B70)
|
||||
and is not for a CPU layer in the first request (cold pages, 13 s for a 26-token prompt). The GPU gave up, went on with the
|
||||
experts' outputs missing, the next layers' routing was garbage (one expert chosen ten times for a token: `nt=10`) and the
|
||||
CPU pool wrote past its token arrays and died with a segmentation fault (exit code 139); when it did not die the logits were NaN
|
||||
and the sampler's answer was token 0. Later requests ran with warm pages and were right. The bound is now a build option,
|
||||
`STRATA_SYCL_SPIN_MAX` (CMake; `SPIN_MAX=` for `sycl/tools/build.sh`): 2,000,000 reads (a few seconds) unless the build is an
|
||||
AOT build for a `bmg` card, which keeps 20,000. Before the change 11 of 16 runs of the engine (three requests each, a 26-token prompt) died or gave
|
||||
token 0 in the first request; with 2,000,000 reads 4 of 4 were right in all three requests.
|
||||
- **Kernels misread memory more than 4 GiB into an allocation (fixed in the build).** On an Arc A770 (16 GB, `xe`, Coder
|
||||
IQ1_M, `--stream-experts`, a 4.46 GiB expert cache) every prompt answered `!!!!` (token 0): the experts in the cache's
|
||||
last 0.46 GiB dequantized to NaN in the prompt path. A copy of those slots read back equal to the GGUF
|
||||
(`STRATA_VERIFY_ALL_SLOTS` passed) and a fresh device copy of the same bytes dequantized clean; only a kernel reading
|
||||
the slot in place got wrong bytes. In a JIT build IGC addresses a kernel's pointer arguments as a 32-bit offset from
|
||||
the allocation's base. The JIT build now passes `-ze-opt-greater-than-4GB-buffer-required` (`sycl/CMakeLists.txt`),
|
||||
which keeps the kernels on 64-bit addresses. After the change, prompts of 73 to 542 tokens had 0 non-finite values
|
||||
(`STRATA_DBG_NAN=1`) and the 542-token prompt answered right. The speed cost is not measured. The AOT (`bmg-*`) build is
|
||||
unchanged. oneMKL's own precompiled kernels do not get the option; the GEMM stages an operand past 4 GiB for that.
|
||||
- **Speed.** About 10 to 15 tok/s decode (76 to 92% of the drafts accepted), a 26-token first prompt in 13 s and later short prompts in 0.2 to
|
||||
1.3 s; the A750's PCIe link probes at 10.6 GB/s.
|
||||
- **A750 and the xe error counters.** The engine segfaults in a worker thread of the CPU pool when it exits (dmesg only, the server
|
||||
has already printed "stopped"); it is not a GPU event.
|
||||
- **The prompt's GDN recurrence runs a sub-group kernel on Alchemist** (`sycl/include/strata/prefill/gdn_xe.hpp`,
|
||||
variant 6 of `gdn_recurrence_variant`). It keeps the column kernel's four row groups and their FMA chains in the same
|
||||
order, but a 16-lane sub-group holds four columns x four row groups, so the two cross-row-group sums are sub-group
|
||||
shuffles instead of SLM round trips and a token needs one work-group barrier instead of five (256 GRFs a thread).
|
||||
Measured on an Arc A770 (16 GB, `xe`, oneAPI 2026.1 JIT), 2026-10-13: `gdn_parity --prefill-tokens 8192` 51.0 ->
|
||||
24.5 ms, 32,768 tokens 204-236 -> 110-113 ms (48 heads), 0 mismatches; end to end, Coder IQ1_M, `--max-context
|
||||
131072 --kv int8 --kv-resident 20480 --vram-reserve-mib 1200 --resident-experts`, prompt 386 -> 396-407 tok/s at
|
||||
8K and 478-480 -> 511-518 tok/s at 32K, the same output tokens. On by default on Alchemist only, the column kernels everywhere else (not measured there). `STRATA_GDN_XE=0`
|
||||
turns it off, `STRATA_GDN_XE=1` turns it on for any Intel GPU with 16-lane sub-groups. To check another Intel card:
|
||||
`STRATA_GDN_XE=1 ./gdn_parity --selftest --prefill-only` (or `ctest -R prefill_gdn_parity`), and `--prefill-tokens
|
||||
8192 --prefill-repeat 5` for the time of both kernels. Not taken: the same kernel with its state in SLM (no register
|
||||
spills, the same bits, ~4x slower: 13.7 vs 3.1-3.3 ms at T=1000).
|
||||
|
||||
## Not done
|
||||
|
||||
- Images, on both Intel engines. PolyStrata's vision path encodes with `strata-vision` into embeddings the CUDA
|
||||
engine reads; neither the SYCL port nor the llama.cpp config wires it yet.
|
||||
- Speculative decoding on the llama.cpp path (the GGUF carries no draft layer llama.cpp can use). The SYCL
|
||||
port has it (MTP draft layer, `--mtp`).
|
||||
|
||||
## Arc Pro B70 with a model that does not fit: Flash-Next IQ3_S (2026-10-07, branch f-141-intel)
|
||||
|
||||
The earlier B70 rows are for models whose experts all fit in VRAM. IQ3_S has 24,576 experts of 1.97 MB (46 GB): the 32 GB
|
||||
card holds 11.5k of them (22 GiB of cache) and the rest sit in a pinned host mirror that the GPU reads over PCIe. Tested on
|
||||
the B70 VM (xe driver, kernel 7.0, oneAPI 2026.1, PCIe measured at 13.3 GB/s host to device), engine 0.1.40-sycl.
|
||||
|
||||
**Two things made it produce garbage, both fixed or documented here.**
|
||||
|
||||
- **Aliased pages in big allocations (fixed in the engine).** The xe driver returned the 22 GiB expert-cache arena with two
|
||||
of its 2 MiB pages mapped onto the same memory: a write at +2 MiB showed at +1022 MiB. Cache slots there held other
|
||||
experts' bytes, and the prompt came out NaN at the first layer that routed to one (layer 4, expert 249); the same run
|
||||
with another `--max-context`, or with an MTP window of 4 instead of 6, was clean. `STRATA_VERIFY_ALL_SLOTS=1`
|
||||
(`STRATA_VERIFY_FIND=1`, `STRATA_VERIFY_DUMP=dir`) reads every filled slot back and compares it with the GGUF; that is how
|
||||
the aliasing was found (the wrong bytes were slot 0's blob). Every allocation of 32 MiB or more now goes through
|
||||
`strata::malloc_device_guarded`: it tags every 64 KiB, reads the tags back in a second kernel, and allocates again behind a
|
||||
growing spacer until the range is clean (a warning names each retry; the check costs under 0.5 s at startup;
|
||||
`STRATA_ARENA_ALIAS_CHECK=0` skips it). `sycl/probe/arena_rw.cpp` and `alias_scan.cpp` do not reproduce it on their own: it
|
||||
needs the engine's allocation history.
|
||||
- **`STRATA_VERIFY_NO_HOST=1` is required whenever part of the experts is not in VRAM.** `sycl/serve/strata-sycl.sh` sets
|
||||
it; a by-hand run must too. Without it the per-layer host/GPU handshake is not visible across the bus on xe and the logits
|
||||
turn NaN a few tokens into the answer, differently on every run. With it (and the mirror covering every miss) the run is
|
||||
deterministic: two runs gave identical tokens.
|
||||
|
||||
**Numbers** (greedy, `--spec 4 --spec-min-p 0.5 --mtp`, INT8 KV, 32K context, `--stream-experts --vram-reserve-mib 1024
|
||||
--ple-io ram`, 11.5k experts resident; the 10-prompt `mg_norepeat` gate passes 10 of 10, the xe error counters did not move):
|
||||
|
||||
| | before | after |
|
||||
|---|---|---|
|
||||
| 4,095-token prompt, `--prefill auto` (2,048-token chunks) | 618 tok/s | 730 |
|
||||
| 4,095-token prompt, `--prefill 4096` | 784 | **980-1,002** |
|
||||
| 8,169-token prompt: auto / 4096 / 8192 lending cache slots / 8192 own buffers | 676 | 953 / 1,037 / 1,117 (9.4k slots) |
|
||||
| decode, 200-token story (66% of drafts accepted, 1.98 tokens per round) | 31.4 tok/s | 30.5 with 4096-token chunks (700 fewer cache slots) |
|
||||
| decode, 200-token code answer (90% accepted, 3.65 tokens per round) | not measured | 40.8 with 4096-token chunks |
|
||||
|
||||
(Interleaved A/B pairs, medians of 3-5. "Before" is the same build with the old short first chunk; the decode figures are
|
||||
the old default and `--prefill 4096`.)
|
||||
|
||||
**Why the prompt is slow here, and the two changes.** Every prompt chunk streams the experts the cache does not hold over
|
||||
PCIe, and a 4K prompt touches nearly all 512 experts of every layer: 13.5k missing experts x 1.97 MB = 26 GB, 2 s of the
|
||||
bus per chunk. So the prompt reads faster in fewer, bigger chunks, and the short first chunk (`STRATA_PREFILL_FIRST`, 256
|
||||
tokens, there to start the GPU while the PLE rows are read) cost a whole extra pass of that stream. It is now 256 only when
|
||||
the cache holds every expert, else 0. `setup_intel.py` writes `--prefill 4096` for a card with 24 GB or more (the chunk's
|
||||
buffers take ~700 cache slots; `--prefill 8192 --prefill-borrow` lends cache slots instead and keeps all of them for decode,
|
||||
at ~1 s of refill per prompt). Where the 4K prompt's GPU time goes now (GPU timeline, timing on): expert dequant 20%, the two
|
||||
expert GEMMs 34%, QSA attention 14%, host grouping 6.5%, GDN 9%, hyper-connection reads 4.6%.
|
||||
|
||||
**Draft length** (200 tokens, medians of 5 interleaved pairs, `--spec-min-p 0.5`): `--spec 6` against `--spec 4` is +6.5% on
|
||||
code (43.4 against 40.8 tok/s, 84% accepted against 90%) and -1.5% on prose (29.9 against 30.4). A 2-run sweep of the rest
|
||||
(`--spec 2/3/5`, min-p 0.3/0.7) was within the run-to-run noise of ~1 tok/s; the setup default (4, 0.5) stays.
|
||||
|
||||
**FP64.** Arc Alchemist emulates it (`IGC_EnableDPEmulation=1`); on the A750 one row of the sampler's top_p/temperature tail
|
||||
costs 451 us in double and 20 us in float (`sycl/probe/fp64_cost.cpp`), and a sampled decode ran at 7.6 tok/s against 12 for
|
||||
a greedy one. On the B70 the same kernels cost 3.4 against 2.1 us, so FP64 is not a B70 problem. Of the kernels that use
|
||||
double, the native-pack path (the packs setup builds) runs only the sampler (a 16-token greedy run created 173 kernels, the
|
||||
double ones among them: `sample_tokens` only; the native router, combine, gate and norm kernels are float). The sampler's tail
|
||||
now accumulates in `strata::samp_acc_t`, float by default (`-DSTRATA_SYCL_SAMPLER_FP64=1` keeps double): A750 sampled decode
|
||||
7.62 -> 8.10 tok/s (medians of 5 interleaved pairs, runs 7.1-9.2), `sampler_parity` 0 failures on both cards, and the B70 gate's
|
||||
sampled cases picked the same tokens.
|
||||
|
||||
The sampler's launchers also kept dpct's `aspect::fp64` check, which threw "'double' is not supported" at the first sampled token on an A750 without the emulation keys even though the kernels had been float since the accumulator change; 0.1.41 drops the check (it stays in a `-DSTRATA_SYCL_SAMPLER_FP64=1` build). Measured on the A750 (IQ3_XXS, `--spec 4 --mtp`, sampled, 100 tokens, 4 interleaved pairs, one binary): without `IGC_EnableDPEmulation` / `OverrideDefaultFP64Settings` 11.0 / 11.6 / 12.4 / 12.4 tok/s, with them 9.3 / 9.9 / 9.8 / 9.8 (median 12.0 against 9.8, faster in 4 of 4 pairs). Setup still writes the keys for an A-series card: the kernels other than the sampler's that use double (the oracle router, norms, PLE, QSA indexer) were not exercised without them on long contexts or with vision, so the keys stay the safe default.
|
||||
|
||||
**XMX.** oneMKL's FP16 GEMMs already run on the matrix engines; per expert the dequant (42 us for a gate/up matrix) costs
|
||||
twice the GEMM (20 us), and the fused dequant+XMX kernel (`xmx_gemm_bench`) is 0.22x of the pair on this card. The speed left
|
||||
on this card for this model is the dequant kernels (at ~200 GB/s against a 600 GB/s card), the host grouping, and the QSA
|
||||
prompt attention (14%); the multi-column int8 DPAS decode kernels of llama.cpp PR 29864 target K-quant and Q8_0 weights, not
|
||||
the IQ-quant experts, and were not ported.
|
||||
|
||||
## Arc Pro B70, Flash-Next IQ3_S: prompt and decode speed in 0.1.43 (branch f-143-intel)
|
||||
|
||||
Measured on the B70 (xe, 32 GB, 60 GB RAM, IQ3_S, 11.5k of 24.6k experts in VRAM, the rest in the pinned mirror; unitrace from pti-gpu
|
||||
for the kernel timelines). All the changes below leave the tokens as they were (first-token logits compared byte for byte, the 10-prompt
|
||||
gate identical in the 32K and the 128K configuration); every one has an off switch.
|
||||
|
||||
- **Prompt: the expert copies run on the card's copy engine** (`sycl/include/strata/copy_queue.hpp`). The Level Zero v2 adapter runs every
|
||||
SYCL queue on the compute engine, a copy-only queue included: the ~10,000 expert DMAs of a 4K prompt (2 MB, ~80 us each) sat between the
|
||||
expert kernels and never overlapped one (unitrace: 0 of 2,000 copies overlapped a kernel). An immediate command list on the copy-only queue
|
||||
group (ordinal 1) wrapped with `sycl::make_queue` puts them on `Copy Engine<1,0>`; events work across the two queues as before. 4K prompt
|
||||
3.82 -> 3.25 s, 16K 15.5 -> 13.5 s. On by default for a Battlemage card; `STRATA_COPY_ENGINE=1` forces it elsewhere, `=0` turns it off (an A750
|
||||
gained 1.4% and the prompt hung there once the stager's completion flag was a copy-engine memcpy, so Alchemist stays off).
|
||||
- **The 128K configuration setup writes** (`--kv-resident 32768`, the prompt borrows cache slots) paid three more costs: `kv_append` wrote the
|
||||
host copy of the KV with 1-byte stores (2 s of a 4K prompt, now 4-byte lane stores), every expert GEMM staged two 6.5/3.3 MB operands because they
|
||||
sit past 4 GiB in the borrowed region (an A770 oneMKL bug that did not show on this card: off on Battlemage, `STRATA_SYCL_GEMM_STAGE=1`
|
||||
brings it back), and the lent slots were refilled by a single-threaded GGUF read (0.9 s for 930 slots, now a DMA from the pinned mirror:
|
||||
the experts in the last 10% of the cache slots are mirrored too, `STRATA_LEND_MIRROR=0` off). 4K prompt incl. the refill 7.2 -> 3.3 s,
|
||||
1K 3.1 -> 1.6 s, 16K 25.5 -> 13.5 s, 49K 78 -> 44 s; a 684-token request through the server 2.64 -> 1.59 s, a 3,083-token one 6.1 -> 2.95 s (the same answer).
|
||||
- **Decode: `data/expert-profile-sycl.bin`.** The shipped profile ranks the experts for a document summary; a chat, code or non-English prompt finds
|
||||
only 60% of its routed experts in the cache (85% for a summary). `tools/make_profile_mix.py` builds a ranking from several routing traces with
|
||||
every trace counting the same, `tools/collect_profile_traces.py` records them (`bench/profile_corpus.json`: 45 prompts) through the engine's
|
||||
device-side routing counts (`STRATA_USAGE_DUMP=PATH`). The profile built from the 45 prompts and eight summaries holds 71% / 84%
|
||||
(leave-one-out) and gave +5% to +64% decode (mean +21%) on 12 prompts that were in neither set, identical tokens; setup_intel writes it for a
|
||||
card on xe (the i915 A750 keeps the shipped one: its CPU computes the misses, so the residency moves roundings).
|
||||
- Decode graph without the nodes nobody answers under `STRATA_VERIFY_NO_HOST` (`STRATA_VERIFY_LEAN=0` off): -2%.
|
||||
- Tried and not worth it on this card: the grouped XMX expert GEMM for Battlemage (built, `STRATA_PF_XMX=1/2`, correct to 6e-7, 11-15% slower), a
|
||||
miss-first or hit-first group order in the device plan (-3% / -7%), spreading the expert chains over several queues (one compute engine),
|
||||
`STRATA_LFUSE`, `STRATA_VERIFY_EAGER`.
|
||||
|
||||
## Measured, 2026-10-01, Arc Pro B70, Coder IQ1_M, 32K context, INT8 KV: the SYCL port (engine 0.1.31-sycl)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| decode | 78.2 tok/s on a 19-token prompt, 75.7 after a 2,184-token prompt (256 greedy tokens, MTP + suffix drafts) |
|
||||
| prompt | 780 tok/s on 2,184 tokens; 934 tok/s at 128K, 784 at 256K |
|
||||
| through the API | 48-72 tok/s on a ~190-token chat answer, prompt included (the first request after a start is the slower one) |
|
||||
| VRAM | all 12,288 experts resident, ~1.9 GB free with everything loaded (`--vram-reserve-mib 1024`) |
|
||||
| RAM | no host copy of the experts (`--stream-experts`) |
|
||||
|
||||
## Measured, 2026-09-29, Arc Pro B70, Coder IQ1_M, 32K context, q8_0 KV: llama.cpp
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| load | ~100 s |
|
||||
| VRAM | 28.4 of 32 GB |
|
||||
| decode | 23-25 tok/s; GPU 92% busy at 165 W, CPU idle |
|
||||
| prefill | 149 tok/s on a 2,701-token prompt; 424 tok/s on a 104,798-token prompt at 131k context |
|
||||
| quality | correct code on every test; matches the NVIDIA path token for token in spirit, not measured |
|
||||
@@ -0,0 +1,175 @@
|
||||
# Intel Arc (experimental)
|
||||
|
||||
PolyStrata 0.1.39 includes an **experimental Intel Arc engine**: PolyStrata's own engine ported to SYCL (Intel oneAPI).
|
||||
maxfridbe wrote it in [#423](https://github.com/Niko1221/Strata/pull/423), with fixes from the people testing it.
|
||||
The code is in `sycl/`, and the port's own notes, measurements and maintenance procedure are in
|
||||
[docs/INTEL.md](INTEL.md). This page covers what you need, how to build it, and what has been tested.
|
||||
|
||||
**Experimental means:** the Strata maintainers have no Intel GPU. We compile the port and run its kernel tests, but
|
||||
we have not run it on an Arc. Every result on Arc hardware below comes from the community. The NVIDIA and AMD
|
||||
engines are unchanged: the Intel build is a separate CMake target, off by default.
|
||||
|
||||
There is **no ready-made Intel engine** in the release zips. You build it from source on Linux.
|
||||
|
||||
## What has been run, and by whom
|
||||
|
||||
| | Hardware | Result | Reported in |
|
||||
|---|---|---|---|
|
||||
| Port author | Arc Pro B70 32 GB, Ubuntu 24.04 | Coder IQ1_M: 70-78 tok/s decode, ~790 tok/s prompt; IQ2_XS: 51-64 tok/s; 256K context measured | #423, [INTEL.md](INTEL.md) |
|
||||
| Community | 2x Arc Pro B70, `--layer-split` | Flash-Next IQ3_XXS 66 tok/s decode, 394 tok/s prompt (with the `stage_room` fix that is now in 0.1.39) | #423 |
|
||||
| Community | Arc Pro B50 16 GB | Coder IQ1_M ~23 tok/s, IQ2_XS ~25-27 tok/s, up to 128K | #423 |
|
||||
| Community | Arc B580 12 GB, WSL2 | IQ2_XS ~21 tok/s, Coder ~15 tok/s; **device loss also seen** | #423 |
|
||||
| Community | 2x Arc Pro B60 24 GB, `--layer-split` | Coder IQ1_M: 56.6 tok/s decode, 428 tok/s prompt (2,129 tokens); Flash-Next IQ2_XS: 58.6-61.3 tok/s decode, 436 tok/s prompt; all experts in VRAM; 8K context | [bench/results/2026-10-04-community-2x-arc-pro-b60](../bench/results/2026-10-04-community-2x-arc-pro-b60/README.md) |
|
||||
| Community | one Arc Pro B60 24 GB | Coder IQ1_M with 4,042 of 12,288 experts mirrored in RAM: 11.9 tok/s decode (needs the ring-wait fix from the same report) | same |
|
||||
| Strata maintainers (0.1.40.2 and later) | Arc Pro B70 32 GB (xe) and Arc A750 8 GB (i915), test machines | Flash-Next IQ3_S on the B70 with 11.5k of 24.6k experts resident: 10-prompt gate passes, prompt 980-1,000 tok/s on 4K tokens, decode 30 (prose) to 41 (code) tok/s; the xe aliased-pages fix and the `NO_HOST` requirement are in [INTEL.md](INTEL.md) | INTEL.md, "Arc Pro B70 with a model that does not fit" |
|
||||
|
||||
The 0.1.39 port re-migrates 0.1.38's port onto the 0.1.39 engine sources (the #606 NaN fix, the #649 verify
|
||||
trace, the new prompt paths). 0.1.39's `sycl/` did not compile against 0.1.39's own engine sources (#784: the
|
||||
`ThreadAffinity` type of #626 and the layer range of `NativeDense::load` from #559), and its ring waits never saw a
|
||||
slow layer as still running (#866, #867). Both are fixed in 0.1.40, and the two B60 reports below were measured with
|
||||
exactly those two fixes on top of 0.1.39. **No one has run an unpatched 0.1.39 port on an Arc**, and the other rows were
|
||||
measured on earlier versions.
|
||||
|
||||
The two B60 rows ran `6f32ec0` plus two small `sycl/` fixes (the compile fix and the ring-wait fix), AOT `bmg-g21`, on Ubuntu 24.04 with
|
||||
`xe`, Level Zero V2, NEO 26.09.37435.12 and oneAPI 2026.1.1, without Docker. Host: Ryzen 5 5600, 64 GB RAM, PCIe 3.0 x8 per card.
|
||||
Full flags, per-request timings and engine logs are in the report linked in the table.
|
||||
|
||||
## What was tested here (0.1.39)
|
||||
|
||||
- **Compiles:** Ubuntu 24.04 (WSL2), Intel oneAPI DPC++ 2026.1.1 + oneMKL 2026.1. The whole `sycl/` project
|
||||
builds with 0 errors: the `strata` engine plus all 157 targets (the kernel parity tests and benches). The build is
|
||||
SPIR-V (JIT). The AOT build (`STRATA_SYCL_AOT`) was not built here, because it needs `ocloc`.
|
||||
- **Kernel parity tests on a CPU** (`ONEAPI_DEVICE_SELECTOR=opencl:cpu`, Intel's OpenCL CPU runtime, AMD Ryzen 5 7600):
|
||||
14 of 25 pass. That is the same set that PR #423's own 0.1.38 port passes on that device: the failures are tight
|
||||
float tolerances on the CPU's math (rel 3e-6 against a 1e-6 limit), model fixtures that are not present, and two
|
||||
tests that time out on a CPU. This is a check that the kernels compile and compute, not a test of an Arc.
|
||||
- **Setup:** `--backend sycl` warns, then hands over to `sycl/setup_intel.py` on Linux (unit tests:
|
||||
`tools/test_setup_sycl.py`).
|
||||
- **Unchanged:** the CUDA engine's greedy output, checked byte-identical against the gated 0.1.39 build (Q2_0 and Coder).
|
||||
The HIP build is not affected (the option is off by default).
|
||||
|
||||
**Not tested by anyone yet:** Windows (no native build path; see below), Arc on WSL2 for the 0.1.39 port, the Alchemist
|
||||
A-series, integrated Arc GPUs (the B390 / Panther Lake in #515; the shared-memory planning does not exist yet), and
|
||||
images (not wired on Intel).
|
||||
|
||||
## What you need
|
||||
|
||||
- **Linux**, e.g. Ubuntu 24.04, with Intel's GPU driver (the `xe` or `i915` kernel driver plus the compute runtime /
|
||||
Level Zero; on Ubuntu, `intel-opencl-icd libze1 libze-intel-gpu1`, or Intel's
|
||||
[client GPU guide](https://dgpu-docs.intel.com/driver/client/overview.html)).
|
||||
- **Intel oneAPI**: the DPC++ compiler (`icpx`, 2025.3 or newer; 2026.1 is what was built here) and **oneMKL**. About 5 GB.
|
||||
- `cmake` 3.24+, `ninja`, `git` (the build fetches ggml unless you point `STRATA_GGML_DIR` at a llama.cpp checkout),
|
||||
Python 3.
|
||||
- For `./setup.sh --backend sycl` today: **Docker**, and nothing else from the list above except the GPU driver.
|
||||
`sycl/setup_intel.py` runs the engine in the `strata-sycl-dev` image built from `sycl/tools/Dockerfile`, and the
|
||||
engine is built in that image too ("Build with Docker" below). On Ubuntu: `sudo apt install docker.io git`, then
|
||||
`sudo usermod -aG docker,render $USER` and log in again. Note that the Dockerfile starts from a community
|
||||
llama.cpp SYCL image (`ghcr.io/snailium/...`), not an Intel or PolyStrata image.
|
||||
- VRAM: the port keeps the experts on the card (`--stream-experts`). A 32 GB card holds the Coder IQ1_M or IQ2_XS.
|
||||
Smaller cards mirror part of the experts in RAM and are slower.
|
||||
|
||||
## Build with Docker (what `setup --backend sycl` uses)
|
||||
|
||||
Two commands, the same as in [INTEL.md](INTEL.md), "How to build it" (about 10 minutes the first time). From the checkout,
|
||||
called `PolyStrata` here:
|
||||
|
||||
```sh
|
||||
cd PolyStrata
|
||||
docker build -t strata-sycl-dev sycl/tools # once: ~6 minutes, a 13 GB image
|
||||
H=$(basename "$PWD")
|
||||
# Arc B-series: bmg-g31 (Pro B70), bmg-g21 (B580, B570, Pro B60). Arc A-series (Alchemist): leave out AOT (JIT) and use build-sycl
|
||||
docker run --rm -u $(id -u):$(id -g) -v "$PWD/..:/work" -e AOT=bmg-g31 -e REPO=/work/$H \
|
||||
-e BUILD_DIR=/work/$H/build-sycl-aot strata-sycl-dev "cd /work/$H && bash sycl/tools/build.sh strata"
|
||||
```
|
||||
|
||||
Then `./setup.sh --backend sycl` (below). Do not run `python3 sycl/setup_intel.py` by hand: on Ubuntu it fails with
|
||||
`externally-managed-environment`; `setup.sh` runs it in its own `.venv`.
|
||||
|
||||
## Build without Docker (Linux)
|
||||
|
||||
This builds the engine for running it by hand ("How to run it by hand" in [INTEL.md](INTEL.md)); `setup` itself uses the
|
||||
Docker build above. Install oneAPI from Intel's apt repository (this is what was used here):
|
||||
|
||||
```sh
|
||||
wget -qO- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
|
||||
| sudo gpg --dearmor -o /usr/share/keyrings/oneapi-archive-keyring.gpg
|
||||
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" \
|
||||
| sudo tee /etc/apt/sources.list.d/oneAPI.list
|
||||
sudo apt update
|
||||
sudo apt install intel-oneapi-compiler-dpcpp-cpp intel-oneapi-mkl-devel ninja-build cmake git
|
||||
```
|
||||
|
||||
Then build the engine. Either command works: the first goes through the top-level CMake option, the second
|
||||
configures the `sycl/` project directly.
|
||||
|
||||
```sh
|
||||
source /opt/intel/oneapi/setvars.sh
|
||||
cmake -S . -B build-sycl -G Ninja -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DSTRATA_ENABLE_SYCL=ON
|
||||
# or: cmake -S sycl -B build-sycl -G Ninja -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
|
||||
cmake --build build-sycl --target strata
|
||||
```
|
||||
|
||||
Options:
|
||||
|
||||
- `-DSTRATA_SYCL_AOT=bmg-g31` (Arc Pro B70) or `bmg-g21` (B580 / B570 / Pro B60) compiles the GPU code ahead of
|
||||
time. This needs `ocloc` (Intel's `intel-ocloc` package). Without it, the first start JIT-compiles every kernel,
|
||||
which takes about 47 s.
|
||||
- `-DSTRATA_SYCL_PARITY=OFF` skips the kernel tests (on by default). Run them with
|
||||
`ctest --test-dir build-sycl` on the card.
|
||||
|
||||
`setup_intel.py` looks for `build-sycl-aot/strata` or `build-sycl/strata` in the checkout. With the
|
||||
top-level option the engine is at `build-sycl/sycl/strata`, so either use `-S sycl` or set `STRATA_SYCL_BIN`.
|
||||
|
||||
## Setup and running
|
||||
|
||||
```sh
|
||||
./setup.sh --backend sycl [setup's usual options, e.g. --model IQ2_XS --context 32768]
|
||||
```
|
||||
|
||||
This prints the experimental warning and continues with `sycl/setup_intel.py` (in setup's own Python environment).
|
||||
That script finds the Arc in sysfs, uses the SYCL engine you built, and writes the config and `run-<model>.sh`.
|
||||
On a card under 12 GB or an `i915` card (the A-series) it writes the small-card config ([INTEL.md](INTEL.md), "Arc A750
|
||||
and the other Alchemist cards"). It still downloads and packs the model
|
||||
the usual way. To run the engine by hand (no Docker), see "How to run it by hand" in [INTEL.md](INTEL.md).
|
||||
|
||||
Things that matter on an Arc (details in INTEL.md):
|
||||
|
||||
- **Do not ask for more VRAM than the card has.** On the `xe` driver, an allocation past VRAM can push buffers into
|
||||
RAM until the machine runs out of memory and stalls. Leave about 1.5 GB free.
|
||||
- `SYCL_CACHE_PERSISTENT=0`: the persistent JIT cache crashed on Xe2 during the first compile.
|
||||
- Two cards: `ONEAPI_DEVICE_SELECTOR=level_zero:*` (the image pins `level_zero:0`; `strata-sycl.sh` now passes the
|
||||
variable through) and `--layer-split`.
|
||||
- **`--layer-split auto` on two equal cards (0.1.44, #1440):** when several splits hold all the experts and predict the
|
||||
same speed, the search now takes the one that leaves its fullest card the most VRAM to spare (within 0.2% of the best
|
||||
predicted time, `STRATA_SPLIT_HEADROOM_TOL`). It used to take the first one tried, which filled the second card to its
|
||||
last MiB. A full card under `xe` moves buffers to system memory instead of failing: 2x B70 with IQ3_S, auto picked
|
||||
K=24 (~11 tok/s) where `--layer-split 30` ran ~54. The startup line names both splits when the choice moves.
|
||||
`STRATA_SPLIT_HEADROOM=0` keeps the old pick.
|
||||
- **Arc Pro B60:** the PCI id is `8086:e211` (`lspci -nn`, the kernel's `xe` id list files it with the BMG-G21 cards), `sycl-ls` prints
|
||||
`Intel(R) Arc(TM) Pro B60 Graphics 20.1.0`, and `ocloc ids bmg-g21` prints 20.1.0, so `-DSTRATA_SYCL_AOT=bmg-g21` is the right target.
|
||||
`setup_intel.py` knows both B60 ids, `e211` and `e221` (both seen on B60 cards). On a `--layer-split` the startup line "N experts are neither in VRAM nor mirrored"
|
||||
counts the other card's layers; the lines `100% of the experts resident` that follow are the ones to read. Set `STRATA_MIRROR_MIB=0` there,
|
||||
or the pinned mirror is allocated and not used.
|
||||
- **`setvars.sh` and `set -u`:** `source /opt/intel/oneapi/setvars.sh` in a shell with `set -u` stops at `OCL_ICD_FILENAMES: unbound variable`
|
||||
(oneAPI 2026.1.1). Source it before `set -u`, or run `set +u` around it.
|
||||
- **Without Docker:** `sycl/serve/strata-sycl.sh` needs Docker. Natively, `source setvars.sh`, export `SYCL_CACHE_PERSISTENT=0`,
|
||||
`ZES_ENABLE_SYSMAN=1` and `STRATA_VERIFY_DEVICE_PLAN=1`, then run `build-sycl-aot/strata` or `sycl/serve/server_intel.py` with an `exe` that does this.
|
||||
A normal user is not in the `render` group on Ubuntu, and then `sycl-ls` shows only the CPU device.
|
||||
- `STRATA_VERIFY_NO_HOST=1` (set by `strata-sycl.sh` unless the config's `"env"` says otherwise) is needed on `xe`
|
||||
cards when part of the experts is not in VRAM (the host-to-GPU flag stores are not visible there, NaN logits
|
||||
otherwise) and is left off on the `i915` Arc A-series: see [INTEL.md](INTEL.md). The config's `"env"` block and any
|
||||
`STRATA_*`, `ONEAPI_*`, `UR_*`, `IGC_*`, `SYCL_*` or `ZES_*` variable of the server's environment reach the engine
|
||||
through `strata-sycl.sh` (for example `STRATA_MIRROR_MIB`, `IGC_EnableDPEmulation`).
|
||||
|
||||
## Windows
|
||||
|
||||
There is no Windows path yet. `setup --backend sycl` on Windows stops and points here. oneAPI exists for Windows,
|
||||
but `sycl/CMakeLists.txt` uses GCC-style flags (`-mavx512f`, `-fp-model=precise`, `-qmkl`) and the runner is a
|
||||
bash/Docker script, so a native Windows build would need work. Nobody has tried it. WSL2 with an Arc has been
|
||||
used by one tester (the B580 row above), but setup cannot detect the card there, because it reads `/sys/class/drm`,
|
||||
which WSL2 does not have.
|
||||
|
||||
## Reporting a problem
|
||||
|
||||
Open an issue with: the card, the driver version, `sycl-ls` output, the oneAPI version, the model and flags, and the
|
||||
engine's stderr. Results from real cards are what move this from experimental to supported.
|
||||
@@ -0,0 +1,57 @@
|
||||
# Overlap streamed KV uploads with prefill computation
|
||||
|
||||
## Why this helps
|
||||
|
||||
When long-context KV lives partly in system RAM, prefill uploads each attention
|
||||
layer's cached prefix. Waiting for every upload on the compute stream leaves
|
||||
the GPU idle.
|
||||
|
||||
This opt-in change starts the next attention layer's upload on a separate stream
|
||||
while the current layer continues computing. It reuses the existing staging
|
||||
pool; it does not allocate another KV buffer.
|
||||
|
||||
## Use and ordering
|
||||
|
||||
Set `STRATA_KV_PREFETCH=1` before starting the engine. It is off by default.
|
||||
A release event protects the staging pool's last reader; a ready event orders
|
||||
the next attention consumer. Early returns drain pending copies before the caller
|
||||
can refill borrowed expert slots. Relayout and destruction also drain the stream.
|
||||
|
||||
## Validation environment
|
||||
|
||||
- Two modified RTX 3080 20 GB cards; CUDA SM86, CUDA 13.1, Linux.
|
||||
- Intel Xeon E5-2686 v4 (18 cores / 36 threads), about 94 GiB usable RAM.
|
||||
- PCIe 3.0, no GPU peer-to-peer access; 17 expert-pool workers.
|
||||
- Qwen3.8-Flash-Next IQ3_S, 131,072-token context, INT8 KV,
|
||||
32,768 resident KV cells.
|
||||
- Medium thinking: 2,048-token reasoning cap, 8,192-token output cap.
|
||||
- Physical GPU power limits stayed at 250 W and 280 W. No power increase.
|
||||
- Historical performance tests used an isolated engine based on official
|
||||
v0.1.38 plus reviewed architectds/PolyStrata changes (best, 05c0f36).
|
||||
This PR contains only our change, ported to official main (99f3dbd).
|
||||
The historical timings are NOT a measured speedup of this pure-upstream port.
|
||||
|
||||
## Historical benefit
|
||||
|
||||
ABBA comparison, two observations per arm, all 20 complete JSON checks passed:
|
||||
|
||||
| Cold input | Serial prefill | Overlapped prefill | Serial request | Overlapped request |
|
||||
| --- | ---: | ---: | ---: | ---: |
|
||||
| 8K | 5.013 s | 5.025 s | 6.727 s | 6.726 s |
|
||||
| 32K | 16.989 s | 16.082 s | 18.468 s | 17.559 s |
|
||||
| 64K | 32.604 s | 31.259 s | 34.354 s | 32.775 s |
|
||||
|
||||
Prefill time fell by 5.3% at 32K and 4.1% at 64K.
|
||||
There was no useful 8K improvement and no decode speedup.
|
||||
Profiling showed roughly 939 ms / 1,553 ms of serial KV-stage wait moving off
|
||||
the critical path. The copies still execute; they are not eliminated.
|
||||
|
||||
## Validation and remaining work
|
||||
|
||||
- Linux compile/link against pure official main (99f3dbd) passed. No engine
|
||||
was started and no production settings were changed.
|
||||
- No claim of a pure-upstream GPU speedup or bitwise numerical parity yet.
|
||||
- The standalone historical prototype did not run the full vision/120K/cancel
|
||||
safety suite. Later combined builds did, but they do not validate this port.
|
||||
- Keep draft until pure-upstream long-context, cancellation, and image-history
|
||||
tests pass. HIP and other GPUs are unvalidated.
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
# LFM2.5-24B-A2B (`strata-poly`)
|
||||
|
||||
`strata-poly`, the engine of GLM 5.3 Flash and the smaller models, also runs Liquid AI's LFM2.5-24B-A2B: llama.cpp's
|
||||
architecture `lfm2moe`, read from the GGUF files of Unsloth and Liquid AI. The server, the web app and the API are the
|
||||
ones the README describes.
|
||||
|
||||
It is new here. This project has run it on two machines: a Windows laptop whose card has 8 GB, and a Linux
|
||||
workstation with a 32 GB card.
|
||||
|
||||
Its license is Liquid AI's LFM Open License v1.0, not an open-source one: commercial use is licensed only to
|
||||
companies under 10 million US dollars of yearly revenue
|
||||
([the license](https://huggingface.co/LiquidAI/LFM2.5-24B-A2B/blob/main/LICENSE)).
|
||||
|
||||
## The sizes
|
||||
|
||||
| Size | From | Download | Experts | RAM beside an 8 GB card (setup's estimate) |
|
||||
| --- | --- | ---: | ---: | ---: |
|
||||
| **UD-Q4_K_XL** | [Unsloth](https://huggingface.co/unsloth/LFM2.5-24B-A2B-GGUF): 4-bit experts, 5- and 6-bit where they write | 14.9 GB | 14.0 GB | about 20 GB |
|
||||
| **UD-Q3_K_XL** | Unsloth: 3-bit i-quant experts, 4-bit where they write | 10.9 GB | 10.2 GB | about 16 GB |
|
||||
| **QAD-Q4_0** | [Liquid AI](https://huggingface.co/LiquidAI/LFM2.5-24B-A2B-GGUF): Q4_0, trained for it (quantization-aware distillation) | 13.6 GB | 12.9 GB | about 18 GB |
|
||||
| **UD-Q6_K_XL** | Unsloth: 6-bit experts, 8-bit where they write | 21.9 GB | 20.9 GB | about 27 GB |
|
||||
| **Q8_0** | Unsloth: 8-bit throughout | 25.5 GB | 24.4 GB | about 31 GB |
|
||||
|
||||
Setup takes UD-Q4_K_XL, or UD-Q3_K_XL when the PC has too little RAM for it; the others are chosen by name
|
||||
(`--model QAD-Q4_0`). Every file is pinned to its repository's commit of 2026-10-15 and checked against its SHA-256.
|
||||
|
||||
## How fast
|
||||
|
||||
The README's numbers are PolyStrata's own benchmark through the server, the test every model of this engine gets
|
||||
([BACKENDS.md](BACKENDS.md#a-prompt-of-30000-tokens)): `polystrata.py benchmark --prompt-tokens 24000`, a short chat
|
||||
and a prompt built from this repository's documents, 256 tokens written after each, three runs a size and the last
|
||||
two below. The engine is 4a644a8d's, with the run configs setup writes for each machine: on both, a prompt is read
|
||||
2,048 tokens at a time.
|
||||
|
||||
### On a laptop with 8 GB of VRAM
|
||||
|
||||
An RTX 4070 Laptop with 8 GB, an i7-14700HX, 32 GB of RAM, Windows 10, CUDA 13.0. A context of 32,768 and 13 threads
|
||||
for the experts the card does not hold. The prompt came to 29,804 tokens.
|
||||
|
||||
| Size | First token, s | Reads, tokens/s | Writes a short chat | Writes after the prompt | Experts from VRAM | Machine's RAM, GiB |
|
||||
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
|
||||
| UD-Q4_K_XL | 8.3 to 8.4 | 3,575 to 3,601 | 67 to 68 | 69 | 52% to 53% | 22.5 to 22.6 |
|
||||
| UD-Q3_K_XL | 7.9 to 8.0 | 3,758 to 3,811 | 80 to 81 | 70 to 76 | 67% | 18.7 to 18.8 |
|
||||
| QAD-Q4_0 | 8.1 | 3,685 to 3,694 | 72 to 73 | 77 to 79 | 59% | 21.1 to 21.2 |
|
||||
| UD-Q6_K_XL | 9.6 to 9.9 | 3,035 to 3,115 | 41 to 44 | 53 to 54 | 36% | 29.1 |
|
||||
| Q8_0 | 10.3 to 12.4 | 2,406 to 2,923 | 19 to 34 | 44 to 47 | 30% to 31% | 31.2 |
|
||||
|
||||
Q8_0 fills the machine's RAM, and part of its file is read from the disk again; that is what makes it the slowest
|
||||
here, and the most uneven. Four passes before this one, with earlier engines, read the prompt at 1,290 to 3,778
|
||||
tokens/s, the last of them, d74c5e25's with the same batch, at 2,954 to 3,778. A README cell has the highest of the
|
||||
five passes: the short chat came a little faster in an earlier one with most sizes.
|
||||
|
||||
### On a workstation
|
||||
|
||||
An RTX 5090 (32 GB), 25 vCPU of a Xeon Platinum 8470Q, 120 GB of RAM, Linux, CUDA 12.8. The card holds every expert
|
||||
of every size. The prompt came to 29,816 tokens.
|
||||
|
||||
| Size | First token, s | Reads, tokens/s | Writes a short chat | Writes after the prompt | Experts from VRAM |
|
||||
| --- | ---: | ---: | ---: | ---: | ---: |
|
||||
| UD-Q4_K_XL | 1.3 to 1.4 | 23,387 to 23,462 | 480 to 485 | 639 to 640 | 100% |
|
||||
| UD-Q3_K_XL | 1.3 to 1.4 | 22,923 to 23,396 | 455 to 472 | 663 to 675 | 100% |
|
||||
| QAD-Q4_0 | 1.3 | 23,878 to 23,899 | 495 to 497 | 419 to 420 | 100% |
|
||||
| UD-Q6_K_XL | 1.5 | 21,252 to 21,270 | 423 to 426 | 366 to 376 | 100% |
|
||||
| Q8_0 | 1.4 | 23,272 to 23,349 | 376 | 341 to 343 | 100% |
|
||||
|
||||
The answer after the prompt goes faster than the short chat where it repeats the prompt's text and the engine's
|
||||
guesses from it are right. One token at a time (`--window 1`), UD-Q4_K_XL writes at 452 tokens/s after a short
|
||||
prompt and at 387 after 29,816 tokens. Three passes before this one, with earlier engines, read the prompt at 10,007
|
||||
to 21,666 tokens/s; a README cell has the highest of the four.
|
||||
|
||||
### Against llama.cpp
|
||||
|
||||
On the laptop, UD-Q4_K_XL through each server with the same prompts
|
||||
([the runs](../bench/results/2026-10-15-laptop-lfm25-llamacpp-b11540/README.md)):
|
||||
|
||||
| | PolyStrata | llama.cpp b11540, `--n-cpu-moe 25` | llama.cpp b11540, `--fit on` |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| Reads about 4,000 tokens | 2,193 to 2,215 tokens/s | 498 to 505 | 483 to 485 |
|
||||
| Writes after them | 89 to 94 tokens/s | 57.7 to 58.0 | 55.1 to 55.3 |
|
||||
| Reads about 32,000 tokens | 3,543 to 3,545 tokens/s | 528 to 537 | 505 to 516 |
|
||||
| Writes after them | 71 to 73 tokens/s | 52.8 to 53.0 | 50.9 to 51.0 |
|
||||
|
||||
`--n-cpu-moe 25` was the fastest of the settings tried for llama.cpp there. On the workstation, `llama-bench` of the
|
||||
llama.cpp that [Strata](https://github.com/Niko1221/Strata) v0.1.39 vendors, every layer on the card and flash
|
||||
attention on:
|
||||
|
||||
| | PolyStrata | llama.cpp, batch of 512 (its default) | llama.cpp, batch of 2,048 |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| Reads 29,816 tokens | 23,400 tokens/s (18,700 with a batch of 1,024) | 13,311 | 23,614 |
|
||||
| Writes, one token at a time | 452 tokens/s | 455 | |
|
||||
| Writes after 29,816 tokens, one at a time | 387 tokens/s | 369 | |
|
||||
|
||||
With a batch of 2,048 llama.cpp reads the prompt as fast as PolyStrata, 1% faster, and writes as fast one token
|
||||
at a time; after the long prompt PolyStrata writes 5% faster. Its guesses add to that where the answer repeats the
|
||||
prompt.
|
||||
|
||||
## Long contexts
|
||||
|
||||
LFM2.5 was trained for 131,072 tokens, and setup offers a context up to that. The test is the one DEEPSEEK.md has:
|
||||
a document of this repository's docs with three facts planted at 15%, 50% and 85% of it, then three questions.
|
||||
UD-Q4_K_XL, a context of 131,072 and prompts read 2,048 tokens at a time:
|
||||
|
||||
- On the workstation, through the server, the 123,609-token request was read and answered in 8.7 s. The answer had
|
||||
the second and the third fact and made the first one up.
|
||||
- Given the prompt as llama.cpp tokenizes it, 123,602 tokens with thinking off, the engine wrote all three facts
|
||||
greedily. llama.cpp's own CUDA build (llama-server of 86ebfef, flash attention on, the same file) wrote the second
|
||||
and the third and made the first one up. The fact furthest back is where the model is least sure.
|
||||
- On the laptop the same tokens were read in 44.7 and 45.4 s, 2,700 tokens/s, and the answer written at 35 tokens/s;
|
||||
its first 80 tokens had the first two facts.
|
||||
|
||||
## How it was checked
|
||||
|
||||
- The tokenizer gives the same ids as llama.cpp's `llama-tokenize` on 174,442 tokens: three READMEs (English,
|
||||
Chinese, Japanese), BACKENDS.md, a Python file and a CUDA file.
|
||||
- With greedy sampling the engine and llama.cpp on the CPU write the same tokens until two candidates are close: 1,
|
||||
39 and 10 of 64 tokens on three short prompts, 20 on a prompt of 17,575 tokens. llama.cpp's CUDA build parts
|
||||
from its CPU build at 5, 40 and 23 tokens on the same three. While they agree on the long prompt, the
|
||||
probabilities are 0.087 apart at most.
|
||||
- A window of guesses writes the same tokens as one token at a time, with the experts on the CPU: 300 tokens after
|
||||
a prompt of 26 tokens and after one of 4,259.
|
||||
- `poly_attend_test`, `poly_norm_q8_test`, `poly_shortconv_test` and `poly_route_test` check the kernels written for
|
||||
it against the ones they stand for; `serve/test_lfm2.py` the tool calls and the chat template.
|
||||
|
||||
## How the sizes compare
|
||||
|
||||
Q8_0 wrote 256 greedy tokens on each of five prompts (code, a summary of 4,260 tokens of BACKENDS.md, arithmetic,
|
||||
a story, a question in Chinese); each other size then followed those tokens, and the share of steps where its most
|
||||
likely token is Q8_0's was counted. Q8_0 stands in for the model as trained here.
|
||||
|
||||
| Size | Same most likely token as Q8_0 | Mean probability of Q8_0's token |
|
||||
| --- | ---: | ---: |
|
||||
| UD-Q6_K_XL | 96.8% (1,239 of 1,280) | 0.782 |
|
||||
| UD-Q4_K_XL | 95.5% (1,222 of 1,280) | 0.781 |
|
||||
| QAD-Q4_0 | 92.7% (1,186 of 1,280) | 0.762 |
|
||||
| UD-Q3_K_XL | 91.6% (1,173 of 1,280) | 0.766 |
|
||||
|
||||
## What was tuned for it
|
||||
|
||||
The decode numbers are UD-Q4_K_XL on the RTX 5090 with the engine's guesses, after a short prompt and after one of
|
||||
4,300 tokens, tokens/s:
|
||||
|
||||
| Commit | Change | Effect |
|
||||
| --- | --- | --- |
|
||||
| d4d5049c | the model runs | 386 and 347 |
|
||||
| 6af34f82 | a layer's residual sum, RMS norm and Q8_1 quantization in one launch | 401 and 359 |
|
||||
| 962da9b9 | the router's kernel with as few slots a lane as 64 experts need | 405 and 368 |
|
||||
| 72a738f6, 165bb4da | with every expert on the card, the card picks a few tokens' experts itself, and a token's 40 layers run as one recorded launch | 454 and 408 |
|
||||
| 4f5947f5 | the attention of a few tokens in blocks of 64 rows, a launch block each | one token at a time after 4,300 tokens 381 to 441, after 30,000 196 to 350; the laptop after 30,000 49 to 56 |
|
||||
| d74c5e25 | a prompt batch's attention in registers, the way FlashAttention-2 goes | a prompt of 29,816 tokens read in 1,852 ms instead of 2,787 on the 5090, in 8.9 s instead of 16.8 on the laptop |
|
||||
| 0ec4802d | setup's config reads 2,048 tokens at a time on a card that holds every expert | 1,415 ms instead of 1,852 |
|
||||
| 36fdc62e | and on any card from 8 GB | the laptop 7.8 to 8.0 s instead of 8.9 to 9.1 |
|
||||
| 3d51cba9 | the blocks of rows added up 16 warps at a time | one token at a time after 30,000 tokens 348 to 388 |
|
||||
| cd87aecd | the next block of keys copied in while attn_flash64 works on one | 1,361 to 1,371 ms instead of 1,398 to 1,400 |
|
||||
| 4a644a8d | a prompt batch's cached experts in three widths of tiles instead of nine | 1,280 ms instead of 1,367 to 1,376 |
|
||||
|
||||
## What you need
|
||||
|
||||
- An NVIDIA card, RTX 20 or newer, with 8 GB of VRAM or more. About 4 GB go to the weights outside the experts, the
|
||||
caches and the buffers at a 32K context; the rest holds experts. A 24 GB card holds the three smaller sizes
|
||||
whole, by setup's estimate.
|
||||
- RAM for the experts the card does not hold. They are read from the mapped file while the model answers, so they
|
||||
should stay in the OS file cache: setup's estimate is in the table above. All five sizes have run on the laptop
|
||||
with 32 GB, but Q8_0 fills it and is slow there.
|
||||
- Linux or Windows 10 / 11. AMD cards: the engine compiles for them on Linux, and this model has not been tried on
|
||||
one; setup says so.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
./setup.sh --family lfm25
|
||||
```
|
||||
|
||||
On Windows, `START-HERE.bat` and pick it from the list. Setup asks for the size, the context and whether to keep
|
||||
several conversations in RAM, downloads the file, checks its SHA-256, writes the tokenizer and the run config
|
||||
`strata-lfm25-<size>.json`, and starts the model. `--model UD-Q3_K_XL` (or another size) skips the question, and
|
||||
`--gguf-dir <folder>` uses a file you already have, under its name from the repository.
|
||||
|
||||
## How it differs from the other models
|
||||
|
||||
- **Most layers have no attention.** 30 of its 40 layers mix the tokens with a short convolution over the last
|
||||
three: each projects a token to three vectors B, C and x, convolves B times x, and scales the result by C. Its
|
||||
state is two vectors a layer. The other 10 layers attend over the whole conversation, with 8 key heads of 64
|
||||
values, so a context token takes 20,480 bytes of VRAM: a 128K context takes 2.0 GB more than 32K.
|
||||
- **The experts.** 38 layers have 64 routed experts each, of which a token uses 4, with sigmoid gates, a bias that
|
||||
steers the pick and weights that sum to one. There is no shared expert. The first two layers have a plain FFN.
|
||||
The output matrix is the token table.
|
||||
- **No draft block.** The files have nothing that guesses ahead, so the engine guesses only from text the
|
||||
conversation repeats, as for DeepSeek V4 Flash.
|
||||
- **Tool calls** come as a Python list between two tokens, `<|tool_call_start|>[f(a='x'), g(b=1)]<|tool_call_end|>`,
|
||||
several calls in one; the server turns them into OpenAI's and Anthropic's tool calls.
|
||||
- **Thinking.** The template always opens a `<think>` block; with thinking off the server closes it at once, as for
|
||||
GLM. Liquid AI's model card suggests temperature 0.1, top-k 50 and a repetition penalty of 1.05; setup does not
|
||||
set them. To use them for clients that send no sampling of their own, add
|
||||
`"sampling": {"temperature": 0.1, "top_k": 50, "repetition_penalty": 1.05}` to the run config.
|
||||
|
||||
## What is missing
|
||||
|
||||
- Pictures: the model reads text only.
|
||||
- A draft model. Liquid AI publishes none for it.
|
||||
- Contexts past 128K: it was trained for 131,072 tokens, and setup offers up to that.
|
||||
@@ -0,0 +1,76 @@
|
||||
# Per-request token biases
|
||||
|
||||
`POST /v1/chat/completions` accepts `logit_bias` with a supporting CUDA or HIP
|
||||
engine, without continuous batching. The same bias applies to every generated
|
||||
token in the request, including tokens checked together during speculative
|
||||
decoding. It does not force single-token verification windows.
|
||||
|
||||
## Example: Hello becomes Hi
|
||||
|
||||
We use `Hello` because it is a familiar word, it is exactly one token in the
|
||||
tested tokenizer, and the unbiased model naturally chooses it for this prompt.
|
||||
The tokenizer maps `Hello` to **token ID 9419**. That number identifies the token;
|
||||
it is not its logit or probability. The value **-100** is the requested bias,
|
||||
which this implementation treats as a hard exclusion.
|
||||
|
||||
Before: send this request without a bias. The measured response was **Hello**.
|
||||
|
||||
```json
|
||||
{
|
||||
"model": "bias-validation",
|
||||
"messages": [{"role": "user", "content": "Reply with one English greeting, one word only."}],
|
||||
"max_tokens": 8,
|
||||
"temperature": 0,
|
||||
"reasoning_effort": "none"
|
||||
}
|
||||
```
|
||||
|
||||
After: add only `logit_bias`. The measured response was **Hi** (token 12675).
|
||||
|
||||
```json
|
||||
{
|
||||
"model": "bias-validation",
|
||||
"messages": [{"role": "user", "content": "Reply with one English greeting, one word only."}],
|
||||
"max_tokens": 8,
|
||||
"temperature": 0,
|
||||
"reasoning_effort": "none",
|
||||
"logit_bias": {"9419": -100}
|
||||
}
|
||||
```
|
||||
|
||||
The equivalent llama.cpp-style pair list is `"logit_bias": [[9419, false]]`;
|
||||
it also produced **Hi**. Removing the field on the next request restored **Hello**.
|
||||
Nothing is banned by default. This is a per-request example, not a built-in list.
|
||||
The `model` value above is the test server's alias; use your server's model name.
|
||||
Numeric pair values are also supported, for example `[[42, 2.5]]`.
|
||||
Token IDs belong to the loaded model's tokenizer; the example ID is not portable
|
||||
between arbitrary models. Leading spaces and letter case can also change token IDs.
|
||||
The four English requests were measured on ISTA IQ3_XXS; a
|
||||
[reproduction script](../tools/logit_bias_english_example.py) is included.
|
||||
|
||||
## Semantics and limits
|
||||
|
||||
Biases must be finite numbers in `[-100, 100]`. Negative values discourage a
|
||||
token, positive values encourage it, and **-100 excludes it** (`false` in a
|
||||
pair list has the same meaning). The bias is added before repetition/frequency/
|
||||
presence penalties, temperature, and candidate filtering. Raw model logits
|
||||
are not overwritten. Banning a token does not ban a word or language: other
|
||||
token sequences may produce the same text.
|
||||
|
||||
Omitting the field, `null`, `{}`, or `[]` clears the previous request's bias.
|
||||
Biases are request sampling state; they are not stored in a conversation cache.
|
||||
They do not change the model weights or prompt KV. A fixed dense vocabulary
|
||||
vector is uploaded when the bias changes and reused within the request.
|
||||
|
||||
Malformed entries, duplicate IDs in pair lists, IDs outside the vocabulary,
|
||||
out-of-range biases, or banning the entire vocabulary return HTTP 400. Validation
|
||||
on the chat route occurs before SSE streaming headers are sent. Nonempty biases
|
||||
also return HTTP 400 with older engines, the current SYCL engine, or continuous
|
||||
batching (`--batch`), rather than being silently ignored. The engine advertises
|
||||
`logit_bias=1` in its `INFO` response when this implementation is present.
|
||||
|
||||
MTP target verification applies the bias; the draft model is not biased, so a
|
||||
restrictive list may reduce draft acceptance. Ordinary MTP was tested. The
|
||||
experimental coupled/rejection-sampling combinations and multi-GPU execution
|
||||
were not validated in this campaign. There is no startup bias-file option in
|
||||
this change: send the field with each request.
|
||||
+222
@@ -0,0 +1,222 @@
|
||||
# PolyStrata on a Mac (Apple Silicon, Metal)
|
||||
|
||||
PolyStrata runs on Apple Silicon Macs through its own engine on Metal. This is the same engine as on a PC. The NVIDIA
|
||||
kernels are replaced by Metal ones (`metal/`), and the host code and the server are the PC's. `./setup.sh` sets it up the way
|
||||
`START-HERE.bat` does on Windows. There is no ready-made Mac engine: setup builds it from source on your Mac
|
||||
(about 1-15 minutes). The NVIDIA, AMD and Intel engines are unchanged.
|
||||
|
||||
**Status:** new. It is measured on three Macs: an M5 Max with 128 GB, where the model stays in memory; and an M4 Mac mini
|
||||
with 32 GB and an M1 Max with 34 GB, where the experts stream from the SSD (the M1 Max: 7.9 tok/s decode, 186 tok/s on a
|
||||
9,940-token prompt, Q2_0, the expert cache at 64 slots, as reported with the kernel fix #2348). Other chips are untested, and reports help
|
||||
([COMMUNITY_BENCHMARKS.md](COMMUNITY_BENCHMARKS.md)).
|
||||
|
||||
## What you need
|
||||
|
||||
- **An Apple Silicon Mac (M1 or newer).** Intel Macs cannot run it.
|
||||
- **macOS 15 or newer.** The engine keeps its buffers resident through a residency set, which macOS 15 introduced.
|
||||
- **The Command Line Tools:** `xcode-select --install`. That is the compiler. Xcode itself is not needed.
|
||||
- **Enough unified memory for the pack.** The GPU maps the model's main file and keeps it in memory while the model runs. Metal lets one
|
||||
program keep about 3/4 of the memory resident (107.5 GB of 128 GB, measured on the M5 Max).
|
||||
|
||||
| Pack | The file the GPU maps | Needs about (with the prompt buffers, KV cache, draft layer) | Recommended from |
|
||||
|---|---|---|---|
|
||||
| Q2_0 | 37.6 GB | 46 GB | 64 GB |
|
||||
| IQ3_XXS | 47.0 GB | 55 GB | 74 GB (where IQ3_S does not fit) |
|
||||
| IQ3_S (recommended; the default from 96 GB) | 54.8 GB | 63 GB | 96 GB |
|
||||
| UD-Q4_K_XL (Unsloth, recommended: higher quality) | 82.6 GB | 91 GB | 128 GB |
|
||||
| UD-Q5_K_XL, UD-Q6_K_XL (Unsloth) | 103.9 / 114.8 GB | stream from the SSD on 128 GB | 128 GB, streamed |
|
||||
|
||||
- **The n-gram table:** each pack also has a 28.8 GB n-gram table (the model's second file). It is read from the SSD a few rows at a time and does not count against the memory above.
|
||||
- **Disk:** the download is 66-84 GB, plus about 7 GB for the pack and the draft layer. A Mac that streams also needs room for the experts' copy (below): 34-40 GB.
|
||||
- **A Mac whose memory cannot hold the pack (32-48 GB):** the engine streams the experts from the SSD instead. It decides this by itself when the experts are more than 60% of Metal's share.
|
||||
- It keeps the most-used experts in an arena: Metal's share, or the memory macOS reports as available less what it keeps for macOS, whichever is smaller. It keeps 7 GB, or 15% of the RAM when that is more, and it also keeps the n-gram table's share. It counts as free only what macOS can give without swapping (free and purgeable memory and the clean file cache, not other programs' idle memory). It checks again just before it takes the arena, and fills the arena in 1.5 GB steps, checking again before each one; it stops early rather than push macOS below what it keeps. On a Mac with 64 GB or more the arena, the Metal buffers and the host memory together also stay under 60% of the RAM (see "The engine's whole anonymous footprint" below).
|
||||
- It reads the rest as each token needs them, and reads ahead the experts the next layer will probably use.
|
||||
- Setup writes a second copy of the experts for such a Mac (`<model>.experts`, 40 GB for IQ3_XXS). In it each expert's three matrices sit together, so the SSD reads an expert with one request instead of three. On the 32 GB M4 that is about 17% faster decoding and 30% faster prompts, with the same tokens. Setup writes it only when the disk has room for it plus 10 GB; otherwise it warns, and the engine reads the model file as before.
|
||||
- Setup configures such a Mac without the MTP draft layer: one token per step is faster there.
|
||||
- Measured at 32 GB (below). Smaller Macs are untested.
|
||||
- **Setup recommends, and never forces.** It recommends the pack by memory; a bigger pack chosen with `--model` is kept, with a warning about what it risks.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
git clone https://github.com/Niko1221/Strata && cd PolyStrata
|
||||
./setup.sh # asks the size; --yes takes the recommended answers
|
||||
```
|
||||
|
||||
What the first run does (each step is skipped when it is already done):
|
||||
|
||||
1. **Python.** It needs Python 3.10 or newer, but macOS ships 3.9. If that is all your Mac has, `setup.sh` downloads a standalone Python 3.12 (25 MB, pinned by SHA-256) into `.python`. No sudo, no Homebrew.
|
||||
2. **Checks your Mac:** the chip, the memory, the macOS version, the Command Line Tools and the free disk.
|
||||
3. **Python packages** into `.venv`. CMake and Ninja come from pip.
|
||||
4. **Builds the engine** (`build-metal/strata`). It uses Apple's metal-cpp headers (pinned by SHA-256) and llama.cpp's ggml at the commit the PC build pins.
|
||||
5. **Downloads the model.** The download resumes if interrupted. `--gguf-dir` uses files you already have.
|
||||
6. **Prepares the model:** the pack (seconds), and the MTP draft layer (about 5 GB of the original checkpoint). On a Mac that streams: the experts' copy instead of the draft layer (about 3 minutes on the M4, checked byte for byte against the model file).
|
||||
7. **Writes `strata-<model>.json` and `run-<model>.sh`, then starts the server.**
|
||||
|
||||
The config uses the Mac defaults: `--spec 2` and the Q8_0 hyper-connection read (below). After that, `./setup.sh` or `./run-q2_0.sh` starts the model directly. The server is the same as on a PC:
|
||||
- the OpenAI-compatible API on `http://127.0.0.1:8080/v1`;
|
||||
- the Anthropic API on `/v1/messages`;
|
||||
- the chat page on `http://127.0.0.1:8080/`.
|
||||
|
||||
Options: `--model Q2_0|IQ3_XXS|IQ3_S|UD-Q4_K_XL|UD-Q5_K_XL|UD-Q6_K_XL` (the UD files are Unsloth's), `--vision yes|no`, `--context N`, `--port`, `--host` / `--api-key`, `--draft-vocab`, `--no-browser`,
|
||||
`--data-dir`, `--models-dir`, `--gguf-dir`, `--setup` (another model or new settings), `--no-start`, `--check` (only
|
||||
check the Mac), `--build` (build the engine again).
|
||||
|
||||
## Measured (M5 Max, 128 GB, macOS 27.2)
|
||||
|
||||
**Decode**, in tokens per second over 200 generated tokens, with greedy answers. The table gives two prompts: a short question
|
||||
("prompt1") and a story.
|
||||
|
||||
| | Q2_0 | IQ3_XXS | IQ3_S |
|
||||
|---|---|---|---|
|
||||
| Setup's defaults (`--spec 2` with MTP, the suffix drafter on) | **119.5 / 108.2** | **108.9 / 97.0** | - |
|
||||
| `--spec 2` with MTP, suffix drafter off | 114.0 / 107.9 | 103.5 / 96.9 | 98.2 / 94.1 |
|
||||
| No MTP (one token per step) | 87.4 / 87.3 | 78.7 / 78.6 | 74.5 / 74.3 |
|
||||
|
||||
The output with MTP is the same as without it, token for token, in every run. MTP only proposes tokens, and the
|
||||
full model checks every one of them.
|
||||
|
||||
**Prompt reading** (time to the first token), on the needle-test prompts below:
|
||||
|
||||
| | 4K tokens | 32K tokens |
|
||||
|---|---|---|
|
||||
| Q2_0 | ~1,430 tok/s | ~1,460 tok/s |
|
||||
| IQ3_XXS | ~1,260 tok/s | ~1,240 tok/s |
|
||||
| IQ3_S | ~1,320 tok/s | ~1,140-1,190 tok/s |
|
||||
|
||||
The first prompt after the Mac starts is slower, while macOS reads the model file (IQ3_S: 413 tok/s on the first 4K
|
||||
prompt, cold).
|
||||
|
||||
**For comparison**, llama.cpp on the same Mac with Q2_0: 56.6 tok/s decode on the story, and 887 / 809 tok/s on 4K / 32K prompts.
|
||||
|
||||
### Unsloth's UD-Q4/Q5/Q6_K_XL on the M5 Max
|
||||
|
||||
IQ3_S and UD-Q4_K_XL are the recommended sizes. Setup offers IQ3_S as the default and names UD-Q4_K_XL as the
|
||||
higher-quality choice where it fits. Decode is tokens per second over 200 tokens (greedy, MTP); prompts are the warm rate
|
||||
of the second request on (the first request after the start pays a few seconds of first-use cost).
|
||||
|
||||
| | IQ3_S | UD-Q4_K_XL | UD-Q5_K_XL (streamed) | UD-Q6_K_XL (streamed) |
|
||||
|---|---|---|---|---|
|
||||
| Quality against Q8_0 (top-1 / KL) | 87.9% / 0.142 | 92.8% / 0.055 | not measured | not measured |
|
||||
| Decode, short question, no MTP / MTP | 75.4 / 101.9 | 60.7 / 94.0 | - | - |
|
||||
| Decode, story, no MTP / MTP | 74.8 / 94.7 | 59.7 / 73.7 | 28 / 46-51 (`--spec 3`) | not measured / 47-51 (`--spec 3`) |
|
||||
| Prompt 4K / 32K | ~1,180 / ~1,290 | ~1,150 / ~1,290 | ~1,070 / ~1,110 | ~1,020 / ~1,020 |
|
||||
| llama.cpp Metal, decode (story / code) | 51.1 / 44.1 | 48.4 / 47.3 | 45.1 / 43.2 | does not run (Insufficient Memory) |
|
||||
| llama.cpp Metal, prompt 4K / 32K | 791 / 730 | 821 / 739 | 729 / 693 | - |
|
||||
|
||||
- **UD-Q5 and UD-Q6 cannot stay resident:** their repacked file (103.9 and 114.8 GB) is bigger than the largest buffer Metal gives (86.6 GB), so the experts stream from the SSD into an arena of about 65-67 GB on the 128 GB M5 Max (about 68% of Q5's experts, 62% of Q6's; it was 80-86 GB before the footprint cap below, and the decode and prompt speeds did not change: Q6 story 51 tok/s, 15K prompt 1,020 tok/s at both sizes).
|
||||
- **The cost is a fixed hand-shake per layer** (the engine reads the router's choice and makes sure the experts are in the arena), not the SSD. A window of 2 tokens costs 38 ms against ~17 resident, so a longer window pays: Q5 story 28 tok/s without MTP, 41.8 with `--spec 2`, 50.6 with `--spec 3`, 46 with `--spec 4`. Setup writes `--spec 3` and keeps the MTP draft layer for a streaming Mac with 96 GB or more.
|
||||
- **The engine's whole anonymous footprint is limited to 60% of the RAM on a Mac with 64 GB or more (82.4 GB of the M5 Max's 137.4 GB): the arena, every Metal buffer and the host memory the process holds, not only the Metal buffers.** macOS keeps a floor of file cache (`vm.vm_page_filecache_min`: 37.2 GB here) and compresses anonymous memory instead of dropping cache below it. The arena is anonymous, and the GPU wires it only while a command buffer runs, so while it is filled it is ordinary pageable memory. Two kernel panics on the M5 Max (the watchdog daemon starved for 92 s) had the engine at 95 and 90 GiB resident and the compressor at 2-4 million pages. Measured again with a memory watchdog every second: an old-build arena of 100 GB compressed 19 GB of itself in 7 seconds and swapped 24,000 pages; the old automatic arena (69 GB) with a 40 GB file write and a 16 GB program beside it took the compressor from 21,000 to 4.07 million pages in 10 seconds (pressure "warn"). With 30% left (footprint 94.5 GB) and the file write alone, 12,000 pages were swapped out; with 35% left, 316; with 40% left and the write and the 16 GB program, none and the compressor at 0.3 million pages. The old rule (arena + Metal buffers under 67%) counted 7.5 GB of buffers where the process held 11-15 GB, so its real total was about 100 GB. A resident pack is different (clean file pages that macOS drops, never compresses): UD-Q4_K_XL resident (wired 91.7 GB) took the same 40 GB write and 16 GB program with no swap-out and nothing compressed, so resident packs are limited to 70% of the RAM as before. The arena is also wired (`mlock`) once it is filled: unwired it is ordinary pageable memory whenever the GPU is idle (the GPU's own wiring ends a few seconds after its last command buffer; a Metal residency set did not hold it), and a 20 GB file written beside the idle engine took the arena into the compressor and froze the Mac (a third watchdog panic, in a control run of this work). Wired, the same write at full speed raised the compressor by 0.7 million pages (the engine's non-arena memory), swapped out 408 pages and changed nothing else. `STRATA_METAL_WIRE_ARENA=0` turns it off; it is on for Macs with 64 GB or more. The engine prints the planned total (`planned resident footprint ... cap ...`) and the footprint after the fill. `STRATA_METAL_ARENA_GB` still sets the arena as you say, with a warning when it is over the cap.
|
||||
- **The experts' copy** (`<model>.experts`, 98 GB for Q5) did not pay on the M5 Max: decode 50.3 against 50.2 tok/s without it, 4K prompt 741 against 685 (noisy). Setup does not write it on a Mac with 96 GB or more.
|
||||
- **Prompts stream in chunks of 4096** on a streaming Mac with 96 GB or more (the engine's own default there; 1024 on a smaller one): every chunk makes one pass over the experts that are not in the arena, so a longer chunk reads them fewer times. UD-Q5, warm, 2 interleaved rounds: chunks of 1024 gave 700 tok/s on the 4K prompt, 2048 gave 920 and 4096 gave 1,100 (32K: 710, 970, 1,100); the decode did not change. `STRATA_METAL_PROMPT_CHUNK=N` sets it. On a resident model 4096 instead of 2048 gained only 2-4% (Q2_0), so that default stays.
|
||||
|
||||
### M4 Mac mini, 32 GB, experts streamed from the SSD
|
||||
|
||||
The arena was 11.5-14.7 GB. Tokens per second, one token per step (no MTP), medians of 5 interleaved runs:
|
||||
|
||||
| | Q2_0 | IQ3_XXS | llama.cpp, CPU only (Q2_0 / IQ3_XXS) |
|
||||
|---|---|---|---|
|
||||
| Decode, short question (200 tokens) | **14.1** | **10.0** | 6.3 / 4.1 |
|
||||
| Decode, story (200 tokens) | **13.5** | **9.2** | 6.3 / 4.1 |
|
||||
| Decode after a 6K-token document | **13.1** | **7.7** | 5.1 / 2.8 |
|
||||
| Prompt, 4K tokens | **93.6** | **65.8** | 21.2 / 8.7 |
|
||||
|
||||
- The greedy answers equal the M5 Max's (model in memory) on 10 of 10 test prompts, for both packs.
|
||||
- No memory was swapped out during the runs; the least memory left to macOS was 7.1 GB.
|
||||
- MTP was slower here (Q2_0 story 12.1-12.3 with it against 12.3-12.8 without). The draft layer's 1.2 GB do more as expert cache.
|
||||
|
||||
**The experts' copy** (`<model>.experts`, one SSD request per expert): IQ3_XXS after the 6K-token document, the arena held at 12 GB, medians of 5 interleaved runs each:
|
||||
|
||||
| | Decode | The 6K prompt | SSD wait per token |
|
||||
|---|---|---|---|
|
||||
| The model file (three reads per expert) | 7.37 tok/s | 64.7 tok/s | 46.6 ms |
|
||||
| The experts' copy (one read per expert) | **8.62 tok/s** | **84.1 tok/s** | 31.5 ms |
|
||||
|
||||
- The tokens are identical in all 10 runs.
|
||||
- The 4K-token prompt (3 interleaved runs each, default arena): 72.9 tok/s with the copy against 62.5 with the model file (+17%), the same tokens.
|
||||
- 32K-token prompts through the server, with the copy: 29,768 tokens at 89.2 tok/s (5.6 minutes to the first token), 33,803 tokens at 84.4 tok/s. The code word was found both times.
|
||||
- A 34-minute server run with the copy (47 requests: 32K and 6K needles, short questions, a story, code; context 34,816) got every answer right and did not slow down over time. Decode was 7.2-7.7 tok/s on short answers and 9.9-10.4 on the story; the 6K prompts ran at 80-90 tok/s. macOS's memory pressure was never critical: one 2-second "warn" sample while the arena filled at the start. About 90 MB were swapped out in those same 2 seconds and nothing after; three restarts afterwards (smaller arenas, less memory free) swapped nothing.
|
||||
- The SSD alone measures the same: 2.97 GB/s for one 1.75 MB read per expert against 2.30 GB/s for three 0.58 MB reads (6 threads, uncached).
|
||||
- The arena's size matters most. With the model file, a 7.5 GB arena gave 5.5 tok/s, 10.5 GB gave 6.7 and 12 GB gave 7.5. The read-ahead depth, the I/O threads and the eviction order each moved decode by less than 3%.
|
||||
- The Q2_0 copy is not measured yet. The numbers in the table above are with the model file.
|
||||
- **Measured again on the release build, with less memory free:** the M4 had 13-17 GB available when the engine started (another user's programs held the rest), so the arena was 5.7 GB (Q2_0) and 9.3 GB (IQ3_XXS, with the experts' copy). One token per step, medians of 3: Q2_0 story 8.3 tok/s, 4K prompt 80; IQ3_XXS story 8.3, 4K prompt 89. That is the arena's size effect above, not a regression: with a 6.6 GB arena the engine used to stop at the first prompt ("no free slot"); a small arena now gives the prompt's 1.6 GB of buffers their own allocation, also when no chunk of the arena is big enough for them (on a 24 GB M2 whose arena shrank below the prompt's needs, every prompt stopped with "no arena region for the prompt buffers"), and a 26-minute server run with a 5.4 GB arena (29 requests, 6K and 31K needles found) was clean.
|
||||
- With the default arena (12.1-12.2 GB here), the experts' copy gives 8.35-8.48 tok/s decode and 82.5-82.8 tok/s on the prompt. Nothing was swapped out. macOS's memory pressure stayed "normal", except for one 2-second "warn" sample while the arena fills; keeping 7 GB for macOS shows the same sample.
|
||||
- Those runs and the server run below kept 5 GB for macOS. The default is now 7 GB with the stepped fill: after the 6K document, 7.3 and 6.7 tok/s decode (arenas 9.3 and 7.6 GB, as much as was free), the same tokens, the memory pressure "normal" throughout and nothing swapped out.
|
||||
|
||||
**Why `--spec 2`:** measured with MTP on the same two prompts.
|
||||
|
||||
| Window | Q2_0 (prompt1 / story) | IQ3_XXS (prompt1 / story) |
|
||||
|---|---|---|
|
||||
| `--spec 2` | 111 / 106 | 102 / 95 |
|
||||
| `--spec 3` | 116 / 92 | 108 / 95 |
|
||||
| `--spec 4` | 111 / 81 | 108 / 83 |
|
||||
| `--spec 5-6` | slower | slower |
|
||||
|
||||
`--spec 2` is the best default on mixed text. An explicit `--spec N` in the config's `args` is kept.
|
||||
|
||||
### Quality
|
||||
|
||||
- **The Q8_0 hyper-connection read is the default on Mac.** It keeps a Q8_0 copy of the hyper-connection matrices instead of BF16. `STRATA_HC_Q8=0` in the config's `env` gives the exact BF16 read.
|
||||
- **How the KL was measured:** teacher-forced over 28 prompts (code, reasoning, chat, six languages, documents), about 6,000 positions per set. The reference is BF16.
|
||||
- On the model's own text: mean KL 0.0007, top-1 agreement 98.9%.
|
||||
- On another model's text: mean KL 0.0007, top-1 agreement 99.1%.
|
||||
- Perplexity of the text is unchanged (×0.9995 and ×1.0006).
|
||||
- For scale, IQ3_XXS against Q2_0 is a KL of 0.094.
|
||||
- The Mac engine is deterministic: two runs give identical numbers.
|
||||
- **The fast prompt path** (the prompt kernels) against reading the prompt through decode windows: mean KL 0.0004, top-1 99.4-99.6%.
|
||||
- **Needles:** a code word hidden in 8K, 16K and 32K tokens of text, at 10/50/90% depth. Found 9 of 9 with Q2_0 and with IQ3_XXS, both with Q8_0 and with BF16. With the fast prompt path (4K-32K) the answers are the same.
|
||||
- **Same answers as on a PC:**
|
||||
- against the CUDA engine on a Tesla P100 (IQ3_XXS and IQ3_S), the first 200 tokens of a reply are identical on the short question;
|
||||
- on the story, the first IQ3_S tokens differ at token 1, a near-tie (margin 0.12). Following the CUDA engine's tokens, 4 of 200 picks differ, all at margins 0.06-0.21;
|
||||
- against the HIP engine on a Radeon AI PRO R9700 (Q2_0), 36 of 39 first tokens are identical.
|
||||
- The differences are near-ties between the two best tokens, from a different floating-point order.
|
||||
|
||||
## Limits (this version)
|
||||
|
||||
- **Images (vision):** `--vision yes` in setup. Checked on one test picture with Q2_0 and UD-Q4_K_XL: the answers equal the HIP engine's, and text output is unchanged with vision on. No other tests yet.
|
||||
- **Context:** measured up to 32K (needles, KL). Setup recommends 32K below 96 GB and 64K from 96 GB. Up to the model's 262K can be set, but it is not measured.
|
||||
- **One request at a time.** `--parallel` (batch slots) is not ported. Several clients queue.
|
||||
- **Not ported:** the control vector (`--control-vector-scaled`) and the PC tuning (`--calibrate`).
|
||||
- **Streaming:** measured at 32 GB only. The model's file must be on the internal SSD; an external disk is untested and likely much slower.
|
||||
- **Families:** the original Qwen3.8-Flash-Next and Unsloth's UD-Q4/Q5/Q6_K_XL are measured (above). Setup repacks Unsloth's shards into one file for the GPU. The Swift and Coder releases are not set up on Mac yet, and Qwen3.6 does not run on the Mac engine.
|
||||
- **Engine only from source.** There is no ready-made Mac engine in the release zips.
|
||||
|
||||
## Switches (for testing; all off unless set, the defaults are above)
|
||||
|
||||
| Variable | Effect |
|
||||
|---|---|
|
||||
| `STRATA_HC_Q8=0` | The BF16 hyper-connection read (exact) instead of Q8_0 |
|
||||
| `STRATA_METAL_PROMPT=window` | Read the prompt through decode windows (the slow, exact fallback; ~190 tok/s) |
|
||||
| `STRATA_METAL_PROMPT_CHUNK=N` | Prompt chunk size (default 2048) |
|
||||
| `STRATA_METAL_MTP_Q8=0` | The draft layer's matrices in BF16 instead of Q8_0 |
|
||||
| `STRATA_METAL_MTP_CHAIN=0` | One GPU submission per draft step instead of one per round |
|
||||
| `STRATA_METAL_FUSE=0`, `STRATA_METAL_LAZY_FOLD=0` | Turn off two decode fusions (same tokens, slower) |
|
||||
| `STRATA_METAL_PARTIAL=1`, `STRATA_METAL_ROUTE=1` | Two decode variants that measured no faster here (same tokens) |
|
||||
| `STRATA_METAL_STREAM=1` / `=0` | Stream the experts from the SSD even when the pack fits / never (the default decides by size) |
|
||||
| `STRATA_METAL_CONTIG=0` | Streaming: read the model file even when the experts' copy is there |
|
||||
| `STRATA_METAL_ARENA_GB=N`, `STRATA_METAL_KEEP_FREE_GB=N` | Streaming: the arena's size, or the memory left to macOS when the arena is sized |
|
||||
| `STRATA_METAL_LEAVE_SHARE=0.4` | Streaming, Macs with 64 GB or more: the share of the RAM left to macOS and its file cache when the footprint cap is set (for measuring) |
|
||||
| `STRATA_METAL_WIRE_ARENA=0` | Streaming, Macs with 64 GB or more: leave the filled arena pageable (default: wired with mlock) |
|
||||
| `STRATA_METAL_IGNORE_REPACK=1` | Start the engine although a model repack or setup's preparation is running beside it (the engine refuses by default: it froze this Mac) |
|
||||
| `STRATA_METAL_KEEP_HOST_WEIGHTS=1` | Streaming: keep the host code's own copies of the weights (2-3 GB) instead of giving them back to macOS |
|
||||
| `STRATA_METAL_TRACE=1`, `STRATA_METAL_PROFILE=1`, `STRATA_METAL_KPROF=T` | Per-window traces, a time breakdown, per-kernel GPU times |
|
||||
|
||||
**Two opt-ins an M1 Max cannot run (measured on an M1 Max, macOS 26.6.2, Q2_0):** `STRATA_METAL_PROMPT_EXPERTS=v3` - the
|
||||
prompt's expert GEMMs with the M5's layout, `mm_gu3` - loses the threadgroup once a prompt spreads over more than 40
|
||||
threadgroups of it (35 pass, 40 fail; 190 tiles and the engine's tile both fail, one tile passes), so it is off there (the
|
||||
default is v2). `STRATA_METAL_ROUTE=1` - the router GEMV and `moe_route` fused into one dispatch - routes with stale
|
||||
logits and gives a different top-10 per run (two identical runs differ in ids, weights and plan; the logits themselves
|
||||
stay bitwise): the fusion hands the routing to the last threadgroup of the GEMV through a device counter, and this
|
||||
Metal's device atomics are relaxed-only, with no acquire to pair with the writers' fence. Both are off by default. The
|
||||
`no faster` measurement in the table is from the Macs above; on an M1 Max `ROUTE` is also wrong.
|
||||
|
||||
## How it works
|
||||
|
||||
The code is in `metal/` (the engine's side in `metal/src/engine`, the kernels in `metal/kernels`). In short:
|
||||
- **Host code:** the PC host code compiles unchanged for macOS. `metal/include/metal_compat` maps the CUDA runtime calls it makes onto a small Metal runtime (`metal/src/gpu`).
|
||||
- **The decode and prompt work** run in Metal kernels (`metal/kernels`, `metal/src/engine`):
|
||||
- one command buffer per verify window;
|
||||
- the experts are read in place from the mapped model file;
|
||||
- the hyper-connections, the GDN state and the QSA attention stay on the GPU;
|
||||
- a whole MTP draft round runs in one command buffer.
|
||||
- **The PC builds are byte-identical** with this code present. Every shared file's change is behind `STRATA_GPU_METAL` or `__APPLE__`, and the CUDA and HIP objects are compared after each change.
|
||||
@@ -0,0 +1,74 @@
|
||||
# Where the model lives: GPU, RAM, SSD
|
||||
|
||||
Qwen3.8 Flash-Next GSQ-RCO on a 16 GB VRAM frame, measured 2026-10-20 (Coder IQ1_M, RTX 3090, arena mode).
|
||||
|
||||

|
||||
|
||||
(`strata-mem-layout.excalidraw` is the source of the drawing.)
|
||||
|
||||
The model is two GGUF shards: shard 1 (29.6 GB for Coder) holds the experts, dense layers and attention; shard 2
|
||||
(28.8 GB, the same file for every GSQ-RCO quant) is the n-gram table. The engine never holds all of it anywhere.
|
||||
|
||||
## GPU
|
||||
|
||||
| what | Coder, `--vram-reserve-mib 8700` on a 24 GB card |
|
||||
|---|---|
|
||||
| expert cache | 9.28 GiB, 4,881 slots: the experts ranked highest in `--expert-profile`, pre-filled at start |
|
||||
| dense layers, attention weights | the non-expert part of shard 1 |
|
||||
| MTP draft layer | 820 MiB (`--mtp`) |
|
||||
| KV cache, resident part | `--kv-resident 32768` cells of the 131,072-cell context, rotated q4_0 |
|
||||
| prompt path | borrows 2,223 of the cache's slots (4.18 GiB) during prefill; not extra memory |
|
||||
|
||||
`--vram-reserve-mib N` is the binding cap: the cache sizes itself to what is left, and `--expert-cache N` is
|
||||
clamped to it. Peak during a 99k-token prompt: 16,024 MiB.
|
||||
|
||||
## RAM
|
||||
|
||||
What is in RAM depends on the expert mode. The cache in VRAM is the same in all three; the difference is where a
|
||||
cache miss is served from.
|
||||
|
||||
| mode | flag | in RAM | a miss is |
|
||||
|---|---|---|---|
|
||||
| arena (default) | none | the whole expert set, page-locked with `cudaHostRegister` (23.4 GiB for Coder, ~30 GiB for IQ2_XS) | a DMA read over PCIe; the GPU computes every expert |
|
||||
| resident | `--resident-experts` | only the complement of the GPU cache, page-locked (24 GiB for IQ2_XS at 7,389 slots) | the same, for what fits; the memory probe sizes the copy with 4 GiB of headroom |
|
||||
| mmap | `--mmap-experts` | nothing on purpose; the shards are mapped and the page cache holds what was touched | a page fault on the decode path, computed by the CPU pool |
|
||||
|
||||
Two more residents in every mode: the KV cells that are not in VRAM, in 0.84 GiB of pinned RAM, streamed in on
|
||||
demand; and the engine itself (about 2 GiB over the arena: 26.4 GiB RSS for Coder).
|
||||
|
||||
Measured on the same 3090 with 40 % of Coder's experts in VRAM: arena 67-99 tok/s decode, mmap 20 tok/s. The mmap
|
||||
mode is for a machine whose GPU holds most of the experts; a 16 GB frame is not that machine.
|
||||
|
||||
`--resident-experts` falls back to mmap, silently, when the memory probe fails. It fails inside RunPod containers
|
||||
(cgroup v1 with a hybrid `0::/docker/...` line, [issue #16](https://github.com/robertkarl/UnbiasedStrata/issues/16)).
|
||||
The arena mode reads the limit through the memory guard instead and works there.
|
||||
|
||||
## SSD, and the page-cache trap
|
||||
|
||||
The n-gram table (shard 2, 28.8 GB) is read a few rows per token. `--ple-io direct`, the default, reads them
|
||||
unbuffered: the table never occupies RAM. `--ple-io mmap` maps it and `--ple-io ram` copies it; both are for drives
|
||||
too slow for the direct reads.
|
||||
|
||||
With `mmap`, the hot rows accumulate in the page cache, which is the strip at the bottom of the RAM box in the drawing.
|
||||
On a box with RAM to spare that strip grows until the table's working set is in memory, and the run is no longer the
|
||||
run of the machine it claims to be. The Coder run above, on a pod with a 125 GB cgroup, showed 25.5 GiB of RSS next to
|
||||
65 GiB of page cache with 24 GiB of it mapped file pages; a 32 GB machine would have been evicting those pages and
|
||||
faulting them back. Both runs were restarted with `--ple-io direct` (decode 47-50 tok/s on the pod, which is the honest
|
||||
number).
|
||||
|
||||
Rules for a RAM-framed measurement:
|
||||
|
||||
1. Anonymous plus pinned memory is the frame. Page cache is not a free tier; read the cache and mapped-file columns of
|
||||
whatever samples the box before believing a RAM number.
|
||||
2. `--ple-io direct`.
|
||||
3. Arena or `--resident-experts`, never `--mmap-experts`, so the experts' cost shows up as RSS where the frame pays for
|
||||
it, not in latency.
|
||||
4. Prefer a box whose RAM actually bounds the run (a VM sized to the frame); a cgroup you cannot shrink is observed,
|
||||
not enforced.
|
||||
|
||||
## Pre-built artifacts
|
||||
|
||||
The MTP draft directory (787 MB) is a deterministic product of `tools/mtp_fetch.py`, `tools/mtp_pack.py` and
|
||||
`tools/mtp_rt.py`; three builds on two hosts produced byte-identical files. It and the expert profile for the
|
||||
2026-10-17 Coder shard are at https://huggingface.co/robertkarl/UnbiasedStrataPacks, with the commands and hashes
|
||||
in its README, so a new host copies them instead of fetching 5.2 GB of BF16 tensors and quantizing.
|
||||
@@ -0,0 +1,66 @@
|
||||
# Reuse long chat history when the last user message is edited
|
||||
|
||||
## Why this helps
|
||||
|
||||
An agent can keep the same long history but replace the final user message.
|
||||
The final cached state no longer matches, and the nearest periodic checkpoint
|
||||
may be far behind. The engine then rereads history it already processed.
|
||||
|
||||
This opt-in change saves one checkpoint at the previous turn boundary, before
|
||||
the final short message. It uses the existing bounded cache and leaves normal
|
||||
token and image-prefix validation in charge of reuse.
|
||||
|
||||
## Use and limits
|
||||
|
||||
Set `STRATA_CACHE_MESSAGE_BOUNDARY=1` before starting the engine.
|
||||
It is off by default, requires prompt caching and a valid turn token, and
|
||||
only selects prefixes of at least 8,192 tokens with a tail of at most 1,024.
|
||||
Layer-split execution is excluded (`multi_gpu`); helper-expert GPUs still work.
|
||||
It can split prefill chunks and add snapshot cost to a fresh request.
|
||||
|
||||
## Validation environment
|
||||
|
||||
- Two modified RTX 3080 20 GB cards; CUDA SM86, CUDA 13.1, Linux.
|
||||
- Intel Xeon E5-2686 v4 (18 cores / 36 threads), about 94 GiB usable RAM.
|
||||
- PCIe 3.0, no GPU peer-to-peer access; 17 expert-pool workers.
|
||||
- Qwen3.8-Flash-Next IQ3_S, 131,072-token context, INT8 KV,
|
||||
32,768 resident KV cells.
|
||||
- Medium thinking: 2,048-token reasoning cap, 8,192-token output cap.
|
||||
- Physical GPU power limits stayed at 250 W and 280 W. No power increase.
|
||||
- Historical performance tests used an isolated engine based on official
|
||||
v0.1.38 plus reviewed architectds/PolyStrata changes (best, 05c0f36).
|
||||
This PR contains only our change, ported to official main (99f3dbd).
|
||||
The historical timings are NOT a measured speedup of this pure-upstream port.
|
||||
|
||||
## Historical benefit
|
||||
|
||||
Same-binary ABCCBA comparison, two repetitions per variant:
|
||||
|
||||
| Metric | On-demand boundary + 16K chunks | Anticipatory boundary + 32K chunks |
|
||||
| --- | ---: | ---: |
|
||||
| First complete 100-record edit | 17.236 s | 11.527 s |
|
||||
| Three complete edits | 41.266 s | 35.802 s |
|
||||
| Cold setup plus three edits | 58.688 s | 53.146 s |
|
||||
| Eleven-case wall-time sum | 133.844 s | 127.983 s |
|
||||
|
||||
First-edit time fell by 33.1%; reused prefix grew from 22,016 to 32,831 tokens.
|
||||
This is a COMBINED boundary-policy and chunk-size comparison, not the isolated
|
||||
benefit of adding this checkpoint to pristine upstream.
|
||||
Hot generation was unchanged (97.55 vs 97.60 tokens/s).
|
||||
The mixed-suite reduction was 4.4%; ordinary cold 8K requests cost about 0.2 s more.
|
||||
|
||||
The historical comparison passed 77 task/cache checks and cancellation/recovery.
|
||||
A separate safety arm for the adopted 32K choice passed 22 task/cache checks,
|
||||
including 120K, image-history isolation, and cancellation/recovery.
|
||||
|
||||
## Validation and related work
|
||||
|
||||
- Standalone selector test passes all 21 cases, without assertions that disappear
|
||||
in Release builds.
|
||||
- Linux compile/link against pure official main (99f3dbd) passed. No engine
|
||||
was started and no production settings were changed.
|
||||
- PR #614 checkpoints an already-reached chunk near the tail without splitting it.
|
||||
This proposal chooses a message boundary, which can split chunks. They solve
|
||||
related cases with different cost and numerical tradeoffs.
|
||||
- Chunk geometry can change floating-point results. No pure-upstream bitwise
|
||||
parity or isolated upstream speedup is claimed. Keep draft until validated.
|
||||
@@ -0,0 +1,32 @@
|
||||
# The interleaved small-batch matvec (STRATA_MMVQ_IL): how to measure a table for your card
|
||||
|
||||
The decode and verify windows run their dense projections (2 to 4 tokens at a time) through `native_mmvq_il`, which reads an
|
||||
interleaved copy of the q8_1 activations. Every choice it makes gives the same bits as the plain kernels
|
||||
(`STRATA_MMVQ_IL=0` turns the whole path off); only the speed differs. How many matrix rows one warp takes
|
||||
(1, 2 or 4, or 0 = use the plain kernel) is a table in `src/kernels/cuda/native_mmvq.cu`, indexed by the
|
||||
quantisation type (IQ4_XS, Q4_K, Q5_K, Q6_K), the token count (2-4) and the matrix's row count (five classes).
|
||||
|
||||
Which table a card gets:
|
||||
|
||||
| card | table |
|
||||
|---|---|
|
||||
| sm_86 (Ampere consumer) and sm_120 (Blackwell consumer) | `kIlRowsShared`, measured on an RTX 3060 and an RTX 5070 together (a cell is non-zero only if the worse of the two cards still gains 3%) |
|
||||
| sm_89 (Ada) and every other sm_80+ card | `kIlRowsShared` too. Nobody has measured sm_89 yet (we have no such card). |
|
||||
| sm_75 and older | the path is off; the plain kernels run |
|
||||
| a card listed in `kIlArch` | its own table |
|
||||
|
||||
## Measuring sm_89 (or any other card)
|
||||
|
||||
1. Build with tests: `cmake -S . -B build -DSTRATA_BUILD_TESTS=ON` and `cmake --build build --target mmvq_il_parity`.
|
||||
2. Close everything else on the GPU, then run `build/mmvq_il_parity --bench --emit-table` (a few minutes).
|
||||
It first checks bit-for-bit parity of every shape and every rows choice (it must end with `mmvq_il_parity: OK`),
|
||||
prints a `BENCH` line per shape and token count, and last a ready-to-paste block, one line per type.
|
||||
3. Post the whole output on the issue. A maintainer pastes the block as `kIlRows_89[]` and adds
|
||||
`{89, kIlRows_89, sizeof(kIlRows_89) / sizeof(IlRows)}` to `kIlArch`.
|
||||
4. To try a table without rebuilding, set `STRATA_MMVQ_IL_ROWS="type:ncols:r0,r1,r2,r3,r4;..."`, for example
|
||||
`STRATA_MMVQ_IL_ROWS="23:3:0,0,2,4,4;12:2:0,1,1,1,1"` (the five numbers are the row classes below 2048, 4096, 8192,
|
||||
12288 and above; each is 0, 1, 2 or 4). Then A/B the decode: same flags, `STRATA_MMVQ_IL_ROWS` set or unset, 10
|
||||
interleaved pairs, medians.
|
||||
|
||||
The emit rule: per cell, the fastest rows count if it takes at least 3% off the plain kernel's time, else 0; shapes of one
|
||||
class that disagree give 0; a class with no measured shape copies its neighbour below.
|
||||
@@ -0,0 +1,36 @@
|
||||
# Model files tried with UnbiasedStrata 2
|
||||
|
||||
(Upstream's `docs/MODELS.md` describes the models in general; this file is the fork's record of files actually run.)
|
||||
|
||||
A fork of an inference engine has to say which model files it has actually run. One row per file (not per model):
|
||||
the same quantization from two Hugging Face repos is two files. "Works" means the front end served `/v1/chat/completions`
|
||||
with correct text, streaming, a tool call and reasoning, through `frontend/tests/`-style checks against the real engine;
|
||||
"measured" means a row exists in `README.md` "Measured" (the run directories behind the rows are in git history at
|
||||
7551f138, `bench/unbiased/`; removed from the tree 2026-10-19). Hashes are SHA-256 of the file as served.
|
||||
|
||||
| File | Source | Size (bytes) | SHA-256 | Engine | Boxes | Status | Correctness (PLAN.md step 12; harness `bench/correctness/`, record in history at 7551f138) |
|
||||
| --- | --- | --- | --- | --- | --- | --- | --- |
|
||||
| `Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00001-of-00002.gguf` + `-00002-of-00002.gguf`, with `pack-iq3-xxs/` and `mtp/` made by upstream's `tools/iq_pack.py` and `tools/mtp_rt.py` | Niko1221 Strata GSQ-RCO release; pack and MTP built 2026-10-05 (`artifacts.sha256` on the pod) | 47,039,860,096 + 28,800,138,432 | shards unhashed; pack `dense.bin` `d2af3d83…`, mtp `dense.bin` `c724dc0b…` (full hashes in `bench/unbiased/*/engine-info.txt`) | `strata` | RTX 3090 pod, A6000 VM | works (2026-10-17: A6000 `bench/unbiased/2026-10-17-a6000-flash-next-iq3xxs-step6/`, RTX 3090 pod `…-3090pod-flash-next-iq3xxs-step6/`; the greedy answers of the two boxes are identical, and identical to upstream PolyStrata v0.1.45-poly.1 on the same files on the pod: `…-3090pod-…/upstream-compare/`; pi completed the multi-step coding task against it on the pod, `…-3090pod-flash-next-iq3xxs-step7-pi/`, and the request-shape checks pass, `…-step7-shapes/`; step 9 upstream-vs-fork measurement on the pod, `…-3090pod-step9/`: fork faster on every workload) | **passed with findings** (2026-10-18, A6000 VM, `strata` against llama.cpp `3cf03257` on 16 sequences, 3,279 teacher-forced steps; the reference is a partial offload, 28 of 48 layers on the card, and its CPU run): T2 passes on every set in every arm (fp16, 4-token windows, int8 KV, streamed KV, 512-token prompt chunks, every expert on the card, the CPU expert tier), 0.67 to 0.94x the reference's own spread; top-1 agreement at the floor's level; T1 fails at 0 to 4 of about 2,880 margin positions per arm, six distinct near-tie positions, none in every arm (USTRAT-5); the engine's bits depend on the free VRAM at start through the CPU-computed share of expert misses (USTRAT-4); with the placement held, repeats, window sizes, KV streaming and the CPU tier are bitwise reproducible |
|
||||
| `Qwen3.6-35B-A3B-UD-Q3_K_M.gguf` (MTP draft block in the file) | `unsloth/Qwen3.6-35B-A3B-MTP-GGUF` @ `5bc3e238` | 17,104,402,720 | `8966dd0cd8c543c4228490a2a8b0e0814fc4f1e6a8e199ceed4de6754ae7b8e1` | `strata-poly` | pod, A6000 VM | works (2026-10-17, RTX 3090 pod: `bench/unbiased/2026-10-17-3090pod-qwen36-ud-q3km-mtp-step6/`; 211 to 227 tok/s decode on short prompts, 88% of drafts accepted); A6000 `…-a6000-qwen36-ud-q3km-mtp-step6/`, 214 to 235 tok/s); the measured configuration of PLAN.md section 6; step 9 upstream-vs-fork on the pod, `…-3090pod-step9/`: decode within noise, 16K prefill 2.3 % slower, to explain | **passed with findings** (2026-10-18, A6000 VM, `strata-poly` against llama.cpp `3cf03257` CUDA on 16 sequences, 2,976 teacher-forced steps): T2 (mean KL to llama.cpp's GPU run within 1.5x llama.cpp's own CPU-vs-GPU spread) passes on every set and every arm, 0.81 to 1.18x base; top-1 agreement at the floor's level; T1 (argmax at every position with a 0.5-nat margin) fails at 4 of 2,700 positions, 3 of them where llama.cpp's CPU run also disagrees with its GPU run, 1 engine-only (`puzzle` step 144, USTRAT-3); upstream's `poly_expert_parity` exceeds its own bound on one expert (USTRAT-1); drafting is not bitwise inert above 4-token windows but passes T2 (USTRAT-2); `--check-batch 4` passes on the short set |
|
||||
| `Qwen3.6-35B-A3B-UD-IQ4_XS.gguf` (MTP draft block in the file; the `…-IQ4_XS-MTP.gguf` next to it in the repository is a 1,067-byte LFS pointer, not the file) | `unsloth/Qwen3.6-35B-A3B-MTP-GGUF` @ `5bc3e238` | 18,209,036,576 | `df27a780435b7b45c2597536112ea3cb091f8544c3d0c3318d9f4258b31f7adf` | `strata-poly` | pod, A6000 VM | works (2026-10-17: A6000 `bench/unbiased/2026-10-17-a6000-qwen36-ud-iq4xs-mtp-step6/`, 207 to 215 tok/s decode on short prompts; RTX 3090 pod `…-3090pod-qwen36-ud-iq4xs-mtp-step6/`, 205 to 245 tok/s; pi completed a multi-step coding task against it on the A6000, `…-step7-pi/`); chosen as the local-use quant | **passed** (2026-10-18, A6000 VM, as the row above: 16 sequences, 2,972 steps): T2 passes on every set and arm, 0.59 to 1.35x; T1 fails at 2 of 2,672 positions in the base arm (`d4k` 249 inside a degenerate repetition loop where llama.cpp's own two runs are 0.3 to 1.3 nats apart, `r16k` 440 a near tie), 3 with drafting on; `--check-batch 4` passes on the short set |
|
||||
| `Qwen3.6-35B-A3B-UD-IQ4_XS.gguf` (no draft block) | `unsloth/Qwen3.6-35B-A3B-GGUF` | 17,730,509,792 | `649d7508507b84638732c4f52c24c8b15843c6dca2f3ff793ae07c14a67ebbb3` | `strata-poly` | pod | on disk, untried: without the draft block the engine runs without speculation | not run |
|
||||
| `Qwen3.6-35B-A3B-UD-Q3_K_M.gguf` (no draft block) | `unsloth/Qwen3.6-35B-A3B-GGUF` | 16,600,710,112 | `1b715841683f960bd9a49f008181bd910ee169b78d4cf465b6fde7f4d929ff99` | `strata-poly` | pod | on disk, untried; downloaded by mistake for the row above, kept to compare | not run |
|
||||
| `DeepSeek-V4-Flash-0731-UD-IQ2_XXS-00001-of-00003.gguf` + `-00002-` + `-00003-of-00003.gguf` | `unsloth/DeepSeek-V4-Flash-0731-GGUF` @ `fbbb5b93` | 5,257,664 + 49,890,588,800 + 40,964,890,464 | `c58c9d62eac7b62e9578b52613f425e48313d7212ab8d1d76caed8ea8de26595`, `65a113df6d4469f16db6882b6919e153c464c3c78c833f5e1b41a33803cdbd52`, `a69102ddfaf4a84426e11fdb66716654f4260dc3a1de3ade9fd50e006b8691d3` | `strata-poly` | 2x B200 pod (one card, 91 GB of VRAM used at a 32K context) | works (2026-10-19, first start through the fork, `tools/pod/bringup.sh 100 big` files; docs/DEEPSEEK.md's run config as engine args, `--conversation-cache-mib 8192`): ready 32 s after start; 78 tok/s decode on short prompts, 94 tok/s prompt reading on a 22-token prompt, reasoning split into `reasoning_content` with thinking on; with `chat_template_kwargs.thinking=false` the content begins with a stray `</think>` (to look at); PLAN.md step 13 (2026-10-19, `bench/unbiased/2026-10-19-step13-acceptance/`): pi completes all four work items and Minesweeper at temperature 1.0 once tool-call arguments are accepted in any order (USTRAT-7); API checks pass, 72 tok/s decode, 1,954 tok/s prompt reading on one card | step 12 on the 2x RTX PRO 6000 pod (2026-10-19, `bench/unbiased/correctness/` section 8, reference llama.cpp 3cf03257 GPU, floor its CPU run): T2 pass on every set, base/draft 0.69 to 1.00x the floor, prompt chunks of 512 0.89 to 1.06x; T1 3 flips at margin positions where both reference runs agree (USTRAT-10); draft arm bitwise the base arm on 15 of 16 sequences (d4k from step 112, USTRAT-2); llama.cpp master's own CPU run differs from the pinned reference as much as the engine does (USTRAT-11) |
|
||||
| `GLM-5.3-Flash-GSQ-RCO-3.0bit-q4kattn.gguf` (no draft block in the file, checked in its header 2026-10-19: the block is cut from Unsloth's UD-IQ2_XXS files with `tools/glm_draft_fetch.py`, 2,787,998,016 bytes, SHA-256 `91a04445…6e3218`, and given to the engine as `--draft-model`; the pod runs of 2026-10-19 ran without it) | `neuralll/GLM-5.3-Flash-GSQ-RCO-3.0bit-Q4Kattn-GGUF` @ `7feedfeb` | 113,585,695,168 | `5f03b74ffe7513479795ca60a0fd8c40cbb3101769672b2c91b3df01138d9f6d` | `strata-poly` | 2x B200 pod (one card, 113 GB of VRAM used at a 32K context) | works after a fix (2026-10-19): the front end's vocabulary load refused the file's architecture name `glm5-next`, which llama.cpp does not know (USTRAT-6); the load is retried with the name overridden (vocabulary only), after which the server starts, the template renders (`[gMASK]<sop><|system|>Reasoning Effort: …`) and answers; 74 tok/s decode on a short prompt (5 of 11 drafts accepted), reasoning split with thinking on; PLAN.md step 13: pi completes all four work items and Minesweeper at temperature 1.0 at `reasoning_effort` low (the template treats anything but low/high as max, and at max it thinks to the token cap) once arguments are accepted in any order; API checks pass, 74 tok/s decode, 1,341 tok/s prompt reading on one card | step 12 on the 2x RTX PRO 6000 pod (2026-10-19, `bench/unbiased/correctness/` section 8, reference llama.cpp master 99db719b because the pinned tree does not know `glm5-next`): T2 pass on every set, 0.89 to 1.13x the floor; T1 5 flips where both reference runs agree plus 2 at reference-spread positions (USTRAT-10); the draft arm is not bitwise the base arm on any sequence because its 0.4 GiB moves 52 experts to the CPU (USTRAT-9) |
|
||||
| `GLM-5.3-Flash-REAP50-Q3_K_M.gguf` (draft block in the file; 144 of 288 experts a layer kept by REAP pruning, 46 layers) | `patrickbdevaney/GLM-5.3-Flash-REAP50-GGUF` @ `f0535a9c` | 78,776,759,712 | `5a865918aea87a362ff8ae419581a0447929bfd68534a44d1125b394c272762d` | `strata-poly` | RTX A6000 VM (48 GB VRAM, 52 GB RAM, 12 vCPU Ryzen 1700, file on NVMe), 2026-10-20 | serves at a 64K context with 3,367 of 6,192 experts in VRAM (37.4 GiB), 40 s load from NVMe (331 s from the HDD pool); warm decode 15 to 23 tok/s on 220-token answers with about 1.1 GB of expert reads per answer from the NVMe, 2,846-token prompt read at 234 tok/s; the file on the HDD pool gave 7 to 9 tok/s (page-cache thrash, see notes). **Not usable as an agent as served (2026-10-20):** in pi (1,771-token agent prompt, tools, reasoning low, temperature 0.6 / top_k 20 / top_p 0.95) the first answer degenerated into repetition: `5.5.5.5…`, fragments of its own context ("iTerm2 window creation failed", "AGENTS.md says", "item 9 should be item 1") looped for 1,373 tokens until cancelled, with 705 of 764 guesses accepted. Short single-turn prompts (54 tokens, 220-token coding answers) were coherent. Not separated yet between the pruned model and the engine's lookup guessing (`--no-draft --lookup 0` replay of the same request is the first test; USTRAT-13). Serve: `unbiased-strata --engine strata-poly -m <file> -- --model <file> --max-context 65536 --expert-profile <profile seeded from data/expert-profile-glm-reap50.txt>` |
|
||||
| `mmproj-F16.gguf` (Qwen3.6 vision projector, `qwen3vl_merger`, projection width 2048) | `unsloth/Qwen3.6-35B-A3B-MTP-GGUF` | 899,283,584 | `71f3cbc1f7cc0f30d09d41cfa924c0060827ebc33bf15ace7e86661e856f0160` | front end (`--mmproj`; the encoder runs in `unbiased-strata`, the engine takes the rows over `GENI`) | A6000 VM, pod | works (2026-10-18, A6000 VM with UD-IQ4_XS: `bench/unbiased/2026-10-18-a6000-qwen36-iq4xs-images-step8/`; six facts read off a 1920x1080 screenshot at the 300-row default, 15 s to encode on the VM's Ryzen 7 1700; CPU encoder only, see README "Known limits") | not in scope (the encoder is llama.cpp's own code in the front end) |
|
||||
|
||||
Rules: a file is added here when it is first downloaded for this fork, with its hash from the Hugging Face LFS object id
|
||||
or from `sha256sum` on the box; its status changes only with a measured result (a row in `README.md` "Measured" with its run directory in history). Models
|
||||
upstream lists but nobody here has run stay out of this table and are "present, unmeasured" in `README.md`.
|
||||
|
||||
## Request shapes a coding agent sends (step 7)
|
||||
|
||||
`frontend/tests/shapes-real-engine.sh` against a live server: no `max_tokens`; `max_tokens` 32768 with a short
|
||||
answer (clamped to what the context leaves, not refused); a prior assistant message carrying `reasoning_content` and
|
||||
`tool_calls` followed by a tool result; two tool calls in one turn; a call whose optional arguments come before the
|
||||
required one; a client that disconnects two seconds into a long stream, then a clean request; an 18k-token prompt
|
||||
streamed. Results per box and model: the `*-step7-shapes/` directories, in history at 7551f138. The pinned llama.cpp server sends an
|
||||
SSE ping only after 30 s of silence (`--sse-ping-interval`, default 30); an 18k-token prompt on Qwen3.6 is read in
|
||||
5 s, so no ping is seen there. Run lines for long prompts should pass `--sse-ping-interval 10` if the client times out
|
||||
sooner.
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
# Which model? Sizes, versions and what fits
|
||||
|
||||
This page is about [Qwen3.8-Flash-Next](https://huggingface.co/Qwen/Qwen3.8-Flash-Next), which PolyStrata runs in
|
||||
several **sizes** (the same model, compressed more or less) and several **versions** (the original, a coding
|
||||
version, a fine-tune). The installer recommends one for your PC; this page explains the choice. The other model,
|
||||
GLM 5.3 Flash, has a page of its own: [GLM.md](GLM.md). Back to the [README](../README.md).
|
||||
|
||||
> **On this page:** [Pick by RAM](#pick-by-ram) · [Speed](#how-fast-is-each-size) · [The sizes](#the-sizes) ·
|
||||
> [Will it fit?](#will-it-fit) · [The versions](#the-versions) · [Adding another model](#adding-or-switching-models)
|
||||
|
||||
## Pick by RAM
|
||||
|
||||
| Your RAM | Take | Why |
|
||||
| --- | --- | --- |
|
||||
| **32 GB** | **Coder** | it fits 32 GB; best at code, weaker at everything else ([why](#coder)). With a 24 GB card, Q2_0 and IQ2_XS run too ([low-RAM mode](#a-big-graphics-card-and-little-ram)) and are the better pick for general use |
|
||||
| **48 GB** | **IQ2_XS** (or Q2_0, the fastest) | the larger sizes do not fit |
|
||||
| **64 GB** | **IQ2_XS** (recommended), or IQ3_XXS / IQ3_S | every size fits (IQ3_S with little else open) |
|
||||
| **96 GB or more** | **IQ3_S**, or [Unsloth's UD-IQ4_XS or UD-Q4_K_XL](#unsloths-files-ud-iq4_xs-to-q8_0) (~4-bit) | room for the largest sizes |
|
||||
| **128-192 GB** | [Unsloth's UD-Q5_K_XL, UD-Q6_K_XL or Q8_0](#unsloths-files-ud-iq4_xs-to-q8_0) | every expert of the 5-8-bit files in RAM |
|
||||
|
||||
Not sure? Take **IQ2_XS**. The **Coder** is the one that fits a 32 GB PC, but it keeps only 256 of the 512 experts,
|
||||
chosen on code data, so it is weaker outside code and in languages other than English. For general use, or whenever
|
||||
your RAM allows, take a full model (Q2_0, IQ2_XS or IQ3_S).
|
||||
|
||||
## How fast is each size
|
||||
|
||||
Measured on an RTX 5070 (12 GB), a Ryzen 5 7600 and 64 GB of RAM:
|
||||
|
||||
| Size | Writes answers (short chat) | Writes answers (128K context) | Reads your prompt |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| **Q2_0** | 94 tokens/s | 76 tokens/s | 2,650 tokens/s |
|
||||
| **IQ2_XS** | 79 tokens/s | 63 tokens/s | 2,090 tokens/s |
|
||||
| **IQ3_XXS** | 62 tokens/s | 49 tokens/s | 1,750 tokens/s |
|
||||
| **IQ3_S** | 53 tokens/s | 46 tokens/s | 1,620 tokens/s |
|
||||
| **Coder** (IQ1_M) | 55 tokens/s | 43 tokens/s | 2,180 tokens/s |
|
||||
|
||||
Measured on an AMD RX 9070 XT (16 GB), a Ryzen 9 3900X and 47 GB of RAM (Linux, setup's own install; Q2_0 is
|
||||
above setup's RAM estimate for 47 GB and was installed with `--model Q2_0 --yes`):
|
||||
|
||||
| Size | Writes answers (short chat) | Writes answers (128K context) | Reads your prompt |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| **Q2_0** | 60 tokens/s | 48 tokens/s | 1,160 tokens/s |
|
||||
| **IQ2_XS** | 52 tokens/s | 36 tokens/s | 1,110 tokens/s |
|
||||
| **Coder** (IQ1_M) | 44 tokens/s | 33 tokens/s | 1,420 tokens/s |
|
||||
|
||||
- **Writes answers** = how fast the reply appears (tokens per second; a token is about ¾ of a word).
|
||||
- **Reads your prompt** = how fast it takes in what you send (long documents, code, chat history), measured on a
|
||||
32K-token prompt; a 4K prompt reads at 910-1,580 tokens/s. A 32K prompt takes about 15 seconds with Q2_0.
|
||||
|
||||
A card with more VRAM is faster, because more of the model fits on the GPU: an RTX 3090 (24 GB) should do roughly
|
||||
100-140 tokens per second. All measurements, long-context numbers and estimates for other cards are in the
|
||||
[details](DETAILS.md#speed-measured). The AMD measurements per card (RX 9070 XT, Radeon AI PRO R9700, RX 7800 XT,
|
||||
RX 9060 XT, RX 6900 XT) are in [AMD_HIP.md](AMD_HIP.md#rdna4-gfx1201).
|
||||
|
||||
Every PC is different: `START-HERE.bat --calibrate` measures a few engine settings on yours and keeps the fastest
|
||||
(about 15-30 minutes, longer on a slow card; on the PC above it made the Coder 7% faster; NVIDIA cards for now). Measured PolyStrata on your own
|
||||
PC? See [Community benchmark results](COMMUNITY_BENCHMARKS.md) for a report template and how to share your results
|
||||
in a pull request.
|
||||
|
||||
## The sizes
|
||||
|
||||
| Model | RAM+VRAM Requirements | Speed | Quality |
|
||||
| --- | ---: | --- | --- |
|
||||
| **Q2_0** | 37.6 GB | fastest | good |
|
||||
| **IQ2_XS** | 39.2 GB | fast | better (**recommended**) |
|
||||
| **IQ3_XXS** | 47.0 GB | slower | great |
|
||||
| **IQ3_S** | 54.8 GB | slowest | best: matches the full model on the published tests |
|
||||
|
||||
The download is 66-76 GB for the three smaller sizes ([details](DETAILS.md#which-model)); the first start also
|
||||
fetches the MTP draft layer (~6 GB, +1 GB with images).
|
||||
|
||||
## Will it fit?
|
||||
|
||||
Shard 1 is the part of the model that gets loaded when it starts: its experts go into your **RAM**, the rest onto
|
||||
your graphics card (the second shard, a 29 GB lookup table, stays on the SSD). So it fits when your **RAM is at least
|
||||
the experts + about 10 GB** for Windows and your other programs - the experts are most of shard 1: 34 GB for Q2_0,
|
||||
35.5 for IQ2_XS, 43 for IQ3_XXS, 50 for IQ3_S, 23 for the Coder (the dense weights in shard 1 go to the graphics
|
||||
card). With 64 GB of RAM every size fits (IQ3_S with little else open); with 48 GB, Q2_0 and IQ2_XS. A bigger graphics card makes it faster, but it doesn't lower the RAM needed
|
||||
- except in the low-RAM mode below.
|
||||
|
||||
### A big graphics card and little RAM
|
||||
|
||||
On a PC whose RAM cannot hold the experts beside the system, setup maps them from the model's files instead and keeps
|
||||
in RAM only what the graphics card does not hold (the [low-RAM mode](DETAILS.md#speed-measured), chosen by setup). For
|
||||
example, a 32 GB PC with a 24 GB GPU runs Q2_0, IQ2_XS and the Coder this way, and a 32 GB PC with a 12-16 GB GPU the
|
||||
Coder. With a small card most experts then come from the SSD and it is much slower (setup says so).
|
||||
`START-HERE.bat --setup --low-ram on|off` overrides the choice.
|
||||
|
||||
## The versions
|
||||
|
||||
### Qwen3.8-Flash-Next
|
||||
|
||||
The original, in all four sizes. With images, and with the
|
||||
[experimental speed projection](DETAILS.md#experimental-speed-projection-experimental-off-by-default) as an option.
|
||||
|
||||
### Coder
|
||||
|
||||
**[Coder](https://huggingface.co/ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-Coder-GGUF)** - ISTA-DASLab's coding version:
|
||||
it keeps 256 of each layer's 512 experts, chosen on code (with agentic and image) data, and drops the rest (91% of
|
||||
the full model's SWE-bench Verified score, 99% of LiveCodeBench, by its authors). One size (IQ1_M: its experts stored
|
||||
like IQ3_S): shard 1 is **29.6 GB**, so it fits a PC with **32 GB of RAM**, runs 262K context on 64 GB, and reads long
|
||||
prompts the fastest of all. With half the experts gone it is weaker outside code and in languages other than
|
||||
English, Chinese and other CJK text included (#438: Chinese answers came out wrong or looping where English was
|
||||
fine). For general use, or whenever your RAM allows, take a size that keeps every expert: Q2_0, IQ2_XS or IQ3_S.
|
||||
More: [details](DETAILS.md#or-the-coder-half-the-experts-for-code).
|
||||
|
||||
```
|
||||
START-HERE.bat --setup --family coder
|
||||
```
|
||||
|
||||
### Swift 1.5
|
||||
|
||||
**[Swift 1.5](https://huggingface.co/ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF)** - a fine-tune by UkisAI that
|
||||
thinks much shorter before answering, so you get the answer sooner, with about the same quality. Same speed per
|
||||
token, and about the same RAM as the same size of the original. Its own license applies (see its page).
|
||||
More: [details](DETAILS.md#or-swift-15-a-fine-tune-that-thinks-shorter).
|
||||
|
||||
```
|
||||
START-HERE.bat --setup --family swift --model IQ2_XS
|
||||
```
|
||||
|
||||
<a id="unsloth-ud-iq4_xs"></a><a id="unsloth-ud-q4_k_xl-experimental"></a>
|
||||
|
||||
### Unsloth's files: UD-IQ4_XS to Q8_0
|
||||
|
||||
The fourth version in setup's menu (`--family unsloth`) is **Unsloth's quantizations** of the same model, from ~4 to 8
|
||||
bits. They keep the original's experts at more bits than the 2-3-bit sizes above, so they need more RAM. Setup keeps
|
||||
every expert in RAM where they and 16 GB more fit (the fastest way); with less RAM it keeps as many as fit and reads
|
||||
the rest from the SSD while it answers (much slower), and for the bigger files it asks first. Images are on by default
|
||||
on an NVIDIA card of 16 GB or more (and on AMD with the CPU encoder where the experts fit in RAM).
|
||||
|
||||
| Size | Download | Experts | RAM for all of them in RAM | Same top token as Q8_0 | AMD R9700 (32 GB): story / code / 32K prompt |
|
||||
| --- | ---: | ---: | ---: | ---: | --- |
|
||||
| **UD-IQ4_XS** (setup's first) | 94 GB | 55 GiB | ~72 GB | 88.9% | - |
|
||||
| **UD-Q4_K_XL** | 111 GB | 72 GiB | ~88 GB | 93.1% | 63 / 87 tok/s / 1,110-1,320 tok/s |
|
||||
| **UD-Q5_K_XL** | 158 GB | 92 GiB | ~108 GB | 94.6% | 57-60 / 82 / 810-1,260 |
|
||||
| **UD-Q6_K_XL** | 169 GB | 102 GiB | ~118 GB | 94.6% | 54 / 76 / 1,020 |
|
||||
| **Q8_0** | 188 GB | 120 GiB | ~136 GB | 100% (the reference) | 53-57 / 66-74 / 1,230-1,300 |
|
||||
|
||||
For comparison, IQ3_S on the same card: 75 / 95 tok/s, 87.7% the same top token as Q8_0. The quality numbers, the
|
||||
speed bound and NVIDIA/AMD/Intel details: [QUANTS.md](QUANTS.md); the files: [UD-Q4_K_XL](UNSLOTH_Q4.md),
|
||||
[UD-Q6_K_XL](UNSLOTH_Q6.md).
|
||||
|
||||
```
|
||||
START-HERE.bat --setup --family unsloth --model UD-Q5_K_XL
|
||||
```
|
||||
|
||||
### OrcaRouter Uncensored IQ3_XXS
|
||||
|
||||
For **OrcaRouter's Flash-Next Uncensored IQ3_XXS**, see the [manual compatibility setup](ORCA.md). It needs an
|
||||
explicit packing conversion and is not an installer menu option.
|
||||
|
||||
## Adding or switching models
|
||||
|
||||
You can add another model any time with `SETUP.bat` (the same as `START-HERE.bat --setup`; on Linux
|
||||
`./setup.sh --setup`). Files another model shares are not downloaded again (the Coder uses the original's shard 2 and
|
||||
vision encoder). With more than one model installed, `START-HERE.bat` asks which one to start; `run-<model>.bat`
|
||||
(Linux: `run-<model>.sh`) starts one directly. Once it runs, the chat page's model list switches to another installed
|
||||
model without a restart, and each model runs with its own settings
|
||||
([DETAILS.md](DETAILS.md#using-it), "Switching models in the web page").
|
||||
@@ -0,0 +1,553 @@
|
||||
# PolyStrata on two or more GPUs (layer split)
|
||||
|
||||
One model can run across several NVIDIA cards in one PC. The layers are split into contiguous ranges, one per GPU:
|
||||
the first card runs layers 0 to K-1, the next card runs K onward, and so on; the last card also runs the output head
|
||||
and the draft (MTP) layer. Each card keeps an expert cache for **its own layers only**, so two cards hold about twice
|
||||
the experts one card holds - for the Coder model on a 16 GB + 24 GB pair, nearly all of them, which is where the
|
||||
speed comes from (decode then barely touches the CPU pool).
|
||||
|
||||
This is pipeline (layer) parallelism, not tensor parallelism: a token crosses from one card to the next once per
|
||||
verify window (a few hundred KB through pinned RAM), not twice per layer. No NVLink or peer-to-peer access is
|
||||
needed; cards on x4 or x1 slots work, and the PCIe share of each card is probed on its own link. A `--pcie-frac` you give
|
||||
is every card's share and skips those probes; there is no per-card setting yet.
|
||||
|
||||
Most of this page is about the engine of Qwen3.8-Flash-Next. The models of the strata-poly engine (Qwen3.6, Gemma 4,
|
||||
Ornith, Tiel Coder, GLM 5.3 Flash) split their layers as well, more simply: see
|
||||
[The strata-poly models](#the-strata-poly-models).
|
||||
|
||||
## Using it
|
||||
|
||||
**Nothing to type.** `START-HERE.bat` (Linux: `./setup.sh`) lists your NVIDIA cards and says for each one whether
|
||||
PolyStrata can use it:
|
||||
|
||||
```
|
||||
Your NVIDIA GPUs:
|
||||
GPU 0: NVIDIA GeForce RTX 5080, 16 GB VRAM - can be used
|
||||
GPU 1: NVIDIA GeForce GTX 1080 Ti, 11 GB VRAM - not supported - older than the RTX 20 series (compute capability 6.1; PolyStrata needs 7.5 or newer)
|
||||
GPU 2: NVIDIA GeForce RTX 3090, 24 GB VRAM - can be used
|
||||
...
|
||||
1) GPU 0 (NVIDIA GeForce RTX 5080, 16 GB) + GPU 2 (NVIDIA GeForce RTX 3090, 24 GB) together (recommended)
|
||||
2) GPU 2 (NVIDIA GeForce RTX 3090, 24 GB) only
|
||||
3) GPU 0 (NVIDIA GeForce RTX 5080, 16 GB) only
|
||||
Which GPUs? [1]:
|
||||
```
|
||||
|
||||
When two or more cards can share the model, the two best together are recommended (the newest generation first:
|
||||
it becomes the main card). A model installed on one card asks once, at its next start, whether to use both from
|
||||
now on; the answer is kept.
|
||||
|
||||
**Choosing yourself** (at setup or at any start):
|
||||
|
||||
```
|
||||
--gpus 0,2 these cards together, as nvidia-smi numbers them; the first is the main one. Remembered.
|
||||
--gpus all every card that can share the model
|
||||
--gpu 0 one card (at a start: for that start only)
|
||||
--layer-split auto (default) or the first layer of each later card, e.g. 18 or 16,32
|
||||
```
|
||||
|
||||
**Not supported** (setup says so and names the cards that can be used instead):
|
||||
- a card older than the RTX 20 series (compute capability below 7.5: GTX 10 and older), unless you name it: Pascal
|
||||
and Volta cards (Tesla P100 / P40, GTX 10, V100) are admitted when you choose them with `--gpus` (or `--gpu`,
|
||||
`--cuda 12`) and then run the experimental CUDA 12 engine, see [OLDER_GPUS.md](OLDER_GPUS.md). Two Tesla P40s
|
||||
(`"gpu": [0, 1]` in the config) ran the layer split in a community benchmark: IQ2_XS decode 19.6 tok/s on one card,
|
||||
34.8 on both (#1028, experimental, one report);
|
||||
- a card with less than 8 GB of VRAM, together with others (each card holds a copy of the dense weights and its
|
||||
own prompt buffers) - unless you name it with `--gpus`: then setup says the risk and asks (`--yes` with the named
|
||||
cards goes ahead);
|
||||
- Intel GPUs, and a mix of NVIDIA and AMD cards. (AMD cards share a model among themselves: `./setup.sh --backend
|
||||
hip --gpus 1,0`, see [AMD_HIP.md](AMD_HIP.md).)
|
||||
|
||||
Or edit an existing config (`strata-*.json`), then restart:
|
||||
|
||||
```json
|
||||
"gpu": [0, 2],
|
||||
"layer_split": "auto"
|
||||
```
|
||||
|
||||
`"layer_split"` is `"auto"` (placed by each card's free VRAM) or the **first layer of each later card**: one rising
|
||||
number per card after the first, not a count of layers per card. With 4 cards and a 48-layer model, `"24,36,42"`
|
||||
(or `[24, 36, 42]`) puts layers 0-23 on the first card, 24-35 on the second, 36-41 on the third and 42-47 on the last.
|
||||
The server checks it before the start and says what is wrong (0.1.39, #644).
|
||||
|
||||
**Card order with `"auto"`** (NVIDIA, #1352): the faster card (multiprocessors x max clock) goes **last** - the last stage runs the head, the draft layer and the verify, and a prompt chunk waits on it (a 4070 Ti SUPER + 5060 Ti read a 6K prompt in 50 s one way round and 15 s the other). Cards whose scores are within 5% of each other (two of the same model) keep your order; a manual split keeps it too. `"gpu_order": "as_given"` keeps the order you wrote under `"auto"` as well. The engine log line `layer split: card order ...` says when it changed.
|
||||
|
||||
**An unequal pair under `"auto"` (#2644).** The search prices a decode window, and it can give almost every layer to the card it
|
||||
rates faster. A card with one or two layers holds a handful of experts and clamps the prompt chunk of the whole pipeline
|
||||
(#1616), so the search then asks for at least 3 layers per card - which on a 4060 Ti 16 GB + 3060 12 GB (48 layers, IQ3_S)
|
||||
was K=3: the 3060 ran 3 layers, 12 GB idle, 452 tok/s of prefill against 802 at 28 layers on the 3060 (the reporter's sweep of
|
||||
`"layer_split"` 12, 18, 24, 28, 32: 582, 693, 762, 802, 803 tok/s; the 3060's 360 GB/s of memory bandwidth against the 4060 Ti's
|
||||
288 counts for more than its SMs). On two cards the engine now first asks for a placement in which each card owns at least its
|
||||
share of the layers by its room for experts, and the log line says which rule chose the split. Measured on 2x RTX A4000 made
|
||||
unequal (stage 0 priced at 0.57 of the speed with 3.7 GiB less room, `STRATA_SPLIT_SPEED_SCALE=0.57` and `--vram-reserve-mib 4400`; 14.5K-token
|
||||
prompt, IQ3_XXS, 5 interleaved pairs): the old rule chose K=3 (3 layers on stage 0), the new one K=20; prompt reading 945 -> 1,441 tok/s (+52%,
|
||||
5/5 pairs), decode 50.2 -> 65.9 tok/s (+31%, 5/5). Equal cards and three or more GPUs are unchanged.
|
||||
On x16 + x4 rigs the link-miss scaling (#2007, from a 4x gap) can also move `auto` off the balanced placement (2x RTX 3090, x16 + x4:
|
||||
K=31 with miss cost x4.20, 114-119 tok/s decode against 130-136 at K=27, #2418): `STRATA_SPLIT_UNIFORM=1` (opt-in, with `"gpu_order": "as_given"`)
|
||||
prices every link the same, as before 0.1.41.
|
||||
Prefill that is flat in the prompt length (no gain from 4K to 16K) is the sign of an idle card; **on an unequal pair sweep
|
||||
`"layer_split"` once** - a 4K-only benchmark cannot see it.
|
||||
|
||||
**Skip the split when the first card holds everything** (opt-in, 0.1.31): `"split_skip_if_fits": true` in the config
|
||||
(engine flag `--split-skip-if-fits`, with `--layer-split auto`) runs on the first card alone when it holds every
|
||||
profiled expert plus the context's KV, the draft layer and the reserve, and says so in the log; otherwise the split
|
||||
stays. On an R9700 32 GB + RX 9070 XT the R9700 holds all of the Coder's experts: with the flag 4K prompts read at
|
||||
1,776 tok/s instead of 1,244 (split) and decode runs at ~60 tok/s instead of ~51 (16K prompts ~5% slower than split).
|
||||
|
||||
**Short prompts on a split (0.1.32, #340).** 0.1.30 gave each card's prompt path a loan from its own expert cache,
|
||||
refilled after every request; on cards that hold nearly all their experts that cost short prompts up to a third of
|
||||
their speed. 0.1.32 refills all cards at once, uses a smaller streaming ring on a split, and lets a card with free
|
||||
VRAM keep its own prompt buffers - the same output as 0.1.31, measured on an R9700 + RX 9070 XT: 2K prompts 993 ->
|
||||
1,265 tok/s, 16K 1,852 -> 1,950, decode unchanged. `STRATA_SPLIT_OWN=1` (opt-in) gives every card its own buffers:
|
||||
2K 1,450 and 16K 2,227 tok/s there, but a full card then keeps a different set of experts resident, so the output
|
||||
differs from the default's (stable and coherent); `STRATA_SPLIT_OWN=auto` does that only where the buffers are at
|
||||
most 12% of each card's VRAM.
|
||||
|
||||
**The idle card can help one-chunk prompts (opt-in, `STRATA_PREFILL_HELP=1`).** A prompt that fits one chunk runs the stages one after the other, so while
|
||||
one card reads its layers the other idles. With it on, each stage hands a share of its streamed experts to the idle card: it
|
||||
streams them over its own PCIe link into its own (lent) prompt buffers, computes their rows on the MMQ path and sends
|
||||
them back - `--peer-device`'s peer streaming, without P2P (the activations and the rows go through mapped host memory,
|
||||
read by copy kernels, so they do not queue behind the expert blobs on either card's copy engine). The share falls with
|
||||
the prompt (0.41 of the streamed experts at 1.5K tokens, 0.32 at 3K) and is off from ~3.3K tokens, where the stages
|
||||
overlap anyway and no share paid. Measured on 2x RTX 3090 (UD-Q4_K_XL, no P2P), prompt tok/s without / with: 1.1K 496 /
|
||||
723, 1.5K 674 / 833, 2K 878 / 1,128, 2.5K 1,017 / 1,296, 3K 1,260 / 1,440; 4K and 8K unchanged, decode unchanged. It
|
||||
costs no VRAM (the idle card's own prompt buffers) and ~110 KB of mapped host memory per token of the largest chunk it
|
||||
helped (~360 MB at 3.3K tokens). The rows it computes round like a different MMQ grouping, so the output is not
|
||||
bit-identical to the default's (it is repeatable: same prompt, same output), which is why it is **opt-in**:
|
||||
`STRATA_PREFILL_HELP=1` turns it on. Native packs on the MMQ prompt path only (not with the fused prompt kernels,
|
||||
`STRATA_PF_FUSED=1`, nor with `--peer-device`). With it on, `STRATA_PREFILL_HELP_FRAC=f` fixes the share.
|
||||
|
||||
The engine flags behind it: `--layer-split K1[,K2..]|auto` and `--split-device D1[,D2..]` (the later stages'
|
||||
devices; default the next visible ones). `--layer-split K --split-device 0` runs both stages on one card sharing
|
||||
everything - the bit-exact check of the hand-off, not a speed mode.
|
||||
|
||||
**The draft layer's prompt K/V in batches on a split (opt-in, `STRATA_SPLIT_MTP_BATCH=1`).** With `--mtp` the draft
|
||||
layer sits on the last card, and each prompt chunk ends by filling that layer's K/V for the chunk's rows. On one card the
|
||||
prompt path does it in batches (`Prefill::draft_kv`, a few large matrix products per chunk); on a split the drafter's own
|
||||
pass always did it, one graph launch and four device copies per group of 8 rows (1,024 groups per 8,192-token chunk).
|
||||
With the variable set, the last card's prompt path batches it as it does on one card. Restart-only; default off, so the
|
||||
default start is unchanged. It needs a `--native` pack (the GGUF-form token table) and a paged or ring (`--kv-resident`)
|
||||
draft K/V (`STRATA_MTP_BATCH_RING=0` sends a ring back to the old pass); otherwise it says why once and keeps the old pass:
|
||||
`strata serve: draft layer prompt K/V batched on CUDA<d> ...` or `strata serve: STRATA_SPLIT_MTP_BATCH=1 declined, the
|
||||
drafter's own pass runs: <reason>`. The draft layer's K/V come out of Q8_1 x Q8_0 MMQ instead of its own mmvq, so the
|
||||
drafts, and how many are accepted, can move; the target's tokens are decided by the verify window.
|
||||
`tools/split_mtp_batch_parity.py` compares the greedy texts of the two arms. Measured on one machine (2x RTX 3080 20 GB
|
||||
at 220 W, Xeon E5-2696 v4, UD-Q4_K_XL, `--layer-split 23`, `--batch-mtp`, two slots, `--prefill auto:16384`), two full
|
||||
restarts per arm in the order off, on, off, on, the same binary in every arm: pooled medians of the prompt read were 1,996
|
||||
tok/s without and 2,129 with at 25K tokens (+6.7%), 2,448 and 2,553 at 51K (+4.3%), 2,846 and 2,940 at 104K (+3.3%); all 8
|
||||
on/off ratios of medians are above 1 (1.03 to 1.08), and the two off restarts differ by at most 2% at 25K and 0.3% at the
|
||||
other sizes. The host's "after each chunk" time per request fell from 0.9-1.3 s to 0.1-0.25 s (one restart per arm). Greedy
|
||||
output (`--adapt-every 0 --suffix-draft 0`, five prompts of 256 tokens and one 25.5K-token prompt) was identical in 6 of 6
|
||||
prompts in all five comparisons, the two runs inside one process (A/A) included, and the drafts accepted were 826 of 1,210
|
||||
in every run, so no difference in acceptance was visible. Decode is not shown to be unchanged: the medians with the variable
|
||||
set were about 3% lower (pooled solo 82.6 -> 80.2 tok/s, two streams 93.2 -> 90.8), and the same configuration restarted
|
||||
twice moved up to 4.7%, so two restarts per arm can neither confirm nor exclude it; the change touches only the prompt path.
|
||||
|
||||
**Each card loads only its own layers' dense weights** (0.1.39, PR #639) with explicit split points (`--layer-split
|
||||
27`, not `auto`): every card used to keep a full copy (~3.4 GB for the Coder) though its stage reads only its own
|
||||
layers, and the VRAM it frees goes to that card's expert cache (2x MI50 16 GB, Coder: 8,819 -> 10,626 experts in
|
||||
VRAM, decode 39.2 -> 41.7 tok/s). Opt-in for now, on AMD and NVIDIA alike: `STRATA_STAGE_TRIM=1` (please report how
|
||||
it goes).
|
||||
A card holding more experts can change which experts run on the GPU, so the output can differ slightly from a run
|
||||
without it.
|
||||
|
||||
**The resident RAM mode works on a split** (`--resident-experts`, the low-RAM mode). The RAM copy of the experts
|
||||
leaves out the ones every card's cache holds, not only the first card's, and when the rest does not fit whole it keeps
|
||||
the hottest by the expert profile over all the layers. An adaptive swap copies the evicted expert back into RAM from
|
||||
the card that owns its layer. Before, `--resident-experts` with a split ran as `--mmap-experts`, and setup recommended
|
||||
one card in the low-RAM mode; with an engine that has it (`RESIDENT_SPLIT_ENGINE` in setup.py), setup keeps the cards
|
||||
together and the experts no card holds in RAM. The same copy, sized by a RAM budget (`--resident-budget-gib`, the
|
||||
Unsloth UD-Q4_K_XL and UD-IQ4_XS configs), is kept on a split as well ([UNSLOTH_Q4.md](UNSLOTH_Q4.md)). Swift 1.5 IQ3_XXS at
|
||||
160K (q4_0 KV, `--prefill 4096`, `--spec 4` with the stock draft layer), RTX 4060 Ti (layers 0-19) + RTX 5080 (20-47),
|
||||
i9-14900KF, 32 GB of RAM, Windows 11, four greedy prompts at a time, decode tok/s:
|
||||
|
||||
| | first four prompts | after three more rounds |
|
||||
|---|---|---|
|
||||
| 5080 alone, `--resident-experts` | 25 | 29 |
|
||||
| split, `--mmap-experts` (what `--resident-experts` became on a split) | 32 | 64 |
|
||||
| split, `--resident-experts` (22 GiB of experts locked in RAM) | 71 | 69 |
|
||||
|
||||
The split with `--mmap-experts` catches up once the OS file cache holds the experts, on a PC with nothing else
|
||||
running; the resident copy is there from the first request and stays locked when other programs need the RAM. With
|
||||
`--pcie-frac 0 --adapt-every 0` the split's greedy output is the same with either mode.
|
||||
|
||||
**The prompt path's loan on a split and its streamed ring (`STRATA_SPLIT_RING`).** Under a split the prompt path borrows
|
||||
the tail slots of each card's expert cache for its buffers (they are given back after the prompt), and the resident RAM
|
||||
copy keeps those experts too, so a borrowed expert is not read back from the model file during a prompt. How many slots
|
||||
are borrowed depends on the prompt path's streamed ring: a split uses 96 ring slots when at least 75% of the (layer,
|
||||
expert) pairs sit in some card's cache, and `STRATA_SPLIT_RING=N` sets N slots (`0` goes back to the pinned-share rule).
|
||||
The ring used to be chosen after the RAM copy's regions were sized, so the regions were sized for a different ring than
|
||||
the prompt path then used: with `STRATA_SPLIT_RING=384` it borrowed 5,396 slots and the copy kept 4,662, and the
|
||||
other 734 were read from the model file in every chunk. The ring is now chosen first (`Prefill::set_ring_override`
|
||||
says it must be set before the buffers are counted). The start-up line `strata serve: lend sizing: the prompt path
|
||||
borrows N slots (ring R slots at chunk C), K of them keep their experts in RAM too` shows both numbers, and a
|
||||
`WARNING` follows when K is below N. Without a split, or without `--resident-experts`, nothing changes. With a split
|
||||
the order of the two steps changed for every ring choice, the 96-slot rule included: its regions used to be sized for
|
||||
the larger default ring, so there the copy probably kept more slots than were borrowed (not measured). The 5,396 /
|
||||
4,662 figures were measured on the test machine (2x RTX 3080 20 GB at 220 W, Xeon E5-2696 v4, UD-Q4_K_XL,
|
||||
`--layer-split 23`, resident RAM mode, `--prefill auto:16384`, 2 slots), one restart per arm, with `STRATA_SPLIT_RING=384`
|
||||
and `STRATA_PREFILL_RING` unset. Before the change a 104K-token prompt made 413 blob reads and read 10.3 GB of experts
|
||||
from the model file per request; after it, 0, with all 5,396 borrowed slots kept in RAM, for 2.15 GiB more pinned RAM
|
||||
(13.61 -> 15.76 GiB). 25K and 51K prompts read nothing from the file in either case. With the override unset and
|
||||
`STRATA_PREFILL_RING=384` the lend lines are identical before and after (5,396 / 5,396, 15.76 GiB). No speed gain is
|
||||
shown: the medians of three 104K reads were 2,803 tok/s before and 2,907 after, but the spread before is 2,540-2,897
|
||||
(its first read faulted 4.2 GB in from NVMe) and there is no A/A restart. Here the page cache absorbed the 10 GB per
|
||||
request; with less spare page cache it would be disk traffic. Not measured: both ring variables unset.
|
||||
|
||||
**A separate VRAM reserve for the later cards:** `--vram-reserve-later-mib N` (default: `--vram-reserve-mib`'s value).
|
||||
The card that drives the monitors needs more headroom than one that drives none; with the display on the last card,
|
||||
`--vram-reserve-mib 300 --vram-reserve-later-mib 1800` gives the first card's cache that VRAM.
|
||||
|
||||
**auto** tries every placement (all of them for two, three or, since 0.1.40, four cards; proportional to the free VRAM beyond that) and
|
||||
keeps the one whose caches would hold the most of the expert profile, hottest pairs weighted most; ties go to the
|
||||
placement that leaves the fullest card the most room. The startup log prints the choice:
|
||||
|
||||
```
|
||||
strata generate: layer split auto: K=19 - the caches hold 11767 of 12288 profiled pairs (fullest device 100%)
|
||||
strata serve: layer split: layers 0-18 (CUDA0), 19-47 (CUDA1), one hand-off per window
|
||||
```
|
||||
|
||||
## What each card holds
|
||||
|
||||
- **every card**: a copy of the dense weights (~3.4 GB for the Coder), its own session state (the KV cache of the full
|
||||
context), its verify window and its prompt-path buffers, and an expert cache for its layers filled from the profile;
|
||||
- **the last card**: also the output head and the draft layer (~0.8 GB);
|
||||
- **host RAM**: the expert arena once, shared by all cards (the CPU pool computes whatever no card holds).
|
||||
|
||||
Prompts are read in chunks that flow through the cards in turn; while a later card reads chunk c, the first card
|
||||
already reads chunk c+1. (0.1.44, AMD gfx12: the auto chunk on a split stays at 8192, not the single-card 16384: a 16K prompt is then two chunks
|
||||
that overlap instead of one, a 32K one four instead of two. Same tokens; 2x / 3x / 4x R9700 prompt tok/s at 16K +36% / +45% / +53%,
|
||||
32K +18% / +21% / +29%, 64K +4% / +12% / +17%, 8K unchanged. `STRATA_SPLIT_CHUNK16K=1` keeps 16384.) Conversation checkpoints save and restore every card's state; the adaptive expert swaps copy
|
||||
into the card that owns the layer.
|
||||
|
||||
## Overlapped hand-off (`STRATA_SPLIT_OVERLAP=1`, opt-in)
|
||||
|
||||
By default each verify window runs the stages one after another: the host syncs stage 1, then stages and launches
|
||||
stage 2's graph, and so on. `STRATA_SPLIT_OVERLAP=1` (stages on different cards only) gives the hand-off a ready
|
||||
flag: the earlier stage's GPU writes the hand-off with volatile stores and raises the flag (`handoff_publish`), the
|
||||
next stage's graph is staged and launched on a helper thread while the earlier stage is still running and waits for
|
||||
the flag on its GPU (`wait_flag_ge`), and the host goes straight from serving one stage's layers to the next, syncing
|
||||
the earlier stage only once the chain is done. It takes one stream sync and one graph launch per window off the
|
||||
critical path. Batch windows (several conversations) keep the serial order. It is off beside `--pipeline-windows`, whose loop overlaps the stages its own way.
|
||||
|
||||
Measured on 2x RX 7900 XTX (gfx1100, ROCm, Linux), Ryzen 9 9900X, 52 GB RAM, Swift 1.5 IQ3_XXS, 128K context, 8-bit
|
||||
KV, layers 0-25 / 26-47; 512-token greedy answers, median of 8 runs:
|
||||
|
||||
| | serial (default) | `STRATA_SPLIT_OVERLAP=1` | one card |
|
||||
|---|---|---|---|
|
||||
| decode, code prompt | 53 tok/s | 70.1 tok/s | ~70 tok/s |
|
||||
| decode, prose prompt | 45 tok/s | 55.9 tok/s | ~68 tok/s |
|
||||
|
||||
Greedy output is byte-identical with the flag at 0 and 1; the quiz set scored the same (47/51). Not measured on
|
||||
NVIDIA yet, where a sync and a graph launch cost less.
|
||||
|
||||
The reading stage's wait for the flag is bounded on the GPU: `STRATA_SPLIT_WAIT_MS` (default 30000, 0 = no bound).
|
||||
If the flag does not arrive in time, the wait marks an error word and returns, the window's graph completes, and the
|
||||
host fails that window with an error naming the setting (the server then restarts the engine) instead of using a
|
||||
stale hand-off. Normally the host's own per-layer wait (20 s, #267) ends a stalled window first and releases every
|
||||
GPU wait, the hand-off's included. Test hook: `STRATA_TEST_HANDOFF_DROP=N` withholds the flag in the first stage's
|
||||
N-th window, as if the publish were lost.
|
||||
## Prompt chunks sized for the pipeline (`--prefill-pipe`, opt-in; setup's `--calibrate` sets it)
|
||||
|
||||
`--prefill auto` takes the largest chunk the buffers allow (up to 8192), which is what one card wants: a chunk costs a
|
||||
fixed pass over its layers' experts (b: dequantized, or streamed over PCIe where they are not in VRAM) plus a part per
|
||||
token (a), so few large chunks are cheapest. A layer split reads a prompt as a pipeline - stage s reads chunk c while
|
||||
stage s+1 reads chunk c-1 - and then takes about sum_i (b + a C_i) + (S - 1) max_i (b + a C_i) for chunks C_i over S
|
||||
stages: large or uneven chunks keep the later cards waiting (a 10.7K-token prompt in a 7680 and a 3011 chunk over
|
||||
four stages: the first stage carried 24 of the 36 s), small ones pay b again and again.
|
||||
|
||||
`--prefill-pipe R` reads each prompt in the chunk count with the least pipeline time for b/a = R tokens, when that
|
||||
beats today's split by 3% or more: every count from the fewest the buffers allow is tried, each chunk evened out on the
|
||||
256-token grid (at least 512, at most the buffers' chunk; keep `--prefill auto` so long prompts may use large chunks).
|
||||
b/a differs by an order of magnitude between rigs - about 700 tokens on four GP100 dies (every expert in VRAM, slow
|
||||
arithmetic), about 5000 on two RTX 3090 Ti (part of the experts streamed per chunk, fast arithmetic) - and a wrong one
|
||||
costs: a fixed 1024 read 19-24% slower on the two RTX 3090 Ti and 22-36% slower on two RTX 4090 (reported in the PR by
|
||||
MistyMoonR). So it is neither guessed nor learned from the prompts the engine serves (that made a prompt's chunks, and
|
||||
so its output bits, depend on how busy the PC happened to be): like the PCIe share and the draft floor, it is a
|
||||
setting of the PC that setup's `--calibrate` measures once (`tools/calibrate.py`: on a layer split, the prompt read
|
||||
speed of a 2K- and an 8K-token prompt - the same text every time, after a header of its own so nothing is reused -
|
||||
with the chunks off, evened out and b/a 768, 1536, 3072 and 6144; the best is kept only when it reads faster than off
|
||||
in each of three paired rounds and by more than 3% in the median) and writes into the config. Measured so: four GP100
|
||||
dies keep b/a 768 (355-356 against 219-220 tok/s in every round, +62%); two RTX 3090 Ti keep it off (nothing read
|
||||
faster than off, b/a 768 20% slower). A first version that read a different stretch of text per value and confirmed in
|
||||
two rounds picked 1536 on the RTX 3090 Ti pair from one fast read - where the experts are streamed, the read speed
|
||||
depends on the text. `--prefill-pipe 1` needs no
|
||||
b/a: it is `STRATA_PREFILL_EQUAL=1`'s rule (#693) - today's chunk count, evened out on the 256-token grid, and only
|
||||
when today's last chunk has 1024 tokens or more (3072 with `STRATA_PREFILL_CPU_SHARE` set). A chunk that size streams
|
||||
every expert its card does not hold, a shorter one only the experts it routes to, so a prompt just past the chunk size
|
||||
reads as one full chunk and a nearly free tail, and evening that out would add a second full pass over the experts:
|
||||
the first version evened every split out, and on two RTX 4090 MistyMoonR's calibration read 1,601 tok/s with it
|
||||
against 2,129 off. 0 (the default) is today's split;
|
||||
`STRATA_PREFILL_PIPE=<R>` is the same as the flag where the config cannot carry it. The chunk geometry changes the
|
||||
rounding, which is why it is opt-in.
|
||||
|
||||
A prompt segment (the prompt between two of its cuts: the system-prompt root, the last turn, a `pin=`) is planned once,
|
||||
on its whole length and R, and every run of it reads in that chunk. So its chunks, and the loan its buffers are laid
|
||||
out for, are the same whether it is read in one run, in pieces between the windows of decoding `--batch` slots, or goes
|
||||
on after a `BYIELD` or from a periodic checkpoint taken inside it (the slot and the checkpoint keep the plan; the read
|
||||
goes on in it when it continues the same segment, else it plans again and says so in the log). The output bits then
|
||||
match as far as the experts the cards hold do (`--adapt-swaps 0` for byte-identical repeats, as without the pipe).
|
||||
Before this, a read beside decoding slots re-planned every piece, and one that went on after a `BYIELD` re-planned what
|
||||
was left. A chunk the pipe planned takes no `STRATA_PREFILL_CPU_SHARE`: the stages read
|
||||
such chunks at the same time, and which stage got the CPU pool first would decide which experts the CPU computed. The
|
||||
DONE line ends with `chunk=` (the first chunk of the request's longest batched segment) and `experts_streamed=` (the
|
||||
expert blobs its prompt copied to the cards), and the INFO line carries `prefill_cap`, `prefill_stages`,
|
||||
`stream_all_min` and `prefill_pipe`. One line in the log says what a plan chose:
|
||||
|
||||
strata prefill: 10058 tokens in 1280-token chunks over 4 stages (--prefill-pipe 706: b/a)
|
||||
|
||||
Four GP100 dies (PH402 SKU 200, `--layer-split 12,24,36`, Flash-Next IQ3_XXS, 64K context), prompt tok/s, fresh
|
||||
prompts, two interleaved rounds (each within 0.2%), with b/a 1024 (the same chunks as 700-890, measured on this rig):
|
||||
|
||||
| Prompt tokens | `--prefill auto` | `--prefill 2048` | `--prefill auto` + `--prefill-pipe 1024` (chunk) |
|
||||
| ---: | ---: | ---: | ---: |
|
||||
| 2,013 | 180.9 | 181.4 | 228.0 (1024) |
|
||||
| 3,865 | 207.6 | 276.5 | 312.4 (1024) |
|
||||
| 10,041 | 261.1 | 433.0 | 432.6 (2048) |
|
||||
| 28,998 | 475.7 | 554.1 | 559.7 (3328) |
|
||||
|
||||
Two RTX 3090 Ti (CUDA 12.9 build for sm_86, two stages, Swift 1.5 IQ3_XXS, 1M context, 13,371 of 24,576 experts in
|
||||
VRAM), prompt tok/s, fresh prompts, two starts per arm, each reading the four prompts twice (the cold first pass after
|
||||
a card was freed is left out); b/a 5836 and 6432 (timed on the rig), against 1024:
|
||||
|
||||
| Prompt tokens | `--prefill auto` | + b/a 5836 / 6432 (chunk) | for comparison: b/a 1024 |
|
||||
| ---: | ---: | ---: | ---: |
|
||||
| 2,035 | 694-815 | 698-816 (today's) | 560-562 |
|
||||
| 3,887 | 1,127-1,207 | 1,115-1,227 (today's) | 880-885 |
|
||||
| 10,063 | 1,437-1,553 | 1,654-1,681 (2 x 5120) | 1,109-1,113 |
|
||||
| 29,019 | 2,532-2,603 | 2,566-2,620 (today's) | 2,064-2,089 |
|
||||
|
||||
## Limits (for now)
|
||||
|
||||
- **Works across cards** (bench/results/2026-09-29-layer-split-limits):
|
||||
- images (`--vision`): each card keeps its own image-position table;
|
||||
- control vectors and the experimental speed projection: each card holds the vector's tables, switched on and
|
||||
off per request on all of them;
|
||||
- KV streaming (`--kv-resident`): each card streams the KV of its own session;
|
||||
- mid-prompt checkpoints (`--prompt-cache-every`): each card saves its part of a checkpoint when it has read that
|
||||
chunk;
|
||||
- the older helper-GPU caches (`--expert-cache-remote`, docs/SECOND_GPU.md): they take the visible GPUs no stage
|
||||
runs on, and hold only experts no stage's cache holds. On the test rig, a 2080 Ti helper made decoding slower,
|
||||
as it did without a split: its per-layer round trip costs more than the CPU pool needs for those experts.
|
||||
- `--mmap-experts` needs a canonical pack (`experts.bin`), with or without a split; a native (IQ) pack says so at
|
||||
start.
|
||||
- The prompt path has its own buffers on every card (1.5 GB each at the default 2048-token chunk; `--prefill 1024`
|
||||
halves that) instead of borrowing cache slots as one card does. An explicit `--expert-cache` on the first card is
|
||||
capped to leave room for them.
|
||||
- Under WDDM (Windows, and WSL2) only 8 GiB of the expert arena is pinned (more, mapped into two GPU contexts,
|
||||
leaves WDDM refusing allocations); the rest streams through the pinned staging ring. A Linux driver has no such
|
||||
limit, so there the whole arena is pinned (since 0.1.31; the cap cost a 4090 + 3060 split two thirds of its
|
||||
prompt speed, #253). `STRATA_ARENA_PIN_GIB=N` pins at most N GiB, `0` the whole arena, on any OS.
|
||||
- Every card needs compute capability 7.5 (RTX 20 or newer). The pre-sm_80 QSA scorer path is fp32 FMAs, so a
|
||||
Turing card runs the same kernels instead of the tensor-core prompt attention.
|
||||
|
||||
## Measured
|
||||
|
||||
The Coder on an RTX 5080 + RTX 3090 (Ryzen 9 9950X3D), 32K context; details in
|
||||
`bench/results/2026-09-29-layer-split/`:
|
||||
|
||||
| | Prompt 16K / 28K tok/s | Decode story / code tok/s |
|
||||
|---|---|---|
|
||||
| 5080 alone | 1,726-2,017 / 1,970 | 83-87 / 88-105 |
|
||||
| 5080 + 3090, best split (K=26) | 2,039 / 2,357 | 84 / 110 |
|
||||
| 5080 + 3090, auto (K=22) | 2,037 / 2,073 | 80 / 109 |
|
||||
|
||||
- **Prompts gain the most** (+18-20%): each card reads its own layers of the chunk while the other reads the next.
|
||||
- **Decode is on par with the faster card alone**, and ahead on code. Once both caches hold nearly every routed
|
||||
expert, the per-layer GPU time decides.
|
||||
- **Correctness:** one GPU is byte-identical to 0.1.20, and the hand-off itself is bit-exact.
|
||||
|
||||
**Which cards and in what order:**
|
||||
- Put the fastest card first; auto gives it as many layers as its cache allows.
|
||||
- Leave out a much slower card when two already hold the model. An RTX 2080 Ti as a third card made the 5080 +
|
||||
3090 pair slower (68 / 90 tok/s decode): every extra card costs its own round per window.
|
||||
- More cards pay off when the model's routed experts do not fit the faster ones.
|
||||
|
||||
## One conversation with both cards busy (`--pipeline-windows`, default on two or more AMD gfx12 stages)
|
||||
|
||||
**Default on AMD RDNA4 (gfx1200 / gfx1201).** With `--serve`, the draft layer and a layer split of **two or more stages**,
|
||||
`--pipeline-windows 2` is on unless you say otherwise (the log says "is on by default for a layer split of N stages"; two
|
||||
stages since 0.1.44, three or more since 0.1.43). It is no quality trade: the tokens are the serial loop's up to CPU rounding
|
||||
(below). `--pipeline-windows 0` or `STRATA_PIPELINE_AUTO=0` turns it off; `--pipeline-windows 2` asks for it on any split.
|
||||
The same options that switch it off when you ask for it (`--batch`, `--peer-device`, the helper caches, no draft layer,
|
||||
`--adapt-async 1`) leave it off without a line when it is only the default. NVIDIA builds keep it opt-in.
|
||||
|
||||
**Where the draft layer sits (0.1.44).** The draft layer's chain used to run on the last card, beside the last stage's window.
|
||||
On 2x / 4x R9700 the two streams then slowed each other, in most engine starts and for the whole life of that engine: the
|
||||
last stage's window took 27 ms instead of 13 ms while a chain ran (14.9 ms in the lucky starts, which also decoded 25% faster;
|
||||
the 0.1.43 notes' "128.9 does not reproduce" was this). With the pipeline on, the engine now loads the draft layer on the
|
||||
**first** card, whose window has finished when the chain starts: the chain's source rows are copied across once per chain and the
|
||||
draft head's rows once at load. Same tokens; `STRATA_MTP_STAGE0=0` keeps the old place. Exact-flags A/B, 5 pairs, decode tok/s
|
||||
(serial loop -> now): 2 cards code 103 -> 125 (+21%), 4K prompt +8%, prose equal; 3 cards code +19%, 4K +12%, prose +2%; 4 cards
|
||||
code +22%, prose +4%, 4K +15%.
|
||||
|
||||
With a split the cards take turns on a verify window: the first card runs its layers and hands off, then waits while
|
||||
the last card runs the rest, the head and the draft. `--pipeline-windows 2` lets the first card start the **next**
|
||||
window while the last card still verifies this one. The next window is a guess: that this window is accepted whole
|
||||
and that its bonus token is the one the draft layer predicts (the draft layer is run on through the drafts of the
|
||||
window in flight). When the guess holds, half of the next window is already done; when it does not, the first card
|
||||
puts its state back (a copy of its recurrent state taken while the window ran) and the next window is built from the
|
||||
real tokens. A guessed window is only started when the draft layer's estimate says it is likely to be kept. Windows
|
||||
copied from earlier context (`--suffix-draft`) are guessed past as well, which is where edits that copy text gain
|
||||
most. `--pipeline-windows 1` overlaps only the short prompt reads that go through the verify windows
|
||||
(`--short-read`).
|
||||
|
||||
Two or more cards, `--serve`. With three or more stages every stage but the last is a front stage: the guessed
|
||||
window follows the verified one through them one card behind (each front stage keeps its own pair of recurrent-state
|
||||
copies and puts its state back on a wrong guess), and only the last stage waits for the verdict. `--pipeline-windows 1`
|
||||
and the asynchronous tier stay two-stage. In the config:
|
||||
|
||||
```
|
||||
"args": [ ..., "--pipeline-windows", "2" ],
|
||||
"layer_split": "20"
|
||||
```
|
||||
|
||||
- **Cost**: a second verify window on each card, 160 MiB more kept out of each card's expert cache, plus two copies
|
||||
of the first card's recurrent state (about 3 MiB per GDN layer it runs) on the first card with `2` (on every front
|
||||
card with three or more stages; only the first card's room is kept out of its cache, the others allocate theirs after).
|
||||
- **Same text**: the last card only ever runs windows that are verified, and every window row computes what it
|
||||
would in any other window, so the tokens are the serial loop's. With `STRATA_IQ_MT_MIN=1 --pcie-frac 0
|
||||
--adapt-every 0` the greedy output is identical bit for bit to the serial loop's with the same expert caches. The pipeline keeps
|
||||
its VRAM out of the caches, so against a run without the flag a few experts move from a card to the CPU, which
|
||||
rounds them differently, and a near-tie can flip (a serial run given the same caches through `--vram-reserve-mib`
|
||||
matches it exactly).
|
||||
- **Off, with one line in the log saying why**, with `--batch` slots, `--peer-device`, the helper caches
|
||||
(`--expert-cache-device1..3`, which `--remote-expert-opt` builds on), a split onto one GPU (`--split-device 0`), or no
|
||||
draft layer; on three or more stages also `--pipeline-windows 1` and `--adapt-async 1`. A request with repetition penalties (`penalty_last_n`) or coupled
|
||||
draft sampling decodes serially.
|
||||
- **With the resident RAM mode's asynchronous swaps** (`--adapt-async 1`, [DETAILS.md](DETAILS.md)) a round's steps
|
||||
advance between the verified windows. Each card's copies are queued by the decode loop itself while that card has
|
||||
no window in flight, after every window that may still read what they overwrite has finished; the moves into RAM
|
||||
wait the same way.
|
||||
- **Measured** (Swift 1.5 IQ3_XXS, 160K context, q4_0 KV, the stock draft layer, RTX 4060 Ti (layers 0-19) +
|
||||
RTX 5080 (20-47), i9-14900KF, 32 GB of RAM with the resident RAM mode on the split (#848); greedy, 500 tokens, two
|
||||
interleaved pairs of three rounds, decode tok/s): Python code 90.4 -> 103.1, C code 76.6 -> 81.6, English prose
|
||||
63.0 -> 71.1, Italian prose 41.6 -> 46.3, a copy-heavy edit (a 5 KB file back with a rename) 90.5 -> 117.9; mean
|
||||
72.4 -> 84.0 (+16%). It pays when the windows are GPU-bound: with the experts read through the OS file cache
|
||||
(`--mmap-experts` on that 32 GB PC) the file reads dominate and it measured no faster.
|
||||
- **Measured on four stages** (Flash-Next GSQ-RCO IQ3_S, 262K context, int8 KV, layer split 12,24,36 on 4x RX 7900 XT,
|
||||
every expert in VRAM; greedy, reasoning off, 256 tokens, repository-text prompts): decode 59.4 -> 67.6 tok/s at 4K
|
||||
(median of 3) and 51.8 -> 65.6 at 32K. A guessed window that holds costs ~15 ms against ~43 ms for a fresh one; about
|
||||
a third of the guesses held. The greedy text was identical to the serial loop's on all four prompts (`STRATA_IQ_MT_MIN=1
|
||||
--pcie-frac 0 --adapt-every 0`), and with every guess forced wrong (`STRATA_PIPELINE_FORCE_MISS=1`).
|
||||
- **HIP**: the draft layer's per-row `gr_read` used the last stage's session scratch (`ss.block.gr`), which that stage's
|
||||
verifier also uses; a chain launched at a verdict and the next window's last stage then ran on the card at once and
|
||||
the window's head read a clobbered mix (wrong tokens after a guess that held). The draft layer now has its own scratch.
|
||||
|
||||
The `STRATA_PIPELINE_*` tuning and test variables (THETA, FORCE_MISS, SWITCH, LOG, TRACE, SPEC_DEPTH and the like) are read only with
|
||||
`STRATA_PIPELINE_DEBUG=1`. `--pipeline-windows` and `--adapt-async 1` combine: the engine turns the asynchronous tier
|
||||
off beside `--pipeline-windows 2` only when `STRATA_PIPELINE_ADAPT_ASYNC=0` is set. What switches either one off is
|
||||
printed once at start ("is off: ..."). `--remote-expert-opt` does something only with a helper cache
|
||||
(`--expert-cache-device1..3`); on a plain layer split it is inert, and setup no longer writes it there (#1447).
|
||||
|
||||
Measured on 2x RTX 3090 (sm_86, 250 W limits; GPU0 PCIe 4.0 x16, GPU1 x4, no NVLink; Ryzen 7 9800X3D, 32 GB RAM),
|
||||
Qwen3.8-Flash-Next GSQ-RCO IQ3_S, `--resident-experts`, KV int8, `--spec 4 --mtp`, `"layer_split": "29"` for the
|
||||
`--pipeline-windows` rows (without `--remote-expert-opt`); the others are setup's config (`auto`). Decode is the mean of
|
||||
runs 2-6 of 1,500-token coding replies at temperature 0.6, prefill one cold 19.9K-token prompt; one run per arm unless
|
||||
noted (reported by adambenhassen, #1447; not repeated on our boxes):
|
||||
|
||||
| Arm | Decode tok/s | Prefill tok/s |
|
||||
|---|---:|---:|
|
||||
| setup defaults (two runs) | 137.0 / 136.9 | 1798 |
|
||||
| `--adapt-async 1` (two runs) | 145.2 / 143.7 | 1800 / 1797 |
|
||||
| `--adapt-async 1`, no `--remote-expert-opt` | 145.0 | 1807 |
|
||||
| `STRATA_ADAPT_LAG=2` | 142.8 | 1800 |
|
||||
| `STRATA_EXCHANGE_ROTATE=1` | 139.6 | 1800 |
|
||||
| `STRATA_PF_FUSED=1` | 137.2 | 1913 |
|
||||
| `--pipeline-windows 2` | 136.7 | 2097 |
|
||||
| `STRATA_SPEC_COUPLED=1` | 137.6 | 1804 |
|
||||
| `STRATA_SPEC_PROB=1` | 137.2 | 1788 |
|
||||
| `STRATA_SPEC_COUPLED=1` + `STRATA_SPEC_GUMBEL=1` | 136.5 | 1805 |
|
||||
| async + lag 2 + rotate + pf_fused | 145.0 | 1829 |
|
||||
| pw2 + lag 2 + rotate + pf_fused | 135.9 | 2296 |
|
||||
| pw2 + async + lag 2 + rotate + pf_fused | 142.0 | 2302 |
|
||||
|
||||
The last row keeps most of the asynchronous tier's decode gain and the pipeline's +28% prefill; no stalls in any arm.
|
||||
These are opt-in settings on one rig, not defaults.
|
||||
|
||||
## Several conversations at once
|
||||
|
||||
With a layer split, `--batch N --batch-groups G --trim-stage-weights` decodes several conversations together and
|
||||
pipelines them through the cards: see [BATCHING.md](BATCHING.md).
|
||||
|
||||
## The strata-poly models
|
||||
|
||||
Qwen3.6, Gemma 4, Ornith, Tiel Coder and GLM 5.3 Flash run on the strata-poly engine, which splits a model's layers
|
||||
across cards too. Each card runs a range of layers and keeps the routed experts of those layers in its VRAM, as many
|
||||
as fit. The last card also runs the output and the draft block, or Gemma 4's draft model. After its layers a card
|
||||
copies the rows of the tokens it read into pinned RAM, and the next card reads them from there: one row of the
|
||||
model's width a token, 8 KB for Qwen3.6. No NVLink or peer-to-peer access is needed.
|
||||
|
||||
A prompt read in several calls keeps the cards busy together when every routed expert is in VRAM, or when the
|
||||
prompt is shorter than `--stage-ahead` tokens: the next card runs its layers for a call on a thread of its own while
|
||||
this card runs the call after it. A longer prompt with experts outside VRAM is read a layer at a time for all its
|
||||
calls, so that each layer's experts are copied in once, and there the cards take turns. Having them overlap would
|
||||
mean reading the prompt in parts, which copies every layer's experts once a part, and the copy is most of the time
|
||||
such a read takes. An answer is written a token at a time, and the cards take turns on it too. So with no expert in
|
||||
VRAM two cards read a long prompt no faster than one. What a split adds there is VRAM: two cards hold more of the
|
||||
experts, and an expert on a card is not computed by the processor.
|
||||
|
||||
Setup asks which cards as it does for Qwen3.8-Flash-Next (`--gpus 0,1`, or the list it shows) and writes
|
||||
`"gpu": [0, 1]` and `"layer_split": "auto"` into the config. With `"auto"` each card gets a share of the layers'
|
||||
bytes by its free VRAM less 1.5 GiB, and the last card's share is smaller by the output and the draft block. A list
|
||||
of numbers is the first layer of each later card, as above, and the last card keeps two layers at least. The server
|
||||
puts the faster card last, as it does for the other engine. The engine's flag is `--layer-split auto|N[,N...]`; it
|
||||
splits across the cards `CUDA_VISIBLE_DEVICES` shows it, in that order. The log names each card's layers:
|
||||
|
||||
```
|
||||
strata-poly: layers 0 to 21 on card 0: 5632 of 5632 routed experts in VRAM (7.2 GiB)
|
||||
strata-poly: layers 22 to 39 on card 1: 4864 of 4864 routed experts in VRAM (6.5 GiB)
|
||||
```
|
||||
|
||||
Measured on two RTX 3080 (10 GB each, 320 W) with a Xeon Platinum 8255C under Linux, the engine built with CUDA
|
||||
12.4: a prompt of 2,727 tokens read with nothing cached, and 256 tokens written after a short prompt, in three
|
||||
starts of each. The engine of 2026-10-11 ran it again, three starts on one card and three on both in turn, and read
|
||||
at 1,567-1,582 and 3,425-3,562 tokens/s and wrote at 165-177 and 217-221. A cell has the higher of the two passes.
|
||||
|
||||
| Qwen3.6 UD-Q3_K_M | Experts in VRAM | Reads the prompt | Writes |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| one RTX 3080 | 4,606 of 10,496 | 1,570-1,700 tokens/s | 165-177 tokens/s |
|
||||
| both | 10,496 of 10,496 | 3,420-3,560 tokens/s | 217-221 tokens/s |
|
||||
|
||||
With the cards taking turns on the prompt, as they did before, both read it at 3,070-3,090 tokens/s in two starts
|
||||
of the same test, and wrote as fast.
|
||||
|
||||
Gemma 4 UD-Q3_K_M: a prompt of 3,527 tokens at 2,190 tokens/s on one card in one start, and at 3,600 on both in
|
||||
two starts (3,110-3,160 with the cards taking turns); writing at 178 and 189 tokens/s in one start each. The engine
|
||||
of 2026-10-11, two starts of each in turn, read it at 2,170 and 3,540-3,590 and wrote at 182-187 and 191-193. One
|
||||
card already held 2,042 of its 3,840 experts, which were most of what an answer used.
|
||||
|
||||
With no expert in VRAM (`--vram-reserve-mib 20000`) and `--cpu-share 0`, and with every expert on the processor
|
||||
(`--no-gpu-experts`), both cards gave the same greedy tokens as one card, for Qwen3.6 and for Gemma 4, through a
|
||||
prompt read in several calls, the prompt cache, a checkpoint, the conversation cache and a request stopped in the
|
||||
middle. With no expert in VRAM and the CPU's share at its default, Gemma 4 still did, and two of Qwen3.6's eight
|
||||
answers came out other: the share follows how long the calls before took, so which experts the processor computes
|
||||
changes from one run to the next. With experts in VRAM the answers can differ a little, as they do between two
|
||||
starts on one card: which experts run on a card and which on the processor changes the rounding.
|
||||
|
||||
GLM 5.3 Flash REAP50-Q3_K_M (79 GB) ran on the same two cards with 80 GB of RAM. One 10 GB card cannot hold the
|
||||
weights outside the routed experts, about 12 GB, so there is no one-card row. With `"auto"` the cards took layers 0
|
||||
to 27 and 28 to 44 and held 602 of the 6,192 routed experts (6.7 GiB). A prompt of 6,087 tokens read at 397-398
|
||||
tokens/s and 256 tokens were written at 20-21 tokens/s, in two starts; with no expert in VRAM, 367-384 and 16-16.5.
|
||||
The engine of 2026-10-11 read it at 398-399 and wrote at 20-22 in two starts, and with no expert in VRAM at 386
|
||||
and 14-16 in four.
|
||||
With no expert in VRAM and `--cpu-share 0` the split at layer 28 and the split at layer 30 gave the same greedy
|
||||
tokens for a short prompt, a long one read in several calls, the prompt cache and a checkpoint; with the share at
|
||||
its default, six of the eight answers differed. The conversation cache was not compared:
|
||||
with the RAM nearly full it parked nothing in the runs split at layer 28. Of eight starts of that test, one failed
|
||||
its long prompt with `pinned memory: invalid argument` and one stopped without a message while reading it. Both
|
||||
come from the container's memory: its limit is 80 GiB and the file is 73.4 GiB. With the whole file read into
|
||||
the page cache before the start, so that the container was within 2% of its limit, the engine was ended by
|
||||
SIGKILL in 3 of 6 starts of the speed test, each 17 s into the first long prompt, with no OOM kill counted by
|
||||
the kernel for the container or for the host; the 6 starts in turn with no expert in VRAM, which copy nothing
|
||||
to the cards, all ran through. The starts that lived wrote at 6 tokens/s where 20, the experts read from the
|
||||
disk again. With the cache empty at the start, the same test ran through at about the speeds above. The five
|
||||
`pinned memory: invalid argument` all came at load within five minutes, while a 78 GB download was filling the
|
||||
same container's cache; the engine now asks four times, a quarter of a second apart, before it gives up, and
|
||||
says at load when the container has less than the model's files and 8 GiB. This pod has less than setup asks
|
||||
for REAP50 beside 6.7 GiB of experts in VRAM, about 82 GB.
|
||||
|
||||
Not done yet:
|
||||
|
||||
- Only two cards under Linux have run it. Three cards and Windows were not tried.
|
||||
- A long prompt with experts outside VRAM, and an answer, have the cards take turns (above). The other engine's
|
||||
chunk pipeline, `--pipeline-windows`, `"split_skip_if_fits"` and its `STRATA_*` variables are not in strata-poly.
|
||||
+219
@@ -0,0 +1,219 @@
|
||||
# NVFP4 routed experts
|
||||
|
||||
The engine can serve a Qwen3.8-Flash-Next whose routed experts are NVFP4, as NVIDIA's ModelOpt stores them: 64-value
|
||||
blocks of E2M1 codes with four UE4M3 sub-block scales, plus one FP32 `weight_scale_2` per expert and projection.
|
||||
Everything else (attention, GDN, shared experts, routers, the head) stays in the formats the native path already
|
||||
reads. Measured on Windows 11, RTX 5090 (32 GB), Ryzen 9 9950X3D, 128 GB DDR5-5600.
|
||||
|
||||
## Getting a model
|
||||
|
||||
```
|
||||
python tools/nvfp4_convert.py --model <ModelOpt NVFP4 checkpoint dir> --outfile <model>.gguf
|
||||
python tools/iq_pack.py --gguf <model>.gguf --out <pack dir>
|
||||
```
|
||||
|
||||
- `nvfp4_convert.py` runs llama.cpp's own converter (`third_party/llama.cpp`, the commit setup pins) with the type
|
||||
policy the engine needs. The experts are repacked without loss: `tools/nvfp4_verify.py` compares them with the
|
||||
checkpoint bit for bit, and `tools/nvfp4_verify_gguf.py` checks the GGUF.
|
||||
- The small projections the BF16 kernels read (routers, SSM gates, indexer, PLE and hyper-connection projections)
|
||||
are written as BF16.
|
||||
- Everything served natively goes to Q8_0: attention, `ssm_out`, the shared experts, the output head, and the
|
||||
token embedding.
|
||||
- The 51.2e9-value PLE table is left out.
|
||||
- `iq_pack.py` writes `experts.bin` for an NVFP4 GGUF by itself. Each blob is `[gate | up | down]` plus a 16-byte
|
||||
tail `{s_gate, s_up, s_down, 0}`. The GGUF has no room for these scales, so the engine reads NVFP4 experts from
|
||||
`experts.bin` only.
|
||||
|
||||
Run it like an IQ pack, with the GGUF as its own dense-weight source and the PLE table from an IQ GGUF's PLE shard:
|
||||
|
||||
```
|
||||
strata --pack <pack dir> --native <model>.gguf --native-dense-gguf <model>.gguf \
|
||||
--ple-gguf <an IQ model's shard with per_layer_token_embd> --mtp <mtp/rt> \
|
||||
--expert-profile data/expert-profile.bin --expert-cache auto --prefill auto --spec 4 ...
|
||||
```
|
||||
|
||||
The NVFP4 checkpoints change only the routed experts. The PLE table, the MTP layer and the expert profile of the
|
||||
original model therefore work as they are.
|
||||
|
||||
Tested end to end with `jpezzulli/OrcaRouter-Qwen3.8-Flash-Next-Uncensored-ModelOpt-NVFP4`. By its
|
||||
`hf_quant_config.json`, NVIDIA's `nvidia/Qwen3.8-Flash-Next-NVFP4` quantizes the routed experts the same way
|
||||
(NVFP4, group 16; the other layers BF16, the PLE table FP8, the MTP experts FP8), so it takes the same path. It has
|
||||
not been run here.
|
||||
|
||||
## Measured
|
||||
|
||||
RTX 5090, 64K context, int8 K/V, `--vram-reserve-mib 1500`:
|
||||
|
||||
| | NVFP4 pack | IQ2_XS, same engine |
|
||||
| --- | ---: | ---: |
|
||||
| experts in RAM | 63.3 GiB | 33.0 GiB |
|
||||
| expert cache slots | ~8,350 | ~17,300 |
|
||||
| decode, 400-token answer | 114-116 tokens/s | 132-139 tokens/s |
|
||||
| a 32K prompt | 3,900 tokens/s | 5,600 tokens/s |
|
||||
|
||||
An NVFP4 expert blob is 2.76 MB, against 1.51 MB for IQ2_XS: the cache holds half as many, and a miss costs twice
|
||||
the bytes over PCIe. The PCIe share of the missed experts is therefore 0.25 for an NVFP4 pack, not the usual 0.55.
|
||||
At 0.55 the copy kernel was 40% of all GPU kernel time (nsys, 300-token decode). A sweep at 262K context gave the
|
||||
following decode rates:
|
||||
|
||||
| PCIe share | short prompt | 32K prompt |
|
||||
| --- | ---: | ---: |
|
||||
| 0.55 | 103 tokens/s | 105 |
|
||||
| 0.40 | 110 | 117 |
|
||||
| 0.25 | 117 | 124 |
|
||||
| 0.10 | 112 | 118 |
|
||||
|
||||
## Measured in PolyStrata (2026-10-13)
|
||||
|
||||
The numbers above are the fork author's, on his RTX 5090 and 128 GB. These were measured here, on the ready-made GPTQ
|
||||
pack (`--family nvfp4 --model NVFP4`).
|
||||
|
||||
Quality, the quant yardstick (`tools/quant_quality.py`, 4,995 teacher-forced positions of code, docs, English, other
|
||||
languages and an agent transcript, against Unsloth's Q8_0; RTX 3060 box):
|
||||
|
||||
| | same top token as Q8_0 | mean KL | KL p99 |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| NVFP4 GPTQ, experts on the CPU | 92.09% | 0.070 | 1.12 |
|
||||
| NVFP4 GPTQ, 1,500 experts on the GPU | 91.79% | 0.069 | 1.07 |
|
||||
| the same with `STRATA_ROUTE_TAIL_SKIP=7` | 88.59% | 0.118 | 1.76 |
|
||||
| NVFP4 GPTQ with the GSQ-RCO IQ4_NL n-gram table instead of the FP8 one | 92.15% | 0.069 | 1.07 |
|
||||
| for comparison, the same tool: Unsloth UD-Q5_K_XL | 94.55% | 0.038 | 0.64 |
|
||||
| Unsloth UD-Q4_K_XL | 93.09% | 0.056 | - |
|
||||
| Unsloth UD-IQ4_XS | 88.91% | 0.101 | 1.60 |
|
||||
| GSQ-RCO IQ3_S | 87.69% | 0.144 | 1.98 |
|
||||
|
||||
The route tail skip moves the answers by more than the quantization itself, so it is off by default for NVFP4
|
||||
experts. `STRATA_ROUTE_TAIL_SKIP=7` turns it on: +7-25% decode on the RTX 3060, +47-55% on the RTX 5070 (64 GB).
|
||||
|
||||
Decode experts (`nvfp4_decode_bench`, 64 distinct experts per call, the share of the card's DRAM bandwidth):
|
||||
|
||||
| tokens per expert | RTX 5070 | RTX 3060 | Tesla P100 |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| 1 | 0.294 ms (89%) | 0.554 ms (89%) | 0.910 ms |
|
||||
| 2 | 0.298 ms (88%) | 0.596 ms | 1.247 ms |
|
||||
| 4 | 0.335 ms (79%) | 0.766 ms | 1.954 ms |
|
||||
|
||||
Each weight is decoded once for all the tokens of a verify window (before the port's kernel work: 2.26 ms on the 3060
|
||||
at 4 tokens), bit for bit the same results.
|
||||
|
||||
Prompt experts on the RTX 5070 (`mmq_expert_bench`, one launch of 16 experts with 625 rows each, gate/up + down): w4a8
|
||||
1.52 ms, w4a4x2 (`STRATA_PREFILL_NVFP4=w4a4x2`) 1.13 ms, w4a4x2 with down too (`STRATA_PREFILL_X2_MIN_K=640`)
|
||||
0.995 ms, UD-IQ4_XS's experts 1.20 ms. First-token KL against the exact FP16 path (24 prompts, 1.5-8K tokens): w4a8
|
||||
0.0068, w4a4x2 0.0056, w4a4x2 with down 0.0044. On a 64 GB PC the prompt waits for the experts read from the SSD,
|
||||
so the modes give the same prompt speed there; w4a8 stays the default until a 96 GB+ RTX 50 PC measures the others.
|
||||
On RTX 20-40 the NVFP4 prompt products are 1.35-1.6x slower than IQ3_S / IQ4_NL ones at 32K: NVFP4's 16-value scales
|
||||
are applied in FP32 after every int8 step, which only Blackwell's FP4 tensor cores avoid.
|
||||
|
||||
Below its RAM need (68 GB of experts plus room) setup runs the pack in the RAM-budget mode (`--resident-budget-gib`,
|
||||
the RAM less 24 GB), as for Unsloth's files. Mapped experts (`--mmap-experts`) on a 64 GB Windows PC filled the RAM.
|
||||
|
||||
Images: the packs keep Qwen's vision tower unquantized, so the original's image encoder reads pictures for them
|
||||
(`--vision`; strata-vision opens the dense GGUF for the vocabulary). Checked on an RTX 5070 and an RTX 3060 against
|
||||
IQ3_XXS's answers on the same picture (a number in the picture read, two shapes with their colours and sides). The
|
||||
encoder on the GPU takes ~1.1 GiB of VRAM: on the 3060 at 8K context the cache held 1,293 experts with images against
|
||||
1,734 without.
|
||||
|
||||
## Where the global scales go
|
||||
|
||||
Each scale multiplies its own projection's FP32 output, as llama.cpp applies `.scale`:
|
||||
`h = silu(s_gate * (G x)) * (s_up * (U x))`, `y = s_down * (D h)`.
|
||||
|
||||
The scales are ~1e-4 each. Folding `s_down` into up is algebraically the same, but it leaves the hidden near 1e-5.
|
||||
The hidden is then rounded to Q8_0 (CPU) or q8_1 (GPU) blocks with an FP16 scale, and `amax / 127` lands deep in
|
||||
FP16's subnormals: one expert's output was off by 2-12% instead of 1.1% (`nvfp4_avx512_parity --expert`). The FP16
|
||||
prompt path had the same problem in its dequantized up weights (~1e-8). Any future fold must be checked against
|
||||
FP16's range.
|
||||
|
||||
## Prompt path precision
|
||||
|
||||
`STRATA_PREFILL_NVFP4` picks how the batched prompt path multiplies the experts:
|
||||
|
||||
| mode | kernel | activations | one product vs FP64 (`mmq_nvfp4_parity`) |
|
||||
|---|---|---|---|
|
||||
| `w4a8` (default) | llama.cpp MMQ, int8 tensor cores | q8_1, float block scales | 0.53% |
|
||||
| `w4a4` | llama.cpp MMQ, Blackwell FP4 MMA (sm_120a only) | NVFP4 | 8.6% |
|
||||
| `fp16` | dequantize + cuBLAS FP16 GEMM | FP16 | reference |
|
||||
|
||||
`src/prefill/mmq_nvfp4_w4a8.cu` compiles mmq.cuh's int8 NVFP4 path with Blackwell's FP4 MMA hidden from both the
|
||||
device code and the host's tile config, so it is the same on every architecture; decode already multiplies at this
|
||||
precision. The FP4 MMA exists only in the arch-specific target, so `src/prefill/mmq_nvfp4_w4a4.cu` (the FP4 x FP4
|
||||
kernel and its FP4 activation quantizer) is the one unit CMake builds with `12x` -> `12xa` (`strata_mmq_w4a4`);
|
||||
the rest of the engine keeps the architectures as given and runs on sm_121 too. A card without that unit's image
|
||||
(another architecture, or sm_121 against a 120a build) falls back to `w4a8` with a note.
|
||||
|
||||
First-token KL divergence against `fp16`, 8 prompts (code and prose, 1K-8K tokens). The noise floor is the same
|
||||
`fp16` path cut into 4096-token chunks instead of 8192: another summation order, same arithmetic.
|
||||
|
||||
| mode | KL mean | KL median | KL max | top-1 agreement | prefill, 4-8K prompts |
|
||||
|---|---|---|---|---|---|
|
||||
| noise floor | 0.00023 | 0.00003 | 0.0016 | 8/8 | - |
|
||||
| `w4a8` | 0.0018 | 0.0010 | 0.0096 | 8/8 | 2,503 tok/s |
|
||||
| `w4a4` | 0.0080 | 0.0027 | 0.040 | 7/8 | 2,904 tok/s |
|
||||
| `fp16` | reference | | | | 1,905 tok/s |
|
||||
|
||||
`w4a8` is the default. It is 4.5x closer to the reference than `w4a4`, at 86% of its speed, and it is the precision
|
||||
every generated token already runs at. `fp16` is the choice when the prompt must be read exactly.
|
||||
|
||||
`STRATA_DUMP_MOE_INPUT` + `mmq_nvfp4_parity --real` test one product on a real prompt's rows: layer 20, its 12
|
||||
busiest experts, max|x|/rms 4 median and 9 at most. The errors:
|
||||
|
||||
| mode | gate/up | down (heavier SwiGLU tails) |
|
||||
| --- | ---: | ---: |
|
||||
| `w4a8` | 0.46% | 0.90% |
|
||||
| `w4a4` | 7.2% | 8.4% |
|
||||
| `fp16` | 0.017% | 0.021% |
|
||||
|
||||
## CPU experts
|
||||
|
||||
`src/kernels/cpu/nvfp4_avx512.cpp` computes the CPU pool's NVFP4 rows in 512-bit lanes. Each 64-value block is
|
||||
decoded once for every token of a verify window: `vpdpbusd` on |E2M1| codes, with the sign moved onto the
|
||||
activation. The arithmetic is ggml-cpu's `ggml_vec_dot_nvfp4_q8_0`, with the float additions ordered differently
|
||||
(worst 4.5e-7 relative, `nvfp4_avx512_parity`). `STRATA_NO_NVFP4_512=1` falls back to ggml-cpu.
|
||||
|
||||
A CPU without AVX-512 (Zen 1-3, Intel Core 4th-10th and 12th-14th gen, Core Ultra, Xeon E5 v3/v4) runs the same rows in 256-bit lanes
|
||||
(`src/kernels/cpu/nvfp4_avx2.cpp`): ggml's AVX2 arithmetic step for step, so every row is bit-equal to ggml-cpu's
|
||||
(`nvfp4_cpu_parity`, 0 of 1280x9 / 2560x9 rows differ on a Ryzen 5 5600X, a Ryzen 7 255 and a Core Ultra 7 265).
|
||||
`STRATA_NO_NVFP4_256=1` falls back to ggml-cpu. An NVFP4 pack is a native pack (its folder holds `native_experts.txt`),
|
||||
so the engine starts on such a CPU; the AVX-512 requirement belongs to the canonical Q2_0 pack only (#2347: a `--pack`
|
||||
folder without `native_experts.txt` is read as that pack, and the engine now says so before it refuses).
|
||||
|
||||
| tokens | ggml-cpu | AVX-512 | speedup |
|
||||
|---|---|---|---|
|
||||
| 1 | 0.102 ms | 0.058 ms | 1.76x |
|
||||
| 4 | 0.410 ms | 0.125 ms | 3.29x |
|
||||
| 7 | 0.719 ms | 0.196 ms | 3.66x |
|
||||
|
||||
These are one expert's gate+up (1280 rows of 2560, cache-resident). The pool itself is bound by DRAM.
|
||||
|
||||
The pool in DRAM terms (`nvfp4_avx512_parity --bw THREADS TOKENS`: 1536 experts, 4.2 GB, GB/s of weights read; tokens = tokens an
|
||||
expert serves in one verify window, 1-2 in decode):
|
||||
|
||||
| CPU (threads) | kernel | 1 thread, 1 tok | all cores, 1 tok | 2 tok | 4 tok |
|
||||
|---|---|---|---|---|---|
|
||||
| Ryzen 7 255, Zen 4 (8) | AVX-512 | 15.4 | 58.6 | 57.6 | 47.7 |
|
||||
| | AVX2 rows | 13.9 | 58.9 | 58.1 | 42.1 |
|
||||
| | ggml-cpu | 12.6 | 58.7 | 44.8 | 22.4 |
|
||||
| Ryzen 5 5600X, Zen 3, DDR4-3200 (6) | AVX2 rows | 12.1 | 42.2 | 41.5 | 30.1 |
|
||||
| | ggml-cpu | 10.4 | 42.9 | 30.9 | 15.5 |
|
||||
| Core Ultra 7 265, DDR5-5600 (20) | AVX2 rows | 16.0 | 74.2 | 73.0 | 60.6 |
|
||||
| | ggml-cpu | 10.3 | 74.1 | 62.7 | 37.1 |
|
||||
|
||||
Without AVX-512 a core reads ~10% slower (13.9 vs 15.4 GB/s), but a pool that reads DRAM runs at the same rate up to two tokens a
|
||||
window and ~12% below at four. The CPU's memory decides, not its vector width.
|
||||
|
||||
## Other GPUs
|
||||
|
||||
Only the optional `w4a4` needs Blackwell. The default `w4a8` is ggml's int8 MMQ (sm_75 and up), and decode uses the
|
||||
engine's own q8_1 kernels, which decode UE4M3/E2M1 in software. The engine was built for sm_75/86/89 as PTX and run
|
||||
on the RTX 5090 with the host answering as that generation. On those builds `mmq_nvfp4_parity` and
|
||||
`nvfp4_expert_gpu_parity` gave results identical to sm_120.
|
||||
|
||||
HIP: the decode kernels use no CUDA-only intrinsics. The NVFP4 MMQ instance and the W4A8 unit are CUDA-only and
|
||||
guarded (`GGML_USE_HIP`). Neither was built for HIP here.
|
||||
|
||||
## Tests
|
||||
|
||||
- `nvfp4_expert_gpu_parity`: the decode kernels against ggml's reference.
|
||||
- `nvfp4_avx512_parity`: the CPU rows against ggml-cpu (with `--expert`: one whole expert).
|
||||
- `mmq_nvfp4_parity`: the prompt path's products against FP64 (with `--real`: rows dumped by `STRATA_DUMP_MOE_INPUT`).
|
||||
- `tools/nvfp4_verify.py` and `tools/nvfp4_verify_gguf.py`: the conversion, bit for bit.
|
||||
@@ -0,0 +1,91 @@
|
||||
# NVIDIA Tesla V100 / Titan V (Volta, sm_70): the community build
|
||||
|
||||
PolyStrata's ready-made engine and the support matrix start at compute capability 7.5 (RTX 20). A V100 (7.0) runs the same
|
||||
engine compiled for it, through the experimental build that issue #236 added. It is **community-tested, not part of the
|
||||
supported cards**: no ready-made engine is published for it and the numbers below come from one machine.
|
||||
|
||||
## Build
|
||||
|
||||
CUDA 13 dropped Volta, so the build needs a **CUDA 12.x** toolkit (12.8 was used) and a host GCC that toolkit accepts.
|
||||
|
||||
```sh
|
||||
cmake -S . -B build -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=OFF \
|
||||
-DCMAKE_CUDA_ARCHITECTURES=70 -DSTRATA_EXPERIMENTAL_SM60=ON
|
||||
cmake --build build --target strata -j
|
||||
```
|
||||
|
||||
Setup does the same by itself for a model on a V100 (the experimental CUDA 12 engine, in `engine-cuda12/`: ready-made
|
||||
on Windows, compiled with a CUDA 12.x toolkit on Linux; [OLDER_GPUS.md](OLDER_GPUS.md)). For a PC with a V100 and a newer card, a build for both architectures (`-DCMAKE_CUDA_ARCHITECTURES="70;86"`) is the
|
||||
natural choice (a community report in issue #509 ran an RTX 3080 beside a V100 that way; it was not repeated here). On the
|
||||
measuring PC a Quadro RTX 4000 (sm_75) sits beside the V100s and was hidden with `CUDA_VISIBLE_DEVICES` because the sm_70-only
|
||||
build has no code for it.
|
||||
|
||||
## What runs on Volta
|
||||
|
||||
The flag only lowers the floor (CMake and the runtime device check) and replaces two intrinsics Volta lacks. It does not
|
||||
select "old" kernels everywhere: which kernel runs is decided per architecture when the engine is built.
|
||||
|
||||
| Part of the prompt path | On sm_70 |
|
||||
| --- | --- |
|
||||
| MoE experts (ggml MMQ) | `dp4a` kernels (Volta has no int8 tensor cores) |
|
||||
| Dense projections (dequantized weights) | FP16 tensor-core GEMMs (cuBLAS / CUTLASS `s884`) |
|
||||
| BF16 projections (hyper-connection, router, indexer, ...) | converted to FP16 and run on the FP16 tensor cores (#655, #540; `STRATA_BF16_TC=0`: cuBLAS BF16, an FP32 SIMT kernel on Volta) |
|
||||
| QSA attention for decode and verify windows (and prompts with `STRATA_PROMPT_ATTN_OLD=1`) | #540's kernel (fewer shuffles, bit-exact; `STRATA_ATTN_PRE75=0`: the one other cards run) |
|
||||
| QSA prompt attention, int8 / FP16 / K8V4 KV | `prompt_attn_v70_kernel` on `mma.m8n8k4` (`STRATA_PROMPT_ATTN_OLD=1`: the decode kernel, one query at a time) |
|
||||
| QSA prompt attention, Q4_0 KV | the decode kernel |
|
||||
| QSA block scores | the warp kernel (the tensor-core scorer needs sm_80) |
|
||||
|
||||
| Part of a decode / verify window | On sm_70 |
|
||||
| --- | --- |
|
||||
| Routed experts in VRAM | gfx906's expert mode 8: the codebook grid and the group's activations in shared memory, SwiGLU fused (`STRATA_EXP_MODE=0`: the CUDA layout other cards run) |
|
||||
| Dense 2-4 column GEMVs and the head | the interleaved `native_mmvq_il` with a Volta rows table (`STRATA_MMVQ_IL=0`: `native_mmvq`) |
|
||||
| Hyper-connection read, up projection | gfx906's latency-hidden up kernel (`STRATA_GR_FAST=0`: the plain one) |
|
||||
|
||||
All three are bitwise the kernels they replace; on a V100-SXM2 they take a verify window's GPU work from 22.8 to 21.2 ms
|
||||
([bench/results/2026-10-07-v100-decode-kernels](../bench/results/2026-10-07-v100-decode-kernels/README.md)).
|
||||
|
||||
## Measured
|
||||
|
||||
One V100-PCIE-32GB, i9-7960X, Unsloth `UD-IQ4_XS` (not a setup model), int8 KV, MTP `--spec 2`; prompt read speed of random-word prompts, tokens/s,
|
||||
with and without the Volta attention kernel (`STRATA_PROMPT_ATTN_OLD=1`):
|
||||
|
||||
| Prompt tokens | old attention path | `prompt_attn_v70_kernel` |
|
||||
| --- | ---: | ---: |
|
||||
| 7,194 | 1,010 | 1,164 |
|
||||
| 28,650 | 1,063 | 1,251 |
|
||||
| 114,338 | 973 | 1,123 |
|
||||
|
||||
Decode was 38-51 tok/s in every run and is not affected. The profile, the parity numbers, the needle test and the limits are in
|
||||
[bench/results/2026-10-03-v100-prompt-attn](../bench/results/2026-10-03-v100-prompt-attn/README.md).
|
||||
|
||||
What the kernel does and does not guarantee: against an FP64 reference its error is about 2-3e-6 (output scale 3.6; the FP32 kernel it replaces: 2e-6; 5e-6 before the hi and lo halves got separate accumulator chains); 15 of 15
|
||||
needles were found; greedy output was identical on the 28,650- and 114,338-token prompts and differed late in the answer on the 7,194-token one (another
|
||||
summation order).
|
||||
|
||||
## Checking and benchmarking the Volta kernels
|
||||
|
||||
```sh
|
||||
cmake -S . -B build -DSTRATA_PARITY_PROMPT_ATTN=ON ... && cmake --build build --target qsa_prompt_attn_parity
|
||||
CUDA_VISIBLE_DEVICES=0 ./build/qsa_prompt_attn_parity 32768 2048 5 # synthetic, no model; exit 0 = PASS
|
||||
```
|
||||
|
||||
It compares the tensor-core attention with the FP32 kernel and an FP64 host reference and times both. The Q4_0 cases are skipped below
|
||||
sm_80.
|
||||
|
||||
## Limits
|
||||
|
||||
- A layer split over two V100 was not measured with this kernel. The cards work in turn on a single request, so a split adds expert-cache room, not prompt speed.
|
||||
- sm_60 (Pascal) is covered by the same flag, and community runs exist: two Tesla P40 with a layer split (#1028, bench
|
||||
[2026-10-05-community-2x-p40](../bench/results/2026-10-05-community-2x-p40/README.md)), a Tesla P100 alone and with an RTX 2070 SUPER as
|
||||
the expert-helper card (#1069: 30.5 tok/s alone, 35.8-38.4 with the helper), and a V100 + P100 pair (#1079: +6-11% decode from 0.1.39 to
|
||||
0.1.40 with the P100 as helper cache). One reporter's numbers each; this page's own kernel measurements are V100 only.
|
||||
- Volta's tensor cores take FP16 only: a model's BF16 weights are converted, and a weight outside FP16's range would saturate (none did in
|
||||
the check above).
|
||||
|
||||
## The decode kernels measured on a V100 (opt-in: `STRATA_SM70_TABLE=1`)
|
||||
|
||||
The interleaved 2-4 column matvec with a Volta rows table, expert mode 8 and the latency-hidden norm/up (bitwise the default
|
||||
kernels' output, GPU work per verify window 22.8 -> 21.2 ms on a V100-SXM2 in the contributor's measurement) are used on
|
||||
sm_70 only when `STRATA_SM70_TABLE=1` is set. They become the default once the contributor has confirmed them on a V100 with
|
||||
the 0.1.41 code. Without the variable sm_70 runs what 0.1.40.3 ran. The single switches (`STRATA_EXP_MODE`, `STRATA_MMVQ_IL`,
|
||||
`STRATA_GR_FAST`) still apply on top.
|
||||
@@ -0,0 +1,238 @@
|
||||
# Older GPUs (experimental)
|
||||
|
||||
PolyStrata's supported cards are NVIDIA RTX 20 / 30 / 40 / 50 and the AMD cards in [AMD_HIP.md](AMD_HIP.md). The cards
|
||||
below run through **opt-in, experimental** paths that community members wrote and measured on their own machines. The
|
||||
maintainers have none of these cards: each path is compile-checked and unit-tested here, and the ready-made engines
|
||||
and their output stay exactly as they were. Numbers are the reporters' own, on one machine each.
|
||||
|
||||
## Support matrix
|
||||
|
||||
### NVIDIA
|
||||
|
||||
| Cards | Compute capability | How it runs | What is different on it | Reported |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| Tesla P100 | 6.0 | the CUDA 12 engine | `__dp4a` emulated (bit-exact); BF16 projections through fp32 | 2x P100, IQ3_S, engine 0.1.39: prompt 526-532 tok/s, decode 28-32 tok/s at 128K prompt tokens, 3 of 3 needle checks at 122K ([report](../bench/results/2026-10-06-community-2x-p100/README.md), #1157) |
|
||||
| Tesla P40 / P4, GTX 10 series | 6.1 | the CUDA 12 engine | BF16 projections through fp32 (cuBLAS has no BF16 GEMM there, #395); the dense weights dequantized by a wide kernel, expert mode 8 and its own interleaved-matvec table; opt-in `STRATA_DENSE_F32=1`: the large dense GEMMs as `cublasSgemm` ([below](#tesla-p40-sm_61-what-was-measured-and-changed)) | P40, IQ3_S, engine 0.1.30: prompt 217-374 tok/s, decode 30-33 tok/s (#395); 0.1.43.1 with the sm_61 changes: prompt 255 tok/s at 565 tokens (was 205), decode 37-38 tok/s (was 34-35); with `STRATA_DENSE_F32=1` 464-474 tok/s at 7K tokens (was 360-432) |
|
||||
| Tesla V100, Titan V | 7.0 | the CUDA 12 engine | BF16 projections on the FP16 tensor cores (#655, #540); the prompt attention on `mma.m8n8k4` (#600); a leaner attention kernel (#540) | V100-PCIE-32GB, UD-IQ4_XS: prompt 1,123-1,251 tok/s (#600); V100 32GB, IQ2_XS: prompt +22% from #540 |
|
||||
| RTX 20 (Turing) | 7.5 | **supported**, the ready-made engine | opt-in: `STRATA_BF16_TC=1` runs the BF16 projections on the FP16 tensor cores | RTX 2080 Ti, Q2_0: prompt +15-18% (#655) |
|
||||
|
||||
A card needs enough VRAM to be useful: 12 GB or more is recommended, as for every card (a 2 GB GT 1030 is compute
|
||||
capability 6.1 too, and cannot hold any of the model).
|
||||
|
||||
### AMD
|
||||
|
||||
| Cards | Architecture | How it runs | Reported |
|
||||
| --- | --- | --- | --- |
|
||||
| RX 6800 / 6900 series | gfx1030 | setup (`--backend hip`), unvalidated; #540's attention kernel is the default there, with 8 cells per step and DPP lane exchanges (bit-exact; `STRATA_ATTN_PRE75=0` runs the standard kernel) | [AMD_HIP.md](AMD_HIP.md#rdna2-gfx1030); RX 6900 XT, IQ3_S: prompts +4-6% alone, +7-12% with #835 ([bench/results/2026-10-04-rdna2-pre75-attention](../bench/results/2026-10-04-rdna2-pre75-attention/README.md)) |
|
||||
| RX 6700 XT | gfx1031 | setup (`--backend hip`), unvalidated (#524) | used daily by its reporter, one card |
|
||||
| RX 5500 XT (RDNA1) | gfx1012 | built by hand: `-DCMAKE_HIP_ARCHITECTURES=gfx1012` (HIP 5.7 or 7) | 8 GB card, IQ3_S, 8K prompt: 15.3 tok/s decode (#442) |
|
||||
| RX 5700 XT (RDNA1) | gfx1010 | built by hand: `-DCMAKE_HIP_ARCHITECTURES=gfx1010`, on ROCm 7.14's `gfx101X-dgpu` wheels; needs `ROCR_VISIBLE_DEVICES=0` in a PC that also has an AMD iGPU | 8 GB card, Coder IQ1_M, 32K context: prompt 115 / 144 / 149 tok/s and decode 18.0 / 20.3 / 23.3 tok/s at 4K / 16K / 30K prompt tokens, 6 of 6 needle checks at 8K and 30K, 61 of 61 ctest on the card, 607 of 12,288 experts in VRAM |
|
||||
| RX 5700 and the 6 GB RX 5600 (RDNA1) | gfx1010 | as above | the same Navi 10 silicon as the RX 5700 XT, so the same build; a 6 GB card leaves ~50 expert slots, expect the RX 5500 XT's range, not this one's |
|
||||
| Radeon PRO V520 / Pro 5600M (RDNA1) | gfx1011 | built by hand: `-DCMAKE_HIP_ARCHITECTURES=gfx1011` | untested on hardware: it is the same RDNA1 ISA as gfx1010 (Navi 12), and the engine builds for it with 0 errors on the same wheels |
|
||||
| Instinct MI50 / MI60, Radeon VII | gfx906 (wave64) | built by hand: `-DSTRATA_HIP_GFX906=ON` | 2x MI50, Coder IQ1_M, 128K context: decode 50.1 / 47.8 / 45.7 tok/s at 4K / 32K / 128K prompt tokens, prompt ~520 tok/s (#677) |
|
||||
|
||||
## NVIDIA: the CUDA 12 engine
|
||||
|
||||
CUDA 13 dropped Pascal and Volta: it cannot compile for them. Setup therefore keeps a **second engine**, built with
|
||||
CUDA 12.9 and `-DSTRATA_EXPERIMENTAL_SM60=ON`, in its own folder (`engine-cuda12\`, beside `engine\`). One engine runs
|
||||
per model, so the choice is made per model, by the oldest card that model runs on:
|
||||
|
||||
- **Every card the model uses is RTX 20 or newer:** the ready-made CUDA 13 engine, as always.
|
||||
- **A card is Pascal or Volta:** the CUDA 12 engine. Setup says so (`CUDA 12: sm_70 is older than CUDA 13 supports
|
||||
...`). On Windows it downloads `strata-windows-x64-cuda12.zip` with NVIDIA's CUDA 12 libraries (from pip, like the
|
||||
CUDA 13 ones); on Linux, or with `--build`, it compiles the engine with a CUDA 12.x toolkit.
|
||||
|
||||
### Opting in
|
||||
|
||||
An older card is used only when you choose it; a PC with a newer card keeps recommending the newer one.
|
||||
|
||||
| You | Setup |
|
||||
| --- | --- |
|
||||
| have only Pascal / Volta NVIDIA cards (and no AMD card it can use) | uses them, with the CUDA 12 engine |
|
||||
| name the card: `START-HERE.bat --setup --gpu 1`, or `--gpus 0,1` with a newer card | uses it; the model gets the CUDA 12 engine |
|
||||
| `--cuda 12` (or `STRATA_CUDA=12`) | the CUDA 12 engine for this model, on any card |
|
||||
| `--cuda 13` | the CUDA 13 engine even with an older card (a warning: it has no code for that card) |
|
||||
| `STRATA_EXPERIMENTAL_SM60=1` | the older cards are listed as usable (the setting from #295 still works) |
|
||||
|
||||
The choice is kept in the model's config (`"cuda": 12`): its starts and `UPDATE.bat` keep it, and other models keep
|
||||
their own engine. Setting the model up again chooses again (by its cards; add `--cuda 12` to keep a forced choice). A Pascal / Volta card added to a model at a start (`--gpus`) moves that model to the
|
||||
CUDA 12 engine.
|
||||
|
||||
`--cuda 12` is also the way to run PolyStrata with an NVIDIA driver older than 580: CUDA 12 needs 528 or newer on Windows
|
||||
(527.41, NVIDIA's minor-version compatibility) and 525 on Linux; setup's "driver too old" stop says so. Such old
|
||||
drivers were not tested here.
|
||||
|
||||
### Mixed cards
|
||||
|
||||
A model that shares a V100 with an RTX 30 / 40 card runs both on the CUDA 12 engine (it has code for sm_60 to sm_89,
|
||||
plus PTX). An RTX 50 card (sm_120) in a CUDA 12 engine is a warning, not a stop: CUDA 12.8 and newer compile for it,
|
||||
but engines built with 12.8 crashed on long prompts there (#220, #224). Keep the RTX 50 card on its own model (`--gpu
|
||||
N`), where it runs the CUDA 13 engine.
|
||||
|
||||
### GLM 5.3 Flash, Qwen3.6, Ornith 1.5, Gemma 4 and Tiel Coder
|
||||
|
||||
These run on strata-poly, whose ready-made engine (Windows) is built with CUDA 13. With `--cuda 12` setup compiles
|
||||
strata-poly here instead, on Windows or Linux, with a CUDA 12.x toolkit (12.8 or newer for an RTX 50 card), and the
|
||||
image encoder with it. It goes in `engine-poly\` in place of the ready-made one, for every model of that engine; a
|
||||
later setup without `--cuda 12` takes the ready-made one back. #220 is the Qwen engine's prompt path and does not
|
||||
apply here: on an RTX 5090 with driver 570, strata-poly built with CUDA 12.8 read Tiel Coder's 31,516-token prompts
|
||||
at 6,200 to 6,700 tokens/s. On a Pascal or Volta card setup adds `-DSTRATA_EXPERIMENTAL_SM60=ON`; strata-poly
|
||||
compiles for sm_61 and sm_70 with CUDA 12.4 and 12.8. It has not run on such a card. Built as compute_61 PTX only and
|
||||
run on an RTX 3080, which takes the Pascal code paths, Qwen3.6's greedy answer matched llama.cpp's for 60 of 64
|
||||
tokens (the sm_86 build: 64) and differed after that by a near tie. On Windows, with CUDA 12.9 and Visual Studio's
|
||||
14.44 compiler, it builds for sm_61 and for sm_89; the sm_89 build wrote the same 200 tokens of Qwen3.6 UD-Q2_K_XL as
|
||||
the CUDA 13 one on an RTX 4070 Laptop GPU, at 95.6 tokens/s against 93.2.
|
||||
|
||||
### Building it yourself
|
||||
|
||||
```sh
|
||||
# Linux (Windows: the same with the toolkit's nvcc.exe)
|
||||
cmake -S . -B build-cuda12 -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=OFF -DSTRATA_EXPERIMENTAL_SM60=ON \
|
||||
-DCMAKE_CUDA_ARCHITECTURES="61;70" -DCMAKE_CUDA_COMPILER=/usr/local/cuda-12.9/bin/nvcc
|
||||
cmake --build build-cuda12 --target strata -j
|
||||
```
|
||||
|
||||
Setup does the same when it compiles: it looks for the newest CUDA 12.x toolkit (`STRATA_NVCC=<path to nvcc>` picks
|
||||
one, #601; on glibc 2.43 use 12.8, see [TROUBLESHOOTING.md](TROUBLESHOOTING.md)).
|
||||
|
||||
On GCC 12.3 with nvcc (openEuler 24.03, CUDA 12.8, 2x V100) the build needed `-D_BITS_OPT_RANDOM_H` added to the host flags (#1074; one
|
||||
report, not reproduced here). The `size_t` error in `vmm.hpp` that the same report hit is fixed in 0.1.40.2.
|
||||
|
||||
### What the flag changes, and what it does not
|
||||
|
||||
`-DSTRATA_EXPERIMENTAL_SM60=ON` lowers the runtime floor to compute capability 6.0 and compiles the older cards' code
|
||||
paths into that build only: the Volta prompt attention (#600), #540's attention kernel (used below sm_75), and the
|
||||
Pascal BF16 path. The ready-made CUDA 13 engine has none of them, so its kernels and its output are unchanged. The
|
||||
FP16 path for BF16 projections is in every build but runs by default only below sm_75; RTX 20 owners can try it with
|
||||
`STRATA_BF16_TC=1` (`=0` turns it off on a V100). It is not bitwise the same as cuBLAS's BF16 kernel (FP16 tensor-core
|
||||
sums round differently): #540 measured a mean KL of 8.4e-3 on the next-token distribution of 24 code prompts on a V100
|
||||
(the same top-1 in 23), the size of other summation-order changes; #655 a worst relative difference of 3.5e-5 per
|
||||
product on an RTX 2080 Ti.
|
||||
|
||||
A/B switches: `STRATA_DEQUANT_WIDE=0`, `STRATA_SM61_TABLE=0` (sm_61: the kernels 0.1.43.1 ran), `STRATA_DENSE_F32=1` (Pascal, opt-in),
|
||||
`STRATA_BF16_TC=0|1`, `STRATA_PROMPT_ATTN_OLD=1` (the decode kernel for prompts), `STRATA_ATTN_PRE75=0`
|
||||
(#540's kernel off; on gfx103x with HIP that kernel is the default, see the AMD table above, and `=1` turns it on for
|
||||
another wave32 AMD card). [NVIDIA_V100.md](NVIDIA_V100.md) has the V100 build, its measurements and the parity test.
|
||||
|
||||
### Tesla P40 (sm_61): what was measured and changed
|
||||
|
||||
One Tesla P40 24 GB in a 20-vCPU VM (Xeon E5-2695 v4, 98 GB RAM), CUDA 12.4 (cuBLAS 12.4.5.8), IQ3_S with MTP
|
||||
(`--spec 4`), int8 KV, `--max-context 262144`, engine 0.1.43.1; the numbers and every run are in
|
||||
[bench/results/2026-10-12-p40-sm61-kernels](../bench/results/2026-10-12-p40-sm61-kernels/README.md).
|
||||
`STRATA_PREFILL_TIMING=1`, `STRATA_DECODE_TIMING=1` and `STRATA_VERIFY_PROFILE=1` show a card that is the bottleneck
|
||||
everywhere: the prompt's GPU timeline equals its wall time (waiting for expert copies 0.2%, host grouping 0.2% of a
|
||||
7K-token prompt) and a decode window is 49 ms of GPU stages with 1-3 ms of CPU experts. Of a 7K-token prompt, 36% is
|
||||
the dense projections' GEMMs, 28% the experts (ggml's MMQ, which has its own Pascal dp4a configuration), 13% the
|
||||
hyper-connection read and 12% the attention.
|
||||
|
||||
Three things run differently on compute capability 6.1 by default and a fourth is opt-in. Each gives the same bits as
|
||||
what it replaces:
|
||||
|
||||
| Change | What it replaces | Measured on the P40 | Switch |
|
||||
| --- | --- | --- | --- |
|
||||
| Wide dequantization (a thread per 8 values, 16-bit loads, 16-byte stores) for Q4_K / Q5_K / Q6_K / IQ4_XS | a thread per 32 values with byte loads: 0.5 s of every prompt chunk, whatever its length | Q6_K 10240 x 2560: 7.2 -> 0.33 ms (10 -> 227 GB/s); Q4_K 5.2x, Q5_K 3.8x, IQ4_XS 3.6x; `dequant_wide_parity` 360 cases bitwise | on; `STRATA_DEQUANT_WIDE=0` |
|
||||
| Expert mode 8 for the experts in VRAM (decode and verify windows) | the CUDA layout | an 18-expert call at 2 tokens: IQ3_S 390 -> 255 us, IQ3_XXS 345 -> 252, IQ2_S 290 -> 238, IQ4_XS 328 -> 261; `native_expert_bench` bitwise | on; `STRATA_SM61_TABLE=0` (or `STRATA_EXP_MODE=0`) |
|
||||
| The interleaved small-batch matvec with a table measured on the P40 (`kIlRows_61`) | `native_mmvq` | IQ4_XS 2560 x 10240 at 2 columns 112 -> 65 us, Q6_K 12288 x 2560 at 4 columns 189 -> 127 us, the Q5_K head at 3 columns 2,545 -> 1,766 us; `mmvq_il_parity` bitwise | on; `STRATA_SM61_TABLE=0` (or `STRATA_MMVQ_IL=0`) |
|
||||
| The large dense GEMMs (qkv, query, gate, output projections) as `cublasSgemm` on FP32 copies of the FP16 operands | cuBLAS's FP16-operand kernels, which run at 4.3 TFLOPS instead of 7.6 for most chunk sizes (a 7K-token prompt reads in 16.3 or 19.5 s by its exact token count) | 8.4-9.8 TFLOPS at every size from 512 tokens; qkv at 7,041 tokens 85 -> 45 ms; `gemm_f32_parity` 5,201 chunk sizes bitwise | **opt-in**, `STRATA_DENSE_F32=1` |
|
||||
|
||||
The GEMM route is opt-in because its equality is a property of the cuBLAS build, not of the code: it was measured with
|
||||
cuBLAS 12.4.5.8 only. Run `gemm_f32_parity` (a build with `-DSTRATA_BUILD_TESTS=ON`; exit 0 = every size bitwise) with
|
||||
your toolkit's library before you set it.
|
||||
|
||||
Through the server, medians of 3 requests per run, two runs per build alternated, each run started with the card at
|
||||
65 C (see below). By default: a 565-token prompt 203 / 205 -> 256 / 255 tok/s, decode after it 35.0 / 34.2 -> 38.2 /
|
||||
37.2 tok/s, a 7,047-token prompt 1-3% faster at the same token count. With `STRATA_DENSE_F32=1` as well: the
|
||||
7,047-token prompt 430 / 364 -> 474 / 473 tok/s (the old build reads it at ~361 or ~431 tok/s depending on whether the
|
||||
chunk has more than 7,040 tokens; with the route every request read at 464-474), decode after it 32.1 / 33.4 -> 35.9 /
|
||||
34.0. With `STRATA_DEQUANT_WIDE=0 STRATA_SM61_TABLE=0` and the route off the new build measures as the old one (210 /
|
||||
365 tok/s, 33.3 tok/s).
|
||||
|
||||
Measured and **not** changed: the latency-hidden hyper-connection read (`STRATA_GR_FAST=1`) is slower on the P40 below
|
||||
5 tokens (82 -> 88 us at one); `STRATA_PREFILL_CPU_SHARE=auto` and `STRATA_ADAPT_OVERLAP=1` gave nothing.
|
||||
|
||||
Two things to know when measuring on such a card:
|
||||
|
||||
- **Temperature.** A P40 has no fan of its own. This one reaches 87-89 C in a few minutes of work; at 89 C the driver
|
||||
reports `SW Thermal Slowdown: Active` and the clock falls from 1,531 to ~1,300 MHz (`nvidia-smi -q -d PERFORMANCE`,
|
||||
`nvidia-smi --query-gpu=temperature.gpu,clocks.gr --format=csv -l 2`). Start every arm of an A/B at the same
|
||||
temperature, or the later arm loses.
|
||||
- **Greedy answers are not identical run to run on a CPU without AVX-512**, even with `--prompt-cache 0
|
||||
--adapt-swaps 0 --pcie-frac 0`: an expert computed on the CPU rounds differently for a lone token than in a window
|
||||
of several (`native_gu_mt_min`), and how many drafts a window holds depends on timing. Add `STRATA_IQ_MT_MIN=1`
|
||||
(and `STRATA_PREFILL_CPU_SHARE=0`, `STRATA_ROUTE_TAIL_SKIP=0`) to compare two builds' answers byte for byte.
|
||||
|
||||
### Quadro RTX 8000: measurements of existing switches
|
||||
|
||||
The Quadro RTX 8000 is Turing (sm_75): it has FP16 tensor cores, but no native BF16 or TF32 tensor cores. Two
|
||||
**existing, opt-in** CUDA switches are worth comparing on your own workload:
|
||||
|
||||
- `STRATA_BF16_TC=1` converts BF16 projection operands to FP16 and uses FP16 tensor cores with FP32 accumulation.
|
||||
The default on sm_75 is off; `=0` restores the cuBLAS BF16 path. The switch applies to 7.x cards, not the native
|
||||
BF16 path on sm_80 and newer. Conversion clamps finite values outside FP16's range to ±65504; small values and
|
||||
differently ordered sums can round differently.
|
||||
- `STRATA_SELECT_SIMT=1` uses the tiled FP32 QSA block scorer on the pre-sm_80 CUDA path instead of the default
|
||||
warp scorer. `=0` keeps the warp scorer. It does not enable TF32 on Turing, and its summation order differs.
|
||||
|
||||
The existing paths are in [gemm.cu](../src/prefill/gemm.cu) and [qsa_select.cu](../src/kernels/cuda/qsa_select.cu).
|
||||
|
||||
Set the environment before starting the engine, or set the switches in the model config's `env` object, then
|
||||
restart. For example, this config fragment opts into both (keep the config's other settings):
|
||||
|
||||
```json
|
||||
"env": {
|
||||
"STRATA_BF16_TC": "1",
|
||||
"STRATA_SELECT_SIMT": "1"
|
||||
}
|
||||
```
|
||||
|
||||
This section records an investigation, **not a new kernel or a change to defaults**. Measurements on 2026-10-07
|
||||
used one 48 GiB Quadro RTX 8000 (physical GPU 3), a 260 W power limit, a Xeon W-2295, CUDA 12.4 and GCC 13.
|
||||
The source-built engine was based on v0.1.40.3 with other local changes integrated; unrelated opt-in changes
|
||||
were disabled in these arms. These are not measurements of an otherwise clean documentation-only checkout,
|
||||
not results at the launcher's 200 W setting, and not a speed promise for every sm_75 card.
|
||||
|
||||
The model was IQ3_S with MTP (`--spec 4`), `--max-context 262144`, INT8 KV with `--kv-resident 32768`,
|
||||
`--pcie-frac 0.20`, a fixed `--expert-cache 19000` request and `--prefill auto` (8,192-token ceiling).
|
||||
The engine reported 21,189 cache slots including the prompt loan. Prompt caching and adaptive swaps were off
|
||||
(`--prompt-cache 0 --adapt-swaps 0`). Each size used three fresh, seeded synthetic prompts and 128 output tokens
|
||||
per request; the table gives median engine-reported rates, not end-to-end server latency.
|
||||
|
||||
| Existing switch settings | 537 tokens: prompt / decode tok/s | 4,057 tokens: prompt / decode tok/s | 32,057 tokens: prompt / decode tok/s |
|
||||
| --- | --- | --- | --- |
|
||||
| BF16_TC=0, SELECT_SIMT=0 | 493 / 86.8 | 1,055 / 79.9 | 1,135 / 70.6 |
|
||||
| BF16_TC=1, SELECT_SIMT=0 | 661 / 83.7 | 1,262 / 75.4 | 1,416 / 68.4 |
|
||||
| BF16_TC=1, SELECT_SIMT=1 | 679 / 87.1 | 1,290 / 78.2 | 1,501 / 71.6 |
|
||||
|
||||
BF16_TC improved prompt throughput by about 20–34%, but did not improve decode in these comparisons. Adding
|
||||
SELECT_SIMT improved the 32K prompt rate by about 6% over BF16_TC alone; this is not a universal decode win.
|
||||
BF16_TC changed replies in 3 of the 9 paired requests, so use it only if different rounding is acceptable.
|
||||
All five basic arithmetic/JSON checks passed in each arm, which is a smoke check, **not a model-quality study**.
|
||||
A separate synthetic QSA scorer check at 131,072 context tokens matched selected IDs for all 256 queries and
|
||||
passed its FP64 accuracy gate. That check does not prove identical selections on arbitrary prompts or model quality.
|
||||
|
||||
Two other existing tuning options did not justify a recommendation on this machine:
|
||||
|
||||
- `--prefill auto:16384`, with BF16_TC on and SELECT_SIMT off, increased the prompt's cache loan from 4.38 to
|
||||
7.38 GiB for only about 0.6% more 32K prompt throughput (1,425 versus 1,416 tok/s). Just 24 MiB of VRAM remained
|
||||
at the last graph capture. Keep the 8,192 ceiling rather than spend that memory margin for this small gain.
|
||||
- `STRATA_PREFILL_CPU_SHARE=auto` gave no gain at the two tested sizes (537 and 4,057 tokens): prompt rates were
|
||||
647 and 1,253 tok/s versus 661 and 1,262 with BF16_TC alone; decode was also lower. Larger prompts were not
|
||||
tested for this setting.
|
||||
|
||||
## AMD: building gfx906 and gfx1012
|
||||
|
||||
Setup does not build these; build by hand and run `serve/server.py` with a config, as on any other card.
|
||||
|
||||
- **gfx906** (MI50 / MI60 / Radeon VII, wave64): a separate opt-in build, `-DSTRATA_HIP_GFX906=ON
|
||||
-DCMAKE_HIP_ARCHITECTURES=gfx906` (not `STRATA_ENABLE_HIP`). Current ROCm no longer ships gfx906 libraries; the
|
||||
reporter used a community ROCm 7.14 image. Recipe, kernels and measurements: [AMD_HIP.md](AMD_HIP.md#gfx906-instinct-mi50--mi60-radeon-vii-wave64-built-from-source).
|
||||
- **gfx1012** (RX 5500 XT): the wave32 backend, `-DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1012`. HIP 5.7
|
||||
(Ubuntu's packages) works: older hipBLAS (0.x) is used through rocBLAS, the legacy HIP names and the missing
|
||||
`__syncwarp` are version-gated, and RDNA1's missing signed dot4 uses llama.cpp's SDWA sequence
|
||||
(`-DSTRATA_GFX1012_PORTABLE_DOT=ON`: the portable one).
|
||||
|
||||
## Reports welcome
|
||||
|
||||
These paths stay experimental until more people run them. A report with the card, the driver / ROCm version, the
|
||||
model and the engine log (`strata-<model>.log`) in an issue helps; [COMMUNITY_BENCHMARKS.md](COMMUNITY_BENCHMARKS.md)
|
||||
has the format for measurements.
|
||||
@@ -0,0 +1,96 @@
|
||||
# OrcaRouter IQ3_XXS compatibility
|
||||
|
||||
Validated on Linux with an RTX 5090 (32 GB), Ryzen 9 9950X3D and 128 GB RAM on 2026-09-27.
|
||||
|
||||
The target is `orcarouter/Qwen3.8-Flash-Next-Uncensored-GGUF`, **IQ3_XXS** (two shards, 85.20 GB total).
|
||||
It has PolyStrata's Qwen4Exp geometry, but ordinary quantization also compresses the hyperconnection,
|
||||
small attention and PLE projections which PolyStrata's kernels read as BF16.
|
||||
|
||||
`tools/iq_pack.py --compat-bf16` expands only those projections, rounding to BF16 using nearest-even.
|
||||
This adds rounding relative to the GGUF's dequantized weights; it does not recover the original BF16
|
||||
checkpoint or its quality. Expert weights, native attention weights, embeddings and the 28.8 GB PLE
|
||||
lookup table remain unchanged. The latter stays on disk. The pack records its conversions in
|
||||
`compat-bf16.json`.
|
||||
|
||||
The native loader retains this pack's converted PLE key. Its existing native Q2_0 key path remains
|
||||
available to the original model. Hugging Face snapshot symlinks are supported; all split shards must
|
||||
finish downloading before packing. Pass the snapshot filename, not its hash-named blob target.
|
||||
|
||||
## Preparation
|
||||
|
||||
Build PolyStrata normally using the pinned llama.cpp dependency. Python needs numpy, regex and gguf-py
|
||||
from that dependency (`STRATA_GGUF_PY` can point to its `gguf-py` directory).
|
||||
|
||||
```sh
|
||||
.venv/bin/python tools/iq_pack.py \
|
||||
--gguf /path/to/Qwen3.8-Flash-Next-Uncensored-IQ3_XXS-00001-of-00002.gguf \
|
||||
--out packs/orca-iq3_xxs --compat-bf16
|
||||
```
|
||||
|
||||
Use this model's own tokenizer exported into the pack. Do not share another model's `dense.bin`,
|
||||
and do not rename the Orca files to impersonate one of setup's GSQ-RCO models.
|
||||
|
||||
PolyStrata's persistent server also uses the MTP runtime (optional: without `--mtp` it drafts by lookup only), prepared by
|
||||
the existing tools:
|
||||
|
||||
```sh
|
||||
.venv/bin/python tools/mtp_fetch.py fetch --out mtp
|
||||
.venv/bin/python tools/mtp_pack.py --src mtp --experts q2_0 --out mtp/mtp-q2_0.gguf
|
||||
.venv/bin/python tools/mtp_rt.py --gguf mtp/mtp-q2_0.gguf --out mtp/rt
|
||||
cp data/draft_vocab.bin mtp/rt/draft_vocab.bin
|
||||
```
|
||||
|
||||
This uses the original model's draft head, as setup does for Swift. The target model verifies its
|
||||
proposals; draft acceptance and performance must be measured for this fine-tune.
|
||||
|
||||
## Local server
|
||||
|
||||
Save the following as `strata-orca-iq3_xxs.json` at the repository root, replacing both `/path/to/`
|
||||
entries with the **same first shard**. Orca's PLE table is in shard 1. Start with a 32K context and
|
||||
512-token prefill chunks; the expert cache sizes itself to available VRAM. The expert arena alone
|
||||
needs about 49.8 GiB of available system RAM, plus draft/runtime buffers and other applications.
|
||||
|
||||
```json
|
||||
{
|
||||
"exe": "build/strata",
|
||||
"args": [
|
||||
"--pack", "packs/orca-iq3_xxs",
|
||||
"--native", "/path/to/Qwen3.8-Flash-Next-Uncensored-IQ3_XXS-00001-of-00002.gguf",
|
||||
"--ple-gguf", "/path/to/Qwen3.8-Flash-Next-Uncensored-IQ3_XXS-00001-of-00002.gguf",
|
||||
"--expert-profile", "data/expert-profile.bin", "--expert-cache", "auto",
|
||||
"--prefill", "512", "--spec", "4", "--spec-min-p", "0.5",
|
||||
"--mtp", "mtp/rt", "--max-context", "32768", "--kv", "int8"
|
||||
],
|
||||
"cwd": ".",
|
||||
"tokenizer": "packs/orca-iq3_xxs/tokenizer",
|
||||
"model_name": "orcarouter-qwen3.8-flash-next-uncensored-iq3_xxs",
|
||||
"log": "strata-orca-iq3_xxs.log",
|
||||
"host": "127.0.0.1",
|
||||
"port": 8080
|
||||
}
|
||||
```
|
||||
|
||||
Run from the repository root:
|
||||
|
||||
```sh
|
||||
.venv/bin/python -m serve.server --engine strata --config strata-orca-iq3_xxs.json --port 8080
|
||||
```
|
||||
|
||||
The web interface is at `http://127.0.0.1:8080`; API clients use `http://127.0.0.1:8080/v1`.
|
||||
Vision is not configured in this text-only example. Performance of the original GSQ-RCO model
|
||||
does not establish this fine-tune's speed or accuracy.
|
||||
|
||||
## Scope and validation
|
||||
|
||||
- IQ3_XXS is the target of this change; other Orca quantizations are not validated.
|
||||
- IQ3_M additionally uses Q5_0 expert down matrices, which the native GPU expert path does not support.
|
||||
- The installer model menu is unchanged. This is an explicit local packing workflow.
|
||||
- Focused conversion and split-file tests: `.venv/bin/python -m unittest discover -s tools -p test_iq_pack.py`.
|
||||
- All eight packing tests, 17 server tests and the GPU gated-residual parity check passed.
|
||||
- The complete model packed successfully: 460 tensors converted, 1.39 GiB of converted BF16 weights;
|
||||
1.43 GiB total packed dense weights. The 48 expert layers remain IQ3_XXS gate/up and IQ4_NL down.
|
||||
- Real server checks passed: arithmetic, Python code, translation, a longer explanation, multi-turn context
|
||||
reuse (25 prompt tokens reused), streaming cancellation and a subsequent correct response. The engine
|
||||
PID stayed unchanged. These are smoke tests, not a quality benchmark or a full-context stress test.
|
||||
- With the configuration above, a 111-token explanation generated at 77.7 tokens/s (engine decode timing);
|
||||
total request time was 1.77 seconds. This single short measurement is not a general throughput claim.
|
||||
@@ -0,0 +1,36 @@
|
||||
# OrcaRouter Uncensored Q4_K_S (manual setup)
|
||||
|
||||
This path uses the three original `orcarouter/Qwen3.8-Flash-Next-Uncensored-GGUF` Q4_K_S shards without rewriting their expert, embedding or PLE table bytes. It is separate from the installer model menu. Keep all three shard filenames together.
|
||||
|
||||
The ordinary GGUF quantizes some small projections which PolyStrata reads as BF16. `--compat-bf16` dequantizes and rounds those projections to BF16 in the separate pack; it does not restore their original precision. The Q5_0 PLE table remains in the source GGUF and currently uses the mapped reader (`--ple-io mmap`). The Q4_K gate/up experts and Q5_0/Q5_1 down experts remain in GGUF form, including layers whose three tensors cross shard boundaries (each role is read from its own shard). The GPU expert kernels take Q4_K with Q5_1 (or Q8_0) downs; Q5_0 downs are not among them yet, and the engine refuses to start on a pack with such a layer (it names the layer).
|
||||
|
||||
## Build and prepare
|
||||
|
||||
Build PolyStrata with CUDA, native experts, `STRATA_ORCA_Q4KS_MMQ=ON` (and `STRATA_BUILD_TESTS=ON` for the two parity programs below). This opt-in compiles the Q5_0 GGML MMQ instance for CUDA or HIP (the Q4_K and Q5_1 instances come with the engine's K-quant MMQ build on CUDA); the usual Q8_0 draft-layer instance remains in both builds. HIP also needs `STRATA_PREFILL_MMQ=ON`. Select your card's compute capability, for example `89` on an L40S. On Windows with Ninja and CUDA 12.6, use the Visual Studio developer environment and `-DCMAKE_CUDA_RUNTIME_LIBRARY=Shared` to keep the CUDA runtime linkage consistent. The default pinned ggml checkout is supported by the project build.
|
||||
|
||||
```sh
|
||||
cmake -S . -B build -G Ninja -DSTRATA_ENABLE_CUDA=ON -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_ORCA_Q4KS_MMQ=ON -DCMAKE_CUDA_ARCHITECTURES=89 -DCMAKE_CUDA_RUNTIME_LIBRARY=Shared -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build build --target strata native_expert_parity ple_q5_parity
|
||||
python tools/iq_pack.py --gguf /models/Qwen3.8-Flash-Next-Uncensored-Q4_K_S-00001-of-00003.gguf --out packs/orca-q4_k_s --compat-bf16
|
||||
```
|
||||
|
||||
`iq_pack.py` needs NumPy and the `gguf-py` module from the pinned llama.cpp dependency (`STRATA_GGUF_PY` can point to that directory). It writes a roughly 1.43 GiB dense pack and a native-expert manifest. The original 112 GB of model shards are read in place; `experts.bin` is optional and is not written by this command.
|
||||
|
||||
Check the changed kernels against the real files before starting the service:
|
||||
|
||||
```sh
|
||||
build/native_expert_parity /models/Qwen3.8-Flash-Next-Uncensored-Q4_K_S-00001-of-00003.gguf /models/Qwen3.8-Flash-Next-Uncensored-Q4_K_S-00002-of-00003.gguf /models/Qwen3.8-Flash-Next-Uncensored-Q4_K_S-00003-of-00003.gguf 0 5 6 20 47
|
||||
build/ple_q5_parity /models/Qwen3.8-Flash-Next-Uncensored-Q4_K_S-00001-of-00003.gguf
|
||||
```
|
||||
|
||||
## Engine flags
|
||||
|
||||
Pass the same first shard to `--native` and `--ple-gguf`; PolyStrata discovers the other two shards by name. For a first text-only run, use 32K context and a modest cache. Once that passes, increase the context and cache with memory measurements on the target machine.
|
||||
|
||||
```sh
|
||||
--pack packs/orca-q4_k_s --native /models/Qwen3.8-Flash-Next-Uncensored-Q4_K_S-00001-of-00003.gguf --ple-gguf /models/Qwen3.8-Flash-Next-Uncensored-Q4_K_S-00001-of-00003.gguf --ple-io mmap --expert-profile data/expert-profile.bin --expert-cache auto --prefill 512 --spec 4 --mtp /path/to/mtp/rt --max-context 32768 --kv int8
|
||||
```
|
||||
|
||||
For two GPUs in persistent server mode, add `--layer-split auto --split-device 1` (with CUDA0 and CUDA1 visible). The usual PolyStrata MTP runtime is built from the original model's draft layer; draft acceptance on the Uncensored fine-tune must be measured. Keep this model's own tokenizer from the pack. `--expert-cache-per-layer` on a native pack gives every layer the same number of slots, each the size of that layer's own blob. `--expert-cache N` is still the budget of N largest blobs.
|
||||
|
||||
This port does not claim that Q4_K_S beats llama.cpp on a given computer. Compare the same model bytes, prompt, context, output length and GPU load; report prefill and decode separately.
|
||||
@@ -1,475 +0,0 @@
|
||||
# Plan: UnbiasedStrata on Qwen3.6-35B-A3B, any single NVIDIA card from Pascal up, 256K context
|
||||
|
||||
Written 2026-10-11, revised the same day three times: after reading
|
||||
[Project Maya](https://github.com/mw00/project-maya); after the target widened from one card to a range;
|
||||
after the llama.cpp-backend fallback was removed. Status: proposed, nothing started.
|
||||
|
||||
Engine base: this repository's Strata snapshot (`6f32ec0`, engine 0.1.39). Maya is a method reference only.
|
||||
llama.cpp appears in two roles only: the external speed baseline (bare `llama-server`, never inside the
|
||||
binary) and the numerical oracle for parity. There is no fallback path.
|
||||
|
||||
## 0. Target and what "adapt" means
|
||||
|
||||
**Target:** one NVIDIA GPU, compute capability 6.1 or newer (GTX 10 series through RTX 50), **6 GB to 32 GB**
|
||||
of VRAM, Linux, x86-64 with AVX2. The engine sizes itself at start: fixed weights first, then the KV cache
|
||||
for the requested context, then every remaining byte of VRAM becomes expert-cache slots. The same binary
|
||||
and the same model files on every card; only speed differs. Q4 is the default quant. Context 262,144 where
|
||||
it fits, never below 131,072 without saying so. **Multi-GPU is out of scope**; the front end already
|
||||
refuses `--gpus`, and that stays.
|
||||
|
||||
The Strata engine in `src/` runs one architecture, Qwen3.8-Flash-Next (`qwen4_exp_text`). Qwen3.6-35B-A3B
|
||||
(`qwen3_5_moe_text`) is the same family one generation earlier, with the extras removed. From the two
|
||||
models' `config.json`:
|
||||
|
||||
| | Qwen3.8-Flash-Next (what the engine runs) | Qwen3.6-35B-A3B (the target) |
|
||||
| --- | --- | --- |
|
||||
| Hidden / layers | 2560 / 48 | 2048 / 40 |
|
||||
| Layer pattern | 3 linear attention then 1 full attention (`full_attention_interval` 4) | the same |
|
||||
| Linear attention (GDN) | 16 k-heads, 48 v-heads, 128-dim, conv 4 | 16 k-heads, **32** v-heads, 128-dim, conv 4 |
|
||||
| Full attention | 24 heads, 2 KV heads, head_dim 256, partial rotary 0.25, output gate, **plus a sparse indexer (QSA)** | 16 heads, 2 KV heads, head_dim 256, partial rotary 0.25, output gate, **dense** |
|
||||
| MoE | 512 experts, top-10, intermediate 640, shared 640 | 256 experts, top-8, intermediate 512, shared 512 |
|
||||
| Residual | hyper-connections (`hc` 4 streams) | plain residual |
|
||||
| PLE / n-gram table | yes (28.8 GB shard 2) | none |
|
||||
| MTP | 1 draft layer | 1 draft layer |
|
||||
| Vocabulary | 248,320 | 248,320, the same tokenizer |
|
||||
| Context | 262K | 262K native |
|
||||
|
||||
Everything Qwen3.6 has, the engine has a kernel for; what it lacks, the engine treats as optional (PLE) or
|
||||
needs a bypass for (hyper-connections, the QSA indexer). Maya's port study (`docs/GLM5-FLASH.md` in that
|
||||
repo) crossed a larger *kernel* gap for GLM-5.3-Flash in about a week: study 2026-09-29, verified
|
||||
streaming runner 2026-10-01, v1.0.0 on 2026-10-07. The Qwen3.6 kernel gap is smaller (no MLA, no sparse
|
||||
indexer to write, no manifold hyper-connections, a SiLU-for-sigmoid change in the GDN gate). The
|
||||
*plumbing* gap is not small: `docs/qwen36-port/geometry-inventory.md` (154 rows, 2026-10-11) shows the
|
||||
hc = 4 gated residual and the QSA indexer assumed structurally in every block, the output head, the
|
||||
verify window, the MTP drafter and prefill; prefill refusing any geometry but 2560/4/320/top-10; native
|
||||
packs decoding only through the verify window; and `ModelGeometry` reading only the expert counts and
|
||||
rope keys from the file. Expect Maya-scale work, with the risk in plumbing rather than kernels.
|
||||
|
||||
**The deliverable:** this tree's engine running Qwen3.6-35B-A3B natively, by Maya's method, behind the
|
||||
existing front end (`frontend/`: OpenAI API, tokenizer, chat template, tool-call parser, vision), which is
|
||||
model-agnostic and stays. The payoff is what llama.cpp's `--n-cpu-moe` cannot do: hot experts cached in
|
||||
VRAM by usage across all layers, the CPU computing the misses concurrently with the GPU, instead of whole
|
||||
layers' experts on the CPU serially. On a 6 GB card that is the difference between a cache holding the
|
||||
hottest 7% of experts and a layer cut holding none.
|
||||
|
||||
Hypotheses:
|
||||
|
||||
- **H1.** Under llama.cpp `--n-cpu-moe N` the GPU is idle most of each decode step, and the idle share
|
||||
grows with N, so it is worst on the smallest cards. (The baseline sweep measures it.)
|
||||
- **H2.** The idle is CPU expert matmul, not PCIe transfer.
|
||||
- **H3.** 256K context fits at Q4 on every card of 11 GB or more; 128K fits on 8 GB; 6 GB at Q4 holds
|
||||
the 256K fixed set only when prefill borrows cache slots, else it takes 131K or the IQ3 file, and the
|
||||
engine must say which it chose.
|
||||
- **H4.** Qwen3.6's routing is skewed enough that a VRAM expert cache serves well above its slot fraction
|
||||
of routes at every budget from 6 GB up. The replay measures the whole curve before any CUDA.
|
||||
- **H5.** The ported engine's decode scales as `1 / max(cpu, gpu)` rather than `1 / (cpu + gpu)`, and beats
|
||||
the llama.cpp baseline at every VRAM budget, by the most at the small end.
|
||||
- **H6.** With 12 GiB of RAM beside the 1080 Ti, Q4 reaches the disk tier and the profile-ranked VRAM
|
||||
and RAM tiers keep disk reads under one expert per token on a warm conversation; IQ3 never reaches the
|
||||
disk. The replay with three tiers predicts this; the engine's tier counters confirm it.
|
||||
|
||||
H4 and H5 are not a go/no-go for building the engine; the port is the deliverable regardless. They decide
|
||||
how the README describes the result and where the expert-cache tuning effort goes.
|
||||
|
||||
**Measured on 2026-10-11 (Phase 0; details in `~/Code/regina/analysis/qwen36-35b-single-gpu-ladder/`):**
|
||||
|
||||
| | Q4_K_XL at 11 GB | IQ3_XXS at 11 GB |
|
||||
| --- | --- | --- |
|
||||
| llama.cpp, 256K, fit edge (`--n-cpu-moe` 32 / 18), smoke test, cold cache, 400 tokens | 8.8 tok/s decode, 129 prefill, GPU busy 15% | 24.6 tok/s decode, 434 prefill, GPU busy 41% |
|
||||
| llama.cpp, the sweep (warm, 1,200 tokens, `baseline-1080ti.md`) | **the number to beat: N = 30, the lowest N that fits (10,415 MiB): 13.4 tok/s decode on the regina request, 16.3 on the short one.** At N = 32: 13.5 / 12.2, 152 prefill; nvprof at N = 32: busy 13.8%, memcpy 0.6%, gaps 86%; warm nvprof at N = 30: busy 15.0%, memcpy 0.6%, 3.1 MiB of activations per token over PCIe; 14 to 21 MiB per token from disk | 33.5 tok/s decode, 907 prefill; GPU busy 56% (nvidia-smi); warm nvprof at N = 20: busy 24.8% under a 2.1x profiler slowdown, memcpy 0.8%; no disk reads |
|
||||
| Sweep slope | 0.67 to 0.93 points of GPU busy and 0.5 to 0.7 tok/s per layer moved to the CPU (the N = 32 point was the first run and carried steal) | one point and 0.58 tok/s per layer |
|
||||
| Route trace, top 40% of experts per layer | 76% of routes (215K routed tokens) | |
|
||||
| Replay at the censused sizes, LFU with 3 spares per layer, prefill borrowing cache slots | 78 slots per layer: 83.2% hit, 36.6 RAM and 17.0 disk reads per token | 149 slots: 95.4% hit, 14.6 RAM and 0 disk reads |
|
||||
| Replay, no borrowing (prompt buffer held in VRAM) | 52 slots: 72.2% hit, 35.8 disk reads | 103 slots: 89.4% hit, 0 disk reads |
|
||||
| Predicted decode, overlap / serial (gpu 17 ms, CPU lane 0.15 ms per expert, disk 1.3 ms; parameters, not measurements), borrowing | 36.2 / 22.4 tok/s | 58.8 / 52.1 tok/s |
|
||||
|
||||
Readings: H1 holds (the GPU idles 86% of each Q4 step by the kernel timeline, 44% at IQ3). H2 holds (memcpy is 0.6% of the window; the idle is CPU matmul and, at Q4, page-ins). H4 holds (83% hit from 35% of the
|
||||
experts). With 12 GiB of RAM the Q4 arm is disk-limited (17 disk reads per token, about 22 ms, more than
|
||||
the whole GPU step), so on this rung IQ3 is the quant that reaches the GPU ceiling and Q4 needs either
|
||||
16 GiB of RAM or 12 GB of VRAM. Prefill borrowing cache slots is worth 11 points of hit rate at Q4. Prefill hit rates are linear in slots (a prompt touches nearly every
|
||||
expert per layer per ubatch), so prompts stream experts over PCIe, as Strata already does. The overlap
|
||||
column saturates at `1000 / gpu_ms`; the GPU step itself is the next thing to measure properly (nvprof,
|
||||
in the sweep).
|
||||
|
||||
## 1. The card ladder
|
||||
|
||||
Real cards in the homelab cover the range, with Pascal at three sizes:
|
||||
|
||||
| Budget | Card | Where | Arch | Role |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 6 GB | GTX 1060 | g7 (192.168.50.185), laptop | sm_61 | the floor; regina's `g7/README.md` has llama.cpp numbers here already |
|
||||
| 8 GB | GTX 1070 Ti | host .4 (`llama-qwen36-35b-mtp.service`, live) | sm_61 | second Pascal point |
|
||||
| 11 GB | GTX 1080 Ti | .57 at PCI `2a:00`, in **VM 211 `gpu-qwen36`** at 192.168.50.43 (cloned from 210 on 2026-10-11: 8 vCPU, 12 GiB, 100 GB on `local-lvm`, Debian 13, driver 550, CUDA 12.4, gcc-13) | sm_61 | the primary measurement card, and the development card until a pod is rented |
|
||||
| 32 GB, rented | A6000 or similar on RunPod | on demand; this fork was already checked on a RunPod 3090 container (README) | sm_86 | only for the 32 GB rung and if the 4090 becomes busy again; the user has approved spending on this |
|
||||
| 24 GB | RTX 4090 | VM 221 (192.168.50.151) on pve2: 16 vCPU, 62 GB RAM, CUDA 12.4, driver 550; root disk nearly full (build trees under `/models/work`, 174 GB free); system gcc is 14, so builds need gcc-13 as the host compiler | sm_89 | **idle since 2026-10-11 17:20, the user's call: the fast-compile development card for Phase 2 steps 3 to 5 and the 24 GB rung.** Both llama-server units there are inactive; leave them so. No RunPod needed while it stays free |
|
||||
| 12, 16, 32 GB | RTX A6000 (48 GB) **capped** | VM 220 (192.168.50.8) on .57 | sm_86 | **in use by another agent**; the emulated rungs wait for it |
|
||||
|
||||
The cap is Maya's `STRATA_GLM_VRAM_GB` idea: the engine limits its own total VRAM so the expert pool gets
|
||||
what a card of that size would leave it. It is built in Phase 2 step 2; the 1080 Ti emulates the 6 and 8 GB
|
||||
rungs with it (the real 1060 and 1070 Ti then check launch failures, FP16 paths and PCIe), and the A6000
|
||||
emulates 12, 16 and 32 GB whenever it is free.
|
||||
|
||||
Consequence of the 1080 Ti being the only local card: **the Pascal build comes first, not last.** Every
|
||||
parity harness and the streaming runner are brought up under `STRATA_EXPERIMENTAL_SM60=ON` on sm_61 from
|
||||
the start, so Pascal surprises surface in the first week. The rented sm_86 pod runs the same harnesses in
|
||||
parallel for fast iteration; a kernel passes when it passes on both.
|
||||
|
||||
Constraints across the ladder:
|
||||
|
||||
| | |
|
||||
| --- | --- |
|
||||
| CUDA | one toolkit that compiles sm_61 and sm_120 both: **CUDA 12.8** (12.x is the last with Pascal; 13 dropped it). Upstream saw RTX 50 crashes with 12.8-built engines (issues #220, #224), so RTX 50 is "built, not measured" until a card exists here. Fat binary `CUDA_ARCHS=61;70;75;86;89;120` |
|
||||
| Pascal specifics | dp4a exists on sm_61 (not sm_60, which gets the shim); no tensor cores; no `__nanosleep`; FP16 math at 1/64 rate on GP102/GP104/GP106, so every kernel's *arithmetic* on these cards must be FP32 or dp4a int8 (fp16 *storage* with conversion, as in the KV pools and prefill's stores, is full rate and stays); the prompt MoE's dp4a MMQ path must be enabled on sm_61. Strata refuses sm < 75 unless `STRATA_EXPERIMENTAL_SM60=ON`; that flag becomes the default build (Phase 2, step 6). Nobody has run this engine on Pascal; Maya requires Volta or newer |
|
||||
| Build verification | `cuobjdump --list-elf \| grep sm_` after every build; two past incidents here were wrong-arch binaries |
|
||||
| Profilers | current Nsight Systems: Turing and newer only. Nsight Compute: no Pascal since 2019.5. On Pascal use the `nsys` bundled with CUDA 12.x (2023.x) or `nvprof`; on Turing and newer current `nsys`. Same analysis script either way |
|
||||
| .57 host | Ryzen 7 1700 (Zen 1, AVX2, no AVX-512), 62 GiB usable DDR4-2133. Checked 2026-10-11: VM 220 shrunk to 36 GiB by another agent, host 18 GiB available before VM 211, about 6 GiB after. The 1080 Ti's link is **Gen3 x8** (`LnkSta: 8GT/s, Width x8`), so the June Gen1 problem is gone. VM 220 shares the memory bandwidth and the 8 physical cores (VM 220 has 12 vCPU, VM 211 has 8: oversubscribed when both are busy), so each run's metadata records VM 220's load and measurement windows prefer its idle hours |
|
||||
| Stale pointer | `docs/NEW-GPU-VM.md` says "both GTX 1080 Ti"; slot 29:00 now holds the A6000 |
|
||||
|
||||
## 2. Models, the memory hierarchy, and the budget table the engine must reproduce at start
|
||||
|
||||
**Decision 2026-10-13 (step 5, the user):** the hierarchy is two tiers, VRAM plus host RAM, assumed to hold the
|
||||
expert set; spilling to the NVMe is out of scope. Measured on the 1080 Ti at Q4_K_XL: 52 tok/s with the set
|
||||
pinned in the VM's 35 GB, 12 to 15 tok/s under a 12 GiB bound (disk-bound, the replay's prediction; llama.cpp
|
||||
13.4). The README states the RAM a card needs per quantization; the 12 GiB rows below are kept as the measured
|
||||
cost of breaking the assumption, not as a supported rung. H6 and the disk-read instruments are therefore
|
||||
informational.
|
||||
|
||||
**The hierarchy on the primary rung is three tiers, by the user's decision:** 11 GB of VRAM in the 1080 Ti,
|
||||
about 12 GiB of VM RAM (roughly 9 to 10 GB usable for a pinned expert tier after the OS, the process and
|
||||
the KV), then the VM's NVMe disk for the rest. Strata already has the pieces: the VRAM expert cache, the
|
||||
pinned RAM tier, and the low-RAM modes (`--mmap-experts` serving misses from the model file through the
|
||||
page cache; `--resident-experts` copying exactly the non-VRAM experts into RAM when they fit). At Q4 they
|
||||
do not all fit in 12 GiB, so the mapped mode and the disk are in play; at IQ3_XXS the whole expert set fits
|
||||
VRAM plus RAM. Every per-budget number below is therefore a pair: where the experts live, and how many
|
||||
reads per token reach the disk.
|
||||
|
||||
| Arm | File | Size | Where it already is |
|
||||
| --- | --- | --- | --- |
|
||||
| **Q4, default** | `Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf` (unsloth, repo commit `a483e9e`) | ~21 GB | not on hand; download once on the Mac, SHA-256 against the repo, copy over LAN |
|
||||
| Q4 + MTP | `Qwen3.6-35B-A3B-UD-Q4_K_M-MTP.gguf` | 22.66 GB | `.4:/mnt/models/qwen3.6/MTP/`, Mac `~/models/qwen3.6/MTP/` |
|
||||
| Q3 | `Qwen3.6-35B-A3B-UD-IQ3_XXS.gguf` | 13.21 GB | `.4`, `.151:/models`, g7 `/home/rk/models` |
|
||||
|
||||
K-quants for the default because most experts run on the CPU on most of the ladder, and K-quant dot
|
||||
products are the fast AVX2 path. The engine needs the MTP block: Strata's draft protocol is built around
|
||||
the model's own MTP layer. Settled on 2026-10-11: the `Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf` from unsloth's MTP
|
||||
repository (rev 5bc3e238) already carries the draft block as `blk.40` (753 tensors), so it is the default
|
||||
file, and its `blk.40` serves as the draft pack for the IQ3 arm too (the plain IQ3 file has no draft block).
|
||||
|
||||
Fixed VRAM before any expert slot. Measured and censused on 2026-10-11; the authoritative table is
|
||||
`docs/QWEN36-35B-A3B.md` section 4.1, summarized:
|
||||
|
||||
| Item | Q4_K_XL | IQ3_XXS |
|
||||
| --- | --- | --- |
|
||||
| Non-expert weights on the GPU | 2,038 MiB | 1,597 MiB |
|
||||
| Draft block (dense 40 MiB + its experts + ring KV + logits) | ~520 MiB | ~520 MiB (the Q4 file's) |
|
||||
| KV, q4_0, 10 attention layers, 262K | 1,440 MiB | 1,440 MiB |
|
||||
| Session, CUDA context, reserve | ~0.7 to 1.2 GB | same |
|
||||
| Prompt buffers | 0 when prefill borrows cache slots (a profile exists); 1,904 MiB at chunk 2048 otherwise | 0 / 1,878 MiB |
|
||||
| **Decode-time fixed set at 262K** | **~4.8 GB borrowing, ~6.7 without** | **~4.3 / ~6.2** |
|
||||
| Trunk experts, total / per expert (mean, max) | 18,726 MiB / 1.83 MiB, 2.20 max | 10,594 MiB / 1.04 MiB, 1.17 max |
|
||||
|
||||
What each budget leaves for experts at Q4, 262K (the llama.cpp layer cut on the right is the baseline's
|
||||
equivalent, for the comparison only):
|
||||
|
||||
| Budget | Q4 expert slots in VRAM, prefill borrowing (of 10,240) | IQ3 slots | `--n-cpu-moe` equivalent |
|
||||
| --- | --- | --- | --- |
|
||||
| 6 GB | ~525 (5%); without borrowing the fixed set does not fit at 262K, so 131K or the IQ3 file | ~1,350 (13%) | 40 (all) |
|
||||
| 8 GB | ~1,570 (15%) | ~3,200 (31%) | ~37 |
|
||||
| 11 GB (the 1080 Ti, 11,264 MiB), 12 GiB RAM, NVMe | ~3,550 (35%) in VRAM; ~4,950 (48%) pinned in RAM; ~1,740 (17%) on disk | ~6,700 (66%) in VRAM, the rest in RAM, no disk tier | ~32 (llama.cpp's CPU experts at Q4 exceed 12 GiB, so its baseline on this rung is page-cache bound too) |
|
||||
| 12 GB | ~3,650 (36%) | ~6,880 (67%) | ~31 |
|
||||
| 16 GB | ~5,740 (56%) | all | ~26 |
|
||||
| 24 GB | all, ~1 GB spare | all | 0 |
|
||||
| 32 GB | all; the spare VRAM goes to f16 KV or a bigger prompt chunk | all | 0 |
|
||||
|
||||
The sizing rule the engine implements (Phase 2, step 2): take the fixed total for the requested context;
|
||||
if it does not fit, lower the context toward 131,072, then refuse with the exact numbers and the IQ3 file's
|
||||
name. **KV streaming is not a lever for this model**: Strata streams by resolving the *selected* cells, and
|
||||
dense attention selects every cell (study, 3.3 item 6), so the KV stays in VRAM. Never silently pick a
|
||||
shorter context. Then the RAM tier: free RAM minus a headroom for the OS and the KV
|
||||
stream, filled with the next experts by profile rank; whatever remains stays mapped from the GGUF on disk
|
||||
and is read on a miss. The start-up log states all three counts.
|
||||
|
||||
CPU-side ceiling for the misses: ~12 MiB of expert weight per CPU-computed layer-token at Q4. On the .57
|
||||
host (DDR4-2133, ~30 GB/s) that is ~60 to 70 tok/s before compute; Zen 1's 8 cores will be the lower
|
||||
bound. Prior Pascal data: GTX 1060 6 GB, IQ3_XXS, N = 32: 16 tok/s at 8K depth, 11 at 32K, 355 tok/s
|
||||
prefill, all llama.cpp.
|
||||
|
||||
## 3. Phase 0: environment, baseline, and the replay
|
||||
|
||||
Human steps (Proxmox state is the user's):
|
||||
|
||||
1. (Decided: VM 220 stays up; host RAM already freed for a 12 GiB VM.)
|
||||
2. (Done 2026-10-11.) VM 211 `gpu-qwen36`, a full clone of VM 210: **8 vCPU, 12 GiB RAM, balloon 0,
|
||||
100 GB on `local-lvm` (NVMe)**, `--hostpci0 0000:2a:00,pcie=1`. No `rombar=0`: that was needed only
|
||||
for the boot-VGA card at 29:00 (homelab ticket 002); the 1080 Ti at 2a:00 never needed it. VM 220
|
||||
keeps running. The disk is the third tier, so `fio` its read throughput and 4K random latency once,
|
||||
into `phase0-notes.md`.
|
||||
3. Inside the VM: pin the kernel/driver pair, install `build-essential cmake nvtop linux-perf`, CUDA 12.8
|
||||
(the template has 12.4; 12.8 needs a 570-series driver, still a Pascal-capable branch), confirm
|
||||
`nvidia-smi`, check `LnkSta`, set `perf_event_paranoid` to 1.
|
||||
4. Copy the GGUFs over LAN; `sha256sum` each.
|
||||
|
||||
Agent steps (fresh sonnet agent; brief = this section plus the hosts):
|
||||
|
||||
5. Build bare `llama-server` at the submodule's pinned commit `3cf0325`, `-DGGML_CUDA=ON`, arches
|
||||
`61;86;89`, static; verify with `cuobjdump`. Also the latest release (v0.6.0) for its MTP arm. One
|
||||
build per rung, each verified for its own arch. This binary is the baseline and the oracle, nothing
|
||||
else.
|
||||
6. Profiler check on the 1080 Ti: CUDA 12.x `nsys status -e`, a 10-second `nsys profile -t cuda` of
|
||||
`llama-bench`, `nvprof --print-gpu-trace` as fallback. Record which works.
|
||||
7. Smoke test at 256K on the 1080 Ti with `llama-server`: `-ngl 99 --n-cpu-moe 32 -fa on -c 262144
|
||||
-ctk q4_0 -ctv q4_0 -b 2048 -ub 2048 --parallel 1 --cache-ram 0 -lv 4 -t 8`. Save the `-lv 4` buffer
|
||||
lines; they replace the estimates in Section 2.
|
||||
|
||||
**The baseline sweep (sonnet to drive, haiku to monitor).** Regina's harness (`scripts/sweep_ncpumoe.py`,
|
||||
`plot_ncpumoe_sweep.py`): the N sweep with VRAM (`nvidia-smi` and `-lv 4`), host RAM (`RssFile`), prefill
|
||||
and decode from `timings`, one real launch per point. One env spec per card; the A6000 budgets via
|
||||
`CUDA_VISIBLE_DEVICES` plus a side process holding the surplus VRAM. Regina's hygiene: 30 s settle, drop
|
||||
caches, warmup discarded, `--cache-ram 0`, `--parallel 1`. Workload per point: the Opus system prompt
|
||||
(~27K tokens) + "implement Minesweeper", `n_predict 800`, plus one 3K-prefill / 1200-decode request.
|
||||
Reasoning off, `temp 0`, `seed 42`.
|
||||
|
||||
Instruments, logged per run (the same three serve the engine later):
|
||||
|
||||
- **Level 0, always:** `nvidia-smi --query-gpu=timestamp,utilization.gpu,memory.used,power.draw
|
||||
--format=csv -lms 100`. `utilization.gpu` is the GPU-busy share at 100 ms resolution. nvtop in a tmux
|
||||
pane is for the human, not the record.
|
||||
- **Level 1, per point:** a decode-phase kernel timeline (`nsys` or `nvprof`). A script computes busy
|
||||
fraction, gap histogram, memcpy vs kernel share (the H2 test), per-token period, profiler overhead.
|
||||
- **Level 2:** `perf stat` on the server PID, so gaps match CPU time in ggml matmul threads.
|
||||
- **Timeline videos, prefill and decode (added 2026-10-13, the user's standing requirement).** For the
|
||||
engine and for llama.cpp, on the 1080 Ti and the 4090, a real-time video of the request's timeline in the
|
||||
style of `~/projects/ub-strata/strata.mp4`: lanes for CPU cores used (100 ms per-core `/proc/stat`
|
||||
samples), GPU kernels, PCIe H2D / D2H bytes and GPU copy / idle, a playhead, the engine-reported tok/s
|
||||
on completion, and the busy fraction stated both with and without the engine's host-wait spin kernel.
|
||||
Two windows per point: the **prefill** of a long prompt (the regina request's 3.1K prompt, and a 32K
|
||||
prompt where the budget allows) and the **decode** of the short request. Stacked engine-over-llama.cpp
|
||||
comparisons at the fit edges. The traces come from the same nsys / nvprof captures as Level 1, so the
|
||||
profiled request must cover the prefill as well as the decode. Pipeline: `scripts/decode_video_json.py`,
|
||||
`scripts/decode_video_render.swift`, `scripts/render_decode_videos.sh` in regina (adapted from
|
||||
`~/Code/strata-workspace/strata-investigation`); output under
|
||||
`analysis/qwen36-35b-single-gpu-ladder/video/` with a README carrying the method's honesty statements.
|
||||
|
||||
| # | Where | Arm | N values | ctx | Question |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| B1 | 1080 Ti | Q4 | fit edge, +2, +4, +8, 40 | 262144 | H1, H3 on the primary card; with 12 GiB of RAM the CPU experts page from disk, so `RssFile` and disk reads are recorded per point |
|
||||
| B1b | 1060, 1070 Ti, 4090, A6000 at 12/16/32 | Q4 | the fit edge for that budget, and 40 | 262144, or 131072 where 262K does not fit | the baseline row of the ladder table |
|
||||
| B2 | 1080 Ti | Q4 | fixed N | 262144 | depth 8K, 32K, 128K |
|
||||
| B3 | 1080 Ti, 1060 | Q3 | fit edge, +4, +8, 40 | 262144 | K-quant vs i-quant CPU cost; the 6 GB default |
|
||||
| B4 | 1080 Ti | Q4 + MTP | fixed N | 262144 | multi-token verify on CPU experts (llama.cpp's MTP) |
|
||||
|
||||
B1, B1b and B3 are the baseline. B2 and B4 run when a card is idle. File-based drivers under `tmux`,
|
||||
`DRIVER_DONE` markers. B1 takes 2 to 4 hours at 256K context.
|
||||
|
||||
**E0, the route trace and cache replay (sonnet agent; any GPU host, even the Mac).** From Maya; it
|
||||
answers H4 for the whole ladder before any CUDA and it produces the expert profile the engine loads:
|
||||
|
||||
8. Record routes: a small patch to llama.cpp's `examples/eval-callback` writing one line per token and MoE
|
||||
layer with the 8 selected expert ids (`ffn_moe_topk`). Corpus: regina's coding tasks, the Opus system
|
||||
prompt, a few long chats; ~200K routed tokens.
|
||||
9. Replay: adapt Maya's `tools/glm_tier_replay.py` (MIT; models LFU residents + spares + the CPU-lane
|
||||
pick) to 40 layers × 256 experts **and three tiers** (VRAM slots, RAM slots, disk), and sweep the VRAM
|
||||
slot count from 0 to 10,240 landing on each budget from Section 2, at Q4 and IQ3, with the RAM tier
|
||||
fixed at what 12 GiB leaves. Policies: LFU, LRU, Belady ceiling.
|
||||
10. Output: `phase0-replay.md` with VRAM hits, RAM hits and disk reads per token **vs slots**, the seven
|
||||
budgets marked, and the predicted engine decode ceiling per budget against the baseline, using the
|
||||
measured disk latency from step 2 for the disk term. The trace also seeds `expert-profile.bin`.
|
||||
|
||||
Exit criteria: the baseline ladder row with the 1080 Ti's full N sweep; a working profiler on Pascal; the
|
||||
hit-rate curve with the budgets marked; Section 2's estimates replaced by measured buffer sizes.
|
||||
|
||||
## 4. Phase 1: images and the baseline write-up
|
||||
|
||||
Under `~/Code/regina/analysis/qwen36-35b-single-gpu-ladder/`:
|
||||
|
||||
1. `gpu-busy-vs-N.png`: Level-1 busy fraction and Level-0 utilization vs N on the 1080 Ti, both arms. H1.
|
||||
2. `timeline-N<k>.png`: a 200 ms strip of one decode step, kernels vs memcpys vs gaps. H2.
|
||||
3. `ladder-baseline.png`: decode and prefill vs VRAM budget (6, 8, 11, 12, 16, 24, 32), llama.cpp at the
|
||||
fit edge. The engine's points go on the same axes in Phase 2 step 5. The headline image.
|
||||
4. `vram-vs-N.png`: VRAM vs N with the budget lines and the 262K/131K KV points.
|
||||
5. `dmon-strip-N<k>.png`: the raw 100 ms trace over prefill then decode.
|
||||
6. `replay-hitrate-vs-slots.png`: hit rate vs slots per policy, budgets marked. H4.
|
||||
|
||||
Analysis reads the PNGs and CSVs. The write-up answers with numbers: busy fraction and its slope in N;
|
||||
memcpy vs gap; the default quant per budget; the baseline ladder row; the simulated hit rate per budget
|
||||
and the predicted engine gain, largest-to-smallest card. A fresh agent reviews it, given the data but not
|
||||
the conclusion. This write-up is what the engine must beat; it does not decide whether the engine is built.
|
||||
|
||||
## 5. Phase 2: the engine port, Maya's recipe on a smaller gap
|
||||
|
||||
The design document for this phase is `docs/QWEN36-35B-A3B.md` (2026-10-11): the model exactly from the
|
||||
real GGUF's metadata, the component-by-component gap analysis with file:line citations, the memory plan
|
||||
with the censused fixed set, the ladder, the envelope, the execution plan with effort weights (step 2
|
||||
15%, step 3 45%, step 4 20%, step 5 10%, step 6 5%, step 7 5%) and the risks. Where it and this plan
|
||||
differed, the plan was corrected to the study on 2026-10-11 (its section 8 lists the eight points).
|
||||
|
||||
Where: step 2 on VM 211 (the 1080 Ti, the Pascal build from the first step, Section 1). From step 3 on,
|
||||
kernel work and parity iterate on the 4090 in VM 221 (sm_89, idle since 2026-10-11) and every kernel
|
||||
also passes on the 1080 Ti before its step closes; the 4090 is also the 24 GB rung for step 5. Each step has a parity harness in Strata's negative-test discipline (every wrong reading must
|
||||
differ materially before the right one is judged), as Maya's section 6 did. Steps 1 to 4 need no GPU time
|
||||
beyond seconds of parity runs, so they proceed while the Phase 0 sweeps hold the cards.
|
||||
|
||||
1. **Oracle and fixture (sonnet, no GPU).** Found on 2026-10-11 (`docs/qwen36-port/upstream-tooling.md`):
|
||||
upstream never published its Python oracles (`ref/` holds only `load.py`; `gdn.py`, `moe.py`,
|
||||
`qsa.py`, `docs/semantics.md` are cited but absent), most parity tests carry a host C++ reference
|
||||
inside the test file, two embed generated `.inc` vectors, and the ggml-oracle tests link a llama.cpp
|
||||
build through `STRATA_ORACLE_SOURCE_DIR`. So: `tools/` and `tests/` restored from the import commit `12a7825`
|
||||
(done, commit c00942d: development tooling only, the binary still needs no Python), then write `ref/qwen36.py` new on `ref/load.py`, following the submodule's
|
||||
`qwen35moe.cpp` graph with dumps named by its `cb()` calls; `tools/qwen36_synth_gguf.py` from
|
||||
`test_iq_pack.py`'s `write_gguf()`; invariant tests (top-8 renormalization, GDN state shapes, the
|
||||
output gate). Cross-check with the submodule's `llama-eval-callback` on the same synthetic GGUF.
|
||||
One model difference already known: Flash-Next's GDN output norm gates with sigmoid(z), `qwen35moe`
|
||||
with SiLU(z); `gdn.cu` and `gdn_parity` encode the sigmoid reading, so that is the first negative
|
||||
test. `make_profile.py` hardcodes 48 layers and 512 experts; the MTP tools hardcode Flash-Next tensor
|
||||
names; `iq_pack.py`'s `FORM` table has no `qwen35moe` entry. Dependencies: numpy, regex, gguf-py; no
|
||||
torch, no GPU.
|
||||
**Done 2026-10-11 on branch `qwen36-oracle`** (commits 9630539, f1ef81d, 0c850c3, 2094992, unmerged):
|
||||
the oracle matches llama.cpp's own graph on 2,155 comparisons across 14 cases (max abs error 1.1e-4,
|
||||
identical top-k everywhere, the nextn block included); seven rival readings each fail; 21 invariant
|
||||
tests (24 after review). Independent review: no blockers; the GQA fixture (4 query heads over 2 KV
|
||||
heads) added after review and matching on every seam; `ref/load.py`'s dequant bit-identical to ggml's
|
||||
for Q6_K, IQ2_S, IQ3_XXS and IQ4_XS. **Tolerance policy** (`docs/qwen36-port/oracle-crosscheck.md`):
|
||||
the oracle has a Q8 activation mode (`--act-quant q8`) and a per-layer protocol (`--force-topk`,
|
||||
`--force-inputs`) that starts each layer from llama.cpp's inputs; against that, the per-seam relative
|
||||
spread on the real file is 5e-8 (norm), 7e-7 (qkv), 8e-5 (gdn_out), 1.1e-4 (attn_out), 2.3e-3
|
||||
(moe_out), 4e-7 (logits). Those are the kernel parity tolerances. Without forcing, errors compound
|
||||
5 to 30 times and about half the top-k slots flip, so exact top-k agreement stays an F32-fixture-only
|
||||
test. Branch commits after review: e452c51, 0e5344d, 44b0619. Real-file facts the engine
|
||||
needs: the plain GGUF has no nextn block (only the `-MTP` files do, as block 40); nothing is fused;
|
||||
the router, `ssm_alpha`, `ssm_beta` are F32; down experts are IQ3_XXS in 37 layers and IQ4_XS in
|
||||
layers 34, 38, 39; the untied 2048 × 248,320 head is Q6_K.
|
||||
2. **Geometry, metadata, sizing (default model).** Per the inventory: `ModelGeometry` is a set of
|
||||
Flash-Next defaults; only `qwen4exp.expert_count`, `expert_used_count` and the rope keys are read, and
|
||||
`check_architecture` rejects anything but `qwen4exp`. So: read every field of `ModelGeometry` from
|
||||
the `qwen35moe.*` keys (hidden, layers, head counts, `ssm.*`, `n_ff`, interval); add `hc = 1` as "no
|
||||
gated residual" with a plain-residual path and the `attn_norm` / `post_attention_norm` /
|
||||
`output_norm` tensors the engine never references today; fix the one leak in the native expert path
|
||||
(`expert_layout.cpp:284` passes compile-time 2560/640 to `native_fmt`); make `--ple-gguf` optional at
|
||||
the command line (the kernels already allow no PLE); refuse llama.cpp's fused `ffn_gate_up_exps` and
|
||||
`attn_qkv` forms by name (no shipped Qwen3.6 file uses them; the oracle's fused cases document the
|
||||
layouts if one appears); the draft geometry follows the target; the draft vocab size comes from the
|
||||
pack. The per-layer prefetch hints already exist (`FileExpertSource::warm`, `MADV_WILLNEED` on
|
||||
predicted ids): verify they fire on the Qwen3.6 pack's offsets rather than porting Maya's. **The VRAM planner:** free VRAM minus the fixed set for the requested
|
||||
context; KV streaming engaged when the fixed set does not fit (`--kv-resident`); the context lowered
|
||||
toward 131,072 only after that; a refusal with numbers below it; the remainder becomes expert slots;
|
||||
then the RAM tier from free RAM minus headroom (`--resident-experts` machinery), the rest mapped
|
||||
from disk (the existing `--mmap-experts` source with its `MADV_WILLNEED` warm); `--vram-cap` and
|
||||
`--ram-cap` for emulation. This step is what makes "6 GB to 32 GB" one binary, and it is where the
|
||||
engine's tier counters (VRAM, RAM, disk reads per token) are exposed in the log and on `/health`.
|
||||
3. **Kernels and the block (default model).** In order of risk, each with a parity harness:
|
||||
- the GDN mixer: head pairing `h % h_k` already handles 32 v-heads against 16 k-heads; the gate
|
||||
changes from sigmoid(z) to SiLU(z) in four kernels (`gdn.cu`, `fused_gdn.cu`,
|
||||
`native_gdn_preprocess.cu`, the prefill GDN kernels), with the sigmoid reading as the negative test;
|
||||
- the full-attention layer as *dense* attention: the decode kernel reads KV through an index list and
|
||||
does not care how the list was built, so a "select every cell" producer replaces the indexer; the
|
||||
kernels fixed at 12 query heads per KV head (Qwen3.6 has 8) and the short-context kernel fixed at
|
||||
24 heads become parameters; the prompt path is `qsa_prompt_attn.cu` (on Pascal, the batched decode
|
||||
kernel), parameterized the same way; `native_flash_attn.cu` is a 256-cell diagnostic adapter, not a
|
||||
fallback;
|
||||
- the router at top-8 over 256 (generic already; parity at the selection boundary) and the shared
|
||||
expert at 512 (its Q8_K rule needs a multiple of 256, which 512 satisfies);
|
||||
- the block without hyper-connections: `layer.cpp` *and* `verify.cpp`, because native packs decode
|
||||
only through the verify window, and that window requires the fused hc kernels (fixed at
|
||||
2560/4/320), top-10 and the native indexer today;
|
||||
- prefill: `Prefill::init` refuses anything but 2560/4/320/10 and its GDN, split-q, route and MoE
|
||||
kernels carry literals (48 v-heads, 24 heads, 1280, 640, top-10); parameterize or fork them.
|
||||
Then the layer composition test: one GDN+MoE and one attention+MoE layer against the oracle's dumps.
|
||||
The canonical Q2_0 CPU expert kernel bakes Flash-Next's shapes; Qwen3.6 rides the native pack path
|
||||
(per-layer runtime geometry, ggml dot products, Unsloth's Q4_K/Q5_K types already included), as the
|
||||
Coder with its 256 experts per layer does.
|
||||
4. **Pack and runner.** `iq_pack.py` taught `qwen35moe` and its BF16-preserve list; the MTP head: the
|
||||
engine's drafter reads its own Q8_0 directory with vLLM-style names, canonical Q2_0 experts at
|
||||
2560/640 and the default geometry, and Qwen3.6's single `nextn.eh_proj` over the concatenated
|
||||
embedding and hidden state does not match the two separate projections it expects, so the drafter
|
||||
needs a Qwen3.6 pack format and a small graph change (Maya's `mtp_gguf.py` is the model);
|
||||
`make_profile.py` (hardcoded 48 × 512 today) from the E0 trace;
|
||||
the streaming runner held to the oracle at every position of a short sequence; then the real Q4 file
|
||||
end to end, greedy, compared with llama.cpp's output distribution (not token-for-token; the README's
|
||||
known-problems entry says why).
|
||||
5. **Serve and measure on the 1080 Ti at 11 GB, then capped to 8 and 6; the 12, 16, 24 and 32 rungs when a card frees up.** CPU lane and PCIe
|
||||
share calibrated as Maya's `--calibrate` does, against this engine's own session; the Phase 0
|
||||
harness and instruments; the engine's points onto `ladder-baseline.png`. The H5 measurement. The
|
||||
front end's `make test-chat-parser MODEL=<gguf>` against Qwen3.6's template (the homelab services
|
||||
use a patched `qwen3.6-enhanced.jinja`); the Qwen3-Coder any-argument-order patch checked for
|
||||
misfires on this model's tool-call grammar.
|
||||
6. **The other Pascal cards and the fat binary.** The sm_61 build has been the working build since step
|
||||
1; this step makes `STRATA_EXPERIMENTAL_SM60=ON` the default for the fat binary
|
||||
(`CUDA_ARCHS=61;70;75;86;89;120`, CUDA 12.8) and runs the 1070 Ti and the 1060 against B1b. The
|
||||
sm_75+ paths (tensor-core prompt attention, thread-block clusters) stay compiled in for the cards that
|
||||
have them and are checked on the 4090 or A6000 when one is free.
|
||||
7. **README/UPSTREAM.** The supported model and its checksums, the ladder table with the engine against
|
||||
the baseline, the sizing rule in words, the Pascal caveats (CUDA 12.x, FP32 paths, no Nsight Compute).
|
||||
|
||||
**The base is this repository's `src/` and `include/`: Strata at `6f32ec0`, engine 0.1.39.** Maya's engine
|
||||
is not merged, cherry-picked or vendored: it forked from Strata around engine 0.1.27 and has rewritten the
|
||||
expert tiers, the mixers and the server since, so its C++ does not apply to this tree without a port of its
|
||||
own. Taken from Maya (MIT, by reference to a pinned commit): the method and the Python-side tooling; the
|
||||
list of places Strata's geometry was hardcoded, each re-found and fixed here; the route-log format,
|
||||
`glm_tier_replay.py` and `glm_expert_prior.py` adapted as standalone scripts; the VRAM cap and the
|
||||
CPU-lane calibration as *designs*, implemented against this engine. Left out: the Python installer, the
|
||||
dashboard, the Anthropic API, all multi-GPU work. One binary, no Python at run time, no network, one GPU.
|
||||
|
||||
## 6. Acceptance
|
||||
|
||||
Per budget, at the default quant, the engine must meet:
|
||||
|
||||
| Criterion | Threshold | Basis |
|
||||
| --- | --- | --- |
|
||||
| A1 context | 262,144 on 11 GB and up; 131,072 on 8 GB; on 6 GB whichever the sizing rule picks, stated at start | the stated goal and floor |
|
||||
| A2 decode | beats the baseline's fit-edge decode on the same rung; absolute floors ≥ 15 tok/s at 8K depth and ≥ 10 at 32K on 11 GB, ≥ 10 / 7 on 6 GB, ≥ 60 / 45 on 24 GB | the 1060 did 16/11 at IQ3 under llama.cpp; the 4090 did 100+ |
|
||||
| A3 prefill | ≥ 300 tok/s on Pascal, ≥ 2,000 on Ada | the 1060 did 355 |
|
||||
| A4 stability | 7 consecutive requests, no OOM, ≥ 100 MiB VRAM headroom | g7's "+78 MiB per request" |
|
||||
| A5 serving | chat, streaming, reasoning, tool calls and images through the front end, pi writing and running a program through it, on the 1060, the 1080 Ti and the 4090 with no flags but the model | the README's existing status bar |
|
||||
|
||||
If A2's "beats the baseline" fails on a rung after the cache tuning of step 5, the README reports the
|
||||
rung's numbers against the baseline as they are. The engine still ships for that rung; the comparison is
|
||||
the honest part of the result, not a gate.
|
||||
|
||||
## 7. Agents: who does what, and how cheaply
|
||||
|
||||
Rules:
|
||||
|
||||
- `ark` is human-only. If a phase should run under ark, the plan says so and the user starts it.
|
||||
- One fresh agent per phase boundary, briefed with this file, the phase section, the hosts, the run
|
||||
directory, and the previous phase's write-up (not its transcript).
|
||||
- Fork (same context) only to continue an in-progress phase after a wakeup.
|
||||
- Nothing an agent runs changes Proxmox state. Agents do not touch the live `.4` service except by
|
||||
starting a second server on another port with the production unit stopped, and restoring it.
|
||||
- Unattended sweeps: a file-based driver under tmux, polled on a `/loop` or wakeup every 15 to 30
|
||||
minutes, `DRIVER_DONE` markers.
|
||||
|
||||
Tiering:
|
||||
|
||||
| Work | Model | Why |
|
||||
| --- | --- | --- |
|
||||
| `-lv 4` logs to CSV; `dmon.csv` parsing; nsys/nvprof export to busy-fraction and gap histograms; checksums; marker checks; replay runs at given slot counts; B1b single points on a card with a ready script | **haiku** | mechanical, re-runnable |
|
||||
| Env specs, drivers, plots; llama.cpp builds per arch; the eval-callback route-dump patch; the replay adaptation; the oracle and synthetic fixture (Phase 2 step 1) | **sonnet** | code with a known shape and an example to copy |
|
||||
| The Phase 1 write-up; geometry, the VRAM planner, kernels, pack, runner, the Pascal build (Phase 2 steps 2 to 7); diff review before the user ships | **default (Fable)** | judgment and engine code |
|
||||
| Independent review of the Phase 1 write-up and of each parity harness before it is trusted | fresh **default** agent, given data but not the conclusion | an agent handed a hypothesis tends to confirm it |
|
||||
|
||||
Safe parallelism: the 1080 Ti sweep, the B1b points on the other cards, E0 on the Mac, and Phase 2 steps
|
||||
1 to 4 on the A6000 are independent of each other. If the user wants a multi-agent fan-out for Phase 2,
|
||||
they say "use a workflow".
|
||||
|
||||
## 8. Order of work and checkpoints
|
||||
|
||||
1. User: VM 220 decision; the 1080 Ti VM; GGUFs copied to every rung.
|
||||
2. Agent (sonnet): `llama-server` builds per arch, profiler check, smoke test → `phase0-notes.md`.
|
||||
**Checkpoint: the first `-lv 4` table on the 1080 Ti; Section 2's estimates replaced.**
|
||||
3. Agent (sonnet, then haiku): E0 → `phase0-replay.md` and the expert profile. **Checkpoint: the hit-rate
|
||||
curve with the seven budgets marked.** In parallel, Phase 2 step 1 on the Mac.
|
||||
4. Agents: B1 on the 1080 Ti; B1b on the 1060, 1070 Ti, 4090 and capped A6000; B3. **Checkpoint: the
|
||||
baseline ladder row.** In parallel, Phase 2 steps 2 to 4 on the A6000.
|
||||
5. Agent (default): plots and the baseline write-up; separate reviewer. **Checkpoint: the number to beat
|
||||
on every rung.**
|
||||
6. Agent (default): Phase 2 step 5 across the capped budgets. **Checkpoint: the engine's points on the
|
||||
ladder plot against the baseline, and pi served through the front end on the 4090.**
|
||||
7. Agent (default): step 6 on the three Pascal cards. **Checkpoint: `unbiased-strata --model <gguf>`
|
||||
serving pi on the 1060 and the 1080 Ti with no flags but the model; A1 to A5 on every rung.**
|
||||
8. Step 7, the README. B2 and B4 whenever a card is idle.
|
||||
|
||||
Measurements land in `~/Code/regina/analysis/qwen36-35b-single-gpu-ladder/`, infra notes in
|
||||
`~/homelab/investigations/<date>-vm-1080ti-qwen36.md` with a LOG.md entry, the model-support outcome and
|
||||
the ladder table in this repo's README, and the port study in `docs/QWEN36-35B-A3B.md`. Tickets: one
|
||||
`homelab` for the VM, one `regina` for the harness, one `UnbiasedStrata`-prefixed ticket per Phase 2
|
||||
step, filed when the work starts.
|
||||
@@ -0,0 +1,170 @@
|
||||
# Lend the output head's VRAM to the prompt path (`--prefill-head-alias`, opt-in)
|
||||
|
||||
Two large VRAM users never work at the same time. The native output head (417 MiB for the Q5_K head of
|
||||
IQ3_XXS) turns the last hidden state into logits, so it is needed only while tokens are generated. The batched prompt
|
||||
path's buffers are needed only while a prompt is read. With `--prefill-head-alias` the engine takes turns: the head's
|
||||
VRAM holds prompt buffers while a prompt is read, and the head is read back in before the first generated token.
|
||||
|
||||
The flag is off by default. With it off, the engine does exactly what it did before.
|
||||
|
||||
## Why
|
||||
|
||||
On an 8 GB card the prompt chunk is as large as the free VRAM allows, and prefill speed follows the chunk closely. Here
|
||||
is the same 29,854-token prompt with a fresh engine per trial and one request each. The card and settings are listed
|
||||
under [Measurements](#measurements).
|
||||
|
||||
| Prompt chunk | Trials | Prefill, median (range) | How the engine got there | Free VRAM after start |
|
||||
|---:|---:|---:|---|---:|
|
||||
| 256 | 4 | 185.5 (177.8-195.9) tok/s | `--prefill auto`, reserve 686-745 MiB | 383-443 MiB |
|
||||
| 512 | 12 | 292.5 (281.0-306.1) tok/s | `--prefill auto`, reserve 442-667 MiB (590 is our tuned value) | 137-365 MiB |
|
||||
| 768 | 7 | 387.4 (375.8-397.2) tok/s | `--prefill auto`, reserve 331-405 MiB | 27-103 MiB |
|
||||
| 1,024 | 4 | 442.9 (440.8-444.1) tok/s | `--prefill auto`, reserve 239-295 MiB | 0 MiB |
|
||||
| 1,280 | 5 | 514.5 (512.8-517.3) tok/s | `--prefill auto`, reserve 147-221 MiB | 0 MiB |
|
||||
| 1,536 | 2 | 573.6 (571.0-576.3) tok/s | `--prefill auto`, reserve 73-110 MiB | 0 MiB |
|
||||
| 1,792 | 3 | 631.4 (628.7-632.9) tok/s | `--prefill auto`, reserve 0-36 MiB | 0 MiB |
|
||||
| **2,048** | **6** | **667.1 (661.5-667.7) tok/s** | **`--prefill-head-alias`, reserve 590 MiB** | **289 MiB** |
|
||||
|
||||
Without the flag, every chunk above 768 tokens came only from lowering `--vram-reserve-mib`, and that left 0 MiB free.
|
||||
Under WDDM that is the state in which Windows starts paging. With the flag, the 2,048-token chunk came with the 590 MiB
|
||||
reserve unchanged.
|
||||
|
||||
## What it does
|
||||
|
||||
1. **At start**, after the MTP draft layer has copied its draft-head rows from the output head, the head is unloaded.
|
||||
The auto expert cache is then sized with the head's VRAM counted as free (on our card: 749 slots instead of 508).
|
||||
The prompt path borrows cache slots 1 to N (slot 0 stays). Whatever does not fit there is allocated by the prompt
|
||||
path itself, which makes a "hybrid" layout. The chunk is the largest of 2,048, 1,536, 1,024 and 512 tokens whose
|
||||
buffers fit in the borrowed slots plus free VRAM with 512 MiB to spare.
|
||||
2. **For each request**:
|
||||
1. If the head is loaded, unload it and lay the prompt path out again (median 20 ms).
|
||||
2. Read the prompt.
|
||||
3. Refill the lent slots and free the prompt path's own buffers.
|
||||
4. Load the head again (median 255 ms) before the first decode window.
|
||||
3. **Graph safety.** The verify windows' CUDA graphs are captured during the first decode and hold the head's address.
|
||||
If a later reload puts the head at a different address, the engine stops with an error, and the server starts it
|
||||
again. It does not run graphs that point at freed memory. We never saw this happen; see
|
||||
[Open questions](#open-questions).
|
||||
|
||||
The engine refuses the flag, with the reason, without `--serve`, with more than one GPU or a layer split, with
|
||||
`--batch`, with `--pipeline-windows`, with `--short-read` above 0, with a fixed `--expert-cache` above 1, without `--mtp`,
|
||||
or without the native output head.
|
||||
|
||||
## Costs
|
||||
|
||||
- **Short reads get slower.** Each request reloads the head (median 255 ms over 2,717 restores, p90 261 ms, max
|
||||
495 ms) and rebuilds the prompt path (20 ms). It also lends and then refills almost the whole cache, even for a few
|
||||
tokens. The engine's own prompt time, which includes all of this, by fresh tokens read (production, medians):
|
||||
|
||||
| Fresh tokens read | Default | Head alias |
|
||||
|---:|---:|---:|
|
||||
| 1-64 | 671 ms (293 requests) | 1,311 ms (614) |
|
||||
| 65-512 | 1,703 ms (409) | 2,453 ms (955) |
|
||||
| 513-2,048 | 4,062 ms (278) | 3,331 ms (618) |
|
||||
| 2,049-8,192 | 15,206 ms (118) | 6,876 ms (277) |
|
||||
|
||||
So the flag costs about 0.6-0.75 s on reads of up to 512 tokens and pays off from somewhere between 513 and 2,048
|
||||
tokens. In the agent loop, 614 of 2,717 requests read 64 fresh tokens or fewer.
|
||||
- **Less free VRAM while decoding.** In the default run, the verify windows were captured with 207-287 MiB free. With
|
||||
the flag, they were captured with 0 MiB free. Over 2,717 requests (about 26 hours) we saw no paging symptoms: decode
|
||||
held about 29 tok/s from the first request to the last (table below). This is the main risk on other cards and
|
||||
drivers.
|
||||
- **More slots to refill after each prompt.** The prompt path borrows almost the whole cache (748 of 749 slots instead
|
||||
of 328 of 508), so more experts are copied back after each prompt. That time is counted in the prompt time above.
|
||||
|
||||
## Measurements
|
||||
|
||||
Card and settings for every number on this page:
|
||||
|
||||
- NVIDIA RTX PRO 2000 Blackwell Laptop GPU, 8,151 MiB, Windows 11 Pro (WDDM, driver 597.16), CUDA 13.0, sm_120.
|
||||
- Intel Core Ultra 9 285H (AVX2), 64 GiB RAM, PCIe probe 25 GB/s (`pcie_frac` 0.55 picked by auto).
|
||||
- Qwen3.8-Flash-Next IQ3_XXS native pack, `--max-context 262144`, `--kv q4_0`, `--kv-resident 32768`, `--spec 4`,
|
||||
`--spec-min-p 0.5`, MTP with the English draft vocabulary, `--prompt-cache 3`, `--vram-reserve-mib 590`,
|
||||
`--expert-cache auto`, `--prefill auto`.
|
||||
- The engine was a local 0.1.41 build with this change. Both sides also used a local `STRATA_ARENA_REGISTER=0` switch
|
||||
that is not part of this change: it skips `cudaHostRegister` of the 40 GiB arena on this machine.
|
||||
|
||||
### Controlled: one prompt, one forced output
|
||||
|
||||
Each trial ran a fresh engine on the 29,854-token prompt. The same 3,072-token continuation was forced one verify row per
|
||||
token, with no speculative drafts, so the decode numbers compare the same work. A local benchmark switch did the forcing;
|
||||
it is not part of this change.
|
||||
|
||||
| Setting | Trials | Expert slots | Prompt chunk | Prefill | Decode | Expert-cache hits |
|
||||
|---|---:|---:|---:|---:|---:|---:|
|
||||
| 1-slot cache | 4 | 1 | 1,024 (own buffers) | 441.0 tok/s | 22.26 tok/s | 0.2% |
|
||||
| 1-slot cache + head alias | 2 | 1 | 2,048 | 666.3 tok/s | 24.50 tok/s | 0.2% |
|
||||
| auto cache + head alias | 3 | 749 | 2,048 | 667.7 tok/s | 26.21 tok/s | 24.9% |
|
||||
|
||||
We did not run the default (auto cache, no head alias) in this forced mode. Its free-running result on the same prompt
|
||||
is the 512-token row of the first table: one trial at the 590 MiB reserve read 306.1 tok/s and decoded 27.9 tok/s, and
|
||||
six head-alias trials decoded 26.6-29.0 tok/s (median 27.9). Free-running outputs differ from trial to trial, so their
|
||||
decode rates are only a rough comparison.
|
||||
|
||||
### Production: an agent loop
|
||||
|
||||
The workload was OpenCode agents (worker, reviewer and retrospective) running a coding loop against `/v1/chat/completions`.
|
||||
Prompts went up to about 150K tokens, with `--prompt-cache 3` prefix reuse.
|
||||
|
||||
- Default: 1,200 requests over 8 loop cycles.
|
||||
- `--prefill-head-alias`: 2,649 requests over 20 cycles.
|
||||
|
||||
The flag also needs `--short-read 0`; the default run had 64. Everything else was the same. Rates come from the engine's
|
||||
own lines (`reading the prompt` progress over at least 5 s, and the decode rate of requests with at least 32 output
|
||||
tokens). They are compared inside 16K-token context bands, so a heavier or lighter mix of prompts on either side does not
|
||||
count as a speed change. Intervals are 95% bootstrap intervals.
|
||||
|
||||
| | Default | Head alias | Change within context bands |
|
||||
|---|---:|---:|---:|
|
||||
| Prefill, median | 256 tok/s | 583 tok/s | +125% (+123% to +129%) |
|
||||
| Decode, median | 24.8 tok/s | 29.2 tok/s | +19% (+17% to +23%) |
|
||||
| Expert-cache hits, median | 20.8% | 25.9% | 508 -> 749 slots |
|
||||
|
||||
The decode difference needs care. The default runs alternated between long stretches near 27.5 tok/s and long stretches
|
||||
near 19.5 tok/s. A rolling median over 51 requests showed plateaus of hundreds of requests each, and in one run the
|
||||
switch from slow to fast came with no engine restart. In the head-alias run, each twelfth of the 2,649 requests had a
|
||||
median decode of 28.7-29.8 tok/s. Against the default's
|
||||
fast stretches only, decode was about 6% faster. We do not know what caused the slow stretches, so we do not claim that
|
||||
this change removes them.
|
||||
|
||||
The engine binary was also rebuilt between the two runs, to add prompt-cache support to this change. The controlled
|
||||
table above is the comparison that holds the binary fixed.
|
||||
|
||||
## Port check on 0.1.43.1
|
||||
|
||||
This change was moved to upstream main (0.1.43.1) and checked on the same PC. Both runs used the same build, a fresh
|
||||
engine each, and `STRATA_ARENA_PIN_GIB=auto`: without it, the full sliced arena pin on this 64 GB PC left WDDM with
|
||||
0 GiB free for the cache (#243). The requests were the 29,842-token prompt cold, then a 31-token follow-up on its
|
||||
prefix, two 45-token prompts, and the long prompt again. Output was capped at 768 tokens with low reasoning, and
|
||||
generation was free (not forced).
|
||||
|
||||
| | Default | Head alias |
|
||||
|---|---:|---:|
|
||||
| Expert slots, prompt chunk | 507, 512 | 753, 2,048 |
|
||||
| Free VRAM when the verify windows were captured | 207-245 MiB | 0 MiB |
|
||||
| Cold 29,842-token prompt, two runs | 276.5, 277.1 tok/s | 643.1, 649.7 tok/s |
|
||||
| Decode on those two | 35.7, 34.7 tok/s | 34.1, 31.6 tok/s |
|
||||
| 31-token follow-up (29,837 reused), prompt time | 632 ms | 1,721 ms |
|
||||
| 45-46-token prompts, prompt time | 871, 1,005 ms | 1,780, 1,424 ms |
|
||||
|
||||
All five requests completed with coherent answers. The head came back at the same address every time, so the guard
|
||||
never fired. 0.1.43.1's new start-of-request warning ("below 1024 MiB free") appears with both settings, at 289 MiB
|
||||
for the default and 0 MiB with the flag.
|
||||
|
||||
## Open questions
|
||||
|
||||
- **A fixed address for the head.** The head goes back with `cudaMalloc`, which does not promise the same address. The
|
||||
check above makes a moved head a clean engine restart. A cleaner design would keep the head's virtual range and swap
|
||||
its backing (CUDA VMM), or lay prompt buffers directly into the head's allocation instead of freeing it.
|
||||
- **Skip the swap for short reads.** A request that reads a few dozen fresh tokens pays about 0.6 s (table above) for a
|
||||
2,048-token chunk it does not need. A threshold on fresh tokens, below which the head stays and the read goes through
|
||||
the decode windows as `--short-read` does, would remove that cost.
|
||||
- **Other cards.** We measured only the 8 GB card above, on Windows. A larger card already gets a large chunk without
|
||||
the flag, so we expect the gain to be smaller there.
|
||||
|
||||
## Not tested
|
||||
|
||||
- This change on upstream main (0.1.43.1) was compiled for CUDA (13.0, sm_120, MSVC, Windows) and checked with the
|
||||
short run above. The longer measurements come from the 0.1.41 build.
|
||||
- HIP (the same sources) and SYCL. On SYCL, `Prefill::init` refuses the hybrid layout; the SYCL engine has no flag
|
||||
for it.
|
||||
- Linux, multi-GPU, `--batch` and `--pipeline-windows` (all refused), and models other than Qwen3.8-Flash-Next IQ3_XXS.
|
||||
@@ -0,0 +1,33 @@
|
||||
# Optional checkpoint near the prompt tail
|
||||
|
||||
`--prompt-cache-tail` saves at most one extra mid-prompt checkpoint near the end
|
||||
of a request, at a boundary the batched prefill already reaches. It is off by
|
||||
default and applies to single-GPU serve with positive `--prompt-cache` and
|
||||
`--prompt-cache-every` values.
|
||||
|
||||
A branch can share most of a prompt but diverge before its final cached state.
|
||||
If the periodic checkpoint before that branch is far away, the engine has to
|
||||
read the gap again. The extra checkpoint can reduce that gap. It uses the
|
||||
existing bounded checkpoint cache; it does not add another unbounded history.
|
||||
|
||||
The tail is the first chunk boundary within one chunk of the prompt's end, where the chunk is the size that chunk
|
||||
really had (`--prefill auto` chunks differ from `--prefill N`). The tail checkpoint is evicted first (only one stays
|
||||
alive, the root is never dropped), so it never pushes out a periodic checkpoint when `--prompt-cache` is full.
|
||||
|
||||
The option does not split prefill chunks or alter the periodic checkpoint
|
||||
schedule. It selects the first completed batched chunk within one configured
|
||||
chunk of the prompt's end, excluding the short final suffix controlled by
|
||||
`--short-read`. If a periodic checkpoint already falls there, the same state is
|
||||
saved once. Reread diagnostics and layer splits keep their existing behavior.
|
||||
|
||||
For example, with a 6144-token chunk and a 16384-token checkpoint interval,
|
||||
the first periodic checkpoint is at 18432 and the next would be at 36864.
|
||||
A branch sharing 32769 tokens cannot use the latter. A near-tail checkpoint
|
||||
at 30720 can reuse more of that prefix,
|
||||
without changing how the original prompt was computed. The benefit depends
|
||||
on the request and the branch position; it is not a universal speed increase.
|
||||
|
||||
This is a separate conservative alternative to the PolyStrata-2080Ti Daily's
|
||||
checkpoint-grid patch. The grid changes chunk boundaries to reach exact
|
||||
checkpoint intervals and failed its local paired numerical gate. This option
|
||||
does not claim that the original grid patch has been fixed or validated.
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
# The Q8_0 KV cache (`strata-poly --kv q8_0`)
|
||||
|
||||
`strata-poly` can store its attention K and V caches in the ggml **Q8_0** format instead of fp16. It is
|
||||
opt-in: `--kv q8_0`. The default, `--kv fp16`, is unchanged and byte-identical to the build before this
|
||||
option existed. The format halves the KV cache's VRAM and, on the models tested, leaves the answers alone.
|
||||
|
||||
## What the format is
|
||||
|
||||
A cache row holds one value a token for each KV head and each head dimension (`n_kv * head_dim` values).
|
||||
Stored as fp16 that is `2 * n_kv * head_dim` bytes a token for K and, again, for V. Stored as Q8_0 it is cut
|
||||
into 32-value blocks: for every block of 32 values, one fp16 **scale** (the block's largest magnitude over 127)
|
||||
and 32 **int8 codes**. That is `n_kv * (head_dim / 32) * 2` bytes of scales plus `n_kv * head_dim` bytes of codes,
|
||||
a row for K and the same for V. Attention dequantizes a block with its scale on the fly while it computes the
|
||||
scores and the outputs.
|
||||
|
||||
For the three tested models (`n_kv = 2`, `head_dim = 256`, 11 attention layers for Tiel/Ornith, 10 for Occamy)
|
||||
the engine prints its row size at load:
|
||||
|
||||
```
|
||||
strata-poly: q8_0 KV cache: 544 bytes a row
|
||||
```
|
||||
|
||||
544 = 512 codes + 2 blocks × 2 scales, a head, K and V. `--kv q8_0` needs `n_kv * head_dim` to be a multiple
|
||||
of 32; the models here are. A grammar that is not gets a clear error rather than a wrong answer.
|
||||
|
||||
All three models loaded and answered with `--kv q8_0` at the full 131072-token context, and with a picture
|
||||
through the vision encoder (`strata-vision`), each replying `KV OK` to the fixed prompt.
|
||||
|
||||
## What it was measured on
|
||||
|
||||
| | |
|
||||
| --- | --- |
|
||||
| Graphics card | NVIDIA RTX 3070, 8192 MiB |
|
||||
| CPU | 24 threads |
|
||||
| Built with | CUDA (the CUDA build of `strata-poly`); `/opt/cuda` |
|
||||
| Models | `Tiel-Coder-35B-A3B.APEX-I-MiniPlus-V2.1.gguf`, `Ornith-1.5-35B-A3B.APEX-I-MiniPlus-V2.1.gguf`, `Occamy-1.0.APEX-I-MiniPlus-V2.1.gguf`, all `qwen35moe`, Q4_K - Medium |
|
||||
| Context | 131072 tokens |
|
||||
| Server | `serve/server.py --engine strata --config strata-<model>.json --port 8099` |
|
||||
|
||||
## The answers do not move
|
||||
|
||||
With greedy sampling (`temperature: 0`, which the engine reads as its own greedy), `--no-draft` so the
|
||||
speculative path cannot change a token (`timings.draft_n` was 0 on every request), and `max_tokens: 64`, the
|
||||
fp16 and Q8_0 arms were compared over five prompts each: the four short factual ones and one open-ended
|
||||
sentence about the colour blue.
|
||||
|
||||
| model | exact matches | mean character agreement | longest common prefix |
|
||||
| --- | ---: | ---: | --- |
|
||||
| Tiel Coder 35B-A3B | 5/5 | 1.0000 | full reply (137 chars) |
|
||||
| Ornith 1.5 35B-A3B | 5/5 | 1.0000 | full reply (129 chars) |
|
||||
| Occamy 1.0 | 5/5 | 1.0000 | full reply (173 chars) |
|
||||
| **all three** | **15/15** | **1.0000** | — |
|
||||
|
||||
Every Q8_0 answer equals the fp16 one character for character. The short factual prompts (`KV OK`, `42`,
|
||||
`Paris`, `2, 3, 5, 7, 11`) also equal the pre-change fp16 baseline byte for byte on all three models
|
||||
(12/12), which is how the default path's byte-identity was checked; the open-ended fifth prompt is not
|
||||
bit-stable at greedy on Ornith and Occamy even before this change (speculative drafts on Ornith, `--tail-skip`
|
||||
and the adaptive expert cache on Occamy), so it is not used for that check. The engine/API does not return
|
||||
tokens, so agreement is measured on the reply text (longest common prefix and per-prompt agreement).
|
||||
|
||||
## What it saves
|
||||
|
||||
Per token, and in total at a full 131072-token context:
|
||||
|
||||
| model | attention layers | Q8_0 a token | fp16 a token | Q8_0 at 131072 | fp16 at 131072 | saved |
|
||||
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
|
||||
| Tiel | 11 | 11 968 B | 22 528 B | 1.461 GiB | 2.750 GiB | 1.289 GiB |
|
||||
| Ornith | 11 | 11 968 B | 22 528 B | 1.461 GiB | 2.750 GiB | 1.289 GiB |
|
||||
| Occamy | 10 | 10 880 B | 20 480 B | 1.328 GiB | 2.500 GiB | 1.172 GiB |
|
||||
|
||||
**46.88% less KV VRAM** for all three, matching the per-token arithmetic exactly.
|
||||
|
||||
The engine's default KV cache grows as the conversation does, so a short prompt barely moves the load-time
|
||||
expert cache — but with `--kv-whole`, which reserves the whole context's KV at load, the freed VRAM goes to
|
||||
experts. At 131072 the expert cache under `--kv-whole` rose
|
||||
|
||||
```
|
||||
Tiel fp16: 1237 of 10496 experts (1.5 GiB) q8_0: 2319 of 10496 (2.8 GiB) +1082 experts
|
||||
Ornith fp16: 1237 of 10496 experts (1.5 GiB) q8_0: 2313 of 10496 (2.8 GiB) +1076 experts
|
||||
Occamy fp16: 1503 of 10240 experts (1.8 GiB) q8_0: 2480 of 10240 (2.9 GiB) +977 experts
|
||||
```
|
||||
|
||||
with the same free VRAM left per model at the end.
|
||||
|
||||
## What it costs
|
||||
|
||||
At a 972-token prompt, 128-token answers, greedy, `--no-draft`, `--vram-reserve-mib 512` (see the caveat),
|
||||
each arm a fresh process, median of four steps:
|
||||
|
||||
| model | arm | prompt tok/s | decode tok/s |
|
||||
| --- | --- | ---: | ---: |
|
||||
| Tiel | fp16 | 1014.6 | 105.8 |
|
||||
| Tiel | q8_0 | 1008.0 | 105.2 |
|
||||
| Ornith | fp16 | 1022.8 | 106.5 |
|
||||
| Ornith | q8_0 | 1008.4 | 106.2 |
|
||||
| Occamy | fp16 | 1031.8 | 107.1 |
|
||||
| Occamy | q8_0 | 1034.1 | 106.9 |
|
||||
|
||||
Q8_0 against fp16: prompt **−1.4% to +0.2%**, decode **−0.6% to −0.2%** — within run-to-run scatter.
|
||||
|
||||
## A caveat that is not about Q8_0
|
||||
|
||||
At 131072 with the default 256 MiB reserve, long chats intermittently fail with
|
||||
`cudaGraphInstantiate: out of memory`: the engine grows the expert cache down to 128 MiB free, then a newly
|
||||
recorded CUDA graph needs more than what is left. This is **pre-existing and general**: it reproduces on the
|
||||
unchanged fp16 path too, so it is not caused by `--kv q8_0`. `--vram-reserve-mib 512` removes it — all four
|
||||
model/format combinations, eight requests each, with and without a picture, saw zero OOM. The numbers above
|
||||
were taken with that 512 MiB reserve.
|
||||
|
||||
The three run configs (`strata-tiel.json`, `strata-ornith.json` and `strata-occamy.json`) now ship with
|
||||
`--vram-reserve-mib 512`, so the OOM does not occur with them. With that reserve, Tiel at the full
|
||||
131072-token context loads 3481 of 10496 routed experts into VRAM (4.1 GiB), measured on the RTX 3070 below.
|
||||
|
||||
## What was left alone
|
||||
|
||||
- The `strata` engine, and its own `--kv int8`. Nothing in it changed.
|
||||
- `glm5next` / GLM 5.3 Flash (`dsa_attend`): its attention is not the one this cache quantizes, so `--kv q8_0`
|
||||
is not offered for it.
|
||||
- **Gemma 4 is out of v1.** `--kv q8_0` with a `gemma4` file is rejected cleanly at load
|
||||
(`--kv q8_0 is only supported for qwen35moe models in v1; this is a 'gemma4' model`), not run.
|
||||
- ROCm/HIP: the same kernels, measured below on an AMD card (it was rejected on HIP until that was done).
|
||||
- The default path stays byte-identical to the last release.
|
||||
|
||||
## The comparison with another implementation
|
||||
|
||||
`llama.cpp` (the in-tree build `runners/llama.cpp/build/bin/llama-cli`) reads the same `qwen35moe` files and
|
||||
accepts `-ctk q8_0 -ctv q8_0`. Given a Q8_0 KV cache it answered the two short fixed prompts
|
||||
(`Reply with exactly: KV OK` → `KV OK`; `What is 17 + 25? Answer with just the number.` → `42`), the same
|
||||
tokens the poly engine's `--kv q8_0` produced on all three models. It was run on the CPU (`-ngl 0`) because the
|
||||
file is far larger than the card; only the short deterministic answers are a meaningful signal across engines.
|
||||
Full transcript in the T8.5 report.
|
||||
|
||||
## Files touched
|
||||
|
||||
- `src/poly/engine.hpp` — `KvFmt` and `Options::kv_format` (default `kFp16`).
|
||||
- `src/poly/main.cpp` — `--kv fp16|q8_0` parsing and help text.
|
||||
- `src/poly/engine.cpp` — the `qwen35moe`-only check and the clean rejection for other architectures.
|
||||
- `src/poly/qwen35.hpp`, `src/poly/qwen35.cpp` — the Q8_0 cache pointers, allocation, save/load, the row-size
|
||||
print, and the attention path that reads codes+scales.
|
||||
- `src/poly/kernels.cu`, `include/strata/poly/kernels.hpp` — `store_q8` / `store_q8_at` and the Q8_0 attention
|
||||
readers (scores and outputs).
|
||||
- `src/poly/kv_q8_test.cpp` (new) — the kernel unit test: round-trip within half a block scale, byte-exact
|
||||
layout, and the ring store.
|
||||
- `CMakeLists.txt` — the `poly_kv_q8_test` target and its `add_test`.
|
||||
- `strata-tiel.json`, `strata-ornith.json`, `strata-occamy.json` — the three run configs now carry
|
||||
`--kv q8_0` and `--vram-reserve-mib 512`.
|
||||
- `gemma4.hpp` / `gemma4.cpp` — untouched.
|
||||
|
||||
## Builds
|
||||
|
||||
- **CUDA:** builds clean; the test-suite run is **116/117**. The one failure, `ple_parity`, is a missing model
|
||||
file (`.../Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00002-of-00002.gguf: cannot open`), unrelated to this change.
|
||||
`poly_kv_q8_test` passes (0.23 s).
|
||||
- **HIP:** builds clean for gfx1201; `poly_kv_q8_test` passes (91,530 values checked) on an RX 9070 XT.
|
||||
|
||||
## On an AMD card
|
||||
|
||||
RX 9070 XT (16 GB, gfx1201), Ryzen 7 9800X3D, 30 GB of RAM, Fedora, ROCm 7 from AMD's wheels;
|
||||
`Tiel-Coder-35B-A3B-MTP-UD-Q4_K_XL.gguf`, `--kv-whole`, a 2 GiB conversation cache. fp16 at 131072 against Q8_0
|
||||
at 196608, each a fresh server:
|
||||
|
||||
| | experts in VRAM | 256-token answer | 4.5K prompt | 64K prompt | answer after it |
|
||||
| --- | ---: | ---: | ---: | ---: | ---: |
|
||||
| fp16, 131072 | 4415 (7.9 GiB) | 110-127 tok/s | 1,814-1,822 tok/s | 2,065 tok/s | 66 tok/s |
|
||||
| Q8_0, 196608 | 4729 (8.4 GiB) | 106-130 tok/s | 1,843-1,862 tok/s | 2,075 tok/s | 63 tok/s |
|
||||
|
||||
Greedy with `--no-draft`, seven prompts: the four short ones gave the same answers; a docstring, a two-sentence
|
||||
summary of a 24K-character prompt and a list of names from a 60K-character one took other words from the 249th,
|
||||
14th and first character on, each answer as right as the fp16 one.
|
||||
- **SYCL:** not applicable; that is a separate engine.
|
||||
@@ -0,0 +1,70 @@
|
||||
# QSA_ROWS: the decode window's QSA block scores with the queries in registers (`STRATA_QSA_ROWS=1`, opt-in)
|
||||
|
||||
Opt-in: `STRATA_QSA_ROWS=1` (exactly `1`). Unset the engine runs the kernels it ran before. CUDA, the verify window's
|
||||
decode (calls of `qsa_block_scores` without `active_blocks` and with up to 4 queries); the prompt path and HIP are not
|
||||
touched. Scores and top-k ids are bitwise the multi kernel's (`qsa_rows_bench --rows` checks it).
|
||||
|
||||
## Why
|
||||
|
||||
In a 131k decode the QSA kernel that grows most with the window's rows is `block_scores_multi_kernel`: about 20 us more
|
||||
per call for every row of the window on an RTX 2080 Ti and an RTX 3060 (nsys; 8 QSA layers on the second card of a
|
||||
layer split, 4 on the first). The keys are already read once for all the queries; the cost per row is in the shared
|
||||
memory and shuffle pipes: per (key block, query) the kernel reads the four query slices from shared memory (4 x
|
||||
`LDS.128`) and reduces each head's lane products with its own five shuffles (20 per block and query): at 32 769 blocks
|
||||
that is 15-20 us of issue per query.
|
||||
|
||||
## What it changes
|
||||
|
||||
`block_scores_rows_kernel<NQ>` (`src/kernels/cuda/qsa_select.cu`, NQ = 1..4):
|
||||
|
||||
1. the NQ queries' slices (4 heads x 4 floats per lane) stay in registers for the whole kernel (44 / 63 / 78 / 94
|
||||
registers, no stack, `cuobjdump -res-usage`);
|
||||
2. the lane products of the 4 heads are reduced with a scatter that keeps `warp_sum`'s pairings: xor 16 and 8 leave
|
||||
one head per lane, then 4, 2, 1 - six shuffles for the four heads instead of twenty - and gathered on lane 0 in head
|
||||
order (three shuffles).
|
||||
|
||||
Every addition adds the same two operands of the same `warp_sum` level (float addition commutes), the product
|
||||
expression is the same text in the same file, the relus are summed in head order: the same bits as the multi kernel
|
||||
and the per-query kernel. Tail block and the `+1e9` as before. Beyond 4 queries, with `active_blocks`, or without the
|
||||
variable, the multi kernel runs.
|
||||
|
||||
## Micro-bench: `qsa_rows_bench`
|
||||
|
||||
Not in the default build: `cmake --build <dir> --target qsa_rows_bench`. Synthetic data at the real geometry (24 query
|
||||
heads x 256, 2 KV heads, indexer 4 x 128, blocks of 4 cells, top-k 2048), int8 pools, no model.
|
||||
|
||||
```
|
||||
qsa_rows_bench [--device N] [--iters 100] [--ctx 131072] [--max-context 262144] [--rows] [--no-dense]
|
||||
```
|
||||
|
||||
Without `--rows` it measures what the T rows of a verification window cost in a QSA layer's decode kernels (block
|
||||
scores, top-k, attention over each row's selection, indexer append; `--no-dense` skips the drafter's 32768-cell window).
|
||||
`--rows` runs `block_scores_rows_kernel` against the multi kernel - scores and top-k ids bit for bit (memcmp) at T =
|
||||
1..4 at 131k and at a short context (cells 100-103, a full tail block), 16 cases per card - and prints both kernels'
|
||||
microseconds. Exit 0 (77: no GPU; 1: a parity failure).
|
||||
|
||||
`qsa_block_scores`, us per call, 131k context (both kernels read the same pooled keys):
|
||||
|
||||
| | T=1 | T=2 | T=3 | T=4 | per row |
|
||||
|---|---|---|---|---|---|
|
||||
| RTX 2080 Ti, multi (reference) | 47.2 | 56.9 | 78.2 | 101.2 | +18.0 |
|
||||
| RTX 2080 Ti, `STRATA_QSA_ROWS=1` | 36.2 | 38.0 | 49.2 | 54.6 | +6.1 |
|
||||
| RTX 3060, multi | 73.4 | 109.4 | 151.9 | 193.5 | +40.0 |
|
||||
| RTX 3060, `STRATA_QSA_ROWS=1` | 63.3 | 75.5 | 98.0 | 130.2 | +22.3 |
|
||||
|
||||
Parity: 8 cases per card, 0 differ. On the RTX 3060 at T=4 the
|
||||
kernel is at 94 registers (2 CTAs per SM); a two-pass version of 2 queries would stay at 63 if that card matters.
|
||||
|
||||
## In the engine
|
||||
|
||||
Layer split RTX 3060 (layers 0-15) + RTX 2080 Ti (layers 16-47, head), Windows, `--pipeline-windows 2`, 131k context:
|
||||
per window the second card saves -0.09 ms at T=1 and -0.37 ms at T=4 (8 QSA layers), the first -0.04 / -0.25 (4
|
||||
layers). End to end on a deterministic 131k bench (forced tokens and window sizes, 1024 tokens, B-A-B): **+3.2% and
|
||||
+0.1%** decode tokens/s in the two B arms, the text identical.
|
||||
|
||||
## Not done
|
||||
|
||||
A multi-row attention kernel (K/V of a cell read once for all the rows that selected it) is possible bit for bit only
|
||||
if every row keeps its own chunk partition; at the decode window's sizes (cap 2051 cells, T <= 4) the blocks of all rows
|
||||
fit in one wave and the kernel is bound by its block's latency chain, so the gain is bounded by ~0.1-0.2 ms per row on
|
||||
8 layers: not worth it here. `STRATA_QSA_ROWS` turns on the scores kernel only.
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
# Unsloth's K-quants and Q8_0: formats, kernels and quality
|
||||
|
||||
This page covers Unsloth's files of the model ([unsloth/Qwen3.8-Flash-Next-GGUF](https://huggingface.co/unsloth/Qwen3.8-Flash-Next-GGUF),
|
||||
revision `38bb39e`; the repository's head `766911a` has the same files, byte for byte): what each file stores in
|
||||
each layer, which of PolyStrata's kernels run those formats on each kind of hardware, and how close each file comes to
|
||||
the Q8_0 reference. Setup and the per-file details: [UD-Q4_K_XL](UNSLOTH_Q4.md), [UD-Q6_K_XL](UNSLOTH_Q6.md),
|
||||
[MODELS.md](MODELS.md).
|
||||
|
||||
## What each file stores
|
||||
|
||||
Read from the GGUF headers alone with `tools/quant_formats.py --hf unsloth/Qwen3.8-Flash-Next-GGUF 38bb39ee... <dir>`
|
||||
(HTTP range requests, nothing else is downloaded; on local shards: `tools/quant_formats.py <shard glob>`).
|
||||
|
||||
The routed experts (gate, up, down; 512 per layer, 10 used per token) are where the files differ:
|
||||
|
||||
| File | Download | Routed gate / up | Routed down | Routed experts | Per token (10 experts x 48 layers) |
|
||||
|---|---:|---|---|---:|---:|
|
||||
| UD-IQ4_XS | 93.7 GB | IQ3_S (IQ4_XS in layer 2) | IQ4_NL (Q8_0 in layers 2, 4, 30, 46, 47) | 55.4 GiB | 1.16 GB |
|
||||
| UD-Q4_K_XL | 111.3 GB | Q4_K (Q5_K in layer 2) | Q5_1 (Q8_0 in layers 2, 4, 30, 46, 47) | 71.7 GiB | 1.50 GB |
|
||||
| UD-Q5_K_XL | 158.3 GB | Q5_K (Q6_K in layer 2) | Q8_0 | 91.6 GiB | 1.92 GB |
|
||||
| UD-Q6_K_XL | 169.2 GB | Q6_K (Q8_0 in layer 2) | Q8_0 | 101.7 GiB | 2.13 GB |
|
||||
| Q8_0 | 188.2 GB | Q8_0 | Q8_0 | 119.5 GiB | 2.51 GB |
|
||||
|
||||
Everything else is the same in all five: the attention, SSM, hyper-connection and shared-expert projections, the
|
||||
PLE key/value and the token embedding are Q8_0 (the small vectors, norms and the router F32; the QSA indexer BF16),
|
||||
the output head is Q8_0 (Q6_K in UD-IQ4_XS). The PLE table (`per_layer_token_embd`) is IQ4_NL (26.8 GiB) in UD-IQ4_XS
|
||||
and UD-Q4_K_XL and Q8_0 (50.7 GiB) in UD-Q5_K_XL, UD-Q6_K_XL and Q8_0. The dense side the GPU reads once per verify
|
||||
window is about 4.8 GB in every file.
|
||||
|
||||
UD-Q5_K_XL, UD-Q6_K_XL and Q8_0 share their shards 2 (the output head) and 3 (the PLE table) byte for byte (the same
|
||||
SHA-256), so a PC that has one of them can link those two shards instead of downloading them again.
|
||||
|
||||
## Kernels per format and backend
|
||||
|
||||
| Format (role) | CUDA decode (grouped experts) | CUDA prompt | CPU pool | AMD (HIP) decode | AMD prompt | Intel (SYCL) decode | Intel prompt |
|
||||
|---|---|---|---|---|---|---|---|
|
||||
| Q4_K (gate/up) | yes | FP16 path; MMQ with `STRATA_MMQ_KQ=1` | ggml AVX2 dot; multi-token AVX2 (`STRATA_KQ256=1`) | yes (CUDA layout; `STRATA_EXPERT_V2K=1` bitwise) | FP16 path; MMQ with `STRATA_MMQ_KQ=1`; gfx11 fused (`STRATA_PF_FUSED_KQ=1`) | kernels built, not run with these files | FP16 path |
|
||||
| Q5_K (gate/up) | yes | as Q4_K | ggml AVX2 dot | as Q4_K | as Q4_K | kernels built, not run with these files | FP16 path |
|
||||
| Q6_K (gate/up) | yes (since this change; was `-DSTRATA_Q6K_EXPERTS=ON`) | FP16 path; MMQ with `STRATA_MMQ_KQ=1` | ggml AVX2 dot | yes (CUDA layout) | FP16 path; MMQ with `STRATA_MMQ_KQ=1` | kernels built, not run with these files | FP16 path |
|
||||
| Q5_1 (down) | yes | as Q4_K | ggml AVX2 dot; multi-token AVX2 (`STRATA_KQ256=1`) | yes (CUDA layout; V2K) | as Q4_K | kernels built, not run with these files | FP16 path |
|
||||
| Q8_0 (gate/up, down) | yes | MMQ | ggml AVX2 dot; multi-token AVX2 down (`STRATA_KQ256=1`) | yes (CUDA layout; V2K down) | MMQ | kernels built, not run with these files | FP16 path |
|
||||
|
||||
- "FP16 path": the prompt's experts dequantized to FP16 and multiplied by the BLAS library. It works for every format
|
||||
above but reads each expert as ~10 MB of FP16.
|
||||
- **Formats cost nothing unless used.** The engine loads every kernel of its own binary when it starts (so that no
|
||||
kernel needs VRAM later, mid-prompt), which is why kernels for formats a model does not have used to take expert
|
||||
slots from every model. The Q6_K expert kernels are now part of every build: one more instance per grouped kernel,
|
||||
+19 KB of sm_60 code, and the expert-cache slot counts measured unchanged (IQ3_XXS: 6,028 slots on a P100, 15,878
|
||||
and 1,980 on an R9700). The K-quant MMQ prompt kernels (Q4_K, Q5_K, Q5_1, Q6_K: ~3.8 MB of sm_60 code, 3 IQ3_XXS
|
||||
slots on the P100 when they were in the engine) are on CUDA a library of their own next to the engine
|
||||
(`libstrata_kq.so` / `strata_kq.dll`), opened only for a model with these experts and `STRATA_MMQ_KQ=1`; without the
|
||||
file those experts take the FP16 prompt path. On AMD a code object loads on first use, so they stay in the engine.
|
||||
- `STRATA_MMQ_KQ=1` is opt-in because MMQ rounds the prompt's products differently from the FP16 path (the output
|
||||
differs at the rounding level); its speed and KL are measured before it becomes a default.
|
||||
|
||||
## Quality: the yardstick
|
||||
|
||||
`tools/quant_quality.py` scores a quant against Q8_0 on one fixed text set (`data/quant_quality/v1`: code, docs,
|
||||
English prose, German/French/Japanese/Chinese, an agent transcript; 5 x 1,000 tokens in `set.ids.json`). Every token
|
||||
is read through the decode windows (teacher-forced) with the experts on the CPU (one VRAM slot), no expert
|
||||
adaptation, no PCIe share, no route tail skip, FP16 K/V; per position the engine writes the log-probability of the
|
||||
text's next token and its 64 most likely tokens (`STRATA_LOGPOS`, `STRATA_LOGPOS_TOPK=64`). Top-1 agreement: the
|
||||
same most likely token as Q8_0. KL: KL(Q8_0 || quant) over Q8_0's 64 most likely tokens.
|
||||
|
||||
```sh
|
||||
python tools/quant_quality.py run --config strata-<quant>.json --out <quant>.tsv
|
||||
python tools/quant_quality.py compare q8_0.tsv <quant>.tsv --segments
|
||||
```
|
||||
|
||||
Measured on the AMD box (EPYC 7452, R9700, HIP, engine at 0601072d; 4,995 positions; Q8_0 against itself in a second
|
||||
run: byte-identical rows):
|
||||
|
||||
| Quant | Same top token as Q8_0 | Mean KL | KL p99 | Perplexity (Q8_0: 4.052) |
|
||||
|---|---:|---:|---:|---:|
|
||||
| UD-Q6_K_XL | 94.61% | 0.033 | 0.494 | 4.020 |
|
||||
| UD-Q5_K_XL | 94.55% | 0.038 | 0.636 | 4.024 |
|
||||
| UD-Q4_K_XL | 93.09% | 0.056 | 0.829 | 4.068 |
|
||||
| UD-IQ4_XS | 88.91% | 0.101 | 1.596 | 4.120 |
|
||||
| IQ3_S | 87.69% | 0.144 | 1.975 | 4.097 |
|
||||
| IQ3_XXS | 84.46% | 0.202 | 2.433 | 4.119 |
|
||||
| Q2_0 | 80.60% | 0.315 | 3.643 | 4.475 |
|
||||
|
||||
The same file on another backend is not the same answers: UD-Q4_K_XL on an RTX A4000 (CUDA, the RAM
|
||||
budget mode of a 62 GB PC) against UD-Q4_K_XL on the R9700 is 94.5% the same top token (KL 0.038), mostly near-ties.
|
||||
|
||||
**The prompt path:** `tools/quant_quality.py prompt` / `pcompare` score the batched prompt path the same way (20 prompts
|
||||
of 256-1,000 tokens of the set, the full vocabulary's KL of the next token's distribution against Q8_0's): every
|
||||
quant above picks Q8_0's top token after all 20 prompts. The K-quants' MMQ kernels (`STRATA_MMQ_KQ=1`) against the FP16
|
||||
path on the R9700: UD-Q4_K_XL mean KL 0.095 / median 0.0027 (FP16: 0.081 / 0.0047), UD-Q5_K_XL 0.038 / 0.00055 (FP16:
|
||||
0.025 / 0.0016), UD-Q6_K_XL 0.028 / 0.00029 (FP16: 0.029 / 0.00069) - a better median everywhere, a worse mean on Q4/Q5
|
||||
(a few prompts), so it stays opt-in.
|
||||
|
||||
## Speed, and the bound
|
||||
|
||||
Measured on the AMD box: one Radeon AI PRO R9700 (32 GB, capped at 225 W), EPYC 7452 (32 cores, 8 channels of
|
||||
DDR4-2400: 106 GB/s read by `rdbw` at 32 threads), every expert in RAM (setup's rule below), `--expert-cache auto`,
|
||||
40K context, 8-bit K/V, MTP drafts; `rbench.py` cases, the second of two requests; prompt speed varies between runs on
|
||||
this box by up to 2x (the range is given).
|
||||
|
||||
| File | Short story (tok/s) | Code (tok/s) | After a 6K document | Prompt 32K (tok/s) | llama.cpp 8bb3cf0d2 (same card, `-ngl 99 --n-cpu-moe 38-48`): decode / prompt 4K |
|
||||
|---|---:|---:|---:|---:|---:|
|
||||
| IQ3_S (for comparison) | 75 | 95 | 77 | 1,555 | - |
|
||||
| UD-Q4_K_XL | 63-64 | 85-88 | 70-72 | 1,110-1,320 | 18-20 / 198-257 |
|
||||
| UD-Q5_K_XL | 57-60 | 81-83 | 62 | 810-1,260 | 17-18 / 226-270 |
|
||||
| UD-Q6_K_XL | 54 | 76 | 61 | 1,020 | - |
|
||||
| Q8_0 | 53-57 | 66-74 | 54-55 | 1,230-1,300 | 16-18 / 186-225 |
|
||||
|
||||
**Where a decode window goes** (`STRATA_DECODE_TIMING=1 STRATA_VERIFY_PROFILE=1`, UD-Q4_K_XL, the short story, 2.0
|
||||
tokens per window, 34.3 ms per window): the bandwidth bound of what a window must read is ~12.5 ms - the routed
|
||||
experts in VRAM (~2.7 GB at 644 GB/s: 4.2 ms bound, 6.0 measured), the dense Q8_0 projections (2.84 GB: 4.4 ms bound,
|
||||
7.2 measured), the hyper-connections (0.67 GB: 1.0 ms bound, 4.0 measured), router and shared expert (0.5 GB: 0.8 ms
|
||||
bound, 3.7 measured), the head (1.05 bound, 1.26 measured), the CPU pool's experts at RAM bandwidth in parallel
|
||||
(1.2 ms), plus the MTP draft (5.8 ms measured). Decode runs at ~35-40% of that bound for every file, IQ3_S included:
|
||||
the formats' own kernels are near their bandwidth (VRAM-resident experts ~70%, the CPU pool 84-97% of RAM bandwidth,
|
||||
the head 83%); the rest is the per-window latency of the small kernels and the draft, the same for every model.
|
||||
|
||||
The CPU pool's expert rows (`kq_cpu_bench`, the engine's own calls on T threads over 4 GB of experts):
|
||||
|
||||
| Pair | EPYC 7452, 32 threads, 1 token per expert | 3 tokens | Ryzen 5600X, 6 threads, 1 token | 3 tokens | Xeon E5-2643 v3, 12 threads, 1 token | 3 tokens |
|
||||
|---|---:|---:|---:|---:|---:|---:|
|
||||
| Q4_K / Q5_1 | 97% of RAM bandwidth | 80% | 100% | 85% | 94% | 36% |
|
||||
| Q5_K / Q8_0 | 97% | 89% | 100% | 95% | 98% | 47% |
|
||||
| Q6_K / Q8_0 | 97% | 93% | 100% | 100% | 99% | 63% |
|
||||
| Q8_0 / Q8_0 | 96% | 90% | 100% | 100% | 99% | 64% |
|
||||
|
||||
One token per expert (most of decode) is at the RAM bound on all three; older CPUs fall behind with several tokens per
|
||||
expert (ggml's dot decodes the weights once per token; `STRATA_KQ256=1`, bit-exact, takes 11-20% off Q4_K at 3-4
|
||||
tokens).
|
||||
|
||||
**Dense Q8_0 GEMVs** (`q8_gemv_bench`, the engine's shapes, 2-4 columns): one row per block where it was measured
|
||||
faster, the same bits as two (R9700: 2560 -> 10240 / 6144 / 12288 at 76-86% of 644 GB/s instead of 51-80%; RTX A4000:
|
||||
+1-4%, and 6144 -> 2560 at 6 columns 70% -> 76%). UD-Q4_K_XL decode +1.0-2.7% on the R9700, the same text.
|
||||
|
||||
**NVIDIA with the RAM budget** (RTX A4000 16 GB, Xeon E5-2643 v3, 62 GB: UD-Q4_K_XL with 39 GiB of its experts in RAM,
|
||||
the rest read from an NVMe SSD at 2.1 GB/s): 14-20 tokens/s and a 4K prompt at 134-144 tokens/s, bound by the SSD;
|
||||
llama.cpp on the same PC and file 14.8-16.5 / 117-123. `STRATA_PROMPT_DIRECT=1` (Linux, opt-in) reads the prompt
|
||||
path's experts unbuffered while decode keeps the file cache: the same output (6 of 6 prompts identical with fixed
|
||||
flags), the 4K prompt 152 -> 315 tokens/s, a 20K prompt 217 -> 500, decode +2-15% (5 interleaved pairs, page cache
|
||||
dropped before each run). On a second PC with more file-cache room (the R9700 box held to 64 GB) it was mixed: a 6K
|
||||
document's prompt +8%, a 4K prompt -15% and the answer after the document -38%, because the buffered reads had left
|
||||
the document's experts in the file cache. So it stays opt-in. Reading everything unbuffered (`STRATA_UNBUFFERED_LOAD=1`) doubled the prompt too but cost
|
||||
decode 9-13%; a larger or smaller RAM budget, more fetch threads, a deeper read-ahead or a wider look-ahead did not
|
||||
help.
|
||||
|
||||
**Several cards** (R9700 box, every expert in RAM, layer split, 2 runs each): UD-Q4_K_XL on 1 / 2 / 3 / 4 cards writes
|
||||
63 / 64 / 55 / 52 tokens/s on the short story and 88 / 96 / 123 / 96 on code, and reads a 32K prompt at 1,110 /
|
||||
1,275 / 1,987 / 2,381 tokens/s; UD-Q5_K_XL 57 / 60 / 62 / 46 and 83 / 94 / 101 / 89, prompt 1,264 / 1,177 / 1,767 /
|
||||
2,067. llama.cpp on 3 / 4 cards: 24.5 / 28.2 tokens/s and 497 / 800 (4K prompt) for UD-Q4_K_XL. More cards read
|
||||
prompts faster; for short answers the split's per-stage cost outweighs the experts it keeps in VRAM, since one card with
|
||||
every expert in RAM is already fast (`--pipeline-windows 0` helps short answers at 3-4 cards, x1.3, and costs code
|
||||
6-20%).
|
||||
|
||||
**Every expert in RAM against the old RAM budget** (setup's new rule, R9700 box, UD-Q4_K_XL, 5 interleaved pairs, the
|
||||
old config's `--resident-budget-gib 71` holding the same experts read from the GGUF in place): decode x1.34-1.40 (short
|
||||
story 39.5 -> 53.3 tok/s, code 60.1 -> 80.4, after a 6K document 49.0 -> 68.8, 5/5 each), prompt 4K x2.07, 6K x1.58,
|
||||
32K x1.03.
|
||||
|
||||
**The route tail skip** (`STRATA_ROUTE_TAIL_SKIP=7`, the default since 0.1.42: a missed expert every token of a window
|
||||
routes at rank 7 or lower is skipped) costs these files more than the 2-3-bit packs: UD-Q4_K_XL's yardstick KL against
|
||||
Q8_0 goes from 0.056 to 0.086 with every expert in RAM (R9700, the auto cache) and from 0.053 to 0.115 in the RAM
|
||||
budget mode (A4000, 1,500 GPU slots), for +4-10% decode in RAM and +26-67% in the budget mode (5 pairs each).
|
||||
`STRATA_ROUTE_TAIL_SKIP=0` in a config's `"env"` turns it off.
|
||||
|
||||
**The hyper-connections on NVIDIA:** the pack's `--compat-bf16` copy of the Q8_0 HC projections rounds them to BF16
|
||||
(and doubles their bytes). `STRATA_HC_Q8=1` reads the file's own Q8_0 instead (on AMD gfx12 it is the default): on the
|
||||
A4000 UD-Q4_K_XL then comes closer to Q8_0 (yardstick KL 0.0562 -> 0.0526, p99 0.925 -> 0.716) and to the same file on
|
||||
AMD (KL 0.038 -> 0.033). Opt-in until decided.
|
||||
|
||||
## Images
|
||||
|
||||
Every Unsloth file reads pictures with the model's own encoder: setup's `mmproj-Qwen3.8-Flash-Next-BF16.gguf` (from
|
||||
ISTA-DASLab's repository) has the same 334 tensors, byte for byte, as Unsloth's `mmproj-BF16.gguf`. Run end to end
|
||||
with a test picture (a line of text and three coloured shapes), two questions through `/v1/chat/completions`: on an RTX
|
||||
A4000 with the GPU encoder (UD-Q4_K_XL, IQ3_XXS) and on an R9700 with the CPU encoder (UD-Q4_K_XL, UD-Q5_K_XL,
|
||||
IQ3_XXS), every answer had the text and the three shapes right, as llama.cpp's `mtmd-cli` did on the same GGUF and
|
||||
mmproj. The GPU encoder keeps ~1.3 GB of VRAM free (UD-Q4_K_XL on 16 GB: 2,331 expert slots instead of 2,741); the CPU
|
||||
encoder takes none. Setup turns images on by default for these files on an NVIDIA card of 16 GB or more, and on AMD
|
||||
(Linux, the CPU encoder) where every expert stays in RAM.
|
||||
@@ -1,594 +0,0 @@
|
||||
# Running Qwen3.6-35B-A3B on UnbiasedStrata - the study
|
||||
|
||||
What it takes for Qwen3.6-35B-A3B (llama.cpp architecture `qwen35moe`) to run on this tree's Strata
|
||||
engine, component by component, with the numbers the decision needs. Written 2026-10-11 against engine
|
||||
0.1.39 (`CMakeLists.txt:11`, the `6f32ec0` snapshot; tree `8634357`). It is the Phase 2 design document
|
||||
of `docs/PLAN-qwen36-35b-a3b.md` and the counterpart of Project Maya's `docs/GLM5-FLASH.md`, whose shape
|
||||
it copies. Every `file:line` is this tree; "row N" is `docs/qwen36-port/geometry-inventory.md`; the model
|
||||
facts come from `docs/qwen36-port/gguf-metadata.md` and `ref/qwen36.py` on branch `qwen36-oracle`; the
|
||||
measurements from regina's `phase0-notes.md` and `replay/phase0-replay.md`.
|
||||
|
||||
Strata is a native implementation of one architecture, Qwen3.8-Flash-Next (`qwen4exp`), with its memory
|
||||
tiers and its speculation stack built around that shape. Qwen3.6-35B-A3B is the same family one generation
|
||||
earlier with three things removed (the hyper-connection residual, the sparse-attention indexer, the PLE
|
||||
table) and one numerical change in the GDN gate. The kernel gap is small. The plumbing gap is not: the
|
||||
removed pieces are assumed structurally in every block, in the verify window that is the only decode path
|
||||
for native packs, in the drafter and in prefill, and `ModelGeometry` is never populated from the model file.
|
||||
|
||||
---
|
||||
|
||||
## 1. The model, exactly
|
||||
|
||||
From the shipped GGUFs (`gguf-metadata.md`, dumped with `tools/gguf_reader.py`; sizes and SHA-256s in
|
||||
`phase0-notes.md`):
|
||||
|
||||
| | |
|
||||
| --- | --- |
|
||||
| Architecture | `general.architecture = qwen35moe`; `block_count` 40 (41 in the MTP files); `embedding_length` 2048; `context_length` 262,144 |
|
||||
| Layer pattern | `full_attention_interval` 4: layer `il` is recurrent unless `(il+1) % 4 == 0`, so attention at 3, 7, ..., 39 (10 layers), GDN at the other 30 |
|
||||
| GDN | `ssm.conv_kernel` 4, `ssm.state_size` 128, `ssm.group_count` 16 (k-heads), `ssm.time_step_rank` 32 (v-heads), `ssm.inner_size` 4096; conv channels 8192 = 2x2048 + 4096. Output gate `rms_norm(o) * ssm_norm * SiLU(z)` (`qwen35moe.cpp:267-276`) |
|
||||
| Full attention | 16 heads, 2 KV heads, `key_length`/`value_length` 256, `rope.dimension_count` 64 (0.25 of 256), `rope.dimension_sections` [11, 11, 10, 0], `freq_base` 1e7, eps 1e-6; `attn_q` is 2x wide (query then gate per head, interleaved); output `* sigmoid(gate)`. **Dense**: no indexer |
|
||||
| MoE | 256 experts, top-8, `expert_feed_forward_length` 512, shared expert 512 with a 1-D `ffn_gate_inp_shexp` scalar gate. Softmax over all 256, top-8 weights renormalised to sum 1 (`norm_w = true` hard-coded, `qwen35moe.cpp:506`); no `expert_weights_scale` (never loaded for this architecture) |
|
||||
| Residual | plain: `attn_norm`, `post_attention_norm`, `output_norm`, all multiplicative RMS weights (no "+1") |
|
||||
| MTP | `nextn_predict_layers` **absent in the plain file, 1 in the MTP files**; `blk.40` holds one attention + MoE block plus `nextn.eh_proj` [4096, 2048] over `concat(enorm(emb), hnorm(h))`, `nextn.enorm`, `nextn.hnorm`, `nextn.shared_head_norm`; no `embed_tokens`, no `shared_head_head` (the draft head is the main `output.weight`) |
|
||||
| Vocabulary | 248,320 tokens, `pre = qwen35`, BOS/EOS/PAD 248044/248046/248055; the same tokenizer the engine's `--eos-ids` default already names (row 152) |
|
||||
| Float tensors | the router `ffn_gate_inp`, `ssm_alpha`, `ssm_beta`, the shexp gate and every norm are **F32** in the plain file; the nextn block's router and shexp gate are BF16 |
|
||||
| Mixed quantization | per layer and per role: IQ3_XXS file has IQ2_S gate/up everywhere, IQ3_XXS down on 37 layers and IQ4_XS on 3 (34, 38, 39); the nextn block in the MTP files is Q3_K/Q4_K experts with Q8_0 projections |
|
||||
| Fused forms | none shipped: gate and up are separate `ffn_gate_exps`/`ffn_up_exps`, attention layers carry separate `attn_q`/`attn_k`/`attn_v`; `attn_qkv` exists only in the 30 GDN layers (the conv input) |
|
||||
|
||||
The byte census of the three files on hand (gguf-py over the headers, 2026-10-11; `blk.40` separated):
|
||||
|
||||
| File | Non-expert on the GPU (`output` + projections + norms) | `token_embd` | Trunk experts (40 x 256) | Per expert mean / max | `blk.40` dense / experts |
|
||||
| --- | ---: | ---: | ---: | ---: | ---: |
|
||||
| `UD-Q4_K_XL` (MTP repo, rev 5bc3e238, 21,784 MiB) | **2,038 MiB** (Q8_0 1,939 + F32 100) | 515 MiB Q8_0 | **18,726 MiB** (Q4_K 11,232, Q5_K 6,864, Q6_K 630) | 1.829 / 2.195 MiB (layer 39) | 40 / 464 MiB |
|
||||
| `UD-IQ3_XXS` (12,589 MiB) | **1,597 MiB** (Q6_K 1,497 + F32 100) | 398 MiB Q6_K | **10,594 MiB** (IQ2_S 6,560, IQ3_XXS 3,626, IQ4_XS 408) | 1.035 / 1.172 MiB | none |
|
||||
| `UD-IQ4_XS-MTP` (17,355 MiB) | 2,038 MiB | 515 MiB | 14,514 MiB | 1.417 / 1.883 MiB | 40 / 364 MiB |
|
||||
|
||||
The two non-expert figures are what llama.cpp's `-lv 4` reported on the 1080 Ti once the GPU-resident
|
||||
expert layers are subtracted: Q4 `CUDA0 model` 5,917 MiB minus layers 32 to 39 (3,878 MiB) = 2,039; IQ3
|
||||
7,475 minus layers 18 to 39 (5,878) = 1,597 (`phase0-notes.md`, smoke table). The token embedding stays in
|
||||
host memory in both llama.cpp and this engine (`generate.cpp:2190`, "token embedding in mapped host
|
||||
memory"), so it is not in the fixed set. The plan's Section 2 estimated ~3.1 GB for this item; the real
|
||||
figure is 2.0 GiB.
|
||||
|
||||
## 2. What the engine already is
|
||||
|
||||
The implemented geometry is a struct of Flash-Next defaults (`include/strata/core/layout.hpp:27-59`):
|
||||
n_embd 2560, 48 layers, full attention every 4th, GDN 16 k-heads / 48 v-heads / state 128 / conv 4 with
|
||||
conv channels 10240 and value dim 6144 stored as members (row 2), QSA 24 heads / 2 KV heads / 256 with a
|
||||
4-head 128-wide indexer, hyper-connections `hc` 4 with a 320-wide bottleneck, 512 experts x top-10 x 640.
|
||||
`is_qsa_layer` is `layer % 4 == 3` (`layout.hpp:63`). Per layer (`src/core/layer.cpp:1170-1286`,
|
||||
`1319-1342`):
|
||||
|
||||
gr_read(attn) -> GDN | QSA -> gr_write(attn) -> gr_read(ffn) -> moe_route [doorbell] ... moe_finish -> gr_write(ffn)
|
||||
|
||||
The unit is a captured per-layer CUDA graph replayed by a host loop (`include/strata/core/session.hpp:1-15`)
|
||||
that rings a doorbell at the router so a CPU expert pool starts on the misses while the GPU continues.
|
||||
Experts live in three tiers: a VRAM cache of slots filled by a profile and swapped by decayed usage
|
||||
(`include/strata/core/expert_cache.hpp`), a RAM tier (pinned arena, or `--resident-experts` /
|
||||
`--resident-budget-gib` keeping the complement of the VRAM cache in a compact copy,
|
||||
`generate.cpp:1506-1520`, `expert_source.cpp:1331`), and the model file mapped from disk
|
||||
(`--mmap-experts`, `expert_source.cpp:618-680`) with a `MADV_WILLNEED` warm hint per role on predicted
|
||||
ids (`expert_source.cpp:1129-1160`, called at `1264`). Decode for a *native* pack (experts served from the
|
||||
GGUF in their own ggml types, `include/strata/kernels/cpu/native_expert.hpp`) runs only through the verify
|
||||
window (`expert_source.cpp:1869-1875`, row 114): windows of up to `kVerifyMaxT = 8` rows
|
||||
(`verify_kernels.hpp:21`) drafted by the model's own MTP layer, a separate Q8_0 pack in VRAM
|
||||
(`src/core/mtp.cpp:150-216`, `mtp.hpp:1-20`), plus a prompt-lookup drafter (`generate.cpp:522-524`).
|
||||
Prompts go through a chunked prefill with the experts streamed over PCIe through a ring that borrows
|
||||
cache slots (`generate.cpp:2723`, `4404-4425`; `docs/upstream/DETAILS.md`, "How it works"). The front
|
||||
end (`frontend/`) is model-agnostic: OpenAI API, llama.cpp's chat parser (`frontend/chat_parser_test.cpp`),
|
||||
vision through `mtmd` (`frontend/vision.hpp:4-87`), and it refuses `--gpus` (`frontend/main.cpp:558`).
|
||||
|
||||
## 3. Component-by-component gap analysis
|
||||
|
||||
### 3.1 Applies unchanged
|
||||
|
||||
| Piece | Why |
|
||||
| --- | --- |
|
||||
| Layer pattern | `is_qsa_layer` (`layout.hpp:63`) gives 3, 7, ..., 39 for 40 layers; `n_qsa_layers() = 40/4 = 10` (row 55). Every per-layer loop in `session.cpp` uses `g.n_layers` (row 27). |
|
||||
| GDN decode kernels | State 128, head pairing `head % h_k` (`native_gdn.cu:51`, `fused_gdn.cu:29`), grids from `h_v`, `h_v % h_k == 0` checked (`native_gdn.cu:99-101`, `fused_gdn.cu:148-153`); 32 % 16 = 0. The conv (`d_conv == 4 && state 128`, `layer.cpp:247-248`) matches. |
|
||||
| Router | `router_top10` is a generic softmax top-k over runtime `n_expert <= 512`, `k <= 32` (`router_top10.hpp:21`, row 124); `moe_route` takes it whenever the pack is not 512/10 (`layer.cpp:370`). Semantics equal llama.cpp's: softmax over all, stable descending argsort, renormalise with the 2^-14 clamp (`router_top10.hpp:3-5`; `oracle-crosscheck.md`, "Router and experts"). |
|
||||
| Shared expert | Shape-driven (`layer.cpp:418-451`); its Q8_K activation rule needs `n_ff % 256 == 0` (`shared_expert.cu:237-239`), which 640 failed and 512 satisfies (row 127). |
|
||||
| Native expert kernels | CPU: `native_fmt` is ggml-cpu trait-driven, whole-block checks only (`native_expert.cpp:40-60`); 2048 and 512 are multiples of 256. `kNativeActBytes` 4096 / `kNativeHBytes` 1024 hold a 2048-wide Q8_K (2,336 B) and a 512-wide one (584 B) (row 111). GPU: `iq_kernels.cu:1076-1140` read `L.n_embd`/`L.n_ff` per layer; Q4_K/Q5_K gate-up and Q5_1/Q8_0 down are already present (row 120); the IQ2_S/IQ3_XXS/IQ4_XS/Q6_K of the shipped files are ggml types ggml-cpu has `vec_dot` for. |
|
||||
| Expert cache and tiers | Residency `[n_layers x n_expert]`, slots, the profile header checked against `(n_layers, n_expert)` (`expert_cache.cpp:43`); the file source, the complement copy, the warm hint; all parameterised at runtime (rows 118, 109). |
|
||||
| KV formats and streaming machinery | fp16 / int8 / q4_0 / K8V4 pools at `head_dim 256` (`kv_q4.cu:176`, row 103); paged pools, `--kv-resident`, the resident floor 20,480 cells (`layer.cpp:556`). The *use* of streaming changes (section 4.2). |
|
||||
| RoPE | `n_rot 64`, `head_dim 256` (`native_rope.cu:121`), interleaved M-RoPE sections 11/11/10/0 with `t = h = w` for text (`mrope.hpp:3-12`); the oracle pins the same pairs `(p, p+32)` (`oracle-crosscheck.md`, "Full attention"). |
|
||||
| Vocabulary, sampler, head | `n_vocab` is a kernel argument, merge handles <= 262,144 (`sampler.cu:607`); the native head takes `[n_in, n_out]` with `n_in % 256 == 0` (`native_head.cpp:21`); the drafter reads `n_vocab_ = output.weight.ne1` (`mtp.cpp:430`). |
|
||||
| Speculation protocol | Verify windows, draft policy, prompt lookup; the drafter's *weights* change (3.10). |
|
||||
| Front end | Tokenizer, template, tool-call parser, vision (row 154). |
|
||||
| MTP drafter's attention | Already dense over every cell (`mtp.hpp:16-18`, row 76): the one dense-attention path in the tree. |
|
||||
|
||||
### 3.2 GDN: head pairing, SiLU gate, four kernels (small)
|
||||
|
||||
The geometry changes are runtime except two stored members, `ssm_conv_channels` and `ssm_value_dim`,
|
||||
which must become 8192 and 4096 (row 2; `session.cpp:41-44` derives the state size from them). The one
|
||||
numerical change: the output gate is `sigmoid(z)` in the engine and `SiLU(z)` in Qwen3.6 (row 39;
|
||||
`layer.hpp:16` records the difference). Four kernels carry it:
|
||||
|
||||
| Kernel | Line | Path |
|
||||
| --- | --- | --- |
|
||||
| `gdn_out_norm` | `src/kernels/cuda/gdn.cu:148` | legacy decode |
|
||||
| `gdn_step_norm_kernel` | `src/kernels/cuda/fused_gdn.cu:69` (`1/(1+__expf(-zz))`) | the default native decode, inside the fused step |
|
||||
| out-norm kernel | `src/kernels/cuda/native_gdn_preprocess.cu:110-112` | native unfused |
|
||||
| `gdn_rec_kernel`, `gdn_out_norm_kernel` | `src/prefill/kernels.cu:324, 612` (`sigm(z)`) | prompt |
|
||||
|
||||
The oracle's negative control shows the sigmoid reading moves the layer output by 1.07 relative L1 and the
|
||||
logits by 0.92 (`oracle-crosscheck.md`, negative controls), so the trap is far above the 5% gate.
|
||||
`src/kernels/gdn_parity.cpp:104` pins `h_v = 48` and its reference `sigmoid_f` (`:42`); both are re-pinned
|
||||
at 32 v-heads with SiLU, the sigmoid reading becoming the negative case. The prompt GDN kernels are
|
||||
specialised on `VPK = HV / HK = 3` value heads per key head (`prefill/kernels.cu:478`) and launched on the
|
||||
`HV`/`HK`/`C` constants (`kernels.cu:18-19`, rows 89 to 91); they are the prefill item in 3.6.
|
||||
|
||||
### 3.3 Dense attention replacing QSA (the largest kernel item, and a memory item)
|
||||
|
||||
The decode kernel gathers K/V through `ids` and a page table and does not care how `ids` was built
|
||||
(`qsa_decode_attn.cu:100-120`, row 102). So dense attention is a "select every cell" producer feeding the
|
||||
existing kernel. What stands in the way:
|
||||
|
||||
1. **The producer.** `qsa_layer` runs the indexer unconditionally: the raw key projection (`layer.cpp:945`),
|
||||
the append (`:962-964`), the block scores and top-k (`:966-975`), with `indexer.{k,q}_proj.weight` and
|
||||
`indexer.{k,q}_norm.weight` dereferenced as required tensors (`:891-897`, row 45). The verify window
|
||||
does the same per row (`verify.cpp:757-761`, `772-870`, row 145). A dense path skips those steps and
|
||||
writes `ids = 0..n_kv-1` from `st.step`; the selection width `qsa_selection_width(n_kv, s) =
|
||||
min(n_kv, 2051)` (`qsa.hpp:144-147`) and the capacity `cap = qsa_selection_width(kTopkMaxCells, s)`
|
||||
(`layer.cpp:876`, `verify.cpp:352`, `prefill.cpp:865`) become `n_kv` and `max_cells`.
|
||||
2. **The 12-versus-8 literal.** `G = 12` query heads per KV head, refused with `exit(1)` unless
|
||||
`n_head == 12 * n_head_kv` (`qsa_decode_attn.cu:17, 453, 497`; `qsa_prompt_attn.cu:22, 1447`; row 93, 94).
|
||||
Qwen3.6 is 8. `G` becomes a template parameter instantiated at 8 and 12.
|
||||
3. **The 24-head short-context kernel.** `native_flash_attn.cu:196-206` refuses anything but 24/2/256 and
|
||||
contexts above 256; it is a diagnostic adapter (`layer.hpp:53`, "context <= 256") and is not on the
|
||||
prompt path. It stays as it is.
|
||||
4. **State without the indexer.** `qsa_state_bytes` carves `idx_tail`, `idx_dead`, `idx_pooled` with
|
||||
`pooled_rows = max_cells/4 + 2` (`layer.cpp:559-575`, row 43): at 262,144 cells that is 65,538 x 128 x
|
||||
4 B = 32 MiB per attention layer, 320 MiB over ten, all dead. The drafter's ring already passes a state
|
||||
"which has no indexer" with `pooled_rows = 2` (`layer.cpp:527-531`); the dense state takes the same.
|
||||
5. **The split-K scratch scales with the context.** `qsa_decode_attn_scratch_floats(cap, s) = (cap/64) x
|
||||
n_head x 258 + 64` (`qsa_decode_attn.cu:489-491`). Today `cap` is 2,051; with `cap = 262,144` and 16
|
||||
heads it is 64.5 MiB *per query row*: 516 MiB for the 8-row verify window (`verify.cpp:422`) and
|
||||
`attn_batch` times that in prefill (`prefill.cpp:888`). The dense kernel needs either a larger chunk
|
||||
per block or an online-softmax merge that does not keep a partial per 64-cell chunk.
|
||||
6. **KV streaming no longer saves VRAM.** Streaming keeps the authoritative K/V in host memory and resolves
|
||||
the *selected* blocks into VRAM slots before the read (`layer.hpp:230-236`, `qsa_kv_resolve` at
|
||||
`layer.cpp:976`). With every cell selected every token, every block must be resident every token: the
|
||||
mechanism degenerates to copying the whole KV (1,440 MiB at q4_0) over PCIe per token. Section 4.2
|
||||
and section 8 draw the consequence for the plan's sizing rule.
|
||||
|
||||
KV formats, the Hadamard-rotated q4_0 pool, the page table and the RoPE tables carry over unchanged
|
||||
(`layer.cpp:938-1010`, row 46). The prompt attention has three device paths: cp.async + mma on sm_80+,
|
||||
mma on Turing, an m8n8k4 kernel on Volta, and for `cc < 70` the host returns false
|
||||
(`qsa_prompt_attn.cu:1433`) so prefill falls back to the batched decode kernel
|
||||
(`prefill.cpp:2222-2228`). On Pascal that fallback is the prompt attention; it needs `G = 8` and the
|
||||
scratch fix above, nothing else.
|
||||
|
||||
### 3.4 Router and shared expert (small; one measured-not-asserted parity)
|
||||
|
||||
Both are generic already (3.1). Two form questions remain. The router kernel reads a BF16 weight
|
||||
(`layer.cpp:361-366`, `project_bf16`), `fused_gdn_ab` reads BF16 `ssm_alpha`/`ssm_beta`
|
||||
(`layer.cpp:285-287`), and `moe_shared` refuses a `ffn_gate_inp_shexp` that is not engine form BF16
|
||||
(`layer.cpp:427-437`). All four are F32 in the shipped file (`gguf-metadata.md`, "What was unexpected").
|
||||
The pack rounds them: exactly when the low 16 bits are zero, else only under `--compat-bf16`
|
||||
(`upstream-tooling.md` section 4, the ORCA precedent). That is a numerical change against llama.cpp, which
|
||||
multiplies in F32, and it lands on the one place where rounding is not a rounding error: a flipped top-8
|
||||
selection is a different expert (`layer.hpp:131-139`). The oracle's real-file smoke already shows the
|
||||
F32-versus-quantized router disagreeing on 6 of 32 (token, slot) choices in layer 0 and 12 to 23 in layers
|
||||
30 to 39 (`oracle-crosscheck.md`, "Not covered"), so the harness measures a flip rate at the
|
||||
`logits -> top-8` boundary with the quantized-mode gates Maya calibrated (selection equal at probed layers
|
||||
on an F32 fixture; a bounded rate on the real file), not bitwise equality. `router_top10_parity.cpp`'s tie
|
||||
fixtures (all-equal logits, a 12-way tie, the unreachable clamp) carry over at 256/8.
|
||||
|
||||
### 3.5 The block without hyper-connections: `layer.cpp` *and* `verify.cpp` (the largest plumbing item)
|
||||
|
||||
`hc` sizes the residual `R` (hc, n_embd), `inject`, `gr_rs` and the GR workspace (`layer.cpp:1127-1145`),
|
||||
and every block reads four `hc_attn_*` and four `hc_ffn_*` tensors with required forms
|
||||
(`layer.cpp:1231-1255`, row 22). No `hc = 1` meaning exists (row 4): the GR math on one stream is not a
|
||||
plain residual, and the names Qwen3.6 ships (`attn_norm`, `post_attention_norm`, `output_norm`) are
|
||||
referenced nowhere in `src/` (rows 22, 23). The plain block is
|
||||
|
||||
x = rms_norm(R, attn_norm) -> mixer -> R += out
|
||||
x = rms_norm(R, post_attention_norm) -> MoE -> R += out head: rms_norm(R, output_norm) -> output.weight
|
||||
|
||||
(`qwen35moe.cpp` layer loop; the oracle's `attn_norm-N`, `attn_residual-N`, `attn_post_norm-N`, `l_out-N`,
|
||||
`result_norm` seams). The weighted RMS norm kernel exists (`native_qsa_rms_norm_weighted`, used at
|
||||
`layer.cpp:879` and `mtp.cpp:488`). The places that must grow the plain path:
|
||||
|
||||
| Site | What assumes hc |
|
||||
| --- | --- |
|
||||
| `layer.cpp:1170-1286` `block_layer_pre`, `1319-1342` `block_layer_post` | the two GR halves, the fused-GR fast path (`fused = g_fused_gr && fused_gr_supported(2560, 4, 320)`, `:1195`; `fused_gr.cu:1164-1166`), `pending_ffn` folding |
|
||||
| `layer.cpp:1088-1107` `lm_head_mix` | `output_hc_{norm,down,up}` |
|
||||
| `session.cpp:141-148` | first token = `hc` copies of the embedding (one copy at hc = 1, row 26) |
|
||||
| `verify.cpp:331-340` | refuses unless `fused_gr_supported && ss.k == 10 && state 128 && d_conv 4` and `layer_verify_compatible` demands the fused GR and the native indexer (`layer.cpp:476-486`, row 141) |
|
||||
| `verify.cpp:356-434` | `R_`, `xn_` as `T*HC*N`, `inj_`, `lo_ (T*hc_lr)`, `idx_raw_L_`, `qidx_`, `tail_snap_` |
|
||||
| `verify.cpp:1123-1125` | the head mix |
|
||||
| `verify_kernels.cu:256-291` | `broadcast_streams` / `add_streams_broadcast` (runtime `hc`, row 140) |
|
||||
| `mtp.cpp:503-507, 564-568, 613-625`; `prefill.cpp:972-1086` | the drafter's three hc groups (3.10) |
|
||||
|
||||
Because native packs decode only in verify windows (row 114) and the window refuses a layer without fused
|
||||
GR and the indexer (row 141, 142), the plain block has to land in `verify.cpp` for a single token to come
|
||||
out. The verify window's `ss.k == 10` refusal becomes `k == 8` from the file. `cvec` (the control-vector
|
||||
apply over `hc*n_embd`, row 140) is runtime-shaped and needs no change.
|
||||
|
||||
### 3.6 Prefill (the most literal-heavy subsystem)
|
||||
|
||||
`Prefill::init` refuses unless `n_embd == 2560 && hc == 4 && hc_lr == 320 && k == 10`
|
||||
(`prefill.cpp:737`, row 132); the file-wide constants are `N 2560, HC 4, D, LR 320, K 10, NE 512, C 10240,
|
||||
ZV 6144, HV 48` (`prefill.cpp:90-91`) and `N, HC, D, LR, S, HK 16, HV 48, C 10240` in the kernels
|
||||
(`prefill/kernels.cu:18-19`). The literals, each with its Qwen3.6 value:
|
||||
|
||||
| Site | Literal | Qwen3.6 |
|
||||
| --- | --- | --- |
|
||||
| `prefill.cpp:649-650, 883-884` | `Qf` as `T * 12288` (24 x 512), `q`/`attn` as `T * ZV`; `idx_raw`, `q_idx` | 8,192 (16 x 512), 4,096; the two indexer buffers dead |
|
||||
| `prefill.cpp:681-685, 704-721, 896-907` | MoE buffers `T*K*1280`, `T*K*640`, `1280 * 2560`, `2560 * 640`; `mmq::fits(gt, 1280)`, `matrix_bytes(dt, N, 640)` | `2*n_ff` 1024, `n_ff` 512, `n_embd` 2048 |
|
||||
| `prefill.cpp:854-856, 1000-1026, 1375-1380` | `grs`, `gated`, `inj`, `xq`, `ident` from `HC`, `D`, `LR` | removed with hc |
|
||||
| `prefill/kernels.cu:211-215, 285-304, 345-364, 387-432, 478-570, 893-924` | GDN kernels indexed on `HV`, `HK`, `C`, launched `<<<HV, ...>>>`; `VPK = 3` (`:478`) | 32, 16, 8192; `VPK = 2` |
|
||||
| `prefill/kernels.cu:616-657` | `route_kernel<REG>`: `REG 8` exists for 256 experts but the rank loop and `ids[t*10 + rank]`, `lane < 10` bake top-10 | `k` as a parameter |
|
||||
| `prefill/kernels.cu:752-761` | `split_q_kernel`, `gate_attn_kernel` over `T * 24 * 256` and `h * 512` | 16 heads |
|
||||
| `prefill/moe_fused_iq.cu:59` | `GU_ROWS_K = 2560, D_ROWS_K = 640` (the native-pack fused prompt MoE) | 2048, 512 |
|
||||
| `prefill.cpp:1724` loop, `1303` `RP = 48` | layers from `g.n_layers` (fine, row 134); `RP` | check |
|
||||
|
||||
The GDN kernels are forked per geometry (template on `HV, HK, C`) rather than made runtime, because their
|
||||
shared-memory staging (`sq[2][TB][S]`, `kernels.cu:482-484`) is sized from them. `src/prefill/gdn_rec_parity.cu`
|
||||
mirrors the constants (row 91) and is re-pinned with them. The chunked-versus-single-token equivalence (a
|
||||
prefix through prefill then decoded must agree with token-by-token decode) is the harness that already
|
||||
exists for this path (`tests/cuda/prefill_*_test.cpp`, restored in `c00942d`).
|
||||
|
||||
### 3.7 The native pack path (one leak, otherwise runtime)
|
||||
|
||||
The canonical Q2_0 CPU expert kernel bakes `H 2560, FF 640, NE 512, BLOB 1,382,400`
|
||||
(`include/strata/kernels/cpu/expert.hpp:34-47`, row 107) and `expert_pool_dispatch` refuses any other
|
||||
width (`expert_source.cpp:1863-1868`); Qwen3.6 does not go through it. It rides the native path, as the
|
||||
Coder (256 of 512 experts) does. The path is runtime per layer (`NativeFmt` with `n_embd`, `n_ff`, gate/up
|
||||
and down ggml types, `native_expert.hpp:22-31`) with one leak: `expert_layout_load` builds every layer's
|
||||
format with the compile-time `H, FF` (`src/kernels/cpu/expert_layout.cpp:284`, `native_fmt(gt, dt, H, FF,
|
||||
f, err)`) and then checks `f.bytes == blob`, so a 2048/512 pack fails the "blob is X B but its formats make
|
||||
Y" check (row 108). The fix is the loader taking `n_embd`/`n_ff` from the geometry the caller resolved,
|
||||
which means the call at `generate.cpp:2008-2010` (today `g0.n_layers, g0.n_expert` from a default struct,
|
||||
row 10) must run after the metadata read of 3.8, not before it.
|
||||
|
||||
`native_experts.txt` already carries a type per layer and per role (gate/up share one, down may differ,
|
||||
`upstream-tooling.md` section 4; v3 header `(n_expert N)`, `expert_layout.cpp:271`), so the IQ3_XXS file's
|
||||
37/3 down split and the Q4_K_XL's Q6_K layers need no format change. The engine reads experts as three
|
||||
separate `ffn_{gate,up,down}_exps` tensors (`expert_source.cpp:2475-2500`, row 116); the shipped files are
|
||||
separate, and a fused `ffn_gate_up_exps` is refused by name rather than split (section 8, item 5).
|
||||
|
||||
### 3.8 Metadata and `ModelGeometry`
|
||||
|
||||
`check_architecture` requires `general.architecture == "qwen4exp"` and reads six `qwen4exp.*` keys with
|
||||
defaults 48/2560/24/2 (`include/strata/artifact/gguf_reader.hpp:576-597`); its callers are the native dense
|
||||
loader, the native head and embedding, and the GGUF reader (`native_dense.cpp:103`, `native_head.cpp:29`,
|
||||
`:113`, row 18). Every Qwen3.6 load dies there first. Beyond the guard, only `expert_count`,
|
||||
`expert_used_count` and the rope keys are read, under `qwen4exp.` and only with `--native`
|
||||
(`generate.cpp:2089-2096`, rows 8, 9). What `ModelGeometry` must read, all present in the file
|
||||
(`gguf-metadata.md`, metadata table; row 153):
|
||||
|
||||
| Field | Key |
|
||||
| --- | --- |
|
||||
| `n_embd`, `n_layers` | `qwen35moe.embedding_length`, `block_count` minus `nextn_predict_layers` (0 when absent) |
|
||||
| `qsa_interval` | `full_attention_interval` |
|
||||
| `ssm_state_size`, `ssm_k_heads`, `ssm_v_heads`, `ssm_d_conv`; conv channels and value dim derived | `ssm.state_size`, `ssm.group_count`, `ssm.time_step_rank`, `ssm.conv_kernel`, `ssm.inner_size` |
|
||||
| `n_head`, `n_head_kv`, `head_dim`, `n_rot`, sections, base, eps | `attention.head_count`, `head_count_kv`, `key_length`, `rope.dimension_count`, `rope.dimension_sections`, `rope.freq_base`, `attention.layer_norm_rms_epsilon` |
|
||||
| `n_expert`, `k`, `n_ff` (routed and shared) | `expert_count`, `expert_used_count`, `expert_feed_forward_length`, `expert_shared_feed_forward_length` |
|
||||
| `hc` | 1 (no key; the architecture string decides) |
|
||||
|
||||
The oracle's `read_hparams` (`ref/qwen36.py:125-150`) is the reference for defaults and derived values.
|
||||
Other default-geometry sites: the routing trace's `layer >= 48` bounds (`generate.cpp:771, 795`, row 13),
|
||||
the embedding load with `g0.n_embd` and the literal 248320 (`generate.cpp:2184-2186`, row 11), the draft
|
||||
geometry (`generate.cpp:3026`, 3.10), and the standalone planner's `Geometry` and `expert_blob`
|
||||
(`include/strata/plan/plan.hpp:22-52`, row 19), which is off the serving path.
|
||||
|
||||
### 3.9 PLE, optional at the CLI
|
||||
|
||||
The kernels already run without it: `block_layer_pre` applies the PLE only at layer 1 when `ple != nullptr
|
||||
&& ple->ready()` (`layer.hpp:524-545`, row 30), prefill and verify guard on `ple_on` (rows 68, 69). The CLI
|
||||
does not: `--native` refuses to start without `--ple-gguf` or a shard holding `per_layer_token_embd.weight`
|
||||
(`generate.cpp:1800-1815`), and without `--native` the flag is "required" with `--no-ple` called a
|
||||
"diagnostic ablation" (`:1843-1855`, rows 62, 63). The change is to make the absence of the tensor the
|
||||
normal case when the architecture has no PLE. The fixed `NG_HIST x NG_HC_DIM` history buffer (about 360 KB,
|
||||
`session.cpp:50-52`, row 29) and the `blk.1.ple_key` special cases (row 65) are dead but harmless.
|
||||
|
||||
### 3.10 The MTP drafter
|
||||
|
||||
The drafter is its own pack: `<rt_dir>/dense.txt`, `dense.bin` (every dense weight Q8_0), `experts.bin`
|
||||
written by `tools/mtp_rt.py` (`mtp.cpp:150-216`, row 70). It expects vLLM-style names
|
||||
(`fc_embedding`, `fc_hidden`, `pre_fc_norm_*`, `self_attn.*`, `mlp.shared_expert.*`, `mlp.gate`,
|
||||
`mlp.shared_expert_gate`, three `*hyper_connection*` groups; `mtp.cpp:210-212, 488-495, 503-507, 575`),
|
||||
canonical Q2_0 experts of `n_expert x BLOB` bytes in VRAM through `moe_group_resident` /
|
||||
`moe_grouped_s2` (`mtp.cpp:191, 579-583`; `s2_expert_grouped.cu:37-46` bakes 2560/640, row 121), and the
|
||||
default geometry (`generate.cpp:3026`, "the canonical model's MTP head (512 experts)", row 12).
|
||||
|
||||
Qwen3.6's draft block (`gguf-metadata.md`, "The nextn block"): `concat(rms_norm(emb) * enorm, rms_norm(h)
|
||||
* hnorm)` (embedding first) through one `eh_proj [4096, 2048]`, then a plain attention + MoE block
|
||||
(`attn_norm`, joint q+gate, q/k norm, IMRoPE, causal over its own KV, sigmoid gate, `attn_output`,
|
||||
residual, `post_attention_norm`, the same top-8 MoE plus gated shared expert, residual), `shared_head_norm`,
|
||||
the main `output.weight`. Pairing: token k with the trunk's output-normed hidden state of k-1
|
||||
(`oracle-crosscheck.md`, "Nextn / MTP"; verified at every nextn seam, 50 of 50). What the drafter keeps:
|
||||
dense attention over its own KV ring (rows 76), the main head and the `draft_vocab.bin` subset (row 77,
|
||||
the same 248,320 vocabulary, so `data/draft_vocab*.bin` carry over), `token_embd` embeds (row 78). What
|
||||
changes: the two input projections become one `eh_proj` over the concatenation (`mtp.cpp:488-495`); the
|
||||
three hc groups become three norms (`:503-507, 564-568, 613-625`; the prefill-side pass at
|
||||
`prefill.cpp:972-1086` the same); the draft experts are 256 K-quant blobs (Q5_K/Q4_K, 464 MiB in the
|
||||
Q4_K_XL file; Q3_K/Q4_K, 364 MiB in the IQ4_XS file) served by the native GPU expert kernels
|
||||
(`iq_kernels.cu`, row 120) instead of the Q2_0 grouped kernel; the geometry follows the target.
|
||||
|
||||
A Qwen3.6 draft pack: `dense.txt`/`dense.bin` with llama.cpp's names (`nextn.eh_proj`, `nextn.enorm`,
|
||||
`nextn.hnorm`, `nextn.shared_head_norm`, `attn_norm`, `post_attention_norm`, `attn_{q,k,v,output}`,
|
||||
`attn_{q,k}_norm`, `ffn_gate_inp` BF16, `ffn_gate_inp_shexp` BF16, `ffn_*_shexp`), the projections kept
|
||||
Q8_0 as stored (39 MiB), and a `native_experts.txt`-style line for the one layer's three expert tensors.
|
||||
Because the drafter is separate from the trunk file, the pack cut from the Q4_K_XL file's `blk.40` serves
|
||||
the IQ3_XXS trunk too (the plain IQ3 file has no nextn block). Draft acceptance is an empirical question per
|
||||
model; llama.cpp's own MTP arm (B4) is the external reference.
|
||||
|
||||
### 3.11 Tokenizer, chat template, vision
|
||||
|
||||
Same vocabulary and the same `qwen35` pre-tokenizer family (`gguf-metadata.md`; `tools/strata_tokenizer.py`
|
||||
refuses schemes it has not transcribed, `upstream-tooling.md` section 2). The front end uses llama.cpp's
|
||||
chat parser (`frontend/chat_parser_test.cpp`) and carries the Qwen3-Coder any-argument-order patch
|
||||
(`chat_parser_test.cpp:48`); the plan's step 5 checks it against Qwen3.6's template with
|
||||
`make test-chat-parser MODEL=<gguf>` (`Makefile:35-41`). Vision loads an mmproj through `mtmd`
|
||||
(`frontend/vision.hpp:79-87`); the `Qwen3.6-35B-A3B-MTP-GGUF-mmproj-F16.gguf` is on the VM with its SHA-256
|
||||
(`phase0-notes.md`). Nothing in the engine changes for either.
|
||||
|
||||
## 4. The memory plan
|
||||
|
||||
### 4.1 The fixed set, from measurements
|
||||
|
||||
| Item | Q4_K_XL, 262,144 | IQ3_XXS, 262,144 | Source |
|
||||
| --- | ---: | ---: | --- |
|
||||
| Non-expert weights on the GPU | 2,038 MiB | 1,597 MiB | `-lv 4` minus resident expert layers (section 1); census |
|
||||
| Draft block: 40 MiB dense + 256 experts in VRAM + ring KV + 8 x 248,320 logits | ~520 MiB | ~520 MiB (the Q4 draft pack) | census; `mtp.hpp:19`; `mtp.cpp:430-436` |
|
||||
| KV, q4_0, 10 layers | 1,440 MiB | 1,440 MiB | `phase0-notes.md` smoke rows (both arms) |
|
||||
| Session: RoPE table 64 MiB, scratch; **plus 320 MiB of indexer state unless 3.3 item 4 removes it** | ~164 MiB | ~164 MiB | `layer.cpp:559-576` |
|
||||
| CUDA context | ~230 to 300 MiB | same | nvidia-smi 9,487 (peak 9,565) minus the three buffers, Q4 row |
|
||||
| Reserve | 300 MiB (`kSmallReserveMib`) to 700 (default) | same | `generate.cpp:424, 3249` |
|
||||
| Prompt buffers: borrowed from the cache with a profile, else chunk-sized | 0 (borrow) / 1,904 MiB at chunk 2048 | 0 / 1,878 MiB | `generate.cpp:2723`; llama.cpp `-ub 2048` compute buffer |
|
||||
| **Decode-time fixed set** | **~4,760 MiB** borrowing; ~6,660 without | **~4,320** borrowing; ~6,200 without | sum |
|
||||
| Trunk experts (file) | 18,726 MiB; 1.829 MiB mean, 2.195 max | 10,594 MiB; 1.035 mean, 1.172 max | census |
|
||||
| Dense split-K attention scratch at `cap = 262,144` | 64.5 MiB per query row (516 for the verify window) | same | `qsa_decode_attn.cu:489-491` |
|
||||
|
||||
The replay and the plan used a 5.8 GB (Q4) / 4.6 GB (IQ3) fixed set that includes the 1.9 GB prompt buffer
|
||||
and excludes the drafter, and 17.4 GB / 10.5 GB of experts (`phase0-replay.md`, "Budget to slots"). The
|
||||
census moves the expert total up by 7% at Q4 and the fixed set down by the prompt buffer when prefill
|
||||
borrows; the two roughly cancel at the 11 GB rung (table 4.4).
|
||||
|
||||
### 4.2 The VRAM planner (Phase 2 step 2)
|
||||
|
||||
What exists: `--expert-cache auto` reads free VRAM, subtracts the reserve and the prompt estimate, grants
|
||||
slots at `max_blob` (`generate.cpp:3232-3300`), then for a native pack with a profile re-prices the slots
|
||||
per layer so the same VRAM holds the profile's hottest experts at their own blob sizes
|
||||
(`generate.cpp:3307-3327`, "~30% more IQ3_XXS experts than slots of the largest blob"); the prompt path
|
||||
borrows the last slots (`:4404-4425`); below `min_slots` the reserve shrinks to 300 MiB and then the start
|
||||
refuses with the numbers (`:3267-3290`, "no VRAM is left for the expert cache"). What the step adds, in the
|
||||
plan's order with one change:
|
||||
|
||||
1. Fixed set first: weights, drafter, KV for the requested context, session. **KV streaming is not a lever
|
||||
for this model** (3.3 item 6): the resident-window floor of 20,480 cells (`layer.cpp:556`) exists for a
|
||||
selection of 2,051 cells, and dense attention reads every cell. So the rule's first fallback, "stream
|
||||
the KV to RAM above a resident window", is replaced by: hold the KV in VRAM, and if the fixed set does
|
||||
not fit, lower the context toward 131,072, then refuse with the numbers and the IQ3 file's name. Never
|
||||
silently shorten.
|
||||
2. Every remaining byte becomes expert slots, sized per layer from the profile as today.
|
||||
3. The RAM tier: free RAM minus a headroom (`--resident-experts` uses 4 GiB, `generate.cpp:1508`;
|
||||
`--resident-budget-gib N` sets it, `:1516-1520`), filled with the next experts by profile rank
|
||||
(`pin_cache_complement`, `expert_source.cpp:1331`); whatever remains stays mapped from the GGUF
|
||||
(`--mmap-experts`, `:618-680`) with the `MADV_WILLNEED` warm on predicted ids (`:1129-1160`).
|
||||
4. Emulation: `--vram-cap MiB` clamps every `cudaMemGetInfo` free figure the planner reads (`:3297, 3313`)
|
||||
to `cap - used` and, so the driver sees the same pressure the real card would, allocates a blocker of
|
||||
`total - cap` at start; `--ram-cap GiB` bounds `resident_budget` and the pinned arena. The page cache
|
||||
cannot be capped from inside the process; the 12 GiB VM does that physically, and on a larger host a
|
||||
cgroup `memory.max` does.
|
||||
5. The start-up log and `/health` state the three counts (VRAM slots, RAM copies, mapped) and per-token
|
||||
counters: VRAM hits (`cache_hits`), RAM-copy hits, warm-hint count (`warm_count_`), and disk reads as
|
||||
the major-fault delta from `/proc/self/stat`, since a page-cache miss is not otherwise observable.
|
||||
|
||||
### 4.3 The 6-to-32 GB ladder
|
||||
|
||||
Budgets in the replay's decimal convention (6 GB = 5,722 MiB) except the 1080 Ti (11,264 MiB) and a 24 GB
|
||||
card (24,576 MiB). Slots at the census mean blob; "borrow" is the decode-time fixed set of 4.1, "no borrow"
|
||||
adds the chunk-2048 prompt buffer.
|
||||
|
||||
| Budget | Q4 replay basis (5.8 GB fixed, 1.70 MB/expert) | Q4 derived, no borrow | Q4 derived, borrow | IQ3 replay basis | IQ3 derived, borrow |
|
||||
| --- | ---: | ---: | ---: | ---: | ---: |
|
||||
| 6 GB | 80 (1%) | 0 (fixed set does not fit) | ~525 (5%) | 1,360 (13%) | ~1,350 (13%) |
|
||||
| 8 GB | 1,280 (12%) | ~525 (5%) | ~1,570 (15%) | 3,280 (32%) | ~3,200 (31%) |
|
||||
| 11 GB (decimal) | 3,040 (30%) | ~2,090 (20%) | ~3,130 (31%) | 6,240 (61%) | ~5,960 (58%) |
|
||||
| 1080 Ti, 11,264 MiB | | ~2,510 (25%) | ~3,550 (35%) | | ~6,700 (66%) |
|
||||
| 12 GB | 3,640 (36%) | ~2,610 (26%) | ~3,650 (36%) | 7,200 (70%) | ~6,880 (67%) |
|
||||
| 16 GB | 6,000 (59%) | ~4,700 (46%) | ~5,740 (56%) | all | all |
|
||||
| 24 GB (24,576 MiB) | all | ~9,790 (96%) | all, ~1,090 MiB spare | all | all |
|
||||
| 32 GB | all | all | all | all | all |
|
||||
|
||||
The RAM tier at the replay's 9.5 GB usable: Q4 ~4,950 experts at the census blob (the replay's 5,590 was at
|
||||
1.70 MB), IQ3 ~8,760. The disk tier at Q4 on the 1080 Ti is then 10,240 - 3,550 - 4,950 = ~1,740 experts
|
||||
(17%) with borrowing and ~2,780 (27%) without; the replay modelled 1,610 (16%). At IQ3 everything fits VRAM
|
||||
plus RAM at every rung from 6 GB (`phase0-replay.md`, finding 5). The planner's own log at `--vram-cap`
|
||||
6/8/11/12/16/24/32 is the check of this table, within one slot of the derivation.
|
||||
|
||||
## 5. Expected envelope per budget
|
||||
|
||||
From `phase0-replay.md` (LFU, profile seed, second half of a 214,940-token trace of the IQ3_XXS model,
|
||||
decode only; the Q4 arm reuses the IQ3 routes). The parameters are parameters: `gpu_ms` 17 (an upper
|
||||
estimate from the smoke rows' busy share; 12 is a flag away), `cpu_lane_ms` 0.15 per expert (llama.cpp
|
||||
IQ3 N=18 implies 0.17), `disk_ms` 1.3 (fio 1 MiB random QD4; parallel faults may halve it), `pcie_ms` 0
|
||||
(promotions counted, not charged: 47.7 copies per token at Q4 11 GB, about 12 ms at 0.26 ms each, is the
|
||||
largest omission; charging it takes Q4 11 GB LFU from 42.5 to 27.8 tok/s). "Overlap" is
|
||||
`1000 / max(gpu, cpu, disk)`, "serial" the sum.
|
||||
|
||||
| Budget | Q4 VRAM hit | Q4 disk reads/tok | Q4 tok/s overlap / serial | IQ3 VRAM hit | IQ3 disk/tok | IQ3 tok/s overlap / serial |
|
||||
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
|
||||
| 6 GB | 0.0% | 70.7 | 7.7 / 6.8 | 59.7% | 0 | 51.7 / 27.5 |
|
||||
| 8 GB | 57.9% | 51.5 | 12.6 / 10.4 | 84.4% | 0 | 58.8 / 40.9 |
|
||||
| 11 GB | 82.6% | 13.2 | 42.5 / 24.7 | 96.0% | 0 | 58.8 / 52.9 |
|
||||
| 12 GB | 86.8% | 7.1 | 58.8 / 31.8 | 97.7% | 0 | 58.8 / 55.2 |
|
||||
| 16 GB | 95.5% | 0 | 58.8 / 52.2 | 100% | 0 | 58.8 / 58.8 |
|
||||
| 24, 32 GB | 100% | 0 | 58.8 / 58.8 | 100% | 0 | 58.8 / 58.8 |
|
||||
|
||||
58.8 is `1000 / gpu_ms` and the overlap column saturates there by construction. The Belady ceiling at Q4
|
||||
11 GB is 91.0% hit, 6.6 disk reads, 58.8 / 34.6. Against it, the llama.cpp smoke points on the same card:
|
||||
Q4 N=32 **8.78 tok/s** decode, 128.6 prefill, GPU busy 15%; IQ3 N=18 **24.58** decode, 433.9 prefill, GPU
|
||||
busy 41% (`phase0-notes.md`). The plan's floors (A2: 15/10 tok/s at 8K/32K on 11 GB, 10/7 on 6 GB, 60/45 on
|
||||
24 GB; A3: 300 tok/s prefill on Pascal) sit inside these predictions except the Q4 6 GB row, which the
|
||||
plan already routes to the IQ3 file. With the census tiers (4.3) the Q4 11 GB disk term is 17 to 27% of
|
||||
experts rather than 16%, so its disk reads per token sit above 13.2; the replay is re-run with the census
|
||||
blob sizes as part of step 2, not re-derived here. Prefill is not modelled; the engine's chunked MMQ path
|
||||
amortises expert bytes across the chunk, and on Pascal the prompt MoE's fast path is a risk (section 7).
|
||||
|
||||
## 6. Execution plan (Phase 2, steps 2 to 7)
|
||||
|
||||
Step 1, the oracle and fixture, is done on `qwen36-oracle`: `ref/qwen36.py` agrees with the pinned
|
||||
llama.cpp graph on 2,155 comparisons over 116 seam families at 1.1e-4 worst absolute error, the router's
|
||||
integers identical, and all seven rival readings fail at the seam that makes them (`oracle-crosscheck.md`).
|
||||
Every harness below holds the engine to those dumps by llama.cpp's `cb()` names. Each step has a parity
|
||||
harness in the repo's negative-test discipline (`gdn_parity.cpp`: every wrong reading must differ by more
|
||||
than 5% relative L1 before the right one is judged, `upstream-tooling.md` section 3), runs on the 1080 Ti
|
||||
under `STRATA_EXPERIMENTAL_SM60=ON` (sm_61) from the first build and on a rented sm_86 card for compile
|
||||
speed; a kernel passes when it passes on both. Steps 2 to 4 need seconds of GPU per run and proceed while
|
||||
the Phase 0 sweeps hold the card. Effort weights sum to 100 for steps 2 to 7.
|
||||
|
||||
**Step 2, geometry, metadata, sizing (15%).** Files: `gguf_reader.hpp:576-597` (accept `qwen35moe`, read
|
||||
the 3.8 key set), `layout.hpp:27-59` (`hc = 1`, derived conv channels and value dim, no indexer fields),
|
||||
`generate.cpp:2008-2010, 2073-2096, 2184-2186, 771, 795` (geometry from the file before the layout load;
|
||||
the embedding dims from it), `expert_layout.cpp:284` (the leak), `expert_source.cpp:2475-2500` (fused
|
||||
forms refused by name), `generate.cpp:1800-1815, 1843-1855` (PLE optional), the planner
|
||||
(`generate.cpp:3232-3327`) with the 4.2 rule, `--vram-cap`, `--ram-cap`, the counters, `tools/make_profile.py`
|
||||
(`N_LAYER = 48`). Harness: `ModelGeometry` from the synthetic GGUF (`tools/qwen36_synth_gguf.py`) and the
|
||||
real file equals the oracle's `HParams` field by field; the planner's log at the seven caps reproduces
|
||||
table 4.3. Negative tests: a `qwen4exp` file refused with its name; a 48 x 512 profile refused
|
||||
(`expert_cache.cpp:43`); a `--fused-gate-up` fixture refused by tensor name; `--vram-cap` below the fixed
|
||||
set refuses with the context it would need. No GPU beyond the planner's run.
|
||||
|
||||
**Step 3, kernels and the block (45%).** In order of risk:
|
||||
|
||||
- *GDN (3.2):* SiLU in the four kernels; `gdn_parity.cpp` at `h_v 32` with sigmoid as the negative, plus the
|
||||
existing four traps (pairing, decay order, conv direction, l2 epsilon); `gdn_rec_parity.cu` at `VPK 2`.
|
||||
Seams: `conv_output_silu-0`, `new_state-0`, `final_output-0`.
|
||||
- *Dense attention (3.3):* the identity-`ids` producer; `G` templated at 8; the indexer skipped in
|
||||
`qsa_layer` and the verify attention step; the state without indexer buffers; `cap = max_cells`; the
|
||||
split-K scratch bounded. Harness: `qsa_parity.cpp`'s attention cases with `ids` identity against the
|
||||
oracle's `kq_soft_max-3`, `kqv-3`, `attn_gated-3`, and a 300-cell case where the old width (2,051) and
|
||||
the dense width differ. Negative tests: `G = 12` on 16 heads (refused, not mis-indexed), the gate skipped
|
||||
(1.03 relative L1 at `attn_gated-3`), adjacent-pair RoPE (0.20 at `kqv-3`), both from the oracle's
|
||||
controls.
|
||||
- *Router and shared expert (3.4):* `router_top10_parity.cpp` at 256/8 with its tie fixtures; the BF16
|
||||
rounding of the F32 router measured as a flip rate on the real file's first 8 tokens with the quantized-
|
||||
mode gates; `shared_expert_parity.cpp` at 512 with the 1-D F32-to-BF16 gate. Seams: `ffn_moe_topk-N`,
|
||||
`ffn_moe_weights_norm-N`, `ffn_shexp_gated-N`.
|
||||
- *The block without hyper-connections (3.5):* `layer.cpp` and `verify.cpp` both, `session.cpp:141-148`,
|
||||
the head. Harness: the layer composition test, Maya's shape: layer 0 (GDN + MoE) and layer 3 (attention +
|
||||
MoE) of the synthetic model through the engine's kernels, every seam held to the dumps; then the verify
|
||||
window on an 8-token sequence against the oracle's `l_out-N` per position, with the window's row
|
||||
arithmetic required to equal the single-token path (the discipline `verify.cpp:773-774` already states).
|
||||
Negative tests: the GR read with identity weights (not a plain norm), the post-attention norm skipped,
|
||||
`k = 10` on an 8-expert file.
|
||||
- *Prefill (3.6):* the constants and the eight literal sites; the GDN kernels forked at 32/16/8192; the
|
||||
route kernel at `k`; the split-q and gate kernels at 16 heads; `moe_fused_iq.cu` at 2048/512. Harness:
|
||||
the restored `tests/cuda/prefill_*_test.cpp` plus chunked-prefill-then-decode against token-by-token
|
||||
decode on a 40-token sequence (the oracle's `base_c7` case: chunks of 7). Negative tests: `VPK 3` on 32
|
||||
heads, top-10 routing on 8.
|
||||
|
||||
**Step 4, pack, drafter, runner (20%).** `tools/iq_pack.py`: a `qwen35moe` entry in `FORM`/`ROUTERS`
|
||||
(`ssm_alpha`, `ssm_beta`, `ffn_gate_inp`, `ffn_gate_inp_shexp` F32 to BF16 under `--compat-bf16` with
|
||||
`compat-bf16.json`; norms, `ssm_a`, `ssm_dt.bias`, `ssm_conv1d` F32 copied; projections served natively),
|
||||
`native_experts.txt` v3 per layer; `tools/test_iq_pack.py`'s `write_gguf()` fixtures at the new
|
||||
architecture. The draft pack of 3.10 from the MTP file's `blk.40` (a new `tools/mtp_qwen36_pack.py`
|
||||
replacing `mtp_pack.py`/`mtp_rt.py`), `mtp.cpp` and `prefill.cpp:972-1086` on the plain graph, the draft
|
||||
experts through the native GPU kernels, `generate.cpp:3026` following the target. `make_profile.py` from
|
||||
the E0 trace (40 x 256). Harness: the drafter's one-row forward against the oracle's `--mtp` dumps
|
||||
(`mtp_eh_proj`, `mtp_attn_gated`, `mtp_ffn_out`, `result_output`; 50 nextn seams); the streaming runner
|
||||
held to the oracle at every position of the 11- and 40-token cases, autoregressive and chunked
|
||||
(`base_ar`, `base_c7`); then the real Q4 file, greedy, against llama.cpp's output distribution (top-1
|
||||
agreement and KL per teacher-forced position, Maya's quantized-mode gates: no monotone positional drift,
|
||||
selection equal at probed layers). Negative test: a 4 KB weight corruption must move the logits by more
|
||||
than 1e-2 (the mutation-sensitivity gate).
|
||||
|
||||
**Step 5, serve and measure (10%).** The 1080 Ti at 11 GB, then `--vram-cap` 8 and 6; the other rungs when
|
||||
a card frees up. `tools/calibrate.py` for `--pcie-frac`, `--spec-min-p`, `--pool-workers`; regina's harness
|
||||
and the three instruments (`nvidia-smi` 100 ms, `nvprof` on Pascal, `perf stat`); the engine's points on
|
||||
`ladder-baseline.png`; H5. `make test-chat-parser MODEL=<gguf>` against the template; the any-argument-order
|
||||
patch checked for misfires; images through `--mmproj`. Acceptance A1 to A5 per rung.
|
||||
|
||||
**Step 6, the Pascal cards and the fat binary (5%).** `CMakeLists.txt:138-176`: `STRATA_EXPERIMENTAL_SM60`
|
||||
default ON, `CMAKE_CUDA_ARCHITECTURES=61;70;75;86;89;120`, CUDA 12.8 (the sm_120-with-12.8 warning at
|
||||
`:166-169` stays; RTX 50 is built, not measured). `cuobjdump --list-elf | grep sm_` after every build. The
|
||||
1070 Ti and the 1060 against B1b; the sm_75+ paths checked on the 4090 or A6000 when one is free.
|
||||
|
||||
**Step 7, README (5%).** The supported model and checksums, the ladder against the baseline, the sizing
|
||||
rule in words, the Pascal caveats.
|
||||
|
||||
The critical path runs through step 3's block-and-verify rewrite and its composition harness; the dense
|
||||
attention kernel is the one new kernel, the rest is parameterisation and removal.
|
||||
|
||||
## 7. Risks
|
||||
|
||||
1. **Nobody has run this engine on Pascal.** The build refuses `cc < 75` without the experimental flag;
|
||||
the flag is "community-tested, not in the ready-made engine" for sm_60/sm_70 (`CMakeLists.txt:150-160`),
|
||||
and Maya requires Volta. The 1080 Ti is sm_61, so `__dp4a` is native and only the `__nanosleep` shim
|
||||
applies (`dp4a.hpp:27-40`).
|
||||
2. **FP16 on GP102/GP104/GP106 runs at 1/64 rate.** 21 kernel files touch half types. Conversions
|
||||
(`__half2float`, the `hf()` stores in `prefill/kernels.cu:614, 761`, the fp16 K/V reads in
|
||||
`qsa_decode_attn.cu`) are full rate; half *arithmetic* is not. The audit must separate the two in
|
||||
`native_mmvq.cu`, `iq_kernels.cu`, `s_gemv.cu`, `shared_expert.cu` and the prefill kernels. The prompt
|
||||
MoE is the exposed case: the MMQ (dp4a) path is gated by `mmq::built()`/`mmq::fits`
|
||||
(`prefill.cpp:676-684`) and its tests exit 77 below sm_80 (`CMakeLists.txt:1076`); the fallback is the
|
||||
FP16 GEMM path over dequantized fp16 weights (`prefill.cpp:907`), which is exactly the slow case. The
|
||||
A3 floor of 300 tok/s prefill on Pascal depends on the dp4a MMQ running on sm_61, where llama.cpp's own
|
||||
MMQ does run.
|
||||
3. **Prompt attention on Pascal is the decode kernel.** `qsa_prompt_attn_batch` returns false for
|
||||
`cc < 70` (`qsa_prompt_attn.cu:1433`) and prefill falls back to `qsa_decode_attn_batch` over the chunk
|
||||
(`prefill.cpp:2222-2228`): correct, but a 2,048-query chunk through a decode-shaped kernel is a
|
||||
throughput risk, and its split-K scratch is the 64.5 MiB-per-row item of 3.3.
|
||||
4. **Memory items the plan did not count:** the draft block (~520 MiB), the dead indexer state (320 MiB
|
||||
at 256K unless removed), the dense scratch, and the uniform-slot grant before the per-layer re-pricing
|
||||
(`generate.cpp:3307-3327`), which is 17% of capacity at Q4 (2.195 versus 1.829 MiB) if the profile is
|
||||
absent and the re-pricing does not run.
|
||||
5. **KV streaming does not apply** (3.3 item 6): a 6 GB card at 256K holds the KV in VRAM or lowers the
|
||||
context; there is no third option in this engine without a CPU attention path.
|
||||
6. **Numerical:** BF16 rounding of the F32 router and GDN gates (3.4); the router's flip rate is measured
|
||||
on the real file, and the acceptance gates are top-1 and KL, not per-logit tolerances, as Maya's
|
||||
cross-check found (two flips in 512 explained by 1e-5 selection gaps).
|
||||
7. **Verify-only decode.** Every token of a native pack goes through `verify.cpp` with `--spec T >= 2`
|
||||
(`generate.cpp:2178`); the plain IQ3 file has no draft block, so its drafter is the Q4 file's `blk.40`
|
||||
(3.10). Draft acceptance on Qwen3.6 is unmeasured; the prompt-lookup drafter alone leaves short windows.
|
||||
8. **The replay's model:** `pcie_ms` 0, one IQ3 trace reused for Q4, a cache that never resets, no
|
||||
prefill, `gpu_ms` an upper estimate (`phase0-replay.md`, "Limits"); the census blob sizes shift the Q4
|
||||
disk tier up (4.3). The engine's counters, not the replay, decide H4 and H6.
|
||||
9. **The host.** VM 211 has 8 vCPU of a Zen 1 shared with VM 220 and AVX2 only; the native expert path then
|
||||
runs ggml-cpu `vec_dot` for the i-quants and the AVX-2 kernels for the rest (`generate.cpp:2068-2072`).
|
||||
The 0.15 ms CPU lane is the replay's assumption; `perf stat` measures it.
|
||||
10. **Upstream tooling gaps:** no published Python oracle for the Flash-Next kernels, so the parity files'
|
||||
C++ references are the only pins of the existing semantics (`upstream-tooling.md` section 1); the
|
||||
`bench/micro` llama.cpp-oracle tests cannot be restored.
|
||||
|
||||
## 8. Disagreements with the plan
|
||||
|
||||
1. **Section 2, the sizing rule's first fallback ("stream the KV to RAM above a resident window").** Not
|
||||
available for dense attention (3.3 item 6): streaming resolves the selected cells, and every cell is
|
||||
selected. The rule becomes KV in VRAM, then lower the context, then refuse. H3's "6 GB needs the KV
|
||||
streamed" is replaced by: 6 GB at Q4 holds the fixed set at 256K only if prefill borrows from the cache
|
||||
(~525 slots, table 4.3), else it takes 131,072 or the IQ3 file.
|
||||
2. **Section 2, the fixed set.** Non-expert weights are 2,038 MiB at Q4 and 1,597 at IQ3, not ~3.1 / ~1.9
|
||||
GB; the prompt buffer is 1.9 GB at chunk 2048, not 0.8; the drafter (~520 MiB) is missing from the
|
||||
table. The plan says Phase 0 numbers replace the estimates; this study does so and adds the drafter.
|
||||
3. **Section 2, the expert totals.** Q4 trunk experts are 18,726 MiB (19.6 GB), 1.829 MiB mean and 2.195
|
||||
max per expert, not 17.4 GB / 1.7 MiB; IQ3 agrees (10,594 MiB). The 11 GB rung's tiers at Q4 shift to
|
||||
~3,550 VRAM / ~4,950 RAM / ~1,740 disk with borrowing, and the replay's 13.2 disk reads per token is a
|
||||
lower bound until it is re-run at the census sizes.
|
||||
4. **Section 5 step 3, "`native_flash_attn.cu` is the fallback for prompts."** It is a diagnostic adapter
|
||||
for contexts up to 256 with 24 heads hard-coded (`native_flash_attn.cu:196-206`, `layer.hpp:53`). The
|
||||
prompt path is `qsa_prompt_attn.cu`, and on Pascal it is the batched decode kernel (risk 3). The dense
|
||||
prompt attention comes from parameterising those two, not from `native_flash_attn.cu`.
|
||||
5. **Section 5 step 2, "accept llama.cpp's fused `ffn_gate_up_exps` and `attn_qkv` forms or split them at
|
||||
pack time."** No shipped Qwen3.6 file uses either (`gguf-metadata.md`). The study scopes this to a
|
||||
named refusal in `check_experts_gguf` and `native_dense.cpp:31-33`; the oracle's fused cases stay as
|
||||
evidence of the layouts should a file appear.
|
||||
6. **Section 5 step 2, "per-layer prefetch hints as Maya's section 7 added."** This tree already has them:
|
||||
`FileExpertSource::warm` issues `MADV_WILLNEED` per role (`PrefetchVirtualMemory` on Windows) for the
|
||||
predicted ids (`expert_source.cpp:1129-1160`, `1264`). Nothing is ported from Maya; step 2 verifies the
|
||||
hint fires on the Qwen3.6 pack's offsets and counts it.
|
||||
7. **Section 2, "which file" (Q4_K_M-MTP, or Q4_K_XL plus a separately packed head).** The Q4_K_XL from the
|
||||
MTP repository (rev 5bc3e238, SHA in `phase0-notes.md`) already carries `blk.40` (753 tensors). It is
|
||||
the default file, and its `blk.40` is the draft pack for both arms (3.10).
|
||||
8. **Section 1, "every kernel path on these cards must be FP32 or dp4a int8."** Agreed for arithmetic;
|
||||
fp16 *storage* with conversion (the KV pools, the fp16 stores in prefill) is full rate on Pascal and
|
||||
stays. The prompt MoE's dp4a MMQ must be enabled on sm_61 (risk 2), which the plan does not list.
|
||||
|
||||
Nothing else in Sections 0, 2 and 5 is contradicted: the target, the three tiers on the primary rung, the
|
||||
Q4 default with the IQ3 arm, the Pascal-first build, the step order and the acceptance thresholds stand.
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
# Qwen3.6-35B-A3B: pictures, several requests at once and speed
|
||||
|
||||
PolyStrata runs [Qwen3.6-35B-A3B](https://huggingface.co/Qwen/Qwen3.6-35B-A3B) (35B mixture of experts, 3B active, 256 experts, top-8) from
|
||||
[Unsloth's GGUFs with the MTP layer](https://huggingface.co/unsloth/Qwen3.6-35B-A3B-MTP-GGUF) (UD-Q4_K_XL, UD-Q6_K_XL, Q8_0)
|
||||
on the Strata project's own engine path (`src/qwen35`; `strata` switches to it from the file's architecture). Pick it in
|
||||
setup (`--family qwen36-strata`); `--family qwen36` runs the same model on strata-poly instead
|
||||
([BACKENDS.md](BACKENDS.md#qwen36-on-two-engines)). Besides text it
|
||||
reads **pictures** and serves **several requests at once**, the same two options the Flash-Next models have.
|
||||
|
||||
Measured by the Strata project on an AMD Radeon AI PRO R9700 32 GB (HIP, Linux, UD-Q4_K_XL, every expert in VRAM) and on an RTX 3060 12 GB (CUDA, 20 threads,
|
||||
UD-Q4_K_XL in the hybrid mode: 22-37 of 256 experts per layer in VRAM, the rest on the CPU), llama.cpp 972b5fc on the same files.
|
||||
|
||||
## Pictures
|
||||
|
||||
The vision encoder is Unsloth's `mmproj-F16.gguf` (0.9 GB, pinned revision, SHA-256 checked by setup): a 27-layer ViT with a 2x2 merger,
|
||||
the same projector family as the Flash-Next models' (`qwen3vl_merger`; only its output width differs: 2048 here, 2560 there). PolyStrata runs
|
||||
it with the same helper (`strata-vision`, llama.cpp's `mtmd`), so the encoder choices are the Flash-Next ones
|
||||
([Images](DETAILS.md#images-vision)): **setup asks "Do you want images?"**, the default answer is yes on an NVIDIA card of 16 GB or more
|
||||
(GPU encoder, ~1.2 GB of VRAM at up to 1,024 image tokens) and on AMD under Linux (CPU encoder, no VRAM); `--vision yes|no|gpu|cpu`
|
||||
and `--vision-tokens N` work as there. A card under 16 GB is recommended the CPU encoder (the GPU one takes room from the experts);
|
||||
`--vision gpu` is kept as asked, with a note.
|
||||
|
||||
| Encoder | Time per picture (640x400 = 260 tokens / 800x450 = 350 tokens) | VRAM |
|
||||
| --- | --- | --- |
|
||||
| GPU, RTX 3060 | 0.10 s / 0.15 s | 1,179 MiB at up to 1,024 tokens (1,337 MiB at 2,048), CUDA context included |
|
||||
| CPU, 32 threads (R9700 box) | 0.9 s / 1.1 s | none |
|
||||
| CPU, 10 threads (3060 box) | 1.6 s / 2.1 s | none |
|
||||
|
||||
A picture becomes up to 1,024 tokens of the context (the CPU default is 300). The engine puts the encoder's rows where the prompt has
|
||||
`<|image_pad|>` tokens and gives every row its 2-D position, interleaved M-RoPE exactly as llama.cpp does for this model (rotary sections
|
||||
11 / 11 / 10, a picture's rows at (t, h, w) = (p, p + row, p + column), the text after it continuing at p + max(columns, rows)).
|
||||
|
||||
**Checked against llama.cpp** (its `mtmd` and its own graph, the encoder on the CPU on both sides, the same prompt ids, the answer
|
||||
llama.cpp gives fed to both so the logits are compared step by step, 24 steps; the "floor" is llama.cpp's CPU backend against its own
|
||||
HIP run, the noise two correct engines have on this model):
|
||||
|
||||
| Picture and question | Prompt tokens | First token | Mean KL, llama.cpp HIP vs PolyStrata | Floor (llama.cpp CPU vs HIP) |
|
||||
| --- | ---: | --- | ---: | ---: |
|
||||
| 640x400, text in the image | 288 | same | 0.029 | 0.056 |
|
||||
| 640x400, list the shapes | 294 | same | 0.035 | 0.039 |
|
||||
| 800x450, text in the image | 378 | same | 0.021 | 0.031 |
|
||||
| 800x450, describe the shapes | 381 | same | 0.0005 | 0.0019 |
|
||||
| 1024x1024, the title (1,024 image tokens, read in 3 chunks) | 1,042 | same | 0.0022 | 0.0026 |
|
||||
| two pictures in one request, the text in each | 655 | differs (a near tie: the floor's KL at this step is 0.16 too) | 0.014 | 0.022 |
|
||||
|
||||
The answers are the same text as llama.cpp's: `STRATA 42` (with llama.cpp's own spelling ` STRATA42`), `CODE 4217`, `Red circle / Blue square
|
||||
/ Green triangle`, `A red square is positioned on the left ... A blue circle is positioned on the right ...`. With the picture options on,
|
||||
a request without pictures gives the same tokens as without them (10 prompts x 128 greedy tokens, identical).
|
||||
|
||||
Pictures work with several requests at once, with the MTP drafts and with the conversation cache: the same conversation sent again (a chat
|
||||
app resends its pictures) continues from the held state when its pictures are the same (they are matched by the server's key for each
|
||||
picture); a different picture starts that conversation again.
|
||||
|
||||
## Several requests at once
|
||||
|
||||
`"parallel": N` in the model's config (`strata-qwen36s-<size>.json`, or `--parallel N` at setup) makes the engine keep N conversations open
|
||||
(`--batch N`, up to 8) and decode them together: every window carries one token of each conversation, so the dense weights, the head and
|
||||
every routed expert two conversations share are read once for all of them. The server needs no change: it speaks the same engine protocol
|
||||
as for Flash-Next ([BATCHING.md](BATCHING.md)). A request that arrives while another is read waits only for that read: the prompt of a
|
||||
new request is read **between** the decode windows of the others, and a conversation continues in the slot that holds its start (or the
|
||||
engine copies the longer held start from another slot). A 3,008-token prompt read in 0.95 s (3,200 tok/s, 6 chunks) beside three decoding
|
||||
slots: each of them paused at most 160 ms (one chunk) instead of the whole read, and produced 20 tokens meanwhile (one window per chunk,
|
||||
the default); `STRATA_Q36_READ_WINDOWS=4` gives them 65 tokens during a 1.14 s read (more of the time, a slower read).
|
||||
A request that runs alone (the solo path, with its MTP drafts) and is moved into a batch slot when another arrives, and back when it is
|
||||
alone again, gives the text it gives running alone (the server's hand-over reuses the held state).
|
||||
|
||||
Aggregate decode speed, N requests at once, same prompts, greedy, 128 new tokens each, wall time from the first request to the last
|
||||
answer, **R9700 32 GB, UD-Q4_K_XL, llama.cpp `llama-server -np N`** (5 interleaved pairs, median; PolyStrata `--batch 8 --mtp 0`):
|
||||
|
||||
| Requests at once | PolyStrata | llama.cpp | Ratio | Pairs faster |
|
||||
| ---: | ---: | ---: | ---: | ---: |
|
||||
| 1 | 83.9 tok/s | 73.8 | 1.14 | 5/5 |
|
||||
| 2 | 173.5 | 107.4 | 1.61 | 5/5 |
|
||||
| 4 | 252.0 | 165.0 | 1.53 | 5/5 |
|
||||
| 8 | 325.4 | 208.1 | 1.56 | 5/5 |
|
||||
|
||||
**RTX 3060 12 GB, UD-Q4_K_XL in the hybrid mode** (each engine with the slots it needs: `--batch N` takes room from the expert slots; llama.cpp
|
||||
`llama-server -np N -ncmoe 28 -t 8`, the best split of a sweep on this card; 5 interleaved pairs, medians; the box was shared with other
|
||||
jobs between runs, never during one):
|
||||
|
||||
| Requests at once | PolyStrata | llama.cpp | Ratio | Pairs faster |
|
||||
| ---: | ---: | ---: | ---: | ---: |
|
||||
| 1 | 64.0 tok/s | 41.1 | 1.56 | 5/5 |
|
||||
| 2 | 85.1 | 52.5 | 1.62 | 5/5 |
|
||||
| 4 | 99.3 | 63.0 | 1.58 | 5/5 |
|
||||
|
||||
Every slot's tokens equal the tokens of the same request alone (the base engine's), at 2, 4 and 8 slots, with a 2.5K-token prompt read beside
|
||||
decoding slots, with slots reused for later requests, with pictures and with sampling (same seed). Through the server: four concurrent chat
|
||||
requests give the texts of the same four one after the other.
|
||||
|
||||
**MTP drafts.** A request that has the engine to itself keeps its MTP drafts (the server sends it alone while nothing else runs). With
|
||||
several requests the batch window has no drafts unless `--batch-mtp` is in the config's `args` (opt-in): every slot's window then also
|
||||
carries the proposal its MTP block made (one per slot, up to the rows to spare in the 8-row window) and a confirmed proposal moves two
|
||||
tokens in the window. Same prompts, 5 interleaved pairs, R9700:
|
||||
|
||||
| Requests at once | `--mtp 0` | `--mtp 2 --batch-mtp` | Ratio | Pairs faster |
|
||||
| ---: | ---: | ---: | ---: | ---: |
|
||||
| 1 | 83.7 tok/s | 134.0 | 1.60 | 5/5 |
|
||||
| 2 | 173.1 | 207.0 | 1.20 | 5/5 |
|
||||
| 4 | 251.0 | 275.0 | 1.10 | 5/5 |
|
||||
| 8 | 324.0 | 320.5 | 0.99 | 0/5 (no row to spare: no proposals) |
|
||||
|
||||
The text is the same with and without it (every slot equal to its solo tokens).
|
||||
|
||||
**What a slot costs.** Each slot keeps its own cache in VRAM: 1.5 GB at a context of 32K (fp32 keys and values of the 10 attention layers
|
||||
and the MTP block, 45 KB per token) and 0.07 GB of recurrent state. Setup writes the context for one conversation, so N slots take N times
|
||||
that from the room the experts would have: on a card that does not hold every expert (12 and 16 GB, the hybrid mode) that is room the
|
||||
expert slots lose, and a batch reads more distinct experts from RAM. Setup **offers `--parallel`** where the sessions do not eat the experts' room: up to 3-4 where every expert still fits (3 on a 32 GB card at
|
||||
32K), and on a card that does not (the hybrid mode) the count whose sessions take at most 35% of the room the experts would have, so it
|
||||
depends on the context you chose (12 GB: 4 slots at 8K, none at 32K; 16 GB: 2 slots at 32K). It says the price in the same breath, asks
|
||||
"How many requests at once?" (Enter keeps one at a time), and any number you give is kept. Measured on the hybrid cards (UD-Q4_K_XL, medians of 5
|
||||
interleaved pairs, `--mtp 2` as setup writes it; "together" = total tokens per second of N simultaneous requests, against ONE request at a time
|
||||
with the draft layer):
|
||||
|
||||
| card, context | slots | one request alone, vs 1 slot | N together, vs one at a time |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| RTX 3060 12 GB, 8K | 2 / 4 / 8 | -3.5% / -4.3% / -12% | 0.99x / 1.15x / 1.10x |
|
||||
| RTX A4000 16 GB, 32K | 2 / 4 | -10.6% / -29.9% | 1.03x / 0.76x |
|
||||
| Tesla P100 16 GB, 32K | 2 / 4 | -7% / -23% | 0.98x / 0.81x |
|
||||
|
||||
Without the draft layer (`--mtp 0`) the same slots give 1.26-1.64x together (3060 at 8K: 4 slots 1.64x for -5.5% alone), but a single request
|
||||
with drafts is already about 1.6x as fast as one without, so on a small card the main gain is that a second user starts at once; the
|
||||
speed gain is small. On a card that holds every expert (R9700 32 GB, 8K prompts) 4 slots run 1.45x one-at-a-time-with-drafts (1.59x with
|
||||
`--batch-mtp`). The engine says what the sessions take before it allocates them and refuses (with the numbers) a count that cannot fit.
|
||||
|
||||
In the hybrid mode the text of a request can differ a little between running alone and running beside others: the experts that sit on the
|
||||
GPU or on the CPU change with the routing of all the requests, and the two compute with different rounding. With the slot tables fixed (`STRATA_Q36_FIXED_SLOTS=1`, a test setting) every slot equals its
|
||||
solo run there too, with and without `--batch-mtp`.
|
||||
|
||||
## Speed (0.1.45)
|
||||
|
||||
Decode and prompt kernels of this engine path were rewritten for speed; **every change on the decode path gives the old kernels' bits**
|
||||
(`STRATA_Q36_VERIFY=1 strata ... --no-graph` runs the old kernel beside each new one on the real activations and compares them bit for bit:
|
||||
0 mismatches in 18,360 / 8,187 / 6,399 comparisons on the R9700 and the RTX 3060; `STRATA_Q36_OLD_KERNELS=1` switches them all off). The
|
||||
10 parity prompts (greedy 128) give the base engine's tokens, plain and with `--mtp 2`. Where the prompt's chunk size changes, the numbers
|
||||
change a little: see "Prompt chunk".
|
||||
|
||||
**What was slow** (rocprofv3, R9700, UD-Q4_K_XL, plain decode, 11.25 ms of kernel time per token): the big Q8_0 products (attention, GDN
|
||||
projections, head: 1.9 GB per token) run at 530 GB/s, the memory bound. The rest did not: the shared expert's and the attention k/v products
|
||||
(140 per token) at 18 us, the Q4_K gate/up kernel at 250 GB/s, `k_moe_out` (one block) 17 us, `k_group` (one thread walking 256 experts) 9 us.
|
||||
Now: those products one warp per row (a launch of 2048 warps took 21 us on gfx1201 where 1024 warps took 5 us, so the grid is capped), shared
|
||||
gate+up+SwiGLU+q8_1 in one launch, the MoE end with 1024 threads and the next layer's q8_1 image, add+norm+q8_1 in one launch, router top-k and
|
||||
grouping in one launch, the router and the shared gate in one product, Q4_K gate/up on the V2K kernels (`STRATA_EXPERT_V2K`, gfx12 default).
|
||||
The prompt's GDN conv runs in tiles of 16 tokens side by side and the delta rule loads one token ahead with two barriers per token (both exact).
|
||||
|
||||
R9700 32 GB (p620, HIP gfx1201), UD-Q4_K_XL, base = the engine before this work, 5 interleaved pairs, 3 repetitions each, medians; llama.cpp
|
||||
972b5fc HIP on the same file (`-fa 1`, best of `-ub` 512 / 2048):
|
||||
|
||||
| | base | 0.1.45 | ratio | pairs faster | llama.cpp |
|
||||
| --- | ---: | ---: | ---: | ---: | ---: |
|
||||
| decode tg128 | 83.2 tok/s | 117.8 | 1.42 | 5/5 | 81.9-82.1 |
|
||||
| prompt pp4096 | 3,453 | 6,220 (chunk 4096) | 1.80 | 5/5 | 3,794 (-ub 2048) / 3,042 (-ub 512) |
|
||||
| `--mtp 2`, 10 prompts greedy 128 | 167.7 | 183.7 | 1.10 | 3/3 | 129 (draft-mtp, n-max 2, earlier run) |
|
||||
| 1 / 2 / 4 / 8 requests at once (`--batch 8 --mtp 0`) | 85.2 / 182.4 / 271.9 / 361.1 | 122.4 / 205.1 / 303.3 / 386.9 | 1.44 / 1.12 / 1.12 / 1.07 | 5/5 | |
|
||||
|
||||
UD-Q6_K_XL on the same card (every main layer's experts in VRAM, so the prompt chunk stays 512): decode 80.4 -> 106.9 tok/s (1.33), pp4096
|
||||
2,160 -> 2,200 (llama.cpp 3,486 at -ub 2048, 2,738 at -ub 512; decode 81.1), `--mtp 2` 154.7 -> 167.3. `--chunk 2048` there moves the experts
|
||||
to the hybrid placement (205 of 256 per layer in VRAM): prompt 3,500 tok/s, decode 94 - an option, not the default.
|
||||
|
||||
RTX 3060 12 GB (P2003, CUDA sm_86, 20 threads), UD-Q4_K_XL in the hybrid mode (37 of 256 experts per layer in VRAM): the GPU part of a
|
||||
token is the dense Q8_0 at the card's bandwidth (6 ms of the 17) and the rest waits for the CPU pool (9 ms of experts), so only the small
|
||||
kernels' share is gained: decode tg128 58.5 -> 59.7 tok/s (+2%), pp2048 1,958 -> 2,022 (+3.3%), 10/10 identical, plain and `--mtp 2`
|
||||
(84.3 -> 84.7). llama.cpp 972b5fc CUDA (`-ncmoe 26 -t 8 -ub 2048`): pp2048 1,328, tg128 48-52.
|
||||
|
||||
**Prompt chunk (the default changed).** The MoE prompt kernels read every expert once per chunk, so a bigger chunk feeds them more rows per
|
||||
expert: R9700 pp4096 at chunk 512 / 1024 / 2048 / 4096 = 3,453 / 4,786 / 5,766 / 6,223 tok/s. With every expert in VRAM the engine now takes the
|
||||
largest of 4096 / 2048 / 1024 that fits beside the experts, the 0.77 GiB reserve and the sessions' caches without giving the packed decode
|
||||
copies back (8K-64K context: 4096, 100K: 2048, 131K: 512; `--batch 2..4`: 1024 at most so the other slots are not held for a whole chunk,
|
||||
`--batch 8`: 512). The hybrid mode keeps 2048 (a bigger chunk takes expert slots: RTX 3060 chunk 4096 reads prompts 5% faster and decodes 13%
|
||||
slower) and goes down to 1024 / 512 on a card with 7.5 / 5.5 GiB free. **`--prefill 512` (or `STRATA_Q36_CHUNK=512`) gives the old size, and
|
||||
then the text is the base engine's, bit for bit.** The chunk size changes the GEMM tiles the BLAS picks and with them the last bits of the
|
||||
prompt state: KL against the 512 chunk on six real 1.5-3.2K-token documents (48 teacher-forced rows each): chunk 1024 4.0e-3, 2048 4.2e-3,
|
||||
4096 3.6e-3 (per prompt 2.3e-3 .. 5.9e-3), top-1 agreement 44-48 of 48 rows - the size of the llama.cpp CPU-vs-HIP difference on the same
|
||||
file (4.2e-3), not a quality loss. Greedy 64 tokens after those six documents: the default chunk gives the base engine's text for 2 of 6,
|
||||
`--prefill 512` for 6 of 6. A prompt shorter than the chunk (every chat turn after the first) is one chunk either way: unchanged.
|
||||
The new default's goldens are `phaseA-tests/q36speed/golden/` (six documents, greedy 64): later changes are checked against them.
|
||||
|
||||
**Tried and dropped.** The MTP drafts' head over a subset of the vocabulary (`--draft-vocab N`, kept as an opt-in; the answer never
|
||||
changes): the first 16K-131K rows gain 5-8% on English and code but lose 10-15% on Chinese / Russian / Arabic / Hindi (70% of a Chinese
|
||||
prompt's token ids are above 65,536), and a candidate list built from the tokens seen so far loses on both. The shared expert on a second
|
||||
stream (captured into the decode graph) decodes at 36 tok/s instead of 117 with this ROCm. Chunked (WY) GDN and the PCIe-assisted hybrid decode
|
||||
were not attempted.
|
||||
|
||||
## Not done / limits
|
||||
|
||||
- Eight slots at most (the window holds 8 rows); `--batch-mtp` shares those rows between slots and proposals.
|
||||
- A sampling request in a batch decodes one token per window without proposals. `logit_bias` is not available on this engine path: the
|
||||
server refuses a request that has it (as it does with `--batch` for Flash-Next).
|
||||
- A slot that stopped being alone goes back to the solo path only through the server's own hand-over; the MTP block's cache has holes for
|
||||
the tokens a slot decoded in batch windows (the drafts of a later solo stretch are a little worse; the text is not affected).
|
||||
- Intel Arc (SYCL) does not run this family.
|
||||
|
||||
## Testing
|
||||
|
||||
The gates are in `tools/qwen35/` and talk to the engine through its serve protocol (no server needed); run them under the box's GPU lock:
|
||||
|
||||
- `q36_solo_gate.py` + `q36_cmp_gate.py`: the 10 parity prompts x 128 greedy tokens through `GEN`, compared with another build's.
|
||||
- `q36_batch_gate.py --slots N --waves --long 2500`: every slot's tokens equal its solo tokens, slots reused, a long prompt read beside
|
||||
decoding slots. `q36_proto_edge.py`: `max_new` 1, `BSTOP`, a busy slot, `STOP` during a prompt read, held-state reuse, sampled requests,
|
||||
the context's end. `q36_interleave_probe.py`: what the decoding slots see while a long prompt is read.
|
||||
- `q36_vision_cmp.py` (with `q36_mtmd_dump.cpp` built against llama.cpp): the picture comparison above; `q36_vision_proto.py`: pictures through
|
||||
`GENI` / `BGENI` (solo, in a batch, the conversation cache); `q36_vision_serve.py` and `q36_serve_par.py` / `q36_serve_handoff.py`:
|
||||
the same through the server.
|
||||
- `q36_par_bench.py`: the aggregate-throughput A/B against `llama-server -np N`.
|
||||
@@ -0,0 +1,132 @@
|
||||
# Radeon 780M / 760M (Ryzen 7040 / 8040, gfx1103): build from source on Linux
|
||||
|
||||
The Radeon 780M (Phoenix / Hawk Point, RDNA3, `gfx1103`) runs PolyStrata through the same HIP backend as the Radeon
|
||||
cards in [AMD_HIP.md](AMD_HIP.md). **Status: experimental and opt-in** (`STRATA_EXPERIMENTAL_GFX1103=1`): the port
|
||||
is measured on one machine (the numbers below), the maintainers have not run one, and the chip is not Strix Halo.
|
||||
Everything here was measured on a Ryzen 7 8745HS (8 cores, AVX-512), Radeon 780M (12 CUs), 60 GB DDR5, GTT at
|
||||
50 GiB, Ubuntu kernel 7.0.0-38, `cwsr_enable=0`, engine 0.1.43 built from this tree by hand, Qwen3.8-Flash-Next
|
||||
GSQ-RCO Q2_0 with the MTP draft layer, 32K context, Int8 KV.
|
||||
|
||||
## 1. What the port changed
|
||||
|
||||
- **Native dot4.** gfx1103 was outside the `dp4a` guard in `hip_compat/intrinsics.hpp`, so every quantized dot
|
||||
product ran a four-step byte loop instead of `v_dot4_i32_iu8`. gfx1103 now compiles the native instruction
|
||||
(decode +55% measured: 8.70 -> 13.44 tok/s at a 32K prompt, same greedy token ids as before).
|
||||
- **gfx11 WMMA kernels.** gfx1103 was outside the `__gfx11xx__` list of the prompt attention, block scorer,
|
||||
prompt GEMMs and prompt experts, so those fell back to hipBLAS / portable kernels. It is now in the list and
|
||||
the parity tests run on it (`hip_prefill_wmma_gemm_parity`, `hip_prompt_attn_wmma`, `hip_prefill_fused_moe`,
|
||||
`hip_prefill_fused_iq`, `qsa_*`, `hip_gemm_f16_io_parity`, `hip_prefill_mmq_parity`).
|
||||
- **A hipBLASLt table** for gfx1103 + hipBLASLt `100401`: `tools/hip/gfx1103-hipblaslt-100401.txt` (section 3).
|
||||
- **The gfx1103 exact speed switches** (section 4), written into the config's `env` by setup for the opt-in install
|
||||
(the engine keeps gfx1103 out of its arch defaults, as it does for gfx1150). Whether the chip leaves the
|
||||
`STRATA_EXPERIMENTAL_GFX1103=1` opt-in is the maintainers' call; the numbers here are what they need to make it.
|
||||
|
||||
## 2. Toolchain and build
|
||||
|
||||
ROCm 10.1 (`rocm/dev-ubuntu-24.04:10.1.0-full`) is what this build and the table were tested with: HIP
|
||||
7.16.26385, hipBLASLt 1.4.1 (`100401`), clang 24. Its hipBLASLt carries gfx1103 kernels. setup's TheRock index
|
||||
for `gfx110X-all` has no 10.x (its newest is 7.14.0a20260612); the gfx1103 opt-in keeps setup's nightly pin, and
|
||||
the wheel route was not exercised by the numbers below - they come from a hand build.
|
||||
|
||||
By hand, the steps of [STRIX_HALO.md](STRIX_HALO.md) with the architecture and the paths changed:
|
||||
|
||||
```sh
|
||||
cmake -S . -B build-780m -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_PREFILL_MMQ=ON \
|
||||
-DCMAKE_HIP_ARCHITECTURES=gfx1103 \
|
||||
-DCMAKE_HIP_COMPILER=/opt/rocm/lib/llvm/bin/clang++ -DCMAKE_HIP_COMPILER_ROCM_ROOT=/opt/rocm \
|
||||
-DCMAKE_PREFIX_PATH=/opt/rocm \
|
||||
"-DCMAKE_HIP_FLAGS=--rocm-path=/opt/rocm --rocm-device-lib-path=/opt/rocm/lib/llvm/amdgcn/bitcode"
|
||||
cmake --build build-780m -j 12
|
||||
ctest --test-dir build-780m
|
||||
```
|
||||
|
||||
`ctest` on this machine: 57 passed, 2 skipped (`hip_prefill_hcd_exact_parity`, `hip_prefill_hipblaslt_gemm` -
|
||||
they run and pass with the table set), 2 environmental failures (`ple_parity` needs the `bench/micro` fixtures,
|
||||
`platform_memory_test` needs a memlock limit above 8 MiB; this host's hard limit is 8 MiB).
|
||||
|
||||
The model: a GSQ-RCO Q2_0 pack (`tools/iq_pack.py`, the experts read from the GGUF in place), the PLE table on
|
||||
the SSD (`--ple-io direct`), `--mmap-experts --expert-cache 24576`, `--prefill auto`, MTP from
|
||||
`tools/mtp_fetch.py` + `mtp_pack.py` + `mtp_rt.py`. GTT must be raised for this model (`ttm.pages_limit`; setup
|
||||
changes no host setting).
|
||||
|
||||
## 3. The hipBLASLt table
|
||||
|
||||
```sh
|
||||
export STRATA_HIPBLASLT_TUNING=$PWD/tools/hip/gfx1103-hipblaslt-100401.txt
|
||||
```
|
||||
|
||||
setup hands it over automatically when the installed hipBLASLt reports 1.4.1. It was calibrated with
|
||||
`tools/hip/tune_hipblaslt` over the gfx1150 table's 144 GEMM cases at T = 64..16384 (the same case list the 890M
|
||||
run used), two passes, 32 MiB workspace, each row the solution with the lowest median of all six repetitions: 143
|
||||
rows (the `bf16 N=1 K=2560 T=64` shape has no candidate faster than plain hipBLAS and is left out), 1.05-23.30x per
|
||||
GEMM, geometric mean 4.95x. `hip_prefill_hipblaslt_gemm` reports `fallbacks=0`; `hip_prefill_hcd_exact_parity`
|
||||
skips because the table picks no 1176 / 1177 for the HC down GEMM (the gfx1150 table gets the same skip).
|
||||
|
||||
## 4. The exact speed switches
|
||||
|
||||
With `STRATA_EXPERIMENTAL_GFX1103=1` setup writes the 17 exact switches below into the config's `env`, the same way
|
||||
it writes the hipBLASLt table; turning the opt-in off takes them out again. The engine keeps gfx1103 out of its
|
||||
arch defaults (`arch_default_env("gfx1103")` stays empty, checked by `arch_defaults_test`). Measured on the 780M:
|
||||
+13% to +15% prompt with the table (183-186 -> 211-212 tok/s at 4K) and +3.2% decode (16.63 -> 17.17 tok/s, 640
|
||||
greedy tokens, 3 of 3 pairs), with the greedy token ids unchanged. They are the gfx1151 table less
|
||||
`STRATA_HCD_EXACT` (which needs hipBLASLt solutions 1176 / 1177; the gfx1103 table picks others).
|
||||
|
||||
| Switch | What it does |
|
||||
|---|---|
|
||||
| `STRATA_GDN_HEAD`, `STRATA_GDN_PP=2`, `STRATA_GDN_CONVL2`, `STRATA_GDN_NOY`, `STRATA_CVEC_FUSE` | the prompt's gated-delta-net recurrence and the steered layer's fused write |
|
||||
| `STRATA_PF_PAD` | padded GEMM row strides (acts with `STRATA_PF_GEMM`; inert without it) |
|
||||
| `STRATA_Q8_PACKED`, `STRATA_Q6_PACKED`, `STRATA_MMVF_ROWS`, `STRATA_ATTN_LANECELL` | decode layouts and kernels (packed Q8_0 / Q6_K weights, 4-row BF16 GEMV, one-cell-per-thread attention scores) |
|
||||
| `STRATA_EXPERT_V2`, `STRATA_TSUM`, `STRATA_LFUSE`, `STRATA_GDN_SPLIT`, `STRATA_QFUSE`, `STRATA_PLE_BATCH`, `STRATA_SH_STREAM` | grouped decode experts, butterfly warp sums, fewer launches, the GDN step over four blocks per head, producer-written activation images, batched PLE projections, the shared expert on its own stream |
|
||||
|
||||
## 5. Opt-in switches (they change bits)
|
||||
|
||||
Opt-in, and the measured wins are below. The prompt levers need the table to pay: with the table, the WMMA set
|
||||
read 248 tok/s at 4K against 186 without it, and at 32K 272 against 178. No KL was measured on this chip.
|
||||
|
||||
```sh
|
||||
export STRATA_HIP_WMMA=1 # prompt attention on matrix cores
|
||||
export STRATA_PF_GEMM=1 # the prompt's FP16 projections on the WMMA GEMM
|
||||
export STRATA_PA_FAST=1 # prompt attention with single FP16 q and p
|
||||
export STRATA_SELECT_WMMA=1 # the block scorer on matrix cores
|
||||
export STRATA_PF_FUSED=1 # the prompt experts on matrix cores (neutral at 4K here: 246 vs 248)
|
||||
export STRATA_HC_UPMIX=1 # the hyper-connection up projection with its epilogue
|
||||
```
|
||||
|
||||
## 6. Engine flags
|
||||
|
||||
`--spec 2` is the best MTP window on this chip: 15.65 tok/s decode at a 4K prompt against 14.18 at `--spec 4` and
|
||||
11.16 at `--spec 6` (greedy, 256 tokens, medians of three interleaved restarts). `--lookup-chain 4` adds +2.3% (3
|
||||
of 3 pairs, byte-identical greedy answers) and setup's `--spec-min-p 0.5` is 4.5% slower here than the default;
|
||||
`--mtp-q4` is neutral and `--mtp-window 4096` measured +2% at 32K in two pairs (weak). The raw runs are in the
|
||||
results folder.
|
||||
|
||||
## 7. Measured
|
||||
|
||||
bench/bench_vs_llama.py, 256 tokens out, temperature 0 and 0.7, interleaved; each cell one round (medians need
|
||||
more rounds - treat these as one-machine samples):
|
||||
|
||||
| arm | cell | prompt tok/s | decode tok/s | TTFT s |
|
||||
| --- | --- | ---: | ---: | ---: |
|
||||
| plain (no table, no opt-ins) | 4K | 90 | 13.1 | 44.9 |
|
||||
| plain (no table, no opt-ins) | 32K | 90 | 13.1 | 351 |
|
||||
| table + all opt-ins | 4K | 277 | 13.9 | 14.6 |
|
||||
| table + WMMA set | 32K | 272 | 14.3 | 118 |
|
||||
|
||||
A context ladder on the shipping configuration (131K context, `--spec 2 --lookup-chain 4`) with fresh prompts from
|
||||
this checkout's own documentation, 128 greedy tokens each: prefill holds ~310 tok/s to 32K (276.7 at 4K, 314.3 /
|
||||
314.6 at 8K / 16K, 308.7 at 32K), then 258.2 at 64K, 215.5 at 96K and 198.5-221.4 at 128K across two runs - that is
|
||||
the average over the full read, and the last ~14K tokens at 128K depth read at ~206 tok/s with the prefix cached.
|
||||
Decode holds ~16 tok/s to 32K, then 12.1 at 64K and 9.8-9.9 at 96-128K (draft acceptance stays ~70%, so it is
|
||||
context cost, not the drafter). Memory stays flat: 38.1 of 50 GiB GTT at 131K. Raw:
|
||||
[bench/results/2026-10-12-community-gfx1103](../bench/results/2026-10-12-community-gfx1103/README.md).
|
||||
|
||||
## 8. Not tested
|
||||
|
||||
- The TheRock-wheel install for gfx1103 (the hand build above is what was measured).
|
||||
- The opt-in set beyond one round; KL of any bit-changing switch; other models; contexts past 131K.
|
||||
- CUDA and SYCL were not built here (no toolchains on this box); the added gfx1103 macros are undefined for them.
|
||||
- Reset stability looks good but is one machine: a 2 h 07 m soak (`tools/serve_load.py`, 924 requests) and the
|
||||
reset-prone combination from 7.10 (partial expert cache + `STRATA_IO_PREFETCH=1` + the adaptive tier) both ran
|
||||
with zero `amdgpu` resets in the kernel log. The known 780M issue ([DETAILS.md](DETAILS.md)) was seen on ROCm
|
||||
7.10; with `cwsr_enable=0` and this stack it did not reproduce.
|
||||
@@ -0,0 +1,60 @@
|
||||
# One long document, many questions (0.1.40.2, opt-in)
|
||||
|
||||
Read a long document once, then ask many different questions without reading it again. All numbers: Tesla P100 16 GB,
|
||||
IQ2_XS, `--kv int8 --kv-resident 32768`, MTP on, greedy, the 0.1.40 engine unless a row says "pin".
|
||||
|
||||
## What the engine already did (0.1.40)
|
||||
|
||||
The conversation cache keeps small checkpoints (the GDN and indexer state, about 118 MiB each); the K/V of the document
|
||||
stays in the session, so a question that starts from a checkpoint reads only what lies past it.
|
||||
|
||||
| 262K document (258,655 tokens) | time to first token |
|
||||
|---|---|
|
||||
| first question (cold read) | 904 s (286 tok/s) |
|
||||
| questions 2-20, engine with a turn boundary at the document's end | 0.53 s median (0.44-0.72) |
|
||||
| the same through the server's chat API (no turn boundary at the document's end) | 55.5 s each (15 measured): the engine re-reads up to `--prompt-cache-every` (16,384) tokens from the last periodic checkpoint |
|
||||
| `parallel` 2 through the server | the first two questions 918 s and 979 s; the next pair read the document again from token 0 |
|
||||
|
||||
Checkpoint RAM: +804 MiB resident after the first read (6 checkpoints); each later question adds at most 10 MiB. The
|
||||
K/V of 262K takes 3.06 GiB of pinned RAM, once per session (`--batch` slots each take their own).
|
||||
Identity (greedy, 64 tokens): questions 1 and 12 on a fresh engine give the same tokens as in the 20-question run.
|
||||
Caveat: IQ models are not byte-reproducible at temperature 0 between runs unless `STRATA_IQ_MT_MIN=1` (DETAILS.md);
|
||||
some answers differ between two runs of the same prompt for that reason, with or without the field below.
|
||||
|
||||
## `strata_prefix` (and the engine's `pin=N`)
|
||||
|
||||
`"strata_prefix": {"messages": 1}`, `{"message": 0, "chars": N}` or `{"tokens": N}` marks the start of the prompt as the
|
||||
shared document. The checkpoint at its end is pinned: never evicted, kept in the parked-conversation budget, kept by
|
||||
`SAVE`, and a question that resumes from it does not park the branch it leaves.
|
||||
|
||||
| 64K document (P100) | no field | with the field |
|
||||
|---|---|---|
|
||||
| engine, raw prompts, questions 2-5 | 48.6 s | 0.35-0.53 s |
|
||||
| a 100K-token branch between two questions, then a question | 149 s | 0.55 s |
|
||||
| another 20K prompt between (`--conversation-cache-mib 8192`) | 49 s | 0.97 s (restored), then 0.44 s |
|
||||
| server, 18K-token document, split messages / one message | 8.8 s | 0.6-0.8 s |
|
||||
| server `parallel` 2, six questions | 730 s (every pair re-reads) | 220 s (questions 3-6: 2.5-3.8 s) |
|
||||
|
||||
Copy-on-write K/V pages across `--batch` slots are NOT built: each slot keeps its own K/V (3.06 GiB at 262K, about 12 GiB
|
||||
at 1M), and admitting a branch copies the prefix K/V (3 s at 262K). The pinned prefix removes the re-read, not the copy.
|
||||
|
||||
`tools/research_run.py` runs a document and a question list against a server with and without the field.
|
||||
|
||||
## R3: expert slots against K/V blocks (P100, IQ2_XS)
|
||||
|
||||
64K document, 5 questions. Prefill, then median first token of a short question, then decode:
|
||||
|
||||
| expert slots (GiB) | prefill | first token | decode |
|
||||
|---|---|---|---|
|
||||
| 2,083 (2.81) | 230 s | 0.69 s | 27.5 tok/s |
|
||||
| 3,500 | 200.7 s | 0.61 s | 30.9 |
|
||||
| 5,000 | 200.7 s | 0.55 s | 34.2 |
|
||||
| 7,000 | 200.7 s | 0.51 s | 36.7 |
|
||||
|
||||
Marginal value of VRAM: decode 0.31-0.41 s per GiB per 200-token answer between 2,000 and 5,000 slots, 0.15 above;
|
||||
prefill gains only below the prompt loan's floor. K/V cells in VRAM (`--kv-resident`): 4096 / 16384 / 32768 / 65536 give
|
||||
34.05 / 34.06 / 34.21 / 34.92 tok/s at 64K; at 262K (5,000 slots) 8192 / 32768 / 131072 give 29.54 / 29.46 / 29.49 tok/s
|
||||
(block hit rate 92.6 / 94.5 / 95.7 %). So the K/V block cache is worth nothing per GiB, experts only help decode, and the
|
||||
read is already served by the loan. A split planner would gain almost nothing, so none was built. The one real lever in
|
||||
the read is the chunk: `--prefill 16384` with 7,000 slots reads 64K in 186.4 s against 200.7 s (-7%), and 4096 takes 228 s;
|
||||
it needs the larger loan and changes the chunking, hence the rounding, so it is not a placement-only change.
|
||||
@@ -0,0 +1,227 @@
|
||||
# CUDA1–3 expert experiment
|
||||
|
||||
CUDA0 keeps the dense layers, KV/state, MTP and its existing expert cache. Up to
|
||||
three independent expert caches fill CUDA1, CUDA2 and CUDA3 in that order. Each
|
||||
expert has one owner: CUDA0, one secondary GPU, or the CPU pool. Each secondary
|
||||
GPU computes its rows while the CPU pool works; the results return through
|
||||
private pinned host buffers before CUDA0 continues the layer. The GPU launches
|
||||
can overlap, but each layer waits for all three.
|
||||
|
||||
The shipped profile ranks 8,000 `(layer, expert)` pairs. CUDA0 takes its usual
|
||||
`--expert-cache auto` allocation. With only CUDA1, it takes the first remaining
|
||||
pairs. When CUDA2 or CUDA3 is enabled, the remaining profiled pairs are assigned
|
||||
round robin to the secondary GPUs. The ranked list is then extended with all
|
||||
other pairs in expert-then-layer order and distributed in the same way. This
|
||||
fills the additional VRAM and lets all secondary GPUs see frequent experts, but
|
||||
unranked experts may hardly ever be routed. The startup
|
||||
log reports slots and GiB per card; each request reports the number of expert
|
||||
entries actually computed on each secondary GPU. Remote outputs are packed
|
||||
before returning over PCIe/USB4: the request log compares MiB transferred
|
||||
with the previous full-row transfer. The input and routing metadata use pinned
|
||||
host staging. This reduces transfer traffic and launch overhead, but does not
|
||||
release the expert arena in system RAM or significantly change VRAM use.
|
||||
|
||||
The optional `--gpu-placement layer` gives each layer to exactly one secondary
|
||||
GPU (layer number modulo the number of enabled cards). It fills that card with
|
||||
the most frequently routed experts of its layers first, then the unranked ones.
|
||||
This can reduce USB4 device switches and synchronization when several secondary
|
||||
cards serve the same layer in the default `stripe` mode. All three cards still
|
||||
keep their requested expert slots; the primary CUDA0 cache and CPU fallback
|
||||
continue to work. The log counts active layer launches on each card, so the
|
||||
tradeoff can be measured alongside tokens per second. This placement is
|
||||
experimental and may be slower if a given layer needs more than one card's
|
||||
compute capacity.
|
||||
|
||||
The experiment requires the corresponding visible CUDA devices and a CUDA
|
||||
enabled build. Each card must keep at least 512 MiB free. Tiers must be enabled
|
||||
in order. Under WDDM (Windows, WSL2), CUDA registration of the host expert arena is capped at
|
||||
8 GiB to leave room for the contexts and MTP on CUDA0 (`STRATA_ARENA_PIN_GIB` overrides it; on Linux the whole
|
||||
arena is registered). The rest remains
|
||||
available to the CPU pool; the PCIe expert path is available only for the
|
||||
registered layers. Without secondary GPUs, the original uncapped registration
|
||||
behavior applies.
|
||||
|
||||
On an existing Linux installation, apply the patch to its source tree, then run:
|
||||
|
||||
```sh
|
||||
./setup.sh --setup --gpu1-experts 5000 --gpu2-experts 5000 --gpu3-experts 5000
|
||||
```
|
||||
|
||||
On Windows, from PowerShell in the installation folder:
|
||||
|
||||
```powershell
|
||||
.\START-HERE.bat --setup --gpu1-experts 5000 --gpu2-experts 5000 --gpu3-experts 5000
|
||||
```
|
||||
|
||||
To test the layer placement instead, add `--gpu-placement layer` to the setup
|
||||
command. To go back, run the same command with `--gpu-placement stripe`. After
|
||||
the new engine is built, the mode can also be changed without a rebuild: edit
|
||||
`--expert-cache-remote-placement` in `strata-iq3_xxs.json` from `layer` to
|
||||
`stripe` or vice versa and restart the server. If the argument is absent, the
|
||||
default is `stripe`.
|
||||
|
||||
Choose the same model, size, context and image settings as your current
|
||||
installation when prompted. Setup recompiles the engine, updates its server
|
||||
configuration, and starts it. Later starts keep those settings. To tune the
|
||||
slots without recompiling, edit the values after `--expert-cache-device1`,
|
||||
`--expert-cache-device2` and `--expert-cache-device3` in the stored
|
||||
`strata-iq3_xxs.json`, then restart with `.\run-iq3_xxs.bat`.
|
||||
|
||||
Compare identical requests at one, two and four GPUs, preferably with several
|
||||
repeats. VRAM use alone does not show useful offload: compare the per-request
|
||||
CUDA1–3 counts and tokens per second. More GPU contexts and synchronization
|
||||
may lower the speed. Prompt prefill still uses CUDA0; secondary GPUs serve
|
||||
decode, including MTP verification. No peer-to-peer access is required.
|
||||
|
||||
Longer contexts reserve more KV/state memory on CUDA0, which reduces its
|
||||
automatic expert cache. On a 64 GB PC `setup.py` limits IQ3_XXS to 128K even
|
||||
if 262K was selected; the secondary caches still require the host expert arena.
|
||||
To try 262K on 64 GB, choose Q2_0 or IQ2_XS instead and check that CUDA0 still
|
||||
has enough free VRAM after loading. Benchmark long prompts separately from
|
||||
short decode requests.
|
||||
|
||||
The existing warning about the CUDA0 expert-cache GPU hit path still applies:
|
||||
its outputs diverge from cache-off runs. Treat performance as experimental
|
||||
until the generated tokens have been validated.
|
||||
|
||||
## Optional helper decode optimization
|
||||
|
||||
`--remote-expert-opt` (`--serve` only) optimizes the CUDA1-3 helper caches
|
||||
above. The engine's default is off; since 0.1.39b setup adds it to a config on
|
||||
two or more GPUs (`--gpus`, or "use both" at start). It acts only when a helper
|
||||
cache is configured; a layer split runs exactly as before. To leave it out:
|
||||
setup's `--no-remote-expert-opt`, or `"remote_expert_opt": false` in the
|
||||
model's `strata-*.json` (kept when setup runs again). Measured by the PR's
|
||||
author: dual RTX 4090 +63% mixed / +132% code decode over the plain helper
|
||||
path; RTX 5090 + 4090 +28% / +63%. The primary cache avoids admitting experts already held
|
||||
by a helper, and helpers replace cold experts with frequently routed CPU
|
||||
misses using their existing same-layer slots. Each helper reduces its expert
|
||||
outputs to a weighted partial sum on its GPU before returning one vector per
|
||||
token. Tokens with no CPU expert work skip CPU activation quantization.
|
||||
|
||||
For an existing server configuration with CUDA0 as the primary and CUDA1 as a
|
||||
helper, use these engine arguments alongside the model and profile arguments:
|
||||
|
||||
```text
|
||||
--expert-cache auto --expert-cache-device1 auto --remote-expert-opt
|
||||
```
|
||||
|
||||
`--expert-cache-device1`, `--expert-cache-device2` and
|
||||
`--expert-cache-device3` now also accept `auto`: fill each helper from its
|
||||
assigned ranking using actual aligned expert bytes and free VRAM, retaining
|
||||
the existing 512 MiB allowance. Explicit numeric budgets still work. This is
|
||||
startup capacity sizing, not throughput balancing; with several helpers a
|
||||
card's truncated candidate tail is not redistributed to another card.
|
||||
|
||||
The optimization uses the existing host scheduling and pinned-host transport,
|
||||
not P2P or tensor parallelism. Each layer still waits for its participating
|
||||
helpers. It changes floating-point summation order, so enabled output is not
|
||||
claimed to be bitwise identical. Only two-card CUDA operation has been measured
|
||||
by its author; a community machine measured two cards on HIP (2x RX 6900 XT,
|
||||
PCIe 4.0 x8 each, IQ3_S): there the expert plan's PCIe share had been taking
|
||||
experts the helper already held, which made the primary card wait 43 ms per
|
||||
verify window instead of 19 (decode 40 instead of 66 tok/s). #854 keeps a
|
||||
helper's experts out of that share; before it, `--pcie-frac 0` avoided the
|
||||
cost ([bench/results/2026-10-04-rdna2-helper-pcie-share](../bench/results/2026-10-04-rdna2-helper-pcie-share/README.md)).
|
||||
Three/four cards have not been validated. Without the switch, the
|
||||
existing decode path remains in use. This does not optimize the separate
|
||||
`--peer-device` path below or change its existing incompatibility with helper
|
||||
caches.
|
||||
|
||||
## Peer tier (`--peer-device`)
|
||||
|
||||
`--peer-device N` puts a second adaptive expert cache on CUDA device N. It
|
||||
takes the ranked pairs CUDA0's cache does not hold, as many as fit. The peer
|
||||
computes the rows of its own experts, for decode windows and for prompt
|
||||
chunks; the activations and the results cross NVLink or another P2P path. The
|
||||
tier adapts while the server runs, like the primary cache. It is an
|
||||
alternative to the CUDA1-3 caches above, not a third tier beside them.
|
||||
|
||||
- `--peer-device N` (default off): enable the tier on CUDA device N (N >= 1).
|
||||
- `--peer-reserve-mib M` (default 600): leave M MiB free on the peer card; the
|
||||
cache takes what remains. The prompt-path buffers need this headroom.
|
||||
Keep a few hundred MiB free on both cards beyond this: the prompt path loads its kernels and cuBLAS on first use
|
||||
(a start with 5 MiB left on the peer and 485 MiB on the primary stopped at the first prompt with "cuBLAS status 14").
|
||||
- Whether the two cards can really exchange data is tested once at start (#2666): two RTX A4000 behind a host
|
||||
bridge reported peer access, enabled it, and `cudaMemcpyPeerAsync` then copied nothing, so the peer computed on
|
||||
zeros and the first prompt came back NaN. A test copy each way now decides; if it arrives wrong the log says so
|
||||
and the prompt path uses the host route (the one without P2P: activations and rows through mapped host memory).
|
||||
`STRATA_PEER_NO_P2P=1` asks for that route by hand.
|
||||
- `--peer-slots N` (default 0): cap the tier at N experts; 0 = as many as fit.
|
||||
- `--peer-adapt-swaps N` (default -1): swaps per adaptive round on the peer;
|
||||
-1 uses the primary's `--adapt-swaps`.
|
||||
- `--peer-prefill-rows N` (default -1): the share of each prompt chunk's rows
|
||||
the peer computes; -1 is half of chunk x top-k, 0 keeps prompt rows on the
|
||||
primary.
|
||||
|
||||
Through the server, list both cards in the config's `"gpu"` (e.g. `[0, 1]`, numbered as nvidia-smi numbers them)
|
||||
and add `--peer-device 1` to its `"args"`; the number is the card's position in that list (with `"gpu": [2, 0]`,
|
||||
`--peer-device 1` is nvidia-smi's card 0). Several GPUs in `"gpu"` are otherwise a layer split: the server adds
|
||||
`--layer-split` only when `--peer-device` is not among the args.
|
||||
|
||||
`--peer-device` requires `--expert-profile` and an enabled expert cache, and
|
||||
the device must be visible; it refuses otherwise. It also refuses
|
||||
`--layer-split` (a different second-GPU mode: use one or the other) and
|
||||
`--expert-cache-device1..3` (the peer tier already caches experts on that card):
|
||||
|
||||
strata generate: --peer-device cannot be combined with --layer-split (use one or the other)
|
||||
strata generate: --peer-device cannot be combined with --expert-cache-device1..3 (the peer tier already caches experts there)
|
||||
|
||||
Without `--peer-device` the binary is unchanged; its output is byte-identical
|
||||
to the release. With `--peer-device` and the same expert set split across the
|
||||
two cards, the generated tokens are byte-identical to the single-GPU run under
|
||||
the exactness gate.
|
||||
|
||||
With a peer the prompt path keeps the MMQ path; the fused int8 prompt path is
|
||||
not yet combined with the peer's rows. Mapped host buffers gain
|
||||
`cudaHostAllocPortable` only with a peer, since only then does a second
|
||||
context write them. The tier size is manual for now (`--peer-reserve-mib`,
|
||||
`--peer-slots`); automatic sizing on small cards wants the buffer lending of
|
||||
#216 and is a follow-up.
|
||||
|
||||
## The resident RAM mode with the helper caches
|
||||
|
||||
`--resident-experts` (the low-RAM mode) works with the helper caches: the
|
||||
experts a helper holds are left out of the RAM copy as a split stage's are, and
|
||||
the helpers' refills read through the source - the RAM copy when it holds the
|
||||
bytes, the files otherwise. Measured here on an RX 6800 (gfx1030, 16 GB) + RX
|
||||
6600 (gfx1032, 8 GB), Windows 11, an i5-11400F and 32 GB of RAM (the 6800 alone:
|
||||
~37.5 decode tok/s, the same worker configuration): the 6600's 3.4-3.8k-expert
|
||||
cache lifted decode to ~40.6 / 44.2 tok/s on 8K-token requests at 3800 slots,
|
||||
with the CPU pool's share of the experts down from ~2.9 to ~0.4 entries per
|
||||
layer-window. The helper's rows cost about 0.3-0.6 ms per layer on the pool's
|
||||
critical path - usually less than the CPU rows and page faults they replace,
|
||||
which is why the 6600 (about 2-3x the 6800's cost per row) still pays off as a
|
||||
cache tier.
|
||||
|
||||
**Size a helper against the card's *real* free VRAM.** `--expert-cache-device1
|
||||
auto` reads `cudaMemGetInfo`, which on Windows reports the *process's* WDDM
|
||||
budget: it cannot see the desktop, the vision encoder (a separate process), a
|
||||
streaming host or other apps on that card. A helper auto-sized on a card that
|
||||
also drives the display or the encoder over-commits, WDDM backs the excess with
|
||||
system RAM ("shared GPU memory"), and that memory leaves the machine's RAM - on
|
||||
a 32 GB PC it pushed the resident complement into the pagefile and made the
|
||||
helper read its own cache over PCIe. An explicit count
|
||||
(`--expert-cache-device1 3800` here, of ~4100 that fit an empty card) kept the
|
||||
cache in real VRAM; freeing another app's sticky allocation on the same card
|
||||
was worth about the same again. Prefer explicit counts on a card that shares
|
||||
its VRAM with anything else.
|
||||
|
||||
## Choosing the primary device on Windows (`STRATA_PRIMARY_DEVICE`)
|
||||
|
||||
The engine runs the model on the device the runtime numbers 0. Windows' HIP
|
||||
runtime enumerates the cards in a fixed order that `HIP_VISIBLE_DEVICES` only
|
||||
filters - it cannot reorder - so on a PC whose faster card comes second (an RX
|
||||
6800 after an RX 6600, say) a run with both visible could only put the model on
|
||||
the slow one. `STRATA_PRIMARY_DEVICE=N` picks another visible ordinal as the
|
||||
primary; unset or 0 is upstream's behavior.
|
||||
|
||||
- the helper caches (`--expert-cache-device1..3`) take the visible devices
|
||||
other than the primary, in order;
|
||||
- the peer tier's cross-device checks use the same ordinal;
|
||||
- a layer split is refused with this set (its later stages must be > 0, and
|
||||
stage 0 is the primary);
|
||||
- NVIDIA cards do not need it: `CUDA_VISIBLE_DEVICES` with
|
||||
`CUDA_DEVICE_ORDER=PCI_BUS_ID` already reorders.
|
||||
|
||||
Measured on RX 6800 + RX 6600, Windows 11; the report accompanies this change.
|
||||
@@ -0,0 +1,186 @@
|
||||
# Strix Halo (Ryzen AI Max, gfx1151): build from source on Linux
|
||||
|
||||
PolyStrata runs on the Ryzen AI Max "Strix Halo" APUs (Radeon 8060S / 8050S, RDNA3.5, `gfx1151`, one pool of LPDDR5X shared by the
|
||||
CPU and the GPU) through the same HIP backend as the Radeon cards in [AMD_HIP.md](AMD_HIP.md). **Status: experimental.**
|
||||
Everything here was built and measured on one machine, the maintainers' Strix Halo box (Ryzen AI Max+ 395, 128 GB,
|
||||
Ubuntu 26.04, kernel 7.0, ROCm 7.14.1). Setup (`setup.sh`, `START-HERE.bat`) recognizes it from 0.1.40, by its PCI id (`1002:1586`, one id for the 8060S, 8050S and 8040S) and by
|
||||
`gfx1151` exactly: a Strix Point (890M / 880M, gfx1150), Krackan (860M / 840M, gfx1152) or Phoenix / Hawk Point (780M / 760M, gfx1103) Radeon is
|
||||
named as what it is and not supported. On Linux setup compiles the engine for gfx1151 itself (the steps below are the same, by hand). On
|
||||
Windows the ready-made `strata-windows-x64-hip.zip` carries gfx1151 code from 0.1.40 (untested on a Windows Strix Halo so far); a zip
|
||||
without it is refused with a message, never used. Setup counts the GPU's memory as the BIOS carve-out plus the shared memory
|
||||
(the GTT pool; on Windows half the RAM) and recommends UD-IQ4_XS from about 80 GB of memory; it changes no BIOS or kernel setting.
|
||||
|
||||
What the engine does differently on this chip:
|
||||
|
||||
- **Unified memory.** The GPU's "VRAM" is the GTT pool of the same RAM. `device_free_bytes()` (the figure `--expert-cache auto` and
|
||||
the memory plan use) counts what Linux can give back (`MemAvailable` less 6 GiB for the system, `STRATA_UMA_HEADROOM_GIB`
|
||||
changes the 6) instead of only `MemFree`, per device, for any integrated GPU on Linux (this applies to a DGX Spark too).
|
||||
- **gfx11 matrix cores.** The prompt attention, the block scorer, the prompt GEMMs and the prompt experts have WMMA kernels for
|
||||
gfx1100 / 1101 / 1102 / 1103 / 1150 / 1151. A gfx11 part outside that list (gfx1152) is not given them: it takes the portable path.
|
||||
- **The hipBLASLt table** `tools/hip/gfx1151-hipblaslt-100401.txt` (ROCm 7.14.1's hipBLASLt 1.x `100401`), including the prompt shapes
|
||||
at `--prefill 16384` (T 16383 / 16384). Setup's own ROCm for gfx1151 (the 7.14.0a20260608 wheels, hipBLASLt 1.4.0) takes
|
||||
`tools/hip/gfx1151-hipblaslt-100400.txt`: the same shapes, calibrated against that library (docs/AMD_HIP.md, Tuning table).
|
||||
- **The expert cache and the RAM budget share the RAM.** For a model with a RAM budget (UD-IQ4_XS, UD-Q4_K_XL) setup writes a number for `--expert-cache` (the RAM less 24 GB less the budget), not `auto`: `auto` counts all the memory the OS can give back at start, and with a 55 GiB budget and a desktop open it took the room the OS needed (#1715, a global OOM on a 128 GB box). The number is in the config's `args`; `--expert-cache N` there sets it. An engine run by hand should pass one too.
|
||||
|
||||
## 1. The toolchain (no root needed)
|
||||
|
||||
ROCm 7.14.1 for gfx1151 from AMD's TheRock builds, extracted into a folder of your own:
|
||||
|
||||
```sh
|
||||
mkdir -p ~/rocm && cd ~/rocm
|
||||
curl -LO https://repo.amd.com/rocm/tarball-multi-arch/therock-dist-linux-gfx1151-7.14.1.tar.gz # 1.7 GB
|
||||
sha256sum therock-dist-linux-gfx1151-7.14.1.tar.gz # c40e8f2bd6630a7d11557c762b99c6fa8afb04c9bd0e51ed1675ee1ca24afb00
|
||||
mkdir install && tar -xzf therock-dist-linux-gfx1151-7.14.1.tar.gz -C install
|
||||
export SDK=$HOME/rocm/install
|
||||
export ROCM_PATH=$SDK HIP_PATH=$SDK HIP_PLATFORM=amd
|
||||
export PATH=$SDK/bin:$SDK/lib/llvm/bin:$PATH
|
||||
export LD_LIBRARY_PATH=$SDK/lib:$SDK/lib/rocm_sysdeps/lib:$SDK/lib/llvm/lib:${LD_LIBRARY_PATH:-}
|
||||
```
|
||||
|
||||
You also need CMake 3.24+, Ninja, git and a C++ host toolchain with libstdc++ headers (`sudo apt install build-essential cmake ninja-build git`).
|
||||
The maintainers' box has no system compiler: they point ROCm's clang at a user-space copy of gcc 15 with
|
||||
`--gcc-toolchain=<dir>/usr` (added to `CMAKE_HIP_FLAGS` below; leave it out when the system has one).
|
||||
|
||||
The kernel's amdgpu driver and `/dev/kfd` access (your user in the `render` and `video` groups) are all the GPU side needs.
|
||||
To let the GPU use most of a 128 GB machine the maintainers' box boots with `ttm.pages_limit=29360128 ttm.page_pool_size=29360128`
|
||||
(a 112 GiB GTT; the default is about half of the RAM) and `amd_iommu=off`; both are host settings the engine does not need to run,
|
||||
only to have the room.
|
||||
|
||||
## 2. The engine
|
||||
|
||||
llama.cpp's `ggml` sources are pinned by this repository: CMake fetches the revision it needs. For an offline build, point
|
||||
`STRATA_GGML_DIR` at a checkout of exactly that revision.
|
||||
|
||||
```sh
|
||||
git clone https://github.com/VecSzn/PolyStrata.git && cd PolyStrata
|
||||
cmake -S . -B build-halo -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_PREFILL_MMQ=ON \
|
||||
-DCMAKE_HIP_ARCHITECTURES=gfx1151 \
|
||||
-DCMAKE_HIP_COMPILER=$SDK/lib/llvm/bin/clang++ -DCMAKE_HIP_COMPILER_ROCM_ROOT=$SDK \
|
||||
"-DCMAKE_PREFIX_PATH=$SDK;$SDK/lib/rocm_sysdeps;$SDK/lib/llvm" \
|
||||
"-DCMAKE_HIP_FLAGS=--rocm-path=$SDK --rocm-device-lib-path=$SDK/lib/llvm/amdgcn/bitcode"
|
||||
cmake --build build-halo --target strata -j 8 # about 25 minutes the first time
|
||||
```
|
||||
|
||||
`gfx1151` is "unvalidated" in the build's own wording (it warns). `STRATA_PREFILL_MMQ=ON` builds ggml's MMQ kernels the prompt
|
||||
experts need. The tests: `cmake --build build-halo -j 8` builds them all, `ctest --test-dir build-halo` runs them;
|
||||
`hip_prefill_hcd_exact_parity` and `hip_prefill_hipblaslt_gemm` need the table (next section) and skip without it.
|
||||
|
||||
## 3. The prompt table, and running
|
||||
|
||||
Hand the engine the table (`setup` does it for the supported cards; for gfx1151 you do it): without it the prompt's dense matrix
|
||||
products use plain hipBLAS and are slower.
|
||||
|
||||
```sh
|
||||
export STRATA_HIPBLASLT_TUNING=$PWD/tools/hip/gfx1151-hipblaslt-100401.txt
|
||||
```
|
||||
|
||||
The engine accepts it only for the architecture and the hipBLASLt version named on the table's second line
|
||||
(`STRATA_HIPBLASLT_TUNING_V1 gfx1151 100401`: ROCm 7.14.1) and says so at start-up (`prefill gemm: hipBLASLt tuning enabled (90 rows,
|
||||
gfx1151, version 100401)`). Then run `strata` with the same arguments as on any other card (the model packs, `--serve`, the
|
||||
settings of [DETAILS.md](DETAILS.md)); a pack of the Unsloth UD-IQ4_XS or UD-Q4_K_XL GGUFs is what the numbers below used.
|
||||
|
||||
## 4. What is on by default on gfx1151
|
||||
|
||||
At start the engine looks at GPU 0; on a gfx1151 it sets the switches below unless you set them yourself
|
||||
(`STRATA_GFX1151_DEFAULTS=0` turns the whole table off, and the start-up line names what was set). **Every one of them gave
|
||||
byte-identical output on the maintainers' box** (the same token ids, 4K / 32K / 64K and four models, and a bitwise harness per kernel):
|
||||
they change speed, not answers. Nothing here applies to CUDA or to another AMD architecture.
|
||||
|
||||
| Switch | What it does |
|
||||
|---|---|
|
||||
| `STRATA_GDN_HEAD`, `STRATA_GDN_PP=2`, `STRATA_GDN_CONVL2`, `STRATA_GDN_NOY` | the prompt's gated-delta-net recurrence: four lanes per column, two columns per lane, the convolution and the norms fused |
|
||||
| `STRATA_HCD_EXACT` | the hyper-connection down projection (N 320, K 10240) in a WMMA kernel that reproduces hipBLASLt solution 1176 / 1177's summation order (`hip_prefill_hcd_exact_parity` checks it bit for bit); it runs only where the table makes hipBLASLt pick one of those two, and says once if it cannot |
|
||||
| `STRATA_CVEC_FUSE`, `STRATA_PF_PAD` | a steered layer's write, control vector and next norm in one pass; padded GEMM row strides |
|
||||
| `STRATA_TOPK_REG_MIN_BLOCKS=4096` | the prompt's QSA top-k uses the register kernel from 16K cells of context instead of 28K (the original kernel is slower there; the selected cells are identical, `qsa_topk_parity` checks it) |
|
||||
| `STRATA_Q8_PACKED`, `STRATA_Q6_PACKED`, `STRATA_MMVF_ROWS`, `STRATA_ATTN_LANECELL` | decode layouts and kernels (packed Q8_0 / Q6_K weights, 4-row BF16 GEMV, one-cell-per-thread attention scores) |
|
||||
| `STRATA_EXPERT_V2`, `STRATA_TSUM`, `STRATA_LFUSE` | the grouped decode experts (IQ3_S / IQ4_NL), single-butterfly warp sums, fewer launches around the shared expert and the KV append |
|
||||
| `STRATA_GDN_SPLIT`, `STRATA_QFUSE`, `STRATA_PLE_BATCH` | the GDN step over four blocks per head, activation images written by their producers, the PLE key / value projections of a verify window at once |
|
||||
| `STRATA_SH_STREAM=1` | the shared expert on a second stream beside the routed experts. It is off by default on other AMD cards (#816), but it pays on gfx1151: decode +1.8% (UD-IQ4_XS) and +6.7% (UD-Q4_K_XL) at 8K |
|
||||
|
||||
## 5. What is not on by default (it changes bits)
|
||||
|
||||
These are faster on gfx1151 and **round differently** from the default path (a different summation order or a half-precision
|
||||
intermediate), so they are opt-in and the maintainers gate them with KL against the default (`STRATA_PF_SWITCH_MIN_T=4096` keeps
|
||||
the short prompts on the default numerics, since these pay on long ones). The maintainers' fast configuration sets all of
|
||||
them:
|
||||
|
||||
```sh
|
||||
export STRATA_PF_FUSED=1 # the prompt experts on the matrix cores (IQ2 / IQ3 / IQ4_XS gate/up, Q2_0 / IQ4_NL / Q8_0 down)
|
||||
export STRATA_PF_GEMM=1 # the prompt's FP16 projections on the 128 x 256 WMMA GEMM
|
||||
export STRATA_HC_UPMIX=1 # the hyper-connection up projection with its epilogue
|
||||
export STRATA_PA_FAST=1 # the prompt attention with single FP16 q and p
|
||||
export STRATA_HIP_WMMA=1 # the prompt attention on matrix cores
|
||||
export STRATA_SELECT_WMMA=1 # the block scorer on matrix cores
|
||||
export STRATA_HC_Q8=1 # the hyper-connection read from the GGUF's own Q8_0 projections
|
||||
export STRATA_PF_SWITCH_MIN_T=4096
|
||||
export STRATA_PREFILL_STREAM_MIN=128 # prompt reads of 128-1,023 tokens on the fused experts too (below)
|
||||
```
|
||||
|
||||
`STRATA_PF_FUSED=1` reaches only chunks of `STRATA_PREFILL_STREAM_MIN` tokens or more (1,024 by default, the floor measured on
|
||||
a discrete card, where a smaller chunk does not pay for streaming every expert); a smaller read runs its experts through MMQ.
|
||||
With every expert in the unified memory nothing streams, and MMQ is the slow part: an agent's turn - a tool result of ~1,000
|
||||
tokens on a cached conversation - read in 3.1-6.0 s at 1,024 and 0.9-2.5 s at 128 (C2T8, `--no-prefill-borrow`; 12-turn
|
||||
replay 3.4 -> 2.1 s per turn). Its output is the fused path's, which reads of 1,024 tokens or more already take; it is not
|
||||
under `STRATA_PF_SWITCH_MIN_T`, which gates only the hyper-connection and padding switches. A UD-Q4_K_XL or other K-quant
|
||||
pack takes the fused experts only with `STRATA_PF_FUSED_KQ=1` as well.
|
||||
|
||||
`STRATA_PF_F16=1` (gfx11 only; add it to the list above) runs the covered prompt experts on the F16 matrix cores instead of
|
||||
the int8 ones: K-quant gate/up and Q5_1 down (with `STRATA_PF_FUSED_KQ=1`), IQ2 / IQ3 / IQ4_XS gate/up, Q2_0 / IQ4_NL / Q8_0
|
||||
down. One layer, 16,384 tokens: Q4_K / Q5_1 85.3 -> 53.5 ms, IQ3_S / IQ4_NL gate/up 11.65 -> 9.87 and down 6.11 -> 4.71 ms.
|
||||
It rounds differently from the int8 kernels. First-token KL against a run with no switches, 12 natural-text prompts of
|
||||
1.5K-24K tokens (PolyStrata's own docs and sources), top-1 the same in 12 of 12: UD-Q4_K_XL mean 0.0068 (median 0.0021) against
|
||||
0.0031 (0.0024) for `STRATA_PF_FUSED=1 STRATA_PF_FUSED_KQ=1` without it; UD-IQ4_XS 0.0085 (0.0036) against 0.0068 (0.0032). One
|
||||
1.5K prompt carries most of the Q4_K_XL mean (0.049).
|
||||
|
||||
`STRATA_REFILL_PARTS=1` (opt-in, exact; HIP and CUDA, a GGUF read in place) refills the expert-cache slots a prompt borrowed straight from the GGUF mapping (an expert's gate, up and down tensors) instead of through an assembled 4 MB copy per expert: the same bytes in the slot (checked against the assembled blob on 162 slots), 0.1 to 0.3 s less at the end of a prompt; gfx1151, UD-Q4_K_XL and UD-IQ4_XS: a 4K-8K prompt +2.3% to +3.5%, 32K +1.1%. It is not in the table above because only gfx1151 has measured it.
|
||||
|
||||
Two engine flags help on long contexts and are not Strix-specific: `--mtp-window 8192` (the draft layer attends to the last 8,192
|
||||
cells: 64K output +3.5%, 32K -0.4%) and `--spec`, `--lookup-chain`, `--mtp-q4` (see [DETAILS.md](DETAILS.md)).
|
||||
|
||||
## 6. Measured
|
||||
|
||||
Ryzen AI Max+ 395 (128 GB, gfx1151), the maintainers' fast configuration of section 5 on top of the defaults of section 4, `--spec 4`,
|
||||
`--mtp`, `--lookup-chain 3`, `--mtp-q4 all`, `--prefill 16384`, int8 KV, all experts in the unified memory. Prompt tok/s is
|
||||
(prompt tokens - 1) / prompt time, output tok/s is the tokens / decode time; medians of 3 runs, one fresh process per run, the two
|
||||
engines interleaved. "Before" is the maintainers' earlier engine branch (the same switches set by hand), "now" is this release.
|
||||
Every pair printed the same token ids.
|
||||
|
||||
| Model | Context | Prompt before -> now | Output before -> now |
|
||||
|---|---|---|---|
|
||||
| UD-IQ4_XS | 8K | 1,212 -> 1,293 (+6.7%) | 51.7 -> 53.8 (+4.0%) |
|
||||
| UD-IQ4_XS | 128K | 1,241 -> 1,320 (+6.4%) | 49.3 -> 51.4 (+4.2%) |
|
||||
| UD-Q4_K_XL | 8K | 1,136 -> 1,169 (+2.9%) | 50.6 -> 52.6 (+3.9%) |
|
||||
| UD-Q4_K_XL | 128K | 1,220 -> 1,248 (+2.4%) | 41.6 -> 43.3 (+3.9%) |
|
||||
| IQ3_S | 8K | 1,202 -> 1,242 (+3.4%) | 56.2 -> 59.7 (+6.3%) |
|
||||
| IQ3_S | 128K | 1,254 -> 1,312 (+4.6%) | 40.6 -> 42.8 (+5.5%) |
|
||||
| IQ3_XXS | 8K | 1,237 -> 1,238 (+0.1%) | 48.8 -> 51.5 (+5.6%) |
|
||||
| IQ3_XXS | 128K | 1,259 -> 1,252 (-0.6%) | 48.4 -> 50.9 (+5.1%) |
|
||||
|
||||
UD-IQ4_XS at 4K / 32K / 64K (5-6 interleaved pairs): prompt +9.2% / +6.0% / +5.3%, output +5.0% / +3.9% / +4.6%.
|
||||
IQ3_XXS at 8K was measured again with 6 interleaved pairs (an earlier 3-run set had read 5% low while other jobs shared the GPU): prompt equal, output +5.6%. With the defaults off the same build's prompt is 8% lower (1,137), so the table helps there too.
|
||||
|
||||
### Re-measured on the merged 0.1.40 code
|
||||
|
||||
The same box and method, no environment switches at all (the arch defaults only), on the final merged tree. 4 interleaved pairs per cell,
|
||||
medians; "j" is the build of the table above (the Aurora port before the other 0.1.40 work was merged), "merged" is the release
|
||||
code. Every run printed the same token ids, and the ids also match `strata-int29` (the v4.2 config) on UD-IQ4_XS and UD-Q4_K_XL at
|
||||
a8 / 4K / 64K.
|
||||
|
||||
| Model | Context | Prompt j -> merged | Output j -> merged |
|
||||
|---|---|---|---|
|
||||
| UD-IQ4_XS | 8K | 1,260 -> 1,159 (-8.0%, spread 1,070-1,320) | 53.94 -> 53.14 (-1.5%) |
|
||||
| UD-IQ4_XS | 128K | 1,317 -> 1,299 (-1.4%) | 51.38 -> 50.72 (-1.3%) |
|
||||
| UD-Q4_K_XL | 8K | 1,163 -> 1,104 (-5.0%, spread 890-1,240) | 52.66 -> 50.47 (-4.2%) |
|
||||
| UD-Q4_K_XL | 128K | 1,252 -> 1,211 (-3.3%) | 43.28 -> 42.64 (-1.5%) |
|
||||
| IQ3_S | 8K | 1,283 -> 1,265 (-1.4%) | 59.81 -> 59.10 (-1.2%) |
|
||||
| IQ3_S | 128K | 1,311 -> 1,310 (-0.1%) | 42.74 -> 42.09 (-1.5%) |
|
||||
| IQ3_XXS | 8K | 1,127 -> 1,212 (+7.6%) | 51.64 -> 50.95 (-1.3%) |
|
||||
| IQ3_XXS | 128K | 1,252 -> 1,250 (-0.1%) | 50.88 -> 50.22 (-1.3%) |
|
||||
|
||||
The prompt numbers at 8K swing by more than the differences (other jobs share this box), so read them as unchanged. The output
|
||||
column moved by a steady -1.2% to -1.5% (-4% on UD-Q4_K_XL at 8K, where the default arm also had slow runs): since 0.1.39 the
|
||||
shared-expert stream fork is off by default on HIP (#816). It overlaps the shared expert with the routed experts on a second
|
||||
stream and does help on gfx1151, so 0.1.40 turns it on there by default (section 4). It changes no bits (same ids). 4 interleaved pairs at 8K, merged
|
||||
code with the fork off -> on: UD-IQ4_XS output 53.1 -> 54.05 (+1.8%), UD-Q4_K_XL 49.5 -> 52.8 (+6.7%, the default arm ranged 46.0-52.1),
|
||||
prompt unchanged. With the fork on, the merged code's output is at or above the j build's (IQ4_XS 54.05 vs 53.94).
|
||||
@@ -0,0 +1,19 @@
|
||||
# Test requests and hardware wanted
|
||||
|
||||
PolyStrata is built and measured on a few machines. Results from other hardware are welcome and are used: they tell us
|
||||
what a setup really does and show where the engine picks something wrong. Write a report as described in
|
||||
[COMMUNITY_BENCHMARKS.md](COMMUNITY_BENCHMARKS.md): the build, the card and PCIe width, the CPU and RAM speed, the
|
||||
model file, the exact command, three runs per size, and what you did not test. Post it in an issue, or on the pull
|
||||
request it is about.
|
||||
|
||||
This list is edited by the maintainers. An item stays until a report answers it.
|
||||
|
||||
| Wanted | Why | Example of an earlier answer |
|
||||
|---|---|---|
|
||||
| Two NVIDIA cards of different sizes (a large and a small one), in both card orders, with `--layer-split auto` | There is no unequal pair here to check the split planner; the card order and the small card's free memory changed the split | #880, #1238 |
|
||||
| Three or four NVIDIA GPUs | No multi-GPU NVIDIA rig of that size here | #880 |
|
||||
| Pascal (sm_61: Tesla P40, P100, GTX 10 series) | Older cards run on the fp32 path and can behave differently from newer ones | #875, #876 |
|
||||
| A Linux host with 32 GB of RAM or less | The expert file tier and the resident mode depend on how much of the model fits in RAM | #1194 |
|
||||
| A long soak (an hour or more of back-to-back requests) on a split or resident setup | Shows crashes, drift and heat that a short run does not | #848 |
|
||||
|
||||
To add a request, open a pull request that adds a row, or tell the maintainers in an issue.
|
||||
@@ -0,0 +1,195 @@
|
||||
# Something went wrong?
|
||||
|
||||
The common problems and what to do. Back to the [README](../README.md#something-went-wrong). The full table of
|
||||
error messages, with the older engine fixes, is in the [details](DETAILS.md#troubleshooting).
|
||||
|
||||
## While installing or starting
|
||||
|
||||
**My PC froze, or got very slow, the first time PolyStrata started.**
|
||||
That's normal while it starts, most of all the first time. PolyStrata loads 35-55 GB into your RAM, locks part of it for
|
||||
the graphics card, and works out how much of the model fits on your GPU. The mouse can freeze for a few minutes.
|
||||
**Wait, and don't close the window.** The next starts are much faster. Still frozen after 10 minutes? Restart the
|
||||
PC, close other programs (browsers use a lot of RAM) and try again. If it keeps happening, pick a smaller size (Q2_0
|
||||
or IQ2_XS).
|
||||
|
||||
**It stopped while downloading or installing.**
|
||||
Run `START-HERE.bat` (Linux: `./setup.sh`) again. It continues where it stopped.
|
||||
|
||||
**It says the NVIDIA driver is too old.**
|
||||
Update it (NVIDIA App or [nvidia.com/drivers](https://www.nvidia.com/drivers)), restart the PC, and run
|
||||
`START-HERE.bat` again.
|
||||
|
||||
**It says port 8080 is already in use.**
|
||||
PolyStrata is already running. Look for its window. Or another program uses the port: `START-HERE.bat --port 8081`.
|
||||
Only an address that is really taken says "already in use". Any other reason (Windows keeps the port reserved, or
|
||||
the config's `"host"` is not an address of this PC) is printed as what the OS said, with what to change (#769).
|
||||
|
||||
**"Windows blocked the PolyStrata engine (or the image encoder) ... Smart App Control".**
|
||||
On a clean Windows 11, Smart App Control refuses programs that are not signed, and PolyStrata's `strata.exe` and
|
||||
`strata-vision.exe` are not (#735). Turn it off (Windows Security > App & browser control > Smart App Control
|
||||
settings; it cannot be turned back on without a reset of Windows), or, if only the image encoder is blocked, run
|
||||
`START-HERE.bat --setup --vision no`.
|
||||
|
||||
**A new engine misbehaves after an update.**
|
||||
An update keeps the engine it replaced in `engine\.previous` (one generation, about 210 MiB).
|
||||
`python setup.py --rollback-engine` puts it back (and keeps the newer one there: run it again to go forward) (#670).
|
||||
|
||||
**UPDATE.bat / update.sh say "git pull did not succeed", or "has no commit in common" (#1276).**
|
||||
The repository's history was cleaned up on 2026-10-06, so a clone made before that cannot be updated with `git pull`.
|
||||
The 0.1.40.2 scripts handle it: when no tracked file is edited they keep your old commits in the branch
|
||||
`pre-cleanup-backup` and move the clone to the new history; otherwise they print the two commands for you. Your models,
|
||||
settings and engine are untracked files and are never touched. An older UPDATE.bat / update.sh (before 0.1.40.2) cannot
|
||||
do this itself: run these once in the PolyStrata folder, then use UPDATE.bat as usual (add `git stash` first if `git status`
|
||||
lists edited files):
|
||||
|
||||
git fetch origin
|
||||
git branch pre-cleanup-backup
|
||||
git checkout -B main origin/main
|
||||
|
||||
**Python or the build tools could not be installed.**
|
||||
Install what it names (links are printed), then run it again. Everything already done is kept.
|
||||
|
||||
**Linux: the engine does not compile (`unsupported GNU version`, or `exception specification is incompatible` for
|
||||
`cospi`/`sinpi`/`rsqrt`).** Two known mismatches between the CUDA toolkit and a new Linux (#601):
|
||||
- gcc newer than 14 (Ubuntu 26.04's default 15): CUDA 12.x and 13.0 refuse it. Install g++-14 and run
|
||||
`CXX=g++-14 ./setup.sh` (CC, CXX and CUDAHOSTCXX name the build's compilers; setup passes them to CMake itself,
|
||||
so an already-configured build folder picks them up too, #1645).
|
||||
- glibc 2.43 with CUDA 12.9: the toolkit's math headers clash with glibc's, already in CMake's first test compile.
|
||||
Use CUDA 12.8 or 13.x instead. Setup takes the newest toolkit it finds; `STRATA_NVCC=/usr/local/cuda-12.8/bin/nvcc
|
||||
./setup.sh` makes it use that one (only that one).
|
||||
|
||||
**The first start takes minutes.**
|
||||
It is reading 34-55 GB into RAM; the second start is faster while the files are in the OS cache. Started from Task
|
||||
Scheduler, it can be 24x slower: see [Running it at startup](DETAILS.md#running-it-at-startup-task-scheduler).
|
||||
On Linux the engine now asks the kernel to read the model files ahead (a cold start went from ~920 s to 70 s on one
|
||||
PC); `STRATA_READ_AHEAD=0` turns that off. On Linux with transparent huge pages on `always`, the arena no longer asks
|
||||
for `MADV_HUGEPAGE` on top (a fragmented machine spent minutes compacting memory, #771); `STRATA_NO_ARENA_THP=1` skips
|
||||
that request on any setting.
|
||||
|
||||
**Setup says the engine does not match GitHub's checksum.**
|
||||
Setup checks the downloaded ready-made engine against the SHA-256 GitHub publishes. On a mismatch the file is corrupt or was changed on the way, so setup deletes it and stops; run setup again to download it afresh. If GitHub gives no checksum (offline, rate limited, your own mirror), setup warns and installs anyway. `STRATA_SKIP_SHA256=1` skips the check, only if you insist.
|
||||
|
||||
## While it answers
|
||||
|
||||
**It's very slow and the disk light keeps blinking.**
|
||||
Your PC is out of free RAM. Close other programs, or pick a smaller size (Q2_0 or IQ2_XS).
|
||||
|
||||
**An answer stopped with "the engine stopped unexpectedly".**
|
||||
Usually not enough RAM (on Linux the system then stops the engine). Just send your message again: PolyStrata starts the
|
||||
engine by itself. If it keeps happening, close other programs or pick a smaller size.
|
||||
|
||||
**It says the prompt exceeds the context.**
|
||||
The conversation is longer than the context you chose. Start a new chat, or run `SETUP.bat` and pick more
|
||||
context.
|
||||
|
||||
**It is slower than the tables.**
|
||||
The monitor plugged into the graphics card and other GPU programs take VRAM from the expert cache; RAM running below
|
||||
its rated speed (enable EXPO/XMP in the BIOS) slows the CPU half.
|
||||
|
||||
**An earlier reply that came back empty is gone from the chat history (0.1.40, #843).**
|
||||
The server leaves out finished assistant turns that have no text, so the next reply does not copy the empty ones.
|
||||
`STRATA_KEEP_EMPTY_TURNS=1` in the server's environment renders them as before.
|
||||
|
||||
**A Turing card (RTX 20) reads prompts above ~90K tokens differently (0.1.40, #743).**
|
||||
The prompt's top-k selection takes a wider kernel there, with the same ids. `STRATA_TOPK_STREAM=0` restores the old one.
|
||||
|
||||
**Decode is several times slower with `--expert-cache N` than with `auto` (#781, #831).**
|
||||
An explicit N is a byte budget that is not checked against the free VRAM once the slots are written. On a card it
|
||||
fills (the log says `0 MiB of VRAM free with everything loaded - LOW`), Windows pages the GPU's memory and decode drops
|
||||
from 100 to 14 tok/s with only a few hundred slots too many. Use `--expert-cache auto`, or a smaller N.
|
||||
|
||||
**A low-RAM PC (about 32 GB) stalls with `--resident-budget-gib N` (#649).**
|
||||
The budget is pinned (locked) in RAM, which leaves the OS and the CPU workers little room. `STRATA_RESIDENT_PIN=0` keeps
|
||||
it pageable; a smaller budget works too.
|
||||
|
||||
**Decode got slower in 0.1.40 on a 32 GB PC with `--resident-budget-gib N`, and the drive is read hard (#1194, #1116, #1085).**
|
||||
The start line "the file tier reads unbuffered" means the experts outside the RAM copy are read straight from the drive.
|
||||
0.1.40 chose that whenever the free RAM could not hold all of them; but the same few come back token after token, and
|
||||
a cache a twentieth of their size serves most of the repeats. 0.1.40.2 asks for that much (at least 1.5 GiB beside the
|
||||
4 GiB headroom) and reads through the cache otherwise, which measured 7% to 118% faster decode with a third to a sixth of
|
||||
the drive traffic on a 20 to 32 GB box. On 0.1.40 / 0.1.40.1: `STRATA_UNBUFFERED_LOAD=0` does the same, `=1` forces the
|
||||
unbuffered reads.
|
||||
|
||||
**Linux: the start is OOM-killed while the engine allocates the page-locked expert copy (#1250).**
|
||||
Page-locked pages come from the driver in one go and cannot wait for the kernel to give back file cache, so with the
|
||||
model files' cache in the way (little really free RAM, much "available") the host could run out. 0.1.40.2 gives back the
|
||||
cached pages of the model files it mapped before it page-locks the copy; when the really free RAM still does not cover it,
|
||||
it takes the pages in 1 GiB steps while the RAM available (cgroup limits included) stays above the headroom, page-locks
|
||||
what it has, and keeps the rest resident but pageable with a warning ("only N of M GiB could be page-locked"): the answers
|
||||
are the same, only the copies of the pageable part to the GPU go through the CPU. `STRATA_PIN_GUARD=0` turns this off,
|
||||
`STRATA_PIN_RESERVE_GIB=N` sets the RAM that must stay free (default: `STRATA_RESIDENT_HEADROOM_GIB`, 4 GiB).
|
||||
|
||||
**The Windows display driver resets, then the PC blue-screens (0x141, then 0x116 in `nvlddmkm`) during an answer (#961).**
|
||||
This is the NVIDIA driver, not PolyStrata: the report shows the same wedge with other CUDA programs on that driver (610.88,
|
||||
RTX 4080 SUPER). Try another driver (a Studio one, or an older one) and a lower power limit; if it only happens with
|
||||
`--spec 4`, `--spec 0` avoids the verify window while you wait for a driver fix.
|
||||
|
||||
**An RTX 50 card (a source build with CUDA 13.2) answers with nonsense, or reads prompts wrongly (#892, #968).**
|
||||
CUDA 13.2.0 and 13.2.1's compiler (nvcc 13.2.51) miscompile some of the engine's kernels for sm_120: on our RTX 5070 the IQ2_S and IQ3_S
|
||||
products are wrong (relative error 0.5 to 1.0 in the tests) with 13.2 and right with 13.0. The ready-made engine is built
|
||||
with 13.0. If you compile it yourself, use CUDA 13.0, 13.1 or 13.2.2 (13.2.2, nvcc build 13.2.86, fixes it; an older one can sit next to a newer: `STRATA_NVCC=<path to its nvcc>`);
|
||||
setup warns when it finds 13.2.0 or 13.2.1 for such a card, and takes an older 13.x when one is installed.
|
||||
|
||||
**Pictures are refused, or slow.**
|
||||
"this server was started without the vision encoder": the model was set up for text only - run setup again with
|
||||
`--vision gpu` (or `--vision cpu`). Pictures that take several seconds (about 3 s at 300 image tokens on 8 cores, more with more tokens) are read by the encoder on the CPU; `--vision gpu`
|
||||
(NVIDIA, ~1.4 GB of VRAM) makes it 0.1-0.5 s.
|
||||
|
||||
## AMD cards
|
||||
|
||||
**"No AMD GPU found (the amdgpu driver's KFD topology is empty)" on Linux.**
|
||||
The kernel's amdgpu driver is not loaded for the card. Integrated Radeon GPUs are listed as not supported; setup
|
||||
lists every card it found and whether PolyStrata can use it.
|
||||
|
||||
**The engine stops at start with the card's name, its architecture and the build's list.**
|
||||
The engine was compiled for another card (for example after moving the PolyStrata folder to another PC). Run
|
||||
`./setup.sh --setup --backend hip`: it compiles the engine for this card's architecture.
|
||||
|
||||
**On Windows the engine exits with `0xC0000005` in `amdhip64_7.dll` before it prints anything (#654).**
|
||||
Two things in your environment can cause it, and the server now repairs both before it starts the engine (it says so in
|
||||
the log): `HIP_PATH`, `HIP_DEVICE_LIB_PATH` or `LLVM_PATH` naming a ROCm folder that no longer exists (a deleted build),
|
||||
and a `TEMP`/`TMP` folder the engine cannot create files in (AMD's runtime compiles its first kernels through temporary
|
||||
files). If you start `strata.exe` by hand, fix them yourself: `set HIP_PATH=`, and point `TEMP` and `TMP` at a normal
|
||||
folder such as `C:\Temp`.
|
||||
|
||||
**Windows AMD: the driver resets (VIDEO_ENGINE_TIMEOUT_DETECTED / screen flicker / the engine dies mid-answer).**
|
||||
Windows gives a GPU about 2 seconds to answer; when a graphics card does not, it resets the driver (a TDR): the screen
|
||||
flickers, the engine dies, and the Event Viewer shows `VIDEO_ENGINE_TIMEOUT_DETECTED` (#613, with #579 and #541 on
|
||||
Linux). PolyStrata 0.1.39 and newer say "the GPU stopped responding" in the log. It was seen with KV streaming on
|
||||
(`--kv-resident 32768`, which setup turns on from 64K context) while reading a long prompt on a gfx1201 card. Try these
|
||||
in order, one at a time, and tell us what changed:
|
||||
1. **Send us the evidence.** The last ~80 lines of `strata-<model>.log` in the PolyStrata folder (the server window shows
|
||||
the same lines), your AMD driver version (AMD Software > System), your card and Windows version, the PolyStrata
|
||||
version, and the exact steps (context size, how long the prompt was, which app sent it). If Windows wrote a
|
||||
dump, the newest `.dmp` in `C:\Windows\LiveKernelReports\WATCHDOG` (or `C:\Windows\Minidump`) helps; it holds no
|
||||
chats, only the driver state.
|
||||
2. **Find the step that hangs:** add `"STRATA_PF_STEP_SYNC": "1"` to the `"env"` block of `strata-<model>.json`
|
||||
and restart. The prompt path then waits for the GPU after each step and logs any step over 250 ms, so the log names
|
||||
the step. It is slower; use it to diagnose, then take it out.
|
||||
3. **`"STRATA_KV_HOST_DMA": "1"`** in the same `"env"` block: no GPU kernel writes the RAM copy of the K/V during a
|
||||
prompt, it is copied by DMA instead. Same answers.
|
||||
4. **No KV streaming:** run setup again and pick 32K context (or remove `--kv-resident` and its number from
|
||||
`"args"` in the JSON, with a context that fits the VRAM).
|
||||
5. **A smaller prompt chunk:** change `--prefill` in `"args"` (for example `--prefill 512`): each GPU launch then does
|
||||
less work between two checks by Windows. Prompts are read more slowly.
|
||||
6. **Optional, your decision: give Windows more time (`TdrDelay`).** The default is 2 seconds. In the registry,
|
||||
`HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers`, a DWORD `TdrDelay` of `10` (seconds)
|
||||
lets a long GPU job finish before Windows resets the driver; restart the PC. It hides the symptom and does not fix
|
||||
a GPU that has really hung, and a hung GPU then freezes the screen for those 10 seconds. PolyStrata changes no Windows
|
||||
setting itself; to undo it, delete the value.
|
||||
7. **Driver:** use the newest AMD Software release for your card (Adrenalin, not a Windows Update driver) and restart
|
||||
after installing. If it started after a driver update, tell us both versions; going back one version is a fair
|
||||
test.
|
||||
|
||||
**Large pinned host allocations fail on ROCm although RAM is free.**
|
||||
See [AMD_HIP.md](AMD_HIP.md#model-and-serving-configuration): the mapped expert mode avoids the full pinned arena.
|
||||
|
||||
**"verify: timed out at layer N" or "no progress for 60 s" on AMD (Linux), mostly with `--mmap-experts`.**
|
||||
Two reports fixed it with `"GPU_PINNED_MIN_XFER_SIZE": "1048576"` (RX 6800) or `"HSA_USERPTR_FOR_PAGED_MEM": "0"` (two
|
||||
R9700) in the `env` block of the server JSON, then a restart. Experimental, one machine each; on a systemd unit use
|
||||
`MemoryMax`, not `MemoryHigh`. Details: [AMD_HIP.md](AMD_HIP.md#linux-verify-timeouts-while-the-kernel-reclaims-host-memory-experimental-workarounds).
|
||||
|
||||
## Still stuck?
|
||||
|
||||
Look in the [full troubleshooting table](DETAILS.md#troubleshooting), or open an
|
||||
[issue](https://github.com/VecSzn/PolyStrata/issues) and attach `strata-<model>.log` from the PolyStrata folder.
|
||||
Loaded 100 of 1102 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user