Skip to content

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

Python

PR #95: patch 0090, its own variable TF_GLM_EXL3_DEC_ORDER (0020 keeps TF_GLM_EXL3_ORDER), config.sh, start.sh check, README, CHANGELOG, CREDITS

MiaAI-Lab1ec05c892634
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9d49650..b3aaa6c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,12 @@ Every change to this recipe, newest first. Each release names the image it serve
counts it. Paraphrase loops still need `--thinking-budget`. CPU test: `tools/test_loop_guard.py`.
- **The start's smoke test fails on one repeated character** (#76, #81, #86): a collapsed model that answers "!!!!" no
longer passes as OK.
+- **Expert decode launch order** (patch `0090-glm-expert-launch-order`, by Lukasz Raczylo, @lukaszraczylo, PR #95):
+ `TF_GLM_EXL3_DEC_ORDER=1` (or `2`) maps the decode expert kernel's block grid so that the eight 128-column blocks of
+ one k slice run together and read contiguous memory; the same bits for every value. Off by default (`0`, the old
+ order). His run: one request +2.2%, four at once noisy. The patch's variable is its own: his `TF_GLM_EXL3_ORDER` is
+ patch `0020`'s prompt order (default on, any value but `0`), so `true` would have raised and `1` would have turned
+ the new order on for existing users.
- **Long-context decode** (patch `0085-glm-select-split-loop`): the DSA indexer's split top-k selection
(`select_split`, in `0029`'s segmented decode windows) ran its last pass as one `CP x 256` tile per chunk program,
masked to the chunks before it. `CP` comes from the selection scratch, which `verify.py` sizes for the whole KV
diff --git a/CREDITS.md b/CREDITS.md
index da9f0b5..5f1fdea 100644
--- a/CREDITS.md
+++ b/CREDITS.md
@@ -132,6 +132,9 @@ checkpoint's ShapleyMcg attribution and the drafter's license).
[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.
+- `0090-glm-expert-launch-order` (`TF_GLM_EXL3_DEC_ORDER`: the launch order of the expert decode kernel's blocks): by
+ Lukasz Raczylo ([lukaszraczylo](https://github.com/lukaszraczylo)), in
+ [PR #95](https://github.com/MiaAI-Lab/GLM-5.3-Flash-EXL3-2x-DGX-Sparks-TensorFold/pull/95).
- 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 7fc3112..dc0934d 100644
--- a/README.md
+++ b/README.md
@@ -477,6 +477,7 @@ sets a value wins: the environment, then `scripts/local.sh`, then `.env`, then t
| `KDA_CHUNKED` | `1` | KDA prompt chunks in chunked (WY) form, one CUDA kernel |
| `TF_GLM_L2PF` | `1` | L2 prefetch in decode: the weights the next kernels read brought into L2 during each layer's all-gathers; `0`: off |
| `TF_GLM_EXL3_LOADS` | `nc` | the decode expert kernel's trellis as 16-byte non-coherent loads a step ahead (`nc2` / `nc4`: 2 or 4 steps); `0`: TensorFold's 32-bit loads |
+| `TF_GLM_EXL3_DEC_ORDER` | `0` | the decode expert kernel's block launch order (patch 0090): `1` runs the eight 128-column blocks of one k slice together, then the items; `2` then the matrices and splits; `0`: as launched. The same bits. Not `TF_GLM_EXL3_ORDER`, which is patch 0020's prompt order |
| `TF_ROCE_MAX_KB` | `512` | the largest all-gather (KiB) sent over RoCE with `COMM=roce` (TensorFold's default: 256); 512 covers the 17-32-row verify windows of concurrent requests |
| `TF_ROCE_WAIT_S` | `300` | seconds a RoCE all-gather waits for the other Spark before it fails (1 to 3600; the patch's own default is 20, which a late peer on long prompts outlasted, issue #54); until the engine is built, each gather first meets the peer in an NCCL barrier, so a long first start (kernels compiling) does not run into it |
| `TF_GLM_MULTI_WINDOW` | `32`, `64` past 4 requests | with `PARALLEL` above 1, the rows of every request's verify window together in a round (16 to 64 in steps of 8): with more requests at once each one's drafts get fewer of them (8 requests' code: 141.2 / 160.3 / 167.0 tok/s at 32 / 48 / 64 rows); past 32 rows `TF_ROCE_MAX_KB` rises with it (64: 1024) unless you set it. Exact at any size |
@@ -586,6 +587,7 @@ applied with `patch -p0` in filename order); `start.sh` rebuilds or re-pulls the
| Prompt reuse | `0008-glm-prompt-grid`, `0015-glm-shared-prefix`, `0042-glm-prompt-replay`, `0054-glm-image-prompt-reuse`, `0060-glm-keep-thinking`, `0063-glm-kept-cap-superseded-first`, `0071-glm-shared-prefix-copy`, `0077-glm-kept-cap-shared-by-recency`, `0078-glm-take-over-decide-then-copy` | prompt chunks and kept states on a token grid; a shared system prompt's state reused (copied out of the conversation that wrote it, which keeps its own state, by ezoushen, #43); an identical prompt resumes from its kept end state; prompts with pictures resume too, their kept states told apart by each picture's content (by abhicnv007, issue #11); earlier turns' reasoning kept in the prompt (`TF_GLM_CLEAR_THINKING`, by kky42, #23); past the kept-state cap a conversation's superseded states go first (by Alexbob0, #32), and shared-prefix states by recency only, so a new agent run still finds its system prompt (diagnosed and the fix proposed by meleesciony, #75); a fresh conversation after a long one clones only the kept states that stay, not every one first (reserved +14.8 -> +1.4 GiB after 256k, 21 turns; upstream #421) | [Performance](#performance) |
| Decode | `0013-glm-decode-rounds`, `0016-glm-decode-kernels`, `0019-glm-decode-kernels2`, `0031-glm-decode-index-regs` | verify windows of up to 16 rows; faster decode matmuls, hyper-connection mixing and indexer scoring | faster decode rounds; long copy drafts (`COPY_MAX` 15: edit replies 84 -> 119 tok/s) |
| Decode, memory | `0046-glm-l2-prefetch`, `0047-glm-exl3-decode-loads` | the next kernels' weights prefetched into L2 during each layer's all-gathers (`TF_GLM_L2PF`, adapted from jayleaton/glm53-tensorfold-spark's patch 0460); the routed experts' trellis as 16-byte non-coherent loads a step ahead (`TF_GLM_EXL3_LOADS`, adapted from its patch 0580) | with `TF_ROCE_MAX_KB=512`: one request's prose 48.36 -> 49.68 tok/s, code 59.54 -> 61.49 (+2.7% / +3.3%); 4 at once prose 74.8 -> 76.6, code 100.0 -> 102.7 (two starts each); the same bits |
+| Decode, memory | `0090-glm-expert-launch-order` | the decode expert kernel's blocks launched so that the eight 128-column blocks of one k slice run together and read contiguous memory (`TF_GLM_EXL3_DEC_ORDER=1` or `2`; default `0`, the old order), by lukaszraczylo | his run: one request +2.2% tok/s (4 at once noisy); the same bits for every value; not yet measured here |
| Decode, indexer | `0043-glm-visible-pools` | a decode row's token scoring and split selection bounded to the pools it can see (TensorFold v0.6.0 bounds its one-program selection, PR #140) | the same tokens |
| Decode, indexer | `0085-glm-select-split-loop` | the split selection's last pass sums the histograms of the chunks before its own, 16 at a time (`SPLIT_BLK`), instead of loading the row's whole chunk table masked to them: that table is the selection scratch's, sized for the pool (512 chunks a row at `PARALLEL=4` on three Sparks), not the row's context | one request at 226k: the selection 5.79 -> 0.28 ms a layer (11 a round); the same tokens |
| Link | `0006-cuda-roce-allgather`, `0052-cuda-roce-startup` | the small all-gathers as one-shot RDMA writes over RoCE (`COMM=roce`; up to 512 KiB, `TF_ROCE_MAX_KB`: code at 4 streams +1.4%); until the engine is built, each eager gather first waits for the peer in an NCCL barrier, and the RoCE kernel builds during setup (`TF_ROCE_WAIT_S`, 300 s here; errors print the proxy's counters); an idle rank 1 waiting on a socket is TensorFold v0.6.0's (#132) | 11 us a 16 KiB gather against NCCL's 45, decode +6%; an idle server holds no GPU or CPU core; a first start whose ranks drift apart while building kernels no longer fails |
diff --git a/patches/0084-glm-expert-launch-order.patch b/patches/0090-glm-expert-launch-order.patch
similarity index 96%
rename from patches/0084-glm-expert-launch-order.patch
rename to patches/0090-glm-expert-launch-order.patch
index 3d67de8..4265d23 100644
--- a/patches/0084-glm-expert-launch-order.patch
+++ b/patches/0090-glm-expert-launch-order.patch
@@ -97,13 +97,13 @@ index 2bc0b6b..be27418 100644
+def dec_order() -> int:
-+ """TF_GLM_EXL3_ORDER: the decode kernel's block launch order (the same bits for every value). ``0`` (default):
++ """TF_GLM_EXL3_DEC_ORDER: the decode kernel's block launch order (the same bits for every value). ``0`` (default):
+ items fastest; ``1`` / ``2``: the 128-column blocks of one k slice first, then the items (1) or the matrices and
+ splits (2)."""
+
-+ v = os.environ.get("TF_GLM_EXL3_ORDER", "0").strip()
++ v = os.environ.get("TF_GLM_EXL3_DEC_ORDER", "0").strip()
+ if v not in ("0", "1", "2"):
-+ raise ValueError(f"TF_GLM_EXL3_ORDER: 0, 1 or 2, not {v!r}")
++ raise ValueError(f"TF_GLM_EXL3_DEC_ORDER: 0, 1 or 2, not {v!r}")
+ return int(v)
+
+
diff --git a/scripts/config.sh b/scripts/config.sh
index ce5f55f..cae8f8a 100644
--- a/scripts/config.sh
+++ b/scripts/config.sh
@@ -246,6 +246,11 @@ export TF_GLM_L2PF="${TF_GLM_L2PF:-1}"
# Together with TF_GLM_L2PF=1 and TF_ROCE_MAX_KB=512: one request's prose 49.68, code 61.49 (+2.7% / +3.3%); 4 at once
# prose 74.8 -> 76.6, code 100.0 -> 102.7 tok/s in all (two boots each). Same bits. 0: TensorFold's 32-bit loads.
export TF_GLM_EXL3_LOADS="${TF_GLM_EXL3_LOADS:-nc}"
+# The decode expert kernel's block launch order (patch 0090, by lukaszraczylo): 0 (default) the grid as launched, items
+# fastest; 1: the eight 128-column blocks of one k slice run together (contiguous trellis reads), then the items; 2: then
+# the matrices and splits. The same bits for every value; his single-stream gain for 1 is +2.2%, one tester, not yet
+# measured here. Not TF_GLM_EXL3_ORDER, which is patch 0020's prompt order (default on).
+export TF_GLM_EXL3_DEC_ORDER="${TF_GLM_EXL3_DEC_ORDER:-0}"
# Conversations that share a system prompt reuse its prompt state (patch 0015): a 7.9k-token system prompt's second and
# later chats prefill in 0.13 s instead of 4.24 s. Same replies. SHARED_PREFIX=0 turns it off.
SHARED_PREFIX="${SHARED_PREFIX:-1}"
diff --git a/start.sh b/start.sh
index 2d34a3b..12ce245 100755
--- a/start.sh
+++ b/start.sh
@@ -98,6 +98,7 @@ DRY=0; [[ "${DRY_RUN:-0}" == 1 ]] && DRY=1
[[ "$TF_GLM_CLEAR_THINKING" =~ ^[01]$ ]] || die "TF_GLM_CLEAR_THINKING is 0 or 1, not $TF_GLM_CLEAR_THINKING"
[[ "$TF_GLM_L2PF" =~ ^(0|off|1|bulk|lines|touch)$ ]] || die "TF_GLM_L2PF is 0, 1 (bulk), lines or touch, not $TF_GLM_L2PF"
[[ "$TF_GLM_EXL3_LOADS" =~ ^(0|ldg|1|nc|nc1|nc2|nc4)$ ]] || die "TF_GLM_EXL3_LOADS is 0, nc, nc2 or nc4, not $TF_GLM_EXL3_LOADS"
+[[ "$TF_GLM_EXL3_DEC_ORDER" =~ ^[012]$ ]] || die "TF_GLM_EXL3_DEC_ORDER is 0, 1 or 2, not $TF_GLM_EXL3_DEC_ORDER"
[[ "$TF_ROCE_MAX_KB" =~ ^[1-9][0-9]*$ ]] || die "TF_ROCE_MAX_KB is a size in KiB (512: up to 32-row windows over RoCE), not $TF_ROCE_MAX_KB"
if [[ "$THINKING" == 1 ]]; then SERVE_ARGS+=(--thinking); else SERVE_ARGS+=(--no-thinking); fi
[[ "$VISION" == 1 ]] && SERVE_ARGS+=(--vision)