recipe.toml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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: the Lloyd repo is experts-only (L{n}.safetensors + grids/). It
  13. # cannot be served standalone. The base checkpoint is
  14. # aidendle94/GLM-5.2-MXFP4-Experts-GPTQ (full model: config.json with
  15. # quant_method="hybrid_mxfp4_ct", hybrid-ct-*.safetensors non-expert weights
  16. # in block-FP8/NVFP4, tokenizer, mtp-draft). The Lloyd NF4 experts REPLACE
  17. # the MXFP4 E2M1 experts for layers 3–77 (all 75 MoE layers): the Lloyd
  18. # L{n}.safetensors files have the same filenames and tensor names as the
  19. # MXFP4 repo's, so they must be copied into the MXFP4 snapshot directory
  20. # (filesystem overlay). vLLM loads them through the standard weight loader;
  21. # the nf4_e8m0_k32 kernel (baked in production-hybrid-1.4) decodes them with
  22. # the global _NF4_CODEBOOK instead of the E2M1 bit-twiddle. Which layers use
  23. # the NF4 path is controlled by VLLM_NF4_LAYERS — a path to a JSON file
  24. # {"layers": [3, 4, ..., 77]}, NOT a range string.
  25. #
  26. # Image: sparkrun-vllm-ds4-gb10:glm52
  27. # Built from docker-images/glm52/Dockerfile, which FROMs
  28. # aidendle94/sparkrun-vllm-ds4-gb10:production-hybrid-1.4 (bakes the
  29. # nf4_e8m0_k32 / nf4_packed kernel — inert without VLLM_NF4_LAYERS).
  30. #
  31. # PREREQUISITES (manual, on EVERY node):
  32. # 1. Download both repos via HF_HOME:
  33. # huggingface-cli download aidendle94/GLM-5.2-MXFP4-Experts-GPTQ
  34. # huggingface-cli download aidendle94/GLM-5.2-NF4-Lloyd-Experts-GPTQ
  35. # (MXFP4 base ~390 GB, Lloyd experts ~385 GB)
  36. # 2. Overlay the Lloyd NF4 experts onto the MXFP4 snapshot directory:
  37. # MXFP4=$(readlink -f ~/.cache/huggingface/hub/models--aidendle94--GLM-5.2-MXFP4-Experts-GPTQ/snapshots/main)
  38. # LLOYD=$(readlink -f ~/.cache/huggingface/hub/models--aidendle94--GLM-5.2-NF4-Lloyd-Experts-GPTQ/snapshots/main)
  39. # cp "$LLOYD"/L*.safetensors "$MXFP4"/
  40. # Without this overlay the kernel decodes E2M1 weights with the NF4
  41. # codebook → garbage output (the model card warns about this).
  42. # 3. Create the NF4 layer-list JSON in the Lloyd snapshot dir:
  43. # echo '{"layers":[3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,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]}' > "$LLOYD"/nf4_layers.json
  44. #
  45. # REFERENCE:
  46. # https://huggingface.co/aidendle94/GLM-5.2-NF4-Lloyd-Experts-GPTQ
  47. # https://huggingface.co/aidendle94/GLM-5.2-MXFP4-Experts-GPTQ
  48. engine = "vllm"
  49. name = "GLM-5.2 NF4 Lloyd-Experts-GPTQ (vLLM)"
  50. docker_image = "sparkrun-vllm-ds4-gb10:glm52"
  51. model = "aidendle94/GLM-5.2-MXFP4-Experts-GPTQ"
  52. required_nodes = 4
  53. tensor_parallel_size = 4
  54. pipeline_parallel_size = 1
  55. distributed_backend = "mp"
  56. shm_size = "10gb"
  57. docker_image_dir = "glm52"
  58. entrypoint = ["vllm", "serve"]
  59. args = [
  60. # Model name
  61. "--served-model-name", "glm52",
  62. # General
  63. "--trust-remote-code",
  64. "--reasoning-parser", "glm45",
  65. "--tool-call-parser", "glm47",
  66. "--enable-auto-tool-choice",
  67. "--enable-prefix-caching",
  68. # DCP (Decode Context Parallelism)
  69. "--decode-context-parallel-size", "4",
  70. "--dcp-comm-backend", "ag_rs",
  71. # Engine backends
  72. "--attention-backend", "B12X_MLA_SPARSE",
  73. # HF overrides — 78-char index_topk_pattern (GLM-5.2 MLP/expert routing)
  74. "--hf-overrides", """
  75. '{"index_topk_pattern":"FFFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSS"}'""",
  76. # KV cache — NVFP4 with per-token scaling (nvfp4_ds_mla)
  77. "--kv-cache-dtype", "nvfp4_ds_mla",
  78. "--kv-cache-memory-bytes", "5500000000",
  79. # Context & batch config
  80. "--max-model-len", "262144",
  81. "--max-num-batched-tokens", "2048",
  82. "--max-num-seqs", "3",
  83. "--gpu-memory-utilization", "0.89",
  84. # Speculative decode — MTP k=4 with adaptive depths
  85. # {{mtp_draft}} is substituted per-node with the resolved HF cache path
  86. # (refs/main → latest snapshot) so symlinks resolve correctly.
  87. "--speculative-config", """
  88. '{"model":"{{mtp_draft}}","method":"mtp","num_speculative_tokens":4,"draft_attention_backend":"B12X_MLA_SPARSE","adaptive_speculative_tokens_window":32}'""",
  89. # Compilation — FULL_AND_PIECEWISE with all custom ops, 8 capture sizes
  90. "--compilation-config", """
  91. '{"cudagraph_mode":"FULL_AND_PIECEWISE","custom_ops":["all"],"cudagraph_capture_sizes":[1,2,3,4,5,6,8]}'""",
  92. # Timeout safety net (cold boot: ranks finish minutes apart)
  93. "--distributed-timeout-seconds", "3600",
  94. "--cpu-distributed-timeout-seconds", "3600",
  95. ]
  96. # Persistent JIT/torch-inductor cache (avoids ~20 min recompilation on cold boot).
  97. # `alias = "jit_cache"` resolves via [mount_aliases] in config.toml; if absent,
  98. # falls back to host "~/.cache/jit" (expanded to /home/<ssh_user>/.cache/jit).
  99. # `env` injects -e XDG_CACHE_HOME=/root/.cache/jit so vLLM/torch write there.
  100. [[extra_mounts]]
  101. alias = "jit_cache"
  102. host = "~/.cache/jit"
  103. container = "/root/.cache/jit"
  104. env = "XDG_CACHE_HOME"
  105. # MTP draft model — from the MXFP4 base checkpoint's repo. Resolved at serve
  106. # time, per node, from the HF cache (refs/main → latest snapshot), so the
  107. # path survives `huggingface-cli download` updates without a fragile symlink.
  108. # The recipe references {{mtp_draft}} in --speculative-config; the launcher
  109. # substitutes the resolved full HF cache path per-node (no bind-mount — the
  110. # HF cache is already mounted at /root/.cache/huggingface, so symlinks
  111. # resolve correctly).
  112. [[extra_mounts]]
  113. repo = "aidendle94/GLM-5.2-MXFP4-Experts-GPTQ"
  114. subfolder = "mtp-draft"
  115. container = "mtp_draft"
  116. # Lloyd repo path reference — resolved at serve time, per node, from the HF
  117. # cache (refs/main → latest snapshot). {{lloyd_experts}} is substituted into
  118. # VLLM_NF4_LAYERS below so the kernel can find the nf4_layers.json file
  119. # (created by the operator in step 3 of the prerequisites above). This is a
  120. # path reference, NOT a bind-mount — the HF cache is already mounted at
  121. # /root/.cache/huggingface, so the resolved path's symlinks resolve correctly.
  122. [[extra_mounts]]
  123. repo = "aidendle94/GLM-5.2-NF4-Lloyd-Experts-GPTQ"
  124. container = "lloyd_experts"
  125. [env]
  126. # ── NF4 Lloyd expert overlay ──────────────────────────────────────────────
  127. # Path to a JSON file listing which layers use the nf4_e8m0_k32 decode path
  128. # (vs the default fp4_e8m0_k32 E2M1 bit-twiddle). The kernel reads this file
  129. # at init: {"layers": [3, 4, ..., 77]}. {{lloyd_experts}} is substituted
  130. # per-node with the resolved HF cache path to the Lloyd repo snapshot, where
  131. # the operator creates nf4_layers.json (see PREREQUISITES step 3 above).
  132. VLLM_NF4_LAYERS = "{{lloyd_experts}}/nf4_layers.json"
  133. # ── b12x suite ────────────────────────────────────────────────────────────
  134. VLLM_USE_V2_MODEL_RUNNER = "1"
  135. VLLM_USE_B12X_MOE = "1"
  136. VLLM_USE_B12X_SPARSE_INDEXER = "1"
  137. VLLM_DCP_SHARD_DRAFT = "1"
  138. VLLM_DCP_GLOBAL_TOPK = "1"
  139. VLLM_DSV4_INDEXER_SP = "1"
  140. # ── MLA CKV gather (sparse gather for decode) ─────────────────────────────
  141. VLLM_B12X_MLA_CKV_GATHER = "1"
  142. VLLM_B12X_MLA_CKV_GATHER_MAX_TOKENS = "262144"
  143. VLLM_B12X_MLA_DECODE_SPARSE_GATHER = "1"
  144. VLLM_B12X_MLA_DECODE_GATHER_V2 = "1"
  145. # ── Speculative decode ────────────────────────────────────────────────────
  146. VLLM_ADAPTIVE_SPEC_DEPTHS = "2,4"
  147. # ── NVFP4 KV cache ────────────────────────────────────────────────────────
  148. VLLM_NVFP4_MLA_PER_TOKEN_SCALE = "1"
  149. # ── Timeout safety net ────────────────────────────────────────────────────
  150. VLLM_ENGINE_READY_TIMEOUT_S = "3600"
  151. VLLM_EXECUTE_MODEL_TIMEOUT_SECONDS = "1800"
  152. VLLM_ALLOW_LONG_MAX_MODEL_LEN = "1"
  153. # ── MUST unset baked VLLM_PREFIX_CACHE_RETENTION_INTERVAL ─────────────────
  154. # The image bakes a value that GLM-5.2's KV coordinator rejects.
  155. # Empty string = unset at runtime.
  156. VLLM_PREFIX_CACHE_RETENTION_INTERVAL = ""
  157. # ── Architecture (aarch64/sm_121a DGX Spark) ──────────────────────────────
  158. CUTE_DSL_ARCH = "sm_121a"
  159. TORCH_CUDA_ARCH_LIST = "12.1a"
  160. # ── JIT cache ──────────────────────────────────────────────────────────────
  161. # Persisted via the [[extra_mounts]] jit_cache entry above: XDG_CACHE_HOME is
  162. # injected from that mount, pointing at /root/.cache/jit (no hardcoded dupe).
  163. # ── NCCL overrides ─────────────────────────────────────────────────────────
  164. # Cluster config provides NCCL_IB_HCA, NCCL_IB_GID_INDEX, NCCL_SOCKET_IFNAME
  165. # Launcher defaults: NCCL_IGNORE_CPU_AFFINITY=1, NCCL_NET=IB, NCCL_DEBUG=WARN
  166. NCCL_IB_DISABLE = "0" # enable IB (override launcher default)
  167. NCCL_MAX_NCHANNELS = "4"
  168. NCCL_MIN_NCHANNELS = "4"
  169. NCCL_CUMEM_ENABLE = "0"
  170. # ── Compute ────────────────────────────────────────────────────────────────
  171. OMP_NUM_THREADS = "4"