Speculative Decoding at 0 MB Extra VRAM: Can We Have Our Cake and Eat It Too?
First of all, I’m happy to say that we have finally reached line rate saturation on my own Apple M4 Pro’s memory bus. We have dreamed for days like this.
After weeks of debugging cacheline strides, register spills, and threadgroup barriers, our fused Metal kernel is finally streaming weights at full speed. For Ternary-Bonsai-2-27B (64 layers), our baseline single-token autoregressive latency dropped to 60.57 ms (16.51 tok/s), with prefill throughput clocking in at 116.34 tok/s.
We already had the physical memory footprint under control: the entire 27.2B model sits flat at 6.37 GB, shaving nearly 800 MB off the reference implementation.
Time to pull up the whiteboard: what’s compute-bound vs. memory-bound.
The Layman’s Physics: Compute-Bound vs. Memory-Bound
When you interact with a large language model, the hardware alternates between two entirely different physical regimes:
In prefill (M > 1), the model evaluates your entire prompt in parallel. Matrix engines churn through dense arithmetic, fully compute-bound.
In autoregressive decode (M = 1), the model spits out text one solitary word at a time. To produce a single token, the hardware has to drag the entire 27.2 billion parameter weight tensor from RAM across the memory bus. The compute units spend 90% of their cycles idling, waiting for weights to arrive.
If you look at official Bonsai benchmarks on their website, they report a baseline of 45.2 tok/s decode on high-end silicon like the Apple M5 Max. Because autoregressive decode scales almost linearly with memory bandwidth, extrapolating our fused kernel to an M5 Max (with its ~800 GB/s bus) projects decode speeds around 48 to 52 tok/s, while our AMX JIT prefill scales to over 330 tok/s (comfortably beating Bonsai’s ~285 tok/s baseline by 15%).
On our everyday laptop M4 Pro (273 GB/s peak), hitting 16.5 tok/s at line-rate is solid. But for true agentic work (multi-turn tool calls, file parsing, background reflection), you want that 30 to 40+ tok/s responsiveness without having to drop £4,000 on a high-end Max Studio.
The standard reflex is speculative decoding: draft ahead with a small model, verify in parallel.
But it’s never this simple, is it?
1. The VRAM Penalty
Generally, a smaller model entails a smaller memory footprint, so that reflex is justified. In FP16 or INT4 land, pairing a 70B model with a 0.5B draft model takes a tiny fraction of the host budget.
But we are running a ternary model here. The entire 27.2 billion parameter network already fits in a lean 6.37 GB. Adding an extra 1.0 to 2.5 GB just for an external draft network adds 20% to 40% straight back onto our memory footprint.
Do we even have specialized small ternary draft models? Would their vocabularies match? We don’t know until that day comes. For now, ballooning our memory footprint with an external model is probably not the right route to go for.
2. The Entropy & Vocabulary Mismatch
Underneath the hood, models are pure numbers. Numbers need to be mapped to tokens, but there is zero standardization here. Different models use different tokenizers, different vocabularies, and different training distributions.
Speculative decoding with an external draft model makes for a great tech demo. But as Steve Jobs once said, try putting your mission-critical work on it.
And you know what’s completely unacceptable? The acceptance rate cratering. The moment you run complex tasks, acceptance drops below 20%. At that point, whatever gains you hoped for evaporate; the verification overhead kicks in, and you are actually running slower than native autoregressive decode.
So now you get where I’m coming from. I don’t want the memory footprint to balloon, and vocabulary needs to not be an issue. Can we have our cake and eat it too? Following are the recipes I tried.
Strategy 1: Prompt Lookup Decoding (PLD)
If the name didn’t really give it away, think about it this way: for tasks like code generation, JSON schema extraction, and RAG, the next tokens are generally already in the context window. Why run the damn neural network again? Just do an n-gram matching directly against tokenized prompt history, right?
- Zero Memory Overhead: Strictly 0 MB extra VRAM.
- Fast Candidate Lookup: O(1) dictionary lookups over 3-grams and 2-grams via
FastNGramIndex. Zero GPU dispatch. - Early-Break Verification: We rewrote verification with sequential 1-token GEMV on the
lm_headprojection, breaking the instant Candidate 0 misses. That slashed verification latency from 52 ms down to 2.4 ms. - The Result: On structured code synthesis, PLD halved decode latency from 170.5 ms/tok down to 85.14 ms/tok, an immediate 2.0x speedup.
Strategy 2: Self-Speculative Layer Pruning (Layers 1..16)
For generative reasoning where prompt n-grams provide no coverage, we discarded external draft models in favor of in-situ layer pruning.
Instead of loading a separate network, we execute the first 16 layers of Bonsai’s existing 64-layer backbone as our proposal path.
In a unified address space, the weights for layers 1 through 16 already sit resident in RAM. We simply point the draft execution path directly at those identical memory buffers:
- Extra Weight Footprint: Strictly 0 MB.
- Proposal Latency: 17.62 ms (56.8 tok/s), compared to 60.57 ms for the full 64 layers.
- Vocabulary Alignment: 100% shared 248k vocabulary. Zero cross-tokenizer projection bugs.
It’s Never That Easy: Representation Drift and Acceptance Walls
While layer pruning delivers an ultra-fast proposal pass, our empirical benchmarks revealed a harsh systems reality: intermediate representation drift.
In a 64-layer transformer, the hidden state at Layer 16 has not yet converged into the late-stage manifold geometry that the final lm_head expects. Passing uncalibrated Layer 16 activations directly into the unembedding projection caused draft entropy to spike wildly:
- Baseline Layer 16 Acceptance: A dismal 0.8%. Candidate tokens missed almost every single turn.
- The Rejection Penalty: Dragged end-to-end decode down to 5.8 - 6.5 tok/s (far slower than the 16.5 tok/s native decode).
Developer: “Can we have speculative decoding?”
Apple Silicon: “We have speculative decoding at home.”
Speculative decoding at home: Layer 16 draft proposal missing every token, running at 5.8 tok/s because of verification overhead.
The Fix: Training the RFC-002 Early-Exit Adapter
To bridge the representation gap without loading gigabytes of weights, we implemented RFC-002:
- Architecture: A lightweight bottleneck adapter (
5120 -> 1024 -> 5120) with RMSNorm stabilization, projecting Layer 16 hidden states directly into the manifold geometry expected bylm_head. - Footprint: A tiny 20 MB checkpoint (
checkpoints/early_exit_adapter_layer16.safetensors). - Empirical Result: Training the adapter boosted Layer 16 acceptance from 0.8% to 7.1% on complex code.
Great Demos vs. Prime Time: Quarantining for v0.6.0
Here is the honest engineering truth:
A 7.1% acceptance rate makes for an interesting technical demo, but it is not ready for mission-critical prime time. On open-ended text, the overhead of candidate verification still pulls performance below our native engine.
For general-purpose workloads, the native Tier 3 Fused SOTA autoregressive core (15.2 - 16.5 tok/s, 6.37 GB VRAM) remains faster, leaner, and 100% bit-exact.
Rather than shipping a fragile default, we made an executive call for v0.6.0:
- Production Default: Pure Tier 3 Fused autoregressive decode.
- Experimental Flag: Speculative decoding is quarantined behind
--speculative-experimental [pld|self|auto]with a prominent terminal warning banner.
Prompt Lookup Decoding (PLD) delivers real, measurable 2.0x acceleration on repetitive schemas and code generation. But until distilled semantic exit-heads push general acceptance past 50% (slated for v0.7.0), native fused decode remains the production standard.
In Log 04, we step out of speculative scheduling and into raw silicon execution: why 1.58-bit models break classic GPU roofline assumptions by inverting arithmetic intensity, why academic lookup table methods fail on Apple GPUs, and how our production Metal kernel eliminates the ALU decompression bottleneck.