Views
No views yet
┌────────────┐ hidden states ┌──────────────┐
│ Qwen3.8 │ ───(layers 5/19/ ─▶│ DFlash2 draft│──▶ 4-token block
│ 27B mxfp4 │ 33/47/61) │ 5L, parallel │ (one pass)
│ (target) │◀───────────────────│ selector │
└────────────┘ verify 5 tok └──────────────┘
1 forward| Regime | dense | DFlash2 K=4 | speedup |
|---|---|---|---|
| Fresh code gen (300 tok) | 19.5 t/s | 30.6 t/s | +57% |
| Edit 13.8k-ctx (256 tok) | 3.1 t/s | 1.9 t/s | prefill-bound, no win |
| Quality gate (6 prompts) | 6/6 | 6/6 | lossless greedy* |
bench/LOSSLESS.md.1bash scripts/setup.sh # venv + deps + models (~18GB) + text prep
2bash scripts/serve.sh # OpenAI API on :8006
3python scripts/smoke_test.py # verify: health, math, stream, think-cap1python3 -m venv .venv && source .venv/bin/activate
2pip install -r requirements.txt
3bash scripts/download_models.sh
4python dflash2_mlx_server/server.py \
5 --main-dir models/qwen3.8-text --draft-dir models/dflash2 \
6 --port 8006 --block-size 4 --think-cap 12000bash scripts/run_tests.sh (unit + API smoke). Benchmark: python bench/test_dflash2.py 4.| Path | What |
|---|---|
dflash2_mlx_server/server.py | OpenAI-compatible FastAPI server (stream, queue, think-cap) |
dflash_port/ | Vendored z-lab MLX port + integration patches (README inside) |
prep_text_model.py | Strip vision_config → clean mlx_lm text path |
scripts/ | setup / download / serve / smoke_test / run_tests |
bench/ | K sweep, edit gate, lossless-ness diagnostics; shared bench_common.py |
tests/ | Unit tests (CI-safe, no model load) |
deploy/ | macOS launchd installer |
AGENTS.md | Machine-readable guide: traps, workflows, server internals |
_get_layers nesting — mlx_lm.load() on this checkpoint returns
Model.language_model.model.layers (3 levels). Upstream hooks stop at 2.
Applied in dflash2_mlx_server/server.py + bench/bench_common.py.<|im_end|> as
token 1 on bare prompts (instant EOS). Always go through
apply_chat_template(..., add_generation_prompt=True).<think> on a shared route burns the
whole max_tokens budget before answering. The server enforces a hard cap
(--think-cap, default 12000):max_tokens = min(user_budget, THINK_CAP) and
watches for the </think> token id.</think>\n\n into the
context and re-prefills, so the model still produces a full answer in
the remaining budget (verified: cap=300 test produced a complete modular-
arithmetic proof, 94% accept, think_capped: true in response stats).dflash2.think_capped so callers can tell a capped run
from a natural one.POST /v1/chat/completions (stream + non-stream), GET /v1/models,
GET /health. Every response carries a dflash2 stats block
(accept_rate, tok_per_s, think_capped) — use it to verify spec decode is
engaged. Single-flight generation (MLX is single-stream): concurrent
requests queue behind a lock rather than being rejected.1# litellm_config.yaml
2model_list:
3 - model_name: qwen3.8-27b-dflash2
4 litellm_params:
5 model: openai/qwen3.8-27b-dflash2
6 api_base: http://<m3-tailscale-ip>:8006/v1
7 api_key: "not-needed"
8 request_timeout: 900
9 extra_body:
10 chat_template_kwargs:
11 enable_thinking: falsedeploy/install.sh.mlx-community/Qwen3.8-27B-mxfp4z-lab/Qwen3.8-27B-DFlash2