{"slug": "show-hn-airmind-zig-and-metal-qwen4-35b-engine-and-local-agent-for-16gb-macs", "title": "Show HN: AirMind – Zig and Metal Qwen4-35B engine and local agent for 16GB Macs", "summary": "A developer released AirMind, a zero-dependency inference engine written from scratch in Zig 0.17.1 with custom Apple Metal GPU shaders, built to run the Qwen4-35B-A3B model and a built-in local coding agent on 16 GiB MacBooks without swap. In its default IQ2 Resident Mode, AirMind holds a 10.6 GiB UD-IQ2_XXS model fully in unified memory and reports 250–300 tok/s prefill and 25–36 tok/s decode, while a 4-bit streaming mode (--iq4) reaches 14–18 tok/s decode and 70–120 tok/s prefill on 16 GiB of RAM. The engine ships a disk-persisted KV+GDN prefix cache that restores 1,100+ system and tool tokens in about 54 ms on repeat launches, zero-RAM stochastic N-gram speculative decoding that accepts up to roughly 40% free tokens, 9 built-in agent tools, and an OpenAI-compatible HTTP server via `airmind serve`.", "body_md": "**Zero-dependency Zig + Apple Metal GPU inference engine and built-in local coding agent for Qwen4-35B-A3B — engineered to run fast on a 16 GiB MacBook.**\n\nAirMind compiles to a single native binary with **zero external runtime dependencies** (no Python runtime required for inference, no llama.cpp, no PyTorch, no HTTP hop between the agent and the model). Just run `./zig-out/bin/airmind` to launch a resident in-process coding & web agent powered by custom Metal shaders.\n\n- **From-Scratch Zig 0.17.1 + Native Apple Metal GPU**  - Custom `simdgroup_matrix` hardware GEMM prefill, 0-barrier warp QSA attention, 128-TG in-register GDN recurrence, and adaptive expert-grouped MoE.\n  - Full 13-format GGML quantization support (`F32` ,`F16` ,`BF16` ,`Q8_0` ,`Q4_K` ,`Q5_K` ,`Q6_K` ,`IQ4_NL` ,`IQ4_XS` ,`IQ3_XXS` ,`IQ2_S` ,`IQ2_XS` ,`IQ2_XXS` ), bit-exact against`libggml` .\n- Custom \n- **Built-In In-Process Coding & Web Agent (Default Mode)**  - Bare `./zig-out/bin/airmind` launches directly into an interactive coding agent with**zero HTTP overhead** between the agent loop and the GPU engine.\n  - **9 built-in tools** :\n    - Auto-run read-only: `list_files` ,`read_file` ,`grep_files` ,`web_search` (no API key),`web_fetch` ,`plot_chart` (Unicode sparkline + bar chart).\n    - Interactive approval (`[y]es / [n]o / [a]lways` or`--yolo` ):`write_file` ,`edit_file` ,`run_shell` .\n  - Auto-run read-only: \n  - **UTF-8 / CJK-aware terminal line editor** : full Left/Right/Home/End cursor navigation, mid-line insert/delete across wrapped Chinese + English text, Up/Down history, live prefill/tool-generation progress bars, and automatic two-stage context compaction.\n- Bare \n- **Instant Startup & Speculative Acceleration**  - **Disk-persisted KV+GDN prefix cache** (`/tmp/airmind_prefix_*.zqs` ): restores 1,100+ system + tool tokens in**~54 ms** on repeat launches (~1s cold boot to ready).\n  - **Zero-RAM Stochastic N-gram Speculative Decoding** : exact Leviathan rejection sampling compatible with`temperature` ,`min_p` , and`repeat_penalty` — accepts up to**~40% free tokens** when generating code & unit tests with**0 MiB** extra weights.\n- **Fits 16 GiB Apple Silicon Without Swap**  - **IQ2 Resident Mode (default on ≤18 GiB Macs)** : 10.6 GiB`UD-IQ2_XXS` fully resident in unified memory (`250–300 tok/s` prefill,`25–36 tok/s` decode).\n  - **4-Bit Streaming Mode (`--iq4`)** : explicit 2-slab GPU Hot-Expert LRU Cache + 8-thread` F_NOCACHE` NVMe streaming (`14–18 tok/s` decode,`70–120 tok/s` prefill on 16 GiB RAM, zero desktop lag).\n  - **Optional Loop4-HC v3.0 Recurrent Depth (`--smart` / `--deep`)** : zero-LoRA 34.8 MB BF16 Depth-AttnRes sidecar looping` L12..27` (`T=2/3` , Prompt-Split keeps full prefill speed) + bounded`--think-budget` .\n- **OpenAI-Compatible HTTP Server (`airmind serve`)**  - Full SSE streaming, OpenAI `tools` /`delta.tool_calls` /`role: \"tool\"` , and multi-conversation KV+GDN state snapshotting.\n- Full SSE streaming, OpenAI \n\n- **macOS on Apple Silicon** (M1/M2/M3/M4, 16 GiB+ Unified Memory recommended; pure-Zig CPU fallback included)\n- **Zig `0.17.1`** (` brew install zig` )\n\n```\n# One command: builds ReleaseFast binary + auto-downloads optimal model for your Mac's RAM\n# (<=18 GiB RAM -> IQ2_XXS + Loop4-HC sidecar; >=24 GiB RAM -> 4-bit IQ4_XS + Loop4-HC sidecar)\nzig build setup\n\n# Launch AirMind Local Coding Agent (zero flags needed!)\n./zig-out/bin/airmind\n```\n\nOther build & setup options:\n\n```\nzig build setup -Dmodel=iq2      # Force 2-bit full-resident model + Loop4-HC sidecar\nzig build setup -Dmodel=iq4      # Force 4-bit UD-IQ4_XS (hardlinks Shard 2 if IQ2 exists)\nzig build setup -Dmodel=all      # Download both IQ2 and IQ4 + Loop4-HC sidecar\nzig build                        # Offline build only (defaults to ReleaseFast)\nzig build test                   # Run full unit test suite (Debug safety checks)\n# Default: Built-in Local Coding Agent (auto-detects Apple Silicon RAM/cores & local models)\n./zig-out/bin/airmind\n\n# Extra reasoning presets\n./zig-out/bin/airmind --smart            # Loop4-HC v3.0 T=2 Prompt-Split (higher IQ, full prefill speed)\n./zig-out/bin/airmind --deep             # Loop4-HC T=2 + 320-token bounded <think> chain\n./zig-out/bin/airmind --iq4              # True 4-bit UD-IQ4_XS with GPU Hot-Expert LRU Cache + NVMe streaming\n./zig-out/bin/airmind --yolo             # Auto-approve write_file / edit_file / run_shell\n./zig-out/bin/airmind --no-agent         # Plain interactive chat REPL without tools\n\n# OpenAI-compatible HTTP Server (SSE + tool calling + multi-slot KV/GDN cache)\n./zig-out/bin/airmind serve --port 8080 -c 16384\n\n# Single-turn CLI chat / raw completion\n./zig-out/bin/airmind chat -p \"Explain Fermat's Little Theorem briefly\"\n./zig-out/bin/airmind --help\n```\n\n| Command | Action | \n|---|---|\n| `/agent` | Toggle built-in agent tools ON / OFF | \n| `/yolo` | Toggle auto-approval for `write_file` ,`edit_file` ,`run_shell` | \n| `/think` | Toggle Qwen4 `<think>` reasoning mode | \n| `/compact` | Compact older tool outputs / conversation history | \n| `/clear` | Clear conversation & instantly restore disk-cached system prompt | \n| `/stats` | Show context usage and last-turn speed | \n| `/quit` | Exit | \n\n| Mode | Memory Strategy | Prefill | Decode | Notes | \n|---|---|---|---|---|\n| `UD-IQ2_XXS` (default) | 10.6 GiB RAM resident | 210–300 tok/s | 28–36 tok/s | Zero SSD I/O; ~40% free tokens on code via 0-MiB N-gram spec | \n| `UD-IQ2_XXS --smart` | 10.7 GiB RAM resident | 200–290 tok/s | 15–22 tok/s | Loop4-HC `T=2` Prompt-Split (+33% on 10-problem math/logic bench) | \n| `UD-IQ4_XS --iq4` | 1.94 GiB dense + 8.7 GiB GPU LRU | 74–120 tok/s | 15–18 tok/s | Soft-threshold 4-bit streaming, zero swap on 16 GiB | \n| Repeat agent startup | Disk KV+GDN snapshot (85 MiB) | **54 ms** restore | — | Cold boot to interactive `Agent>` in ~1s | \n\n```\nsrc/\n├── main.zig           # CLI entry, Apple Silicon hardware probe, auto-config presets\n├── root.zig           # Library module exports & test root\n├── gguf.zig           # Zero-dependency multi-shard GGUF v3 parser + mmap\n├── quant.zig          # Pure-Zig CPU dequant & SIMD dot products (13 GGML formats)\n├── quant_tables.zig   # IQ2 / IQ3 / IQ4_NL / IQ4_XS lookup tables\n├── tokenizer.zig      # Native BPE tokenizer + Qwen4 special tokens\n├── sampler.zig        # 8-wide SIMD sampler (min_p, top_p, repeat_penalty, Leviathan spec verify)\n├── qwen4.zig          # Qwen4-35B-A3B architecture (GDN, QSA, Engram PLE, HC, MoE) CPU reference\n├── metal.zig          # Apple Metal GPU engine, batched prefill, state snapshots, MTP/N-gram spec\n├── qwen4.metal        # Custom Metal compute shaders (simdgroup_matrix, fused GDN/QSA/MoE/Loop)\n├── metal_bridge.h/.m  # Minimal Objective-C ARC Metal C-ABI bridge\n├── expert_cache.zig   # O(1) 2-slab GPU Hot-Expert LRU Cache + 8-thread F_NOCACHE NVMe streamer\n├── loop4hc.zig        # Zero-dependency safetensors parser & Loop4-HC v3.0 Depth-AttnRes loader\n├── agent.zig          # Built-in 9-tool local coding, web search/fetch & terminal chart agent\n└── server.zig         # In-process Agent REPL (UTF-8/CJK line editor, auto-compact) + OpenAI HTTP server\n```\n\n", "url": "https://wpnews.pro/news/show-hn-airmind-zig-and-metal-qwen4-35b-engine-and-local-agent-for-16gb-macs", "canonical_source": "https://github.com/fxsjy/AirMind", "published_at": "2026-12-06 06:42:00+00:00", "updated_at": "2026-12-06 06:45:17.490212+00:00", "lang": "en", "topics": ["ai-infrastructure", "ai-agents", "large-language-models", "ai-tools"], "entities": ["AirMind", "Zig", "Apple Metal", "Qwen4-35B-A3B", "Apple Silicon", "GGML", "OpenAI"], "also_reported_by": [], "takeaway": "AirMind runs Qwen4-35B-A3B on a 16 GiB Mac by keeping a 10.6 GiB UD-IQ2_XXS model fully resident in unified memory (25–36 tok/s decode) or streaming 4-bit weights through a 2-slab GPU hot-expert LRU cache (14–18 tok/s decode), with a disk-persisted KV+GDN prefix cache restoring 1,100+ tokens in ~54 ", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/show-hn-airmind-zig-and-metal-qwen4-35b-engine-and-local-agent-for-16gb-macs", "markdown": "https://wpnews.pro/news/show-hn-airmind-zig-and-metal-qwen4-35b-engine-and-local-agent-for-16gb-macs.md", "text": "https://wpnews.pro/news/show-hn-airmind-zig-and-metal-qwen4-35b-engine-and-local-agent-for-16gb-macs.txt", "jsonld": "https://wpnews.pro/news/show-hn-airmind-zig-and-metal-qwen4-35b-engine-and-local-agent-for-16gb-macs.jsonld"}}