DwarfStar — Run DeepSeek V4 Flash and PRO Locally on Your Own Machine
DwarfStar — Run DeepSeek V4 Flash and PRO Locally on Your Own Machine 🚀
What is it? DwarfStar (formerly ds4) is a self-contained native inference engine built specifically for DeepSeek V4 Flash and PRO models. Created by Salvatore Sanfilippo (antirez) — the legendary creator of Redis — it's a purpose-built C runtime that is completely independent: not a GGUF wrapper, not a fork of llama.cpp, but a bespoke engine optimized for DeepSeek V4's architecture. It ships with a CLI, an HTTP server, and an integrated coding agent, all running on your own hardware.
Why it's trending: DwarfStar hit 17,600+ GitHub stars in under two months because it solves a real problem: running quasi-frontier open-weight models locally. DeepSeek V4 Flash feels near GPT-5 level for coding and reasoning, and with DwarfStar's aggressive 2-bit quantization (routed MoE experts only), it runs comfortably on 96–128 GB MacBooks, NVIDIA DGX Sparks, and AMD Strix Halo machines. The same creator behind Redis brought his systems programming expertise to local LLM inference — and the community noticed. Distributed inference across multiple machines, SSD streaming for models larger than RAM, and a KV cache that treats your NVMe as a first-class citizen make this a genuinely novel take on on-device AI.
📋 Prerequisites
Before you start, make sure you have:
- A machine with 96+ GB RAM (128 GB recommended for a comfortable experience)
- macOS (Apple Silicon M3/M5 Max or M3 Ultra) or Linux (NVIDIA GPU with 48+ GB VRAM, or AMD Strix Halo)
- Git and a C compiler toolchain (
make,clang/gcc) - curl for downloading model weights
- ~70 GB free SSD space for the Q2 quant, ~150 GB for Q4
🔧 Setup & Installation
1. Clone the Repository
git clone https://github.com/antirez/ds4.git
cd ds4
2. Download the Model Weights
DwarfStar only works with the official GGUFs published on Hugging Face. The download_model.sh script handles everything:
# For 96–128 GB machines (recommended)
./download_model.sh q2-imatrix
# For machines with 256+ GB RAM
./download_model.sh q4-imatrix
# For 512 GB machines — the full PRO model
./download_model.sh pro-q2-imatrix
The script downloads from huggingface.co/antirez/deepseek-v4-gguf, stores files under ./gguf/, and links ./ds4flash.gguf to your chosen model. It resumes partial downloads automatically with curl -C -.
3. Build the Engine
Choose the build target for your hardware:
# macOS with Apple Silicon (Metal)
make
# Linux with NVIDIA CUDA (DGX Spark / GB10)
make cuda-spark
# Linux with NVIDIA CUDA (other GPUs)
make cuda-generic
# Linux with AMD ROCm (Strix Halo)
make rocm
# CPU-only diagnostics (slow, for testing only)
make cpu
That's it — no Python, no Docker, no virtual environments. A single make produces the ./ds4 CLI binary and the ./ds4-server HTTP API server.
4. Verify Your Setup
Run a quick smoke test:
./ds4 -m ./ds4flash.gguf --nothink --prompt "Hello, who are you?"
You should see the model respond in a few seconds. On an M3 Max 128 GB with Q2 quant, expect ~26 tokens/second generation speed.
🏗️ How It Works
DwarfStar is designed around DeepSeek V4's unique architecture — a Mixture of Experts (MoE) model with a compressed KV cache that makes very long contexts practical. Unlike generic runners, every optimization is specific to DeepSeek V4's tensor layout.
⚙️ Architecture Overview
DwarfStar's architecture has four main layers:
-
User Interfaces — Three entry points: the CLI (
./ds4) for interactive sessions, the HTTP Server (./ds4-server) for API access and tool calling, and the experimental ds4-agent for autonomous coding tasks. All three share the same inference backend. -
Inference Engine — The core
ds4.cruntime. It handles prompt processing, tokenization (DeepSeek V4's custom tokenizer), graph compilation for the target backend, and KV cache management. This is not a generic LLM runtime — it's a narrow, DeepSeek-specific engine that achieves its speed by making strong assumptions about model structure. -
GPU Backends — Three hardware paths:
- Metal (Apple Silicon) — the primary target, fastest path for MacBooks and Mac Studios
- CUDA (NVIDIA) — optimized for the DGX Spark / GB10 and other local CUDA GPUs
- ROCm (AMD) — supports Strix Halo systems like the Framework Desktop
-
KV Cache System — The most innovative part of DwarfStar's design. DeepSeek V4's compressed KV cache allows SSD streaming: when the model is larger than available RAM, non-routed weights stay resident while routed MoE experts are loaded on demand from SSD. On modern Mac SSDs (7+ GB/s), cache misses are surprisingly tolerable. For fully in-RAM operation, the cache is a fast in-memory ring buffer with optional on-disk persistence.
Distributed Inference
DwarfStar supports splitting layers across multiple machines. A Q4 Flash model can run across two 128 GB MacBooks connected via Thunderbolt: each machine loads its own layer slice, activations flow over TCP, and the coordinator presents a unified CLI/API. Prefill is pipelined across machines for additional speed.
Speed Benchmarks
| Machine | Quant | Prefill | Generation |
|---|---|---|---|
| M3 Max, 128 GB | Q2 | 58.52 t/s | 26.68 t/s |
| M5 Max, 128 GB | Q2 | 87.25 t/s | 34.27 t/s |
| M3 Ultra, 512 GB | Q2 | 84.43 t/s | 36.86 t/s |
| M3 Ultra, 512 GB | Q4 | 78.95 t/s | 35.50 t/s |
| M3 Ultra, 512 GB | PRO Q2 | 138.82 t/s | 9.56 t/s |
| DGX Spark GB10 | Q2 | 343.81 t/s | 13.75 t/s |
Generation speeds are for greedy decoding with 32K context. Prefill speeds benefit from chunked prefill and long-context optimization.
🚀 Usage
Interactive CLI
# Start an interactive session
./ds4 -m ./ds4flash.gguf
# With thinking mode enabled (slower but better reasoning)
./ds4 -m ./ds4flash.gguf --think
# Limit output tokens
./ds4 -m ./ds4flash.gguf --think --tokens 1500
HTTP API Server
# Start the server on the default port
./ds4-server -m ./ds4flash.gguf
# Listen on a specific port
./ds4-server -m ./ds4flash.gguf --port 8080
The server provides an OpenAI-compatible API endpoint, making it a drop-in replacement for any tool or agent that expects an OpenAI API. Point your coding agent at http://localhost:8080/v1 and it works immediately.
SSD Streaming (for Models Larger Than RAM)
# Automatic cache budget (recommended)
./ds4 -m ./ds4flash.gguf --ssd-streaming
# Manual cache size
./ds4 -m ./ds4flash.gguf --ssd-streaming --ssd-streaming-cache-experts 32GB
The automatic budget takes 80% of the Metal recommended working set, subtracts non-routed weights, and uses the rest for the routed expert cache. On 64 GB machines, start with an explicit 32 GB cache.
🧪 Verification Checklist
git clone, model download, andmakecomplete without errors./ds4 -m ./ds4flash.gguf --nothink --prompt "Hello"responds correctly- Generation speed matches expected range for your hardware
./ds4-serverstarts and responds athttp://localhost:8080/v1- SSD streaming mode loads without crashes on memory-constrained hardware
- KV cache persists across sessions (check
--cacheflag)
🔗 Resources
- GitHub: github.com/antirez/ds4
- Hugging Face Models: huggingface.co/antirez/deepseek-v4-gguf
- DeepSeek V4: deepseek.com
- Author: Salvatore Sanfilippo (antirez) — antirez.com
- Related: llama.cpp — inspired the GGUF ecosystem
- License: MIT