⚡ ds4 (DwarfStar 4):8.3k Stars,antirez 出的 DeepSeek V4 Flash 原生推理引擎,一个 C 文件搞定本地运行
项目地址:github.com/antirez/ds4 | ⭐ 8,345 | 🛠 C | Owner: antirez | 📜 MIT | 🆕 2026-05-06
老实说,要在本地跑 DeepSeek V4 Flash 这个 284B 的 MoE 模型,之前的路子无非两个:要么等 llama.cpp 跟进支持,要么用官方那套依赖一大堆的推理栈。但 Redis 的作者 antirez 不这么想——他直接拿 C 写了一个从头到尾只伺候 DS V4 Flash 这一个模型的推理引擎,完全不依赖 GGUF loader 或通用运行时。
这玩意儿叫 ds4(DwarfStar 4),上周刚开源,不到一周就 8.3k stars。不是 GGUF 套壳,不是 llama.cpp 分支,就是一个纯自包含的 .c 推理引擎。最骚的是它用 2-bit 量化就能在 96GB RAM 的 MacBook 上跑 V4 Flash,还带着 100k~300k token 的上下文窗口。
为什么 antirez 要自己写引擎?
好问题。市面上已经有 llama.cpp、MLC、TensorRT-LLM 一堆方案。antirez 的理由其实很简单:DeepSeek V4 Flash 值得一个专属引擎。
一行命令跑起来
# 下载模型(2-bit 量化,适合 96/128GB Mac)
./download_model.sh q2-imatrix
# 编译(macOS Metal)
make
# 交互式对话
./ds4
# 一行命令推理
./ds4 -p "Explain how Redis replication works in one paragraph."
编译时自动检测 Metal(macOS)或 CUDA(Linux)。CPU 模式也有,但 antirez 说了——make cpu 主要用来做正确性验证,macOS 上跑 CPU 路径会让内核 crash,别试。
跑个 API Server,当本地 ChatGPT 用
ds4 自带一个 OpenAI/Anthropic 兼容的 HTTP 服务器:
# 启动服务,100k 上下文,KV cache 存磁盘
./ds4-server --ctx 100000 --kv-disk-dir /tmp/ds4-kv --kv-disk-space-mb 8192
然后用 curl 调就完事了:
curl http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "deepseek-v4-flash",
"messages": [{"role": "user", "content": "List three Redis design principles."}],
"stream": true
}'
也支持 Anthropic 的 /v1/messages 端点,Claude Code 类的 agent 可以直接连。
接入 Coding Agent
OpenCode 配置示例:
{
"provider": {
"ds4": {
"name": "ds4.c (local)",
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "http://127.0.0.1:8000/v1",
"apiKey": "***"
},
"models": {
"deepseek-v4-flash": {
"name": "DeepSeek V4 Flash (ds4.c local)",
"limit": {
"context": 100000,
"output": 384000
}
}
}
}
}
}
Pi、Claude Code 也可以直接连,ds4-server 的 API 兼容层处理了 DSML tool call 格式的转换——这其实是最麻烦的部分,因为 DeepSeek 的 tool call 用 DSML 文本格式,而 agent 客户端期望标准 JSON。ds4 做了 exact replay,确保 tool call 的字节前缀跟 KV cache 完全匹配。
速度参考
| 机器 | 量化 | Prefill | 生成 |
|------|------|---------|------|
| M3 Max 128GB | q2 | 58.52 t/s | 26.68 t/s |
| M3 Ultra 512GB | q2 | 84.43 t/s | 36.86 t/s |
| M3 Ultra 512GB | q4 | 78.95 t/s | 35.50 t/s |
| DGX Spark 128GB | q2 | 343.81 t/s | 13.75 t/s |
Prefill 速度快到离谱——M3 Ultra 上 q2 prefill 跑到 468 t/s(长上下文)。生成速度 26-37 t/s,日常编码完全够用。