返回资讯中心
外部精选
软件工程
#开发者实时流

AirMind 发布 Zig 与 Metal 推理引擎,面向 16GB Mac 本地运行 Qwen4-35B

来源标题:Show HN: AirMind – Zig and Metal Qwen4-35B engine and local agent for 16GB Macs

AirMind 推出零依赖的 Zig + Apple Metal GPU 推理引擎,并内置本地编程代理,可在 16 GiB MacBook 上运行 Qwen4-35B-A3B。项目编译为单一原生二进制,推理不依赖 Python、llama.cpp 或 PyTorch,代理与模型之间也没有 HTTP 中转。引擎支持全部 13 种 GGML 量化格式,结果与 libggml 逐位一致。

Hacker News 最新fxsjy2026/12/6 · 今天16 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

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.

AirMind 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.

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.

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.

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.

9 built-in tools:

Auto-run read-only: list_files, read_file, grep_files, web_search (no API key), web_fetch, plot_chart (Unicode sparkline + bar chart).

Interactive approval ([y]es / [n]o / [a]lways or --yolo): write_file, edit_file, run_shell.

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.

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).

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.

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).

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).

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.

OpenAI-Compatible HTTP Server (airmind serve)

Full SSE streaming, OpenAI tools / delta.tool_calls / role: "tool", and multi-conversation KV+GDN state snapshotting.

Requirements

macOS on Apple Silicon (M1/M2/M3/M4, 16 GiB+ Unified Memory recommended; pure-Zig CPU fallback included)

Zig 0.17.1 (brew install zig)

Quick Start

One command: builds ReleaseFast binary + auto-downloads optimal model for your Mac's RAM

(<=18 GiB RAM -> IQ2_XXS + Loop4-HC sidecar; >=24 GiB RAM -> 4-bit IQ4_XS + Loop4-HC sidecar)

zig build setup

Launch AirMind Local Coding Agent (zero flags needed!)

./zig-out/bin/airmind

Other build & setup options:

zig build setup -Dmodel=iq2 # Force 2-bit full-resident model + Loop4-HC sidecar zig build setup -Dmodel=iq4 # Force 4-bit UD-IQ4_XS (hardlinks Shard 2 if IQ2 exists) zig build setup -Dmodel=all # Download both IQ2 and IQ4 + Loop4-HC sidecar zig build # Offline build only (defaults to ReleaseFast) zig build test # Run full unit test suite (Debug safety checks)

Usage & Presets

Default: Built-in Local Coding Agent (auto-detects Apple Silicon RAM/cores & local models)

./zig-out/bin/airmind

Extra reasoning presets

./zig-out/bin/airmind --smart # Loop4-HC v3.0 T=2 Prompt-Split (higher IQ, full prefill speed) ./zig-out/bin/airmind --deep # Loop4-HC T=2 + 320-token bounded <think> chain ./zig-out/bin/airmind --iq4 # True 4-bit UD-IQ4_XS with GPU Hot-Expert LRU Cache + NVMe streaming ./zig-out/bin/airmind --yolo # Auto-approve write_file / edit_file / run_shell ./zig-out/bin/airmind --no-agent # Plain interactive chat REPL without tools

OpenAI-compatible HTTP Server (SSE + tool calling + multi-slot KV/GDN cache)

./zig-out/bin/airmind serve --port 8080 -c 16384

Single-turn CLI chat / raw completion

./zig-out/bin/airmind chat -p "Explain Fermat's Little Theorem briefly" ./zig-out/bin/airmind --help

Interactive Slash Commands

Command Action

/agent Toggle built-in agent tools ON / OFF

/yolo Toggle auto-approval for write_file, edit_file, run_shell

/think Toggle Qwen4 <think> reasoning mode

/compact Compact older tool outputs / conversation history

/clear Clear conversation & instantly restore disk-cached system prompt

/stats Show context usage and last-turn speed

/quit Exit

Benchmarks (Apple M4 16 GiB, Qwen4-35B-A3B)

Mode Memory Strategy Prefill Decode Notes

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

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)

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

Repeat agent startup Disk KV+GDN snapshot (85 MiB) 54 ms restore — Cold boot to interactive Agent> in ~1s

Project Structure

src/ ├── main.zig # CLI entry, Apple Silicon hardware probe, auto-config presets ├── root.zig # Library module exports & test root ├── gguf.zig # Zero-dependency multi-shard GGUF v3 parser + mmap ├── quant.zig # Pure-Zig CPU dequant & SIMD dot products (13 GGML formats) ├── quant_tables.zig # IQ2 / IQ3 / IQ4_NL / IQ4_XS lookup tables ├── tokenizer.zig # Native BPE tokenizer + Qwen4 special tokens ├── sampler.zig # 8-wide SIMD sampler (min_p, top_p, repeat_penalty, Leviathan spec verify) ├── qwen4.zig # Qwen4-35B-A3B architecture (GDN, QSA, Engram PLE, HC, MoE) CPU reference ├── metal.zig # Apple Metal GPU engine, batched prefill, state snapshots, MTP/N-gram spec ├── qwen4.metal # Custom Metal compute shaders (simdgroup_matrix, fused GDN/QSA/MoE/Loop) ├── metal_bridge.h/.m # Minimal Objective-C ARC Metal C-ABI bridge ├── expert_cache.zig # O(1) 2-slab GPU Hot-Expert LRU Cache + 8-thread F_NOCACHE NVMe streamer ├── loop4hc.zig # Zero-dependency safetensors parser & Loop4-HC v3.0 Depth-AttnRes loader ├── agent.zig # Built-in 9-tool local coding, web search/fetch & terminal chart agent └── server.zig # In-process Agent REPL (UTF-8/CJK line editor, auto-compact) + OpenAI HTTP server

License

MIT

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →