Show HN: Getting GLM 5.2 running on my slow computer
🐦 Colibrì: Running GLM-5.2 on Low-Spec Hardware
Colibrì is a lightweight engine designed to execute the massive GLM-5.2 (744B Mixture-of-Experts) model on consumer-grade machines with as little as of RAM. It achieves this through a "zero-dependency" pure C implementation that streams model experts directly from the disk.
$ ./coli chat
🐦 colibrì v1.0 — GLM-5.2 · 744B MoE · int4 · streaming CPU ✓ pronto in 32s · residente 9.9 GB
› ciao!
🧠 The Core Concept
The fundamental insight is that while GLM-5.2 has parameters, it is a Mixture-of-Experts (MoE) model. This means for any single token, only parameters are actually activated. Specifically, only about of those parameters change between tokens (the routed experts).
The Strategy: Keep the "dense" components (embeddings, attention, and shared experts params) resident in RAM at
int4precision (). The routed experts (across MoE layers experts, plus the MTP head) are stored on disk () and streamed on-demand.
🛠️ Memory Hierarchy
The engine utilizes a multi-tiered caching system to minimize disk I/O latency:
- L1: Per-layer LRU cache.
- L2: OS page cache (automatic).
- Optional: A pinned "hot-store" for frequently used experts.
⚙️ Technical Implementation
The entire engine is remarkably compact, consisting of a single C file (c/glm.c, roughly lines) and a few headers. It avoids BLAS and Python at runtime, and while it doesn't require a GPU, it offers an optional CUDA tier for pinned experts.
✅ Feature Checklist
- Faithful Forward Pass: The
glm_moe_dsaimplementation is token-exact compared to thetransformersoracle. - MLA Attention: Implements q/kv-LoRA and interleaved partial RoPE.
- Compressed KV-Cache: Reduced from
32,768to floats per token (a reduction). - DeepSeek-V3 Router: Includes
noaux_tcandrouted_scaling_factor. - MTP Speculative Decoding: Uses the layer 78 multi-token-prediction head to draft tokens.
- Integer-Dot Kernels: AVX2
maddubsforint8activations, providing speedups. - Async Readahead: Uses
WILLNEEDto fetch the next expert block while the current one is processing. - DSA Sparse Attention: Faithful to the reference indexer, utilizing top-2048 causal key selection.
- KV-Cache Persistence: Saves state to
.coli_kv() for instant restarts. - BPE Tokenizer: A native C implementation of the GPT-2 style tokenizer with merges.
🔍 Deep Dive: Nuances & Optimizations
Speculative Decoding (MTP)
The MTP head must be int8. If run at int4, the acceptance rate drops to , rendering speculation useless. At int8, acceptance rises to , yielding tokens per forward pass.
Caveat: On a "cold" cache, the extra expert loads required for verification can actually slow down generation. The DRAFT=0 flag or the adaptive guard can be used to mitigate this.
MLA Weight Absorption
To optimize decoding, Colibrì uses the "DeepSeek trick" where the query absorbs , removing the need for per-token reconstruction.
Router-Lookahead (PILOT=1)
Experimental data shows that the next layer's routing is predictable from the current layer's post-attention state. A dedicated I/O thread uses this to prefetch experts.
RAM Safety
To prevent the Linux OOM-killer from terminating the process, the expert cache is dynamically sized at startup based on MemAvailable, accounting for:
📦 Conversion Process
The c/tools/convert_fp8_to_int4.py script allows for the creation of the int4 container without needing of free space.
The Workflow:
- Download one shard ().
- Dequantize (using block scales).
- Requantize into the Colibrì format.
- Delete the shard and repeat.
📊 Performance Metrics
Tested on: WSL2, 12 Cores, 25 GB RAM, NVMe via VHDX
| Metric | Value |
|---|---|
| Model Size on Disk (int4) | |
| Resident RAM (Dense int4) | |
| Initial Load Time | |
| Peak RSS (during chat) | (auto-capped) |
| Cold Decode Cost | disk read |