# Repository Briefing: ARahim3/mlx-dspark
> Source: https://repoforai.com/repo/ARahim3/mlx-dspark (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/ARahim3/mlx-dspark
- **Official Docs / Website**: https://arahim.dev/mlx-dspark/
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: Python
- **License**: MIT
- **Engineering Health**: A+ (90/100 · Maintenance 35/35 · Adoption 15/25 · Releases 20/20 · License 20/20)
- **Latest Release**: v0.21.4 (2026-11-26) — https://github.com/ARahim3/mlx-dspark/releases
- **Review Snapshot**: 2026-12-04
- **Deployment / Stack Signals**: Local AI, Self-Hosted, CLI, GPU, API
- **Momentum**: 811 ★ total (+2 24h / +6 7d) · 69 forks
- **Topics**: `apple-silicon`, `claude-code`, `codex`, `dflash2`, `dspark`, `inference-engine`, `llm-inference`, `local-llm`, `macos`, `metal`, `mlx`, `pi`
- **When to Use**: Best for: Apple Silicon users serving a local chat or coding workflow who can choose a matched target–drafter pair and measure gains at their actual context length. Skip if: You need DeepSeek-V4 inference, a non-Apple GPU runtime, or a managed multi-tenant API with predictable concurrency.

## Overview
```text
### Architecture & Core Mechanics
mlx-dspark is a Python inference engine that uses MLX to run speculative decoding on Apple Silicon GPUs. It keeps the target model in charge of the output and shares a verification loop across several drafting methods. DSpark uses target hidden states to propose seven tokens and applies a previous-token correction through a Markov head. DFlash denoises a 16-token block in parallel and reuses the target's embeddings and output head. DFlash 2 builds a chain from top candidates; DSpine conditions each position on its predecessor.

The target verifies proposed tokens in blocks, allowing one pass to advance multiple positions when the draft matches. Greedy output matches plain target decoding apart from floating-point tie-breaking; speculative sampling preserves the target distribution under the selected sampling settings, rather than promising the same sampled transcript. Matched drafters load from Hugging Face checkpoints and default to 4-bit quantization. For a loadable target without a matched drafter, n-gram lookup can instead propose a continuation seen earlier in the context.

### Key Capabilities & Differentiators
The engine is available through a CLI, Python, and a local HTTP server. The server exposes `/v1/chat/completions`, `/v1/messages`, and `/v1/responses` on one port, with controls for sampling and reasoning as well as tool calling. The CLI can compare plain decoding with speculation, and the separate native Mac app adds model-fit estimates, per-round acceptance telemetry, and a side-by-side output check.

Matched checkpoints cover families including Gemma-4, Qwen3, LFM2.5, and Muse-Glimmer. On a warm M4 Pro at short context, Qwen3.8-27B 4-bit with DFlash 2 decoded at roughly 42–65 tokens/s, with a 2.72× chat speedup and a 4.23× math speedup. The gap matters: measure with your own prompts, and report decode throughput separately from time to first token and end-to-end agent runtime.

### Trade-offs & Limitations
Against plain MLX decoding, the key question is whether accepted tokens repay the cost of drafting and verification. The engine profiles the Mac on the first run of a model pair and caches the result to choose a draft cap, but calibration cannot fix a poor target–drafter match. Lookup also cannot guarantee a speedup on prompts without useful repetition. Benchmark the same checkpoint and quantization with and without speculation, then repeat at the 16k–32k context lengths relevant to coding agents rather than extrapolating short-context results.

Compared with the hosted OpenAI API, this is a way to keep inference local and choose your own checkpoints, not a guarantee of hosted model quality, feature parity, or managed concurrency. Unified memory is a practical constraint: Qwen3-8B-8bit is listed at about 11 GB peak RAM, while Qwen3.8-27B 4-bit is about 18 GB and is not a sensible default for a 16 GB Mac. The MIT license covers the engine; check target and drafter weight terms separately.

### Hardware & Deployment Guide
Install the engine with `pip install mlx-dspark` on an Apple Silicon Mac with Python 3.10 or later. v0.21.4 requires MLX 0.32.5 or later, whose few-row quantized matmul and attention kernels reduce verification cost; the release reports up to 16% faster speculative decoding. Weights are not bundled: populate the Hugging Face cache on first use or supply compatible local files for offline operation. The separately distributed Mac app is not included in the Python wheel.

Start with `mlx-dspark serve --model mlx-community/Qwen3-8B-8bit`; the default listener is `127.0.0.1:8080`. Use `--no-model` and then `/admin/load` to defer loading or swap checkpoints. The server is designed for local, single-user use. If exposing it beyond loopback, set `--api-key`; with a key configured, only `GET /health` remains unauthenticated. Custom checkpoint Python is refused by default, and `--trust-remote-code` changes that policy for the entire process, not just one model load.
```

## Key Capabilities
```text
- Verification: One MLX target-verification loop serves DSpark, DFlash, DFlash 2, and DSpine.
- Model selection: Known target families resolve matched drafters across quantizations; `--mode auto` can fall back to drafter-free n-gram lookup.
- Calibration: First-run measurements are cached per pair, and `--max-draft auto` can adapt the cap each round.
- Benchmarking: On a warm M4 Pro, Qwen3.8-27B 4-bit with DFlash 2 measured 2.72× on chat and 4.23× on math at short context.
- Serving: A Python standard-library HTTP server exposes OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages on one port.
- Operations: `--no-model` and `/admin/load` support deferred loading and model swaps; custom checkpoint Python is blocked by default.
```

## Quick Start / Clone
```bash
brew tap ARahim3/mlx-dspark https://github.com/ARahim3/mlx-dspark
brew trust arahim3/mlx-dspark          # Homebrew 6+: third-party taps need explicit trust
brew install --cask mlx-dspark
xattr -dr com.apple.quarantine /Applications/mlx-dspark.app   # not notarized yet: clear
                                       # quarantine once, or use System Settings › Privacy &
                                       # Security › "Open Anyway" after the first launch
```
