Text Generation
MLX
Safetensors
English
Chinese
glm_moe_dsa
quantized
glm
Mixture of Experts
apple-silicon
mixed-precision
2-bit
speculative-decoding
mtp
conversational
4-bit precision
Instructions to use avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw") prompt = "Write a story about Einstein" messages = [{"role": "user", "content": prompt}] prompt = tokenizer.apply_chat_template( messages, add_generation_prompt=True ) text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Pi
How to use avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw"
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw"
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw
Run Hermes
hermes
- OpenClaw new
How to use avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw"
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw" \ --custom-provider-id mlx-lm \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
- MLX LM
How to use avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw", "messages": [ {"role": "user", "content": "Hello"} ] }'
Add int8 KV usage + Long-context/memory section; correct 256GB->256GiB(274.9GB) and add measured prefill-peak curve (DSA activation caps ~26-32K prompt on 256 GiB)
Browse files
README.md
CHANGED
|
@@ -45,9 +45,9 @@ The pre-DWQ weights remain available on the [`pre-dwq`](https://huggingface.co/a
|
|
| 45 |
| Base model | zai-org/GLM-5.2 (744B total / \~40B active) |
|
| 46 |
| Bits/weight | **\~2.56** (per-tensor mixed) |
|
| 47 |
| On-disk size | **246.9 GB** (48 shards, incl. the 4.5 GB native MTP layer) |
|
| 48 |
-
| Peak memory | \~
|
| 49 |
| Format | MLX (Apple Silicon) |
|
| 50 |
-
| Context |
|
| 51 |
| Speculative decoding | native MTP (nextn layer 78 included) |
|
| 52 |
|
| 53 |
## Why this model
|
|
@@ -112,10 +112,35 @@ Reference numbers (M3 Ultra 512 GB, single request, greedy): the [3.5 bpw siblin
|
|
| 112 |
|
| 113 |
**Long context:** MTP works past `index_topk` (2048 tokens — the DSA-sparse regime). Draft acceptance holds there, and the fork's **small-L gather path** (commit `946c412`) keeps the multi-token verify from paying the sparse-mask setup per iteration (before that fix, long-context MTP decoded at 0.26× plain). Measured on a 4-bit sibling at ~2.1K context: `--mtp` k=2 ≈ 0.85× plain, k=1 ≈ 0.98× — at very long contexts prefer `--mtp-num-draft-tokens 1` or plain; the k=2 gain lives in the ≤2048 dense regime.
|
| 114 |
|
| 115 |
-
**Memory note
|
| 116 |
|
| 117 |
**Notes for other integrators** (verified against vLLM's `deepseek_mtp` semantics): `eh_proj` concat order is `[enorm(embed(t+1)), hnorm(h_t)]`; the hidden fed to the MTP is the backbone's **pre-final-norm** residual stream; for chained drafting feed back the **`shared_head.norm`-normalized** hidden (chaining the raw layer output halves chained acceptance — measured 0.27 → 0.75 conditional at position 2).
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
## Correctness (verified vs the HF reference)
|
| 120 |
|
| 121 |
GLM-5.2's `glm_moe_dsa` needed fixes beyond the stock mlx-lm port; this build was produced with a patched fork and validated:
|
|
@@ -142,9 +167,7 @@ mlx_lm.server --model avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw --mtp
|
|
| 142 |
|
| 143 |
## Hardware
|
| 144 |
|
| 145 |
-
Runs in **≤256 GB unified memory** (Apple Silicon).
|
| 146 |
-
|
| 147 |
-

|
| 148 |
|
| 149 |
## Credits
|
| 150 |
|
|
|
|
| 45 |
| Base model | zai-org/GLM-5.2 (744B total / \~40B active) |
|
| 46 |
| Bits/weight | **\~2.56** (per-tensor mixed) |
|
| 47 |
| On-disk size | **246.9 GB** (48 shards, incl. the 4.5 GB native MTP layer) |
|
| 48 |
+
| Peak memory | \~242 GB (weights, MTP-attached) · \~249 GB (8K) · \~263 GB (26K) · \~293 GB (64K) · \~344 GB (128K) — **measured** (int8 KV); the DSA prefill activation grows with context |
|
| 49 |
| Format | MLX (Apple Silicon) |
|
| 50 |
+
| Context | 1M-capable architecture (DSA); **machine-limited in practice** — ≈26–32K prefill on a 256 GiB box (see *Long context & memory*) |
|
| 51 |
| Speculative decoding | native MTP (nextn layer 78 included) |
|
| 52 |
|
| 53 |
## Why this model
|
|
|
|
| 112 |
|
| 113 |
**Long context:** MTP works past `index_topk` (2048 tokens — the DSA-sparse regime). Draft acceptance holds there, and the fork's **small-L gather path** (commit `946c412`) keeps the multi-token verify from paying the sparse-mask setup per iteration (before that fix, long-context MTP decoded at 0.26× plain). Measured on a 4-bit sibling at ~2.1K context: `--mtp` k=2 ≈ 0.85× plain, k=1 ≈ 0.98× — at very long contexts prefer `--mtp-num-draft-tokens 1` or plain; the k=2 gain lives in the ≤2048 dense regime.
|
| 114 |
|
| 115 |
+
**Memory note:** the MTP-capable fork attaches the module at load (+4.5 GB) even without `--mtp`, trimming the KV+activation budget by that much. To reclaim it, set `"num_nextn_predict_layers": 0` in a local `config.json` copy (or use a runtime without MTP support, which strips the layer). See *Long context & memory* for the machine-level ceiling.
|
| 116 |
|
| 117 |
**Notes for other integrators** (verified against vLLM's `deepseek_mtp` semantics): `eh_proj` concat order is `[enorm(embed(t+1)), hnorm(h_t)]`; the hidden fed to the MTP is the backbone's **pre-final-norm** residual stream; for chained drafting feed back the **`shared_head.norm`-normalized** hidden (chaining the raw layer output halves chained acceptance — measured 0.27 → 0.75 conditional at position 2).
|
| 118 |
|
| 119 |
+
## Long context & memory
|
| 120 |
+
|
| 121 |
+
GLM-5.2's MLA stores a **compressed latent** KV (kv_lora 512 + rope 64 per layer), so the KV cache itself is small — **\~88 KB/token at fp16, \~44 KB/token with int8**. Quantize it with `--kv-bits` (the patched fork engages int8 on the MLA latent; stock `mlx-lm` silently ignores it):
|
| 122 |
+
|
| 123 |
+
```bash
|
| 124 |
+
mlx_lm.generate --model avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw \
|
| 125 |
+
--kv-bits 8 --kv-group-size 64 --quantized-kv-start 4096 --prompt "…"
|
| 126 |
+
|
| 127 |
+
# OpenAI-compatible server
|
| 128 |
+
mlx_lm.server --model avlp12/GLM-5.2-Alis-MLX-Dynamic-2.56bpw \
|
| 129 |
+
--kv-bits 8 --quantized-kv-start 4096
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
**On a 256 GiB machine the KV is *not* the binding constraint — the DSA prefill activation is.** Measured peak on this build (M3 Ultra, int8 KV, MTP-attached weights ≈ 242 GB):
|
| 133 |
+
|
| 134 |
+
| prompt (prefill) | peak | fits 256 GiB (274.9 GB)? |
|
| 135 |
+
|---|---|---|
|
| 136 |
+
| 8K | \~249 GB | ✓ |
|
| 137 |
+
| 26K | \~263 GB | ✓ (tight, \~12 GB headroom) |
|
| 138 |
+
| 32K | \~268 GB | ✓ (very tight) |
|
| 139 |
+
| 64K | \~293 GB | ✗ |
|
| 140 |
+
| 128K | \~344 GB | ✗ |
|
| 141 |
+
|
| 142 |
+
The DSA lightning indexer scores every past token per prefill chunk, so the activation peak climbs \~+20 GB per \~30K tokens — **independent of KV bits** (int8 vs fp16 differed by only \~1 GB at 26K, because the KV is tiny there). So on a **256 GiB box, keep prompts ≤ \~26–32K**. `--kv-bits 8` still helps where the *KV* is what grows — long **decode**/accumulated context, and **512 GiB** machines with headroom for longer prefills. For genuinely long (100K–1M) context, use the **[3.5 bpw build on a 512 GiB machine](https://huggingface.co/avlp12/GLM-5.2-Alis-MLX-Dynamic-3.5bpw)**.
|
| 143 |
+
|
| 144 |
## Correctness (verified vs the HF reference)
|
| 145 |
|
| 146 |
GLM-5.2's `glm_moe_dsa` needed fixes beyond the stock mlx-lm port; this build was produced with a patched fork and validated:
|
|
|
|
| 167 |
|
| 168 |
## Hardware
|
| 169 |
|
| 170 |
+
Runs in **≤256 GB unified memory** (Apple Silicon). A "256 GB" Mac is **256 GiB = 274.9 GB** (not 256 decimal); the \~242 GB of (MTP-attached) weights leave \~33 GB. But the DSA sparse-attention **prefill activation grows with context** (measured +\~20 GB at 26K, +\~50 GB at 64K), so the **practical prefill ceiling on a 256 GiB machine is \~26–32K tokens** (peak \~263–268 GB) — not the architecture's 1M. For 100K+ context use a 512 GB (512 GiB) machine. See *Long context & memory* below.
|
|
|
|
|
|
|
| 171 |
|
| 172 |
## Credits
|
| 173 |
|