Skip to content

GLM-5.3-Flash EXL3 on 2x DGX Spark with TensorFold

Python

Patch 0084: DISPLAY_KV_MIB on kindling spark-os (DISPLAY_KV_BACKEND=dispram, off by default)

BadAd84b50c490c510c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 515fb07..ec40e30 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,21 @@
Every change to this recipe, newest first. Each release names the image it serves: `scripts/prepare.sh` pulls
`ghcr.io/miaai-lab/glm-5.3-flash-exl3-2x-dgx-sparks-tensorfold` by the digest pinned in `scripts/config.sh`.
+## Unreleased
+
+- **`DISPLAY_KV_BACKEND=dispram`** (patch `0084-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 the
+ reservation's slice right above it, one virtual range - the layout `0072`'s `map_span` builds). The backend takes
+ the span from there and everything carved from it is `0072`'s, unchanged. Fails closed like the DRM path: no client,
+ no daemon, or a slice shorter than the span stops the start. `start.sh` checks `/run/dispram/dispram.sock` and
+ `/opt/kindling/dispram/python` on the head and mounts both into every rank. Measured on three Sparks (TP=3,
+ `PARALLEL=4`, `KV_POOL_GIB=30`): 2032 MiB adds 317,440 pool tokens; `tools/display_kv_check.py`'s GPU check
+ passes 53/53 through the dispram span (display -> device copies 46.3 GiB/s); decode and prefill as without the span
+ (structured / prose / code 140.4 / 74.3 / 112.5 tok/s against 141.2 / 74.2 / 112.5; drafted replies equal serial
+ ones 7/7); an NVMe-backed restart and eviction test with the span on resumed byte-identical replies.
+
## v1.8 (2026-10-06): pictures read once, quoted markers, capacity refusals, and the take-over memory fix
Image: `v0.6.0-31557ed1cef6` (`sha256:cbb4b3c66273e2965dd40a7227e7a5243db333fe250113fb3987462ad4f12588`), 82 patches, for two and three Sparks (v1.7.1's plus `0078`-`0083`). Every change below was also
diff --git a/CREDITS.md b/CREDITS.md
index 08c4ae3..cf73896 100644
--- a/CREDITS.md
+++ b/CREDITS.md
@@ -118,6 +118,11 @@ checkpoint's ShapleyMcg attribution and the drafter's license).
[johnwhited](https://github.com/johnwhited) (#48); the admission check and the abort-on-delivery-failure semantics
follow [vLLM](https://github.com/vllm-project/vllm) v1's `check_admission` and generate-abort behaviour
(Apache 2.0) as a reference.
+- `0084-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 of
+ dispram ships here: the ranks import the host's client (`python/dispram.py`, GPL-3.0 with a bundling exception)
+ mounted read-only at run time and talk to `dispramd` (AGPL-3.0) over its socket.
- Every patch, except the parts credited above: by MiaAI-Lab, developed with
[Claude Code](https://claude.com/claude-code), under the Apache License 2.0; the TensorFold code the patches modify or
quote as context stays under TensorFold's licenses (Apache 2.0, and MIT for code written before v0.6.0; see
diff --git a/README.md b/README.md
index 5956b8c..12dd033 100644
--- a/README.md
+++ b/README.md
@@ -286,6 +286,11 @@ needs `/dev/dri/card0` in the containers (`nvidia_drm` with `modeset=1`; `--gpus
checks it on the head, and a worker without it stops at load. **Headless Sparks only:** a monitor's framebuffer lives
in that reservation, so `start.sh` and each rank refuse the setting while any `card0` output reports `connected`.
1792 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 the
+DRM 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
+with the reservation's slice right above it, one virtual range). `start.sh` checks the daemon's socket and client and
+mounts 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
does not fit is refused before any weights load, with the largest window that fits; `start.sh` then restarts once
with that window and says so (free memory on both Sparks for the full one). Other settings' windows:
@@ -453,6 +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) |
| `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) |
@@ -561,6 +567,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 |
| 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, 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% |
| Prompt, KDA | `0012-glm-kda-chunked`, `0014-glm-kda-chunked-gb10`, `0039-glm-kda-chunked-kernel` | the linear-attention layers' prompt chunks in chunked (WY) form, one CUDA kernel (`KDA_CHUNKED`) | 50k prefill 29.3 -> 26.4 s, 149k 91.1 -> 84.5 s (one start each) |
diff --git a/patches/0084-glm-display-kv-dispram.patch b/patches/0084-glm-display-kv-dispram.patch
new file mode 100644
index 0000000..27f3f74
--- /dev/null
+++ b/patches/0084-glm-display-kv-dispram.patch
@@ -0,0 +1,73 @@
+diff --git tensorfold/families/glm5_next/cuda/display_kv.py tensorfold/families/glm5_next/cuda/display_kv.py
+--- tensorfold/families/glm5_next/cuda/display_kv.py
++++ tensorfold/families/glm5_next/cuda/display_kv.py
+@@ -13,6 +13,13 @@
+ For headless Sparks only: a card with a connected output (a monitor) keeps its reservation, and the start stops.
+ Fails closed: the credited bytes were never budgeted against host memory, so a span that cannot be mapped stops the
+ start instead of falling back to ordinary memory.
++
++kindling spark-os: ``TF_GLM_DISPLAY_KV_BACKEND=dispram`` takes the span from kindling's dispramd instead of a
++DRM dumb buffer. kindling's nvidia_drm runs without modeset (CREATE_DUMB fails ENOSYS) and dispramd owns the
++reservation: its client's ``map_glued`` maps ordinary device memory with the reservation's slice right above it as one
++virtual range (CUDA VMM), the same layout ``map_span`` builds, so everything carved from the span is unchanged. Needs
++the client on the path and the daemon's socket in the container (start.sh mounts both for this backend). ``drm``
++(the default) is upstream's path.
+ """
+ from __future__ import annotations
+
+@@ -22,10 +29,19 @@
+
+ ENV = "TF_GLM_DISPLAY_KV_MIB"
+ CARD_ENV = "TF_GLM_DISPLAY_KV_CARD"
++BACKEND_ENV = "TF_GLM_DISPLAY_KV_BACKEND"
+ LARGEST_MIB = 2032
+ SYSFS = "/sys/class/drm"
+
+
++def backend() -> str:
++ """Where the span's reservation half comes from: ``drm`` (the default) or ``dispram`` (kindling spark-os)."""
++ value = (os.environ.get(BACKEND_ENV) or "drm").strip().lower()
++ if value not in ("drm", "dispram"):
++ raise ValueError(f"{BACKEND_ENV}={value!r}: drm or dispram")
++ return value
++
++
+ def mib() -> int:
+ """The display reservation credited to the pool, in MiB; 0 when off."""
+ raw = (os.environ.get(ENV) or "").strip()
+@@ -204,6 +220,26 @@
+ pass # unwinding: the first failure is the one to report
+
+
++def _map_span_dispram(ordinary: int, display: int) -> Span:
++ """``map_span`` from dispramd (kindling spark-os): ``ordinary`` bytes of device memory and at least
++ ``display`` bytes of the reservation right above them, one virtual range. Fails closed like the DRM path: no
++ client, no daemon or a slice short of ``display`` stops the start."""
++ try:
++ import dispram
++ except ImportError as exc:
++ raise RuntimeError(f"{ENV}: {BACKEND_ENV}=dispram, but the dispram client is not importable (mount "
++ "/opt/kindling/dispram/python and put it on PYTHONPATH)") from exc
++ if not dispram.available():
++ raise RuntimeError(f"{ENV}: {BACKEND_ENV}=dispram, but dispramd does not answer (mount /run/dispram)")
++ total = ordinary + display
++ index = torch.cuda.current_device()
++ torch.cuda.synchronize(index)
++ pointer, _, tail = _step("dispram.map_glued", dispram.map_glued, total, index)
++ if tail < display:
++ raise RuntimeError(f"{ENV}: dispramd lent {tail} B of the reservation, short of {display} B")
++ return Span(pointer, total)
++
++
+ def map_span(ordinary: int, display: int) -> Span:
+ """``ordinary`` bytes of host memory and the ``display`` bytes of the reservation right above them, both
+ registered with CUDA, as one span. Unwound completely on any failure."""
+@@ -211,6 +247,8 @@
+ if busy := connected_outputs(SYSFS, card):
+ raise RuntimeError(f"{ENV}: {', '.join(f'{card}-{o}' for o in busy)} has a display connected, which uses the "
+ f"reservation; unset {ENV} on a Spark with a monitor")
++ if backend() == "dispram": # the same refusal first; a scanned-out framebuffer is no place for a pool
++ return _map_span_dispram(ordinary, display)
+ total = ordinary + display
+ system = SYSTEM()
+ fd = handle = base = None
diff --git a/scripts/config.sh b/scripts/config.sh
index 4ee2dc6..7649484 100644
--- a/scripts/config.sh
+++ b/scripts/config.sh
@@ -279,6 +279,12 @@ 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;
+# 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.
+DISPLAY_KV_BACKEND="${DISPLAY_KV_BACKEND:-drm}"
+export TF_GLM_DISPLAY_KV_BACKEND="$DISPLAY_KV_BACKEND"
export TENSORFOLD_NO_UPDATE_CHECK="${TENSORFOLD_NO_UPDATE_CHECK:-1}"
diff --git a/start.sh b/start.sh
index abb4428..109f0bd 100755
--- a/start.sh
+++ b/start.sh
@@ -71,8 +71,15 @@ for v in SPLIT SHARED_PREFIX KDA_CHUNKED COPY_CODE MULTI_PREFILL STREAM_SMOOTH;
[[ "$DISPLAY_KV_MIB" =~ ^(0|[1-9][0-9]{0,3})$ ]] && (( DISPLAY_KV_MIB % 16 == 0 && DISPLAY_KV_MIB <= 2032 )) ||
die "DISPLAY_KV_MIB is a multiple of 16 from 0 to 2032, not $DISPLAY_KV_MIB"
(( DISPLAY_KV_MIB == 0 || PARALLEL > 1 )) || die "DISPLAY_KV_MIB adds to the shared pool, which needs PARALLEL above 1"
-(( DISPLAY_KV_MIB == 0 )) || [[ -e /dev/dri/card0 ]] || die "DISPLAY_KV_MIB needs /dev/dri/card0, which this Spark lacks"
-if (( DISPLAY_KV_MIB )); then # headless only: a monitor's framebuffer lives in the reservation
+[[ "$DISPLAY_KV_BACKEND" == drm || "$DISPLAY_KV_BACKEND" == dispram ]] ||
+ die "DISPLAY_KV_BACKEND is drm or dispram, not $DISPLAY_KV_BACKEND"
+if (( DISPLAY_KV_MIB )) && [[ "$DISPLAY_KV_BACKEND" == dispram ]]; then
+ # kindling spark-os: dispramd owns the reservation (its nvidia_drm has no dumb buffers); every rank gets its socket
+ # and python client (RUN_ARGS below), and the rank fails closed without them
+ [[ -S /run/dispram/dispram.sock ]] || die "DISPLAY_KV_BACKEND=dispram needs dispramd (/run/dispram/dispram.sock), which this Spark lacks"
+ [[ -d /opt/kindling/dispram/python ]] || die "DISPLAY_KV_BACKEND=dispram needs the dispram client (/opt/kindling/dispram/python)"
+elif (( DISPLAY_KV_MIB )); then # headless only: a monitor's framebuffer lives in the reservation
+ [[ -e /dev/dri/card0 ]] || die "DISPLAY_KV_MIB needs /dev/dri/card0, which this Spark lacks"
# no outputs under card0 at all: nvidia_drm runs without modeset, which has no dumb buffers for the span
compgen -G '/sys/class/drm/card0-*/status' >/dev/null ||
die "DISPLAY_KV_MIB needs nvidia_drm with modeset=1, and card0 shows no display outputs (an /etc/modprobe.d file may set modeset=0); set it to 0"
@@ -301,6 +308,10 @@ env_args() {
env_args
RUN_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
+if (( DISPLAY_KV_MIB )) && [[ "$DISPLAY_KV_BACKEND" == dispram ]]; then
+ RUN_ARGS+=(-v /run/dispram:/run/dispram -v /opt/kindling/dispram/python:/opt/dispram:ro -e PYTHONPATH=/opt/dispram)
+fi
# ---------------------------------------------------------------- 3. launch, 4. load (a second try when the window does not fit)
# No token goes into the containers: the ranks read only the local cache (HF_HUB_OFFLINE=1), and with HF_HUB_OFFLINE=0
diff --git a/tools/display_kv_check.py b/tools/display_kv_check.py
index e9f505c..ad76028 100755
--- a/tools/display_kv_check.py
+++ b/tools/display_kv_check.py
@@ -1,14 +1,17 @@
#!/usr/bin/env python3
-"""Checks for patch 0072 (DISPLAY_KV_MIB), run inside the image that scripts/prepare.sh built:
+"""Checks for patches 0072 (DISPLAY_KV_MIB) and 0084 (DISPLAY_KV_BACKEND=dispram), run inside the image that
+scripts/prepare.sh built:
docker run --rm --gpus all --entrypoint python -v "$PWD/tools/display_kv_check.py:/c.py" tensorfold-glm53:v0.6.0 \
/c.py [--gpu]
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 every
-DRM and CUDA driver call), the planes carved from a span, and the pool's row copies of spanned planes against stock
-ones. With --gpu, on a Spark whose display reservation is free (the server stopped, or started with DISPLAY_KV_MIB=0):
-the real span, written and read back by the GPU across both halves, and a pool copy across the boundary. Exit code 1
-when a check fails.
+DRM 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
+is free (the server stopped, or started with DISPLAY_KV_MIB=0): the real span, written and read back by the GPU across
+both 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
+/opt/kindling/dispram/python:/opt/dispram:ro -e PYTHONPATH=/opt/dispram). Exit code 1 when a check fails.
"""
import os
import sys
@@ -20,6 +23,8 @@ from tensorfold.families.glm5_next.cuda import kv8
MIB = 2 ** 20
failures = []
+# the backend the --gpu half maps the real span through (patch 0084); the fake driver checks below use drm
+GPU_BACKEND = os.environ.pop(dk.BACKEND_ENV, None)
def check(name, cond, detail=""):
@@ -35,6 +40,9 @@ 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
+check("the backend is drm unless DISPLAY_KV_BACKEND says otherwise", dk.backend() == "drm")
+
# -- the setting --------------------------------------------------------------------------------------------------------
def setting(value):
@@ -234,11 +242,85 @@ 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) --------------------------------
+import importlib # noqa: E402
+
+importlib.reload(dk) # the real map_span again (the sections above replaced it)
+
+
+def backend(value):
+ if value is None:
+ os.environ.pop(dk.BACKEND_ENV, None)
+ else:
+ os.environ[dk.BACKEND_ENV] = value
+ return dk.backend()
+
+
+check("backend drm by default", backend(None) == "drm")
+check("backend dispram, case and spaces as typed", backend("dispram") == "dispram" and backend(" DisPram ") == "dispram")
+check("backend refuses anything else", raises(backend, "dumb", match="drm or dispram"))
+
+
+class FakeDispram:
+ """kindling's client: available() is the daemon answering; map_glued(nbytes, device) -> (pointer, the ordinary
+ bytes, the reservation bytes lent above them)."""
+
+ def __init__(self, up=True, lend=None):
+ self.up, self.lend, self.calls = up, lend, []
+
+ def available(self):
+ return self.up
+
+ def map_glued(self, nbytes, index):
+ self.calls.append((nbytes, index))
+ return 0x7000_0000_0000, nbytes - self.lend, self.lend
+
+
+def via_dispram(client, call):
+ """call() with ``client`` as the importable dispram module (None: not importable) and CUDA's device calls faked."""
+ saved = sys.modules.get("dispram"), torch.cuda.current_device, torch.cuda.synchronize
+ sys.modules["dispram"] = client
+ torch.cuda.current_device, torch.cuda.synchronize = (lambda: 0), (lambda *a: None)
+ try:
+ return call()
+ finally:
+ if saved[0] is None:
+ sys.modules.pop("dispram", None)
+ else:
+ sys.modules["dispram"] = saved[0]
+ torch.cuda.current_device, torch.cuda.synchronize = saved[1], saved[2]
+
+
+ordinary, display = 64 * MIB, 1792 * MIB
+check("no client: refused", raises(lambda: via_dispram(None, lambda: dk._map_span_dispram(ordinary, display)),
+ match="not importable"))
+check("daemon down: refused", raises(lambda: via_dispram(FakeDispram(up=False, lend=display),
+ lambda: dk._map_span_dispram(ordinary, display)),
+ match="does not answer"))
+check("a slice short of the span: refused", raises(lambda: via_dispram(FakeDispram(lend=display - 16 * MIB),
+ lambda: dk._map_span_dispram(ordinary, display)),
+ match="short of"))
+client = FakeDispram(lend=display)
+span = via_dispram(client, lambda: dk._map_span_dispram(ordinary, display))
+check("the span is the client's one range", span.size == ordinary + display and client.calls == [(ordinary + display, 0)])
+backend("dispram")
+dk.connected_outputs = lambda sysfs, card: [] # noqa: E731
+dk.SYSTEM = lambda: (_ for _ in ()).throw(AssertionError("the DRM path ran")) # noqa: E731
+client = FakeDispram(lend=display)
+span = via_dispram(client, lambda: dk.map_span(ordinary, display))
+check("map_span takes the dispram path, never DRM", span.size == ordinary + display and len(client.calls) == 1)
+dk.connected_outputs = lambda sysfs, card: ["HDMI-A-1"] # noqa: E731
+check("a connected display is refused with dispram too",
+ raises(lambda: via_dispram(FakeDispram(lend=display), lambda: dk.map_span(ordinary, display)),
+ match="display connected"))
+backend(None)
+
# -- the real span on this node ---------------------------------------------------------------------------------------
if "--gpu" in sys.argv:
- import importlib
-
importlib.reload(dk)
+ if GPU_BACKEND:
+ os.environ[dk.BACKEND_ENV] = GPU_BACKEND
+ print(f"---- the real span through {dk.backend()}", flush=True)
os.environ[dk.ENV] = "1792"
rows = 1 << 18 # small planes, so the span takes many and a live server keeps its headroom
planes = dk.latent_planes(17, rows, 512, "fp8", "cuda", dk.credit())