fix(scheduler): clamp admission to the actual KV pool so oversized prompts fail loudly - #118
Open
ascorb12 wants to merge 1 commit into
Open
Conversation
A prompt that fits the model's advertised max_seq_len but exceeds the allocated KV pool passes admission and is queued forever with no error, no log line, and an idle engine (issue FlashML-org#111). Clamp the admission bound to num_pages * page_size and reuse the existing too-long rejection path so such prompts fail loudly with context_length_exceeded instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Addresses the silent-hang half of #111 (the
--moe-cache-autobudget-solve policy is deliberately left alone).Problem
Scheduler._process_one_msgvalidates an incoming prompt againstself.engine.max_seq_len— the model's advertised context — but never againstthe KV pool that was actually allocated (
engine.num_pages * page_size). Anyprompt that fits the model's max but exceeds the pool passes admission, is
handed to
prefill_manager.add_one_req, and can never be scheduled: no prefillbatch, no log line, no HTTP error. The client waits until its own timeout while
the engine sits idle. #111 demonstrates the boundary tracking
num_pagesexactly (8,011 tokens passes, 8,760 hangs, pool 8,209) on a 96 GB RTX PRO 6000,
and with
--moe-cache-autothe pool routinely lands near the 8,192kv_reserve_tokensfloor — so any agent-style workload (system prompt + toolsroutinely >8k tokens) hits this at defaults.
Fix
Clamp the existing admission bound to the pool and reuse the error path that is
already there (
ErrorReplyMsg,code="context_length_exceeded", the"prompt is too long: N tokens > M" phrasing clients already match on):
Three lines plus the two message sites switching
{max_seq_len}→{effective_max}. No new config, no behavior change for prompts that fit.Caveats considered
cache_type=radix, a prompt slightly over thepool could in principle still fit if it shares cached prefix pages. This clamp
rejects it anyway. That is deliberate: admission cannot see prefix matches
(matching happens at prefill), the reject is conservative and loud, and the
alternative is the silent hang this PR removes. If prefix-aware admission is
wanted later, it belongs in the prefill manager.
prompt is the full-attention pool, which is what
engine.num_pagesdescribes;window pools are per-layer bounded and smaller per token. The clamp uses the
full pool, matching the observed hang boundary in Requests longer than the KV pool are queued forever with no error — and --moe-cache-auto leaves only ~8k tokens of KV on a 96GB GPU #111.
--moe-cache-autobudget solve starving KV) isnot addressed here — that is a policy question. This PR only makes the
resulting limit visible instead of a hang.
Tested
scheduler.pyfrom the v0.1.2tag (byte-identical to
mainin this region), shadowing the compiled module.openai/gpt-oss-20b,--num-tokens 8192, no--max-seq-len-override— so the server advertisedcontext_length=131072while the pool held 8,192. This is exactly the configuration Requests longer than the KV pool are queued forever with no error — and --moe-cache-auto leaves only ~8k tokens of KV on a 96GB GPU #111 hangs on.
{"message":"prompt is too long: 9568 tokens > 8192 maximum (prompt + generation); shorten the prompt or increase the KV cache budget", "code":"context_length_exceeded"}. The8192in that message can onlycome from the new clamp — stock code compares against the advertised
131,072 and admits the prompt into the queue it can never leave.
(cold/warm), identical behavior to the unpatched module for anything
that fits.
Per the AI policy in CONTRIBUTING: this change was produced with AI assistance;
the submitter has reviewed and tested everything in it and takes responsibility
for it.
🤖 Generated with Claude Code