Ternary PTQ for DeepSeek V4.1 Flash (Bonsai-2-style, ~1.72 bpw): could make main weights resident on 256 GB Macs and ~2.5x SSD-streaming decode on 128 GB
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 38/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- c
- Ambito
- machine-learning, performance
Direzione di ricerca
Start with the existing IQ2_XXS/Q2_K imatrix pipeline and score harness, following the suggested offline ternarization of a subset of routed experts. Measure NLL and top-token quality before considering Metal kernels; done means the subset results establish whether retention is sufficient to justify further kernel work.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Body:
Proposal
Explore a ternary post-training quantization (Bonsai-2-style: Hadamard-rotated {−1,0,+1} weights, ~1.72 bpw, imatrix-calibrated) for the DeepSeek V4.1 Flash main weights, produced from the FP16 safetensors (not from an existing quant).
Why this could matter a lot for ds4 users
The math (V4.1 Flash, Q4 today = 518.6 GB file):
- Main weights: 294 GB at ~4.5 bpw → ternary ~1.72 bpw ≈ 112 GB
- Engram tables: 189 GB (untouched, they are lookup content)
- Ternary file: ~300 GB total (−217 GB vs Q4)
Two user classes liberated:
-
256 GB Macs — full residency. 112 GB of main weights fits in 256 GB unified memory with room for KV and buffers. Today V4.1 Flash Q4 on a 256 GB machine is SSD-streaming-bound at ~8–9 tok/s decode (measured, M3 Ultra; matches the ROCm port's numbers on similar hardware). Resident decode would put the flagship model in a completely different speed class.
-
128 GB Macs (and all streaming users) — SSD-streaming decode is byte-bound. Streaming decode speed scales with expert bytes fetched per token. Ternary cuts routed-weight bytes by ~60% (1.72 vs 4.5 bpw), so streaming decode should scale to roughly 2–2.5× today's 4.5–5.5 tok/s on equivalent SSDs, making 128 GB machines genuinely usable for V4.1.
Evidence the technique works on this model family
- PrismML's Bonsai 2 27B (Apache-2.0, whitepaper linked) applies exactly this method — Hadamard-rotated ternary at a true 1.72 bpw, no high-precision escape hatches — to Qwen3.8-27B, a hybrid-attention model (~75% linear attention), and reports 98.2% of FP16 benchmark retention (84.78 avg across 14 thinking benchmarks, math within 0.5 pt), beating IQ2_XXS by >12 points at 2/3 of its footprint and matching UD-Q4_K_XL at 1/3 the size. They ship custom ternary llama.cpp kernels for CUDA and Metal, and PQ2_0 (2-bit-slot packing) now runs on mainline llama.cpp CPU/Metal/Vulkan/CUDA.
- So ternary kernels for a Qwen3.8-family hybrid-attention backbone already exist; the missing pieces for V4.1 are (a) the MoE routed-expert path and (b) the Engram/attention specifics of ds4's graph — which is exactly the kernel engineering this project is best at.
- ds4 already has the calibration side: the IQ2_XXS/Q2_K imatrix pipeline for V4.1.
Fair caveats
- 98.2% retention is a 27B dense result; 755B MoE expert ternarization is unproven and router sensitivity is a real risk. A first step could be small-scale: ternarize a few expert layers, measure NLL/top-token on the existing quality harness before committing to full kernels.
- Engram tables (189 GB) cannot be ternarized (lookup content), so total-file savings are bounded (~217 GB); the headline win is residency on 256 GB and streaming speed on everything smaller.
- Vision tower would ship separately as today.
Suggested incremental path
- Imatrix ternary PTQ of a subset of routed experts (offline, no kernels needed) → run the existing score harness → decide.
- If retention looks Bonsai-like: prototype ternary Metal kernels for the routed path, ssd-streaming first (helps 128 GB + all streamers), residency second.
- Optional: coordinate with PrismML — their kernels are Apache-2.0 and already handle Qwen3.8-family hybrid attention.
A 256 GB M3 Ultra user measurably stuck at the SSD-streaming ceiling would love to help test.
- Lingua principale
- C
- Stelle
- 24.4k
- Fork
- 2.4k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di antirez/ds4
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
antirez/ds4#1189 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
antirez/ds4#1173 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
antirez/ds4#1032 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
awslabs/aws-c-common#1319 ·
-
editor/integration
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
DeusData/codebase-memory-mcp#3130 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 13 giorni
-
DBMS_UTILITY.FORMAT_ERROR_STACK exceeds the 2000-byte limitForse già presa @coder999o l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
zephyrproject-rtos/zephyr#127560 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni