Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
feat(glm53): make the whitespace rewind opt-in
eni1ba5b09ef10f
diff --git a/c/glm53.c b/c/glm53.cindex 89267bf4..4101351f 100644--- a/c/glm53.c+++ b/c/glm53.c@@ -3568,12 +3568,13 @@ static int serve_one(GModel *m, Tok *tokenizer, ServeReq *q) {else if (q->pin)fprintf(stderr, "[PIN] stato fotografato a %d token\n", total);GSession *session = slot->session;- /* GLM53_REWIND=0 spegne lo scatto della corsa di spazi, che costa un- * buffer grande quanto lo stato KDA (~149 MiB) e una sua copia per ogni- * corsa, non per ogni token. */+ /* GLM53_REWIND=1 accende lo scatto della corsa di spazi, che costa un+ * buffer grande quanto lo stato KDA (~149 MiB, fuori da GLM53_EXPERT_GB)+ * e una sua copia per ogni corsa, non per ogni token. Spento di+ * default: lo pagherebbe ogni risposta, anche di chi non fa mai Continue. */const char *rewind_setting = getenv("GLM53_REWIND");const int keep_blank = q->logprobs == 0 && n_vision == 0 &&- !(rewind_setting && !strcmp(rewind_setting, "0"));+ rewind_setting && atoi(rewind_setting);int in_blank = 0;for (int step = 0; step < budget; step++) {/* #1332: una guardata a stdin per token. Il costo e' una select condiff --git a/c/tests/glm53_serve_harness.py b/c/tests/glm53_serve_harness.pyindex 0ae10f78..4522a6c5 100644--- a/c/tests/glm53_serve_harness.py+++ b/c/tests/glm53_serve_harness.py@@ -532,7 +532,7 @@ def main() -> int:blank_prompt, kept, k = foundtrimmed = blank_prompt + b"".join(kept)for fed, first in ((1, 40), (2, 44)):- rewound = engine(binary, arguments.fixture)+ rewound = engine(binary, arguments.fixture, {"GLM53_REWIND": "1"})try:handshake(rewound)submit_bytes(rewound, first, blank_prompt, max_tokens=k + fed + 1)@@ -559,8 +559,9 @@ def main() -> int:print(f"FAIL: riavvolto di {fed} spazi, il Continue risponde "f"{from_rewind!r} e un motore appena partito no")return 1- # Lo stesso con GLM53_REWIND=0: niente scatto, prefill da capo.- unwound = engine(binary, arguments.fixture, {"GLM53_REWIND": "0"})+ # Lo stesso senza GLM53_REWIND, cioe' il default: niente scatto, prefill+ # da capo.+ unwound = engine(binary, arguments.fixture)try:handshake(unwound)submit_bytes(unwound, 42, blank_prompt, max_tokens=k + 2)@@ -573,7 +574,7 @@ def main() -> int:if unwound.poll() is None:unwound.kill()if reuse_line(43)[2] != "0":- print(f"FAIL: con GLM53_REWIND=0 il Continue non doveva riusare: "+ print(f"FAIL: senza GLM53_REWIND il Continue non doveva riusare: "f"{reuse_line(43)!r}")return 1diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.mdindex 527ebbc0..1dff8326 100644--- a/docs/ENVIRONMENT.md+++ b/docs/ENVIRONMENT.md@@ -358,7 +358,7 @@ See `docs/glm53-flash.md`.| `GLM53_EXPERT_GB` | measured | RAM budget (GB) for the expert LRU cache; per-layer slots are derived from it. Unset, it is taken from reclaimable physical memory after the weights are loaded (Linux `MemAvailable`, Windows available physical memory, macOS free+inactive+purgeable pages), minus a 3 GB margin. A fixed number is wrong in both directions: too small on a large machine leaves memory idle while the disk does all the work. || `GLM53_MAXT` | `8192` | KV state capacity in tokens, and the session size in serve mode. || `GLM53_PREFILL_CHUNK` | `128` | Prefill chunk size in tokens. Smaller keeps the workspace smaller; too small re-reads experts once per chunk per layer instead of amortizing them. In serve mode, CANCEL is checked before each prefill chunk. Cancellation waits for any chunk already running to finish. |-| `GLM53_REWIND` | on | Avoid reprocessing the prompt when a continue request trims cached trailing whitespace. Rewinding recurrent state requires a snapshot (~149 MiB per slot), allocated on first use, retained across slot resets, and copied once per generated whitespace run. Set `0` to disable; exact-match continuations need no snapshot and still reuse the cache. |+| `GLM53_REWIND` | `0` | Avoid reprocessing the prompt when a continue request trims cached trailing whitespace, by rewinding recurrent state with a snapshot (~149 MiB per slot, outside the `GLM53_EXPERT_GB` budget), allocated on first use, retained across slot resets, and copied once per generated whitespace run, whether or not the reply is ever continued. Off by default for that reason; exact-match continuations need no snapshot and reuse the cache either way. || `GLM53_MAX_IMAGE_TOKENS` | checkpoint's (8000) | Ceiling on tokens per image. Each covers 28×28 pixels, so 256 keeps ordinary text legible and 64 keeps shapes and colours. The image is shrunk, not cropped. Lower it: 8000 is 2691 tokens for a 1080p photo, i.e. a prefill nobody will sit through. || `GLM53_VERBOSE` | unset | Print the parsed geometry, the expert budget and the per-token cache cost to stderr. || `GLM53_DUMP_INDEX` | unset | Print the rows the sparse indexer selected. The first place to look when the engine diverges only at certain lengths. |