docs(bonsai): post-mortem + ANE decode-state lessons#163
Merged
Conversation
Adds the post-mortem for the ternary Bonsai investigation and the ANE decode-path lessons it produced. The Qwen3 architecture support that came out of the same investigation lands separately. Why Bonsai didn't ship: - prism-ml/Ternary-Bonsai-1.7B's compression depends on per-(row, block) independent scales (g=64). ANEC rejects that LUT granularity with error -14, and the stock-API per-block approximation factorizes scales into a rank-1 outer product, defeating the model's design. - For Apple Silicon, the GPU path (mlx-lm with the official Ternary-Bonsai-1.7B-mlx-2bit) is the only honest option. What lands as reusable infrastructure: - docs/TERNARY_BONSAI.md: full post-mortem (what was tried, why each failed, what the right path is) - docs/DECODE_STATE_LAYOUTS.md: ANE decode-state catalog — mask-based rotating buffer pattern, ctx > weight bandwidth result, palettization traps, ternary-on-ANE checklist - docs/GEMMA4_ROTATING_BUFFER_PORT.md: design note for porting our mask-based rotating buffer to Gemma 4's full-attention layers - docs/NEXT_MODELS.md: shortlist (Qwen3-1.7B, Gemma 3 4B QAT, Llama-3.2, SmolLM3) for the next port - docs/ADDING_MODELS.md: §4.5 KV state-layout checklist - docs/ANE_OPTIMIZATION_SURVEY.md: cross-reference to the ctx>weights finding - conversion/experiments/bonsai/: research scripts (oracle, ternary surgery, SWA comparisons, decode-chunks builder) retained as breadcrumbs in case anyone retraces the path - conversion/config.py: NOTE comment in MODEL_REGISTRY explaining why Bonsai is intentionally absent and pointing readers to the doc Extracted from feat/qwen3-bonsai-investigation (commit 56ee545).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Qwen3 architecture support shipped in #162 came out of an investigation into porting
prism-ml/Ternary-Bonsai-1.7Bto ANE. Bonsai didn't ship — its per-(row, block) ternary scales can't be faithfully represented by ANEC (error -14 on per-block LUT palettization, and any stock-API approximation collapses the scales into a rank-1 outer product). This PR captures the post-mortem and the reusable lessons that came out of the failed port.What lands
docs/TERNARY_BONSAI.md— full post-mortem: what was tried, why each path failed, what the right path is (mlx-lm withprism-ml/Ternary-Bonsai-1.7B-mlx-2bit).docs/DECODE_STATE_LAYOUTS.md— ANE decode-state catalog. The headline finding: per-step decode cost on ANE isO(state_length), not weight-bandwidth (halving ctx 2048→1024 = 2.56× speedup, halving weights INT8→INT4 at same ctx = +12% only). Includes the mask-based rotating buffer pattern, palettization traps, and ternary-on-ANE checklist.docs/GEMMA4_ROTATING_BUFFER_PORT.md— design note for applying the mask-based rotating buffer to Gemma 4's full-attention layers.docs/NEXT_MODELS.md— shortlist: Qwen3-1.7B, Gemma 3 4B QAT, Llama-3.2, SmolLM3.docs/ADDING_MODELS.md— new §4.5 KV state-layout checklist.docs/ANE_OPTIMIZATION_SURVEY.md— cross-ref to the ctx > weight-bandwidth finding.conversion/experiments/bonsai/— 8 research scripts (oracle, ternary surgery, SWA comparisons, decode-chunks builder) kept as breadcrumbs.conversion/config.py— NOTE comment inMODEL_REGISTRYexplaining why Bonsai is intentionally absent.Extracted from
feat/qwen3-bonsai-investigation(commit 56ee545). Companion to #162 (Qwen3 architecture).Test plan
python conversion/convert.py --liststill works (config.py NOTE is a Python comment, no syntax change)