Perplexity Open Sources Lily: A Rust + Metal Inference Engine for Qwen3.6-35B-A3B on Apple Silicon
Perplexity open-sourced Lily, a Rust + Metal inference engine for Qwen3.6-35B-A3B on Apple silicon, deliberately excluding PyTorch and MLX from the execution path The engine achieves 1.23x faster prefill and 1.35x faster decode compared to MLX-LM on a 40-core, 128 GB M5 Max at batch 1 Key prefill optimizations include GPU-resident expert routing (+89%) and dequantization fused into grouped GEMM (+77.4%), avoiding unified memory bandwidth bottlenecks Decode performance gains stem from GQA packing
Analysis
TL;DR
- Perplexity open-sourced Lily, a Rust + Metal inference engine for Qwen3.6-35B-A3B on Apple silicon, deliberately excluding PyTorch and MLX from the execution path
- The engine achieves 1.23x faster prefill and 1.35x faster decode compared to MLX-LM on a 40-core, 128 GB M5 Max at batch 1
- Key prefill optimizations include GPU-resident expert routing (+89%) and dequantization fused into grouped GEMM (+77.4%), avoiding unified memory bandwidth bottlenecks
- Decode performance gains stem from GQA packing (+23.8% at 32K context) and fixed-block attention layout (+40.2% at 128K context)
- The 4-bit checkpoint is 19.4 GB, requiring 32 GB+ unified memory on Apple Silicon, with negligible accuracy loss (0.04% perplexity increase, 96.35% top-token agreement)
Why It Matters
Lily demonstrates that narrow, hand-optimized inference engines can significantly outperform general-purpose frameworks like MLX-LM by eliminating abstraction overhead and tailoring execution to a single model architecture. This approach is particularly relevant for practitioners deploying large MoE models on Apple Silicon, where memory bandwidth and kernel efficiency are critical bottlenecks. The open-source release provides a reference implementation for researchers exploring custom inference runtimes beyond mainstream frameworks.
Technical Details
- Architecture: Single-process Rust runtime driving generation, with hand-written Metal kernels; OpenAI-compatible chat-completions API for token streaming; no PyTorch or MLX in the execution path
- Model: Qwen3.6-35B-A3B (35B total parameters, ~3B activated per token), featuring a router selecting 8 of 256 experts plus one shared expert, 10 full-attention layers with grouped-query attention (16 query heads, 2 KV heads), and 30 Gated DeltaNet layers
- Prefill optimizations: Groupwise affine 4-bit quantization (64 weights per group) with dequantization fused into grouped GEMM using threadgroup memory and FP32 accumulation; GPU-resident routing histogram, prefix scan, scatter, and block map within a single command buffer eliminating CPU synchronization; 32-row tiles with four simdgroups; register-resident Gated DeltaNet scan
- Decode optimizations: Concurrent Metal pass recording real kernel dependencies to overlap 795 independent kernels; token written directly into GPU-resident input slot eliminating per-token CPU round trips; four fused kernel chains keeping intermediates in registers; coalesced cache reads improving key bandwidth from 33.8 to 47.9 GB/s and value bandwidth from 42.0 to 61.8 GB/s
- Benchmarks: Tested on M5 Max (40-core, 128 GB) across 10 lengths (256 to 128K tokens); Lily averaged 4,156 prefill tokens/s vs 3,388 (MLX-LM) and 170.0 decode tokens/s vs 126.4; at 4K prompt/context: 5,749.9 prefill and 186.6 decode vs 4,737.5 and 140.9
Industry Insight
- The narrow-specialization strategy challenges the dominant trend of building universally compatible frameworks, suggesting that for production deployments on specific hardware-model combinations, custom engines can deliver meaningful performance gains (1.2-1.4x) that justify the development investment
- GPU-resident MoE routing and fused dequantization represent transferable techniques for other sparse model architectures, particularly as MoE models become more common in open-weight releases
- The 0.04% perplexity overhead and 96.35% token agreement demonstrate that aggressive kernel fusion and custom memory management can achieve near-framework parity in accuracy while substantially improving throughput, a compelling tradeoff for latency-sensitive applications
Disclaimer: The above content is generated by AI and is for reference only.