AIFeed

Show HN: Sinterl 4 persistent LLM engine in Rust (3.1x mlx-lm on Qwen4)

Original text(via HN AI)

sinter

题图
题图

A pure Rust + hand-fused Metal 4 persistent LLM inference engine for Apple Silicon, supporting Qwen4 (qwen4_moe with Hyper-Connections, zero-copy mmap PLE n-gram tables, QSA, and native MTP), Qwen3.5 / Qwen3.6 / Qwen3-Next MoE, Standard MoE, and Dense GQA Transformers (Qwen3, Llama 3, Mistral, Qwen2) with lossless speculative decoding and one-command Hugging Face downloads.

sinter reads config.json at load time, injects model-specific constants into hand-tuned Metal 4 shaders, fuses all transformer layers into a single persistent GPU kernel, packs 4-bit weights into unified GPU-private buffers, and serves an OpenAI-compatible HTTP API with zero quality loss by default.

Supported Models

Qwen4 Hybrid MoE (qwen4_moe)

Native Metal 4 persistent kernels for Qwen4's 4-stream Hyper-Connections, zero-copy mmap PLE n-gram tables (saves ~12 GB GPU RAM), QSA sparse attention, and official MTP neural drafter with trimmed 65K draft vocabulary:

ModelLayersExpertsRoutingVocabStatus
mlx-community/Qwen4-35B-A3B-4bit-text (+ Qwen4 MTP 4-bit)40 (30 DN + 10 FA, PLE L1)256 + 1Top-8248,320Verified M3 Ultra benchmarks + HTTP serve

Hybrid MoE Models (qwen3_5_moe, qwen3_next)

Any 4-bit MLX affine (group_size=64) checkpoint with H=2048, I=512, 16/2 GQA, 16/32 DeltaNet, any layer count, vocab size, 256 or 512 experts, and top-8 or top-10 routing:

ModelLayersExpertsRoutingVocabStatus
mlx-community/Qwen3.6-35B-A3B-4bit (+ MTP-4bit )40 (30 DN + 10 FA)256 + 1Top-8248,320Verified exact parity + M3 Ultra benchmarks
mlx-community/Qwen3.5-35B-A3B-4bit40 (30 DN + 10 FA)256 + 1Top-8248,320Config-driven ( qwen3_5_moe )
lmstudio-community/Qwen3-Coder-Next-MLX-4bit48 (36 DN + 12 FA)512 + 1Top-10151,936Config-driven ( qwen3_next )
mlx-community/Qwen3-Next-80B-A3B-Instruct-4bit48 (36 DN + 12 FA)512 + 1Top-10151,936Config-driven ( qwen3_next )

Dense GQA Transformers (qwen3, llama, mistral, qwen2)

Any 4-bit MLX affine (group_size=64, BF16 or F16 scales/norms) dense checkpoint with SwiGLU MLP, optional QK-norm, optional QKV biases, standard or Llama 3 RoPE scaling, and tied or untied embeddings:

ModelGeometrymlx_lm Decodesinter 1-Step ( B=1 )sinter GPU-Burst (Live Stream)Prefill ( pp256 )Parity vs mlx_lm
mlx-community/Qwen3-0.6B-4bit28L, H=1024, I=3072, GQA 16/8, QK-norm ( BF16 )179.9 tok/s301.5–446.3 tok/s457.4 tok/s (peak 507.3 , 2.54x–2.82x )1,056 tok/sExact ( prefill + spec B=4 + burst exact; step-1 18.5/18.5 tie)
mlx-community/Llama-3.2-1B-Instruct-4bit16L, H=2048, I=8192, GQA 32/8, Llama 3 RoPE ( F16 )218.5 tok/s320.9–383.9 tok/s423.7 tok/s (peak 449.4 , 417.5 live HTTP, 1.94x–2.06x )778 tok/s32/32 exact + live HTTP chat verified

Verified M3 Ultra Benchmarks

Qwen4-35B-A3B (mlx-community/Qwen4-35B-A3B-4bit-text)

Measured on an Apple M3 Ultra (60-core GPU, 96 GB unified memory) against mlx-lm 0.32.3.dev26 on the same 4-bit checkpoint (speculative column uses the 484 MB official Qwen4 MTP head auto-extracted via HTTP Range from mlx-community/Qwen4-35B-A3B-oQ4e-mtp with trimmed 65K draft vocab):

MetricApple mlx-lm 0.32.3.dev26sinter Base ( B=1 )sinter MTP Speculative (Lossless)Delta vs mlx-lm
Decode (4-task avg / tg128)21.88 tok/s81.7–83.6 tok/s92.14 tok/s (508 tok)3.8x raw / 4.21x spec
JSON (128 tok)21.88 tok/s83.62 tok/s107.25 tok/s (71.9% acc)4.90x
Math (128 tok)21.88 tok/s83.62 tok/s105.39 tok/s (72.0% acc)4.82x
Code (128 tok)21.88 tok/s83.62 tok/s82.43–88.72 tok/s3.8x–4.05x
Prose (128 tok)21.88 tok/s83.62 tok/s80.21 tok/s (65.9% acc)3.67x
Prompt prefill ( pp256 )578.3 tok/s811.5–879.2 tok/s811.5–879.2 tok/s+40% to +52%
GPU weight RAM31.50 GB19.75 GB20.23 GB36% less RAM
Live streaming comparison (stream_generate): On the exact same 114-token structured JSON prompt (temperature=0, uncontended sequential runs, zero prefix cache), sinter serve completes 367 tokens in 4.40s (96.8 tok/s decode, 20.2 GB GPU RAM) vs Apple mlx-lm 0.32.3.dev26 stream_generate at 12.28s (31.2 tok/s decode, 31.3 GB active / 31.6 GB peak GPU RAM) — 3.1x faster decode, 2.8x faster wall-clock, 35% less GPU RAM. (1x real-time 60 FPS video)

Qwen3.6-35B-A3B (mlx-community/Qwen3.6-35B-A3B-4bit)

Measured cold-first over live OpenAI-compatible HTTP streaming (temperature=0, default lossless 4-bit mode) on an Apple M3 Ultra (60-core GPU, 96 GB unified memory) against mlx_lm serving the exact same mlx-community/Qwen3.6-35B-A3B-4bit weights:

Workloadmlx_lm HTTPsinter Base ( B=1 )sinter Speculative (Lossless)Speedup vs mlx_lmExact Match vs mlx_lm
Cold Prose48.7 tok/s109.4 tok/s138.3 tok/s (146.8 direct)2.84xFloating-point tie-break near argmax
Math Reasoning ( <think> )48.4 tok/s108.9 tok/s165.0 tok/s3.41xExact
Code Edit48.4 tok/s105.8 tok/s187.3 tok/s3.87xExact
Structured JSON48.7 tok/s107.9 tok/s204.9 tok/s4.21xExact
  • Prompt prefill (pp512): ~905 tok/s via batched Metal 4 MMA kernels.
  • Weight footprint: ~20.1 GB GPU-private packed 4-bit weights (plus ~480 MB MTP draft head); drops below 1 GB when idle via --idle-unload-secs or POST /v1/unload.
  • Optional --moe-budget <N> (MoE-Spec turbo mode): Caps unique routed experts per layer during speculative verification while keeping token 0 100% exact (--moe-budget 16 pushes direct Code Edit to 198.7 tok/s and JSON to 214.0 tok/s, at a small accuracy tradeoff on open-ended reasoning). Default is 0 (100% exact lossless).

Architecture Highlights

  • Single-Dispatch Persistent Megakernels + GPU-Resident Streaming Bursts: Uses Metal 4 MTL4CommandQueue, residency sets, argument tables, and 128-byte cache-line-padded device-coherent grid barriers to run all layers (plus Final RMSNorm, LM Head, and Argmax on dense models) inside a single GPU launch. Greedy dense requests stream up to 32 tokens per launch directly through a unified-memory atomic counter, eliminating per-token macOS command-queue scheduling jitter.
  • Bank-Conflict-Free Threadgroup SRAM & Half-SIMD Packing: Pads 64-element activation groups to 68 elements (17 x float4/half4) to eliminate 32-way Apple9 TG-SRAM bank conflicts, tiles wide MLP layers (I > 4096) to stay under 9 KB per threadgroup, and packs 2 rows per SIMD group (16 lanes/row) when H=1024 or I_GROUPS % 32 == 16.
  • Auto-Scaled Apple Silicon Residency: Reads gpu-core-count from AGXAccelerator and reserves headroom for macOS WindowServer so persistent grid barriers stay safe on 10-core to 80-core Macs (overridable via --tgs).
  • Packed 1-Buffer Q4 & Native Apple9 half4 Dot Products: Repacks MLX 3-buffer (weight, scales, biases) into contiguous GPU-private StorageModePrivate row blocks and unpacks nibbles once across batched tokens in threadgroup SRAM.
  • Hybrid Speculative Decoding (B = 1..6 + 2-Branch Trees): Tier 1: zero-cost exact 6-gram prompt/output match (B = 6 verification at 22.7 ms). Tier 2: official Qwen3.6-35B-A3B-MTP-4bit neural draft head running in a single Metal 4 command buffer with hardware indirect-dispatch early stop (dispatchThreadgroupsWithIndirectBuffer), skipping low-confidence draft steps with zero launched threadgroups. Supports linear chains (B = 2..6), Root-Split ([0 -> {1 -> 2, 3}]), and Depth-1-Split ([0 -> 1 -> {2, 3}]) trees compiled via template<bool> + if constexpr pipelines for zero runtime overhead on linear paths. Zero-copy DeltaNet double-buffered state swap on full accept, and deferred single-CB GPU DeltaNet replay commit (deltanet_commit_all30) on partial or tree accept.
  • Tier 1: zero-cost exact 6-gram prompt/output match (B = 6 verification at 22.7 ms).
  • Tier 2: official Qwen3.6-35B-A3B-MTP-4bit neural draft head running in a single Metal 4 command buffer with hardware indirect-dispatch early stop (dispatchThreadgroupsWithIndirectBuffer), skipping low-confidence draft steps with zero launched threadgroups.
  • Supports linear chains (B = 2..6), Root-Split ([0 -> {1 -> 2, 3}]), and Depth-1-Split ([0 -> 1 -> {2, 3}]) trees compiled via template<bool> + if constexpr pipelines for zero runtime overhead on linear paths.
  • Zero-copy DeltaNet double-buffered state swap on full accept, and deferred single-CB GPU DeltaNet replay commit (deltanet_commit_all30) on partial or tree accept.
  • EcoSpec Online Expert-Overlap Feedback: Accumulates active unique switch experts across all 40 layers on GPU and feeds a rolling overlap estimate into the expected-throughput planner so batch depth adapts automatically to MoE routing density.
  • FP16 KV Cache + Prefix Snapshot Cache: Compact FP16 KV caches across all 10 Full Attention layers and the MTP layer, plus LRU prefix snapshots for instant multi-turn TTFT.

Requirements

  • Apple Silicon Mac with Metal 4 support (macOS 26 / Metal 4 runtime).
  • At least 32 GB unified memory for 35B MoE models (48 GB+ recommended; 0.6B–1B dense models run on any 8 GB+ Apple Silicon Mac).
  • Building from source only: Rust toolchain (rustup / cargo, Rust 2024 edition). Prebuilt binaries need zero dependencies.

Quick Start

  • Install prebuilt Apple Silicon binary (10 seconds, zero dependencies):

        curl -fsSL https://raw.githubusercontent.com/srbryers/sinter/main/scripts/install.sh | sh
      

Or build from source:


        cargo build --release
      
  • Pull or serve any supported Hugging Face model in one command (downloads into $HF_HOME/hub or ~/.cache/huggingface/hub using hf if installed, or macOS built-in curl with resumable transfers):

        # Serve Qwen4-35B-A3B with one-command MTP (auto-extracts ONLY the 484 MB MTP head via HTTP Range!)
sinter serve mlx-community/Qwen4-35B-A3B-4bit-text \
  --mtp mlx-community/Qwen4-35B-A3B-oQ4e-mtp \
  --port 8089

# Or pre-pull just the 484 MB Qwen4 MTP head once (auto-discovered on future Qwen4 runs)
sinter pull --mtp mlx-community/Qwen4-35B-A3B-oQ4e-mtp
sinter --bench-qwen4 --model mlx-community/Qwen4-35B-A3B-4bit-text

# Optional: pull the Qwen3.6 MTP draft head for 3-4x speculative decode speed on Qwen3.6
sinter pull mlx-community/Qwen3.6-35B-A3B-MTP-4bit

# Start the OpenAI-compatible HTTP server for Qwen3.6 (auto-downloads if not yet cached)
sinter serve mlx-community/Qwen3.6-35B-A3B-4bit \
  --host 127.0.0.1 \
  --port 8089 \
  --idle-unload-secs 300 \
  --lazy
      

You can also serve other supported checkpoints directly by repo ID (for example sinter serve mlx-community/Llama-3.2-1B-Instruct-4bit, sinter serve mlx-community/Qwen3-0.6B-4bit, or sinter serve lmstudio-community/Qwen3-Coder-Next-MLX-4bit) or pass a local snapshot folder.

  • Send a streaming chat completion request:

        curl http://127.0.0.1:8089/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mlx-community/Qwen3.6-35B-A3B-4bit",
    "messages": [{"role": "user", "content": "Explain why ocean tides happen twice a day."}],
    "temperature": 0.0,
    "max_tokens": 128,
    "stream": true
  }'
      

CLI Options


        sinter pull <org/repo>                   Download a Hugging Face model into the local HF cache
sinter serve [model-or-repo] [OPTIONS]   Start OpenAI-compatible HTTP server (auto-downloads repo IDs)
sinter --bench-autoresearch              Run 4-workload speculative benchmark
sinter --xray                            Stage-by-stage GPU timing X-ray
sinter --ref <dir> [--out <path>]        Run MLX layer/token parity & latency suite
sinter --phase0 [--out <path>]           Run Metal 4 microbenchmark suite
      

Key server flags:

FlagDefaultDescription
--host <addr>127.0.0.1Bind address
--port <port>8089Bind port
--model <path-or-repo>mlx-community/Qwen3.6-35B-A3B-4bitLocal snapshot directory or HF repo ID (auto-downloads if needed)
--mtp <path-or-repo>HF cache autoLocal snapshot or HF repo ID for MTP draft head
--model-id <name>repo ID / folder nameModel name returned by /v1/models
--max-seq <n>8192Maximum context length
--idle-unload-secs <n>300Unload GPU weights after idle seconds ( 0 disables)
--lazyoffDefer loading weights until first request
--no-mtpoffDisable MTP neural drafter (keep n-gram drafter)
--no-speculativeoffDisable speculative decoding ( B = 1 persistent only)
--moe-budget <n>0 (exact)Optional MoE-Spec max unique switch experts/layer during verification (e.g. 16 )
--moe-3bitoffOpt-in 3-bit MoE weight compression
--tgs <n>autoOverride auto-scaled persistent threadgroup count

Endpoints: GET /health, GET /v1/models, POST /v1/chat/completions, POST /v1/completions, POST /v1/unload.

Reproducing Benchmarks

Run the portable HTTP benchmark against mlx_lm (or standalone with --mlx-url none):


        python3 scripts/bench_vs_mlx.py \
  --sinter-url http://127.0.0.1:8089 \
  --mlx-url http://127.0.0.1:8088 \
  --out bench_results.json
      

Run the direct engine 4-workload benchmark (with strict exact-match gate in lossless mode):


        ./target/release/sinter --bench-autoresearch
      

Roadmap

  • GGUF quantization support: Load standard Q4_K_M / Q8_0 GGUF files directly alongside 4-bit MLX checkpoints.
  • Continuous batching & native tool-call parsing: Serve concurrent HTTP requests and structured OpenAI tool_calls streaming.
  • Apple M5 / Metal 4 TensorOps (MTLTensor / neural accelerators): Add a TensorOps matmul path for prefill and B >= 4 verification once M5 hardware is available.

License

MIT — see LICENSE.

The text above was extracted automatically from the source page and may miss images, tables or code blocks. The original is authoritative.

Published by HN AI
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗