Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.
Python amdapple-siliconcudadeepseekexl3exllamav3glminferencellmllm-inferencelocal-llmnvidiaopenai-apiquantizationqwenrocmstrix-halo
Layer split documentation.
Resynthc883a2e763a6
diff --git a/doc/split-support-matrix.md b/doc/split-support-matrix.mddeleted file mode 100644index 458132a..0000000--- a/doc/split-support-matrix.md+++ /dev/null@@ -1,79 +0,0 @@-# Layer-split support matrix--What the contiguous layer split (`exllamav3/device_map.py`, `exllamav3/bridge.py`,-`exllamav3/serve_split.py`, `Model.load(device_map=...)`) can place today, per model family-and per serve flavor. Stage 1.5 (2026-11-10): the core is policy-driven, devices are-selected by position rather than architecture, GLM is the first adapter, and the part0-reserve is a layout-neutral slab; GLM's Phase 4 gate replay is the measured baseline.-Qwen and DSV4 entries remain code inventories, not load-tested.--Legend — placement: **part0** (the first N layers), **part1** (the rest), **cpu**, **host**-(never enters the map: CPU/streamed by design). Stage links point at the roadmap stage that-must finish before that row is claimable.--**Measured configuration.** RX 9070 (gfx1201, 15.92 GiB) over USB4 as `part0` and a-118 GiB Strix Halo iGPU (gfx1151) as `part1`. Numbers below and in-`docs-notes/split-log.md` are measurements from that pair; the interface does not assume-either architecture or role.--## Measured — GLM-5.3-Flash (`tools/glm/serve.py`, `tools/strix_halo/split_*`)--| Component | Config | Placement | Notes |-| --- | --- | --- | --- |-| text (`Model.from_config`) | shared | layers 0..N-1 part0, N..44 part1; endcaps per allowlist | measured N=4, N=6 at `-c 65536`; N=5 is the long-context setting until the gfx12 KDA kernel lands |-| mtp (`component="mtp"`) | shared | all part0 when `--endcaps on`, else part1 | `ComponentPolicy(whole_component)` (no own trunk), reserve owned by the text map |-| vision (`component="vision"`) | shared | all part0 when `--endcaps on`, else part1 | declared as a whole component; the same bridge/config covers it |-| `embed_tokens` | shared | cpu (`prefer_cpu` cap) | stays host-side by design |-| text endcaps | shared | `hc_expand`/`hc_head`/norm/lm_head part0 per allowlist; unknown non-layer modules part1 | allowlist is class/key based (`TEXT_ENDCAP_TYPES`/`TEXT_ENDCAP_SUFFIXES`), no per-model placement in core |-| KV/recurrent cache | built per model/cache | each cache/recurrent layer follows its block | measured 0.62 GiB part1 / 0.12 GiB part0 at 65K; placement audit after load |-| bridge | shared config | installed by `SplitPlan.install_bridges` for every config | one `Bridge` per config; split_active defuses graphs |--Gate status (Stage 0 replay): N=6 65K load with MTP+vision part0 13.68/13.94 GiB, plain split-run-to-run deterministic; results appended in `docs-notes/split-log.md`. Stage 1.5 selection-changes are CPU-tested; the GPU gate (N=4/6 load in both device positions, plain determinism,-120K needle N=5, split-off regression) is the next checkpoint run.--Known blockers: gfx12 fused KDA kernel (separate PR), MTP cross-device acceptance/determinism,-auto-N not yet subtracting components declared after the target (Stage 5), 128K determinism-must be re-verified with the slab reserve on the box. GLM's auto-N long-context cap applies-only on a gfx12 part0 (adapter tuning, not a split rule).--## Code inventory — Qwen3.8-Flash-Next (`tools/qwen/serve.py`)--| Component | Config | Placement intent | Stage |-| --- | --- | --- | --- |-| text | own (`Model.from_config`) | layers via SplitPlan; `.load()` with no device today → autosplit | 3 |-| dflash drafter | **separate `Config` (`dconf`)**, `attach_to` | needs its own bridge + split_active (install per config) | 3 |-| mtp | shared config, `component="mtp"` | all part0 (endcaps on), else part1 | 3 |-| vision | shared config, `component="vision"` | part0 when it fits | 3 |-| ngram table (`NGramEmbedding`) | inside the text model | host/swap-resident (`ensure_resident`, 24.4 GiB) — never part0 | 3 |-| PLE / DQ / GR / GDN HIP kernels | JIT loaders | gfx11.5-only gates; per-device arch needed; no implicit part0 placement | 3 |-| QSA sparse attention (quant cache pages) | cache layers | gfx1201 `dsa_topk_gfx12` illegal access — keep off part0 until fixed | 3 |-| KV/GDN recurrent state | `Cache(…, max_history=ndt, max_batch_size=sessions)` | per-layer KV automatic; recurrent slot devices need an audit | 3 |--Serve env notes: CUDA-side graph preset (`EXL3_CUDA_GRAPH*`), ROCm chunked prefill-(`EXL3_SCHED_CHUNK_IL`), `EXL3_PF_GR_FUSE`/`EXL3_GR_PF_FUSE` deferred-residual keys must be-disabled for split (roadmap Stage 3).--## Code inventory — DeepSeek-V4.1-Flash (`tools/ds41` ↔ `exllamav3/dsv41`)--The DSV4 engine does **not** go through `Model.load()`: `dsv41/pack.py:load_pack` streams-`model.modules` to one device with `mod.load(dev)` and builds `DSV41Serving(..., device=dev)`.--| Component | Today | Placement intent | Stage |-| --- | --- | --- | --- |-| text blocks | per-module `mod.load(dev)` on one device | contiguous N via a SplitPlan over the same module list | 4 |-| mtp | `Model.from_config(cfg, component="mtp")` then `mod.load(dev)` | part0 with endcaps / part1 | 4 |-| engram tables | `MemoryEngramStore` / `PrefetchRowStore` (O_DIRECT, host) | stay host; `engram_inject` gathers rows at the layer that needs them | 4 |-| MoE | `GroupedMoE(b.ex_w1, ex_w3, ex_w2, dcfg, dev, …)` one device + `MixedKStore` | per-device grouped backends; no cross-device expert state | 4 |-| decode graphs | `serve_graph.DecodeGraph` per run-of-layers around engram layers | the existing per-segment split is the natural seam for Stage 6 | 4/6 |-| KV/state | `DSV41Cache` (custom pool, kv source layers + shared read) | audit device placement of pools and slots | 4 |-| vision | `VisionTower.load(vision_dir, …, vision_device)` | separate device arg; map to part0/part1 policy | 4 |-| tiered experts (`EXL3_EXPERT_BUDGET_GIB`) | forces `DSV41_DECODE_GRAPH=0` | graphs-off for split anyway (Stage 6) | 4 |--## Candidate (best effort) — Flint, Mimo, generic `Model` trees--`tools/flint/serve.py` and `tools/mimo/serve.py` are single-`Config` engines calling-`Model.from_config(...)` + `.load()`; both already accept `device_map` after the Stage 1 core-lands (mimo loads its vision tower separately, mirroring GLM). They inherit whatever the-universal core does for text layers + endcaps; no dedicated adapter is planned (Stage 7).diff --git a/doc/split.md b/doc/split.mdindex 9419e36..3619a84 100644--- a/doc/split.md+++ b/doc/split.md@@ -1,140 +1,129 @@-# Contiguous layer split (part0 + part1 devices)+# Contiguous layer split-*Status: Stage 1.5 of the universal roadmap (see `.kilo/plans/1794309410242-universal-layer-split-roadmap.md`).-The core is policy-driven (`SplitPlan`/`ComponentPolicy`), devices are selected by-position rather than by architecture, the GLM server is the first adapter, and the part0-reserve is a layout-neutral slab. This file is the durable user/ops reference; the-roadmap owns the staging, and `docs-notes/split-log.md` (untracked) owns raw-measurements.*+The layer split places the first N transformer layers of a model on one GPU (`part0`) and+the remaining layers on another (`part1`) in a single process. It is for models that do not+fit on one device, or for pairing a small fast card with a large unified-memory device.-## What it is+Status: GLM-5.3-Flash is measured and supported by the GLM server. Qwen3.8-Flash-Next and+DeepSeek-V4.1-Flash adapters are staged; Flint and Mimo use the generic model path. See+[Model support](#model-support).-One process places the first N transformer layers plus the small endcaps of a model on-one GPU (`part0`) and the rest on another (`part1`), with an asynchronous host-staged-bridge on every crossing:+## How it works++ part0: layers 0..N-1 + endcaps part1: layers N..last+ \______________________________________/+ host-staged crossings++`part0` and `part1` are positions in the layer order, not device indices. Either physical+device can serve either part. Older revisions call the parts `front`/`main`; current flags+and environment names use `part0`/`part1` only.++Every tensor that crosses the split goes through an asynchronous host-staged bridge:src tensor --D2H--> pinned slot ring --H2D--> dst tensor-`part0` and `part1` are positions in the layer order, not CUDA indices: `part0` owns-layers `0..N-1` (plus its endcaps) and `part1` owns the remaining layers. Either physical-device may serve either part. Earlier revisions, the roadmap and-`docs-notes/split-log.md` call these `front`/`main`; the current flags and env names are-`part0`/`part1` only (`--front-*` and `KYOJIN_FRONT_*` are not accepted).+Both legs are enqueued on the two devices' compute streams, so the host does not wait. The+destination is a fresh allocation. `KYOJIN_BRIDGE=0` disables the bridge; cross-device+moves then use `to_device` with a blocking host bounce instead of probing or using a direct+peer copy. An explicit `EXLLAMA_NO_P2P_COPY` still wins.++Measured configuration: an RX 9070 (`gfx1201`, 15.92 GiB) over USB4 as `part0` and a+118 GiB Strix Halo iGPU (`gfx1151`) as `part1`. The numbers below are measurements from+that pair, not assumptions of the interface.-Both legs are enqueued on the two devices' own compute streams; the host never blocks. The-destination tensor is a fresh allocation, so callers may keep using it after the slot cycles.-`KYOJIN_BRIDGE=0` falls back to `to_device` (split still runs, crossings block). With the-bridge disabled, cross-device moves are forced through host memory (a blocking bounce), so-the fallback does not probe or use the direct peer path; an explicit-`EXLLAMA_NO_P2P_COPY` still wins.+## Quick start-Devices are not tied to a role. Either device may serve `part0` or `part1`, and the split-is not restricted to a particular architecture pair. Kernel support remains per-arch: the-split owns placement and transport, not kernel ports.+The GLM server and the split harnesses accept the flags below. The environment-only path+is useful for wrappers that cannot pass CLI flags:-**Measured configuration.** The development box is an RX 9070 (gfx1201, 15.92 GiB) over-USB4 as `part0` and a 118 GiB Strix Halo iGPU (gfx1151) as `part1`. All numbers in-`docs-notes/split-log.md` and the support matrix come from that pair unless a note says-otherwise; they are measurements, not assumptions of the interface.+```sh+KYOJIN_PART0_LAYERS=6 \+KYOJIN_PART0_DEVICE=gfx1201 \+KYOJIN_PART1_DEVICE=gfx1151 \+ python tools/glm/serve.py --model /path/to/model+```## Interface-| Flag (CLI) | Env fallback | Meaning |+| Flag | Environment fallback | Meaning || --- | --- | --- |-| `--part0-layers auto\|N` | `KYOJIN_PART0_LAYERS` | first N transformer layers on `part0`; 0 = off |-| `--part1-device auto\|cuda:N\|gfxXXXX\|uuid\|name` | `KYOJIN_PART1_DEVICE` | `part1` device selection (`auto` = `cuda:0`) |-| `--part0-device auto\|cuda:N\|gfxXXXX\|uuid\|name` | `KYOJIN_PART0_DEVICE` | `part0` device selection (`auto` = the only other device when two are visible; otherwise a selector is required) |-| `--endcaps on\|off` | `KYOJIN_ENDCAPS` | move the text allowlist (norm/hc/lm_head-like) and the whole MTP/vision component (all non-CPU modules) to `part0` (default on) |-| `--part0-reserve-gb` | `KYOJIN_PART0_RESERVE_GB` | VRAM held as a load-time slab on `part0` for workspace (default 1.2; a tuning value, size it to the card) |-| `--split-preset auto\|glm\|qwen\|ds41\|none` | `KYOJIN_SPLIT_PRESET` | per-model unsafe-env preset slot; GLM needs none today |-| `--split-graphs auto\|on\|off` | — | per-segment capture (Stage 6); split forces graphs off until then |+| `--part0-layers auto\|N` | `KYOJIN_PART0_LAYERS` | first N transformer layers on `part0`; 0 = split off |+| `--part1-device auto\|cuda:N\|gfxXXXX\|uuid\|name` | `KYOJIN_PART1_DEVICE` | `part1` device (`auto` = `cuda:0`) |+| `--part0-device auto\|cuda:N\|gfxXXXX\|uuid\|name` | `KYOJIN_PART0_DEVICE` | `part0` device (`auto` = the only other device when two are visible) |+| `--endcaps on\|off` | `KYOJIN_ENDCAPS` | keep text endcaps and whole MTP/vision components on `part0` (default on) |+| `--part0-reserve-gb` | `KYOJIN_PART0_RESERVE_GB` | VRAM held as a load-time slab on `part0` for workspace (default 1.2) |+| `--split-preset auto\|glm\|qwen\|ds41\|none` | `KYOJIN_SPLIT_PRESET` | per-model unsafe-environment preset; GLM needs none today |+| `--split-graphs auto\|on\|off` | - | reserved for per-segment capture; split currently runs graphs off |`cuda:N` is the torch device index **after** `HIP_VISIBLE_DEVICES`, not the `rocm-smi`index. Explicit selectors win in either position: `part0=cuda:1/part1=cuda:0` and-`part0=cuda:0/part1=cuda:1` are both valid. A part0-only selector keeps working when it-lands on `cuda:0`: with exactly two devices, `part1=auto` takes the other device. Two-explicit selectors that resolve to the same device fail, and a one-device split fails with-a clear error. With more than two visible devices, `auto` for either part requires an-explicit selector and prints the inventory.--`KYOJIN_PART0_LAYERS=…` without CLI flags also works in `model_init.init` paths-(examples/eval tools); `KYOJIN_PART1_DEVICE` is honoured there too. The legacy-`EXL3_LOAD_SPLIT` budget knob is **not** part of this interface; combining it with the-new map must error.--## Core objects (Stage 1.5)--- `exllamav3/device_map.py`: `SplitPlan` owns every component the process places.- `ComponentPolicy` declares `part0_eligible`, `endcaps_part0`, the endcap allowlist,- arch gate and unsafe env. `ComponentMap` resolves one component's contiguous boundary.- `resolve_devices(part0, part1, devices=None)` selects by position; `DeviceInfo` lets the- selection tests run without a GPU. Unknown non-layer modules are logged and kept on- `part1`; auxiliary components never move to `part0` implicitly.-- `exllamav3/bridge.py`: one bridge per *config*, installed by `SplitPlan.install_bridges`- for the target, a separate draft config, vision and any extra config.-- `exllamav3/serve_split.py` (shared with `tools/kyojin_serve_split.py`): CLI/env parsing,- device resolution, plan/load/report orchestration, split-safe env. GLM is the first- adapter; the helper is pure stdlib at import so a server can apply `SPEED_ENV` first.-- `model_init.py` uses the same plan for the `KYOJIN_PART0_LAYERS` env-only path.--## Load-time effects worth knowing--- The `part0` reserve is an **inert device slab**, not `set_per_process_memory_fraction`.- The Stage 0 replay showed a process-wide allocator cap makes 128K split runs bimodal;- the slab removes bytes from the pool and is dropped at the first `part1` module (or after- the last component), leaving the freed block available to the workspace without- changing the allocator's policy or the `part1` device's numerics. The 1.2 GiB default is- a tuning value for a small part0 card, not an architecture rule; Stage 5 derives it- from the device total.-- `prepare_for_device` routes CUDA↔CUDA moves through the bridge once- `config.split_active` is set; CPU moves keep the pinned/async path.-- Graphs: split mode declines whole-forward, lag-1, `prepare_inputs` and per-block captures- (`split_active`). Per-segment capture is Stage 6.-- Per-component load table and a cache/recurrent placement audit print after load: every- cache layer must sit on the device its owning layer was mapped to. The table's `devices`- column lists the devices that actually hold tensors, not the configured part0/part1 pair;- an empty range prints `-`. CPU-resident modules (the shared embedding) are reported- separately, so a whole MTP/vision component with endcaps on shows `part1 -` and only- part0 in `devices`.-- Auto-N is a Stage 1 skeleton: it uses actual safetensors bytes for each layer, the- cache/recurrent sizes for layers below N, the part0 endcap bytes and the reserve, with- a `KYOJIN_AUTON_SAFETY_GB` margin (default 0.25) for allocator slack. Adapter tuning- stays in the adapter: GLM caps auto at five layers for `-c > 65536` only on a gfx12- part0, where the deterministic split KDA chain adds a prefill workspace the byte budget- does not yet know. Components declared after the target (GLM's MTP/vision) are not yet- subtracted before the target load; Stage 5 owns cross-component/pre-load auto sizing.-- JIT HIP loaders compile per (device, defines) and launch on the tensor's device stream;- `kda_fused_h`, `gdn_*`, `gr_mix` and `ple_hip` are gfx11.5 WMMA/CI paths and refuse other- archs. In split mode, gfx12 runs the deterministic fla KDA chain (`EXL3_KDA_FUSE=0`- forced there); other arches keep the fused path. See PR C for the fused gfx12 port.- `qsa_prefill_hip` readiness is cached per device, and all audited dsv41/gr/ple loaders- select the calling device before every launch.--## Determinism / verification policy--- Split **off** must stay byte-identical to `main` (outputs and the serve env block), and- must not enumerate devices or mutate split env.-- Split **on** is judged by run-to-run determinism (plain greedy), KLD/task metrics and the- needle probe — a mixed-arch pair is not expected to be bitwise.-- `tools/strix_halo/split_eval.py` (GLM) runs the battery: `--baseline`, `--part0-layers`,- `--part1-device`/`--part0-device`, `--needle-depth`, `--num-draft`,- `--perf-tokens/--perf-reps`, `--compare a.json b.json`. Its context-dependent part0-layer- default is harness tuning exposed as `--long-ctx-part0-layers`/`--short-ctx-part0-layers`,- not a property of the split.+`part0=cuda:0/part1=cuda:1` are both valid. With exactly two visible devices, a part0-only+selector still works and `part1=auto` takes the other device. Two selectors that resolve to+the same device fail, and a one-device split fails with a clear error. With more than two+visible devices, `auto` requires an explicit selector and prints the inventory.++`KYOJIN_PART0_LAYERS` and `KYOJIN_PART1_DEVICE` also work in `model_init.init` paths+(examples and evaluation tools) without CLI flags. The legacy `EXL3_LOAD_SPLIT` budget knob+is not part of this interface and must not be combined with the new map.++## What gets placed++| Where | Contents |+| --- | --- |+| `part0` | first N text layers; with `--endcaps on`, the text allowlist (norm/hc/lm_head-like) and whole non-CPU MTP/vision components |+| `part1` | remaining text layers; MTP/vision when endcaps are off; unknown non-layer modules |+| CPU | the shared `embed_tokens` (`prefer_cpu`) stays host-side by design |+| cache | each KV/recurrent layer follows its owning layer; a placement audit prints after load |+| bridge | one bridge per config, covering the target, drafter and vision |++Text endcaps are selected by a class/key allowlist, not by per-model placement in the core.+“Whole component” means all non-CPU modules of that component.++## Memory and capacity++- The `part0` reserve is an inert load-time slab, not a process-wide allocator cap. It+ removes bytes from the pool while the model loads and is released at the first `part1`+ module. Size it to the part0 card.+- Split mode runs eager. Whole-forward and per-block graphs are disabled; per-segment+ capture is not implemented yet.+- On unified-memory devices, the device total reported by torch is not all usable. The+ iGPU shares host RAM with the OS, so leave several GiB for the OS, page cache and prefill+ workspace. The measured 118 GiB iGPU has about 113 GiB usable for weights plus cache; the+ 16 GiB 9070 has about 15.4 GiB usable. Use `util/memguard.py` when loading near the limit.## Model support-See `doc/split-support-matrix.md` (GLM measured; Qwen and DSV4 adapters staged; Flint/Mimo-best-effort inheritors of the generic `Model` path). Core placement is model-agnostic:-adapters declare components and policies, unknown non-layer modules default to `part1`.--## Known limitations (Stage 1.5)--- Auto-N uses actual text bytes/cache/endcaps but not components declared after the target- load; Stage 5 finishes cross-component, pre-load sizing. On the measured 16 GB gfx12- part0: N=6 at ≤65K, N=5 for long context until the gfx12 KDA kernel lands.-- MTP on the split is not yet deterministic (`--num-draft 0` remains the deterministic mode).-- No per-segment graphs (Stage 6); split runs eager and pays ~0.95× decode (GLM, MTP).-- Qwen3.8 and DSV4 adapters are Stage 3/4; their component inventories are code-level only.-- Same-arch and RDNA3/3.5 pairs are selection-tested only until such hardware is available.- A missing kernel fallback on a new arch is a model/kernel support issue, not a split defect.+| Model | Status | Notes |+| --- | --- | --- |+| GLM-5.3-Flash | measured | text, MTP and vision; on a 16 GiB `gfx12` `part0`, N=6 at ≤65K and N=5 for long context |+| Qwen3.8-Flash-Next | staged, not load-tested | QSA/GDN/PLE components; separate dflash drafter config; QSA `gfx12` caveat below |+| DeepSeek-V4.1-Flash | staged | uses the DSV4 engine, not `Model.load` |+| Flint, Mimo | best effort | generic `Model` path; no dedicated adapter |++Kernel support is per architecture. The split owns placement and transport, not kernel+ports; a missing kernel fallback on a new architecture is a model/kernel issue, not a split+defect.++## Verification++- Split **off** must remain byte-identical to the parent branch, including outputs and the+ serve environment block. It must not enumerate devices or mutate split settings.+- Split **on** is judged by run-to-run determinism with plain greedy decoding, KLD/task+ metrics and the needle probe. A mixed-architecture pair is not expected to be bitwise.+- `tools/strix_halo/split_eval.py` runs the battery: `--baseline`, `--part0-layers`,+ `--part1-device`/`--part0-device`, `--needle-depth`, `--bench-depth`, `--num-draft`,+ `--perf-tokens`/`--perf-reps` and `--compare a.json b.json`. Its context-dependent part0+ default is harness tuning, not a split property; override it with `--part0-layers` or the+ `--long-ctx-part0-layers`/`--short-ctx-part0-layers` flags.++## Known limitations++- MTP on the split is not deterministic. `--num-draft 0` remains the deterministic mode.+- Per-segment graphs are not implemented. Split runs eager and pays about 0.95x decode on+ GLM with MTP.+- Auto-N uses text bytes, cache and text endcaps, but does not yet subtract components+ declared after the target load (MTP/vision). Leave headroom or set N explicitly.+- Qwen QSA sparse attention has an illegal-access report in the `gfx12` top-k path on+ `gfx1201`; keep QSA cache pages off `part0` until that kernel is fixed.+- Same-architecture and RDNA3/3.5 pairs are selection-tested only until such hardware is+ available.diff --git a/exllamav3/architecture/qwen4_exp.py b/exllamav3/architecture/qwen4_exp.pyindex 0127efd..7925d45 100644--- a/exllamav3/architecture/qwen4_exp.py+++ b/exllamav3/architecture/qwen4_exp.py@@ -64,7 +64,9 @@ class Qwen4ExpConfig(Qwen3_5VLMoeBaseConfig):# Gated-residual hyper-connectionsself.hc_mult = self.read_cfg(int, pfx("hc_count"), 4)- # QSA indexer+ # QSA indexer.+ # Split caveat: the gfx12 QSA sparse top-k path has an illegal-access report on+ # gfx1201; keep QSA cache pages off part0 until that kernel is fixed.self.indexer_n_heads = self.read_cfg(int, pfx("indexer_n_heads"), no_default)self.indexer_kv_heads = self.read_cfg(int, pfx("indexer_kv_heads"), 1)self.indexer_head_dim = self.read_cfg(int, pfx("indexer_head_dim"), no_default)