feat: Automatic KV/MoE Laddering for decode speed vs context-length trade off ( upto 33% faster decode ) - #300
Open
aswinkumar1999 wants to merge 4 commits into
Open
feat: Automatic KV/MoE Laddering for decode speed vs context-length trade off ( upto 33% faster decode ) #300aswinkumar1999 wants to merge 4 commits into
aswinkumar1999 wants to merge 4 commits into
Conversation
Added arguments for enabling KV ladder and setting ladder step size.
Add KV ladder policy implementation and management
This module implements a policy for managing key-value (KV) storage growth at request boundaries by optimizing the use of MoE (Mixture of Experts) cache slots. It includes classes for capacity errors and planning growth strategies based on current and target token requirements.
Added new CLI options for KV ladder and MoE configurations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add an automatic KV/MoE cache ladder
Summary
This adds
--enable-kv-ladder, an opt-in serving mode that grows the KV cache when anincoming request could reach its current capacity. Each growth trades GPU-resident MoE cache
slots for KV pages while staying inside the engine's existing measured cache budget.
It also adds
--ladder-step-size, which defaults to 32,768 tokens. With the ladder enabled,startup KV is at least twice the configured step size and grows by that step until reaching the
model's context limit.
With the default step and this model, the resulting ladder is:
Motivation
Preallocating KV for the full model context reduces the number of MoE expert slots that can
remain resident on the GPU, even when most requests use much shorter contexts. Reserving too
little KV preserves decode throughput but prevents long sessions from reaching the model's full
context.
The ladder keeps more experts resident for common shorter requests and spends that memory on KV
only when a request actually needs the next context rung.
Implementation
could exactly fill the current capacity.
The initial version is intentionally restricted to TP=1,
--max-running-requests 1,--moe-cache-auto, and an offload-family MoE backend.Measured results
Environment:
RadixArk/Qwen3.8-Flash-Next-NVFP4Short-output results include proportionally more fixed launch and streaming overhead. The
4,096-token column is the more representative sustained-decode comparison.
Rebuild latency
approximately 0.67-0.99 seconds.
for CUDA graph capture.
Long-context request TTFT should not be interpreted as rebuild latency. For example, the final
196,608-token cold prompt reached first token in 125.8 seconds, but almost all of that time was
prompt prefill rather than the cache rebuild.
Validation
status=ok; no capacity rejection occurred.git diff --checkpassed.Known limitation
This implementation is a grow-only high-watermark ladder for single-decode use cases. A new, unrelated prompt with no
prefix-cache reuse does not yet shrink KV and restore MoE slots automatically. The server sees
stateless prompts and has no direct session-ended signal; shrinking immediately on idle would
also erase useful KV between consecutive turns of the same conversation.
A follow-up can inspect the next tokenized request's reusable-prefix hit and, when reuse is
negligible, rebuild to the smallest rung that fits that request. That should include hysteresis
to prevent rebuild thrashing.