Code Generation
~8 min readUpdated: November 2026

SpecZip: Train Speculative Drafters on 16x Compressed Hidden-State Caches

SpecZip PCA-RWF Compressed Speculative Drafter Training in Smoke Monkey

SpecZip (arXiv:2611.35534) enables single-node offline training of EAGLE-3 and DFlash speculative-decoding drafters by compressing 34–55 TB BF16 target hidden-state caches by 16x down to 2.2–3.4 TB. Using PCA with reverse water-filling (PCA-RWF) and subspace projection, SpecZip retains 99–101% of full-precision acceptance length across Qwen3-4B, Gemma-4-12B, and Qwen3.5-122B-A10B at 1.95–3.25x higher training throughput than online training.

Technical Review: Smoke Monkey Core Architecture Team
Tested on Node.js 18+ & BunTypeScript 5.x
Quick Answer & Executive Definition

SpecZip: Train Speculative Drafters on 16x Compressed Hidden-State Caches: SpecZip (arXiv:2611.35534) enables single-node offline training of EAGLE-3 and DFlash speculative-decoding drafters by compressing 34–55 TB BF16 target hidden-state caches by 16x down to 2.2–3.4 TB. Using PCA with reverse water-filling (PCA-RWF) and subspace projection, SpecZip retains 99–101% of full-precision acceptance length across Qwen3-4B, Gemma-4-12B, and Qwen3.5-122B-A10B at 1.95–3.25x higher training throughput than online training. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.

Key Architectural Takeaways
Quick Implementation Examplespeczip-drafter-pipeline.ts
speczip-drafter-pipeline.tstypescript
import { createAgent } from '@smoke-monkey/harness';
const drafterTrainer = createAgent({
agentId: 'speczip-drafter-orchestrator',
provider: 'vllm',
model: 'Qwen/Qwen3-32B',
workspacePath: process.cwd(),
permissions: {
read_file: 'allow',
write_file: 'allow',
run_command: 'ask',
},
});
async function prepareCompressedCache() {
const result = await drafterTrainer.run(
'Fit PCA-RWF basis on tapped target hidden states at 16x compression (~2.2TB), project out discarded subspace from drafter W_in, and benchmark acceptance length tau.'
);
console.log('SpecZip Pipeline Summary:', result.summary);
}
prepareCompressedCache().catch(console.error);
Video Guides

Watch: Related Video Guides

Faster LLMs: Accelerate Inference with Speculative Decoding

What is Speculative Decoding? making LLMs faster

What Is SpecZip? Why Offline Drafter Caches Break Equal-Bit Codecs

Modern speculative-decoding drafters—including EAGLE-3, DFlash, and DSpark—concatenate intermediate hidden states from several tapped target-model layers. Online training recomputes target forward passes every epoch, burning 2–3x extra GPU hours, while offline BF16 caching balloons to 34–55 TB and overflows local 8-GPU node storage.

SpecZip identifies two root causes behind acceptance-length collapse when compressing these caches: first, 99% of hidden-state variance sits inside 32% of principal components, so equal-bit codecs waste bits on noise; second, training on a compressed cache and serving on uncompressed BF16 states induces a train-serve mismatch in the drafter's linear input layer W. SpecZip solves both via PCA with reverse water-filling (PCA-RWF) and subspace projection.

Acceptance Length Retention & Compression Benchmarks (16x to 64x)

Evaluated with DFlash drafters across Qwen3-4B, Gemma-4-12B, and Qwen3.5-122B-A10B MoE, SpecZip's PCA-RWF codec dominates equal-bit vector and scalar codecs at every compression tier.

Compression CodecAllocation Strategy16x Retention (%)32x Retention (%)64x Retention (%)
SpecZip (`PCA-RWF`)Variance-allocated PCA, no per-token scales99.65%98.50%96.45%
KVTCVariance-allocated transform coding99.36%97.28%94.02%
OPQ + PCA BasisEqual bits in rotated PCA basis91.02%91.52%90.36%
PQEqual-bit product quantization94.63%80.11%61.88%
OPQEqual-bit optimized product quantization94.68%79.88%61.38%
TurboQuantRandom rotation + vector norm80.57%n/an/a

At 16x compression on Qwen3-4B, PCA-RWF preserves 5,346 coded directions (vs 3,872 for KVTC) with orthogonal truncation error E_perp = 0.0028 (vs 0.0078). On Gemma-4-12B, PCA-RWF reaches 10,944 coded directions (E_perp = 0.0037), and adding serve projected subspace alignment lifts KVTC 16x retention from 99.36% to 99.98%.

Fixing Train-Serve Subspace Mismatch

Because speculative verification always uses exact target logits, hidden-state compression only affects acceptance length `tau`—never output distribution. Projecting discarded low-variance components out of the drafter's input at serving recovers up to +2.64 pp retention at 64x.

Implementing Variance-Weighted Subspace Projection for Drafters

To avoid per-token scale overhead while matching target hidden-state statistics, compute the PCA basis on a calibration sample, retain top-variance components under the bit budget, and project out discarded eigenvectors from the drafter's linear input matrix.

python
import torch

def fit_pca_rwf_basis(hidden_samples: torch.Tensor, keep_rank: int):
    """hidden_samples: [N, D_concat] tapped target hidden states."""
    mean = hidden_samples.mean(dim=0, keepdim=True)
    centered = hidden_samples - mean
    _, _, vt = torch.linalg.svd(centered, full_matrices=False)
    basis = vt[:keep_rank].T  # [D_concat, keep_rank]
    return mean, basis

def project_out_unseen(w_in: torch.Tensor, basis: torch.Tensor) -> torch.Tensor:
    """Restrict drafter linear layer W_in [D_draft, D_concat] to kept PCA subspace."""
    proj = basis @ basis.T
    return w_in @ proj

Accelerating Local Coding Loops in Smoke Monkey Harness

Coding agents emit predictable syntax, imports, and AST boilerplate where speculative drafters like DFlash and EAGLE-3 achieve high acceptance lengths. Pairing SpecZip-trained drafters with Smoke Monkey Harness cuts per-turn token generation latency on local vLLM/SGLang nodes while keeping training costs inside a single 8-GPU workstation.

Google Search Questions & Answers

Frequently Asked Questions

Q:Does compressing target hidden states change the LLM's output quality?

No. Speculative decoding verifies every drafted token against the exact target model, so output distribution is mathematically identical. Compression only affects drafter acceptance length `tau`.

Q:Why does SpecZip beat TurboQuant and PQ for drafter training caches?

99% of tapped hidden-state variance lives in 32% of principal components. TurboQuant and PQ allocate equal bits across all coordinates, whereas SpecZip's PCA-RWF allocates bits by variance and drops per-token scale overhead.

Q:How much disk space does a 16x SpecZip cache require?

A standard 34–55 TB BF16 training corpus compresses by 16x to 2.2–3.4 TB, fitting onto the local NVMe SSD array of a single 8-GPU node.

Q:How fast is offline drafter training with SpecZip vs online training?

By caching compressed hidden states once and overlapping GPU decompression with training steps, SpecZip delivers 1.95x to 3.25x higher training throughput than online training.

Related Alternatives & Comparisons

Related Architecture Guides

View all guides

Build with Smoke Monkey Harness

Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.

npm install smoke-monkey-harness