GLM-5.3-Flash — Unique-REAP 128 + GrandHybrid NVFP4/MXFP8 + On-Policy MXFP8 DSpark
A structural compression, mixed-precision optimization, and full-stack serving engineering release of dealignai/GLM-5.3-Flash-UNCENSORED-NVFP4 (320B MoE, 181.30 GiB, 288 routed experts/layer) engineered to run live on a single 122.8 GiB NVIDIA Jetson/Thor (sm_110, unified LPDDR5X) at 12–15.3 tok/s decode and ~535 tok/s flat prefill with 200K context (221,184 live FP8 KV tokens), 94.5%–97.3% multi-turn OpenCode prefix cache hits (up to 81.7K+ tokens verified live), NVMe HiCache, and native multimodal vision.
Everything needed to reproduce or serve this model is bundled directly in this repository:
- Optimized On-Policy MXFP8
DSpark(gamma=8) Speculator:./dspark-onpolicy-lora-mxfp8/(4.05 GiB,-731.4 MBvs BF16). - All Profiling, Pruning, Quantization, Finetuning, Benchmarking & Serving Scripts:
./extras/scripts/. - Standalone
sglangSM110 / DSpark / HiCache Patches & Fused Triton FP8 MQA Indexer:./extras/patches/. - Full Modified
sglangSource Snapshot (with.gitHistory):./extras/packages/sglang-sm110-git.tar.gz(unpack withtar xzf sglang-sm110-git.tar.gz; the only modified inference package in the runtime venv —flashinfer-python 0.7.5.post1,torch 2.11.0+cu130,transformers 5.10.2,tilelang 0.1.15, andtriton 3.6.0are stock wheels). - Exact Per-Layer Unique-REAP Gram Profiling Report & Lab Plan:
./extras/results/glm53_unique_reap_report.json&./extras/PLAN.md.
1. The Story of the Quest
Chapter 0: Proof of Concept on a Smaller Model (16 GB RTX 5060 Ti)
This project is the direct scale-up of our earlier small-rig experiment:
On Qwen3.6-35B-A3B (256 → 128 experts, 67 GB → 13.08 GiB VRAM, 96.74 tok/s live on a single 16 GB RTX 5060 Ti sm_120), we discovered three core principles that turned out to scale dramatically better than expected to a 320B-class MoE:
- Naive activation-norm pruning (REAP) drops rare orthogonal specialists (like
<tool_call>delimiters and code-syntax triggers) while keeping redundant copies of generic prose experts. Unique-REAP (exact per-domain normalized output Gram matrix + Greedy Backward Schur-Complement Elimination + Peak-Token Hero Shield) preserves an orthogonal capability basis instead. - Active-parameter precision beats total-parameter count: protecting boundary layers, attention, vision, and shared experts at higher precision while keeping middle routed experts in native Blackwell
NVFP4prevents the long-context repetition loops that plague uniform 2-bit/4-bit quants. - Quantization entropy calibration: quantized + trimmed models have slightly flatter low-probability logit tails; lowering default sampling temperature from
1.0 → 0.6restores crisp BF16-like reasoning and tool-calling stability.
Chapter 1: Scaling to 320B (GLM-5.3-Flash) on 122.8 GiB Unified Memory (amano)
GLM-5.3-Flash (Glm5NextForConditionalGeneration) has 45 layers (3 dense + 42 MoE layers with 288 routed experts, top_k=8, 1 shared expert, 34 KDA linear-attention layers, 11 DeepSeek Sparse Attention MLA layers, hc_mult=4 multi-stream residuals, and a 347-tensor ViT vision encoder). Even already quantized in NVFP4, the base checkpoint is 181.30 GiB — far too big for 122.8 GiB unified RAM.
To profile a 181 GiB model on a 122 GiB machine without multi-node sharding, we wrote a single-node layerwise streaming profiler (01_profile_glm_layerwise.py) that streams 1 layer at a time onto Thor's GPU (~15–20 GiB peak) across 512 stratified calibration sequences (224,376 tokens: English prose, English→Code + XML tools, Japanese learning, Everyday Vision) and 128 held-out eval sequences (62,512 tokens).
Key Profiling Findings (glm53_unique_reap_report.json):
- The untouched
shared_expertalone contributes31.48%of the mean MoE block output norm (mean_shared_ratio = 0.3148). - Keeping
128 / 288routed experts (44.4%) retains83.44%of raw REAP salience (82.32%Unique-REAP salience), while Unique-REAP's Schur-complement + Peak-Token Hero Shield performs an average of14.38expert swaps per layer (604swaps across 42 MoE layers) compared to naive REAP—trading redundant clones for orthogonal specialists! - Because
Unique-REAPselects whole experts without weight averaging,02_slice_glm_unique_reap.pyslices the existingNVFP4tensors and scales (weight,weight_scale,weight_scale_2,input_scale) directly with zero re-quantization error.
Chapter 2: GrandHybrid Mixed Precision (NVFP4 + MXFP8 + BF16) -> 82.97 GiB
After slicing to 128 routed experts (~92.7 GiB), we applied Unsloth-inspired dynamic protection rules in 04_quantize_glm_unsloth_mxfp8.py (--drop-mtp since we serve with DSpark):
BF16(100% protected):embed_tokens,lm_head,model.visual.*(all 347 vision tensors),mlp.gaterouters,mHCresidual projections/norms, early dense layers (L00..L02), first MoE layer (L03), and final MoE layer (L44).MXFP8(modelopt_mixed): Middle layersL04..L43self_attn(KDA linear attention + DSA MLA projections) andshared_experts.NVFP4(native BlackwellE2M1,group_size=16): All128surviving routed experts per MoE layer.
Result: 82.97 GiB on disk — freeing ~40 GiB on Thor for the DSpark drafter, 221,184 FP8 KV tokens (200K context), Mamba/KDA state checkpoints, CUDA graphs, and OS headroom!
Chapter 3: On-Policy LoRA + MXFP8 DSpark Speculator (gamma=8)
The stock RedHatAI/GLM-5.3-Flash-speculator.dspark drafter was trained on the original 288-expert BF16 model, so its acceptance drops on an abliterated + trimmed + NVFP4/MXFP8 target.
- We added a clean hidden-state trajectory dumper (
sglang_dspark_capture.patch) and collected 160 100% on-policy rollouts (56,821tokens) plus exact[T, 24576]contracted hidden states from our live trimmed target (05b_collect_onpolicy_dspark.sh). - We fine-tuned
DSparkusing zero-depLoRALinear(r=32, alpha=64, lr=1e-4, fc_lr_mult=0.3, freeze_markov, 3 epochs,3.3 min) via06_finetune_dspark.py:- Validation loss:
2.1578 → 1.9999 - Simulated acceptance length:
3.38 → 3.56
- Validation loss:
- We quantized its 15 draft MLP projections to
MXFP8via07_quantize_dspark_mxfp8.py(keepingfc,markov_head,confidence_head, and norms inBF16), shrinking the drafter by-731.4 MB(4.05 GiBtotal) -> bundled in./dspark-onpolicy-lora-mxfp8/.
Chapter 4: Deep Systems & sglang Fixes for Thor (sm_110)
Getting GLM-5.3-Flash + DSpark + 200K context + Vision + Multi-Turn Prefix Caching running smoothly on Thor required five targeted fixes (all bundled in ./extras/patches/):
- SM110 Fused Triton FP8 Tensor-Core MQA Indexer (
sglang_sm110_dsa.patch+triton_fp8_mqa_logits.py):- Bug:
sm_110lacks SM90/SM100 DeepGEMM FP8 MQA cubins, forcingsglang's PyTorch fallback (torch.matmul(q_f, k_f.t())), which allocated34–68 GBand OOM-froze at32Kprefill, and took133.4 msper decode step at40Kcontext. - Fix: Wrote fused SM110 Triton FP8 Tensor-Core prefill & paged-decode MQA indexer kernels (
08_bench_sm110_mqa_logits.py):- Prefill (
q=2048, k=32768):958.5 ms → 95.6 ms(10.03×faster,max_diff=0.00000,100.00%Top-2048 overlap). - Paged Decode (
seq=40960, next_n=9, 11 DSA layers):133.4 ms → 4.1 ms(32.68×faster,99.83%Top-2048 overlap). - Live result at
63.5Kcontext:4.88 steps/s(205 ms/step) and~535 tok/sflat prefill!
- Prefill (
- Bug:
- Unlocking
modelopt_mixedonDSparkDraftModel(sglang_dspark_quant.patch):- Bug:
DFlashDraftModel.supports_quantization = Falsesilently strippedquant_configand layer prefixes, causing ourMXFP8drafter to collapse toaccept len = 1.07. - Fix: Enabled
supports_quantization = Trueand prefix preservation onDSparkDraftModel.
- Bug:
- Configurable HiCache Host Reserve (
sglang_hicache_reserve.patch):- Bug:
pool_host/base.pyhardcoded a10 GiBhost reserve, blocking NVMe HiCache (--hicache-size 1) when--mem-fraction-static 0.935left~10.01 GiBfree on unified memory. - Fix: Added
SGLANG_HICACHE_HOST_MEMORY_RESERVE_GB(default10, set to4on Thor).
- Bug:
- Hybrid Mamba/KDA Multi-Turn Prefix Caching:
- Finding: Default
--hybrid-cache-checkpoints-level 2only saves 1 Mamba state at request end, so any re-serialization of an OpenCode assistant turn rolled back to0cached tokens. Switching to--hybrid-cache-checkpoints-level 3 --mamba-track-interval 4096unlocked94.5%–97.3%prefix cache hits even at81.7Kcontext!
- Finding: Default
- Multimodal Vision Fix for
transformers 5.10.2(processor_config.json):- Bug:
processor_config.jsonoriginally requestedGlm5NextProcessor(absent intransformers 5.10.2), causingAutoProcessor.from_pretrained()to silently fall back to text-onlyTokenizersBackend(image_processor=None,image_tokens: 0). - Fix: Mapped
processor_config.jsontotransformers 5.10.2's built-inGlm46VProcessor/Glm46VImageProcessor/Glm46VVideoProcessor(identical<|image|>ID154854,14×14×2patchify layout,merge_size=2,[16..8000]image token bounds; original preserved inprocessor_config.json.orig). Verified live with910image tokens!
- Bug:
- Unified Memory & FlashInfer Cache Hygiene on Thor (and Other Unified-Memory Boxes):
- Proactive Linux cgroup v2 reclaim (
unglitch+ launcher wrappersunglitched_sglang,unglitched_vllm,unglitched_llama,unglitched_vllm_omni): Uses Linux kernel cgroup v2memory.reclaimonsystem.slice/user.slice+drop_caches+compact_memoryto reclaim120+ GiBcontiguous unified memory (cuda_free) in<1swith zero OOM-killer risk (no brute-forcemlock/force_swapallocation spikes). Because it relies purely on standard Linux cgroup v2 & VM sysctls, these scripts are directly reusable on other NVIDIA unified-memory systems (Jetson Thor, DGX Spark / GB10, Grace-Hopper/Blackwell) and AMD unified-memory workstations (Strix Halo / Ryzen AI Max ROCm boxes)! - Ninja version trap: Never mix system
/usr/bin/ninja(1.11.1,.ninja_logv5) with venvninja(1.13.0,.ninja_logv6) on~/.cache/flashinfer/— version mismatches trigger full CUTLASS MoE recompilation into swap! - FlashInfer autotune: Always pass
--disable-flashinfer-autotuneonsm_110to avoid dummy-forward hangs.
- Proactive Linux cgroup v2 reclaim (
2. Live Performance & Telemetry (NVIDIA Thor sm_110, 122.8 GiB)
| Metric | Value |
|---|---|
Target Checkpoint Size (UniqueREAP-128 GrandHybrid) |
82.97 GiB (128/288 routed experts) |
On-Policy MXFP8 DSpark Drafter (gamma=8) |
4.05 GiB (-731.4 MB vs BF16) |
| Live Context & FP8 KV Pool | 200,000 context / 221,184 live FP8 KV tokens (--mem-fraction-static 0.935) |
| OS Memory Headroom (Steady State) | 6.0–6.5 GiB available, ~180 MiB swap |
Prefill Speed (Flat, 32K–64K ctx) |
~535 tok/s (with SM110 Triton FP8 DSA Indexer) |
Decode Speed (temperature=0.6, DSpark gamma=8) |
12–15.3 tok/s |
| Multi-Turn OpenCode Prefix Cache Hit Rate | 94.5%–97.3% (77,056 / 81,734 cached tokens verified live!) |
| Multimodal Vision (Live Verification) | 910 image tokens on JPEG test photo, accurate item-level description |
Why Does a 55.6% Expert Trim Stay So Stable? (And vs. Low-Bit GGUF)
- The "Always-On Spine" Is 100% Untouched: All 45 attention blocks (
34KDA +11DSA), all 45shared_experts(31.5%of MoE output norm), dense layersL00..L02, vision (model.visual.*),embed_tokens, andlm_headare preserved unpruned. - Active-Parameter Precision Beats Total-Parameter Count: Fitting all
288experts into~83 GiBvia GGUF requires crushing weights to~2.1–2.3 bpw(IQ2_XS), degrading every active token and dropping decode to~3.5–5 tok/swithoutDSparkor native FP4 Tensor Cores. Keeping128orthogonalUnique-REAPspecialists at sharpNVFP4+MXFP8spine +BF16anchors preserves82.3%–83.4%of routed salience and runs ~3× faster on Thor. - Honest Trade-Off: Coding, OpenCode tool calling, vision, and
80K+long-context reasoning remain rock-solid; the trimmed capacity comes primarily from long-tail closed-book trivia and uncalibrated low-resource languages.
3. Serving Instructions (sglang on NVIDIA Thor sm_110)
- Apply the serving patches in
./extras/patches/PATCHES.mdtosglang. - Reclaim unified memory cleanly (
./extras/scripts/unglitch 120). - Launch with
./extras/scripts/inference_glm53_flash_sglang.sh(key flags below):
SGLANG_FP8_PAGED_MQA_LOGITS_TORCH=1 \
SGLANG_ENABLE_JIT_DEEPGEMM=0 \
SGLANG_OPT_USE_TILELANG_MHC_PRE=0 \
SGLANG_OPT_USE_TILELANG_MHC_POST=0 \
SGLANG_HICACHE_HOST_MEMORY_RESERVE_GB=4 \
SGLANG_HICACHE_FILE_BACKEND_STORAGE_DIR=/path/to/nvme/hicache_glm53 \
python3 -m sglang.launch_server \
--model-path /path/to/GLM-5.3-Flash-UniqueREAP-128-GrandHybrid-NVFP4-MXFP8 \
--served-model-name Nikola \
--host 0.0.0.0 --port 9000 \
--mem-fraction-static 0.935 \
--context-length 200000 \
--chunked-prefill-size 2048 \
--max-prefill-tokens 4096 \
--cuda-graph-max-bs-decode 4 \
--cuda-graph-backend-prefill disabled \
--trust-remote-code \
--tool-call-parser glm47 \
--reasoning-parser glm45 \
--chat-template /path/to/GLM-5.3-Flash-UniqueREAP-128-GrandHybrid-NVFP4-MXFP8/chat_template.jinja \
--disable-flashinfer-autotune \
--disable-shared-experts-fusion \
--dsa-prefill-backend tilelang \
--dsa-decode-backend tilelang \
--kv-cache-dtype fp8_e4m3 \
--moe-runner-backend flashinfer_cutlass \
--max-mamba-cache-size 20 \
--hybrid-cache-checkpoints-level 3 \
--mamba-track-interval 4096 \
--mamba-ssm-dtype bfloat16 \
--enable-hierarchical-cache \
--hicache-storage-backend file \
--hicache-size 1 \
--hicache-storage-prefetch-policy wait_complete \
--hicache-storage-backend-extra-config '{"hicache_storage_pass_prefix_keys": true}' \
--enable-cache-report \
--speculative-algorithm DSPARK \
--speculative-draft-model-path /path/to/GLM-5.3-Flash-UniqueREAP-128-GrandHybrid-NVFP4-MXFP8/dspark-onpolicy-lora-mxfp8 \
--speculative-num-draft-tokens 9
Recommended Sampling Parameters
Set in generation_config.json:
temperature:0.6(calibrated for quantized + trimmed logit entropy; avoids tail noise in long reasoning chains)top_p:0.95repetition_penalty:1.1
(If running on transformers >= 5.11 with native Glm5NextProcessor support, you may optionally restore processor_config.json.orig over processor_config.json.)
4. Credits & Acknowledgements
- Original Base Model:
zai-org/GLM-5.3-Flash(MIT License, Copyright (c) 2026 Z.AI Co., Ltd — preserved inLICENSE). - Abliterated NVFP4 Parent:
dealignai/GLM-5.3-Flash-UNCENSORED-NVFP4. - Base DSpark Speculator:
RedHatAI/GLM-5.3-Flash-speculator.dspark. - Predecessor Small-Rig Experiment:
catplusplus/Qwen3.6-19B-A3B-UniqueREAP-QAD-v2-Grand-Hybrid-NVFP4.