瀏覽代碼

feat(recipe): add GLM-5.2 NF4 Lloyd-Experts-GPTQ recipe, bump glm52 image to 1.4

The Lloyd repo (aidendle94/GLM-5.2-NF4-Lloyd-Experts-GPTQ) is experts-only — L{n}.safetensors packed with a fitted Lloyd–Max codebook + per-layer grids/L{n}.json, no config.json or non-expert weights. It cannot be served standalone: the base checkpoint is the MXFP4 repo (aidendle94/GLM-5.2-MXFP4-Experts-GPTQ), which provides config.json (quant_method=hybrid_mxfp4_ct), hybrid-ct-*.safetensors non-expert weights, tokenizer, and mtp-draft. The Lloyd NF4 experts overlay the MXFP4 experts for layers 3–77 (all 75 MoE layers) via the nf4_e8m0_k32 kernel baked into production-hybrid-1.4, activated per-layer by VLLM_NF4_LAYERS. The Lloyd repo path is resolved per-node from the HF cache (refs/main → latest snapshot) via the {{lloyd_experts}} extra_mount repo reference, same pattern as {{mtp_draft}}.

Bumps docker-images/glm52/Dockerfile FROM production-hybrid-1.3 → 1.4. The 1.4 image is a superset of 1.3 (+6.7 MB, 2 appended layers: a root/ overlay + a label); the NF4 kernel is inert without VLLM_NF4_LAYERS, so all existing glm52 recipes (MXFP4, hybrid, int4-int8) are unaffected unless they opt in.
Alexander Korolev 2 月之前
父節點
當前提交
70ff8fda18
共有 2 個文件被更改,包括 177 次插入 和 1 次删除
  1. 1 1
      docker-images/glm52/Dockerfile
  2. 176 0
      recipes/glm52-nf4-lloyd-experts-gptq/recipe.toml

+ 1 - 1
docker-images/glm52/Dockerfile

@@ -8,7 +8,7 @@
 #   cd docker-images/glm52 && bash build.sh
 #   Tags: sparkrun-vllm-ds4-gb10:glm52
 
-FROM aidendle94/sparkrun-vllm-ds4-gb10:production-hybrid-1.3
+FROM aidendle94/sparkrun-vllm-ds4-gb10:production-hybrid-1.4
 
 RUN pip install --no-cache-dir --no-deps --force-reinstall nvidia-nccl-cu13==2.30.4 \
  && pip install --no-cache-dir --no-deps --force-reinstall instanttensor==0.1.9

+ 176 - 0
recipes/glm52-nf4-lloyd-experts-gptq/recipe.toml

@@ -0,0 +1,176 @@
+# GLM-5.2 NF4 Lloyd-Experts-GPTQ — 4× DGX Spark (GB10, sm_121a), TP=4, DCP=4.
+#
+# Model: aidendle94/GLM-5.2-NF4-Lloyd-Experts-GPTQ
+#   → https://huggingface.co/aidendle94/GLM-5.2-NF4-Lloyd-Experts-GPTQ
+#
+# Lloyd-codebook NF4 routed-expert overlay for GLM-5.2 (744B MoE, 256
+# experts/layer, 8 activated/token, 78 layers, sparse-MLA). Expert weights
+# quantized to 4-bit with a fitted Lloyd–Max codebook (−16.8% expert
+# reconstruction error vs E2M1/MXFP4 baseline on the same GPTQ pipeline).
+# Codes are indices into per-layer grids/L{n}.json — NOT the E2M1 table.
+#
+# LOADING: the Lloyd repo is experts-only (L{n}.safetensors + grids/). It
+# cannot be served standalone. The base checkpoint is
+# aidendle94/GLM-5.2-MXFP4-Experts-GPTQ (full model: config.json with
+# quant_method="hybrid_mxfp4_ct", hybrid-ct-*.safetensors non-expert weights
+# in block-FP8/NVFP4, tokenizer, mtp-draft). The Lloyd NF4 experts overlay
+# the MXFP4 experts for layers 3–77 (all 75 MoE layers) via the nf4_e8m0_k32
+# kernel baked into production-hybrid-1.4, activated per-layer by
+# VLLM_NF4_LAYERS. The Lloyd repo path is resolved per-node from the HF
+# cache (refs/main → latest snapshot) and substituted into VLLM_NF4_EXPERTS_PATH.
+#
+# Image: sparkrun-vllm-ds4-gb10:glm52
+#   Built from docker-images/glm52/Dockerfile, which FROMs
+#   aidendle94/sparkrun-vllm-ds4-gb10:production-hybrid-1.4 (bakes the
+#   nf4_e8m0_k32 / nf4_packed kernel — inert without VLLM_NF4_LAYERS).
+#
+# PREREQUISITES:
+#   - Both repos cached on every node via HF_HOME:
+#       huggingface-cli download aidendle94/GLM-5.2-MXFP4-Experts-GPTQ
+#       huggingface-cli download aidendle94/GLM-5.2-NF4-Lloyd-Experts-GPTQ
+#     (MXFP4 base ~390 GB, Lloyd experts ~385 GB)
+#
+# REFERENCE:
+#   https://huggingface.co/aidendle94/GLM-5.2-NF4-Lloyd-Experts-GPTQ
+#   https://huggingface.co/aidendle94/GLM-5.2-MXFP4-Experts-GPTQ
+
+engine = "vllm"
+name = "GLM-5.2 NF4 Lloyd-Experts-GPTQ (vLLM)"
+docker_image = "sparkrun-vllm-ds4-gb10:glm52"
+model = "aidendle94/GLM-5.2-MXFP4-Experts-GPTQ"
+required_nodes = 4
+tensor_parallel_size = 4
+pipeline_parallel_size = 1
+distributed_backend = "mp"
+shm_size = "10gb"
+docker_image_dir = "glm52"
+
+entrypoint = ["vllm", "serve"]
+
+args = [
+    # Model name
+    "--served-model-name", "glm52",
+    # General
+    "--trust-remote-code",
+    "--reasoning-parser", "glm45",
+    "--tool-call-parser", "glm47",
+    "--enable-auto-tool-choice",
+    "--enable-prefix-caching",
+    # DCP (Decode Context Parallelism)
+    "--decode-context-parallel-size", "4",
+    "--dcp-comm-backend", "ag_rs",
+    # Engine backends
+    "--attention-backend", "B12X_MLA_SPARSE",
+    # HF overrides — 78-char index_topk_pattern (GLM-5.2 MLP/expert routing)
+    "--hf-overrides", """
+'{"index_topk_pattern":"FFFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSS"}'""",
+    # KV cache — NVFP4 with per-token scaling (nvfp4_ds_mla)
+    "--kv-cache-dtype", "nvfp4_ds_mla",
+    "--kv-cache-memory-bytes", "5500000000",
+    # Context & batch config
+    "--max-model-len", "262144",
+    "--max-num-batched-tokens", "2048",
+    "--max-num-seqs", "3",
+    "--gpu-memory-utilization", "0.89",
+    # Speculative decode — MTP k=4 with adaptive depths
+    # {{mtp_draft}} is substituted per-node with the resolved HF cache path
+    # (refs/main → latest snapshot) so symlinks resolve correctly.
+    "--speculative-config", """
+'{"model":"{{mtp_draft}}","method":"mtp","num_speculative_tokens":4,"draft_attention_backend":"B12X_MLA_SPARSE","adaptive_speculative_tokens_window":32}'""",
+    # Compilation — FULL_AND_PIECEWISE with all custom ops, 8 capture sizes
+    "--compilation-config", """
+'{"cudagraph_mode":"FULL_AND_PIECEWISE","custom_ops":["all"],"cudagraph_capture_sizes":[1,2,3,4,5,6,8]}'""",
+    # Timeout safety net (cold boot: ranks finish minutes apart)
+    "--distributed-timeout-seconds", "3600",
+    "--cpu-distributed-timeout-seconds", "3600",
+]
+
+# Persistent JIT/torch-inductor cache (avoids ~20 min recompilation on cold boot).
+# `alias = "jit_cache"` resolves via [mount_aliases] in config.toml; if absent,
+# falls back to host "~/.cache/jit" (expanded to /home/<ssh_user>/.cache/jit).
+# `env` injects -e XDG_CACHE_HOME=/root/.cache/jit so vLLM/torch write there.
+[[extra_mounts]]
+alias = "jit_cache"
+host = "~/.cache/jit"
+container = "/root/.cache/jit"
+env = "XDG_CACHE_HOME"
+
+# MTP draft model — from the MXFP4 base checkpoint's repo. Resolved at serve
+# time, per node, from the HF cache (refs/main → latest snapshot), so the
+# path survives `huggingface-cli download` updates without a fragile symlink.
+# The recipe references {{mtp_draft}} in --speculative-config; the launcher
+# substitutes the resolved full HF cache path per-node (no bind-mount — the
+# HF cache is already mounted at /root/.cache/huggingface, so symlinks
+# resolve correctly).
+[[extra_mounts]]
+repo = "aidendle94/GLM-5.2-MXFP4-Experts-GPTQ"
+subfolder = "mtp-draft"
+container = "mtp_draft"
+
+# Lloyd NF4 expert overlay — the Lloyd repo is experts-only (L{n}.safetensors
+# + grids/L{n}.json codebooks). Resolved at serve time, per node, from the HF
+# cache (refs/main → latest snapshot). The launcher substitutes
+# {{lloyd_experts}} into VLLM_NF4_EXPERTS_PATH below, giving the 1.4 image's
+# baked-in nf4_e8m0_k32 kernel the path to the per-layer expert weights.
+# VLLM_NF4_LAYERS activates the NF4 path for layers 3–77 (all 75 MoE layers).
+[[extra_mounts]]
+repo = "aidendle94/GLM-5.2-NF4-Lloyd-Experts-GPTQ"
+container = "lloyd_experts"
+
+
+[env]
+# ── NF4 Lloyd expert overlay ──────────────────────────────────────────────
+# Activates the nf4_e8m0_k32 kernel (baked in production-hybrid-1.4) for
+# layers 3–77 (all 75 MoE layers). {{lloyd_experts}} is substituted per-node
+# with the resolved HF cache path to the Lloyd repo snapshot.
+VLLM_NF4_LAYERS = "3-77"
+VLLM_NF4_EXPERTS_PATH = "{{lloyd_experts}}"
+
+# ── b12x suite ────────────────────────────────────────────────────────────
+VLLM_USE_V2_MODEL_RUNNER = "1"
+VLLM_USE_B12X_MOE = "1"
+VLLM_USE_B12X_SPARSE_INDEXER = "1"
+VLLM_DCP_SHARD_DRAFT = "1"
+VLLM_DCP_GLOBAL_TOPK = "1"
+VLLM_DSV4_INDEXER_SP = "1"
+
+# ── MLA CKV gather (sparse gather for decode) ─────────────────────────────
+VLLM_B12X_MLA_CKV_GATHER = "1"
+VLLM_B12X_MLA_CKV_GATHER_MAX_TOKENS = "262144"
+VLLM_B12X_MLA_DECODE_SPARSE_GATHER = "1"
+VLLM_B12X_MLA_DECODE_GATHER_V2 = "1"
+
+# ── Speculative decode ────────────────────────────────────────────────────
+VLLM_ADAPTIVE_SPEC_DEPTHS = "2,4"
+
+# ── NVFP4 KV cache ────────────────────────────────────────────────────────
+VLLM_NVFP4_MLA_PER_TOKEN_SCALE = "1"
+
+# ── Timeout safety net ────────────────────────────────────────────────────
+VLLM_ENGINE_READY_TIMEOUT_S = "3600"
+VLLM_EXECUTE_MODEL_TIMEOUT_SECONDS = "1800"
+VLLM_ALLOW_LONG_MAX_MODEL_LEN = "1"
+
+# ── MUST unset baked VLLM_PREFIX_CACHE_RETENTION_INTERVAL ─────────────────
+# The image bakes a value that GLM-5.2's KV coordinator rejects.
+# Empty string = unset at runtime.
+VLLM_PREFIX_CACHE_RETENTION_INTERVAL = ""
+
+# ── Architecture (aarch64/sm_121a DGX Spark) ──────────────────────────────
+CUTE_DSL_ARCH = "sm_121a"
+TORCH_CUDA_ARCH_LIST = "12.1a"
+
+# ── JIT cache ──────────────────────────────────────────────────────────────
+# Persisted via the [[extra_mounts]] jit_cache entry above: XDG_CACHE_HOME is
+# injected from that mount, pointing at /root/.cache/jit (no hardcoded dupe).
+
+# ── NCCL overrides ─────────────────────────────────────────────────────────
+# Cluster config provides NCCL_IB_HCA, NCCL_IB_GID_INDEX, NCCL_SOCKET_IFNAME
+# Launcher defaults: NCCL_IGNORE_CPU_AFFINITY=1, NCCL_NET=IB, NCCL_DEBUG=WARN
+NCCL_IB_DISABLE = "0"             # enable IB (override launcher default)
+NCCL_MAX_NCHANNELS = "4"
+NCCL_MIN_NCHANNELS = "4"
+NCCL_CUMEM_ENABLE = "0"
+
+# ── Compute ────────────────────────────────────────────────────────────────
+OMP_NUM_THREADS = "4"