Adaptive Speculative Decoding, Sub-Millisecond Tokenization, and Hot-Path Inference Systems in Hanzo Engine
O(1) Suffix Automata, SA_SPEC Draft Bypass, GuardedDraft Cooldown, Pure-Rust BPE, SIMD Vision, and HKV1 KV Fabric
Zach Kelling · Hanzo AI Research
Abstract
We present native Rust hot-path inference systems shipped in Hanzo Engine (commit 36cd0bb3c) and Hanzo ML (commit c9bee7434): an incremental O(1) SuffixAutomaton tracking most-recent context occurrences via lockstep 2-gram intersection (26.8x-34.8x faster misses across 1K-16K contexts); SA_SPEC neural draft bypass paired with an EWMA GuardedDraft cooldown controller that preserves unconditional target-model verification and fixes CUDA top_k=1 argmax routing plus nonzero layout.start_offset() verification slicing; a clean-room pure-Rust hanzo-tokenizer crate with packed 2-bit Unicode class tables and self-bypassing PromptTokenCache (35.0x-101.9x faster than HF tokenizers 0.21.4 on 32.8 KiB inputs with 100% token-ID parity); SIMD vision preprocessing in hanzo-vision (3.21x-3.23x speedup); cached minijinja environments (1.36x); and epoch-fenced HKV1 KV block transport in hanzo-kv-fabric. On a warm 20-turn developer-agent conversation using zen6-nano-4b-PQ2_0-MTP-Q8_0.gguf on NVIDIA GB10 CUDA, full adaptive speculation lifts draft acceptance from 21.3% to 49.2%, lowers grounded edit inter-token latency from 27.57 ms to 2.79 ms (2.59 ms standalone lookup), and reduces total wall-clock time to 38.19 s (1.96x faster than unguarded MTP and 1.72x faster than uncached decode).