Text Generation
MLX
Safetensors
English
glm_moe_dsa
apple-silicon
Mixture of Experts
pruned
quantized
soul-targeted
agentic
local-agent
glm
conversational
Eval Results (legacy)
4-bit precision
Instructions to use philipjohnbasile/GLM-5.2-Demolition-q4a4-soul-MLX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use philipjohnbasile/GLM-5.2-Demolition-q4a4-soul-MLX 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("philipjohnbasile/GLM-5.2-Demolition-q4a4-soul-MLX") 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 philipjohnbasile/GLM-5.2-Demolition-q4a4-soul-MLX with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "philipjohnbasile/GLM-5.2-Demolition-q4a4-soul-MLX"
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": "philipjohnbasile/GLM-5.2-Demolition-q4a4-soul-MLX" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use philipjohnbasile/GLM-5.2-Demolition-q4a4-soul-MLX 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 "philipjohnbasile/GLM-5.2-Demolition-q4a4-soul-MLX"
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 philipjohnbasile/GLM-5.2-Demolition-q4a4-soul-MLX
Run Hermes
hermes
- MLX LM
How to use philipjohnbasile/GLM-5.2-Demolition-q4a4-soul-MLX with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "philipjohnbasile/GLM-5.2-Demolition-q4a4-soul-MLX"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "philipjohnbasile/GLM-5.2-Demolition-q4a4-soul-MLX" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "philipjohnbasile/GLM-5.2-Demolition-q4a4-soul-MLX", "messages": [ {"role": "user", "content": "Hello"} ] }'
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,3 +1,98 @@
|
|
| 1 |
---
|
| 2 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
+
base_model: zai-org/GLM-5.2
|
| 4 |
+
library_name: mlx
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
language: [en]
|
| 7 |
+
tags: [mlx, moe, code, agentic, glm, pruned, quantized, verified-decoding, apple-silicon, local-agent]
|
| 8 |
---
|
| 9 |
+
|
| 10 |
+
# GLM-5.2-Demolition β a 743B frontier MoE, demolished to run on a 128 GB Mac
|
| 11 |
+
|
| 12 |
+
**One line:** we took `zai-org/GLM-5.2` (743B-parameter Mixture-of-Experts, ~381 GB at 4-bit) and
|
| 13 |
+
demolished it to **99 GB** so it runs **fully on-device on a MacBook Pro M5 Max (128 GB)** β then
|
| 14 |
+
healed it and wrapped it in a **47-tool local agent** that does things a cloud model structurally
|
| 15 |
+
cannot: the **compiler steers every line it writes**, it **can't fake a passing test or leak a
|
| 16 |
+
secret**, and it can be **fine-tuned on *your* private repo** so it writes in your style.
|
| 17 |
+
|
| 18 |
+
A **niche specialist**, not a general model β tuned to beat a frontier model *in one lane* (agentic
|
| 19 |
+
coding + design for **TS/JS/Python/Rust/Go/HTML/CSS** + Postgres) by out-*verifying* it, not out-knowing it.
|
| 20 |
+
|
| 21 |
+
## How it was made
|
| 22 |
+
1. **Pruned** the MoE experts 256 β 77 by **router-weighted saliency (REAP** = `router_weight Γ
|
| 23 |
+
activation_norm`, padding-masked), streaming layer-by-layer (~5 GB working set β it never fits in RAM).
|
| 24 |
+
2. **Quantized** mixed-precision (MLX): experts **3-bit**, attention/embeddings/lm_head **4-bit** β **99 GB**.
|
| 25 |
+
3. **Healed** with **LoRA SFT** (`--no-mask-prompt`, grad-checkpointed). The current **v4** rebuild uses a
|
| 26 |
+
**code-first balanced calibration** (so the *math* super-experts survive the prune β v3's coding-only
|
| 27 |
+
calibration collapsed math) + heal/distill on **R1 long-CoT reasoning traces**. Router-KD / expert-wise
|
| 28 |
+
Logit-KD are research-validated recovery stages (optional). *(GRPO/RLVR was tried and regressed β SFT.)*
|
| 29 |
+
|
| 30 |
+
## What makes it different (built + selftested)
|
| 31 |
+
- **Verified decoding (compiler-steered):** generates line-by-line while the **real type-checker runs in
|
| 32 |
+
the loop**; a line that adds an error is backtracked. TS 0.3 ms Β· Python ~0 ms Β· Rust 34 ms per check.
|
| 33 |
+
Practical *only* on Apple Silicon β unified memory lets the model (GPU) and compiler (CPU) share RAM.
|
| 34 |
+
- **The verifier mesh:** every output meets its real tool β compile+run+**idiomatic lint** (clippy/ruff/
|
| 35 |
+
gofmt/prettier) for 5 langs, **SQL** (sqlite), **math** (SymPy), **proofs** (**Lean 4**), design (render+see).
|
| 36 |
+
- **A 47-tool agent** with **five defense layers** the frontier lacks out of the box:
|
| 37 |
+
**trust** (checkpoint/rollback, secret-scan, prompt-injection guard, audit, risk-gate),
|
| 38 |
+
**reliability** (constraint-pinning vs context-rot, false-success guard, flaky-test re-run, onboarding map),
|
| 39 |
+
**self-improvement** (skill library, large-output pointers, clarify-before-assuming),
|
| 40 |
+
**integrity** (test-tamper guard, fabrication-proof `done`, scope enforcement, slopsquat guard),
|
| 41 |
+
plus a **humanizer** (kills AI-slop, matches your voice).
|
| 42 |
+
- **Own your repo:** `scripts/64_own_your_repo.py` fine-tunes the model on *your* private codebase so it
|
| 43 |
+
writes in your style β a cloud flagship can't be tuned on your private code.
|
| 44 |
+
- **Design soul** (render-and-measure critic: WCAG/type-scale/OKLCH), **CallSieve** zero-token retrieval +
|
| 45 |
+
live-docs RAG, **vision/voice/video** (all MLX), code-rendered math/arch figures (matplotlib/manim/TikZ).
|
| 46 |
+
|
| 47 |
+
## Requirements
|
| 48 |
+
- **Apple Silicon, 128 GB** unified memory (M5-class recommended), macOS 26/27+. **MLX β₯ 0.31.**
|
| 49 |
+
- The architecture (`glm_moe_dsa`: MLA + DSA sparse attention) needs the **bundled patches** β stock
|
| 50 |
+
mlx_lm can't load it.
|
| 51 |
+
- **β οΈ Raise the GPU memory ceiling β required.** The model needs ~101.6 GB; macOS caps the GPU
|
| 52 |
+
working set at ~110 GB by default, so it OOM-crashes (Metal command-buffer timeout) on long
|
| 53 |
+
generations. Fix before serving:
|
| 54 |
+
```bash
|
| 55 |
+
sudo sysctl iogpu.wired_limit_mb=122000 # 122 GB; one-shot (resets on reboot)
|
| 56 |
+
sudo bash dist/install_gpu_limit.sh # OR: persist it via a LaunchDaemon
|
| 57 |
+
```
|
| 58 |
+
Without this the model appears to "randomly crash" β it's just memory-starved.
|
| 59 |
+
|
| 60 |
+
## Use it
|
| 61 |
+
```bash
|
| 62 |
+
python dist/install_glm_dsa_patch.py # patch mlx_lm (venv AND LM Studio's bundled engine)
|
| 63 |
+
GLM_STREAM_EVAL=0 python -m mlx_lm.server --model models/GLM-5.2-q3a4-v4 \
|
| 64 |
+
--adapter-path heal/adapters-v4 # serve (OpenAI-compatible); v2 + heal/adapters also ship
|
| 65 |
+
# drive the 47-tool agent on your repo:
|
| 66 |
+
python scripts/57_tool_agent.py --repo /path/to/your/repo --apply --task "..." --test "cargo test"
|
| 67 |
+
# speed: try --dsa-block-size 32/64/128 (free, pick fastest). External draft is Metal-unstable here; MTP self-spec is the real path.
|
| 68 |
+
```
|
| 69 |
+
In **LM Studio**: run the patch, fully quit + reopen, then load the model.
|
| 70 |
+
|
| 71 |
+
## Performance (M5 Max 128 GB, v4)
|
| 72 |
+
| Metric | Value |
|
| 73 |
+
|---|---|
|
| 74 |
+
| Size | 99 GB (from 381 GB mxfp4 / ~1.5 TB bf16) |
|
| 75 |
+
| HumanEval pass@1 | **19/20 (95%)**, single-shot |
|
| 76 |
+
| Math GSM8K | **8/12 (66%)** β recovered from v3's **0/5** (code-first balanced calibration kept the math super-experts alive through the prune) |
|
| 77 |
+
| Algebra (SymPy-checked) | **3/4 (75%)** |
|
| 78 |
+
| Decode speed | **11.3 tok/s** (no draft) β see the speed note in limitations |
|
| 79 |
+
| Verified-decode checker | TS 0.3 ms Β· Python ~0 ms Β· Rust 34 ms |
|
| 80 |
+
|
| 81 |
+
## Honest limitations
|
| 82 |
+
- **Specialist:** ~70% of experts pruned β strong in the target niche, weaker outside it. Not the full 743B.
|
| 83 |
+
- **Speed ~11 tok/s decode** (reading pace; ~3 min for long thinking-ON answers). Partly MLX's still-naive
|
| 84 |
+
**DSA attention kernels** (mlx #837 / #3402 β *improves for free* as MLX matures), partly the bandwidth
|
| 85 |
+
cost of a 743B-class MoE on a laptop. **Measured dead-ends** (don't bother): 4-bit re-quant is *slower*
|
| 86 |
+
for single-token decode (bandwidth-bound, smaller wins); active-experts 8β4 gives no win at batch=1.
|
| 87 |
+
**Real path:** `--dsa-block-size` sweep (free) β upstream MLX β **MTP self-speculative** (~2.6Γ, a port
|
| 88 |
+
for this arch). Not a quant change.
|
| 89 |
+
- **Multilingual** ability reduced (optional vocab-trim drops ~31% of tokens).
|
| 90 |
+
- **Design** is competent but not yet design-soul-elite (correct structure, but missed OKLCH/grid when
|
| 91 |
+
tested) β the design-canon heal closes this.
|
| 92 |
+
- Prompt-cache can OOM under heavy concurrent load. The external speculative draft is **Metal-unstable**
|
| 93 |
+
on this MoE β **MTP self-speculative is the right path**; the external draft is not recommended.
|
| 94 |
+
|
| 95 |
+
## Attribution & license
|
| 96 |
+
**MIT.** Base model Β© **Z.ai** (`zai-org/GLM-5.2`, MIT-licensed) β so this derivative is MIT too: free
|
| 97 |
+
to use, modify, and redistribute **with attribution to Z.ai**. The demolition / healing / 47-tool agent
|
| 98 |
+
tooling is this repo's contribution.
|