The Pivot to N-Gram Speculation: A Training-Free Gamble

Introduction

In the high-stakes world of large language model inference optimization, every millisecond counts. When speculative decoding—a technique that uses a smaller "draft" model to predict tokens ahead of the main model—fails to deliver speedups, the search for alternatives becomes urgent. Message 5015 in this opencode session captures a critical pivot point: the moment when the assistant, having just concluded that a complex fine-tuning approach had failed, turns to explore a simpler, training-free alternative built directly into the SGLang inference engine.

The Message

The subject message is brief but consequential. After a series of exchanges where the user and assistant debated the viability of fine-tuning an existing EAGLE-3 drafter from the AQ-MedAI project onto the Kimi-K2.5 model, the assistant writes:

SGLang has NGRAM speculation built in. Let me check how it works — it's a training-free approach.

>

``bash ssh root@10.1.230.174 'find /root/sglang/python/sglang/srt/speculative/ -name "*ngram*" -not -path "*__pycache__*"' ``

>

Output: `` /root/sglang/python/sglang/srt/speculative/ngram_info.py /root/sglang/python/sglang/srt/speculative/cpp_ngram /root/sglang/python/sglang/srt/speculative/cpp_ngram/ngram.h /root/sglang/python/sglang/srt/speculative/cpp_ngram/ngram.cpp /root/sglang/python/sglang/srt/speculative/cpp_ngram/ngram_cache_binding.cpp /root/sglang/python/sglang/srt/speculative/cpp_ngram/ngram_cache.py /root/sglang/python/sglang/srt/speculative/ngram_worker.py ``

This message is deceptively simple. It contains a declaration of discovery ("SGLang has NGRAM speculation built in"), a characterization of the approach ("training-free"), and a reconnaissance command to verify the implementation exists. The assistant is not yet running the n-gram speculation—it is gathering information to assess whether this path is viable.

The Context That Drove This Message

To understand why this message was written, one must trace the arc of the preceding conversation. The assistant had spent considerable effort attempting to improve Kimi-K2.5 inference throughput through speculative decoding. The journey had been arduous:

First, a direct probe of the AQ-MedAI K2 EAGLE-3 drafter (Phase 0) achieved an accept length of approximately 1.5 tokens and 52 tokens per second—confirming architectural compatibility but revealing misaligned hidden state representations between the K2 and K2.5 models.

Then came Phase 1: fine-tuning the K2 drafter on K2.5 data. This initially produced random loss values (~18-20), which the assistant diagnosed as a critical vocabulary mapping mismatch—only 252 out of 32,000 draft-to-target token positions matched between the two models' vocabularies. Fixing this dropped the loss to approximately 9 and improved accuracy to around 24%. However, the fine-tuning plateaued at approximately 38% accuracy, converging significantly slower than the from-scratch model (which reached 75% by epoch 5).

The user's question in message 5010—"Do we have a simpler multi token predictors that could be used for now?"—was the catalyst. It signaled a willingness to abandon the complex fine-tuning path in favor of something that could work immediately, even if suboptimally. The assistant's response in message 5011 listed several alternatives (MTP, Lookahead decoding, EAGLE v1/v2, Prompt lookup decoding, REST, Medusa) and then checked what SGLang actually supports. Message 5014 revealed that SGLang's SpeculativeAlgorithm enum includes NGRAM alongside EAGLE, EAGLE3, STANDALONE, and NONE.

Message 5015 is the direct follow-through: now that the assistant knows NGRAM exists in the enum, they verify the implementation is real by locating the relevant source files.## Why N-Gram Speculation Matters

N-gram speculation is a form of speculative decoding that requires no training whatsoever. Instead of using a learned draft model (like EAGLE-3's transformer-based drafter), it works by matching n-gram sequences from the input prompt or recently generated text. If the model is generating text that repeats patterns seen earlier—common in code generation, structured data output, or conversational responses—n-gram speculation can predict multiple tokens ahead with high accuracy, entirely for free.

The appeal for this particular deployment is obvious. The assistant had just spent hours fine-tuning a drafter that plateaued at 38% accuracy, while the from-scratch model had reached 75%. The K2 weights were actively harmful as an initialization. Scaling up training data from 37K to 200K+ samples was the identified path forward, but that would take hours or days of generation, extraction, and retraining. N-gram speculation promised immediate results with zero additional training cost.

However, the assistant's characterization as "training-free" is both accurate and misleading. N-gram speculation requires no model training, but it does require computational overhead: it builds and queries an n-gram cache, and the verification step (checking draft tokens against the target model) still incurs the same ~30ms verify latency that was the fundamental bottleneck in the EAGLE-3 approach. The n-gram approach trades model quality for availability—it will always be available, but its acceptance rate depends entirely on the repetitiveness of the generated text.

Assumptions and Knowledge Required

To understand this message, the reader needs several pieces of context. First, one must understand the architecture of speculative decoding: the distinction between a draft model (which proposes tokens cheaply) and a target model (which verifies them). The "verify step" is the critical bottleneck—in this deployment, it took approximately 30ms and was dominated by NCCL all-reduce communication overhead across 8 GPUs.

Second, one must understand the SGLang codebase structure. The assistant knows that speculative algorithms are defined in spec_info.py and implemented in the speculative/ subdirectory. The find command targets this directory with a pattern for n-gram files, excluding __pycache__ to avoid compiled bytecode.

Third, one must understand the hardware context: a machine with 8 RTX PRO 6000 Blackwell GPUs connected via PCIe, where communication overhead dominates compute time. This constraint shapes every decision about speculation viability.

The assistant makes several assumptions in this message. The primary assumption is that n-gram speculation, being built into SGLang, will work correctly with the existing infrastructure. There is an implicit assumption that the n-gram implementation is mature enough to be worth testing—the presence of C++ source files (.h, .cpp) alongside Python wrappers suggests a performant implementation, but the assistant does not yet verify correctness or performance.

The Thinking Process Visible in the Message

The message reveals a structured investigative process. The assistant first states the discovery ("SGLang has NGRAM speculation built in") and immediately characterizes it ("training-free approach"). This characterization is the key reasoning step: the assistant is evaluating whether this approach avoids the fundamental problem that doomed the K2 fine-tuning (the need for training data and convergence).

The command itself is a reconnaissance operation. The assistant could have simply read the enum definition and assumed the implementation existed, but instead chose to verify by locating actual source files. The -not -path "*__pycache__*" filter shows attention to detail—the assistant wants to see only the actual source code, not cached bytecode that might be stale.

The output reveals a substantial implementation: a Python info module (ngram_info.py), a C++ implementation directory (cpp_ngram with header, implementation, and cache binding files), a Python cache module (ngram_cache.py), and a worker module (ngram_worker.py). This is not a trivial stub—it is a full implementation with C++ performance optimization. The assistant now has enough information to proceed with testing.

What This Message Creates

This message produces several forms of output knowledge. First, it confirms that SGLang's n-gram speculation is a real, implemented feature with both Python and C++ components. Second, it establishes the file locations for future reference—if the assistant needs to modify or debug the n-gram implementation, it knows exactly where to look. Third, it sets the stage for the next action: testing n-gram speculation performance.

The message also implicitly creates a decision point. The assistant has not committed to using n-gram speculation—it has only verified its existence. The next step would be to launch a server with n-gram speculation enabled and benchmark its throughput. The user's question about simpler alternatives has been answered with a concrete, available option.

Conclusion

Message 5015 is a small but pivotal moment in a larger narrative of optimization troubleshooting. It represents the shift from a failed data-centric approach (fine-tuning a drafter that plateaued at 38% accuracy) to a pragmatic, system-level exploration of available alternatives. The assistant's methodical verification—checking the enum, then finding the source files—demonstrates a disciplined approach to problem-solving. While n-gram speculation would ultimately prove worse than baseline (achieving only 41 tok/s in subsequent testing), the pivot itself was a necessary step in the systematic exploration of the optimization landscape. Sometimes the most valuable thing a message can do is confirm that a door exists, even if it leads to a dead end.