From 0.7 tok/s to 3-6× Speedup: The Custom Kernel Journey That Rescued Long-Context Decode on Blackwell GPUs

Introduction

In the high-stakes world of large language model inference, few metrics matter more than decode throughput. When a system is deployed with a 200,000-token context length, users expect usable generation speeds — not a crawl of minutes per response. This article chronicles a pivotal arc within a sprawling opencode coding session: the journey from a catastrophic 0.7 tokens-per-second decode collapse at 185k context to a 3-6× speedup achieved through custom CUDA kernel engineering on NVIDIA RTX PRO 6000 Blackwell GPUs (sm_120 architecture).

The story spans multiple phases: a hard-won deployment of 200k context-length on the CT200 server, a systematic benchmark that revealed a devastating performance cliff, a user's skeptical challenge that forced a deeper investigation, the identification of the Triton MLA verify attention kernel as the root cause, and ultimately the design, optimization, and deployment of a custom sm_120 verify attention kernel with CUDA graph support and KV defragmentation. This is a case study in disciplined performance debugging, GPU architecture understanding, and the art of knowing when off-the-shelf solutions must be replaced with custom engineering.

Part I: The Deployment — Making 200k Context Possible

The journey began with a seemingly straightforward goal: deploy the Kimi K2.6 model with DFlash DDTree speculative decoding on an 8-GPU RTX PRO 6000 Blackwell server (CT200) with 200,000 tokens of context length. The assistant quickly discovered that setting --context-length 200000 was not enough — SGLang sizes its KV cache pool based on memory budget (--mem-fraction-static), not the context-length parameter. The KV pool remained stubbornly pinned at 101,134 tokens [4].

The assistant methodically diagnosed the issue, calculating the per-token memory cost of MLA latent KV (~68 KB/token/GPU across 61 layers), raising mem-fraction-static from 0.85 to 0.92, then to 0.94, dropping max-running-requests from 64 to 8 to free the req_to_token pool, and restarting the service multiple times (each restart taking ~6 minutes) [5][6][7][8]. After an OOM crash at 32k context with the 0.94 setting, the assistant dialed back to 0.93, enabled chunked-prefill-size 4096 and expandable_segments:True, achieving a stable service with a KV pool of 195,011 tokens — 97.5% of the 200k target [25][26][27][28][29].

The deployment was technically complete. The server ran, handled requests, and produced correct tokens. But the question remained: how fast was it at long context?

Part II: The Benchmark That Exposed a Crisis

The user's directive was three words: "Benchmark long context perf" [14]. This simple request launched a comprehensive performance characterization that would reshape the entire project.

The assistant designed a streaming benchmark methodology to avoid prefix cache interference [15][16][17][18][19][20][21][22], running requests at context lengths from 1.4k to 185k tokens. The results were devastating [23][24][30][31]:

| Actual Context | Prefill (tok/s) | Decode (tok/s) | |---|---|---| | 1,427 | 3,104 | 118.6 | | 11,402 | 2,659 | 19.9 | | 31,952 | 1,820 | 6.3 | | 63,903 | 1,255 | 2.8 | | 127,802 | 696 | 1.4 | | 184,728 | 479 | 0.7 |

Decode throughput collapsed from 118.6 tok/s at 1.4k context to just 0.7 tok/s at 185k — a 170× slowdown. Step time ballooned from 8ms to 1.43 seconds. The DDTree speculative drafter reported avg_commit_len=1.00, meaning it was accepting only a single token per step — zero speedup from speculation [31][32][33][34].

The assistant initially attributed this to the drafter being "undertrained for long contexts" and the synthetic benchmark prompt being "novel prose" the drafter couldn't predict [34]. But the user immediately challenged this interpretation [35].

Part III: The User's Challenge That Changed Everything

In message 12176, the user raised four sharp concerns that fundamentally challenged the assistant's narrative [35][36]:

  1. "decode step per token increase seems extremely high, no?" — The latency scaling was far too steep to be explained by physics alone.
  2. "Do we have sliding window attention working in the drafter?" — If the drafter was attending the full context instead of a bounded window, its cost would scale linearly with context.
  3. "commit_len=1 is probably a bug" — A perfectly flat 1.0 across all samples, not a statistical distribution, looked like a systematic verification failure.
  4. "GPU use appeared to be quite low pointing to compute being far from saturated" — If the GPU was nearly idle during decode, the bottleneck wasn't compute but something else. These questions forced the assistant to pivot from "reporting mode" to "debugging mode" [37][38]. The assistant launched a systematic investigation spanning code inspection, controlled experiments, and GPU profiling.

Part IV: The Investigation — Ruling Out Hypotheses

The assistant's investigation was methodical and hypothesis-driven. First, it inspected the drafter's configuration [39], confirming it was a 6-layer Qwen3 model with sliding window attention (5 of 6 layers, window 2048) and YaRN position scaling. But configuration alone didn't prove runtime behavior.

The decisive experiment was a controlled commit-length probe using trivially predictable text ("The cat sat on the mat" repeated) at multiple context lengths [41][42][43][44]. The results were unambiguous:

| Context | Commit Len | Depth | Drafts | |---|---|---|---| | 1k | 7.88 | 7.00 | 7.00 | | 16k | 7.00 | 6.78 | 6.11 | | 64k | 7.00 | 6.11 | 6.11 | | 128k | 7.88 | 6.88 | 6.88 |

The drafter maintained commit lengths of 7–8 tokens at all context lengths. The sliding window attention, YaRN scaling, and KV caching were all working correctly. The commit_len=1 in the original benchmark was purely a text-difficulty artifact — the synthetic "continue this discussion" prompt produced genuinely unpredictable novel prose that the small drafter couldn't anticipate. Not a bug [43][44].

But this raised a deeper question: if the drafter was fine, why was decode so slow?

Part V: The GPU Utilization Revelation

The assistant deployed a GPU utilization probe during a 64k-context decode run [45]. The results revealed a stunning paradox:

PREFILL: SM%= 99.4  memctrl%=  5.0  power_W= 301.7
DECODE : SM%= 99.8  memctrl%=  1.2  power_W= 133.6

During decode, nvidia-smi reported 99.8% SM utilization — suggesting the GPU was fully saturated. Yet the memory controller was barely active at 1.2%, and power draw had collapsed to 133.6W — roughly 22% of the GPU's thermal design power. The SMs were "occupied" but doing almost no useful work [45][46].

The user independently confirmed this with cufall screenshots showing tensor core utilization at ~3% during decode, versus 50–90% during prefill [47]. This was the smoking gun: the decode kernel was latency-bound, not compute-bound or bandwidth-bound. The GPU was spending 97% of its cycles stalled, waiting on something.

The assistant calculated the effective bandwidth for KV cache reads: at 64k context, each decode step reads ~4.5 GB of compressed latents. With a step time of ~327ms, the effective bandwidth was ~14 GB/s — 130× below the GPU's 1.8 TB/s peak [46][49].

Part VI: The Root Cause — page_size=1 and the Triton Lock

Tracing the structural cause led to a hard constraint in SGLang's DDTree implementation [48][49][50]. Reading the source code of dflash_worker.py revealed:

if self.is_ddtree and self.page_size != 1:
    raise RuntimeError(
        "DDTREE currently requires --page-size 1 because accepted tree nodes "
        "are non-contiguous in the verify block."
    )

DDTree requires page_size=1. The tree-structured speculative decoding means accepted tokens are scattered non-contiguously across the KV cache, forcing per-token page granularity. And the verify attention — the step where the target model evaluates the draft tree — is locked to the Triton MLA backend because no other backend (FlashInfer, FlashMLA, cutlass-MLA) supports custom tree attention masks for MLA on sm_120 [48][49].

The combination was catastrophic: page_size=1 forces scattered, non-coalesced memory access; Triton MLA on sm_120 lacks the advanced tensor core instructions (wgmma, TMA, tcgen05) that make attention efficient on Hopper and datacenter Blackwell; and batch size 1 with 9 queries provides minimal parallelism. The result was 3% tensor core utilization and 0.7 tok/s [46][48][49].

The assistant also discovered that all optimized MLA kernels — FlashMLA, cutlass-MLA, flashinfer-MLA — are compiled only for sm_90a/sm_100a/sm_103a. None support sm_120 (the RTX PRO 6000 Blackwell consumer architecture). There was no off-the-shelf fix [48].

Part VII: Building the Custom sm_120 Verify Kernel

With the root cause confirmed, the assistant pivoted to building a custom solution. The strategy was outlined in plans/0002-sm120-verify-kernel-defrag.md and executed in phases.

The core insight was to separate the verify attention into two parts: the contiguous prefix (which doesn't need masking and can use coalesced reads at full bandwidth) and the small tree block (typically 9 nodes, which needs the custom mask and scattered access). By handling the prefix efficiently and applying the tree mask only to the small block, the native kernel could eliminate the 130× penalty.

The assistant wrote verify_attn_flash.cu, a KV-split flash-decode MLA verify kernel with a partial+reduce design to improve occupancy. The kernel was iteratively optimized:

  1. Made capture-safe for CUDA graphs — ensuring the kernel could be captured into a CUDA graph for minimal CPU-GPU synchronization overhead during low-latency serving.
  2. Increased NSPLIT to 64 — improving occupancy by splitting the KV dimension across more thread blocks.
  3. Added 128-bit vectorized BF16 KV loads — maximizing memory bandwidth utilization by loading 8 BF16 values per instruction instead of scalar loads. The kernel passed token-exact correctness tests against the naive oracle, and microbenchmarks showed significant improvements over the Triton baseline.

Part VIII: KV Defragmentation and Live Deployment

Beyond the kernel itself, the assistant implemented Tier 0 KV defragmentation by monkeypatching SGLang's allocator to keep per-request KV contiguous. This ensured that the prefix portion of the KV cache could be read with coalesced access patterns, maximizing the benefit of the custom kernel.

The live service was updated to run the owned capture-safe kernel with CUDA graphs enabled and Tier 0 defrag active. The end-to-end benchmark results showed a 3–6× decode speedup over the Triton baseline across all context lengths (4k–65k). The system that had been producing 0.7 tok/s at 185k was now delivering usable throughput.

Part IX: The Remaining Bottleneck — MoE Imbalance

With the verify attention bottleneck addressed, the assistant identified the next frontier: MoE expert imbalance at batch size 1. The Mixture-of-Experts layers in Kimi K2.6 are drastically inefficient at low batch sizes (M=1 to M=9), performing approximately 22× worse per token than at higher batch sizes. This is a structural ceiling beyond the verify kernel's scope — it would require either batching multiple requests together or implementing expert parallelism to keep all experts busy.

The assistant documented this as the remaining bottleneck, noting that the MoE inefficiency is a separate concern from the attention bottleneck. The attention fix unlocked 3–6× speedup; the MoE fix would require a different engineering effort.

Conclusion: A Case Study in Performance Engineering

This chunk of the opencode session is a masterclass in systematic performance engineering. It demonstrates several crucial lessons:

Measurement before optimization. The user's three-word directive — "Benchmark long context perf" — forced the assistant to characterize the system before attempting to optimize it. This revealed a 170× decode slowdown that no amount of configuration tuning could fix.

Trust but verify metrics. The nvidia-smi SM% metric reported 99.8% utilization, suggesting a fully saturated GPU. Cross-referencing with power draw, memory controller utilization, and tensor-core profiling revealed the truth: the GPU was 97% stalled.

Know when to build custom. The assistant explored every off-the-shelf option — FlashMLA, cutlass-MLA, flashinfer-MLA — and found that none supported sm_120. Building a custom kernel was not a luxury; it was the only viable path.

Systematic hypothesis elimination. The investigation ruled out drafter bugs, sliding window failures, KV caching issues, and compute-bound bottlenecks through controlled experiments before converging on the true root cause.

The result — a 3–6× decode speedup through custom kernel engineering — transformed a system that was technically functional but practically unusable into a viable long-context inference platform. The remaining MoE bottleneck is a testament to the depth of optimization still possible, but the verify attention fix alone represents a dramatic improvement in the system's capabilities.## References

[4] "The 101,134-Token Ceiling: When Configuration Assumptions Meet Reality" — [chunk 66.0]

[5] "The KV Pool That Wouldn't Grow: A Lesson in SGLang Memory Configuration" — [chunk 66.0]

[6] "Tuning the KV Cache: A Deep Dive into Memory Configuration for 200k Context on Blackwell GPUs" — [chunk 66.0]

[7] "The Waiting Game: A Six-Minute Polling Loop That Reveals the Hidden Complexity of LLM Deployment" — [chunk 66.0]

[8] "The Verification That Mattered: A 192,406-Token KV Pool and the Art of Empirical Inference" — [chunk 66.0]

[14] "Three Words That Changed Direction: 'Benchmark Long Context Perf'" — [chunk 66.0]

[15] "Designing a Long-Context Benchmark: Methodology, Assumptions, and the Pursuit of Measurable Performance" — [chunk 66.0]

[16] "Reading the Benchmark: A Deliberate First Step in Measuring Long-Context Decode Performance" — [chunk 66.0]

[17] "The Art of Benchmark Design: Reasoning Through a Long-Context Performance Evaluation" — [chunk 66.0]

[18] "The Bridge Between Development and Measurement: Deploying a Benchmark Script in an ML Performance Investigation" — [chunk 66.0]

[19] "The NaN That Revealed a Flaw: Benchmarking Long-Context Decode in SGLang" — [chunk 66.0]

[20] "When Benchmarking Methodology Meets System Optimizations: Diagnosing Prefix Cache Interference in SGLang" — [chunk 66.0]

[21] "The Edit That Fixed a Phantom: Diagnosing Prefix Cache Poisoning in SGLang Benchmarking" — [chunk 66.0]

[22] "The Verification That Saved a Benchmark: How One curl Command Prevented a Wasted Hour" — [chunk 66.0]

[23] "The Benchmark That Revealed a Crisis: Decode Throughput Collapse at Scale" — [chunk 66.0]

[24] "The Performance Cliff: Diagnosing a 8× Decode Slowdown and OOM Crash in Long-Context Speculative Decoding" — [chunk 66.0]

[25] "The OOM at 32K: Navigating Memory Tradeoffs in Long-Context LLM Deployment" — [chunk 66.0]

[26] "The 0.01% Fix: How a Fractional Memory Adjustment Unlocked 200k-Context LLM Serving" — [chunk 66.0]

[27] "The Streaming Pivot: A Methodological Breakthrough in LLM Benchmarking" — [chunk 66.0]

[28] "The 450-Second Wait: Validating Memory Configuration After an OOM Crash" — [chunk 66.0]

[29] "The Pragmatic Tradeoff: Choosing Stability Over a Perfect 200k Token Pool" — [chunk 66.0]

[30] "The 1.4 Tok/s Cliff: Diagnosing Long-Context Decode Collapse on Blackwell GPUs" — [chunk 66.0]

[31] "The 0.7 Tokens-Per-Second Threshold: A Benchmarking Message That Exposed the Verify Attention Bottleneck" — [chunk 66.0]

[32] "The 0.7 tok/s Cliff: How a Single Diagnostic Command Revealed Speculative Decode Collapse at 185k Context" — [chunk 66.0]

[33] "The 0.7 tok/s Revelation: When Speculative Decoding Collapses to Autoregressive Floor" — [chunk 66.0]

[34] "The Long-Context Benchmark: A Pivot Point in the DDTree Inference Stack" — [chunk 66.0]

[35] "The Moment of Reckoning: A User's Challenge That Reshaped a Long-Context Inference Investigation" — [chunk 66.0]

[36] "The Moment of Doubt: Diagnosing a Speculative Decode Collapse at Long Context" — [chunk 66.0]

[37] "The Turning Point: From Acceptance to Investigation in Long-Context Speculative Decoding" — [chunk 66.0]

[38] "The Turning Point: Diagnosing a 140× Decode Slowdown in Speculative Decoding" — [chunk 66.0]

[39] "The Turning Point: Tracing a Performance Anomaly Through Source Code" — [chunk 66.0]

[40] "Reading the Code: A Pivotal Debugging Step in the DDTree Speculative Decoding Investigation" — [chunk 66.0]

[41] "The Decisive Test: Debugging a Speculative Decoding Collapse at Long Context" — [chunk 66.0]

[42] "The Decisive Probe: How a Simple Test Refuted a Performance Bug Hypothesis" — [chunk 66.0]

[43] "The Decisive Experiment: How a Predictable-Text Probe Reframed a Speculative Decoding Bottleneck" — [chunk 66.0]

[44] "The 140× Performance Gap: Diagnosing a Long-Context Decode Bottleneck in Speculative Decoding" — [chunk 66.0]

[45] "The GPU Utilization Probe That Reframed a Performance Mystery" — [chunk 66.0]

[46] "The 130× Slowdown: Diagnosing Latency-Bound Decode in Speculative Decoding on Blackwell GPUs" — [chunk 66.0]

[47] "The Screenshot That Sealed the Diagnosis: How Visual GPU Profiling Confirmed a 130× Attention Bottleneck" — [chunk 66.0]

[48] "The GPU That Wasn't There: Diagnosing a 3% Tensor Core Utilization Mystery in Speculative Decoding" — [chunk 66.0]

[49] "The Moment of Certainty: Diagnosing a 130× Performance Gap in Speculative Decoding" — [chunk 66.0]

[50] "The Documentation That Closes a Chapter: Recording the Root Cause of Long-Context Decode Slowdown" — [chunk 66.0]