GLM-5.3-Flash EXL3 on 2x DGX Spark with TensorFold
Python
0097 docs: the measured per-state cost (~91 MiB) and budget (~7.5 GiB) on two Sparks, not the estimate
MiaAI-Lab3a8e913daff2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 433a221..c54c81b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -22,10 +22,11 @@ Every change to this recipe, newest first. Each release names the image it serveswitches. CPU test: `tools/test_effort_tail.py` (`--source-root` the patched `src`; `--expect-stock` shows thedifference on the unpatched source).- **Kept-state count follows a share of the pool** (patch `0097-glm-kept-entries-share`, issue #84, diagnosed by- @jdecker76): `TF_GLM_CACHE_ENTRIES` (32) is a count, but each kept state is a reservation of ~45 MiB (KDA recurrent+ @jdecker76): `TF_GLM_CACHE_ENTRIES` (32) is a count, but each kept state is a reservation (~91 MiB measured on two Sparks; KDA recurrentstate, conv window, DFlash2 window copy; flat in the context length) taken from the pool's budget, so finishedone-shot conversations pushed live ones out with millions of pool tokens free. `TF_GLM_CACHE_SHARE_PCT` (default 0:- off) makes the count at least that share of the budget (25: 71 states); the same count sizes the reservation, so the+ off) makes the count at least that share of the budget (on two Sparks at the defaults the budget is ~7.5 GiB and 32 states already take ~38%, so+ 50 gives ~42 states and the 75% ceiling ~63); the same count sizes the reservation, so thestart-up estimate is unchanged and the pool shrinks by it. Any count is cut to three quarters of the budget, logged(past it the states would own memory the estimate never counted). Every admission also rebuilt an int64 array ofevery kept state's ids to find shared prefixes (112 ms for 32 states of 200k tokens): built once per state now.diff --git a/README.md b/README.mdindex bff6a76..b2bcc02 100644--- a/README.md+++ b/README.md@@ -523,7 +523,7 @@ sets a value wins: the environment, then `scripts/local.sh`, then `.env`, then t| `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); 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, reserved out of the pool's `KV_POOL_GIB` budget (the pool shrinks by it, the estimate does not change), flat in the context length. Symptom of too few: `/health` `kept_prompts` stuck at the count while `pool_free_tokens` is large (issue #84, @jdecker76); see `TF_GLM_CACHE_SHARE_PCT` |-| `TF_GLM_CACHE_SHARE_PCT` | `0` (off) | make the kept-state count at least this share of the `KV_POOL_GIB` budget (patch `0097`, issue #84 by @jdecker76): `25` is 71 states of ~45 MiB (~3.1 GiB, ~25% fewer pool tokens), so the pool's tokens, not 32 finished one-shot conversations, decide when a live conversation goes. Any count is cut to three quarters of the budget (logged at start): past that the reservation would exceed the estimate. Set the same on every Spark |+| `TF_GLM_CACHE_SHARE_PCT` | `0` (off) | make the kept-state count at least this share of the `KV_POOL_GIB` budget (patch `0097`, issue #84 by @jdecker76): on two Sparks at the defaults each state reserves ~91 MiB of a ~7.5 GiB budget, so 32 states already take ~38%: `50` gives ~42 states, the ceiling ~63 (each costs pool tokens), so the pool's tokens, not 32 finished one-shot conversations, decide when a live conversation goes. Any count is cut to three quarters of the budget (logged at start): past that the reservation would exceed the estimate. Set the same on every Spark || `TF_GLM_KEPT_BYTES_GIB` | `0` (no cap) | a byte budget for the kept states together (patch `0089`, by Thomas Wade, [ThomasWadeZ](https://github.com/ThomasWadeZ), PR #65): the device memory they own outside the pool (recurrent state, DFlash2 window copies: hundreds of MB each with long contexts); past it states are dropped in the entry cap's order (not written to the spill tier) and freed blocks go back to the driver. The author runs `4`; `kept_bytes` / `kept_bytes_cap` in `/health` || `TF_GLM_KEEP_PER_CHAT` | `0` (no limit) | at most this many of one conversation's own turn-boundary kept states (patch `0089`, PR #65); shared-prefix and mid-prefill states do not count, the older turns are dropped without a spill. The author runs `2`; `kept_mix` in `/health` shows each conversation's count || `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 |diff --git a/scripts/config.sh b/scripts/config.shindex e6af9e6..7a8c6eb 100644--- a/scripts/config.sh+++ b/scripts/config.sh@@ -208,9 +208,10 @@ fi# start: 32 takes ~1 GiB more than 8.export TF_GLM_CACHE_ENTRIES="${TF_GLM_CACHE_ENTRIES:-32}"# TF_GLM_CACHE_SHARE_PCT (patch 0097, off by default; issue #84 by @jdecker76): the count above is also a memory-# reservation (the pool shrinks by ~45 MiB an entry; the estimate is unchanged), so a pool with millions of free tokens+# reservation (the pool shrinks by each entry's fixed state, ~91 MiB measured on two Sparks at the defaults; the+# estimate is unchanged), so a pool with millions of free tokens# can still evict a live conversation at the 33rd state. A share makes the count at least that part of KV_POOL_GIB's-# budget: 25 is 71 states, ~3.1 GiB of the 12.5. Any count is cut to 75% of the budget, logged at start. Watch+# budget (~7.5 GiB on two Sparks at the defaults, where 32 states already take ~38%: 50 is ~42 states, 75 ~63). Any count is cut to 75% of the budget, logged at start. Watch# /health kept_prompts against pool_free_tokens: kept_prompts pinned at the count with a free pool is this symptom.export TF_GLM_CACHE_SHARE_PCT="${TF_GLM_CACHE_SHARE_PCT:-0}"# Two more limits on the kept states (patch 0089, both off by default; PR #65 by Thomas Wade): TF_GLM_KEPT_BYTES_GIB