Skip to content

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.

Layer split front/main renamed to part0/part1

Resynth4e8666677bde
diff --git a/doc/split-support-matrix.md b/doc/split-support-matrix.md
index aa510b4..458132a 100644
--- a/doc/split-support-matrix.md
+++ b/doc/split-support-matrix.md
@@ -3,16 +3,16 @@
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 front
+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: **front** (mapped to the front device), **main** (mapped to the main
-device), **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.
+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 the front and a
-118 GiB Strix Halo iGPU (gfx1151) as the main. Numbers below and in
+**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.
@@ -20,15 +20,15 @@ either architecture or role.
| Component | Config | Placement | Notes |
| --- | --- | --- | --- |
-| text (`Model.from_config`) | shared | layers 0..N-1 front, N..44 main; 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 front when `--endcaps on`, else main | `ComponentPolicy(whole_component)` (no own trunk), reserve owned by the text map |
-| vision (`component="vision"`) | shared | all front when `--endcaps on`, else main | declared as a whole component; the same bridge/config covers it |
+| 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 front per allowlist; unknown non-layer modules main | 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 main / 0.12 GiB front at 65K; placement audit after load |
+| 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 front 13.68/13.94 GiB, plain split
+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.
@@ -36,7 +36,7 @@ changes are CPU-tested; the GPU gate (N=4/6 load in both device positions, plain
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 front (adapter tuning, not a split rule).
+only on a gfx12 part0 (adapter tuning, not a split rule).
## Code inventory — Qwen3.8-Flash-Next (`tools/qwen/serve.py`)
@@ -44,11 +44,11 @@ only on a gfx12 front (adapter tuning, not a split rule).
| --- | --- | --- | --- |
| 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 front (endcaps on), else main | 3 |
-| vision | shared config, `component="vision"` | front when it fits | 3 |
-| ngram table (`NGramEmbedding`) | inside the text model | host/swap-resident (`ensure_resident`, 24.4 GiB) — never front | 3 |
-| PLE / DQ / GR / GDN HIP kernels | JIT loaders | gfx11.5-only gates; per-device arch needed; no implicit front placement | 3 |
-| QSA sparse attention (quant cache pages) | cache layers | gfx1201 `dsa_topk_gfx12` illegal access — keep off the front until fixed | 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
@@ -63,12 +63,12 @@ The DSV4 engine does **not** go through `Model.load()`: `dsv41/pack.py:load_pack
| 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)` | front with endcaps / main | 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 front/main policy | 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
diff --git a/doc/split.md b/doc/split.md
index be07916..16d8fa7 100644
--- a/doc/split.md
+++ b/doc/split.md
@@ -1,8 +1,8 @@
-# Contiguous layer split (front + main devices)
+# Contiguous layer split (part0 + part1 devices)
*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 front
+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.*
@@ -10,21 +10,27 @@ measurements.*
## What it is
One process places the first N transformer layers plus the small endcaps of a model on
-one GPU (the "front") and the rest on another (the "main"), with an asynchronous
-host-staged bridge on every crossing:
+one GPU (`part0`) and the rest on another (`part1`), with an asynchronous host-staged
+bridge on every crossing:
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' 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).
-Devices are not tied to a role. Either device may be the front or the main one, 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.
+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.
**Measured configuration.** The development box is an RX 9070 (gfx1201, 15.92 GiB) over
-USB4 as the front and a 118 GiB Strix Halo iGPU (gfx1151) as the main. All numbers in
+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.
@@ -32,50 +38,50 @@ otherwise; they are measurements, not assumptions of the interface.
| Flag (CLI) | Env fallback | Meaning |
| --- | --- | --- |
-| `--front-layers auto\|N` | `KYOJIN_FRONT_LAYERS` | first N transformer layers on the front device; 0 = off |
-| `--main-device auto\|cuda:N\|gfxXXXX\|uuid\|name` | `KYOJIN_MAIN_DEVICE` | main device selection (`auto` = `cuda:0`) |
-| `--front-device auto\|cuda:N\|gfxXXXX\|uuid\|name` | `KYOJIN_FRONT_DEVICE` | front 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 whole MTP/vision components to the front (default on) |
-| `--front-reserve-gb` | `KYOJIN_FRONT_RESERVE_GB` | VRAM held as a load-time slab on the front for workspace (default 1.2; a tuning value, size it to the card) |
+| `--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 whole MTP/vision components 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 |
`cuda:N` is the torch device index **after** `HIP_VISIBLE_DEVICES`, not the `rocm-smi`
-index. Explicit selectors win in either position: `front=cuda:1/main=cuda:0` and
-`front=cuda:0/main=cuda:1` are both valid. A front-only selector keeps working when it
-lands on `cuda:0`: with exactly two devices, `main=auto` takes the other device. Two
+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 role requires an
+a clear error. With more than two visible devices, `auto` for either part requires an
explicit selector and prints the inventory.
-`KYOJIN_FRONT_LAYERS=…` without CLI flags also works in `model_init.init` paths
-(examples/eval tools); `KYOJIN_MAIN_DEVICE` is honoured there too. The legacy
+`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 `front_eligible`, `endcaps_front`, the endcap allowlist,
+ `ComponentPolicy` declares `part0_eligible`, `endcaps_part0`, the endcap allowlist,
arch gate and unsafe env. `ComponentMap` resolves one component's contiguous boundary.
- `resolve_devices(front, main, devices=None)` selects by position; `DeviceInfo` lets the
+ `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
- main; auxiliary components never move front implicitly.
+ `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_FRONT_LAYERS` env-only path.
+- `model_init.py` uses the same plan for the `KYOJIN_PART0_LAYERS` env-only path.
## Load-time effects worth knowing
-- The front reserve is an **inert device slab**, not `set_per_process_memory_fraction`.
+- 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 main module (or after
+ 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 main device's numerics. The 1.2 GiB default is
- a tuning value for a small front card, not an architecture rule; Stage 5 derives it
+ 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.
@@ -84,10 +90,10 @@ new map must error.
- 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.
- Auto-N is a Stage 1 skeleton: it uses actual safetensors bytes for each layer, the
- cache/recurrent sizes for layers below N, the front endcap bytes and the reserve, with
+ 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
- front, where the deterministic split KDA chain adds a prefill workspace the byte budget
+ 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;
@@ -103,23 +109,23 @@ new map must error.
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`, `--front-layers`,
- `--main-device`/`--front-device`, `--needle-depth`, `--num-draft`,
- `--perf-tokens/--perf-reps`, `--compare a.json b.json`. Its context-dependent front-layer
- default is harness tuning exposed as `--long-ctx-front-layers`/`--short-ctx-front-layers`,
+- `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.
## 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 main.
+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
- front: N=6 at ≤65K, N=5 for long context until the gfx12 KDA kernel lands.
+ 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.
diff --git a/exllamav3/bridge.py b/exllamav3/bridge.py
index c8d019e..5adda71 100644
--- a/exllamav3/bridge.py
+++ b/exllamav3/bridge.py
@@ -2,9 +2,9 @@ from __future__ import annotations
"""Async host-staged bridge for the contiguous layer split.
-The front and main devices may be any two supported ROCm devices in either
-position. On the measured mixed configuration (RX 9070 front over USB4 + Strix
-Halo main) there is no working, fast peer path: a direct device-to-device copy on
+The part0 and part1 devices may be any two supported ROCm devices in either
+position. On the measured mixed configuration (RX 9070 as part0 over USB4 +
+Strix Halo as part1) there is no working, fast peer path: a direct device-to-device copy on
that link class is both slow (under 1 GB/s observed on the 9070 side) and
asymmetric. Every segment crossing therefore goes through pinned host memory:
@@ -54,9 +54,9 @@ class _Channel:
class Bridge:
- def __init__(self, main: torch.device, front: torch.device):
- self.main = torch.device(main)
- self.front = torch.device(front)
+ def __init__(self, *, part1: torch.device, part0: torch.device):
+ self.part1 = torch.device(part1)
+ self.part0 = torch.device(part0)
self.channels: dict[tuple[int, int], _Channel] = {}
self.stats = {"hops": 0, "bytes": 0, "chunk_hops": 0, "chunk_bytes": 0, "reallocs": 0}
@@ -64,10 +64,10 @@ class Bridge:
@property
def pair(self) -> tuple[torch.device, torch.device]:
- return self.main, self.front
+ return self.part1, self.part0
def describe(self) -> str:
- return (f"host-staged async bridge {self.main} <-> {self.front} "
+ return (f"host-staged async bridge {self.part1} <-> {self.part0} "
f"(pinned slots x{_ROUND})")
def summary(self) -> str:
@@ -177,7 +177,7 @@ def bridge_enabled() -> bool:
return os.environ.get("KYOJIN_BRIDGE", "1") != "0"
-def install_bridge(config, main: torch.device, front: torch.device | None) -> Bridge | None:
+def install_bridge(config, *, part1: torch.device, part0: torch.device | None) -> Bridge | None:
"""Attach the bridge to a config and mark the model as split.
The config is shared by the target, the drafter and the vision tower, so one call
@@ -185,18 +185,18 @@ def install_bridge(config, main: torch.device, front: torch.device | None) -> Br
forward or per-block graph must not span the bridge (Phase 6 owns per-segment
capture).
"""
- split_active = front is not None and torch.device(main) != torch.device(front)
+ split_active = part0 is not None and torch.device(part1) != torch.device(part0)
config.split_active = split_active
if not split_active:
return getattr(config, "device_bridge", None)
# Kernel-level fallbacks that must apply only in split mode (the gfx12 KDA
- # determinant fallback) read this; split off stays on the main code path.
+ # determinant fallback) read this; split off stays on the default code path.
os.environ["KYOJIN_SPLIT_ACTIVE"] = "1"
existing = getattr(config, "device_bridge", None)
if not bridge_enabled():
return existing
- if existing is not None and existing.pair == (torch.device(main), torch.device(front)):
+ if existing is not None and existing.pair == (torch.device(part1), torch.device(part0)):
return existing
- bridge = Bridge(main, front)
+ bridge = Bridge(part1 = part1, part0 = part0)
config.device_bridge = bridge
return bridge
diff --git a/exllamav3/device_map.py b/exllamav3/device_map.py
index 5282b64..d10c992 100644
--- a/exllamav3/device_map.py
+++ b/exllamav3/device_map.py
@@ -4,36 +4,38 @@ from __future__ import annotations
Contiguous layer split: resolve the two devices, declare per-component policies and
map model modules to them.
-Devices are selected by position, never by architecture. ``main`` defaults to
-``cuda:0``; ``front`` defaults to the only other visible device when exactly two
-devices are present. A front-only selector keeps working when it lands on
-``cuda:0``: main auto then takes the other device. Either position accepts
-``cuda:N``, ``gfxXXXX``, a device UUID or a device-name substring, and either
-device may serve either position. ``cuda:N`` is the torch index after
-``HIP_VISIBLE_DEVICES``, not the ``rocm-smi`` index. More than two visible devices
-require an explicit selector.
+``part0`` is the first part of the layer stack (the first ``part0_layers``
+transformer layers plus its endcaps); ``part1`` is the rest of the component.
+Devices are selected by position, never by architecture: ``part1`` defaults to
+``cuda:0`` and ``part0`` to the only other visible device when exactly two are
+present. A part0-only selector keeps working when it lands on ``cuda:0``: part1
+auto then takes the other device. Either position accepts ``cuda:N``,
+``gfxXXXX``, a device UUID or a device-name substring, and either device may
+serve either part. ``cuda:N`` is the torch index after ``HIP_VISIBLE_DEVICES``,
+not the ``rocm-smi`` index. More than two visible devices require an explicit
+selector.
The map itself is deliberately independent of the architecture: modules carrying a
-``layer_idx`` are transformer layers and are assigned to the front device for
-indices ``0 .. front_layers - 1`` and to the main device for the rest. Modules
-without a ``layer_idx`` are endcaps (embedding, hyper-connection drivers, final
-norm, lm_head, and the separate MTP/vision components).
+``layer_idx`` are transformer layers and are assigned to ``part0`` for indices
+``0 .. part0_layers - 1`` and to ``part1`` for the rest. Modules without a
+``layer_idx`` are endcaps (embedding, hyper-connection drivers, final norm,
+lm_head, and the separate MTP/vision components).
The universal core separates *policy* from *placement*:
-- ``ComponentPolicy`` says whether a component may use the front device and which
+- ``ComponentPolicy`` says whether a component may use ``part0`` and which
non-layer modules are safe to move there. The text prologue/epilogue allowlist
is norm/hc/lm_head-like modules only; anything the policy does not recognise is
- an unknown non-layer module and stays on the main device.
+ an unknown non-layer module and stays on ``part1``.
- ``ComponentMap`` resolves the contiguous boundary for one component.
- ``SplitPlan`` owns every component of a process (target, MTP, vision, extra),
- the front reserve, auto-N and the load/placement audit. Adapters declare their
+ the part0 reserve, auto-N and the load/placement audit. Adapters declare their
components; the core contains no model-specific placement logic.
-Endcaps ON puts the allowlisted text endcaps on the front device. ENDCAPS OFF
-lets the allowlisted prologue follow layer 0 and the epilogue follow the last
-layer. ``prefer_cpu`` modules, such as the GLM token embedding, always stay on
-the CPU: their upload path is part of the embedding design, not a tile to move.
+Endcaps ON puts the allowlisted text endcaps on ``part0``. ENDCAPS OFF lets the
+allowlisted prologue follow layer 0 and the epilogue follow the last layer.
+``prefer_cpu`` modules, such as the GLM token embedding, always stay on the CPU:
+their upload path is part of the embedding design, not a tile to move.
"""
import os
@@ -45,15 +47,15 @@ from .util.arch_list import device_arch
GIB = 1024 ** 3
-# Default load-time slab on the front device. A tuning value, not an architecture
-# assumption: size it to the front card. Stage 5 derives it from the device total.
-DEFAULT_FRONT_RESERVE_GB = 1.2
-DEFAULT_MAIN_DEVICE = "auto"
-DEFAULT_FRONT_DEVICE = "auto"
+# Default load-time slab on the part0 device. A tuning value, not an architecture
+# assumption: size it to the part0 card. Stage 5 derives it from the device total.
+DEFAULT_PART0_RESERVE_GB = 1.2
+DEFAULT_PART1_DEVICE = "auto"
+DEFAULT_PART0_DEVICE = "auto"
-# Text prologue/epilogue modules that are safe to place on the front device. The
-# list is by class name and key suffix, not by model: an adapter can extend it in
-# its ComponentPolicy. Modules outside this list default to the main device.
+# Text prologue/epilogue modules that are safe to place on part0. The list is by
+# class name and key suffix, not by model: an adapter can extend it in its
+# ComponentPolicy. Modules outside this list default to part1.
TEXT_ENDCAP_TYPES = frozenset((
"RMSNorm", "GatedRMSNorm", "LayerNorm", "HyperHead", "ExpandStreams",
))
@@ -103,10 +105,10 @@ class DeviceInfo:
@dataclass(frozen = True)
class Devices:
- main: torch.device
- front: torch.device | None
- main_arch: str
- front_arch: str | None
+ part1: torch.device
+ part0: torch.device | None
+ part1_arch: str
+ part0_arch: str | None
inventory: tuple[DeviceInfo, ...] = ()
@@ -170,18 +172,18 @@ def _select_device(req: str, role: str, infos: list[DeviceInfo], env_name: str)
def resolve_devices(
- front: str | None = None,
- main: str | None = None,
+ part0: str | None = None,
+ part1: str | None = None,
devices: list[DeviceInfo] | None = None,
) -> Devices:
- """Resolve the front/main pair by position, never by architecture.
+ """Resolve the part0/part1 pair by position, never by architecture.
- ``main`` (or KYOJIN_MAIN_DEVICE) defaults to ``auto`` = ``cuda:0``. ``front``
- (or KYOJIN_FRONT_DEVICE) defaults to the only other visible device when exactly
+ ``part1`` (or KYOJIN_PART1_DEVICE) defaults to ``auto`` = ``cuda:0``. ``part0``
+ (or KYOJIN_PART0_DEVICE) defaults to the only other visible device when exactly
two are visible; with one device the split cannot run, and with more than two an
- explicit selector is required. If the front is explicit and occupies ``cuda:0``
- while main is ``auto`` with exactly two devices visible, main takes the other
- device so a front-only selector keeps working. Both selectors accept
+ explicit selector is required. If part0 is explicit and occupies ``cuda:0``
+ while part1 is ``auto`` with exactly two devices visible, part1 takes the other
+ device so a part0-only selector keeps working. Both selectors accept
``cuda:N``, ``gfxXXXX``, a device UUID or a device-name substring; either
position may be either device.
@@ -192,48 +194,48 @@ def resolve_devices(
if len(infos) < 2:
raise RuntimeError(
f"layer split needs two devices; visible: {_format_inventory(infos)}. "
- "Unset KYOJIN_FRONT_LAYERS / --front-layers to run on one device.")
+ "Unset KYOJIN_PART0_LAYERS / --part0-layers to run on one device.")
- main_req = main if main is not None else os.environ.get("KYOJIN_MAIN_DEVICE", DEFAULT_MAIN_DEVICE)
- front_req = front if front is not None else os.environ.get("KYOJIN_FRONT_DEVICE", DEFAULT_FRONT_DEVICE)
- main_req = (main_req or DEFAULT_MAIN_DEVICE).strip().lower()
- front_req = (front_req or DEFAULT_FRONT_DEVICE).strip().lower()
- main_auto = main_req in ("", "auto")
+ part1_req = part1 if part1 is not None else os.environ.get("KYOJIN_PART1_DEVICE", DEFAULT_PART1_DEVICE)
+ part0_req = part0 if part0 is not None else os.environ.get("KYOJIN_PART0_DEVICE", DEFAULT_PART0_DEVICE)
+ part1_req = (part1_req or DEFAULT_PART1_DEVICE).strip().lower()
+ part0_req = (part0_req or DEFAULT_PART0_DEVICE).strip().lower()
+ part1_auto = part1_req in ("", "auto")
- if main_auto:
- main_i = min(d.index for d in infos)
+ if part1_auto:
+ part1_i = min(d.index for d in infos)
else:
- main_i = _select_device(main_req, "main", infos, "KYOJIN_MAIN_DEVICE")
+ part1_i = _select_device(part1_req, "part1", infos, "KYOJIN_PART1_DEVICE")
- if front_req in ("", "auto"):
+ if part0_req in ("", "auto"):
if len(infos) != 2:
raise RuntimeError(
- f"front device is 'auto' but {len(infos)} devices are visible; set "
- f"KYOJIN_FRONT_DEVICE (or --front-device) to one of: {_format_inventory(infos)}")
- front_i = next(d.index for d in infos if d.index != main_i)
+ f"part0 device is 'auto' but {len(infos)} devices are visible; set "
+ f"KYOJIN_PART0_DEVICE (or --part0-device) to one of: {_format_inventory(infos)}")
+ part0_i = next(d.index for d in infos if d.index != part1_i)
else:
- front_i = _select_device(front_req, "front", infos, "KYOJIN_FRONT_DEVICE")
- if main_auto and front_i == main_i:
- # An explicit front selector must keep working when it lands on cuda:0:
- # main auto takes the only other device. With more devices the choice
- # is ambiguous, so ask for the main selector instead of guessing.
+ part0_i = _select_device(part0_req, "part0", infos, "KYOJIN_PART0_DEVICE")
+ if part1_auto and part0_i == part1_i:
+ # An explicit part0 selector must keep working when it lands on cuda:0:
+ # part1 auto takes the only other device. With more devices the choice
+ # is ambiguous, so ask for the part1 selector instead of guessing.
if len(infos) == 2:
- main_i = next(d.index for d in infos if d.index != front_i)
+ part1_i = next(d.index for d in infos if d.index != part0_i)
else:
raise RuntimeError(
- f"main device is 'auto' (cuda:{main_i}) and equals the explicit front; "
- f"with {len(infos)} devices visible set KYOJIN_MAIN_DEVICE (or --main-device)")
+ f"part1 device is 'auto' (cuda:{part1_i}) and equals the explicit part0; "
+ f"with {len(infos)} devices visible set KYOJIN_PART1_DEVICE (or --part1-device)")
- if front_i == main_i:
- raise RuntimeError(f"layer split main and front resolve to the same device "
- f"(cuda:{main_i}); choose a different --front-device/--main-device")
+ if part0_i == part1_i:
+ raise RuntimeError(f"layer split part0 and part1 resolve to the same device "
+ f"(cuda:{part1_i}); choose a different --part0-device/--part1-device")
by_index = {d.index: d for d in infos}
- main_info, front_info = by_index[main_i], by_index[front_i]
+ part1_info, part0_info = by_index[part1_i], by_index[part0_i]
return Devices(
- main = torch.device("cuda", main_i),
- front = torch.device("cuda", front_i),
- main_arch = main_info.arch or "",
- front_arch = front_info.arch or "",
+ part1 = torch.device("cuda", part1_i),
+ part0 = torch.device("cuda", part0_i),
+ part1_arch = part1_info.arch or "",
+ part0_arch = part0_info.arch or "",
inventory = tuple(infos),
)
@@ -248,22 +250,22 @@ class ComponentPolicy:
``kind`` is one of ``text``, ``mtp``, ``vision``, ``draft``, ``aux`` or
``unknown``. Whole-component kinds (MTP/vision/draft) put every module on
- the front when endcaps are on, because they have no trunk boundary of their
- own. Auxiliary components never visit the front implicitly.
+ part0 when endcaps are on, because they have no trunk boundary of their own.
+ Auxiliary components never visit part0 implicitly.
"""
name: str
kind: str = "aux"
- front_eligible: bool = False
- endcaps_front: bool = True
+ part0_eligible: bool = False
+ endcaps_part0: bool = True
whole_component: bool = False
endcap_types: frozenset[str] = frozenset()
endcap_key_suffixes: tuple[str, ...] = ()
arch_gate: frozenset[str] | None = None
unsafe_env: tuple[tuple[str, str], ...] = ()
- def allows_front(self, arch: str | None) -> bool:
- if not self.front_eligible or arch is None:
+ def allows_part0(self, arch: str | None) -> bool:
+ if not self.part0_eligible or arch is None:
return False
return self.arch_gate is None or arch in self.arch_gate
@@ -273,15 +275,15 @@ def component_policy(name: str, **overrides) -> ComponentPolicy:
key = (name or "unknown").strip().lower()
if key == "text":
defaults = dict(
- name = name, kind = "text", front_eligible = True, endcaps_front = True,
+ name = name, kind = "text", part0_eligible = True, endcaps_part0 = True,
endcap_types = TEXT_ENDCAP_TYPES, endcap_key_suffixes = TEXT_ENDCAP_SUFFIXES)
elif key in WHOLE_COMPONENT_KINDS:
defaults = dict(
- name = name, kind = key, front_eligible = True, endcaps_front = True,
+ name = name, kind = key, part0_eligible = True, endcaps_part0 = True,
whole_component = True)
else:
- defaults = dict(name = name, kind = "aux", front_eligible = False,
- endcaps_front = False)
+ defaults = dict(name = name, kind = "aux", part0_eligible = False,
+ endcaps_part0 = False)
defaults.update(overrides)
return ComponentPolicy(**defaults)
@@ -297,8 +299,8 @@ def _key_matches(key: str, suffixes) -> bool:
return False
-def is_front_endcap(module, policy: ComponentPolicy) -> bool:
- """True for a non-layer module the text policy allows on the front device."""
+def is_part0_endcap(module, policy: ComponentPolicy) -> bool:
+ """True for a non-layer module the text policy allows on part0."""
if getattr(module, "caps", {}).get("prefer_cpu"):
return False
if getattr(module, "caps", {}).get("logits_output"):
@@ -403,22 +405,22 @@ class ComponentMap:
``reserve_bytes`` is a per-device *slab* held for the duration of the load,
not a process-wide allocator cap: a cap changes the ROCm allocator's layout
- and perturbs the main device's kernel choices (measured at 128K), while a
+ and perturbs the part1 device's kernel choices (measured at 128K), while a
slab only removes bytes from the pool and releases them without changing the
allocator's policy.
"""
- main: torch.device
- front: torch.device | None
- front_layers: int
+ part1: torch.device
+ part0: torch.device | None
+ part0_layers: int
endcaps: bool
component: str = "text"
layer_count: int = 0
policy: ComponentPolicy | None = None
- main_arch: str = ""
- front_arch: str | None = None
+ part1_arch: str = ""
+ part0_arch: str | None = None
reserve_bytes: dict[int, int] = field(default_factory = dict)
- front_endcap_keys: tuple[str, ...] = ()
+ part0_endcap_keys: tuple[str, ...] = ()
unknown_keys: tuple[str, ...] = ()
size_bytes: int = 0
load_order: int = 0
@@ -436,33 +438,33 @@ class ComponentMap:
def from_model(
cls,
model,
- front_layers: int,
+ part0_layers: int,
endcaps: bool,
devices: Devices,
component: str = "text",
- front_reserve_gb: float = DEFAULT_FRONT_RESERVE_GB,
- main_reserve_gb: float = 0.0,
+ part0_reserve_gb: float = DEFAULT_PART0_RESERVE_GB,
+ part1_reserve_gb: float = 0.0,
config = None,
cache = None,
policy: ComponentPolicy | None = None,
load_order: int = 0,
) -> "ComponentMap":
policy = policy or component_policy(component)
- return cls.from_policy(model, front_layers, endcaps, devices, policy,
- front_reserve_gb = front_reserve_gb,
- main_reserve_gb = main_reserve_gb,
+ return cls.from_policy(model, part0_layers, endcaps, devices, policy,
+ part0_reserve_gb = part0_reserve_gb,
+ part1_reserve_gb = part1_reserve_gb,
config = config, cache = cache, load_order = load_order)
@classmethod
def from_policy(
cls,
model,
- front_layers: int | str,
+ part0_layers: int | str,
endcaps: bool,
devices: Devices,
policy: ComponentPolicy,
- front_reserve_gb: float = DEFAULT_FRONT_RESERVE_GB,
- main_reserve_gb: float = 0.0,
+ part0_reserve_gb: float = DEFAULT_PART0_RESERVE_GB,
+ part1_reserve_gb: float = 0.0,
config = None,
cache = None,
load_order: int = 0,
@@ -470,58 +472,58 @@ class ComponentMap:
modules = list(model.modules)
layers = [m for m in modules if getattr(m, "layer_idx", None) is not None]
n_layers = len(layers)
- auto = front_layers in ("auto", -1) or (isinstance(front_layers, str) and front_layers.strip().lower() == "auto")
- front_layers = 0 if auto else int(front_layers)
- endcaps = bool(endcaps and policy.endcaps_front)
+ auto = part0_layers in ("auto", -1) or (isinstance(part0_layers, str) and part0_layers.strip().lower() == "auto")
+ part0_layers = 0 if auto else int(part0_layers)
+ endcaps = bool(endcaps and policy.endcaps_part0)
if policy.whole_component:
# These components are endcaps in their entirety: they have no trunk
- # boundary of their own, so ENDCAPS OFF leaves them on the main device.
- front_layers = n_layers if endcaps else 0
- front_layers = max(0, min(int(front_layers), n_layers))
- if devices.front is None or not policy.allows_front(devices.front_arch):
- front_layers = 0
+ # boundary of their own, so ENDCAPS OFF leaves them on part1.
+ part0_layers = n_layers if endcaps else 0
+ part0_layers = max(0, min(int(part0_layers), n_layers))
+ if devices.part0 is None or not policy.allows_part0(devices.part0_arch):
+ part0_layers = 0
positions = {id(m): i for i, m in enumerate(modules)}
first = positions[id(layers[0])] if layers else 0
last = positions[id(layers[-1])] if layers else -1
stc = getattr(config, "stc", None) if config is not None else None
- # The front reserve caps the small card while its weights load. It is released
- # before the first main module (see Model._load_mapped): the main device has ample
- # headroom and is never capped. A component other than the budget owner clears
- # reserve_bytes after construction (SplitPlan does this).
+ # The part0 reserve caps the small card while its weights load. It is released
+ # before the first part1 module (see Model._load_mapped): the part1 device has
+ # ample headroom and is never capped. A component other than the budget owner
+ # clears reserve_bytes after construction (SplitPlan does this).
reserve: dict[int, int] = {}
- if devices.front is not None and front_layers > 0 and front_reserve_gb > 0:
- reserve[devices.front.index] = max(0, int(front_reserve_gb * GIB))
- if devices.main is not None and main_reserve_gb > 0:
- reserve[devices.main.index] = max(0, int(main_reserve_gb * GIB))
+ if devices.part0 is not None and part0_layers > 0 and part0_reserve_gb > 0:
+ reserve[devices.part0.index] = max(0, int(part0_reserve_gb * GIB))
+ if devices.part1 is not None and part1_reserve_gb > 0:
+ reserve[devices.part1.index] = max(0, int(part1_reserve_gb * GIB))
layer_bytes = _layer_bytes(model, stc)
cache_by_layer = _cache_bytes_by_layer(cache)
- front_endcaps = tuple(
+ part0_endcaps = tuple(
m.key for m in modules
- if getattr(m, "layer_idx", None) is None and is_front_endcap(m, policy)
+ if getattr(m, "layer_idx", None) is None and is_part0_endcap(m, policy)
)
unknown = tuple(
m.key for m in modules
if getattr(m, "layer_idx", None) is None
and not getattr(m, "caps", {}).get("prefer_cpu")
- and not is_front_endcap(m, policy)
+ and not is_part0_endcap(m, policy)
)
size = (sum(layer_bytes.values()) +
sum(_module_bytes(m, stc) for m in modules if getattr(m, "layer_idx", None) is None))
return cls(
- main = devices.main,
- front = devices.front,
- front_layers = front_layers,
- endcaps = bool(endcaps) and front_layers > 0,
+ part1 = devices.part1,
+ part0 = devices.part0,
+ part0_layers = part0_layers,
+ endcaps = bool(endcaps) and part0_layers > 0,
component = policy.name,
layer_count = n_layers,
policy = policy,
- main_arch = devices.main_arch,
- front_arch = devices.front_arch,
+ part1_arch = devices.part1_arch,
+ part0_arch = devices.part0_arch,
reserve_bytes = reserve,
- front_endcap_keys = front_endcaps,
+ part0_endcap_keys = part0_endcaps,
unknown_keys = unknown,
size_bytes = int(size),
load_order = load_order,
@@ -539,13 +541,13 @@ class ComponentMap:
@property
def enabled(self) -> bool:
- return self.front is not None and self.front_layers > 0
+ return self.part0 is not None and self.part0_layers > 0
@property
def used_devices(self) -> list[torch.device]:
- out = [self.main]
- if self.enabled and self.front is not None:
- out.append(self.front)
+ out = [self.part1]
+ if self.enabled and self.part0 is not None:
+ out.append(self.part0)
return out
@property
@@ -553,7 +555,7 @@ class ComponentMap:
return self.policy or component_policy(self.component)
def _endcap_allowed(self, module) -> bool:
- return is_front_endcap(module, self.policy_or_default)
+ return is_part0_endcap(module, self.policy_or_default)
def device_for(self, module) -> torch.device:
if getattr(module, "caps", {}).get("prefer_cpu"):
@@ -561,35 +563,35 @@ class ComponentMap:
idx = getattr(module, "layer_idx", None)
if idx is not None:
if not self.enabled:
- return self.main
+ return self.part1
if self.policy_or_default.whole_component:
- return self.front
- return self.front if idx < self.front_layers else self.main
+ return self.part0
+ return self.part0 if idx < self.part0_layers else self.part1
if not self.enabled:
- return self.main
+ return self.part1
if self.policy_or_default.whole_component:
# MTP/vision/draft have no trunk boundary: all their modules share the
# component's endcaps verdict.
- return self.front if self.endcaps else self.main
+ return self.part0 if self.endcaps else self.part1
if not self._endcap_allowed(module):
# Unknown / auxiliary non-layer module: always safe, never moved implicitly.
- return self.main
- if not self.policy_or_default.endcaps_front:
- return self.main
+ return self.part1
+ if not self.policy_or_default.endcaps_part0:
+ return self.part1
if self.endcaps:
- return self.front
+ return self.part0
# ENDCAPS OFF: allowlisted prologue follows layer 0, epilogue follows the last layer.
pos = self._positions.get(id(module), 0)
if pos < self._first_layer_pos:
- return self.front
+ return self.part0
if pos > self._last_layer_pos:
- return self.front if self.front_layers >= self.layer_count else self.main
- return self.main
+ return self.part0 if self.part0_layers >= self.layer_count else self.part1
+ return self.part1
# -- load-time budget --------------------------------------------------
def engage_budget(self) -> None:
- """Hold the front reserve as a slab (never a process-wide allocator cap)."""
+ """Hold the part0 reserve as a slab (never a process-wide allocator cap)."""
if getattr(self, "_budget_engaged", False):
return
for i, reserve in self.reserve_bytes.items():
@@ -606,18 +608,18 @@ class ComponentMap:
flush = True)
self._budget_engaged = True
- def release_front_budget(self) -> None:
- """Release the front slab before the first main module loads.
+ def release_part0_budget(self) -> None:
+ """Release the part0 slab before the first part1 module loads.
The slab is dropped; the caching allocator keeps the freed block for the
forward workspace, so the headroom is preserved without a cap.
"""
if not getattr(self, "_budget_engaged", False):
return
- if self.front is None:
+ if self.part0 is None:
return
- self._reserve_slabs.pop(self.front.index, None)
- self._budget_engaged = any(i != self.front.index and r > 0 for i, r in self.reserve_bytes.items())
+ self._reserve_slabs.pop(self.part0.index, None)
+ self._budget_engaged = any(i != self.part0.index and r > 0 for i, r in self.reserve_bytes.items())
def release_budget(self) -> None:
self._reserve_slabs.clear()
@@ -631,11 +633,11 @@ class ComponentMap:
def layer_cache_bytes(self, idx: int) -> int:
return int(self._cache_by_layer.get(idx, 0))
- def front_cost(self, n: int, endcaps: bool | None = None) -> int:
- """Estimated front bytes for n text layers plus the policy's front endcaps."""
+ def part0_cost(self, n: int, endcaps: bool | None = None) -> int:
+ """Estimated part0 bytes for n text layers plus the policy's part0 endcaps."""
n = max(0, min(n, self.layer_count))
endcaps = self.endcaps if endcaps is None else bool(endcaps)
- endcaps = endcaps and self.policy_or_default.endcaps_front
+ endcaps = endcaps and self.policy_or_default.endcaps_part0
cost = sum(self.layer_weight_bytes(i) for i in range(n))
cost += sum(self.layer_cache_bytes(i) for i in range(n))
if not endcaps:
@@ -645,14 +647,14 @@ class ComponentMap:
return cost + sum(_module_bytes(m, stc)
for m in self._module_refs if getattr(m, "layer_idx", None) is None
and not getattr(m, "caps", {}).get("prefer_cpu"))
- allowed = set(self.front_endcap_keys)
+ allowed = set(self.part0_endcap_keys)
return cost + sum(_module_bytes(m, stc) for m in self._module_refs if m.key in allowed)
def describe(self) -> str:
- parts = [f"{self.component}: layers 0..{self.front_layers - 1} front, "
- f"{self.front_layers}..{self.layer_count - 1} main"]
+ parts = [f"{self.component}: layers 0..{self.part0_layers - 1} part0, "
+ f"{self.part0_layers}..{self.layer_count - 1} part1"]
if self.endcaps:
- parts.append(f"endcaps front ({len(self.front_endcap_keys)} modules)")
+ parts.append(f"endcaps part0 ({len(self.part0_endcap_keys)} modules)")
else:
parts.append("endcaps follow neighbours")
return "; ".join(parts)
@@ -670,7 +672,7 @@ LayerDeviceMap = ComponentMap
class ComponentLoad:
component: str
seconds: float
- front_layers: int
+ part0_layers: int
layer_count: int
device_map: ComponentMap | None
weight_bytes: int = 0
@@ -685,20 +687,20 @@ class SplitPlan:
self,
devices: Devices,
endcaps: bool = True,
- front_layers: int | str = 0,
- front_reserve_gb: float = DEFAULT_FRONT_RESERVE_GB,
- main_reserve_gb: float = 0.0,
+ part0_layers: int | str = 0,
+ part0_reserve_gb: float = DEFAULT_PART0_RESERVE_GB,
+ part1_reserve_gb: float = 0.0,
preset: str = "auto",
auto_cap: int | None = None,
logger = print,
):
self.devices = devices
self.endcaps = bool(endcaps)
- self.requested_front_layers = front_layers
- self.auto = isinstance(front_layers, str) and front_layers.strip().lower() == "auto" or front_layers == -1
- self.front_layers = 0 if self.auto else max(0, int(front_layers or 0))
- self.front_reserve_gb = float(front_reserve_gb)
- self.main_reserve_gb = float(main_reserve_gb)
+ self.requested_part0_layers = part0_layers
+ self.auto = isinstance(part0_layers, str) and part0_layers.strip().lower() == "auto" or part0_layers == -1
+ self.part0_layers = 0 if self.auto else max(0, int(part0_layers or 0))
+ self.part0_reserve_gb = float(part0_reserve_gb)
+ self.part1_reserve_gb = float(part1_reserve_gb)
self.preset = (preset or "auto").strip().lower()
self.auto_cap = None if auto_cap is None else max(0, int(auto_cap))
self.logger = logger
@@ -720,19 +722,19 @@ class SplitPlan:
config = None,
cache = None,
policy: ComponentPolicy | None = None,
- front_layers: int | str | None = None,
+ part0_layers: int | str | None = None,
load_order: int | None = None,
) -> ComponentMap:
was_built = self._built
policy = policy or component_policy(component)
- layer = self.requested_front_layers if front_layers is None else front_layers
+ layer = self.requested_part0_layers if part0_layers is None else part0_layers
self._decls[component] = (model, config, cache, policy, layer, load_order)
if config is not None:
self.register_config(config)
cmap = ComponentMap.from_policy(
model, layer, self.endcaps, self.devices, policy,
- front_reserve_gb = self.front_reserve_gb,
- main_reserve_gb = self.main_reserve_gb,
+ part0_reserve_gb = self.part0_reserve_gb,
+ part1_reserve_gb = self.part1_reserve_gb,
config = config, cache = cache,
load_order = load_order if load_order is not None else len(self._decls),
)
@@ -762,17 +764,17 @@ class SplitPlan:
n = self._auto_n(text)
if self.auto_cap is not None:
n = min(n, self.auto_cap)
- self.front_layers = n
- self.logger(f"[split] auto-N: {n} front layer(s) "
+ self.part0_layers = n
+ self.logger(f"[split] auto-N: {n} part0 layer(s) "
f"(budget {self._auto_budget() / GIB:.2f} GiB, "
- f"reserve {self.front_reserve_gb:.2f} GiB tuning slab)")
+ f"reserve {self.part0_reserve_gb:.2f} GiB tuning slab)")
for name, (model, config, cache, policy, layer, load_order) in self._decls.items():
if self.auto and policy.kind == "text":
- layer = self.front_layers
+ layer = self.part0_layers
self.maps[name] = ComponentMap.from_policy(
model, layer, self.endcaps, self.devices, policy,
- front_reserve_gb = self.front_reserve_gb,
- main_reserve_gb = self.main_reserve_gb,
+ part0_reserve_gb = self.part0_reserve_gb,
+ part1_reserve_gb = self.part1_reserve_gb,
config = config, cache = cache,
load_order = load_order if load_order is not None else 0,
)
@@ -811,13 +813,13 @@ class SplitPlan:
cmap.reserve_bytes.clear()
def _auto_budget(self) -> int:
- if self.devices.front is None:
+ if self.devices.part0 is None:
return 0
- total = int(torch.cuda.get_device_properties(self.devices.front).total_memory)
+ total = int(torch.cuda.get_device_properties(self.devices.part0).total_memory)
# Allocator slack, not an architecture rule; Stage 5 replaces it with measured
# load/forward headroom.
safety = int(float(os.environ.get("KYOJIN_AUTON_SAFETY_GB", "0.25")) * GIB)
- return max(0, total - int(self.front_reserve_gb * GIB) - safety)
+ return max(0, total - int(self.part0_reserve_gb * GIB) - safety)
def _auto_n(self, text: str | None) -> int:
if text is None or text not in self.maps:
@@ -833,10 +835,10 @@ class SplitPlan:
if name != text and m.enabled and m.policy_or_default.whole_component and self.endcaps)
for n in range(cmap.layer_count, -1, -1):
if self.endcaps:
- cost = other + cmap.front_cost(n, self.endcaps)
+ cost = other + cmap.part0_cost(n, self.endcaps)
else:
- # Prologue follows layer 0; epilogue only when every layer is front.
- cost = other + cmap.front_cost(n, self.endcaps)
+ # Prologue follows layer 0; epilogue only when every layer is part0.
+ cost = other + cmap.part0_cost(n, self.endcaps)
if n > 0:
cost += self._prologue_bytes(cmap)
if n >= cmap.layer_count:
@@ -849,7 +851,7 @@ class SplitPlan:
stc = getattr(cmap.config, "stc", None)
out = 0
for m in cmap._module_refs:
- if getattr(m, "layer_idx", None) is not None or not is_front_endcap(m, cmap.policy_or_default):
+ if getattr(m, "layer_idx", None) is not None or not is_part0_endcap(m, cmap.policy_or_default):
continue
if cmap._positions.get(id(m), 0) < cmap._first_layer_pos:
out += _module_bytes(m, stc)
@@ -859,7 +861,7 @@ class SplitPlan:
stc = getattr(cmap.config, "stc", None)
out = 0
for m in cmap._module_refs:
- if getattr(m, "layer_idx", None) is not None or not is_front_endcap(m, cmap.policy_or_default):
+ if getattr(m, "layer_idx", None) is not None or not is_part0_endcap(m, cmap.policy_or_default):
continue
if cmap._positions.get(id(m), 0) > cmap._last_layer_pos:
out += _module_bytes(m, stc)
@@ -876,7 +878,7 @@ class SplitPlan:
def engage_budget(self) -> None:
# One reserve for the whole load sequence (target + drafter + vision). After
- # the owner releases the slab at its first main module, a later component must
+ # the owner releases the slab at its first part1 module, a later component must
# not allocate a second one.
if self._budget_engaged_once:
return
@@ -890,7 +892,7 @@ class SplitPlan:
return
from .bridge import install_bridge
for config in self.configs:
- install_bridge(config, self.devices.main, self.devices.front)
+ install_bridge(config, part1 = self.devices.part1, part0 = self.devices.part0)
def record_load(self, component: str, seconds: float, warnings = ()) -> None:
cmap = self.maps.get(component)
@@ -899,7 +901,7 @@ class SplitPlan:
cache_bytes = _cache_bytes_for(cmap.cache, cmap.layer_count)
self.records.append(ComponentLoad(
component = component, seconds = float(seconds),
- front_layers = cmap.front_layers, layer_count = cmap.layer_count,
+ part0_layers = cmap.part0_layers, layer_count = cmap.layer_count,
device_map = cmap, weight_bytes = int(cmap.size_bytes),
cache_bytes = cache_bytes, warnings = tuple(warnings)))
@@ -932,10 +934,10 @@ class SplitPlan:
@staticmethod
def _expected_layer_device(cmap: ComponentMap, idx: int):
if not cmap.enabled:
- return cmap.main
+ return cmap.part1
if cmap.policy_or_default.whole_component:
- return cmap.front if cmap.endcaps else cmap.main
- return cmap.front if idx < cmap.front_layers else cmap.main
+ return cmap.part0 if cmap.endcaps else cmap.part1
+ return cmap.part0 if idx < cmap.part0_layers else cmap.part1
def report(self, model, cache, extra: list[tuple[str, object, object]] | None = None,
ctx: int | None = None) -> None:
@@ -947,7 +949,7 @@ class SplitPlan:
self.print_component_table()
for name, cmap in self.maps.items():
if cmap.unknown_keys and cmap.policy_or_default.kind == "text":
- self.logger(f"[split] {name}: unknown non-layer modules kept on the main device: "
+ self.logger(f"[split] {name}: unknown non-layer modules kept on the part1 device: "
f"{', '.join(cmap.unknown_keys)}")
issues = self.audit_caches()
for name, bad in issues.items():
@@ -970,10 +972,10 @@ class SplitPlan:
d = r.device_map
if d is None:
continue
- front = f"0..{r.front_layers - 1}" if r.front_layers else "-"
- main = f"{r.front_layers}..{r.layer_count - 1}" if r.layer_count else "-"
- self.logger(f"[split] {r.component:7s} {r.seconds:7.1f}s front {front:>10s} "
- f"main {main:>10s} weights {r.weight_bytes / GIB:7.2f} GiB "
+ part0 = f"0..{r.part0_layers - 1}" if r.part0_layers else "-"
+ part1 = f"{r.part0_layers}..{r.layer_count - 1}" if r.layer_count else "-"
+ self.logger(f"[split] {r.component:7s} {r.seconds:7.1f}s part0 {part0:>10s} "
+ f"part1 {part1:>10s} weights {r.weight_bytes / GIB:7.2f} GiB "
f"cache {r.cache_bytes / GIB:6.2f} GiB devices "
f"{', '.join(str(x) for x in d.used_devices)}")
for w in r.warnings:
@@ -1045,14 +1047,14 @@ def print_split_table(
weights = allocated - cache_bytes
print(f"[split] {str(dev):9s} weights {_gib(weights)} cache {_gib(cache_bytes)} "
f"allocated {_gib(allocated)} peak {_gib(peak)}", flush = True)
- if device_map.front is not None:
+ if device_map.part0 is not None:
try:
- p = torch.cuda.get_device_properties(device_map.front)
+ p = torch.cuda.get_device_properties(device_map.part0)
total = p.total_memory
except Exception: # noqa: BLE001
total = 0
- reserve = device_map.reserve_bytes.get(device_map.front.index, 0)
- print(f"[split] front {str(device_map.front)} {device_map.front_arch}: "
+ reserve = device_map.reserve_bytes.get(device_map.part0.index, 0)
+ print(f"[split] part0 {str(device_map.part0)} {device_map.part0_arch}: "
f"{total / GIB:.2f} GiB total, reserve {reserve / GIB:.2f} GiB, "
f"budget {(total - reserve) / GIB:.2f} GiB", flush = True)
cpu = [m.key for m in model.modules if getattr(m, "caps", {}).get("prefer_cpu")]
diff --git a/exllamav3/model/model_ls.py b/exllamav3/model/model_ls.py
index 00286e1..d3b222c 100644
--- a/exllamav3/model/model_ls.py
+++ b/exllamav3/model/model_ls.py
@@ -79,22 +79,22 @@ class Model_LSMixin(ABC):
):
"""Load every top-level module straight to the device the map assigns it.
- No autosplit measuring forwards: the boundary is explicit. The front reserve is a
- held device slab while its segment loads, then is dropped at the first main module
+ No autosplit measuring forwards: the boundary is explicit. The part0 reserve is a
+ held device slab while its segment loads, then is dropped at the first part1 module
(the freed block stays available to the workspace without changing the allocator's
- policy or the main segment's numerics). The caller releases whatever remains after
+ policy or the part1 segment's numerics). The caller releases whatever remains after
the last component.
"""
device_map.engage_budget()
pin_all = config.infer_params.vision_pinned and getattr(self, "component", "text") == "vision"
- front_released = not device_map.enabled
+ part0_released = not device_map.enabled
with ProgressBar(f"Loading (split)" if progressbar else None, len(modules)) as progress:
for idx, module in enumerate(modules):
if callback: callback(idx, len(modules))
dev = device_map.device_for(module)
- if not front_released and dev == device_map.main:
- device_map.release_front_budget()
- front_released = True
+ if not part0_released and dev == device_map.part1:
+ device_map.release_part0_budget()
+ part0_released = True
defer = module.can_defer_load()
if defer:
# Pinned modules leave the arena alone (see _load_single)
@@ -117,7 +117,7 @@ class Model_LSMixin(ABC):
# shares it.
if device_map.enabled:
from ..bridge import install_bridge
- bridge = install_bridge(config, device_map.main, device_map.front)
+ bridge = install_bridge(config, part1 = device_map.part1, part0 = device_map.part0)
if bridge is not None and verbose:
print(f" -- split: {bridge.describe()}")
diff --git a/exllamav3/model_init.py b/exllamav3/model_init.py
index bf1441a..01471e6 100755
--- a/exllamav3/model_init.py
+++ b/exllamav3/model_init.py
@@ -337,24 +337,24 @@ def init(
# Explicit contiguous layer split. GLM serve has its own CLI; this env-only path
# keeps examples/chat.py and the eval tools able to exercise the split.
- from .serve_split import parse_front_layers
- front_layers = parse_front_layers(os.environ.get("KYOJIN_FRONT_LAYERS", "0"))
+ from .serve_split import parse_part0_layers
+ part0_layers = parse_part0_layers(os.environ.get("KYOJIN_PART0_LAYERS", "0"))
split_plan = None
draft_component = None
- front_map = draft_map = None
- if front_layers:
+ text_map = draft_map = None
+ if part0_layers:
if args.tensor_parallel or single_device or split is not None:
- raise ValueError("KYOJIN_FRONT_LAYERS cannot be combined with tensor parallel, "
+ raise ValueError("KYOJIN_PART0_LAYERS cannot be combined with tensor parallel, "
"EXL3_LOAD_DEVICE or --gpu_split")
if os.environ.get("EXL3_LOAD_SPLIT"):
- raise ValueError("KYOJIN_FRONT_LAYERS cannot be combined with the legacy EXL3_LOAD_SPLIT budget")
+ raise ValueError("KYOJIN_PART0_LAYERS cannot be combined with the legacy EXL3_LOAD_SPLIT budget")
from .device_map import SplitPlan, resolve_devices
- devices = resolve_devices(os.environ.get("KYOJIN_FRONT_DEVICE"),
- os.environ.get("KYOJIN_MAIN_DEVICE"))
+ devices = resolve_devices(os.environ.get("KYOJIN_PART0_DEVICE"),
+ os.environ.get("KYOJIN_PART1_DEVICE"))
endcaps = os.environ.get("KYOJIN_ENDCAPS", "1") != "0"
- reserve = float(os.environ.get("KYOJIN_FRONT_RESERVE_GB", "1.2"))
- split_plan = SplitPlan(devices, endcaps = endcaps, front_layers = front_layers,
- front_reserve_gb = reserve,
+ reserve = float(os.environ.get("KYOJIN_PART0_RESERVE_GB", "1.2"))
+ split_plan = SplitPlan(devices, endcaps = endcaps, part0_layers = part0_layers,
+ part0_reserve_gb = reserve,
preset = os.environ.get("KYOJIN_SPLIT_PRESET", "auto"),
logger = lambda m: printp(not quiet, m))
split_plan.add("text", model, config = config, cache = cache, load_order = 0)
@@ -365,24 +365,24 @@ def init(
cache = draft_cache, load_order = 1)
else:
# A separate text drafter has its own trunk; do not treat it as a
- # whole-component MTP and place it entirely on the front card.
+ # whole-component MTP and place it entirely on the part0 card.
from .device_map import ComponentPolicy
draft_component = "draft"
split_plan.add("draft", draft_model, config = draft_config,
cache = draft_cache,
policy = ComponentPolicy(name = "draft", kind = "aux",
- front_eligible = False,
- endcaps_front = False),
- front_layers = 0, load_order = 1)
+ part0_eligible = False,
+ endcaps_part0 = False),
+ part0_layers = 0, load_order = 1)
split_plan.build()
split_plan.install_bridges()
split_plan.engage_budget()
- front_map = split_plan.map("text")
+ text_map = split_plan.map("text")
draft_map = split_plan.map(draft_component) if draft_component is not None else None
- if front_map is not None:
- printp(not quiet, f" -- layer split: {front_map.describe()}")
+ if text_map is not None:
+ printp(not quiet, f" -- layer split: {text_map.describe()}")
if split_plan.auto:
- printp(not quiet, f" -- layer split: auto chose {front_map.front_layers} front layer(s)")
+ printp(not quiet, f" -- layer split: auto chose {text_map.part0_layers} part0 layer(s)")
# Parallelism options
tp_options = {
@@ -421,7 +421,7 @@ def init(
# Load model
printp(not quiet, f" -- Loading {args.model_dir}")
model.load(
- **({"device_map": front_map} if front_map else
+ **({"device_map": text_map} if text_map else
({"device": single_device} if single_device else {"use_per_device": split})),
tensor_p = args.tensor_parallel,
progressbar = progress,
diff --git a/exllamav3/serve_split.py b/exllamav3/serve_split.py
index aab336a..c6b20a4 100644
--- a/exllamav3/serve_split.py
+++ b/exllamav3/serve_split.py
@@ -6,7 +6,7 @@ Adapters (``tools/glm`` first, then Qwen/DSV4) parse the same flags, resolve the
same devices and hand their components to ``SplitPlan``. No placement logic or
hardware-specific default lives here: a component is declared with a name and,
optionally, a policy. Devices are chosen by position (``cuda:N``, ``gfxXXXX``,
-UUID or name); either device may be the front or the main one.
+UUID or name); either device may serve ``part0`` or ``part1``.
This module stays pure stdlib at import: adapters must be able to apply their
serving environment before ``exllamav3`` (and therefore torch) is imported, so the
@@ -22,9 +22,9 @@ from typing import TYPE_CHECKING
if TYPE_CHECKING:
from exllamav3.device_map import ComponentMap, ComponentPolicy, SplitPlan
-# Load-time slab held on the front device. A tuning value, not a hardware rule:
-# size it to the front card (Stage 5 derives it from the device total).
-DEFAULT_FRONT_RESERVE_GB = 1.2
+# Load-time slab held on the part0 device. A tuning value, not a hardware rule:
+# size it to the part0 card (Stage 5 derives it from the device total).
+DEFAULT_PART0_RESERVE_GB = 1.2
# Split mode runs eager until per-segment capture lands (Stage 6). A whole-forward
# or per-block graph must never span the host-staged bridge between segments.
@@ -59,7 +59,7 @@ SPLIT_PRESETS: dict[str, dict[str, str]] = {
}
-def parse_front_layers(value) -> int | str:
+def parse_part0_layers(value) -> int | str:
if value is None:
return 0
if isinstance(value, int):
@@ -72,53 +72,53 @@ def parse_front_layers(value) -> int | str:
try:
return max(0, int(v))
except ValueError as exc:
- raise ValueError(f"front layers must be 0, N or auto, not {value!r}") from exc
+ raise ValueError(f"part0 layers must be 0, N or auto, not {value!r}") from exc
@dataclass
class SplitSettings:
- front_layers: int | str = 0
- front_device: str = "auto"
- main_device: str = "auto"
+ part0_layers: int | str = 0
+ part0_device: str = "auto"
+ part1_device: str = "auto"
endcaps: bool = True
- front_reserve_gb: float = DEFAULT_FRONT_RESERVE_GB
+ part0_reserve_gb: float = DEFAULT_PART0_RESERVE_GB
preset: str = "auto"
split_graphs: str = "auto"
@property
def enabled(self) -> bool:
- return self.front_layers == "auto" or (isinstance(self.front_layers, int) and self.front_layers > 0)
+ return self.part0_layers == "auto" or (isinstance(self.part0_layers, int) and self.part0_layers > 0)
@property
def auto(self) -> bool:
- return self.front_layers == "auto"
+ return self.part0_layers == "auto"
def describe(self) -> str:
- return (f"front_layers={self.front_layers} main_device={self.main_device} "
- f"front_device={self.front_device} "
+ return (f"part0_layers={self.part0_layers} part1_device={self.part1_device} "
+ f"part0_device={self.part0_device} "
f"endcaps={'on' if self.endcaps else 'off'} "
- f"reserve={self.front_reserve_gb:.2f}GiB preset={self.preset} "
+ f"reserve={self.part0_reserve_gb:.2f}GiB preset={self.preset} "
f"graphs={self.split_graphs}")
def add_split_arguments(parser: argparse.ArgumentParser) -> None:
- parser.add_argument("--front-layers", default = None,
- help = "contiguous layer split: first N transformer layers on the front device; "
- "auto = fit from actual bytes; 0 = off (default: KYOJIN_FRONT_LAYERS, else 0)")
- parser.add_argument("--main-device", default = None,
- help = "main device: auto, gfxXXXX, cuda:N or a UUID/name substring "
- "(default: KYOJIN_MAIN_DEVICE, else auto = cuda:0)")
- parser.add_argument("--front-device", default = None,
- help = "front device: auto, gfxXXXX, cuda:N or a UUID/name substring "
- "(default: KYOJIN_FRONT_DEVICE, else auto = the only other device). "
- "cuda:N is the torch index after HIP_VISIBLE_DEVICES; either device "
- "may be the front or the main one")
+ parser.add_argument("--part0-layers", default = None,
+ help = "contiguous layer split: first N transformer layers on the part0 device; "
+ "auto = fit from actual bytes; 0 = off (default: KYOJIN_PART0_LAYERS, else 0)")
+ parser.add_argument("--part1-device", default = None,
+ help = "part1 device (the rest of the layers): auto, gfxXXXX, cuda:N or a "
+ "UUID/name substring (default: KYOJIN_PART1_DEVICE, else auto = cuda:0)")
+ parser.add_argument("--part0-device", default = None,
+ help = "part0 device (the first N layers): auto, gfxXXXX, cuda:N or a UUID/name "
+ "substring (default: KYOJIN_PART0_DEVICE, else auto = the only other device). "
+ "cuda:N is the torch index after HIP_VISIBLE_DEVICES; either device may "
+ "serve part0 or part1")
parser.add_argument("--endcaps", choices = ("on", "off"), default = None,
help = "with a layer split, keep allowlisted embedding/norm/lm_head/MTP/vision "
- "modules on the front device (default: KYOJIN_ENDCAPS, else on)")
- parser.add_argument("--front-reserve-gb", type = float, default = None,
- help = "VRAM held as a load-time slab on the front device for workspace; a "
- "tuning value, not a hardware rule (default: KYOJIN_FRONT_RESERVE_GB, else 1.2)")
+ "modules on the part0 device (default: KYOJIN_ENDCAPS, else on)")
+ parser.add_argument("--part0-reserve-gb", type = float, default = None,
+ help = "VRAM held as a load-time slab on the part0 device for workspace; a "
+ "tuning value, not a hardware rule (default: KYOJIN_PART0_RESERVE_GB, else 1.2)")
parser.add_argument("--split-preset", choices = tuple(SPLIT_PRESETS), default = None,
help = "per-model split preset (default: KYOJIN_SPLIT_PRESET, else auto)")
parser.add_argument("--split-graphs", choices = ("auto", "on", "off"), default = None,
@@ -126,9 +126,9 @@ def add_split_arguments(parser: argparse.ArgumentParser) -> None:
def settings_from_namespace(args) -> SplitSettings:
- raw = getattr(args, "front_layers", None)
+ raw = getattr(args, "part0_layers", None)
if raw is None:
- raw = os.environ.get("KYOJIN_FRONT_LAYERS", "0")
+ raw = os.environ.get("KYOJIN_PART0_LAYERS", "0")
endcaps = getattr(args, "endcaps", None)
if endcaps is None:
endcaps = os.environ.get("KYOJIN_ENDCAPS", "1") != "0"
@@ -136,15 +136,15 @@ def settings_from_namespace(args) -> SplitSettings:
endcaps = endcaps == "on"
preset = getattr(args, "split_preset", None) or os.environ.get("KYOJIN_SPLIT_PRESET", "auto")
graphs = getattr(args, "split_graphs", None) or "auto"
- reserve = getattr(args, "front_reserve_gb", None)
+ reserve = getattr(args, "part0_reserve_gb", None)
if reserve is None:
- reserve = float(os.environ.get("KYOJIN_FRONT_RESERVE_GB", str(DEFAULT_FRONT_RESERVE_GB)))
+ reserve = float(os.environ.get("KYOJIN_PART0_RESERVE_GB", str(DEFAULT_PART0_RESERVE_GB)))
return SplitSettings(
- front_layers = parse_front_layers(raw),
- main_device = getattr(args, "main_device", None) or os.environ.get("KYOJIN_MAIN_DEVICE") or "auto",
- front_device = getattr(args, "front_device", None) or os.environ.get("KYOJIN_FRONT_DEVICE") or "auto",
+ part0_layers = parse_part0_layers(raw),
+ part1_device = getattr(args, "part1_device", None) or os.environ.get("KYOJIN_PART1_DEVICE") or "auto",
+ part0_device = getattr(args, "part0_device", None) or os.environ.get("KYOJIN_PART0_DEVICE") or "auto",
endcaps = bool(endcaps),
- front_reserve_gb = float(reserve),
+ part0_reserve_gb = float(reserve),
preset = (preset or "auto").strip().lower(),
split_graphs = graphs,
)
@@ -187,7 +187,7 @@ class SplitController:
self.plan = None
if settings.enabled:
from exllamav3.device_map import resolve_devices
- self.devices = resolve_devices(settings.front_device, settings.main_device)
+ self.devices = resolve_devices(settings.part0_device, settings.part1_device)
@property
def enabled(self) -> bool:
@@ -201,8 +201,8 @@ class SplitController:
self.plan = SplitPlan(
self.devices,
endcaps = self.settings.endcaps,
- front_layers = self.settings.front_layers,
- front_reserve_gb = self.settings.front_reserve_gb,
+ part0_layers = self.settings.part0_layers,
+ part0_reserve_gb = self.settings.part0_reserve_gb,
preset = self.settings.preset,
logger = self.logger,
)
@@ -243,7 +243,7 @@ class SplitController:
cmap = self.map(component)
if cmap is None:
raise RuntimeError(f"split: component {component!r} was not declared")
- # The owner map holds the front reserve for the whole load sequence; repeated
+ # The owner map holds the part0 reserve for the whole load sequence; repeated
# calls are idempotent (ComponentMap.engage_budget).
self.plan.engage_budget()
t0 = time.perf_counter()
diff --git a/tests/test_split_plan_cpu.py b/tests/test_split_plan_cpu.py
index 87ddd5c..b6065b8 100644
--- a/tests/test_split_plan_cpu.py
+++ b/tests/test_split_plan_cpu.py
@@ -1,7 +1,7 @@
"""CPU contract tests for the universal split core.
The placement rules, endcap allowlist, auto-N arithmetic and the layout-neutral
-front reserve are pure Python/torch-device logic: they run without a GPU or the
+part0 reserve are pure Python/torch-device logic: they run without a GPU or the
compiled extension. The integration gates (loads, determinism, needle) stay in
the strix_halo harnesses.
"""
@@ -119,10 +119,10 @@ class FakeProps:
def _devices(dm):
return dm.Devices(
- main = torch.device("cuda", 0),
- front = torch.device("cuda", 1),
- main_arch = "gfx1151",
- front_arch = "gfx1201",
+ part1 = torch.device("cuda", 0),
+ part0 = torch.device("cuda", 1),
+ part1_arch = "gfx1151",
+ part0_arch = "gfx1201",
)
@@ -142,7 +142,7 @@ def _infos(dm, *pairs):
@pytest.fixture
def clean_split_env(monkeypatch):
- for key in ("KYOJIN_FRONT_DEVICE", "KYOJIN_MAIN_DEVICE", "KYOJIN_FRONT_LAYERS", "KYOJIN_ENDCAPS"):
+ for key in ("KYOJIN_PART0_DEVICE", "KYOJIN_PART1_DEVICE", "KYOJIN_PART0_LAYERS", "KYOJIN_ENDCAPS"):
monkeypatch.delenv(key, raising = False)
@@ -161,10 +161,10 @@ def test_component_policy_defaults(split_modules):
text = dm.component_policy("text")
mtp = dm.component_policy("mtp")
aux = dm.component_policy("ngram")
- assert text.kind == "text" and text.front_eligible and text.endcaps_front
+ assert text.kind == "text" and text.part0_eligible and text.endcaps_part0
assert "RMSNorm" in text.endcap_types and "lm_head" in text.endcap_key_suffixes
- assert mtp.kind == "mtp" and mtp.whole_component and mtp.front_eligible
- assert aux.kind == "aux" and not aux.front_eligible
+ assert mtp.kind == "mtp" and mtp.whole_component and mtp.part0_eligible
+ assert aux.kind == "aux" and not aux.part0_eligible
def test_text_placement_uses_endcap_allowlist_and_safe_unknown_default(split_modules):
@@ -177,7 +177,7 @@ def test_text_placement_uses_endcap_allowlist_and_safe_unknown_default(split_mod
assert devices["hc_expand"] == torch.device("cuda", 1)
assert devices["model.language_model.norm"] == torch.device("cuda", 1)
assert devices["lm_head"] == torch.device("cuda", 1)
- assert devices["ngram"] == torch.device("cuda", 0) # unknown non-layer: main, warning default
+ assert devices["ngram"] == torch.device("cuda", 0) # unknown non-layer: part1, warning default
for i in range(4):
assert devices[f"model.language_model.layers.{i}"] == torch.device("cuda", 1 if i < 2 else 0)
@@ -189,12 +189,12 @@ def test_endcaps_off_follows_neighbours_only_for_allowlisted_modules(split_modul
devices = {m.key: cmap.device_for(m) for m in model.modules}
assert devices["hc_expand"] == torch.device("cuda", 1) # prologue follows layer 0
- assert devices["model.language_model.norm"] == torch.device("cuda", 0) # epilogue: last layer is main
+ assert devices["model.language_model.norm"] == torch.device("cuda", 0) # epilogue: last layer is part1
assert devices["lm_head"] == torch.device("cuda", 0)
assert devices["ngram"] == torch.device("cuda", 0)
- all_front = dm.ComponentMap.from_model(model, 4, False, _devices(dm), component = "text")
- devices = {m.key: all_front.device_for(m) for m in model.modules}
+ all_part0 = dm.ComponentMap.from_model(model, 4, False, _devices(dm), component = "text")
+ devices = {m.key: all_part0.device_for(m) for m in model.modules}
assert devices["model.language_model.norm"] == torch.device("cuda", 1)
assert devices["lm_head"] == torch.device("cuda", 1)
@@ -204,10 +204,10 @@ def test_layer_device_map_alias_keeps_harness_api(split_modules):
model = _glm_model()
cmap = dm.LayerDeviceMap.from_model(model, 2, True, _devices(dm), component = "text")
assert isinstance(cmap, dm.ComponentMap)
- assert cmap.front_layers == 2 and cmap.enabled
+ assert cmap.part0_layers == 2 and cmap.enabled
-def test_whole_component_places_every_module_front_only_with_endcaps(split_modules):
+def test_whole_component_places_every_module_part0_only_with_endcaps(split_modules):
dm, _bridge, _split = split_modules
mtp = FakeModel([
FakeModule("mtp.pre", caps = {}),
@@ -232,10 +232,10 @@ def test_module_bytes_uses_compile_or_alt_key_when_prefix_is_empty(split_modules
assert dm._module_bytes(tied, stc) == 456
-def test_policy_can_disable_endcap_front(split_modules):
+def test_policy_can_disable_endcap_part0(split_modules):
dm, _bridge, _split = split_modules
model = _glm_model()
- policy = dm.component_policy("text", endcaps_front = False)
+ policy = dm.component_policy("text", endcaps_part0 = False)
cmap = dm.ComponentMap.from_model(model, 2, True, _devices(dm), component = "text", policy = policy)
devices = {m.key: cmap.device_for(m) for m in model.modules}
assert devices["hc_expand"] == torch.device("cuda", 0)
@@ -248,7 +248,7 @@ def test_recurrent_placement_audit_reads_state_device(split_modules):
model = FakeModel([FakeModule("layer.0", layer_idx = 0)])
cache = FakeCache()
cache.recurrent_layers[(0, 0)] = FakeRecurrent(1024, torch.device("cuda", 0))
- plan = dm.SplitPlan(_devices(dm), endcaps = True, front_layers = 1,
+ plan = dm.SplitPlan(_devices(dm), endcaps = True, part0_layers = 1,
logger = lambda *_a: None)
plan.add("text", model, cache = cache)
plan.build()
@@ -264,11 +264,11 @@ def test_auto_n_is_capped_for_long_context(split_modules, monkeypatch):
model = FakeModel([FakeModule(f"layer.{i}", layer_idx = i) for i in range(4)])
cfg = FakeConfig({f"layer.{i}": gib for i in range(4)})
monkeypatch.setattr(dm.torch.cuda, "get_device_properties", lambda dev: FakeProps(16 * gib))
- plan = dm.SplitPlan(_devices(dm), endcaps = True, front_layers = "auto",
- front_reserve_gb = 1.0, auto_cap = 2, logger = lambda *_a: None)
+ plan = dm.SplitPlan(_devices(dm), endcaps = True, part0_layers = "auto",
+ part0_reserve_gb = 1.0, auto_cap = 2, logger = lambda *_a: None)
plan.add("text", model, config = cfg)
plan.build()
- assert plan.front_layers == 2
+ assert plan.part0_layers == 2
def test_auto_n_uses_actual_bytes_cache_and_reserve(split_modules, monkeypatch):
@@ -283,28 +283,28 @@ def test_auto_n_uses_actual_bytes_cache_and_reserve(split_modules, monkeypatch):
cache = FakeCache(per_layer = gib // 5) # 0.2 GiB per layer, only 16 keys exist
monkeypatch.setattr(dm.torch.cuda, "get_device_properties", lambda dev: FakeProps(6 * gib))
- plan = dm.SplitPlan(_devices(dm), endcaps = True, front_layers = "auto",
- front_reserve_gb = 1.0, logger = lambda *_a: None)
+ plan = dm.SplitPlan(_devices(dm), endcaps = True, part0_layers = "auto",
+ part0_reserve_gb = 1.0, logger = lambda *_a: None)
plan.add("text", model, config = cfg, cache = cache)
plan.build()
# budget 6 - 1 reserve - 0.25 safety = 4.75 GiB; each layer is 1.0 weights +
# 0.2 cache, endcap 0.1. N=3 -> 3.7, N=4 -> 4.9.
- assert plan.front_layers == 3
- assert plan.map("text").front_layers == 3
+ assert plan.part0_layers == 3
+ assert plan.map("text").part0_layers == 3
- plan_off = dm.SplitPlan(_devices(dm), endcaps = False, front_layers = "auto",
- front_reserve_gb = 1.0, logger = lambda *_a: None)
+ plan_off = dm.SplitPlan(_devices(dm), endcaps = False, part0_layers = "auto",
+ part0_reserve_gb = 1.0, logger = lambda *_a: None)
plan_off.add("text", model, config = cfg, cache = cache)
plan_off.build()
- assert plan_off.front_layers == 3
+ assert plan_off.part0_layers == 3
-def test_front_reserve_is_a_slab_not_an_allocator_cap(split_modules, monkeypatch):
+def test_part0_reserve_is_a_slab_not_an_allocator_cap(split_modules, monkeypatch):
dm, _bridge, _split = split_modules
model = _glm_model()
cmap = dm.ComponentMap.from_model(model, 2, True, _devices(dm), component = "text",
- front_reserve_gb = 0.5)
+ part0_reserve_gb = 0.5)
calls = []
def fake_empty(size, dtype = None, device = None):
@@ -318,7 +318,7 @@ def test_front_reserve_is_a_slab_not_an_allocator_cap(split_modules, monkeypatch
assert len(calls) == 1
assert calls[0][0] == int(0.5 * dm.GIB)
assert calls[0][2] == torch.device("cuda", 1)
- cmap.release_front_budget()
+ cmap.release_part0_budget()
assert cmap._reserve_slabs == {}
@@ -326,22 +326,26 @@ def test_bridge_installs_per_config_and_is_reused(split_modules, monkeypatch):
dm, bridge_mod, _split = split_modules
monkeypatch.setenv("KYOJIN_BRIDGE", "1")
monkeypatch.setenv("KYOJIN_SPLIT_ACTIVE", "0")
- main, front = torch.device("cuda", 0), torch.device("cuda", 1)
+ part1, part0 = torch.device("cuda", 0), torch.device("cuda", 1)
cfg = SimpleNamespace()
draft_cfg = SimpleNamespace()
- b1 = bridge_mod.install_bridge(cfg, main, front)
- b2 = bridge_mod.install_bridge(cfg, main, front)
- b3 = bridge_mod.install_bridge(draft_cfg, main, front)
+ b1 = bridge_mod.install_bridge(cfg, part1 = part1, part0 = part0)
+ b2 = bridge_mod.install_bridge(cfg, part1 = part1, part0 = part0)
+ b3 = bridge_mod.install_bridge(draft_cfg, part1 = part1, part0 = part0)
assert cfg.split_active is True and draft_cfg.split_active is True
assert b1 is b2
assert b1 is not b3
- assert b1.pair == (main, front)
+ assert b1.pair == (part1, part0)
assert os.environ["KYOJIN_SPLIT_ACTIVE"] == "1"
+ # The pair is keyword-only so a caller cannot silently pass (part1, part0) backwards.
+ with pytest.raises(TypeError):
+ bridge_mod.install_bridge(cfg, part1, part0)
+
single = SimpleNamespace()
- assert bridge_mod.install_bridge(single, main, None) is None
+ assert bridge_mod.install_bridge(single, part1 = part1, part0 = None) is None
assert single.split_active is False
@@ -351,7 +355,7 @@ def test_named_preset_is_applied_by_the_plan(split_modules, monkeypatch):
old = split.SPLIT_PRESETS.get("glm", {})
split.SPLIT_PRESETS["glm"] = {"EXL3_TEST_PRESET": "1"}
try:
- plan = dm.SplitPlan(_devices(dm), endcaps = True, front_layers = 1,
+ plan = dm.SplitPlan(_devices(dm), endcaps = True, part0_layers = 1,
preset = "glm", logger = lambda *_a: None)
plan.add("text", _glm_model())
plan.build()
@@ -372,9 +376,9 @@ def test_named_preset_is_applied_by_the_plan(split_modules, monkeypatch):
def test_auto_selection_is_positional_and_arch_independent(split_modules, clean_split_env, archs):
dm, _bridge, _split = split_modules
devices = dm.resolve_devices(devices = _infos(dm, *archs))
- assert devices.main == torch.device("cuda", 0)
- assert devices.front == torch.device("cuda", 1)
- assert devices.main_arch == archs[0] and devices.front_arch == archs[1]
+ assert devices.part1 == torch.device("cuda", 0)
+ assert devices.part0 == torch.device("cuda", 1)
+ assert devices.part1_arch == archs[0] and devices.part0_arch == archs[1]
assert [d.index for d in devices.inventory] == [0, 1]
@@ -383,32 +387,32 @@ def test_explicit_selectors_support_both_positions(split_modules, clean_split_en
infos = _infos(dm, "gfx1151", "gfx1201")
mixed = dm.resolve_devices("cuda:1", "cuda:0", devices = infos)
- assert (mixed.main_arch, mixed.front_arch) == ("gfx1151", "gfx1201")
+ assert (mixed.part1_arch, mixed.part0_arch) == ("gfx1151", "gfx1201")
reversed_pair = dm.resolve_devices("gfx1151", "gfx1201", devices = infos)
- assert reversed_pair.main == torch.device("cuda", 1)
- assert reversed_pair.front == torch.device("cuda", 0)
- assert (reversed_pair.main_arch, reversed_pair.front_arch) == ("gfx1201", "gfx1151")
+ assert reversed_pair.part1 == torch.device("cuda", 1)
+ assert reversed_pair.part0 == torch.device("cuda", 0)
+ assert (reversed_pair.part1_arch, reversed_pair.part0_arch) == ("gfx1201", "gfx1151")
by_name_uuid = dm.resolve_devices("device-1", "device-0", devices = infos)
- assert by_name_uuid.main == torch.device("cuda", 0)
- assert by_name_uuid.front == torch.device("cuda", 1)
+ assert by_name_uuid.part1 == torch.device("cuda", 0)
+ assert by_name_uuid.part0 == torch.device("cuda", 1)
-def test_explicit_front_with_auto_main_uses_the_other_device(split_modules, clean_split_env):
+def test_explicit_part0_with_auto_part1_uses_the_other_device(split_modules, clean_split_env):
dm, _bridge, _split = split_modules
infos = _infos(dm, "gfx1151", "gfx1201")
by_index = dm.resolve_devices("cuda:0", devices = infos)
- assert by_index.main == torch.device("cuda", 1)
- assert by_index.front == torch.device("cuda", 0)
+ assert by_index.part1 == torch.device("cuda", 1)
+ assert by_index.part0 == torch.device("cuda", 0)
by_arch = dm.resolve_devices("gfx1151", devices = infos)
- assert by_arch.main == torch.device("cuda", 1)
- assert by_arch.front == torch.device("cuda", 0)
+ assert by_arch.part1 == torch.device("cuda", 1)
+ assert by_arch.part0 == torch.device("cuda", 0)
many = _infos(dm, "gfx1100", "gfx1151", "gfx1201")
- with pytest.raises(RuntimeError, match = "set KYOJIN_MAIN_DEVICE"):
+ with pytest.raises(RuntimeError, match = "set KYOJIN_PART1_DEVICE"):
dm.resolve_devices("cuda:0", devices = many)
@@ -420,16 +424,16 @@ def test_uuid_and_name_substring_selectors(split_modules, clean_split_env):
("gfx1151", "AMD Radeon 8060S", "dd-ee-ff"),
)
dev = dm.resolve_devices("aa-bb-cc", "8060s", devices = infos)
- assert dev.main == torch.device("cuda", 1)
- assert dev.front == torch.device("cuda", 0)
+ assert dev.part1 == torch.device("cuda", 1)
+ assert dev.part0 == torch.device("cuda", 0)
-def test_main_device_env_is_honoured(split_modules, clean_split_env, monkeypatch):
+def test_part1_device_env_is_honoured(split_modules, clean_split_env, monkeypatch):
dm, _bridge, _split = split_modules
- monkeypatch.setenv("KYOJIN_MAIN_DEVICE", "cuda:1")
+ monkeypatch.setenv("KYOJIN_PART1_DEVICE", "cuda:1")
dev = dm.resolve_devices(devices = _infos(dm, "gfx1151", "gfx1201"))
- assert dev.main == torch.device("cuda", 1)
- assert dev.front == torch.device("cuda", 0)
+ assert dev.part1 == torch.device("cuda", 1)
+ assert dev.part0 == torch.device("cuda", 0)
def test_one_device_fails_clearly(split_modules, clean_split_env):
@@ -438,14 +442,14 @@ def test_one_device_fails_clearly(split_modules, clean_split_env):
dm.resolve_devices(devices = _infos(dm, "gfx1151"))
-def test_three_devices_require_an_explicit_front(split_modules, clean_split_env):
+def test_three_devices_require_an_explicit_part0(split_modules, clean_split_env):
dm, _bridge, _split = split_modules
infos = _infos(dm, "gfx1100", "gfx1151", "gfx1201")
- with pytest.raises(RuntimeError, match = "3 devices.*--front-device"):
+ with pytest.raises(RuntimeError, match = "3 devices.*--part0-device"):
dm.resolve_devices(devices = infos)
dev = dm.resolve_devices("cuda:2", "cuda:1", devices = infos)
- assert dev.main == torch.device("cuda", 1)
- assert dev.front == torch.device("cuda", 2)
+ assert dev.part1 == torch.device("cuda", 1)
+ assert dev.part0 == torch.device("cuda", 2)
def test_same_device_and_bad_selectors_fail_clearly(split_modules, clean_split_env):
@@ -459,21 +463,21 @@ def test_same_device_and_bad_selectors_fail_clearly(split_modules, clean_split_e
dm.resolve_devices("gfx9999", devices = infos)
-def test_settings_parse_main_device_and_keep_split_off_off(split_modules, clean_split_env, monkeypatch):
+def test_settings_parse_part1_device_and_keep_split_off_off(split_modules, clean_split_env, monkeypatch):
dm, _bridge, split = split_modules
- monkeypatch.setenv("KYOJIN_MAIN_DEVICE", "cuda:1")
- args = SimpleNamespace(front_layers = None, front_device = None, main_device = None,
+ monkeypatch.setenv("KYOJIN_PART1_DEVICE", "cuda:1")
+ args = SimpleNamespace(part0_layers = None, part0_device = None, part1_device = None,
endcaps = None, split_preset = None, split_graphs = None,
- front_reserve_gb = None)
+ part0_reserve_gb = None)
settings = split.settings_from_namespace(args)
- assert settings.main_device == "cuda:1"
+ assert settings.part1_device == "cuda:1"
assert settings.enabled is False
- args.main_device = "gfx1100"
- args.front_device = "gfx1151"
- args.front_layers = "2"
+ args.part1_device = "gfx1100"
+ args.part0_device = "gfx1151"
+ args.part0_layers = "2"
settings = split.settings_from_namespace(args)
- assert (settings.main_device, settings.front_device) == ("gfx1100", "gfx1151")
+ assert (settings.part1_device, settings.part0_device) == ("gfx1100", "gfx1151")
assert settings.enabled is True
@@ -484,9 +488,9 @@ def test_split_off_does_not_touch_device_selection(split_modules, monkeypatch):
pytest.fail("split off must not enumerate or resolve devices")
monkeypatch.setattr(dm, "resolve_devices", boom)
- controller = split.SplitController(split.SplitSettings(front_layers = 0,
- main_device = "cuda:9",
- front_device = "cuda:9"),
+ controller = split.SplitController(split.SplitSettings(part0_layers = 0,
+ part1_device = "cuda:9",
+ part0_device = "cuda:9"),
logger = lambda *_a: None)
assert controller.devices is None
assert controller.plan is None
@@ -514,28 +518,28 @@ def test_harness_graph_env_matches_shared_list(split_modules):
assert set(mod.GRAPH_ENV_OFF) == set(split.GRAPH_ENV_OFF)
-def test_harness_default_front_layers_depends_on_context(monkeypatch):
+def test_harness_default_part0_layers_depends_on_context(monkeypatch):
mod = _load_split_eval()
for ctx, expected in ((131072, 5), (65536, 6)):
monkeypatch.setattr(sys, "argv", ["split_eval.py", "--max-ctx", str(ctx)])
- assert mod.parse_args().front_layers == expected
+ assert mod.parse_args().part0_layers == expected
-def test_harness_front_layers_are_explicit_flags(monkeypatch):
+def test_harness_part0_layers_are_explicit_flags(monkeypatch):
mod = _load_split_eval()
- monkeypatch.setattr(sys, "argv", ["split_eval.py", "--max-ctx", "131072", "--front-layers", "7"])
- assert mod.parse_args().front_layers == 7
+ monkeypatch.setattr(sys, "argv", ["split_eval.py", "--max-ctx", "131072", "--part0-layers", "7"])
+ assert mod.parse_args().part0_layers == 7
monkeypatch.setattr(sys, "argv", ["split_eval.py", "--max-ctx", "131072",
- "--long-ctx-front-layers", "3"])
+ "--long-ctx-part0-layers", "3"])
args = mod.parse_args()
- assert args.front_layers == 3 and args.front_layers_defaulted is True
+ assert args.part0_layers == 3 and args.part0_layers_defaulted is True
def test_adapter_unsafe_env_is_applied_and_logged(split_modules, monkeypatch):
dm, _bridge, _split = split_modules
monkeypatch.setenv("EXL3_TEST_UNSAFE", "0")
policy = dm.component_policy("text", unsafe_env = (("EXL3_TEST_UNSAFE", "1"),))
- plan = dm.SplitPlan(_devices(dm), endcaps = True, front_layers = 1, logger = lambda *_a: None)
+ plan = dm.SplitPlan(_devices(dm), endcaps = True, part0_layers = 1, logger = lambda *_a: None)
plan.add("text", _glm_model(), policy = policy)
plan.build()
assert os.environ["EXL3_TEST_UNSAFE"] == "1"
@@ -546,12 +550,12 @@ def test_split_settings_off_is_a_noop(split_modules, monkeypatch):
monkeypatch.setenv("EXL3_BLOCK_GRAPH", "1")
for _k in ("EXL3_PF_HC_FUSE", "EXL3_PF_GR_FUSE", "EXL3_GR_PF_FUSE"):
monkeypatch.setenv(_k, "1")
- off = split.SplitSettings(front_layers = 0)
+ off = split.SplitSettings(part0_layers = 0)
assert off.enabled is False
assert split.apply_split_env(off) == []
assert os.environ["EXL3_BLOCK_GRAPH"] == "1"
- on = split.SplitSettings(front_layers = "auto")
+ on = split.SplitSettings(part0_layers = "auto")
assert on.enabled is True and on.auto is True
split.apply_split_env(on)
assert os.environ["EXL3_BLOCK_GRAPH"] == "0"
diff --git a/tools/glm/serve.py b/tools/glm/serve.py
index 6306ec7..77fc997 100644
--- a/tools/glm/serve.py
+++ b/tools/glm/serve.py
@@ -27,7 +27,7 @@ sys.path.append(str(Path(__file__).resolve().parent.parent))
import startup_health # noqa: E402 (GET /health with load progress while the model loads)
# Shared split helper: pure stdlib at import, it loads exllamav3 lazily after SPEED_ENV.
from kyojin_serve_split import ( # noqa: E402
- SplitController, SplitSettings, add_split_arguments, apply_split_env, parse_front_layers,
+ SplitController, SplitSettings, add_split_arguments, apply_split_env, parse_part0_layers,
settings_from_namespace,
)
from loopguard import AnswerTap, loop_guard_default # noqa: E402 (answer-phase loop guard shared with the Qwen server)
@@ -53,17 +53,17 @@ EH_SIDECAR_DEFAULT = "~/models/glm53-mtp-eh-proj-bf16.safetensors"
EH_SIDECAR_IN_PACK = "mtp_eh_proj.st"
# GLM adapter tuning, deliberately outside the split core: on RDNA4 (gfx12) the
# split runs the deterministic fla KDA chain, whose long-context prefill workspace
-# is not yet part of auto-N. Measured on a 16 GB gfx12 front card. This is a
-# property of this adapter/front pair, not of the split; explicit --front-layers
+# is not yet part of auto-N. Measured on a 16 GB gfx12 part0 card. This is a
+# property of this adapter/part0 pair, not of the split; explicit --part0-layers
# always wins.
GLM_LONG_CTX = 65536
GLM_LONG_CTX_AUTO_CAP = 5
-def _glm_small_kda_front(front_arch: str | None) -> bool:
- """True when this front runs the deterministic split KDA chain."""
+def _glm_small_kda_part0(part0_arch: str | None) -> bool:
+ """True when this part0 device runs the deterministic split KDA chain."""
from exllamav3.util.arch_list import kda_fused_output_unstable
- return kda_fused_output_unstable(front_arch)
+ return kda_fused_output_unstable(part0_arch)
# --sessions > 1 (several requests decode in one step): plain steps take the R-row exact paths (union MoE on the device table, R-row
@@ -698,9 +698,9 @@ class ResidentEngine:
image_cache_dir: str | None = IMAGE_CACHE_DIR_DEFAULT,
image_cache_dir_max_gb: float = IMAGE_CACHE_DIR_MAX_GB,
image_cache_dir_lock_s: float = IMAGE_CACHE_DIR_LOCK_S,
- front_layers: int | str = 0, front_device: str | None = None,
- main_device: str | None = None,
- endcaps: bool = True, front_reserve_gb: float = 1.2,
+ part0_layers: int | str = 0, part0_device: str | None = None,
+ part1_device: str | None = None,
+ endcaps: bool = True, part0_reserve_gb: float = 1.2,
split_settings: SplitSettings | None = None):
import torch
from exllamav3 import Cache, Config, Generator, Job, Model, Tokenizer
@@ -733,30 +733,30 @@ class ResidentEngine:
self.model = Model.from_config(self.config)
if split_settings is None:
split_settings = SplitSettings(
- front_layers = parse_front_layers(front_layers),
- front_device = front_device or "auto",
- main_device = main_device or "auto",
- endcaps = bool(endcaps), front_reserve_gb = float(front_reserve_gb))
+ part0_layers = parse_part0_layers(part0_layers),
+ part0_device = part0_device or "auto",
+ part1_device = part1_device or "auto",
+ endcaps = bool(endcaps), part0_reserve_gb = float(part0_reserve_gb))
self.split = SplitController(split_settings, logger = lambda m: print(f"serve: {m}", flush=True))
self.split_map = None
if self.split.enabled:
plan = self.split.build_plan()
- if plan is None or plan.devices.front is None:
- raise ValueError("layer split requested but no usable front device")
+ if plan is None or plan.devices.part0 is None:
+ raise ValueError("layer split requested but no usable part0 device")
print(f"serve: layer split: {split_settings.describe()}; "
- f"main {plan.devices.main} ({plan.devices.main_arch}), "
- f"front {plan.devices.front} ({plan.devices.front_arch})", flush=True)
+ f"part1 {plan.devices.part1} ({plan.devices.part1_arch}), "
+ f"part0 {plan.devices.part0} ({plan.devices.part0_arch})", flush=True)
if split_settings.auto:
- if _glm_small_kda_front(plan.devices.front_arch) and max_ctx > GLM_LONG_CTX:
+ if _glm_small_kda_part0(plan.devices.part0_arch) and max_ctx > GLM_LONG_CTX:
# Auto-N's byte budget does not yet know the split KDA prefill
# workspace; keep the measured-safe long-context cap until it does.
plan.auto_cap = GLM_LONG_CTX_AUTO_CAP
print(f"serve: layer split: auto-N capped at {GLM_LONG_CTX_AUTO_CAP} layers for "
- f"-c > {GLM_LONG_CTX} on this gfx12 front: the split KDA prefill workspace "
- "is not in the byte budget (adapter tuning; pass --front-layers N to "
+ f"-c > {GLM_LONG_CTX} on this gfx12 part0: the split KDA prefill workspace "
+ "is not in the byte budget (adapter tuning; pass --part0-layers N to "
"override)", flush=True)
else:
- print("serve: layer split: auto-N uncapped (front does not need the split "
+ print("serve: layer split: auto-N uncapped (part0 does not need the split "
"KDA long-context reserve)", flush=True)
self.tokenizer = Tokenizer.from_config(self.config)
if os.environ.get("KYO_TOKCACHE", "8") == "0":
@@ -804,16 +804,16 @@ class ResidentEngine:
self.split.build()
self.split_map = self.split.map("text")
if self.split_map is not None and not self.split_map.enabled:
- raise ValueError("layer split requested but no usable front device (or auto-N found no layer that fits)")
+ raise ValueError("layer split requested but no usable part0 device (or auto-N found no layer that fits)")
if split_settings.auto and self.split_map is not None:
- print(f"serve: layer split: auto-N chose {self.split_map.front_layers} front layer(s) "
+ print(f"serve: layer split: auto-N chose {self.split_map.part0_layers} part0 layer(s) "
f"for -c {ctx}", flush=True)
- if (self.split_map is not None and self.split_map.front_layers > GLM_LONG_CTX_AUTO_CAP
+ if (self.split_map is not None and self.split_map.part0_layers > GLM_LONG_CTX_AUTO_CAP
and max_ctx > GLM_LONG_CTX
- and _glm_small_kda_front(plan.devices.front_arch)):
- print(f"serve: warning: front layers > {GLM_LONG_CTX_AUTO_CAP} at -c > {GLM_LONG_CTX} "
- "is measured to OOM a 16 GB gfx12 front on long prefill (split KDA fallback "
- f"workspace); use --front-layers {GLM_LONG_CTX_AUTO_CAP} for long-context split runs",
+ and _glm_small_kda_part0(plan.devices.part0_arch)):
+ print(f"serve: warning: part0 layers > {GLM_LONG_CTX_AUTO_CAP} at -c > {GLM_LONG_CTX} "
+ "is measured to OOM a 16 GB gfx12 part0 on long prefill (split KDA fallback "
+ f"workspace); use --part0-layers {GLM_LONG_CTX_AUTO_CAP} for long-context split runs",
flush=True)
self.split.engage_budget()
self.split.load("text", self.model, progressbar=False,
diff --git a/tools/strix_halo/split_eval.py b/tools/strix_halo/split_eval.py
index 617541c..5e2cce2 100644
--- a/tools/strix_halo/split_eval.py
+++ b/tools/strix_halo/split_eval.py
@@ -6,9 +6,9 @@ baseline (--baseline), saves the greedy token ids to JSON, and optionally compar
saved runs token-for-token. It also measures decode t/s under --num-draft and can run a
long-context needle probe.
-The split works on any two supported devices; use --main-device/--front-device to put
-either device in either position. The context-dependent --front-layers default is
-harness tuning for a small front card, not a property of the split; pass --front-layers
+The split works on any two supported devices; use --part1-device/--part0-device to put
+either device in either position. The context-dependent --part0-layers default is
+harness tuning for a small part0 card, not a property of the split; pass --part0-layers
to choose N explicitly.
Usage (from the repo root, after `source tools/strix_halo/env.sh`):
@@ -65,19 +65,19 @@ def parse_args() -> argparse.Namespace:
p = argparse.ArgumentParser()
p.add_argument("-m", "--model", default="/data/models/NicSir--GLM-5.3-Flash-EXL3-2.72bpw")
p.add_argument("--baseline", action="store_true", help="single device (cuda:0), no layer split")
- p.add_argument("--front-layers", type=int, default=None)
- p.add_argument("--main-device", default="auto")
- p.add_argument("--front-device", default="auto")
+ p.add_argument("--part0-layers", type=int, default=None)
+ p.add_argument("--part1-device", default="auto")
+ p.add_argument("--part0-device", default="auto")
p.add_argument("--long-ctx-threshold", type=int, default=65536,
- help="context above which the harness default front-layer count changes")
- p.add_argument("--long-ctx-front-layers", type=int, default=5,
+ help="context above which the harness default part0-layer count changes")
+ p.add_argument("--long-ctx-part0-layers", type=int, default=5,
help="harness default for contexts above --long-ctx-threshold; measured on a "
- "small front card, not a property of the split")
- p.add_argument("--short-ctx-front-layers", type=int, default=6,
+ "small part0 card, not a property of the split")
+ p.add_argument("--short-ctx-part0-layers", type=int, default=6,
help="harness default at or below --long-ctx-threshold")
p.add_argument("--endcaps", choices=("on", "off"), default="on")
- p.add_argument("--front-reserve-gb", type=float, default=1.2)
- p.add_argument("--main-reserve-gb", type=float, default=0.0)
+ p.add_argument("--part0-reserve-gb", type=float, default=1.2)
+ p.add_argument("--part1-reserve-gb", type=float, default=0.0)
p.add_argument("-c", "--max-ctx", type=int, default=131072)
p.add_argument("--num-draft", type=int, default=2)
p.add_argument("--no-vision", action="store_true")
@@ -92,12 +92,12 @@ def parse_args() -> argparse.Namespace:
help="compare two saved runs: prompt ids and decode numbers")
p.add_argument("--no-perf", action="store_true", help="skip the 3 decode timing prompts")
args = p.parse_args()
- args.front_layers_defaulted = args.front_layers is None
- if args.front_layers is None:
- # Harness tuning for memory, not a split property: a small front card cannot
+ args.part0_layers_defaulted = args.part0_layers is None
+ if args.part0_layers is None:
+ # Harness tuning for memory, not a split property: a small part0 card cannot
# hold N=6 plus the long-context workspace. Both values are explicit flags.
- args.front_layers = (args.long_ctx_front_layers if args.max_ctx > args.long_ctx_threshold
- else args.short_ctx_front_layers)
+ args.part0_layers = (args.long_ctx_part0_layers if args.max_ctx > args.long_ctx_threshold
+ else args.short_ctx_part0_layers)
return args
@@ -182,10 +182,10 @@ def build_needle(depth: int, tokenizer):
def main() -> None:
args = parse_args()
- if args.front_layers_defaulted and not args.baseline:
- print(f"[harness] no --front-layers given: using N={args.front_layers} at -c "
+ if args.part0_layers_defaulted and not args.baseline:
+ print(f"[harness] no --part0-layers given: using N={args.part0_layers} at -c "
f"{args.max_ctx} (harness tuning, not a split property; override with "
- f"--front-layers N or --long-ctx-front-layers N)", flush=True)
+ f"--part0-layers N or --long-ctx-part0-layers N)", flush=True)
if args.compare:
compare(args.compare[0], args.compare[1])
return
@@ -214,16 +214,16 @@ def main() -> None:
text_map = None
if not args.baseline:
from exllamav3.device_map import SplitPlan, resolve_devices
- devices = resolve_devices(args.front_device, args.main_device)
+ devices = resolve_devices(args.part0_device, args.part1_device)
plan = SplitPlan(
- devices, endcaps = args.endcaps == "on", front_layers = args.front_layers,
- front_reserve_gb = 0.0 if args.no_budget else args.front_reserve_gb,
- main_reserve_gb = args.main_reserve_gb)
+ devices, endcaps = args.endcaps == "on", part0_layers = args.part0_layers,
+ part0_reserve_gb = 0.0 if args.no_budget else args.part0_reserve_gb,
+ part1_reserve_gb = args.part1_reserve_gb)
plan.add("text", model, config = config, cache = cache, load_order = 0)
plan.build()
text_map = plan.map("text")
- if args.front_layers > 0 and (text_map is None or not text_map.enabled):
- raise SystemExit("split map not enabled (no front device)")
+ if args.part0_layers > 0 and (text_map is None or not text_map.enabled):
+ raise SystemExit("split map not enabled (no part0 device)")
plan.install_bridges()
plan.engage_budget()
@@ -281,7 +281,7 @@ def main() -> None:
result = {
"mode": "baseline" if args.baseline else "split",
"model": args.model,
- "front_layers": None if args.baseline else args.front_layers,
+ "part0_layers": None if args.baseline else args.part0_layers,
"endcaps": None if args.baseline else args.endcaps,
"ctx": args.max_ctx,
"num_draft": args.num_draft,
diff --git a/tools/strix_halo/split_load.py b/tools/strix_halo/split_load.py
index d33e930..3870030 100644
--- a/tools/strix_halo/split_load.py
+++ b/tools/strix_halo/split_load.py
@@ -1,13 +1,13 @@
#!/usr/bin/env python3
"""Phase 3 loader gate: load the GLM pack across two devices and print the table.
-No forward pass is run. Either device may be the front or the main one; select
-them with --main-device/--front-device (cuda:N, gfxXXXX, UUID or name).
+No forward pass is run. Either device may serve part0 or part1; select them with
+--part1-device/--part0-device (cuda:N, gfxXXXX, UUID or name).
Usage (from the repo root, after `source tools/strix_halo/env.sh`):
python tools/strix_halo/split_load.py \
-m /data/models/NicSir--GLM-5.3-Flash-EXL3-2.72bpw \
- --front-layers 4 --endcaps on -c 65536
+ --part0-layers 4 --endcaps on -c 65536
"""
from __future__ import annotations
@@ -30,15 +30,15 @@ def mem_available_gib() -> float:
def main() -> None:
p = argparse.ArgumentParser()
p.add_argument("-m", "--model", required=True)
- p.add_argument("--front-layers", type=int, default=4)
- p.add_argument("--main-device", default="auto")
- p.add_argument("--front-device", default="auto")
+ p.add_argument("--part0-layers", type=int, default=4)
+ p.add_argument("--part1-device", default="auto")
+ p.add_argument("--part0-device", default="auto")
p.add_argument("--endcaps", choices=("on", "off"), default="on")
- p.add_argument("--front-reserve-gb", type=float, default=1.2)
+ p.add_argument("--part0-reserve-gb", type=float, default=1.2)
p.add_argument("-c", "--cache-size", type=int, default=65536)
p.add_argument("--num-draft", type=int, default=2)
p.add_argument("--no-vision", action="store_true")
- p.add_argument("--baseline", action="store_true", help="load everything on the main device, for the host-RAM comparison")
+ p.add_argument("--baseline", action="store_true", help="load everything on cuda:0, for the host-RAM comparison")
args = p.parse_args()
import torch
@@ -75,21 +75,21 @@ def main() -> None:
except Exception as exc: # noqa: BLE001
print(f"[baseline] vision not loaded: {type(exc).__name__}: {exc}", flush=True)
print(f"[baseline] load {time.perf_counter() - t0:.1f} s; "
- f"main allocated {torch.cuda.memory_allocated(torch.device('cuda:0')) / 2**30:.2f} GiB; "
+ f"cuda:0 allocated {torch.cuda.memory_allocated(torch.device('cuda:0')) / 2**30:.2f} GiB; "
f"peak {torch.cuda.max_memory_allocated(torch.device('cuda:0')) / 2**30:.2f} GiB", flush=True)
peak = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024 ** 2
print(f"[baseline] host RSS peak {peak:.2f} GiB; "
f"MemAvailable {host_before:.1f} -> {mem_available_gib():.1f} GiB", flush=True)
return
- devices = resolve_devices(args.front_device, args.main_device)
- plan = SplitPlan(devices, endcaps=endcaps, front_layers=args.front_layers,
- front_reserve_gb=args.front_reserve_gb)
+ devices = resolve_devices(args.part0_device, args.part1_device)
+ plan = SplitPlan(devices, endcaps=endcaps, part0_layers=args.part0_layers,
+ part0_reserve_gb=args.part0_reserve_gb)
plan.add("text", model, config=config, cache=cache, load_order=0)
plan.build()
text_map = plan.map("text")
if text_map is None or not text_map.enabled:
- raise SystemExit("split map is not enabled (no front device)")
+ raise SystemExit("split map is not enabled (no part0 device)")
plan.install_bridges()
plan.engage_budget()