GLM-5.3-Flash EXL3 on 2x DGX Spark with TensorFold
Python
Renumber #96's patch to 0087 (0084 goes to the Anthropic Messages API, #90)
MiaAI-Labb17bc5e3c35c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b921372..f923510 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -27,7 +27,7 @@ Every change to this recipe, newest first. Each release names the image it serveall rows' heads, is faster still but changes the head sum's rounding). Every score bit and selectionidentical (`tools/scores_loop_check.py`, 37 checks). Live on three Sparks: the same prompts cold, 35k 17.87 ->17.47 s, 226k 138.27 -> 126.60 s, replies byte-identical. `TF_GLM_SCORE_RB` is retired.-- **`DISPLAY_KV_BACKEND=dispram`** (patch `0084-glm-display-kv-dispram`; default `drm`, unchanged): `DISPLAY_KV_MIB` on+- **`DISPLAY_KV_BACKEND=dispram`** (patch `0087-glm-display-kv-dispram`; default `drm`, unchanged): `DISPLAY_KV_MIB` on[kindling spark-os](https://github.com/kindlingai/kindling-spark-os). There `nvidia_drm` runs without modeset, so`0072`'s DRM dumb buffer fails (`DRM_IOCTL_MODE_CREATE_DUMB`: ENOSYS) and the span never forms; kindling's`dispramd` owns the reservation and lends it through its client's `map_glued` (ordinary device memory with thediff --git a/CREDITS.md b/CREDITS.mdindex 79dbe2d..1ef9f99 100644--- a/CREDITS.md+++ b/CREDITS.md@@ -124,7 +124,7 @@ checkpoint's ShapleyMcg attribution and the drafter's license).- `0085-glm-select-split-loop` (the split selection's last pass over the earlier chunks only): by- `0086-glm-prompt-scores-loop` (the prompt scoring, one row and many pool blocks a program): by[BadAd84](https://github.com/BadAd84).-- `0084-glm-display-kv-dispram` (`DISPLAY_KV_BACKEND=dispram`: `0072`'s display reservation on kindling spark-os): by+- `0087-glm-display-kv-dispram` (`DISPLAY_KV_BACKEND=dispram`: `0072`'s display reservation on kindling spark-os): by[BadAd84](https://github.com/BadAd84). It maps the span through `dispram`, the display-carveout lender of[kindling spark-os](https://github.com/kindlingai/kindling-spark-os) by Matt Mastracci (Kindling AI). Nothing ofdispram ships here: the ranks import the host's client (`python/dispram.py`, GPL-3.0 with a bundling exception)diff --git a/README.md b/README.mdindex d4bfc47..cbee088 100644--- a/README.md+++ b/README.md@@ -288,7 +288,7 @@ in that reservation, so `start.sh` and each rank refuse the setting while any `c1792 is measured; 2048 failed in the vLLM kit (#234).On [kindling spark-os](https://github.com/kindlingai/kindling-spark-os), `nvidia_drm` runs without modeset, so theDRM path has no dumb buffers (`CREATE_DUMB` fails ENOSYS), and kindling's `dispramd` owns the reservation instead:-`DISPLAY_KV_BACKEND=dispram` (patch 0084) maps the same span through it (`dispram.map_glued`: ordinary device memory+`DISPLAY_KV_BACKEND=dispram` (patch 0087) maps the same span through it (`dispram.map_glued`: ordinary device memorywith the reservation's slice right above it, one virtual range). `start.sh` checks the daemon's socket and client andmounts both into every rank. 2032 MiB, measured on three Sparks at `PARALLEL=4`: +317,440 pool tokens.On the Spark's unified memory, running out tends to freeze the machine rather than fail an allocation. A setting that@@ -458,7 +458,7 @@ sets a value wins: the environment, then `scripts/local.sh`, then `.env`, then t| `WORKER_WEIGHTS` | `copy` | `copy`: the worker keeps its own copy of the weights; `nfs`: it reads the head's over NFS ([Worker weights over NFS](#worker-weights-over-nfs)); with `NFS_PATH`, `NFS_SERVER`, `NFS_VOLUME` || `KV_POOL_GIB` / `MEMORY_RESERVE_GIB` | `12.5` (`32` at `TP=3`) / `14.5`, plus ~0.95 a request past 4 and ~0.04 a window row past 32 (`19.6` at 8 requests and 64 rows) | the shared pool beyond the window (kept prompts, more long conversations at once) grows into what is free at start minus the reserve, up to `KV_POOL_GIB` GiB a Spark; the reserve sets the lowest free memory on the head (~4.5-5 GiB under a 1M-token prompt); it grows with `PARALLEL` because more requests at once take more than the startup estimate counts; raise it when other work shares the Sparks || `DISPLAY_KV_MIB` | `0` (off) | MiB of the GPU's display reservation added to the shared pool on every rank (patch 0072, `PARALLEL` above 1; a multiple of 16 up to 2032, 1792 measured): pool tokens without host memory, on top of `KV_POOL_GIB`; needs `/dev/dri/card0`; headless Sparks only (refused while a display is connected) |-| `DISPLAY_KV_BACKEND` | `drm` | where `DISPLAY_KV_MIB`'s reservation comes from: `drm` (a DRM dumb buffer on `card0`, `nvidia_drm` with `modeset=1`) or `dispram` (kindling spark-os's `dispramd`; `start.sh` mounts its socket and client into every rank) (patch 0084) |+| `DISPLAY_KV_BACKEND` | `drm` | where `DISPLAY_KV_MIB`'s reservation comes from: `drm` (a DRM dumb buffer on `card0`, `nvidia_drm` with `modeset=1`) or `dispram` (kindling spark-os's `dispramd`; `start.sh` mounts its socket and client into every rank) (patch 0087) || `DENSE` | `q4` | the checkpoint's BF16 weights (attention, shared experts, dense layers, head): `q4` (4-bit groups of 64, the head in FP8, kv_b in BF16), `fp8` or `bf16`. **Non-English prompts:** `q4` can lose the end of turn on short French coding prompts (replies run to `max_tokens`, issue #18); `fp8` keeps it, at ~10% decode speed || `ABLIT` | `0` | `1`: serve the gated [Ablit weights](https://huggingface.co/Mia-AiLab/GLM-5.3-Flash-EXL3-4bpw-TensorFold-Ablit) instead of the published checkpoint; needs `HF_TOKEN` and the terms accepted on the model's page; thinking defaults to off ([Ablit weights](#ablit-weights)) || `DRAFTER` | `dflash2` | `dflash2`: IncoAI's DFlash2 drafter, licensed [CC BY-NC-ND 4.0](https://creativecommons.org/licenses/by-nc-nd/4.0/), **non-commercial use only**; +5-10% decode. `mtp`: the checkpoint's own MTP head, one request at a time, which avoids that license (set it before the first `./start.sh` and DFlash2 is never downloaded) |@@ -577,7 +577,7 @@ applied with `patch -p0` in filename order); `start.sh` rebuilds or re-pulls the| Weights | `0002-glm-dense-fp8`, `0005-glm-dense-q4` | the checkpoint's BF16 dense weights in FP8, or 4-bit with MSE-searched ranges (`DENSE`) | q4 over fp8: prose 38.9 -> 44.4 tok/s, code 44.2 -> 48.7, prefill ~1,090 -> ~1,260 tok/s || KV cache | `0038-glm-kv-fp8` | the DSA latent cache and the indexer's pooled keys as FP8 rows (`KV=fp8`) | the 1M window with 4 requests fits || KV pool | `0072-glm-display-kv` | the first DSA latent planes in a span ending in the GPU's display reservation, which `MemAvailable` does not count; the pool's row copies of those planes by a kernel (a memcpy may not cross the span's two registrations) (`DISPLAY_KV_MIB`, by ezoushen) | 1792 MiB: ~277k more tokens at `PARALLEL=8`; the same bits, decode and prefill |-| KV pool, kindling | `0084-glm-display-kv-dispram` | `0072`'s span with its reservation half from kindling spark-os's `dispramd` instead of a DRM dumb buffer, which kindling's `nvidia_drm` (no modeset) cannot make; the rest of `0072` runs unchanged (`DISPLAY_KV_BACKEND=dispram`) | 2032 MiB: +317,440 tokens at `PARALLEL=4` on three Sparks; the display check 53/53 |+| KV pool, kindling | `0087-glm-display-kv-dispram` | `0072`'s span with its reservation half from kindling spark-os's `dispramd` instead of a DRM dumb buffer, which kindling's `nvidia_drm` (no modeset) cannot make; the rest of `0072` runs unchanged (`DISPLAY_KV_BACKEND=dispram`) | 2032 MiB: +317,440 tokens at `PARALLEL=4` on three Sparks; the display check 53/53 || Prompt | `0001-glm-exl3-prompt-experts`, `0004-glm-prompt-kernels`, `0009-glm-prefill-kernels`, `0020-glm-prompt-experts-order`, `0024-glm-prompt-select-rows`, `0028-glm-lean-prompt-scratch` | EXL3 expert kernels that keep a prompt chunk's rows in L2, launched in a better order; each row's input rotated once; dense attention only where the sparse pass needs it; token selection in blocks of 512 rows; smaller prompt scratch | faster prefill, less memory at 1M || Prompt, indexer | `0086-glm-prompt-scores-loop` | a prompt chunk's indexer scoring (`0009`'s `_scores`) takes one row and 32 pool blocks a program (`SCORE_LOOP`), the row's queries loaded once, instead of 4 rows and one block (`TF_GLM_SCORE_RB`, retired), which reloaded every row's queries for each 64-pool block | the scoring 36% faster at long context (the part of a cold prefill that grows with it); cold prefill at 226k 138.3 -> 126.6 s; the same bits || Prompt, two Sparks | `0010-glm-hc-split`, `0033-glm-prefill-overlap2`, `0017-glm-overlap-priority`, `0022-glm-overlap-normal-priority`, `0064-glm-split-connect-early` | hyper-connection glue split by rows between the Sparks, exchanges overlapped with the next rows' work (`SPLIT`); the split's send/receive connection opened before the weights and the cache pool (issue #36) | 50k prefill ~1,270 -> ~1,730 tok/s with 0009 and 0020; decode rounds pay ~1.5% |diff --git a/patches/0084-glm-display-kv-dispram.patch b/patches/0087-glm-display-kv-dispram.patchsimilarity index 100%rename from patches/0084-glm-display-kv-dispram.patchrename to patches/0087-glm-display-kv-dispram.patchdiff --git a/scripts/config.sh b/scripts/config.shindex 7649484..ce5f55f 100644--- a/scripts/config.sh+++ b/scripts/config.sh@@ -279,7 +279,7 @@ export TF_GLM_CACHE_GIB="$KV_POOL_GIB"# to card0. Needs /dev/dri/card0 in the containers (nvidia_drm with modeset=1; --gpus all passes it). 0 (default): off.DISPLAY_KV_MIB="${DISPLAY_KV_MIB:-0}"export TF_GLM_DISPLAY_KV_MIB="$DISPLAY_KV_MIB"-# Where the span's reservation half comes from (patch 0084): drm (default) maps a DRM dumb buffer on card0, as above;+# Where the span's reservation half comes from (patch 0087): drm (default) maps a DRM dumb buffer on card0, as above;# dispram takes it from the dispramd daemon of kindling spark-os, whose nvidia_drm runs without modeset (no dumb# buffers: CREATE_DUMB fails ENOSYS) and whose daemon owns the reservation. start.sh mounts dispramd's socket and its# python client into every rank for dispram and refuses a Spark without them.diff --git a/start.sh b/start.shindex 109f0bd..9d97775 100755--- a/start.sh+++ b/start.sh@@ -308,7 +308,7 @@ env_args() {env_argsRUN_ARGS=(--gpus all --ipc=host --network host --shm-size 16g --device /dev/infiniband --cap-add IPC_LOCK--ulimit memlock=-1 --ulimit stack=67108864)-# DISPLAY_KV_BACKEND=dispram (patch 0084): dispramd's socket and its python client in every rank+# DISPLAY_KV_BACKEND=dispram (patch 0087): dispramd's socket and its python client in every rankif (( DISPLAY_KV_MIB )) && [[ "$DISPLAY_KV_BACKEND" == dispram ]]; thenRUN_ARGS+=(-v /run/dispram:/run/dispram -v /opt/kindling/dispram/python:/opt/dispram:ro -e PYTHONPATH=/opt/dispram)fidiff --git a/tools/display_kv_check.py b/tools/display_kv_check.pyindex ad76028..699746a 100755--- a/tools/display_kv_check.py+++ b/tools/display_kv_check.py@@ -1,5 +1,5 @@#!/usr/bin/env python3-"""Checks for patches 0072 (DISPLAY_KV_MIB) and 0084 (DISPLAY_KV_BACKEND=dispram), run inside the image that+"""Checks for patches 0072 (DISPLAY_KV_MIB) and 0087 (DISPLAY_KV_BACKEND=dispram), run inside the image thatscripts/prepare.sh built:docker run --rm --gpus all --entrypoint python -v "$PWD/tools/display_kv_check.py:/c.py" tensorfold-glm53:v0.6.0 \@@ -7,7 +7,7 @@ scripts/prepare.sh built:Without --gpu: the setting, the refusal while a display is connected, how many latent planes the span takes, the span's mapping and unwinding (a fake for everyDRM and CUDA driver call), the planes carved from a span, the pool's row copies of spanned planes against stock-ones, and 0084's backend switch and refusals (a fake dispram client). With --gpu, on a Spark whose display reservation+ones, and 0087's backend switch and refusals (a fake dispram client). With --gpu, on a Spark whose display reservationis free (the server stopped, or started with DISPLAY_KV_MIB=0): the real span, written and read back by the GPU acrossboth halves, and a pool copy across the boundary. On kindling spark-os, run the GPU half through dispramd: add-e TF_GLM_DISPLAY_KV_BACKEND=dispram and start.sh's mounts (-v /run/dispram:/run/dispram -v@@ -23,7 +23,7 @@ from tensorfold.families.glm5_next.cuda import kv8MIB = 2 ** 20failures = []-# the backend the --gpu half maps the real span through (patch 0084); the fake driver checks below use drm+# the backend the --gpu half maps the real span through (patch 0087); the fake driver checks below use drmGPU_BACKEND = os.environ.pop(dk.BACKEND_ENV, None)@@ -40,7 +40,7 @@ def raises(call, *args, match=""):return match in str(exc)return False-# patch 0084: with DISPLAY_KV_BACKEND unset the span is the DRM path's, which every fake driver check below drives+# patch 0087: with DISPLAY_KV_BACKEND unset the span is the DRM path's, which every fake driver check below drivescheck("the backend is drm unless DISPLAY_KV_BACKEND says otherwise", dk.backend() == "drm")@@ -242,7 +242,7 @@ for dtype, shape in ((torch.uint8, (64, 528)), (torch.bfloat16, (64, 512))):check(f"spanned rows copy as stock, by a kernel: {dtype} {src}->{dst} x{n}", same and by_kernel,f"stock kernel calls {stock_calls}, spanned {len(calls) - stock_calls}")-# -- patch 0084: the reservation from kindling's dispramd (DISPLAY_KV_BACKEND=dispram) --------------------------------+# -- patch 0087: the reservation from kindling's dispramd (DISPLAY_KV_BACKEND=dispram) --------------------------------import importlib # noqa: E402importlib.reload(dk) # the real map_span again (the sections above replaced it)