Skip to content
King Jin

mini-sglang-mac

An LLM serving engine that runs natively on Apple Silicon, adapted from mini-sglang, with my own Metal paged-attention kernel.

About

Built to understand how a modern inference engine works by making one run well on my Mac. I kept mini-sglang's scheduler, radix prefix cache, chunked prefill, overlap scheduling and OpenAI-compatible server, replaced its CUDA engine with an MLX one, and wrote a Metal paged-attention kernel for decoding. Dropping everything CUDA-only took it from about 10k lines of Python, CUDA and C++ to 4.4k lines of Python.

Key features

  1. 01Decode throughput at batch 128 went from 1,521 to 7,206 tok/s, and time per output token from 84 ms to 18 ms (Qwen3-0.6B in BF16 on an M5 Pro)
  2. 02Metal paged decode kernel that reads K/V in place through a GPU copy of the page table, loads each KV row once per GQA group and splits long contexts across threadgroups: 4–5× faster than gathering the cache for MLX attention, at 249 GB/s
  3. 03MLX engine for Llama, Qwen2 and Qwen3 in BF16 or MLX-quantized form, with a paged KV cache and sampler driven by the original scheduler
  4. 04Tracked down three MLX pitfalls: KV writes that quietly copied the whole cache, a buffer cache that grew to 35 GB, and one GPU job per layer that stopped the CPU from preparing the next step
  5. 05Scheduler reserves only part of each request's output and pauses the newest requests if memory runs out, so far more requests run at once

Details

Year
2026
Link
github.com/Kingjinsight/mini-sglang-mac ↗
  • PythonPython
  • AppleMLX
  • AppleMetal
  • FastAPIFastAPI
  • ZeroMQ
NextDysCover →