AIFeed

Show HN:Sinterl 4——用 Rust 实现的持久化 LLM 引擎(在 Qwen4 上比 mlx-lm 快 3.1 倍)

Translation(model translation, not the source's own text)

sinter

题图
题图

一个纯 Rust + 手工融合 Metal 4 的持久化 LLM 推理引擎,面向 Apple Silicon,支持 Qwen4(qwen4_moe,含 Hyper-Connections、零拷贝 mmap PLE n-gram 表、QSA 和原生 MTP)、Qwen3.5 / Qwen3.6 / Qwen3-Next MoE、标准 MoE,以及 Dense GQA Transformer(Qwen3、Llama 3、Mistral、Qwen2),支持无损投机解码和一键 Hugging Face 下载。

sinter 在加载时读取 config.json,将模型相关常量注入手工调优的 Metal 4 shader,把所有 transformer 层融合进单个持久化 GPU kernel,把 4-bit 权重打包进统一的 GPU 私有缓冲区,并对外提供兼容 OpenAI 的 HTTP API,默认零质量损失。

支持的模型

Qwen4 Hybrid MoE(qwen4_moe)

针对 Qwen4 的 4 流 Hyper-Connections、零拷贝 mmap PLE n-gram 表(节省约 12 GB GPU 内存)、QSA 稀疏注意力和官方 MTP 神经草稿模型(草稿词表裁剪至 65K)的原生 Metal 4 持久化 kernel:

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 模型(qwen3_5_moe、qwen3_next)

任意 4-bit MLX affine(group_size=64)checkpoint,要求 H=2048、I=512、16/2 GQA、16/32 DeltaNet,层数和词表大小不限,256 或 512 个专家,top-8 或 top-10 路由:

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 Transformer(qwen3、llama、mistral、qwen2)

任意 4-bit MLX affine(group_size=64,BF16 或 F16 scales/norms)稠密 checkpoint,要求 SwiGLU MLP、可选 QK-norm、可选 QKV 偏置、标准或 Llama 3 RoPE 缩放、绑定或非绑定 embedding:

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

已验证的 M3 Ultra 基准测试

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

在 Apple M3 Ultra(60 核 GPU、96 GB 统一内存)上,于同一 4-bit checkpoint 上对比 mlx-lm 0.32.3.dev26 测得(投机解码一列使用 484 MB 的官方 Qwen4 MTP head,通过 HTTP Range 从 mlx-community/Qwen4-35B-A3B-oQ4e-mtp 自动提取,草稿词表裁剪至 65K):

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
实时流式对比(stream_generate):在完全相同的 114 token 结构化 JSON 提示词上(temperature=0,无争用的顺序运行,零前缀缓存),sinter serve 在 4.40s 内完成 367 个 token(解码 96.8 tok/s,GPU RAM 20.2 GB),而 Apple mlx-lm 0.32.3.dev26 stream_generate 为 12.28s(解码 31.2 tok/s,活跃 GPU RAM 31.3 GB / 峰值 31.6 GB)——解码快 3.1x,墙钟时间快 2.8x,GPU RAM 少 35%。(1x 实时 60 FPS 视频)

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

在 Apple M3 Ultra(60 核 GPU,96 GB 统一内存)上,通过实时 OpenAI 兼容 HTTP 流式接口进行冷启动首次测量(temperature=0,默认无损 4-bit 模式),与 mlx_lm 加载完全相同的 mlx-community/Qwen3.6-35B-A3B-4bit 权重进行对比:

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
  • 提示词预填充(pp512):通过批处理 Metal 4 MMA 内核约 905 tok/s。
  • 权重占用:约 20.1 GB GPU 私有打包 4-bit 权重(外加约 480 MB MTP 草稿头);通过 --idle-unload-secs 或 POST /v1/unload 在空闲时降至 1 GB 以下。
  • 可选 --moe-budget <N>(MoE-Spec 加速模式):在投机验证期间限制每层唯一路由的专家数,同时保持 token 0 100% 精确(--moe-budget 16 将直接 Code Edit 推至 198.7 tok/s,JSON 推至 214.0 tok/s,代价是在开放式推理上有小幅精度折损)。默认值为 0(100% 精确无损)。

Architecture Highlights

  • Single-Dispatch Persistent Megakernels + GPU-Resident Streaming Bursts:使用 Metal 4 MTL4CommandQueue、residency sets、argument tables,以及 128 字节缓存行填充的设备一致网格屏障,在单次 GPU 启动内运行所有层(以及稠密模型上的 Final RMSNorm、LM Head 和 Argmax)。贪心稠密请求每次启动最多流式输出 32 个 token,直接通过统一内存原子计数器完成,消除逐 token 的 macOS 命令队列调度抖动。
  • Bank-Conflict-Free Threadgroup SRAM & Half-SIMD Packing:将 64 元素激活组填充至 68 元素(17 x float4/half4),以消除 32 路 Apple9 TG-SRAM bank 冲突;对宽 MLP 层(I > 4096)进行分块,使每个 threadgroup 保持在 9 KB 以下;当 H=1024 或 I_GROUPS % 32 == 16 时,每个 SIMD 组打包 2 行(每行 16 通道)。
  • Auto-Scaled Apple Silicon Residency:从 AGXAccelerator 读取 gpu-core-count,并为 macOS WindowServer 预留余量,使持久网格屏障在 10 核至 80 核 Mac 上保持安全(可通过 --tgs 覆盖)。
  • Packed 1-Buffer Q4 & Native Apple9 half4 Dot Products:将 MLX 3-buffer(权重、缩放、偏置)重新打包为连续的 GPU 私有 StorageModePrivate 行块,并在批处理 token 间于 threadgroup SRAM 中一次性解包半字节。

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

正文:

  • 混合投机解码(B = 1..6 + 双分支树):第一层:零成本精确 6-gram 提示/输出匹配(B = 6 验证耗时 22.7 ms)。第二层:官方 Qwen3.6-35B-A3B-MTP-4bit 神经草稿头(neural draft head)在单个 Metal 4 command buffer 中运行,并借助硬件间接调度(indirect-dispatch)提前停止(dispatchThreadgroupsWithIndirectBuffer),在零启动线程组的情况下跳过低置信度的草稿步骤。支持通过 template<bool> + if constexpr 管线编译的线性链(B = 2..6)、Root-Split([0 -> {1 -> 2, 3}])以及 Depth-1-Split([0 -> 1 -> {2, 3}])树,使线性路径上的运行时开销为零。完全接受时执行零拷贝 DeltaNet 双缓冲状态交换;部分接受或树接受时执行延迟的单 CB GPU DeltaNet 重放提交(deltanet_commit_all30)。
  • 第一层:零成本精确 6-gram 提示/输出匹配(B = 6 验证耗时 22.7 ms)。
  • 第二层:官方 Qwen3.6-35B-A3B-MTP-4bit 神经草稿头(neural draft head)在单个 Metal 4 command buffer 中运行,并借助硬件间接调度(indirect-dispatch)提前停止(dispatchThreadgroupsWithIndirectBuffer),在零启动线程组的情况下跳过低置信度的草稿步骤。
  • 支持通过 template<bool> + if constexpr 管线编译的线性链(B = 2..6)、Root-Split([0 -> {1 -> 2, 3}])以及 Depth-1-Split([0 -> 1 -> {2, 3}])树,使线性路径上的运行时开销为零。
  • 完全接受时执行零拷贝 DeltaNet 双缓冲状态交换;部分接受或树接受时执行延迟的单 CB GPU DeltaNet 重放提交(deltanet_commit_all30)。
  • EcoSpec 在线专家重叠反馈(Online Expert-Overlap Feedback):在 GPU 上累积全部 40 层中活跃的唯一 switch 专家,并将滚动重叠估计值馈入预期吞吐量规划器,使 batch 深度自动适应 MoE 路由密度。
  • FP16 KV 缓存 + 前缀快照缓存:在所有 10 个 Full Attention 层和 MTP 层上使用紧凑的 FP16 KV 缓存,并采用 LRU 前缀快照,实现即时多轮 TTFT。

环境要求

  • 支持 Metal 4 的 Apple Silicon Mac(macOS 26 / Metal 4 运行时)。
  • 35B MoE 模型至少需要 32 GB 统一内存(建议 48 GB 以上;0.6B–1B 稠密模型可在任意 8 GB+ 的 Apple Silicon Mac 上运行)。
  • 仅支持从源码构建:Rust 工具链(rustup / cargo,Rust 2024 edition)。预编译二进制无需任何依赖。

快速开始

  • 安装预编译的 Apple Silicon 二进制(10 秒,零依赖):

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

或从源码构建:


        cargo build --release
      
  • 一条命令即可拉取或服务任意受支持的 Hugging Face 模型(若已安装 hf,则下载到 $HF_HOME/hub 或 ~/.cache/huggingface/hub;否则使用 macOS 内置的 curl 并支持断点续传):

        # 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
      

你也可以直接通过 repo ID 服务其他受支持的 checkpoint(例如 sinter serve mlx-community/Llama-3.2-1B-Instruct-4bit、sinter serve mlx-community/Qwen3-0.6B-4bit,或 sinter serve lmstudio-community/Qwen3-Coder-Next-MLX-4bit),或传入本地快照文件夹。

  • 发送流式 chat completion 请求:

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

正文:


        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 选项


        sinter pull <org/repo>                   将 Hugging Face 模型下载到本地 HF 缓存
sinter serve [model-or-repo] [OPTIONS]   启动兼容 OpenAI 的 HTTP 服务器(自动下载 repo ID)
sinter --bench-autoresearch              运行 4 工作负载推测基准测试
sinter --xray                            逐阶段 GPU 计时 X-ray
sinter --ref <dir> [--out <path>]        Run MLX layer/token parity & latency suite
sinter --phase0 [--out <path>]           Run Metal 4 microbenchmark suite
      

关键服务器标志:

标志默认值描述
--host <addr>127.0.0.1绑定地址
--port <port>8089绑定端口
--model <path-or-repo>mlx-community/Qwen3.6-35B-A3B-4bit本地快照目录或 HF repo ID(如需要会自动下载)
--mtp <path-or-repo>HF 缓存自动用于 MTP draft head 的本地快照或 HF repo ID
--model-id <name>repo ID / 文件夹名由 /v1/models 返回的模型名称
--max-seq <n>8192最大上下文长度
--idle-unload-secs <n>300空闲秒数后卸载 GPU 权重( 0 表示禁用)
--lazy关闭推迟加载权重直到首次请求
--no-mtp关闭禁用 MTP 神经 drafter(保留 n-gram drafter)
--no-speculative关闭禁用推测解码( B = 1 仅持久模式)
--moe-budget <n>0(精确)可选 MoE-Spec 在验证期间每层最大唯一切换专家数(例如 16 )
--moe-3bit关闭选择性启用 3-bit MoE 权重压缩
--tgs <n>自动覆盖自动缩放的持久线程组数量

端点:GET /health、GET /v1/models、POST /v1/chat/completions、POST /v1/completions、POST /v1/unload。

复现基准测试

针对 mlx_lm 运行可移植的 HTTP 基准测试(或使用 --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
      

运行直接引擎的 4 工作负载基准测试(在无损模式下带有严格的精确匹配门控):


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

路线图

  • GGUF 量化支持:直接加载标准 Q4_K_M / Q8_0 GGUF 文件,与 4-bit MLX 检查点并存。
  • 连续批处理与原生工具调用解析:服务并发 HTTP 请求以及结构化 OpenAI tool_calls 流式输出。
  • Apple M5 / Metal 4 TensorOps(MTLTensor / 神经加速器):一旦 M5 硬件可用,为 prefill 和 B >= 4 验证添加 TensorOps matmul 路径。

许可证

MIT — 参见 LICENSE。

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; 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 ↗