feat: dynamic micro-batching for VLM generate paths (off by default) + GPU image inference_models fix#2435
Closed
hansent wants to merge 4 commits into
Closed
feat: dynamic micro-batching for VLM generate paths (off by default) + GPU image inference_models fix#2435hansent wants to merge 4 commits into
hansent wants to merge 4 commits into
Conversation
Per-model-instance DynamicBatcher (request queue + batcher thread + future per request) replaces direct lock contention on model.generate: concurrent requests for the same model are collated (left-padded) into one batched generate call, split per request, trimmed to each request's max_new_tokens. Grouped by generation-param signature; any batch failure falls back to serial execution per member so a poisoned request only fails itself. Off by default (INFERENCE_MODELS_DYNAMIC_BATCHING_ENABLED). Wired: qwen3_5, qwen3vl, qwen25vl, glm_ocr, paligemma, smolvlm. Also adds HTTP_API_THREADPOOL_WORKERS to raise the anyio sync-handler threadpool cap (default 40) on high-concurrency pools.
The builder installs inference_models dependencies from the repo lock, but the package content came from the PyPI release — local changes to inference_models/ (e.g. dynamic batching) silently never shipped.
GLM-4V ships a bare PreTrainedTokenizerFast whose chat template emits token_type_ids; the dynamic batcher's collate rejected the key and fell back to serial execution on every batch. GLM-4V's forward never reads it, so dropping it is output-neutral on both paths.
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.
What
generate(), split per request, trimmed to each request'smax_new_tokens; serial fallback isolates poisoned requests. Off by default (INFERENCE_MODELS_DYNAMIC_BATCHING_ENABLED).inference_modelsdependencies from the repo lock but the package content from PyPI — local changes toinference_models/silently never shipped in GPU images. Now copies repo source over dist-packages.token_type_idswhich broke batch collation (silent serial fallback); GLM-4V's forward never reads it — dropped in preprocessing (output-neutral).HTTP_API_THREADPOOL_WORKERSenv to raise the anyio sync-handler cap (hidden default 40).Staging results — honest
max_new_tokens→ slowest-member tax → p95 224–437s + timeouts. Worse than serial for tails.Status
Per team decision the flag stays off and the HF multi-adapter iteration is skipped — vLLM pools (companion PR) are the throughput path. Before any future enablement this needs per-family flags + a batched-mode token cap. The Dockerfile and glm fixes are valuable regardless and are the main reason to land this.
373 tests passed (27 new batcher tests: windows, signature grouping, trimming, poison isolation, 64-thread stress).