# GLM-5.2 Hybrid FP8 / NVFP4 / MXFP4

GLM-5.2, a large mixture-of-experts (MoE) model, on four DGX Spark GB10 nodes, each part stored at its own precision so that it fits.

Web page: https://aidenle.com/models/glm-5-2-hybrid-quantized-runtime/. Source: [NVIDIA Developer Forums](https://forums.developer.nvidia.com/t/glm-5-2-hybrid-fp8-nvfp4-mxfp4-optimal-runtime-recipe/377598/4). This guide describes a deployment that someone else published; reported results are attributed.

Each part of GLM-5.2 has its own precision, so the model fits on four DGX Spark nodes without the accuracy loss of an all-MXFP4 build.

| Fact | Value |
|---|---|
| Hardware | 4× DGX Spark GB10 |
| Precision | FP8 / NVFP4 / MXFP4 |
| Runtime | vLLM (custom b12x fork) |
| Max context | 262,144 tokens |

## In short

- Attention is FP8 and the dense layers NVFP4 (Red Hat quantizations). The routed experts are MXFP4 (AMD/community "festr2" calibration).
- The launch command unsets an image variable that would stop GLM-5.2 at startup.
- Early community release: the kernel code is not cleaned up for public release.

## Setup

1. Download the checkpoint: hf download aidendle94/GLM-5.2-Hybrid-FP8-MXFP4 --local-dir /models/glm52-hybrid
2. Pull the image on all four nodes: docker pull aidendle94/sparkrun-vllm-ds4-gb10:production-hybrid-1.2
3. Link the four nodes with InfiniBand or RoCE. Note your network interface (NIC) and InfiniBand adapter (IB HCA) names.
4. Run the recipe on every node: RANK=0 on the head, RANK=1, RANK=2 and RANK=3 on the workers.
5. Wait about 15 to 20 minutes on the first start, about 6 minutes on later starts.
6. Check that the server is ready: curl http://<head>:8210/health
7. Send requests to the OpenAI-compatible endpoint at /v1/chat/completions.

## The recipe

Docker launch (run on every node):

```bash
docker run -d --name glm52-hybrid \
  --network host --ipc host --shm-size 10gb --gpus all \
  --cap-add IPC_LOCK --ulimit memlock=-1:-1 \
  --device /dev/infiniband:/dev/infiniband \
  -v /models/glm52-hybrid:/hybridmodel:ro \
  -v $HOME/glm-jit-cache:/cache/jit \
  -e VLLM_USE_V2_MODEL_RUNNER=1 -e VLLM_USE_B12X_MOE=1 \
  -e VLLM_USE_B12X_SPARSE_INDEXER=1 \
  -e VLLM_DCP_SHARD_DRAFT=1 -e VLLM_DCP_GLOBAL_TOPK=1 \
  -e VLLM_DSV4_INDEXER_SP=1 \
  -e VLLM_B12X_MLA_CKV_GATHER=1 \
  -e VLLM_B12X_MLA_CKV_GATHER_MAX_TOKENS=262144 \
  -e VLLM_B12X_MLA_DECODE_SPARSE_GATHER=1 \
  -e VLLM_B12X_MLA_DECODE_GATHER_V2=1 \
  -e VLLM_ADAPTIVE_SPEC_DEPTHS=2,4 \
  -e VLLM_NVFP4_MLA_PER_TOKEN_SCALE=1 \
  -e VLLM_ENGINE_READY_TIMEOUT_S=3600 \
  -e VLLM_EXECUTE_MODEL_TIMEOUT_SECONDS=1800 \
  -e VLLM_ALLOW_LONG_MAX_MODEL_LEN=1 \
  -e CUTE_DSL_ARCH=sm_121a -e TORCH_CUDA_ARCH_LIST=12.1a \
  -e XDG_CACHE_HOME=/cache/jit \
  -e NCCL_NET=IB -e NCCL_IB_DISABLE=0 \
  -e NCCL_IB_HCA=$HCA -e NCCL_IB_GID_INDEX=3 \
  -e NCCL_SOCKET_IFNAME=$NIC -e GLOO_SOCKET_IFNAME=$NIC \
  -e NCCL_MAX_NCHANNELS=4 -e NCCL_MIN_NCHANNELS=4 \
  -e NCCL_CUMEM_ENABLE=0 \
  -e RANK=$RANK -e HEAD_IP=$HEAD_IP \
  aidendle94/sparkrun-vllm-ds4-gb10:production-hybrid-1.2 \
  bash -lc 'unset VLLM_PREFIX_CACHE_RETENTION_INTERVAL; exec vllm serve /hybridmodel \
    --served-model-name glm-5.2 --host 0.0.0.0 --port 8210 \
    --trust-remote-code --reasoning-parser glm45 \
    --tool-call-parser glm47 --enable-auto-tool-choice \
    --enable-prefix-caching \
    --tensor-parallel-size 4 --decode-context-parallel-size 4 \
    --dcp-comm-backend ag_rs \
    --attention-backend B12X_MLA_SPARSE \
    --hf-overrides "{\"index_topk_pattern\":\"FFFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSSFSSS\"}" \
    --kv-cache-dtype nvfp4_ds_mla --kv-cache-memory-bytes 5500000000 \
    --max-model-len 262144 --max-num-batched-tokens 2048 \
    --max-num-seqs 3 \
    --gpu-memory-utilization 0.89 \
    --speculative-config "{\"model\":\"/hybridmodel/mtp-draft\",\"method\":\"mtp\",\"num_speculative_tokens\":4,\"draft_attention_backend\":\"B12X_MLA_SPARSE\",\"adaptive_speculative_tokens_window\":32}" \
    --compilation-config "{\"cudagraph_mode\":\"FULL_AND_PIECEWISE\",\"custom_ops\":[\"all\"],\"cudagraph_capture_sizes\":[1,2,3,4,5,6,8]}" \
    --distributed-timeout-seconds 3600 \
    --cpu-distributed-timeout-seconds 3600 \
    --distributed-executor-backend mp \
    --nnodes 4 --node-rank $RANK --master-addr $HEAD_IP \
    --master-port 29501'
```

## Reported results

- **Alexander Korolev:** Encountered the same problem with the VLLM_PREFIX_CACHE_RETENTION_INTERVAL variable that the image sets, on four DGX Spark nodes. Worked around it with a derived Dockerfile. In it, a small entrypoint wrapper unsets the variable and then hands over to the original NVIDIA entrypoint (exec /opt/nvidia/nvidia_entrypoint.sh "$@"). ([source](https://forums.developer.nvidia.com/t/glm-5-2-hybrid-fp8-nvfp4-mxfp4-optimal-runtime-recipe/377598/6))
- **CosmicRaisins:** Responded positively to the throughput of 25 tok/s on prose that the original recipe reports. This is a reaction, not an independent re-measurement. ([source](https://forums.developer.nvidia.com/t/glm-5-2-hybrid-fp8-nvfp4-mxfp4-optimal-runtime-recipe/377598/5))
