Run Models Optimally On Your Local NVIDIA AI System
2× DGX Station
4 models available on this hardware at 748 GB.
Recipe details
- Execution
- Container
- Backend version
- v0.34.0
- Peak GPU Memory
- Draft model
- hf: nvidia/Muse-Spark-Open-816B-A42B-DFlash2
- Speculative Decoding
- DFlash2
- Concurrency
- 4
- Topology
- 2× DGX Station with 1× GB300 each; one node rank per station; tensor parallel 2 over two 400 Gb/s ConnectX-8 RoCE v2 rails
- Runtime — Container (ARM64)
vllm/vllm-openai:v0.34.0- Served model
muse-spark-open- Port
- 30000
- Notes
- Start the worker before the head. Both nodes need the same `nvfp4rq/` and `draft/` directories under the model path. Verify both NCCL logs (`docker exec muse-tp2 bash -c 'grep -h "NET/IB : Using" /tmp/nccl_*.log'`) show `mlx5_0` and `mlx5_1` over RoCE with GDRDMA channels and no `NET/Socket` fallback. Muse always reasons; vLLM streams the thinking in `delta.reasoning`, so clients that read only `reasoning_content` report a fake time to first token.
- Recipe ID
meta/muse-spark-open-816b-a42b/dgx-station-2gpu/linux/vllm/nvfp4
Selected recipe
2× DGX Station · Linux · vLLM · NVFP4
Check nodes, download, and requantize
Runtime: Container (ARM64). Use Bash on both nodes and replace the placeholder. Each node downloads its own copy (497 GiB, 127 shards, plus the 8.2 GB DFlash2 drafter) and writes the requantization script (checked against its SHA-256) and the requantized checkpoint to `nvfp4rq/`. The script prints the borrowed activation scales; they must read 4.4474e-02 / 7.9304e-01 (layer 0) and 5.0595e-02 / 7.9657e-02 (layer 61). Container image: vllm/vllm-openai:v0.34.0
set -euo pipefail
HOST_DIR="<model-host-path>"
RAIL_HCAS=mlx5_0,mlx5_1
IMG=vllm/vllm-openai:v0.34.0
MODEL_REPO=unsloth/Muse-Spark-Open-816B-A42B-NVFP4
DRAFT_REPO=nvidia/Muse-Spark-Open-816B-A42B-DFlash2
GPU_UUID=$(nvidia-smi --query-gpu=uuid,name --format=csv,noheader | awk -F', ' '/GB300/ {print $1; exit}')
test -n "$GPU_UUID"
for h in ${RAIL_HCAS//,/ }; do
p=/sys/class/infiniband/$h/ports/1
echo "$h $(cat $p/state) $(cat $p/rate) $(cat $p/link_layer)"
grep -q ACTIVE $p/state
done
nvidia-smi -q -d PERFORMANCE -i "$GPU_UUID" | grep -E 'HW Power Brak'
mkdir -p "$HOST_DIR"
# One-time requantization of the BF16 routed experts of layers 0 and 61. This step goes away once
# vllm-project/vllm#67136 and #64552 are merged; vLLM then quantizes these two layers at load time.
cat > "$HOST_DIR/requant_nvfp4_vllm.py" <<'PY'
"""Requantize the BF16 routed experts of Muse Spark Open layers 0 and 61 to NVFP4 (the layout of layers 1..60), so all 62 MoE
layers run through the same packed-FP4 TRT-LLM path and the 2 x 24 GiB BF16 layers shrink to 2 x 6.75 GiB.
NVFP4 (ModelOpt layout, matches the checkpoint's layers 1..60):
<p> U8 [E, R, C/2] two E2M1 codes per byte, low nibble = even column
<p>_weight_scale F8_E4M3 [E, R, C/16] per-16-element block scale (amax_block / 6 / weight_scale_2)
<p>_weight_scale_2 F32 [E] (down) / [E, 2] (gate_up: gate, up) per-expert global scale (amax / (6 * 448))
<p>_input_scale F32 same shape as weight_scale_2; there is no activation calibration for these layers, and vLLM's
TRT-LLM NVFP4 MoE uses static activation scales, so this writes the max input scale of the
neighbour layers (layer 0: layers 1, 2; layer 61: layers 59, 60)
gate_up gets one global scale per expert, shared by its gate and up halves (written twice), so the row order of the halves
does not matter.
Usage:
python3 requant_nvfp4_vllm.py convert <src_ckpt_dir> <dst_ckpt_dir> [device=cuda:0]
dst gets symlinks to every src file, except the four BF16 expert shards (rewritten as NVFP4) and the configs/index
(rewritten: layers 0/61 experts no longer excluded from quantization).
python3 requant_nvfp4_vllm.py selftest quantize random data, check the round trip error and the byte packing
"""
import json
import os
import sys
import torch
E2M1 = torch.tensor([0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0])
# Midpoints between consecutive E2M1 magnitudes: |x| below bound i maps to code i.
BOUNDS = torch.tensor([0.25, 0.75, 1.25, 1.75, 2.5, 3.5, 5.0])
FP8_MAX, FP4_MAX = 448.0, 6.0
def global_scale(w):
"""ModelOpt weight_scale_2: amax / (6 * 448), as float32 (amax over the whole tensor)."""
return (w.abs().amax().float() / (FP4_MAX * FP8_MAX)).clamp(min=torch.finfo(torch.float32).tiny)
def quantize(w, gs):
"""w [R, C] (any float dtype), gs scalar fp32 tensor -> (packed u8 [R, C/2], block scales f8e4m3 [R, C/16])."""
R, C = w.shape
blocks = w.float().reshape(R, C // 16, 16)
bmax = blocks.abs().amax(-1)
scale = (bmax / FP4_MAX / gs).clamp(max=FP8_MAX).to(torch.float8_e4m3fn)
denom = scale.float() * gs
x = torch.where(denom[..., None] > 0, blocks / denom[..., None].clamp(min=torch.finfo(torch.float32).tiny),
torch.zeros_like(blocks))
mag = torch.bucketize(x.abs().clamp(max=FP4_MAX), BOUNDS.to(x.device)) # 0..7
code = (mag | ((x < 0) & (mag > 0)).to(mag.dtype) << 3).to(torch.uint8).reshape(R, C)
packed = code[:, 0::2] | (code[:, 1::2] << 4)
return packed.contiguous(), scale.contiguous()
def dequantize(packed, scale, gs):
R, Ch = packed.shape
lut = torch.cat([E2M1, -E2M1]).to(packed.device)
vals = torch.empty(R, Ch * 2, device=packed.device)
vals[:, 0::2] = lut[(packed & 0xF).long()]
vals[:, 1::2] = lut[(packed >> 4).long()]
return (vals.reshape(R, -1, 16) * (scale.float() * gs)[..., None]).reshape(R, Ch * 2)
def quantize_experts(w, device):
"""w [E, R, C] BF16 (CPU, possibly mmapped) -> dict of NVFP4 tensors on CPU."""
E, R, C = w.shape
packed = torch.empty(E, R, C // 2, dtype=torch.uint8)
scale = torch.empty(E, R, C // 16, dtype=torch.float8_e4m3fn)
gs = torch.empty(E, dtype=torch.float32)
err = 0.0
for e in range(E):
we = w[e].to(device)
g = global_scale(we)
p, s = quantize(we, g)
packed[e], scale[e], gs[e] = p.cpu(), s.cpu(), g.cpu()
if e % 64 == 0:
d = dequantize(p, s, g)
err = max(err, ((d - we.float()).norm() / we.float().norm()).item())
return packed, scale, gs, err
def selftest():
torch.manual_seed(0)
w = (torch.randn(64, 256) * 0.02).to(torch.bfloat16)
w[3, 5] = 0.3 # an outlier
g = global_scale(w)
p, s = quantize(w, g)
d = dequantize(p, s, g)
rel = ((d - w.float()).norm() / w.float().norm()).item()
# Packing: element 0 -> low nibble of byte 0, element 1 -> high nibble.
v = torch.zeros(1, 16)
v[0, 0], v[0, 1] = 6.0, -0.5
gp, gsc = quantize(v, torch.tensor(6.0 / (FP4_MAX * FP8_MAX)))
assert gp[0, 0].item() == (7 | ((8 | 1) << 4)), gp[0, :2]
assert rel < 0.12, rel
assert torch.allclose(d[3, 5], torch.tensor(0.3), rtol=0.1)
print(f"SELFTEST_OK rel_err={rel:.4f} outlier={d[3, 5].item():.4f}")
# There is no activation calibration for layers 0/61. vLLM's TRT-LLM NVFP4 MoE quantizes activations with the static
# input scale, so take the largest one of the two nearest NVFP4 layers (larger = no clipping, slightly coarser).
NEIGHBOURS = {0: (1, 2), 61: (59, 60)}
def neighbour_input_scale(src, wm, L, proj):
from safetensors import safe_open
best = 0.0
for n in NEIGHBOURS[L]:
k = f"model.language_model.layers.{n}.mlp.experts.{proj}_input_scale"
with safe_open(os.path.join(src, wm[k]), "pt") as fh:
best = max(best, fh.get_tensor(k).float().max().item())
return best
def convert(src, dst, device="cuda:0"):
from safetensors import safe_open
from safetensors.torch import save_file
os.makedirs(dst, exist_ok=True)
idx = json.load(open(os.path.join(src, "model.safetensors.index.json")))
wm = idx["weight_map"]
targets = {} # shard -> (layer, proj)
for L in (0, 61):
for proj in ("gate_up_proj", "down_proj"):
k = f"model.language_model.layers.{L}.mlp.experts.{proj}"
targets[wm[k]] = (L, proj, k)
for s, (L, proj, k) in targets.items():
assert sum(v == s for v in wm.values()) == 1, f"{s} holds more than {k}"
for f in os.listdir(src):
if f in targets or f in ("model.safetensors.index.json", "config.json", "hf_quant_config.json"):
continue
if not os.path.exists(os.path.join(dst, f)):
os.symlink(os.path.join(src, f), os.path.join(dst, f))
for s, (L, proj, k) in sorted(targets.items()):
out = os.path.join(dst, s)
with safe_open(os.path.join(src, s), "pt") as fh:
w = fh.get_tensor(k)
assert w.dtype == torch.bfloat16 and w.dim() == 3, (k, w.dtype, w.shape)
packed, scale, gs, err = quantize_experts(w, device)
E = w.shape[0]
tens = {k: packed, f"{k}_weight_scale": scale}
a_s = neighbour_input_scale(src, wm, L, proj)
if proj == "gate_up_proj":
tens[f"{k}_weight_scale_2"] = gs[:, None].repeat(1, 2).contiguous()
tens[f"{k}_input_scale"] = torch.full((E, 2), a_s, dtype=torch.float32)
else:
tens[f"{k}_weight_scale_2"] = gs.contiguous()
tens[f"{k}_input_scale"] = torch.full((E,), a_s, dtype=torch.float32)
print(f"REQUANT layer={L} {proj} input_scale={a_s:.4e} (max of layers {NEIGHBOURS[L]})", flush=True)
save_file(tens, out + ".tmp", metadata={"format": "pt"})
os.replace(out + ".tmp", out)
for name in tens:
wm[name] = s
print(f"REQUANT layer={L} {proj} {tuple(w.shape)} -> {tuple(packed.shape)} max_rel_err(sampled)={err:.4f} "
f"gs[min,max]=({gs.min().item():.3e},{gs.max().item():.3e}) -> {out}", flush=True)
del w, packed, scale
json.dump(idx, open(os.path.join(dst, "model.safetensors.index.json"), "w"), indent=2)
drop = {"model.language_model.layers.0.mlp.experts", "model.language_model.layers.61.mlp.experts"}
cfg = json.load(open(os.path.join(src, "config.json")))
q = cfg["quantization_config"]
q["modules_to_not_convert"] = [m for m in q["modules_to_not_convert"] if m not in drop]
q["exclude_modules"] = [m for m in q.get("exclude_modules", []) if m not in ("layers.0.", "layers.61.")]
json.dump(cfg, open(os.path.join(dst, "config.json"), "w"), indent=2)
hq_path = os.path.join(src, "hf_quant_config.json")
if os.path.exists(hq_path):
hq = json.load(open(hq_path))
hq["quantization"]["exclude_modules"] = [m for m in hq["quantization"]["exclude_modules"]
if m not in ("layers.0.", "layers.61.")]
json.dump(hq, open(os.path.join(dst, "hf_quant_config.json"), "w"), indent=2)
print(f"REQUANT_DONE dst={dst} modules_to_not_convert={len(q['modules_to_not_convert'])} "
f"exclude_modules={q['exclude_modules']}", flush=True)
if __name__ == "__main__":
if sys.argv[1] == "selftest":
selftest()
elif sys.argv[1] == "convert":
convert(sys.argv[2], sys.argv[3], *(sys.argv[4:5] or ["cuda:0"]))
PY
echo "71b7720a0b565fe11d97fa06e74cc9f0180369b0054a89401722e05829ffe85e $HOST_DIR/requant_nvfp4_vllm.py" | sha256sum -c -
docker run --rm --network host --gpus device="$GPU_UUID" -v "$HOST_DIR:/w" -e HF_HOME=/w/hf_home \
-e CUDA_VISIBLE_DEVICES="$GPU_UUID" --entrypoint bash "$IMG" -lc "
set -euo pipefail
hf download $MODEL_REPO --local-dir /w/nvfp4
test \$(ls /w/nvfp4/*.safetensors | wc -l) = 127
hf download $DRAFT_REPO --local-dir /w/draft
python3 /w/requant_nvfp4_vllm.py convert /w/nvfp4 /w/nvfp4rq cuda:0
"Launch head
Run after the worker launch, within a few minutes. Replace the placeholders with the same values as on the worker. Startup takes about 6 minutes.
set -euo pipefail
HEAD_MGMT_IP="<head-management-ip>"
HOST_DIR="<model-host-path>"
RAIL_HCAS=mlx5_0,mlx5_1
IMG=vllm/vllm-openai:v0.34.0
CONTAINER=muse-tp2
PORT=30000
RANK=0
HEADLESS=
SPEC_CONFIG='{"method":"dflash","model":"/w/draft","num_speculative_tokens":7}'
LAUNCH='set -euo pipefail
# FlashInfer 0.7.3 ships its Muse norm backend without build.json; fall back to the CuTe DSL kernel when the file is missing.
FI_DIR=$(python3 -c "import flashinfer, os; print(os.path.dirname(flashinfer.__file__))")
if [ ! -f "$FI_DIR/cake_muse_spark_norm_backend/build.json" ]; then
sed -i "s/^ _HAS_CAKE_FUSED_NORM = True\$/ _HAS_CAKE_FUSED_NORM = False/" "$FI_DIR/norm/__init__.py"
fi
exec vllm "$@"'
NODE_MGMT_IP=$(ip -4 route get 1.1.1.1 | awk '{for (i = 1; i < NF; i++) if ($i == "src") print $(i + 1)}')
MGMT_IFACE=$(ip -4 route get 1.1.1.1 | awk '{for (i = 1; i < NF; i++) if ($i == "dev") print $(i + 1)}')
GPU_UUID=$(nvidia-smi --query-gpu=uuid,name --format=csv,noheader | awk -F', ' '/GB300/ {print $1; exit}')
test -n "$GPU_UUID"
docker rm -f "$CONTAINER" > /dev/null 2>&1 || true
docker run -d --name "$CONTAINER" --privileged --gpus device="$GPU_UUID" --network host --ipc host --shm-size 16g \
--ulimit memlock=-1 --ulimit stack=67108864 -v "$HOST_DIR:/w" \
-e CUDA_VISIBLE_DEVICES="$GPU_UUID" \
-e NCCL_IB_HCA="$RAIL_HCAS" -e NCCL_SOCKET_IFNAME="$MGMT_IFACE" -e GLOO_SOCKET_IFNAME="$MGMT_IFACE" \
-e NCCL_CUMEM_ENABLE=1 -e NCCL_NET_GDR_LEVEL=5 -e NCCL_IB_TIMEOUT=22 -e NCCL_IB_RETRY_CNT=7 \
-e NCCL_DEBUG=INFO -e NCCL_DEBUG_SUBSYS=INIT,NET -e NCCL_DEBUG_FILE='/tmp/nccl_%h_%p.log' \
-e VLLM_ALLREDUCE_USE_FLASHINFER=0 -e VLLM_ALLREDUCE_USE_SYMM_MEM=0 \
-e VLLM_HOST_IP="$NODE_MGMT_IP" -e VLLM_EXECUTE_MODEL_TIMEOUT_SECONDS=1800 \
-e VLLM_WEIGHT_OFFLOADING_DISABLE_PIN_MEMORY=1 -e VLLM_ALLOW_LONG_MAX_MODEL_LEN=1 \
-e PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True -e HF_HUB_OFFLINE=1 \
--entrypoint bash "$IMG" -c "$LAUNCH" bash serve /w/nvfp4rq \
--served-model-name muse-spark-open --host 0.0.0.0 --port "$PORT" \
--nnodes 2 --node-rank "$RANK" --master-addr "$HEAD_MGMT_IP" --master-port 29501 \
--tensor-parallel-size 2 --max-model-len 32768 --max-num-seqs 4 \
--trust-remote-code --disable-custom-all-reduce \
--kv-cache-memory-bytes 8589934592 \
--cpu-offload-gb 24 --cpu-offload-params experts \
--hf-overrides '{"text_config": {"max_position_embeddings": 32768}}' \
--kernel-config '{"enable_flashinfer_autotune": false}' \
--speculative-config "$SPEC_CONFIG" \
--reasoning-parser muse $HEADLESSLaunch worker
Run first on the worker. Replace the placeholders with the same values as on the head.
set -euo pipefail
HEAD_MGMT_IP="<head-management-ip>"
HOST_DIR="<model-host-path>"
RAIL_HCAS=mlx5_0,mlx5_1
IMG=vllm/vllm-openai:v0.34.0
CONTAINER=muse-tp2
PORT=30000
RANK=1
HEADLESS=--headless
SPEC_CONFIG='{"method":"dflash","model":"/w/draft","num_speculative_tokens":7}'
LAUNCH='set -euo pipefail
# FlashInfer 0.7.3 ships its Muse norm backend without build.json; fall back to the CuTe DSL kernel when the file is missing.
FI_DIR=$(python3 -c "import flashinfer, os; print(os.path.dirname(flashinfer.__file__))")
if [ ! -f "$FI_DIR/cake_muse_spark_norm_backend/build.json" ]; then
sed -i "s/^ _HAS_CAKE_FUSED_NORM = True\$/ _HAS_CAKE_FUSED_NORM = False/" "$FI_DIR/norm/__init__.py"
fi
exec vllm "$@"'
NODE_MGMT_IP=$(ip -4 route get 1.1.1.1 | awk '{for (i = 1; i < NF; i++) if ($i == "src") print $(i + 1)}')
MGMT_IFACE=$(ip -4 route get 1.1.1.1 | awk '{for (i = 1; i < NF; i++) if ($i == "dev") print $(i + 1)}')
GPU_UUID=$(nvidia-smi --query-gpu=uuid,name --format=csv,noheader | awk -F', ' '/GB300/ {print $1; exit}')
test -n "$GPU_UUID"
docker rm -f "$CONTAINER" > /dev/null 2>&1 || true
docker run -d --name "$CONTAINER" --privileged --gpus device="$GPU_UUID" --network host --ipc host --shm-size 16g \
--ulimit memlock=-1 --ulimit stack=67108864 -v "$HOST_DIR:/w" \
-e CUDA_VISIBLE_DEVICES="$GPU_UUID" \
-e NCCL_IB_HCA="$RAIL_HCAS" -e NCCL_SOCKET_IFNAME="$MGMT_IFACE" -e GLOO_SOCKET_IFNAME="$MGMT_IFACE" \
-e NCCL_CUMEM_ENABLE=1 -e NCCL_NET_GDR_LEVEL=5 -e NCCL_IB_TIMEOUT=22 -e NCCL_IB_RETRY_CNT=7 \
-e NCCL_DEBUG=INFO -e NCCL_DEBUG_SUBSYS=INIT,NET -e NCCL_DEBUG_FILE='/tmp/nccl_%h_%p.log' \
-e VLLM_ALLREDUCE_USE_FLASHINFER=0 -e VLLM_ALLREDUCE_USE_SYMM_MEM=0 \
-e VLLM_HOST_IP="$NODE_MGMT_IP" -e VLLM_EXECUTE_MODEL_TIMEOUT_SECONDS=1800 \
-e VLLM_WEIGHT_OFFLOADING_DISABLE_PIN_MEMORY=1 -e VLLM_ALLOW_LONG_MAX_MODEL_LEN=1 \
-e PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True -e HF_HUB_OFFLINE=1 \
--entrypoint bash "$IMG" -c "$LAUNCH" bash serve /w/nvfp4rq \
--served-model-name muse-spark-open --host 0.0.0.0 --port "$PORT" \
--nnodes 2 --node-rank "$RANK" --master-addr "$HEAD_MGMT_IP" --master-port 29501 \
--tensor-parallel-size 2 --max-model-len 32768 --max-num-seqs 4 \
--trust-remote-code --disable-custom-all-reduce \
--kv-cache-memory-bytes 8589934592 \
--cpu-offload-gb 24 --cpu-offload-params experts \
--hf-overrides '{"text_config": {"max_position_embeddings": 32768}}' \
--kernel-config '{"enable_flashinfer_autotune": false}' \
--speculative-config "$SPEC_CONFIG" \
--reasoning-parser muse $HEADLESSMeasured performance
Measured 2026-11-16 · 2x NVIDIA DGX Station