{"slug": "colibri-ran-glm-5-2-744b-moe-bnekhruue-ng-25gb-ram-dwy-pure-c-aiflediiyw", "title": "Colibri — รัน GLM-5.2 (744B MoE) บนเครื่อง 25GB RAM ด้วย Pure C ไฟล์เดียว", "summary": "A developer known as Nokka built Colibri, a pure C inference engine (~2,400 lines, zero dependencies) that runs the 744B-parameter GLM-5.2 Mixture-of-Experts model on a consumer machine with only 25 GB of RAM and no GPU. The engine achieves this by keeping the dense part (~9.9 GB) in RAM while streaming the 21,504 routed experts (~370 GB) from NVMe on demand, achieving 0.05-0.1 tokens per second. GLM-5.2, released by Z.ai under MIT license, uses techniques like Multi-head Latent Attention and DeepSeek Sparse Attention to reduce memory and compute requirements.", "body_md": "*โดย Nokka (นก-กา) | 11 กรกฎาคม 2026*\n\n*บทความนี้เขียนโดย AI (DeepSeek V4 Pro) ผ่าน Hermes Agent ภายใต้การควบคุมและตรวจสอบคุณภาพโดยมนุษย์ — Nokka (นก-กา)*\n\nColibri คือ inference engine ที่เขียนด้วย **Pure C ไฟล์เดียว (~2,400 บรรทัด) — zero dependencies — ไม่ต้องใช้ GPU** — รัน GLM-5.2 โมเดล 744B พารามิเตอร์ บนเครื่อง consumer ที่มี RAM แค่ 25 GB ได้ [1]\n\nเทคนิคหลัก: แยกโมเดลเป็นสองส่วน — **dense part (~9.9 GB)** อยู่ใน RAM ตลอดเวลา ส่วน **routed experts 21,504 ตัว (~370 GB)** อยู่บน NVMe และถูก stream เข้ามาเฉพาะตอนที่ router เลือกใช้ — เหลือ RAM ว่าง ~15 GB สำหรับ LRU cache และ OS page cache [1]\n\nความเร็ว: 0.05-0.1 tok/s บน dev machine (WSL2, 12 cores, 25 GB RAM) — ไม่เร็ว แต่มันคือ **744B frontier model ที่ตอบถูกต้องบนเครื่องที่ราคาถูกกว่า H100 หนึ่งใบ** [1]\n\n```\n$ ./coli chat\n  🐦 colibrì v1.0 — GLM-5.2 · 744B MoE · int4 · streaming CPU\n  ✓ pronto in 32s · residente 9.9 GB\n  › ciao!\n  ◆ Ciao! 😊 Come posso aiutarti oggi?\n```\n\n32 วินาทีในการโหลด — 9.9 GB resident — แล้ว GLM-5.2 ก็พร้อมตอบบนเครื่อง 25 GB RAM [1]\n\nGLM-5.2 คือ **Mixture-of-Experts (MoE) โมเดล 744B พารามิเตอร์** จาก Z.ai — เปิดตัว 13 มิถุนายน 2026 — MIT license — หนึ่งใน open-weight model ที่แข็งแกร่งที่สุดในปัจจุบัน [5][6]\n\n| สเปค | ค่า |\n|---|---|\n| Total parameters | 744B |\n| Active per token | ~40B |\n| MoE layers | 75 |\n| Experts per layer | 256 (8 active + 1 shared) |\n| Context window | 1M tokens |\n| Attention | MLA (Multi-head Latent Attention) + DSA (DeepSeek Sparse Attention) |\n| Router | DeepSeek-V3-style sigmoid (noaux_tc) |\n| License | MIT |\n\n**MoE ทำงานยังไง:** แทนที่จะใช้ทั้ง 744B พารามิเตอร์ทุก token — GLM-5.2 ใช้ router เลือกแค่ 8 experts จาก 256 ตัวต่อ layer — รวมแล้ว activate แค่ ~40B พารามิเตอร์ต่อ token — ที่เหลือ ~700B นอนเฉยๆ [1][5]\n\n**นี่คือกุญแจที่ทำให้ Colibri ทำงานได้:** เพราะแต่ละ token ใช้แค่ ~11 GB ของ expert weights — Colibri เลยเก็บ experts ไว้บน disk แล้ว stream เฉพาะตัวที่ถูกเลือกเข้ามา [1]\n\n```\n┌─────────────────────────────────────────┐\n│ RAM (Resident — ~9.9 GB int4)           │\n│  • Dense layers (attention, shared      │\n│    experts, embeddings) — ~17B params   │\n│  • LRU Expert Cache (auto-sized)        │\n│  • Pinned Hot Experts (learning cache)  │\n│  • Compressed MLA KV-cache              │\n├─────────────────────────────────────────┤\n│ NVMe (Streamed — ~370 GB int4)          │\n│  • 21,504 routed experts               │\n│  • 75 MoE layers × 256 experts          │\n│  • ~19 MB per expert at int4            │\n│  • Streamed on-demand per token         │\n└─────────────────────────────────────────┘\n```\n\n**Dense part** (~17B params → ~9.9 GB int4): attention weights, shared experts, embeddings — ใช้ทุก token → อยู่ใน RAM ตลอด\n\n**Routed experts** (21,504 ตัว → ~370 GB int4): ถูก router เลือกใช้แค่ 8 ตัวต่อ layer ต่อ token — อยู่บน NVMe — stream เข้ามาเฉพาะตอนถูกเลือก [1]\n\nGLM-5.2 ใช้ **Multi-head Latent Attention (MLA)** — เทคนิคจาก DeepSeek-V3 — แทนที่จะเก็บ full KV-cache (32,768 floats/token สำหรับ 64 heads) — MLA ใช้ low-rank projection บีบเหลือแค่ **576 floats/token** — เล็กลง 57 เท่า [1]\n\nColibri ยัง implement **MLA weight absorption** (DeepSeek trick) — query ดูดซับ kv_b projection — ไม่ต้อง reconstruct k/v ต่อ token — validated token-exact เทียบกับ transformers oracle [1]\n\n**KV-cache persistence:** Colibri เซฟ compressed MLA KV-cache ลงดิสก์หลังทุก turn (~182 KB/token, crash-safe) — ปิดแชทแล้วเปิดใหม่พรุ่งนี้ — โมเดลยังจำบทสนทนาทั้งหมด — validated byte-identical กับ session ที่ไม่เคยถูกขัดจังหวะ [1]\n\nGLM-5.2 ใช้ **DeepSeek Sparse Attention (DSA)** — แทนที่จะ attend ทุก token ใน context — DSA ใช้ learned indexer เลือก top-2,048 keys ต่อ layer — ลด compute จาก O(n²) เป็น O(n × 2048) [1][5]\n\nColibri implement DSA แบบ faithful — auto-detect จาก out-idx weights — validated: forcing ให้ keep ทุก key reproduce dense attention token-for-token [1]\n\nGLM-5.2 มี **Multi-Token Prediction (MTP) head** ที่ layer 78 — มัน draft tokens ล่วงหน้า แล้ว main model verify ใน batched forward ครั้งเดียว [1]\n\n| MTP head precision | Draft acceptance | Tokens/forward |\n|---|---|---|\n| int4 | 0-4% | ~1.0 (ไม่เวิร์ค) |\nint8 |\n39-59% |\n2.2-2.8 |\n\n**สำคัญ:** MTP head ต้องเป็น int8 — ที่ int4 draft acceptance ตกเหลือ 0-4% — speculation ไม่เกิด — converter ทำ int8 ให้อัตโนมัติ [1]\n\n**ข้อควรระวัง:** cold cache — แต่ละ verified draft route ไปหา experts เพิ่ม (~660 → ~1,100 expert-loads/token) — speculation อาจช้าลงจนกว่า cache/pin จะอุ่น — adaptive guard และ `DRAFT=0`\n\nมีไว้สำหรับกรณีนี้ [1]\n\nColibri ใช้ hand-tuned integer matmul kernels:\n\n| Kernel | Speed vs baseline | ใช้เมื่อไหร่ |\n|---|---|---|\n| int8 (Q8_0-style, AVX2 maddubs) | 1.4-2.5× faster | matmul ทั่วไป |\n| int4 (packed, dequant-on-use) | 1.8× in batch | expert matmul |\n| int4 single-row | slower → fallback to f32 | routing decision |\n\n119 GFLOP/s measured — routing ตัดสินใจต่อ shape โดย measurement — int4 single-row วัดแล้วช้ากว่า f32 เลย fallback [1]\n\n**Async readahead:** ขณะที่ kernel กำลังคูณ expert block หนึ่ง — kernel ถัดไปกำลังอ่าน expert ถัดไปจาก disk (WILLNEED) [1]\n\n**Router-lookahead prefetch (PILOT=1, experimental):** GLM-5.2's expert routing สามารถทำนายล่วงหน้าได้ — เอา router ของ layer L+1 มารันบน post-attention state ของ layer L — recall 71.6% ของ top-8 จริง (เทียบกับ 41.3% สำหรับ \"ใช้ expert เดิมกับ token ที่แล้ว\") — I/O thread แยก prefetch experts ที่น่าจะถูกใช้ขณะที่ layer ปัจจุบันกำลัง compute [1]\n\nColibri บันทึกว่า experts ตัวไหนถูกใช้บ่อย (.coli_usage — อัปเดตทุก turn) — ตอน startup จะ pin experts ที่ร้อนที่สุดไว้ใน RAM ว่างโดยอัตโนมัติ — **Colibri เร็วยิ่งขึ้นเมื่อคุณใช้มันมากขึ้น** [1]\n\n**Live tier adaptation (--repin N):** ทุก N tokens — session heat map แบบ decaying จะแทนที่ cold pinned experts ด้วย hot streamed experts — 25% hysteresis + four-swap limit ป้องกัน tier thrashing [1]\n\n**Batch-Union MoE:** ใน prefill และ MTP verification — expert แต่ละตัวที่ถูกเลือกโดย batch จะถูกอ่านครั้งเดียวแล้ว apply กับทุก position ที่ route ไปหามัน [1]\n\n**RAM safety:** expert cache auto-sized จาก MemAvailable ตอน startup — honest peak projection (working set, KV, MTP row, reconstruction buffers) — kernel OOM-killer ไม่เคยถูกยิง [1]\n\n| Metric | Value |\n|---|---|\n| Model on disk (int4) | ~370 GB |\n| Resident RAM | 9.9 GB |\n| Load time | ~30 s |\n| Peak RSS | ~20 GB (auto-capped) |\n| Cold decode cost | ~11 GB disk reads/token |\n| Disk ceiling (VHDX random) | ~1 GB/s |\nCold speed |\n~0.05–0.1 tok/s |\n| MTP speculation | 2.2–2.8 tok/forward |\n\n| Machine | Disk (iobench) | Config | Speed |\n|---|---|---|---|\n| Intel Core Ultra 7 270K Plus (24 threads) · WSL2 · 24 GB RAM | 1.96 GB/s buffered | default | 0.07 tok/s |\n| 〃 | 〃 | --topp 0.7 | 0.11 tok/s |\nApple M5 Max (18 cores) · 128 GB unified · internal SSD |\n14.2 GB/s O_DIRECT | default, MTP off | 1.06 tok/s |\n| Framework 13 (learned cache) | — | — | 0.37 tok/s |\n| Ryzen 9 9950X · PCIe 5.0 NVMe | — | — | 0.28 tok/s |\n| Epyc 9654 ES · Linux · DDR5-4800 | — | MTP on | 0.40 tok/s |\n\n| Hardware | Expected |\n|---|---|\n| PCIe4 NVMe (~3-5 GB/s random), 32 GB | ~0.5–1 tok/s |\n| PCIe5 NVMe หรือ 2×NVMe RAID0 (~8-12 GB/s), 64 GB (PIN ~40 GB) | ~2–4 tok/s |\n| 128-256 GB RAM, 12 cores (hot experts cached) | ~2–4 tok/s (matmul-bound) |\n| Same RAM + 24-32 cores หรือ AVX-512/VNNI kernels | ~5–15 tok/s (interactive) |\n\n**คอขวด:** ต่ำกว่า 5 GB/s → disk-bound — เกิน 5 GB/s → CPU matmul-bound — เพิ่ม cores ช่วยได้ [1]\n\nColibri มี `coli serve`\n\n— OpenAI-compatible HTTP API — text-only — SSE streaming:\n\n```\nCOLI_MODEL=/nvme/glm52_i4 COLI_API_KEY=*** ./coli serve \\\n  --host 127.0.0.1 --port 8000 --model-id glm-5.2-colibri\n\ncurl http://127.0.0.1:8000/v1/chat/completions \\\n  -H 'Authorization: Bearer ***' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n    \"model\": \"glm-5.2-colibri\",\n    \"messages\": [{\"role\": \"user\", \"content\": \"Hello\"}],\n    \"stream\": true\n  }'\n```\n\n**Endpoints:** `GET /v1/models`\n\n, `GET /v1/models/{model}`\n\n, `POST /v1/chat/completions`\n\n, `POST /v1/completions`\n\n[1]\n\n**Isolated KV contexts (--kv-slots N):** แยก conversation contexts ได้สูงสุด 16 slots — แต่ละ slot มี KV-cache, MTP window, และ crash-safe persistence file ของตัวเอง — engine ยัง execute ทีละ sequence — นี่คือ explicit KV ownership ไม่ใช่ continuous batching ปลอมๆ [1]\n\n**Extension enable_thinking: true:** เปิด GLM-5.2's reasoning block —\n\n`reasoning_effort`\n\nfield ก็ใช้ได้เหมือนกัน [1]`web/`\n\n— React + TypeScript (~390 lines) — pure API client — พูด OpenAI Chat Completions protocol + SSE streaming — ใช้ได้กับ Colibri server หรือ endpoint อะไรก็ได้ที่ compatible [1]\n\nColibri มี opt-in CUDA backend สำหรับ model-resident tensors — **streaming experts ยังอยู่บน CPU path** — เพราะการ copy expert จาก NVMe → GPU ทุกครั้งแค่เปลี่ยนคอขวดจาก disk เป็น PCIe [1]\n\n```\nmake CUDA=1\nCOLI_CUDA=1 COLI_GPU=0 CUDA_DENSE=1 ./glm 64 4 4\n```\n\n**Multi-GPU expert tier:** ปัก experts ที่ร้อนที่สุดใน VRAM แบบถาวร — budget แบ่งตาม device ที่โหลดน้อยที่สุด:\n\n```\nCOLI_CUDA=1 COLI_GPUS=0,1,2,3,4,5 CUDA_EXPERT_GB=96 \\\nPIN=stats.txt PIN_GB=160 ./glm 64 4 4\n```\n\n**ข้อจำกัดปัจจุบัน:** devices ใช้ independent contexts — synchronous host-staged activation copies — ยังไม่มี P2P/NCCL — kernels เป็น correctness-first custom kernels ยังไม่ใช่ cuBLAS/Tensor Core [1]\n\n`c/tools/convert_fp8_to_int4.py`\n\n— ดาวน์โหลดทีละ shard (~5 GB) — dequant (128×128 block scales) — requantize เป็น container ของ engine — ลบ shard — **756 GB FP8 checkpoint ไม่เคยต้องอยู่บนดิสก์พร้อมกัน** — resumable [1]\n\nหรือใช้ pre-converted model บน Hugging Face: `jlnsrk/GLM-5.2-colibri-int4`\n\n(~370 GB) [3]\n\n| Use Case | ทำไมถึงเหมาะ |\n|---|---|\nBatch processing |\nLegal document review, large corpus analysis, offline summarization — queue งานแล้วรอ — 2,000-token response ใช้เวลา 30-100 นาที — โอเคสำหรับ overnight jobs [2] |\nPrivacy-sensitive data |\nMedical notes, confidential business analysis, personal data — ไม่มี API call, ไม่มี telemetry, ไม่มี cloud — ข้อมูลไม่เคยออกจากเครื่อง [2] |\nResearch & Evaluation |\nGLM-5.2 คือ MIT-licensed — รัน evaluation harnesses, ศึกษา model behavior, fine-tune — zero marginal cost ต่อ token [2] |\nEarly Exploration |\nรัน prompt สองสามพันครั้งผ่าน GLM-5.2 เพื่อเข้าใจ capabilities ก่อน commit API contract — ช้าดีกว่าแพง [2] |\nInteractive (ใกล้ถึงแล้ว) |\n1 tok/s บน M5 Max — ยังไม่ใช่ production speed แต่ใช้ทดลอง interactive ได้ — PCIe 5.0 machines กำลังเข้าใกล้ความเร็วที่ใช้ได้จริง [2] |\n\n| Use Case | ทำไมถึงไม่เหมาะ |\n|---|---|\nInteractive chatbot |\n0.1 tok/s — ใช้ไม่ได้ — มนุษย์รอไม่ไหว [2] |\nCoding assistant |\nรอ 10 นาทีเพื่อ complete function — ไม่ใช่ assistant [2] |\nProduction API |\nSingle-generation-at-a-time — concurrent requests เข้าคิว — ไม่ใช่ horizontal scaling [1] |\nLow-latency anything |\nDisk คือคอขวด — latency วัดเป็นนาที ไม่ใช่มิลลิวินาที |\n\nColibri ทลายความเชื่อที่ว่า \"744B model ต้องใช้ H100 8 ใบ\" — มันพิสูจน์ว่าถ้าคุณเข้าใจ architecture ของโมเดล (MoE sparsity, MLA compression, DSA sparse attention) — คุณสามารถรันมันบนเครื่องที่ราคาถูกกว่า H100 หนึ่งใบได้ [1]\n\n`c/glm.c`\n\n— ~2,400 บรรทัด — ไฟล์เดียว — ไม่มี BLAS, ไม่มี Python runtime, ไม่มี Docker — แค่ gcc + OpenMP + AVX2 [1]\n\nสำหรับโปรแกรมเมอร์ที่อยากเข้าใจว่า inference engine ทำงานยังไง — นี่คือ codebase ที่อ่านจบได้ในบ่ายเดียว\n\nแทนที่จะพยายามทำทุกอย่างให้เร็วตั้งแต่แรก — Colibri ยอมรับว่ามันช้า — แล้วใช้ learning cache ทำให้เร็วขึ้นเมื่อคุณใช้มันมากขึ้น — นี่คือแนวคิดที่ต่างจาก \"optimize for first token\" ที่ทุกคนทำ [1]\n\nMTP head ที่ int8 — 39-59% draft acceptance — 2.2-2.8 tokens/forward — **lossless** — validated ด้วย rejection sampling — นี่คือเทคนิคที่ทุก inference engine ควรมี [1]\n\nCompressed MLA KV-cache — 576 floats/token — เซฟลงดิสก์หลังทุก turn — crash-safe — เปิดใหม่พรุ่งนี้ — zero re-prefill — นี่คือ feature ที่แม้แต่ ChatGPT ยังไม่มี [1]\n\n| ข้อจำกัด | รายละเอียด |\n|---|---|\nความเร็ว |\n0.05-1 tok/s — ไม่ใช่ interactive speed |\nDisk |\nต้องการ NVMe ~400 GB — ext4 — ห้าม network/9p mount |\nCPU-only |\nAVX2 required — ARM ไม่รองรับ (ยกเว้น Apple Silicon ผ่าน Rosetta? — ยังไม่ test) |\nSingle sequence |\nExecute ทีละ sequence — concurrent requests เข้าคิว |\nText-only |\nAPI เป็น text-only — ไม่มี image/audio input |\nLinux/WSL2 |\nไม่มี native Windows build — macOS ยัง experimental |\nMTP head ต้อง int8 |\nint4 MTP head ใช้ไม่ได้ — ต้องโหลด int8 head แยก |\n\nColibri ไม่ได้พยายามเป็น inference engine ที่เร็วที่สุด — มันพยายามเป็น **inference engine ที่เล็กที่สุดที่ยังตอบถูกต้อง** — และมันทำสำเร็จ\n\nสำหรับโปรแกรมเมอร์ — Colibri คือ:\n\n**ลองวันนี้:**\n\n```\ngit clone https://github.com/JustVugg/colibri\ncd colibri/c && ./setup.sh\nhf download jlnsrk/GLM-5.2-colibri-int4 --local-dir /nvme/glm52_i4\nCOLI_MODEL=/nvme/glm52_i4 ./coli chat\n```\n\n*แล้วคุณจะได้คุยกับ 744B frontier model — บนเครื่องคุณเอง — โดยไม่ต้องใช้ GPU สักใบ*\n\n[1] JustVugg, \"colibri — Run GLM-5.2 (744B MoE) on a 25GB-RAM consumer machine\", GitHub, July 2026. [https://github.com/JustVugg/colibri](https://github.com/JustVugg/colibri)\n\n[2] ChatForest (Grove), \"Colibri Runs a 744B Model on 25 GB of RAM — Here Is the Architecture and When It Makes Sense for Builders\", July 11, 2026. [https://chatforest.com/builders-log/colibri-engine-glm-5-2-744b-local-inference-disk-streaming-moe-builder-guide/](https://chatforest.com/builders-log/colibri-engine-glm-5-2-744b-local-inference-disk-streaming-moe-builder-guide/)\n\n[3] jlnsrk, \"GLM-5.2-colibri-int4\", Hugging Face, July 2026. [https://huggingface.co/jlnsrk/GLM-5.2-colibri-int4](https://huggingface.co/jlnsrk/GLM-5.2-colibri-int4)\n\n[4] PromptZone, \"Colibri Runs GLM 5.2 on Low-End Hardware\", July 2026. [https://www.promptzone.com/priya_sharma_8c5c4c03/colibri-runs-glm-52-on-low-end-hardware-4gbd](https://www.promptzone.com/priya_sharma_8c5c4c03/colibri-runs-glm-52-on-low-end-hardware-4gbd)\n\n[5] Luca Berton, \"GLM-5.2 744B: Sparse Attention Meets Efficient MoE\", June 2026. [https://lucaberton.com/blog/glm-5-2-744b-moe-architecture-2026/](https://lucaberton.com/blog/glm-5-2-744b-moe-architecture-2026/)\n\n[6] Labellerr, \"7 Top Mixture of Experts AI Models for Developers in 2026\", June 2026. [https://www.labellerr.com/blog/top-open-source-moe-llms/](https://www.labellerr.com/blog/top-open-source-moe-llms/)", "url": "https://wpnews.pro/news/colibri-ran-glm-5-2-744b-moe-bnekhruue-ng-25gb-ram-dwy-pure-c-aiflediiyw", "canonical_source": "https://dev.to/sarantoon/colibri-ran-glm-52-744b-moe-bnekhruueng-25gb-ram-dwy-pure-c-aiflediiyw-3ae9", "published_at": "2026-07-12 09:00:39+00:00", "updated_at": "2026-07-12 09:14:18.586870+00:00", "lang": "en", "topics": ["artificial-intelligence", "large-language-models", "ai-infrastructure", "ai-research", "developer-tools"], "entities": ["Nokka", "Colibri", "GLM-5.2", "Z.ai", "DeepSeek", "DeepSeek-V3", "Hermes Agent", "DeepSeek V4 Pro"], "alternates": {"html": "https://wpnews.pro/news/colibri-ran-glm-5-2-744b-moe-bnekhruue-ng-25gb-ram-dwy-pure-c-aiflediiyw", "markdown": "https://wpnews.pro/news/colibri-ran-glm-5-2-744b-moe-bnekhruue-ng-25gb-ram-dwy-pure-c-aiflediiyw.md", "text": "https://wpnews.pro/news/colibri-ran-glm-5-2-744b-moe-bnekhruue-ng-25gb-ram-dwy-pure-c-aiflediiyw.txt", "jsonld": "https://wpnews.pro/news/colibri-ran-glm-5-2-744b-moe-bnekhruue-ng-25gb-ram-dwy-pure-c-aiflediiyw.jsonld"}}