GLM-5.3-Flash EXL3 on 2x DGX Spark with TensorFold
Python
0077: shared-prefix states go by recency, never as superseded (#75, by @meleesciony)
MiaAI-Lab742a2cc7064c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a019014..6af426b 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++Image: not published yet; `prepare.sh` builds it locally from the 76 patches (the patches' hash no longer matches the+pinned `v0.6.0-c4cab25d2d36` until a new image is published and pinned).++### Fixed+- **#75, a new run of an agent no longer resumed its system prompt once the kept cap was full** (patch+ `0077-glm-kept-cap-shared-by-recency`; diagnosed, and the fix proposed, by @meleesciony). Since `0071` every run and+ every cold start keeps its states in an extent of its own, and `0063` never dropped an extent's latest state while+ anything superseded was kept anywhere. Within hours of a start every entry was some conversation's latest state; a+ new run's system-block state was then the only superseded entry and went at its next kept state, so the next run of+ the same agent read its whole prompt again (first token 14 s -> 40 s on 42-49k-token prompts; 15 of 16 runs cold).+ Shared-prefix states now go by recency only, beside the other conversations' latest states; a conversation's earlier+ states still go first. A larger `TF_GLM_CACHE_ENTRIES` now helps too (before, it only delayed this). Same replies.+## v1.7 (2026-10-05): the Ablit weights (`ABLIT=1`, gated: needs `HF_TOKEN`)Image: `v0.6.0-c4cab25d2d36` (`sha256:b47c19d66633f27cbe37da13fbc580363f466c08b9529feab1eecb1a4b904bf1`), 75 patches, for two and three Sparks (unchanged from v1.6).diff --git a/README.md b/README.mdindex 05eb1c0..d5b6af6 100644--- a/README.md+++ b/README.md@@ -474,7 +474,7 @@ sets a value wins: the environment, then `scripts/local.sh`, then `.env`, then t| `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 || `TF_GLM_MULTI_LONE` | `0` | `1`: with `PARALLEL` above 1, a request decoding alone runs on the one-stream graphs (+0.6-0.9%), but its move to the pool's first rows evicts other conversations' kept prompts there (issues #12, #13); `0`: on the batched ones |-| `TF_GLM_CACHE_ENTRIES` | `32` | kept prompt states at most (TensorFold's default is 8); past this count a conversation's earlier (superseded) states go first, then the least recently used, however much of the pool is free (patch `0063`, @Alexbob0). An agent request keeps 1 to 3 (issue #17); each costs ~45 MiB at start |+| `TF_GLM_CACHE_ENTRIES` | `32` | kept prompt states at most (TensorFold's default is 8); past this count a conversation's earlier (superseded) states go first, then the least recently used, however much of the pool is free (patch `0063`, @Alexbob0); shared-prefix states (a system block) go by recency only, so a new run of an agent still finds its system prompt (patch `0077`, issue #75, @meleesciony). An agent request keeps 1 to 3 (issue #17); each costs ~45 MiB at start || `TF_GLM_MULTI_WATCHDOG_S` / `TF_GLM_MULTI_WATCHDOG_EXIT` | `300` / `0` | a rank stuck this many seconds in one step prints every thread's stack to its log (`/health`'s `iteration_s` shows how long the current step has run); `EXIT=1`: the server then exits (code 1) instead of waiting, so a supervisor can restart it. Both ranks also check that they received the same message each step, and stop with an error naming it if not || `TF_GLM_CLEAR_THINKING` | `0` | `1`: drop earlier turns' reasoning from the prompt, as the checkpoint's template does (agents then prefill the previous turn's tool loop again); a request's `chat_template_kwargs.clear_thinking` wins || `MULTI_PREFILL` | `1` | prompts that arrive together are filled in one forward (each with the bits it gets alone); `0`: one after another |diff --git a/patches/0077-glm-kept-cap-shared-by-recency.patch b/patches/0077-glm-kept-cap-shared-by-recency.patchnew file mode 100644index 0000000..1a8eab2--- /dev/null+++ b/patches/0077-glm-kept-cap-shared-by-recency.patch@@ -0,0 +1,42 @@+# Kept prompt cap: a shared-prefix state (a system block, where prompts stop sharing) is no longer dropped as superseded+# by its writer's own longer state; it goes by recency only. Since 0071 every run and every cold start keeps its states+# in an extent of its own, whose latest state is never superseded, so past TF_GLM_CACHE_ENTRIES the cap filled with+# conversations' latest states within hours of a start; from then on a new run's system-block state was the only+# superseded entry and went at its next kept state, and the next run of that agent read its whole prompt again (first+# token 14 s -> 40 s). A larger cap only delayed it. A conversation's earlier non-shared states still go first (0063),+# then the least recently used of any. Same replies: which state is kept only. Issue #75, diagnosed and the fix+# proposed by @meleesciony.++diff --git tensorfold/families/glm5_next/cuda/multi.py tensorfold/families/glm5_next/cuda/multi.py+index 0b743b7..75d50b4 100644+--- tensorfold/families/glm5_next/cuda/multi.py++++ tensorfold/families/glm5_next/cuda/multi.py+@@ -179,19 +179,20 @@ def fill_share(value: str | None = None) -> float:+ def cap_victim(kept: list):+ """The kept prompt to drop past TF_GLM_CACHE_ENTRIES (``kept``: least recently used first). An extent's kept+ prompts are prefixes of its rows, so one shorter than another in its extent is an earlier point of that+- conversation, superseded by the longer one: those go first (the oldest that is not a shared-prefix state, then+- the oldest of any), then the least recently used. A conversation taking many turns thus drops its own earlier+- turns instead of the only state of a conversation that is waiting on a long reply. Deterministic in ``kept``'s+- order and extents, so both ranks drop the same one."""++ conversation, superseded by the longer one: the oldest of those goes first, then the least recently used of any.++ A conversation taking many turns thus drops its own earlier turns instead of the only state of a conversation++ that is waiting on a long reply. A shared-prefix state (a system block, where prompts stop sharing) is never++ dropped as superseded: it is what the next conversation or run with that prefix resumes from, and its writer's++ longer state cannot serve them, so it goes by recency only, with the other conversations' latest states.++ Deterministic in ``kept``'s order and extents, so both ranks drop the same one."""++ longest: dict[int, int] = {}+ for c in kept:+ longest[id(c.extent)] = max(longest.get(id(c.extent), 0), len(c.ids))+- superseded = [c for c in kept if len(c.ids) < longest[id(c.extent)]]+- for c in superseded:+- if not getattr(c, "shared", False):++ for c in kept:++ if len(c.ids) < longest[id(c.extent)] and not getattr(c, "shared", False):+ return c+- return superseded[0] if superseded else kept[0]++ return kept[0]+++ def multi_code(code: list[int], dflash: bool, dflash_policy: list[int]) -> list[int]: