[misc] fix: Cap server requests by token budget - #5594
Conversation
Signed-off-by: Yu Yao <yaoyu.094@gmail.com>
|
/ok to test deb4cc2 |
|
Light review of the build_inference_config change. The change adds a server auto-sizing path: when both max_batch_size and num_prompts are None but an explicit --max_tokens is given, max_requests is now derived from the token budget (floored to a multiple of tp) instead of being left None for the KV-cache engine to size. Logic is correct and the docstring was updated to match. Findings:
Suggested test cases (no perf configs touched; unit-level):
|
|
|
||
| assert config.kwargs["max_requests"] is not None | ||
| assert config.kwargs["max_requests"] <= 128 | ||
| assert config.kwargs["max_requests"] % 2 == 0 |
There was a problem hiding this comment.
The new server auto-size path adds a raise ValueError(... must be at least --tp ...) when max_tokens // tp * tp == 0 (both max_batch_size and num_prompts None, max_tokens < tp). That branch (text_generation.py:350-351) is not covered by any test. Consider adding a case, e.g. max_batch_size=None, num_prompts=None, tp=2, max_tokens=1, asserting the ValueError is raised.
What changed
Cap OpenAI-server request capacity at an explicit active-token budget while preserving tensor-parallel divisibility. When neither
--max_batch_sizenor a prompt count supplies a request limit, Bridge now derives a request ceiling only if the user explicitly set--max_tokens; otherwise the existing KV-memory auto-sizing path remains unchanged.Supported trigger and user impact
The maintained OpenAI-server example supports
Qwen/Qwen2.5-1.5Band exposes--max_tokens. With--max_tokens 128and the documented unset--max_batch_size, Bridge passedmax_requests=Noneinto pinned MCore. MCore independently auto-sized 2,924 requests from the default 20 GiB KV buffer, then aborted context construction because 128 active tokens cannot support 2,924 active requests. The HTTP server therefore failed before binding its port.This is the server-side omitted sibling of the prompt-derived capacity invariant fixed in #5577.
Root cause and minimal fix
build_inference_config()reconciled explicit and prompt-derived request counts with the effective token budget, but skipped the cap when both request inputs were unset. The shared builder is the owning Bridge-to-MCore boundary. It now selects the largest TP-divisible request ceiling within an explicitly supplied token budget. No-limit server startup still leavesmax_requests=Nonefor KV-based sizing.Regression evidence
Focused contract test:
max_requestsremainedNoneunder an explicit 128-token server budget.Adjacent validation:
A CPU-only dependency preload was used locally to isolate the real shared helper from unrelated optional CUDA import initialization; no MCore behavior was mocked in the request/token contract itself.
Scope
--max_tokensis unset.