recipe.toml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. # GLM-5.2 NF4 Lloyd-Experts-GPTQ — 4× DGX Spark (GB10, sm_121a), TP=4, DCP=4.
  2. #
  3. # Model: aidendle94/GLM-5.2-NF4-Lloyd-Experts-GPTQ
  4. # → https://huggingface.co/aidendle94/GLM-5.2-NF4-Lloyd-Experts-GPTQ
  5. #
  6. # Lloyd-codebook NF4 routed-expert overlay for GLM-5.2 (744B MoE, 256
  7. # experts/layer, 8 activated/token, 78 layers, sparse-MLA). Expert weights
  8. # quantized to 4-bit with a fitted Lloyd–Max codebook (−16.8% expert
  9. # reconstruction error vs E2M1/MXFP4 baseline on the same GPTQ pipeline).
  10. # Codes are indices into per-layer grids/L{n}.json — NOT the E2M1 table.
  11. #
  12. # LOADING via [composed_model]: the Lloyd repo is experts-only (no config,
  13. # no tokenizer, no non-expert weights). The launcher builds a /tmp dir per
  14. # node with symlinks into the HF cache and bind-mounts it at /root/model:
  15. # 1. aidendle94/GLM-5.2-MXFP4-Experts-GPTQ (base checkpoint — config.json
  16. # with quant_method="hybrid_mxfp4_ct", hybrid-ct-*.safetensors non-expert
  17. # weights, tokenizer, mtp-draft) → all files symlinked.
  18. # 2. aidendle94/GLM-5.2-NF4-Lloyd-Experts-GPTQ (Lloyd NF4 experts) →
  19. # L*.safetensors symlinked, OVERWRITING the MXFP4 E2M1 experts
  20. # (later sources win). Same filenames, same tensor names — the Lloyd
  21. # codes replace the E2M1 codes.
  22. # 3. nf4_layers.json (generated) — tells the kernel which layers use the
  23. # nf4_e8m0_k32 decode path vs the default fp4_e8m0_k32 E2M1 bit-twiddle.
  24. #
  25. # The symlinks point to container-side paths (/root/.cache/huggingface/...)
  26. # so they resolve inside the container where the HF cache is mounted. The
  27. # _NF4_CODEBOOK is GLOBAL and hardcoded in the b12x binary (fitted as the
  28. # mean of 71 per-layer Lloyd–Max tables) — the per-layer grids/L{n}.json
  29. # files are reference artifacts, NOT loaded at runtime.
  30. #
  31. # Image: sparkrun-vllm-ds4-gb10:glm52
  32. # Built from docker-images/glm52/Dockerfile, which FROMs
  33. # aidendle94/sparkrun-vllm-ds4-gb10:production-hybrid-1.4 (bakes the
  34. # nf4_e8m0_k32 / nf4_packed kernel — inert without VLLM_NF4_LAYERS).
  35. #
  36. # PREREQUISITES:
  37. # - Both repos cached on every node via HF_HOME:
  38. # huggingface-cli download aidendle94/GLM-5.2-MXFP4-Experts-GPTQ
  39. # huggingface-cli download aidendle94/GLM-5.2-NF4-Lloyd-Experts-GPTQ
  40. # (MXFP4 base ~390 GB, Lloyd experts ~385 GB)
  41. # No manual overlay or JSON creation — [composed_model] handles everything.
  42. engine = "vllm"
  43. name = "GLM-5.2 NF4 Lloyd-Experts-GPTQ (vLLM)"
  44. docker_image = "sparkrun-vllm-ds4-gb10:glm52"
  45. model = "aidendle94/GLM-5.2-MXFP4-Experts-GPTQ"
  46. parent_model = "zai-org/GLM-5.2"
  47. required_nodes = 4
  48. tensor_parallel_size = 4
  49. pipeline_parallel_size = 1
  50. distributed_backend = "mp"
  51. shm_size = "10gb"
  52. docker_image_dir = "glm52"
  53. entrypoint = ["vllm", "serve"]
  54. args = [
  55. # Model name
  56. "--served-model-name", "glm52",
  57. # General
  58. "--trust-remote-code",
  59. "--reasoning-parser", "glm45",
  60. "--tool-call-parser", "glm47",
  61. "--enable-auto-tool-choice",
  62. "--enable-prefix-caching",
  63. # DCP (Decode Context Parallelism)
  64. "--decode-context-parallel-size", "4",
  65. "--dcp-comm-backend", "ag_rs",
  66. # Engine backends
  67. "--attention-backend", "B12X_MLA_SPARSE",
  68. # HF overrides — 78-char index_topk_pattern (GLM-5.2 MLP/expert routing)
  69. "--hf-overrides", """
  70. '{"index_topk_pattern":"FFFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSS"}'""",
  71. # KV cache — NVFP4 with per-token scaling (nvfp4_ds_mla)
  72. "--kv-cache-dtype", "nvfp4_ds_mla",
  73. "--kv-cache-memory-bytes", "5500000000",
  74. # Context & batch config
  75. "--max-model-len", "262144",
  76. "--max-num-batched-tokens", "2048",
  77. "--max-num-seqs", "3",
  78. "--gpu-memory-utilization", "0.89",
  79. # Speculative decode — MTP k=4 with adaptive depths
  80. # /root/model/mtp-draft is symlinked from the MXFP4 base checkpoint
  81. # (the composed dir includes it via source #1).
  82. #
  83. # NOTE: MTP + reasoning parser (glm45) + response_format (guided decoding)
  84. # requires the vLLM structured-output reasoning-boundary fix (upstream
  85. # PRs #44297 + #44993, forward-ported in docker-images/glm52/). Without
  86. # it, the grammar FSM fails to advance across the reasoning-end marker
  87. # (|◊|) under MTP, so the content channel is unconstrained and the model
  88. # emits prose/markdown-fence prefixes before JSON. The fix is baked into
  89. # the sparkrun-vllm-ds4-gb10:glm52 image.
  90. "--speculative-config", """
  91. '{"model":"/root/model/mtp-draft","method":"mtp","num_speculative_tokens":4,"draft_attention_backend":"B12X_MLA_SPARSE","adaptive_speculative_tokens_window":32}'""",
  92. # Compilation — FULL_AND_PIECEWISE with all custom ops, 8 capture sizes
  93. "--compilation-config", """
  94. '{"cudagraph_mode":"FULL_AND_PIECEWISE","custom_ops":["all"],"cudagraph_capture_sizes":[1,2,3,4,5,6,8]}'""",
  95. # Timeout safety net (cold boot: ranks finish minutes apart)
  96. "--distributed-timeout-seconds", "3600",
  97. "--cpu-distributed-timeout-seconds", "3600",
  98. ]
  99. [composed_model]
  100. mount = "/root/model"
  101. [[composed_model.sources]]
  102. repo = "aidendle94/GLM-5.2-MXFP4-Experts-GPTQ"
  103. [[composed_model.sources]]
  104. repo = "aidendle94/GLM-5.2-NF4-Lloyd-Experts-GPTQ"
  105. glob = "L*.safetensors"
  106. # Exclude the 5 layers with mis-packed experts (per model card known-defect
  107. # workaround). These layers' Lloyd repo L{n}.safetensors contain 255 Lloyd-
  108. # coded experts + 1 E2M1 expert — decoding as E2M1 (which nf4_layers.json
  109. # does) would garbage-decode the 255 Lloyd experts. Instead, skip the Lloyd
  110. # overlay for these files so the MXFP4 base's all-E2M1 L{n}.safetensors
  111. # survives, and the excluded-from-NF4 E2M1 decode path matches their bytes.
  112. exclude = [
  113. "L5.safetensors",
  114. "L8.safetensors",
  115. "L9.safetensors",
  116. "L32.safetensors",
  117. "L46.safetensors",
  118. ]
  119. # NF4 layer list — all 75 MoE layers (3–77) EXCEPT the 5 layers with a
  120. # known packing defect (per model card 2026-07-27). Layers 5, 8, 9, 32, 46
  121. # each contain 1 expert whose bytes were packed with E2M1/MXFP4 nibbles
  122. # (quantizer arm won per-expert, but decoding is per-layer). These layers
  123. # are ALSO excluded from the Lloyd source above (exclude = [...]) so the
  124. # MXFP4 base's all-E2M1 L{n}.safetensors survives — decoding as E2M1
  125. # (which this list does) matches their bytes. Layer 10 had the same defect
  126. # but was already caught + fixed upstream by the packing guard, so it
  127. # stays in the NF4 set.
  128. # Ref: https://huggingface.co/aidendle94/GLM-5.2-NF4-Lloyd-Experts-GPTQ
  129. # ("Known defect: 5 experts are packed on the wrong grid")
  130. [[composed_model.files]]
  131. name = "nf4_layers.json"
  132. content = '{"layers":[3,4,6,7,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,33,34,35,36,37,38,39,40,41,42,43,44,45,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77]}'
  133. # Persistent JIT/torch-inductor cache (avoids ~20 min recompilation on cold boot).
  134. # `alias = "jit_cache"` resolves via [mount_aliases] in config.toml; if absent,
  135. # falls back to host "~/.cache/jit" (expanded to /home/<ssh_user>/.cache/jit).
  136. # `env` injects -e XDG_CACHE_HOME=/root/.cache/jit so vLLM/torch write there.
  137. [[extra_mounts]]
  138. alias = "jit_cache"
  139. host = "~/.cache/jit"
  140. container = "/root/.cache/jit"
  141. env = "XDG_CACHE_HOME"
  142. [env]
  143. # ── NF4 Lloyd expert overlay ──────────────────────────────────────────────
  144. # Path to a JSON file listing which layers use the nf4_e8m0_k32 decode path
  145. # (vs the default fp4_e8m0_k32 E2M1 bit-twiddle). Generated by [composed_model]
  146. # at /root/model/nf4_layers.json — no placeholder needed (known container path).
  147. VLLM_NF4_LAYERS = "/root/model/nf4_layers.json"
  148. # ── b12x suite ────────────────────────────────────────────────────────────
  149. VLLM_USE_V2_MODEL_RUNNER = "1"
  150. VLLM_USE_B12X_MOE = "1"
  151. VLLM_USE_B12X_SPARSE_INDEXER = "1"
  152. VLLM_DCP_SHARD_DRAFT = "1"
  153. VLLM_DCP_GLOBAL_TOPK = "1"
  154. VLLM_DSV4_INDEXER_SP = "1"
  155. # ── MLA CKV gather (sparse gather for decode) ─────────────────────────────
  156. VLLM_B12X_MLA_CKV_GATHER = "1"
  157. VLLM_B12X_MLA_CKV_GATHER_MAX_TOKENS = "262144"
  158. VLLM_B12X_MLA_DECODE_SPARSE_GATHER = "1"
  159. VLLM_B12X_MLA_DECODE_GATHER_V2 = "1"
  160. # ── Speculative decode ────────────────────────────────────────────────────
  161. VLLM_ADAPTIVE_SPEC_DEPTHS = "2,4"
  162. # ── NVFP4 KV cache ────────────────────────────────────────────────────────
  163. VLLM_NVFP4_MLA_PER_TOKEN_SCALE = "1"
  164. # ── Timeout safety net ────────────────────────────────────────────────────
  165. VLLM_ENGINE_READY_TIMEOUT_S = "3600"
  166. VLLM_EXECUTE_MODEL_TIMEOUT_SECONDS = "1800"
  167. VLLM_ALLOW_LONG_MAX_MODEL_LEN = "1"
  168. # ── MUST unset baked VLLM_PREFIX_CACHE_RETENTION_INTERVAL ─────────────────
  169. # The image bakes a value that GLM-5.2's KV coordinator rejects.
  170. # Empty string = unset at runtime.
  171. VLLM_PREFIX_CACHE_RETENTION_INTERVAL = ""
  172. # ── Architecture (aarch64/sm_121a DGX Spark) ──────────────────────────────
  173. CUTE_DSL_ARCH = "sm_121a"
  174. TORCH_CUDA_ARCH_LIST = "12.1a"
  175. # ── JIT cache ──────────────────────────────────────────────────────────────
  176. # Persisted via the [[extra_mounts]] jit_cache entry above: XDG_CACHE_HOME is
  177. # injected from that mount, pointing at /root/.cache/jit (no hardcoded dupe).
  178. # ── NCCL overrides ─────────────────────────────────────────────────────────
  179. # Cluster config provides NCCL_IB_HCA, NCCL_IB_GID_INDEX, NCCL_SOCKET_IFNAME
  180. # Launcher defaults: NCCL_IGNORE_CPU_AFFINITY=1, NCCL_NET=IB, NCCL_DEBUG=WARN
  181. NCCL_IB_DISABLE = "0" # enable IB (override launcher default)
  182. NCCL_MAX_NCHANNELS = "4"
  183. NCCL_MIN_NCHANNELS = "4"
  184. NCCL_CUMEM_ENABLE = "0"
  185. # ── Compute ────────────────────────────────────────────────────────────────
  186. OMP_NUM_THREADS = "4"