GLM-5.3-Flash EXL3 on 2x DGX Spark with TensorFold
Python
FILL_ROWS=2048: a prompt that fills while other replies stream uses the whole prompt chunk (~10-14% sooner)
BadAd84cefd1b08e6f0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 54a3f69..0b9b2c6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -3,6 +3,16 @@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++- **A prompt that fills beside other replies, ~10-14% sooner** (`FILL_ROWS`, by [BadAd84](https://github.com/BadAd84)):+ while other requests decode, a new prompt filled in 1,024-row chunks (TensorFold's `TF_GLM_FILL_ROWS` default),+ half the 2,048-row prompt chunk whose buffers the engine keeps anyway. `scripts/config.sh` now sets 2,048 (at+ most `TF_GLM_PREFILL_ROWS`): the same memory, the same replies, half the passes over the expert weights. Three+ Sparks, `PARALLEL=4`, a 35k-token reply streaming meanwhile: a warm +20k turn on a 596k conversation 15.6-15.7 ->+ 14.0-14.1 s, a cold ~256k prompt 132.2-132.6 -> 113.4-114.0 s; the reply's gaps during the fill median 13-15 /+ p99 20-25 / max 25-67 ms either way. `FILL_ROWS=1024` restores the old size. CPU check: `tools/fill_rows_check.py`.+## v1.10 (2026-10-08): the effort line at the tail (opt-in), a kept-state share, and a checked second railImage: `v0.6.0-a1897d591f70` (`sha256:bc34d7d63f978cf601f42863b284bc95a567c50c10e9adb0866a635be568bf5f`), 96 patches (v1.9.1's plus `0096`, `0097`). Tested live on twodiff --git a/README.md b/README.mdindex 2bace9c..6364b45 100644--- a/README.md+++ b/README.md@@ -533,7 +533,8 @@ sets a value wins: the environment, then `scripts/local.sh`, then `.env`, then t| `TF_GLM_MAX_QUEUED` | unset | admission at saturation (patch `0082`): past the lanes plus this many queued foreground requests, a request is refused with 429 + `Retry-After: 5` instead of queueing; unset queues as every scheduler always has, `0` refuses anything past the lanes (by johnwhited, #48) || `MULTI_PREFILL` | `1` | prompts that arrive together are filled in one forward (each with the bits it gets alone); `0`: one after another || `STREAM_SMOOTH` / `STREAM_SMOOTH_MS` | `1` / `400` | streamed replies go out one token an event at a steady pace from a playout buffer of this many ms, so drafted bursts (~3 tokens every ~50-100 ms) and short pauses do not show; text appears that much later, the reply ends when it did, tool calls keep their place; `0`: one event a round |-| `FILL_BUDGET_MS` | `200` | while other requests decode, a new prompt fills in layer slices of about this many ms with a decode round between them; `0`: whole 1,024-row chunks, each of which froze the other replies ~0.65 s. A request alone fills at full speed either way |+| `FILL_BUDGET_MS` | `200` | while other requests decode, a new prompt fills in layer slices of about this many ms with a decode round between them; `0`: whole `FILL_ROWS` chunks, each pausing the other replies for its whole pass: about 1.3 s at the default 2,048 rows (about 0.65 s at 1,024). A request alone fills at full speed either way |+| `FILL_ROWS` | `2048` | rows of a prompt chunk that fills while other requests decode (`TF_GLM_FILL_ROWS`; TensorFold's default is 1,024): 2,048 is the whole prompt chunk, whose buffers already exist, so the same memory and the same replies in half the passes. Three Sparks, `PARALLEL=4`, a prompt filling beside a streaming reply: a warm +20k turn at 596k 15.6-15.7 -> 14.0-14.1 s, a cold 256k prompt 132.2-132.6 -> 113.4-114.0 s, the reply's gaps unchanged; at most `TF_GLM_PREFILL_ROWS` (the default follows a smaller one); `1024`: as before. With `FILL_BUDGET_MS=0` a fill chunk now pauses the other replies for about 1.3 s instead of about 0.65 s || `FILL_DRAFTS` | `1` | the rounds between those slices draft as usual (the other replies ~10 tokens/s each during a fill); `0`: one token a reply (the new prompt's first token sooner, the other replies slower while it fills) || `SERVED_NAME` / `PORT` / `HOST` | `GLM-5.3-Flash-EXL3` / `8888` / `0.0.0.0` | the model id in `/v1/models` and replies; where the API listens || `TENSORFOLD_GLM_IMAGE_TOKENS` / `_VIDEO_TOKENS` / `_VIDEO_FRAMES` | `2048` / `16384` / `128` | a picture's and a clip's token caps, and a clip's frames |diff --git a/scripts/config.sh b/scripts/config.shindex 68e6fd4..f034171 100644--- a/scripts/config.sh+++ b/scripts/config.sh@@ -261,14 +261,23 @@ export TF_GLM_MULTI_PREFILL="$MULTI_PREFILL"STREAM_SMOOTH="${STREAM_SMOOTH:-1}"STREAM_SMOOTH_MS="${STREAM_SMOOTH_MS:-400}"export TF_GLM_STREAM_SMOOTH="$STREAM_SMOOTH" TF_GLM_STREAM_SMOOTH_MS="$STREAM_SMOOTH_MS"-# Concurrent prompt fills in layer slices (patch 0062): while other requests decode, a new prompt's 1,024-row chunks+# Concurrent prompt fills in layer slices (patch 0062): while other requests decode, a new prompt's FILL_ROWS chunks# run a few layers at a time (about FILL_BUDGET_MS each) with a decode round between slices, instead of freezing the# other replies for a whole chunk. FILL_DRAFTS=1 (default): those rounds draft as usual (~3 tokens a stream);# 0: one token a stream (the new prompt's first token sooner, the others slower while it fills). FILL_BUDGET_MS=0:# whole chunks, as before. A request alone fills at full speed either way. Same replies.FILL_BUDGET_MS="${FILL_BUDGET_MS:-200}"FILL_DRAFTS="${FILL_DRAFTS:-1}"-export TF_GLM_FILL_BUDGET_MS="$FILL_BUDGET_MS" TF_GLM_FILL_DRAFTS="$FILL_DRAFTS"+# FILL_ROWS (TensorFold's TF_GLM_FILL_ROWS, whose own default is 1,024): the rows of such a fill's chunk. 2,048+# (default) is the whole prompt chunk (TF_GLM_PREFILL_ROWS, 2,048), whose buffers already exist: the same memory and+# the same replies (a token's result does not depend on the chunk it is filled in), half the passes over the weights.+# Three Sparks, PARALLEL=4, a prompt filling while another reply streams: a warm +20k turn on a 596k conversation+# 15.6-15.7 -> 14.0-14.1 s, a cold 256k prompt 132.2-132.6 -> 113.4-114.0 s; the streaming reply's gaps the same+# (max 25-67 ms either way). At most the prompt chunk (the engine refuses more): a smaller TF_GLM_PREFILL_ROWS lowers+# the default with it. 1024: as before.+_fill_max="${TF_GLM_PREFILL_ROWS:-2048}"+FILL_ROWS="${FILL_ROWS:-${TF_GLM_FILL_ROWS:-$(( _fill_max < 2048 ? _fill_max : 2048 ))}}"+export TF_GLM_FILL_BUDGET_MS="$FILL_BUDGET_MS" TF_GLM_FILL_DRAFTS="$FILL_DRAFTS" TF_GLM_FILL_ROWS="$FILL_ROWS"# L2 prefetch in decode windows (patch 0046, adapted from jayleaton/glm53-tensorfold-spark's patch 0460): a side stream# brings the weights the next kernels read into L2 during each layer's all-gathers. 1 (default): one request's prose# 48.36 -> 49.46 tok/s, code 59.54 -> 61.08 (two boots each). Same bits. 0: off.diff --git a/start.sh b/start.shindex cc7c3d2..70a1875 100755--- a/start.sh+++ b/start.sh@@ -19,8 +19,8 @@# Setup: WORKER=user@<worker address> in scripts/local.sh (key-based ssh).# Settings, from the environment, scripts/local.sh or ./.env (defaults and measured effects in scripts/config.sh):# serving CONTEXT, PARALLEL, KV, DENSE, DRAFTER, DRAFT_POLICY, COPY, COPY_MAX, COPY_CODE, SPLIT, KDA_CHUNKED,-# SHARED_PREFIX, MULTI_PREFILL, STREAM_SMOOTH, STREAM_SMOOTH_MS, FILL_BUDGET_MS, FILL_DRAFTS, KV_POOL_GIB,-# MEMORY_RESERVE_GIB, MAX_TOKENS, THINKING, VISION, VISION_URLS, COMM, SERVED_NAME, HOST, PORT+# SHARED_PREFIX, MULTI_PREFILL, STREAM_SMOOTH, STREAM_SMOOTH_MS, FILL_BUDGET_MS, FILL_DRAFTS, FILL_ROWS,+# KV_POOL_GIB, MEMORY_RESERVE_GIB, MAX_TOKENS, THINKING, VISION, VISION_URLS, COMM, SERVED_NAME, HOST, PORT# nodes WORKER, FABRIC_PEER, WORKER_HF_CACHE, MASTER_PORT, NCCL_RAILS (1: one RoCE device), NCCL_CHANNELS,# NCCL_DEBUG; TP (2), WORKER2, FABRIC_PEER2, WORKER_HF_CACHE2, MASTER_ADDR, SOCKET_IFNAME (3 Sparks)# files ABLIT (1: the gated Ablit weights, needs HF_TOKEN), MODEL_ID, MODEL_REVISION, DFLASH2_ID, DFLASH2_REVISION,diff --git a/tools/fill_rows_check.py b/tools/fill_rows_check.pynew file mode 100644index 0000000..752b006--- /dev/null+++ b/tools/fill_rows_check.py@@ -0,0 +1,102 @@+#!/usr/bin/env python3+"""tools/fill_rows_check.py <recipe checkout>: the FILL_ROWS setting, CPU only, in the image (the engine's code is+read and called, nothing runs on a GPU):++ docker run --rm --network none -e CUDA_VISIBLE_DEVICES= -v "$PWD:/recipe:ro" --entrypoint python3 \+ tensorfold-glm53:v0.6.0 /recipe/tools/fill_rows_check.py /recipe++1. Every rank gets it: scripts/config.sh exports TF_GLM_FILL_ROWS=2048 by default, takes FILL_ROWS or+ TF_GLM_FILL_ROWS from the environment, and lowers the default with a smaller TF_GLM_PREFILL_ROWS; start.sh's own+ env_args puts it in ENV_ARGS, which every rank's docker run gets.+2. The engine takes it: multi.fill_rows (what MultiDecoder reads) gives 2,048 against the engine's 2,048-row prompt+ chunk at every prompt grid, and refuses a fill chunk past the prompt chunk (the engine's own refusal at startup).+3. The same memory: the prompt chunk's buffers are sized by the prompt chunk's rows, and the fill rows size nothing:+ no read of fill_rows in the GLM CUDA family sits inside an allocation or a buffer's construction, and a chunk run+ refuses more rows than the prompt chunk.+Prints PASS / FAIL lines and ALL PASS; exit 1 on any FAIL."""+import ast+import os+import pathlib+import re+import subprocess+import sys++import tensorfold.families.glm5_next.cuda as glm+from tensorfold.families.glm5_next.cuda import decode, engine, multi++recipe = pathlib.Path(sys.argv[1]).resolve()+fails = 0+++def check(name, ok):+ global fails+ print(("PASS " if ok else "FAIL ") + name, flush=True)+ fails += not ok+++# 1. every rank gets it+start = (recipe / "start.sh").read_text()+m = re.search(r"^env_args\(\) \{\n.*?^\}\n", start, re.S | re.M)+check("start.sh defines env_args", m is not None)+check("every rank's docker run takes ENV_ARGS (the workers' and rank 0's)", start.count('"${ENV_ARGS[@]}"') >= 2)+++def forwarded(env, tp="3"):+ """TF_GLM_FILL_ROWS as start.sh's env_args passes it to the ranks, after scripts/config.sh, in a clean env."""+ script = (f"cd {recipe} && source scripts/config.sh >/dev/null 2>&1; TP={tp}\n"+ + (m.group(0) if m else "env_args() { ENV_ARGS=(); }\n")+ + 'env_args\nfor a in "${ENV_ARGS[@]}"; do [[ "$a" == TF_GLM_FILL_ROWS=* ]] && echo "${a#*=}"; done\n')+ base = {"PATH": os.environ.get("PATH", "/usr/bin:/bin"), "HOME": "/nonexistent"}+ out = subprocess.run(["bash", "-c", script], env={**base, **env}, capture_output=True, text=True, timeout=60)+ return out.stdout.split()+++for env, want, what in (({}, ["2048"], "by default"), ({"FILL_ROWS": "1024"}, ["1024"], "FILL_ROWS=1024"),+ ({"TF_GLM_FILL_ROWS": "512"}, ["512"], "TF_GLM_FILL_ROWS=512"),+ ({"TF_GLM_PREFILL_ROWS": "1024"}, ["1024"], "TF_GLM_PREFILL_ROWS=1024 (the default follows)"),+ ({"TF_GLM_PREFILL_ROWS": "4096"}, ["2048"], "TF_GLM_PREFILL_ROWS=4096")):+ got = forwarded(env)+ check(f"{what}: every rank gets TF_GLM_FILL_ROWS={want} (got {got})", got == want)+check("two Sparks too (TP=2)", forwarded({}, tp="2") == ["2048"])++# 2. the engine takes it+check(f"the engine's prompt chunk is 2,048 rows (decode.PREFILL_ROWS {decode.PREFILL_ROWS})", decode.PREFILL_ROWS == 2048)+check("TensorFold's own default is 1,024 (what the recipe changes)", multi.fill_rows(2048, 0, "") == 1024)+grids = (0,) + tuple(engine.GRIDS)+check(f"2,048 is taken at every prompt grid {grids}", all(multi.fill_rows(2048, g, "2048") == 2048 for g in grids))+try:+ multi.fill_rows(1024, 0, "2048")+ refused = False+except ValueError:+ refused = True+check("a fill chunk past the prompt chunk is refused at startup (TF_GLM_FILL_ROWS=2048, 1,024-row chunks)", refused)++# 3. the same memory+files = sorted(pathlib.Path(glm.__file__).parent.glob("*.py"))+ALLOC = {"empty", "zeros", "ones", "full", "empty_like", "zeros_like", "Buffers", "reserve", "alloc", "allocate",+ "buffer_rows", "index_ring", "mla_geometry", "CUDAGraph"}+reads, sized = 0, []+for f in files:+ tree = ast.parse(f.read_text())+ parents = {c: p for p in ast.walk(tree) for c in ast.iter_child_nodes(p)}+ for n in ast.walk(tree):+ if not (isinstance(n, ast.Attribute) and n.attr == "fill_rows" and isinstance(n.ctx, ast.Load)):+ continue+ reads += 1+ p = n+ while p in parents:+ p = parents[p]+ if isinstance(p, ast.Call):+ fn = p.func.attr if isinstance(p.func, ast.Attribute) else getattr(p.func, "id", "")+ if fn in ALLOC:+ sized.append(f"{f.name}:{n.lineno} in {fn}()")+check(f"the fill rows size no buffer ({reads} reads in {len(files)} files; inside an allocation: {sized})",+ reads > 0 and not sized)+src = (pathlib.Path(decode.__file__)).read_text()+check("the prompt chunk's buffers are sized by the prompt chunk's rows (Buffers(w, prefill_rows, ..., prefill=True))",+ "self.pbuf = Buffers(w, prefill_rows, capacity, prefill=True" in src)+msrc = pathlib.Path(multi.__file__).read_text()+check("a chunk run refuses more rows than the prompt chunk (multi.py: stop - start > e.prefill_rows)",+ msrc.count("stop - start > e.prefill_rows") >= 2)+print("ALL PASS" if not fails else f"{fails} FAIL", flush=True)+sys.exit(1 if fails else 0)