Skip to content

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

Python
25.6 KB
Raw Blame

Credits

This repository is a thin layer of scripts and patches. Almost everything that makes it work was built by others. Its own work is licensed under the Apache License 2.0 (LICENSE); NOTICE carries the third-party notices that go with it (TensorFold's MIT and Apache-2.0 notices, b12x, glm53-tensorfold-spark, the checkpoint's ShapleyMcg attribution and the drafter's license).

Model

  • GLM-5.3-Flash by Z.ai: the model's design, training and evaluations. Its license, on the model card, governs any use of the weights. The weights are not part of this repository; scripts/prepare.sh downloads them from Hugging Face.

  • Mia's AI Lab: the default checkpoint since v1.3.3, Mia-AiLab/GLM-5.3-Flash-EXL3-4bpw-TensorFold (Apache-2.0), made with exllamav3 by turboderp (MIT).

  • brandonmusic: the default checkpoint before v1.3.3, still selectable with MODEL_ID: the EXL3 4-bit quantization, brandonmusic/GLM-5.3-Flash-tr3-4bpw, served here from its mirror Mia-AiLab/GLM-5.3-Flash-EXL3-TR3-4bpw (a byte-identical copy), made with ShapleyMcg by Brandon M. Music under the ShapleyMcg License 1.0 (attribution required; the checkpoint's LICENSE file has the terms). Its attribution notice:

    This work includes or was produced using ShapleyMcg, created by Brandon M. Music (https://github.com/brandonmmusic-max/shapleymcg). ShapleyMcg is licensed under the ShapleyMcg License v1.0, an attribution-required license that grants no rights to the person known as "0xSero." Use of ShapleyMcg without this attribution is unlicensed.

  • IncoAI: the DFlash2 drafter, incoai/GLM-5.3-Flash-DFlash2 (CC BY-NC-ND 4.0: non-commercial use, no derivatives). Downloaded from its source, never redistributed here.

Inference engine

  • TensorFold by Ash Hart (ashhart) and the TensorFold contributors (Apache 2.0 from v0.6.0; releases up to v0.5.0 were MIT, and code written before v0.6.0 keeps its MIT notice): the engine that serves the model, including the two-rank CUDA engine for GLM-5.3-Flash, its EXL3 expert kernels, DFlash2 and MTP drafting with exact verification and the OpenAI-compatible server. Every file in patches/ is a modification of TensorFold v0.6.0.
  • TensorFold itself builds on, and credits in its third-party notices: ExLlamaV3 (turboderp, MIT), whose EXL3 format the routed experts are stored in, the GLM-5.3-Flash modeling code in Hugging Face transformers (Apache 2.0), and z-lab/dflash (Z Lab, MIT), whose DFlash2 architecture its drafter ports.

Patches

  • 0003-glm-vision: GLM's image and video processors (resize with pad, 2 fps frame choice, prompt layout) and vision tower, checked bit for bit against Hugging Face transformers 5.17 (Apache 2.0), the reference they follow; builds on TensorFold's Qwen image pipeline.
  • 0006-cuda-roce-allgather: the one-shot RoCE all-gather (COMM=roce) is the "RoCEnante" transport of b12x by local-inference-lab (Apache 2.0): its C proxy (roce_proxy.c), modified for more than two Sparks (per-peer routes over up to 4 network cards; its header lists the changes), and its CuTe all-gather kernel reimplemented in CUDA C++ (roce.cu).
  • 0012-glm-kda-chunked, 0014-glm-kda-chunked-gb10, 0039-glm-kda-chunked-kernel (KDA_CHUNKED, on by default): the chunked WY / UT form of the delta-rule recurrence follows the published chunkwise algorithm of gated delta networks and Kimi Delta Attention, as implemented in flash-linear-attention (MIT); the kernels are written anew.
  • 0013-glm-decode-rounds: verify windows of up to 16 rows so copy drafts can run long, after the wider copy windows proposed in TensorFold PR #115 by Ash Hart.
  • 0036-glm-tool-calls (tool calling for agent clients): the rule that tool calls written inside the think block count when they end the reply, the store that gives back a step's reasoning to clients that drop it, and null / const typing of tool arguments are adapted from patch 0620 of jayleaton/glm53-tensorfold-spark (Apache 2.0); the rest of that patch's fixes are our own implementation.
  • 0037-cuda-tokenize: the /tokenize and /detokenize endpoints take and return what vLLM's (Apache 2.0) do, so clients written for vLLM work unchanged; the code is our own.
  • 0043-glm-visible-pools: the idea of bounding decode token selection to the pools a row can see follows TensorFold PR #140 by mikolaj92, which TensorFold v0.6.0 has for its selection kernel; this patch's bound on the decode scoring and the split selection is our own.
  • 0044-cuda-context-errors: TensorFold v0.6.0's context-window refusals (commit 68c6e35 by Ash Hart) extended: the param field, and the same wording and context_length_exceeded code for the GLM app's window check and image prompts.
  • 0045-cuda-metrics: TensorFold v0.6.0's Prometheus /metrics (commit 4447ac3, #110, by Ash Hart) extended with /health's figures as tensorfold_health: metrics.
  • 0046-glm-l2-prefetch (L2 prefetch in decode, TF_GLM_L2PF): adapted from patch 0460 of jayleaton/glm53-tensorfold-spark (Apache 2.0); changes listed in NOTICE.
  • 0047-glm-exl3-decode-loads (routed-expert decode loads, TF_GLM_EXL3_LOADS): adapted from patch 0580 of jayleaton/glm53-tensorfold-spark (Apache 2.0); changes listed in NOTICE.
  • 0054-glm-image-prompt-reuse (image prompts resume from kept prompt states, issue #11): by abhicnv007, applied as contributed, with two small review changes.
  • 0057-server-thinking-alias (chat_template_kwargs.thinking): from Alexbob0's pull request #25; the {"type": ...} forms and the refusal of other values were added here.
  • 0058-server-client-gone-poll: TensorFold PR #218 by jayleaton (Apache 2.0), applied unchanged: the client-gone check sees descriptors past 1023.
  • 0059-server-refused-bodies: TensorFold v0.6.1's fix for #181 (commit 50dfe38a, by SxMShaDoW), backported to v0.6.0.
  • 0113-http-get-delete-body-discard (GET and DELETE bodies read before the response, as 0059 does for refused requests): by cawilliamson.
  • 0060-glm-keep-thinking (earlier turns keep their reasoning, TF_GLM_CLEAR_THINKING): by kky42, pull request #23.
  • 0071-glm-shared-prefix-copy (a shared system prompt's resume keeps the writer's kept prompt, issue #43): by ezoushen, pull request #44, applied as contributed, with tools/prompt_reuse.py.
  • 0072-glm-display-kv (DISPLAY_KV_MIB, the display reservation in the shared pool, issue #55): by ezoushen, pull request #56, applied as contributed, with tools/display_kv_check.py (one review fix in its start.sh check, which ended a headless Spark's start without a message). It applies to TensorFold's pool the display-reserve KV technique that gabewillen proposed for the vLLM kit in MiaAI-Lab/GLM-5.3-Flash-EXL3-2x-DGX-Sparks#234.
  • 0073-glm-queued-cancellation (requests waiting for a slot are dropped when their client leaves): by desy0305, pull request #51, applied as contributed, with tools/test_queued_cancellation.py; its delivery-failure handling comes from johnwhited's pull request #48.
  • 0074-glm-compact-before-evict (the shared pool compacts before it evicts, issue #61): by ezoushen, pull request #62 (contributed as 0073), applied as contributed, with tools/pool_pressure.py and tools/pool_room_check.py.
  • 0077-glm-kept-cap-shared-by-recency (a new agent run keeps its system prompt's state once the kept-state cap is full): the diagnosis, and the fix of evicting shared-prefix states by recency only, by meleesciony in issue #75; the code is our own.
  • 0097-glm-kept-entries-share (the kept-state count as a share of the pool's memory, TF_GLM_CACHE_SHARE_PCT): the diagnosis (a count cap against a pool sized in tokens, with the reporter's measured eviction pattern and the 128 workaround) is by jdecker76 in issue #84; the code is our own.
  • 0078-glm-take-over-decide-then-copy (a fresh conversation after a long one clones only the kept states that stay): by m-naoki-m, also proposed upstream as TensorFold PR #421.
  • 0079-glm-picture-cache and 0080-vision-quoted-markers: by ThomasWadeZ (#63, #64).
  • 0081-tfcap-capacity-status, 0082-tfcap-admission-cap and 0083-tfcap-delivery-abort: by johnwhited (#48); the admission check and the abort-on-delivery-failure semantics follow vLLM v1's check_admission and generate-abort behaviour (Apache 2.0) as a reference.
  • 0084-anthropic-messages: TensorFold v0.6.3's Anthropic Messages API (commits 8cca6e3 and ba18743, merged as e9fade0, with ced6139's request framing) by evilpsycho42 and ashhart, and its request body reading (server/request_body.py, commit 977f2cc) by Jordi Posthumus (JordiPosthumus); backported to v0.6.0 by Eduardo Florencio (eduffd) in PR #90.
  • 0094-chunked-request-bodies (chunked request bodies on the chat, completions, tokenizer and Responses routes and the MLX-style server, issues #67, #74): uses the reader tensorfold/server/request_body.py (read_body, TensorFold commit 977f2cc), authored by Jordi Posthumus (JordiPosthumus) and brought in by 0084; the call sites are ours. TensorFold's own chunked-body issue is ashhart/TensorFold#244.
  • 0111-server-sse-keepalive (SSE keep-alive comments while a streamed reply is silent, issue #106): the diagnosis, the measurements behind a Cloudflare Tunnel, the design (a : keepalive comment line after TENSORFOLD_SSE_KEEPALIVE_S seconds of silence) and the first patch and CPU test, for the chat stream, by stevehansen in issue #106; this version, which also carries the comments through the Messages and Responses streams, and its extended test, by BadAd84.
  • 0085-glm-select-split-loop (the split selection's last pass over the earlier chunks only): by BadAd84.
  • 0086-glm-prompt-scores-loop (the prompt scoring, one row and many pool blocks a program): by BadAd84.
  • 0099-glm-tokenize-nogil (prompts tokenized with Python's GIL released): by BadAd84.
  • 0087-glm-display-kv-dispram (DISPLAY_KV_BACKEND=dispram: 0072's display reservation on kindling spark-os): by BadAd84. It maps the span through dispram, the display-carveout lender of 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.
  • 0119-glm-chat-continued (a conversation keeps its id across a rewind or a resume from disk, for patch 0089's quota by Thomas Wade; issue #104 by danielbanu): by Robert Wojciechowski (wojo on GitHub, @rwojo on X).
  • 0098-glm-mmap-uploads (the drafter's and the vision tower's tensors copied out of the safetensors mmap before they go to the GPU: kindling spark-os's 64 KiB-page kernel): by BadAd84.
  • 0090-glm-expert-launch-order (TF_GLM_EXL3_DEC_ORDER: the launch order of the expert decode kernel's blocks): by Lukasz Raczylo (lukaszraczylo), in PR #95.
  • docs/hermes-agent.md, tools/hermes_benchmark.py and tests/test_hermes_benchmark.py (the Hermes Agent custom-endpoint guide and the synthetic speed harness with its tests): by Steve Darlow (kerpopule), in PR #52.
  • 0088-glm-spill-tier (kept prompt states on local disk, SPILL_GIB): authored by Robert Wojciechowski (wojo on GitHub, @rwojo on X): tensorfold/cuda/spill.py and its hooks in the GLM engine, multi.py and the server, in PR #78. What it builds on, by its authors: the idea of persisting session state on NVMe per rank was proposed in MiaAI-Lab's GLM-5.3-Flash vLLM kit (pull request #232 by gabewillen; the idea only, no code from that AGPL-3.0 project); the multi-rank design (one directory a rank, rank 0 deciding, an agreement on every read, a reconcile at start) is that of patch 0250 of jayleaton/glm53-tensorfold-spark by Jay Leaton (Apache 2.0); the file conventions and flag names are those of TensorFold's MLX spill (PR #68 by gilby) and issue #155 by raymondkpwong; the order in which kept prompts leave is 0063-glm-kept-cap-superseded-first (PR #32 by Alexbob0); checking every file on read, private file modes, a per-Spark weights fingerprint and naming a rank whose settings differ are those of the session tier of JSpark3 v2.0.1 by jakejharris. The code is new. The scheduler's mark that a held request's stored prompt was already looked for (not forgotten before admit, so a request NoRoom holds does not start its read again every round) is nanashi66's, from PR #210.
  • 0128-glm-spill-blocks (the spill tier's block store and the in-flight prefix wait, SPILL_GIB with PARALLEL above 1, PREFIX_WAIT): the block layout (blocks of the pool's alignment named by a hash chained over the ids and salted with the state's lineage), the lineage, writing a state when it is kept through a pinned staging ring between rounds, copying rows still waiting before they are freed or overwritten (release), and the fsync order are those of the NVMe KV tier by BadAd84 in PR #118 (Apache 2.0), carried over into tensorfold/cuda/spill_blocks.py; the rest (lineage forks at each resume point, eviction by conversation and the quota from issue #122, reported by xiepengqi, the free-disk floor making room in that order, content dedup by hard link, reads on a CUDA stream beside decoding after every rank's HAS, pictures by content keys, and the prefix wait) by Robert Wojciechowski (wojo on GitHub, @rwojo on X). It builds on 0088-glm-spill-tier, whose credits above apply to the tier around it.
  • 0129-glm-kv-shard (KV sharding, TF_GLM_KV_SHARD; its checks tools/kv_shard_check.py and tools/kv_shard_mutants.sh): authored by Robert Wojciechowski (wojo on GitHub, @rwojo on X) in PR #152, from issue #151. It builds on 0128-glm-spill-blocks and 0119-glm-chat-continued, whose credits are above.
  • 0089-glm-kept-state (a byte budget for the kept states and a per-conversation quota, TF_GLM_KEPT_BYTES_GIB and TF_GLM_KEEP_PER_CHAT): authored by Thomas Wade (ThomasWadeZ) in PR #65 (Apache 2.0); rebased onto the current patches, with both limits off by default and their drops kept out of the spill tier, by MiaAI-Lab.
  • 0101-glm-prompt-select-floor (a prompt chunk's pool selection from one pass over the scores): by BadAd84.
  • 0105-glm-prompt-scores-cuda (a prompt chunk's indexer scoring in CUDA, Triton's instruction order): by BadAd84.
  • 0106-glm-sparse-onepass-cuda (a prompt chunk's sparse attention in CUDA, Triton's instruction order): by BadAd84.
  • 0107-glm-decode-indexer (a decode window's indexer: the scoring in CUDA, the selection in one pass): by BadAd84.
  • 0104-glm-seg-attention-tp3-tiles (32-head tiles from 5 rows at 17-24 heads): by BadAd84.
  • 0108-glm-seg-chunks-cuda (a decode window's latent attention chunk pass in CUDA): by BadAd84.
  • 0100-glm-draft-prelaunch (the next round's DFlash2 block pass launched at a decode round's end, TF_GLM_DRAFT_PRELAUNCH): by BadAd84.
  • 0102-glm-prompt-matmul-tile (a prompt chunk's dense projections on tile 9 or 3): by BadAd84.
  • 0103-glm-qmm-decode-noclusters (decode matmuls reduce through the partials buffer at few rows): by BadAd84.
  • 0109-responses-tool-image (image parts in a Responses function_call_output): by StrayDragon, pull request #175 for issue #162, backporting the _output hunk of TensorFold commit 69d0ca9 (v0.6.3, TensorFold issue #235).
  • 0110-vision-mpo-first-frame (an iPhone MPO JPEG is read from its first frame): the diagnosis (the n_frames guard refuses an MPO's second frame) is by robertforbes68 in issue #201; the code is our own.
  • 0112-anthropic-stream-head-usage (a streamed Messages head carries the prompt's token count): by kky42 (commits authored as evilpsycho42), pull request #145, mirroring the Zig server's fix (TensorFold PR #672).
  • 0114-glm-tool-tag-mention (a tool call after a quoted <tool_call> tag is a call again): by kky42 (commits authored as evilpsycho42), pull request #134.
  • 0115-glm-unoffered-tool-call (a call to a tool the request did not offer, reported): by kky42 (commits authored as evilpsycho42), pull request #140; its report adapted from BadAd84's 0114-glm-tool-call-rejections (#137).
  • 0116-glm-literal-added-tokens (a quoted added token stays text): by ahinore (the commit is authored as iegamo), pull request #164.
  • 0117-glm-reply-marker-ids (a reply's markup is read at its marker tokens): by ahinore, pull request #203, the reply's side of 0116's rule. It follows TENSORFOLD_REPLY_IDS of bertholomus/TensorFold (commit 113a151c, in Zig, which credits the rule to DeepInfer's output parsing); the Python code is ahinore's.
  • 0118-glm-broken-health-exit (/health and /metrics report a broken engine; opt-in TF_GLM_EXIT_ON_BROKEN): by bblicke1, pull request #146.
  • 0120-glm-fork-point-shared (a kept state a second conversation goes on from is a shared prefix): the diagnosis and the first fix (the writer's next ids kept with a state, the state flagged when a resumed prompt goes on otherwise, the flag kept when the same ids are kept again) are by RyanLeeUPC in issue #121; the rest by BadAd84.
  • 0121-glm-kept-reasoning-linear (kept reasoning restored in one pass over the conversation): by cawilliamson.
  • 0122-cuda-budget-parked-pages (the start-up budget counts the pages parked on the per-CPU free lists): by Robert Wojciechowski (wojo on GitHub, @rwojo on X).
  • Every patch, except the parts credited above: by MiaAI-Lab, developed with 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 NOTICE).

Runtime stack

  • NVIDIA PyTorch container (nvcr.io/nvidia/pytorch:26.07-py3), the base of the image, with NVIDIA's CUDA, cuDNN, cuBLAS, NCCL and related libraries. Governed by the NVIDIA Software License Agreement and the Product-Specific Terms for NVIDIA AI Products.
  • PyTorch (BSD-3-Clause): tensors, CUDA streams and the C++ extension builder that compiles the patches' CUDA kernels.
  • Triton (MIT): the language many of TensorFold's CUDA kernels are written in.
  • NCCL (BSD-3-Clause) and rdma-core (libibverbs, GPL-2.0 / BSD-2-Clause): the two ranks' exchanges over the Sparks' ConnectX-7 RoCE link.
  • PyAV (BSD-3-Clause) and FFmpeg (LGPL): video decoding. Pillow (MIT-CMU): image decoding.
  • xgrammar (Apache 2.0): structured outputs (response_format and the guided_* fields).
  • Hugging Face Hub: model hosting, the hf CLI and huggingface_hub (Apache 2.0), and the safetensors format (Apache 2.0) the checkpoint ships in.
  • Docker and the NVIDIA Container Toolkit (Apache 2.0): running the server on the GPU in a container.

Hardware

  • NVIDIA DGX Spark (GB10 Grace Blackwell, 128 GB unified memory), two of them linked by their ConnectX-7 ports: every number in the README was measured there.

If you believe something here is missing or credited wrongly, please open an issue.