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.

Document copy lookup, sampled drafts, recurrent slots and collector freeze env vars; note the shared spec_policy location

YanissAmz070cdee5e3b7
diff --git a/doc/env_vars.md b/doc/env_vars.md
index b9c8d91..23cff2f 100644
--- a/doc/env_vars.md
+++ b/doc/env_vars.md
@@ -937,6 +937,10 @@ latch the value at import.
| `EXL3_BIG_TAIL_DENSE` | `1` | On a sparse single-session decode pass longer than the query-length cap, lets the tail attend densely instead of sparsely. |
| `EXL3_PREFILL_BIG_CHUNK_MAXPOS` | `32768` | From this position on, prefill goes back to plain chunks, which lowers peak memory at very long context. `0` is off. |
| `EXL3_MOE_UNION_V2` | `1` | The v2 union MoE table, which stays on the device instead of synchronizing to the host. Already the engine default; `0` disables it. |
+| `EXL3_VERIFY_ROW_SPLIT` | `2` | Same switch as in the Qwen table: a verify round of 5 to 8 rows (copy-lookup rounds) runs as fused sub-calls. Rows 4 and below are unchanged. |
+| `EXL3_MOE_R8` | `1` | Same switch as in the Qwen table: rows 5 to 8 run as one fused MoE launch. |
+| `EXL3_GEMV_R_RM6` | `1` | Same switch as in the Qwen table: 5 or 6 rows run in one launch of the 6-row dense GEMV. |
+| `EXL3_SPEC_SAMPLED` | `1` | See the speculative-decoding entries below. The engine default is `0`; the GLM server turns it on. |
#### MiMo: the defaults in `tools/mimo/serve.py`
@@ -957,6 +961,17 @@ latch the value at import.
The same lane also exports `EXL3_HOST_LEAN`, `EXL3_HOST_CUTS`, `EXL3_LOAD_DEVICE` and
`EXL3_DENSE_GEMM_TUNE_FILE`, all covered above.
+#### Speculative decoding and start-up options of the GLM and Qwen servers
+
+| variable | default | what it does |
+|---|---|---|
+| `GLM_NGRAM` | `2,7,16,3` with one session, `off` with more | Copy lookup for the GLM server, as `gram,K,match[,cmin]`. When the last `match` tokens of the context appeared before, the next round verifies the `K` tokens that followed them, instead of the drafter's tokens. `cmin` cuts the copy where the two latest occurrences stop agreeing, and drops it if that leaves fewer than `cmin` tokens. The default copies 7 tokens after a 16-token match. It speeds up requests that copy or edit text; other requests are unchanged. It needs about 0.7 GiB of GPU memory more. It works only while one request is active. `off` (or `0`, `none`) turns it off, and so does `--num-draft 0`. A malformed value stops the server at start. With greedy decoding, a near-tie in a long answer can make the text differ from a run without lookup. |
+| `QWSPEC_NGRAM` | `2,7,16,3` | The same copy lookup for the Qwen server, in the same format. `2,3,5` gives the earlier setting (a 5-token match, 3 copied tokens). `off` turns it off. |
+| `QWSPEC_NGRAM_IDX` | `1` | Builds the lookup index when the request is queued, so its cost lands in the time to first token and not in the first decode round. `0` builds it lazily and also turns off the `cmin` check. |
+| `EXL3_SPEC_SAMPLED` | engine `0`; the GLM server sets `1` | For requests with temperature above 0 and an MTP drafter: the drafter draws its tokens from its own distribution, and the verify keeps each one with probability min(1, p/q), or resamples from the remainder. The output has the same distribution as plain sampling. Greedy requests are untouched. `0` goes back to taking the drafter's top token. The Qwen server does not set it. |
+| `EXL3_GLM_SLOTS` | `0` (one recurrent state slot per session) | Minimum number of recurrent state slots the GLM server allocates. The default sizes them to `--sessions`, which frees about 6 GiB of GPU memory at one session. `16` restores the earlier layout. |
+| `EXL3_GC_FREEZE` | Qwen server `1`, GLM server `0` | Moves the loaded model and tokenizer objects out of the Python garbage collector before the first generator is built. Without it, rebuilding the generator (for example after a `cache_salt` change) pays a collector pass of about 0.5 s inside the time to first token. `0` leaves them in the collector. |
+
### Server state
#### `KYOJIN_HEALTH_DIR` (default: `~/.cache/kyojin`)
diff --git a/flake.nix b/flake.nix
index 95e1737..7bd71d7 100644
--- a/flake.nix
+++ b/flake.nix
@@ -550,6 +550,8 @@
$out/share/kyojin/$flavor/
# qwen/serve.py imports spec_policy at draft-build time
# (sibling import, resolved relative to its own file).
+ # glm/serve.py imports the same file from ../qwen (path built
+ # from its own location), so the qwen flavor must ship too.
[ "$flavor" = qwen ] && cp $src/tools/$flavor/spec_policy.py \
$out/share/kyojin/$flavor/
# chat templates live next to the scripts (qwen/mimo) or in
diff --git a/tools/glm/SERVE.md b/tools/glm/SERVE.md
index 622f562..0486ba5 100644
--- a/tools/glm/SERVE.md
+++ b/tools/glm/SERVE.md
@@ -41,6 +41,11 @@ wins): `EXL3_CONV_GEMM=1`, `EXL3_DENSE_GEMM_TUNE=0`, `EXL3_MOE_UNION_V2=1`, `EXL
`Generator.MTP_FUSE_CATCHUP = 2`. There is no `--temperature`/seed handling beyond the
request body.
+Copy lookup (`GLM_NGRAM`), sampled drafts (`EXL3_SPEC_SAMPLED`), the recurrent slot count (`EXL3_GLM_SLOTS`) and the
+collector freeze (`EXL3_GC_FREEZE`) are described in [doc/env_vars.md](../../doc/env_vars.md).
+The lookup code is `tools/qwen/spec_policy.py`, which the GLM server finds through its own file path, so `tools/qwen`
+must ship next to `tools/glm`.
+
### MTP sidecar (higher draft acceptance)
The pack stores the MTP `eh_proj` at 2 bits. The pack also ships an unquantized copy,