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 research/mlx_speed_deepdive.md with huggingface_hub
Browse files
research/mlx_speed_deepdive.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Can we code MLX ourselves for more decode speed? (June 2026 deep dive)
|
| 2 |
+
|
| 3 |
+
**Question:** the agentic coder's one weakness is decode speed (~11β14 tok/s). Can custom MLX/Metal code beat it?
|
| 4 |
+
|
| 5 |
+
## The wall (unchanged, re-confirmed)
|
| 6 |
+
Decode is **memory-bandwidth-bound** β generation speed β *bytes moved per token* (every token streams the active
|
| 7 |
+
expert weights through the memory bus). TTFT is compute-bound (and the M5 fixes that); decode is not. Our **#33 fused
|
| 8 |
+
MoE dequant-matmul Metal kernel already IS the 11β14 tok/s** β it maxed the compute side. You cannot out-*compute*
|
| 9 |
+
bandwidth. "More speed" = fewer bytes/token, or faster per-byte processing on M5 hardware.
|
| 10 |
+
|
| 11 |
+
## Lever 1 β NVFP4 on the M5 hardware path *(easy, no custom code, biggest, do first)*
|
| 12 |
+
- **We already have it** (probed: `mx.quantize(..., mode="nvfp4", group_size=16)` works on our MLX 0.31.2).
|
| 13 |
+
- **Round-trip fidelity:** affine-3bit mean|err| **0.159** vs **NVFP4-4bit 0.077** β *half the quantization damage.*
|
| 14 |
+
- **M5 hardware path:** the Neural Accelerators have a native NVFP4 dequant+matmul; a 35B-A3B MoE went **58β112 tok/s
|
| 15 |
+
(2Γ)** on M5 Max with NVFP4. It's 4-bit (more bytes than our 3-bit) but the hardware path + better fidelity net a win.
|
| 16 |
+
- **Action:** re-quantize the 4-bit layers in **#59** as NVFP4 (group 16), keep the middle 3-bit affine; measure decode.
|
| 17 |
+
Zero custom code β just the quant mode + a `04b/24b` NVFP4 path.
|
| 18 |
+
|
| 19 |
+
## Lever 2 β a Metal-4 **TensorOps** fused-MoE kernel *(the "code it ourselves" win, ~30β60%)*
|
| 20 |
+
- **#33's kernel predates the M5** β it uses plain Metal, not the **Neural Accelerators' hardware matmul** (Metal 4
|
| 21 |
+
TensorOps). MLX gets 30β60% on M5 by using TensorOps; a *custom* MoE kernel that does too captures that for our model.
|
| 22 |
+
- **How:** `mx.fast.metal_kernel` + Metal 4 **TensorOps** β slice the gather'd expert weights into tiles, tile-wise
|
| 23 |
+
matmul on the Neural Accelerators, keep data in cache (WWDC26 session 330 "Optimize custom ML operations with Metal
|
| 24 |
+
tensors" is the recipe). Fuse: expert-gather β NVFP4-dequant β matmul β accumulate, in one dispatch.
|
| 25 |
+
- **Effort:** real Metal work (~weeks). Reference impls exist (TurboQuant-MLX fused kernels; simdgroup-MMA int4-MoE kernels).
|
| 26 |
+
|
| 27 |
+
## Honest ceiling
|
| 28 |
+
Neither lever breaks the bandwidth wall β they reduce bytes (NVFP4) and speed per-byte (TensorOps on the Accelerators).
|
| 29 |
+
Realistic: **11β14 β ~20β28 tok/s** from NVFP4+M5 alone; **~30+** with the custom TensorOps kernel. A genuine **2β3Γ**,
|
| 30 |
+
not 100+. Speculative decode stays dead on this MoE (any multi-token verify reloads ~all experts β the bandwidth wall again).
|
| 31 |
+
|
| 32 |
+
## Plan (CPU now β GPU later)
|
| 33 |
+
1. **NVFP4 re-quant** β wire `nvfp4` (group 16) into `04b`/`24b` as the 4-bit-layer format for #59; re-quant; **measure decode** (the proof).
|
| 34 |
+
2. If the gain lands and we want more β **write the Metal-4 TensorOps fused-MoE kernel** (the 30β60% lever); benchmark vs #33.
|
| 35 |
+
3. Keep the verify-everything stack (constrained decode, compiler-steer) intact β none of this touches it.
|
| 36 |
+
|
| 37 |
+
*Sources: MLX custom Metal kernels (ml-explore docs 0.31.2) Β· `mx.fast.metal_kernel` Β· WWDC26 #330 Metal tensors Β·
|
| 38 |
+
Apple "LLMs with MLX + M5 Neural Accelerators" Β· TurboQuant-MLX fused kernels Β· MLX-vs-llama.cpp M5 benchmarks (yage.ai 2026) Β· our SPEED.md root-cause.*
|