Skip to content

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
mainfrom
feat/vlm-dynamic-batching
Closed

feat: dynamic micro-batching for VLM generate paths (off by default) + GPU image inference_models fix#2435
hansent wants to merge 4 commits into
mainfrom
feat/vlm-dynamic-batching

Conversation

@hansent

@hansent hansent commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

What

  1. Per-model dynamic micro-batching for the HF VLM wrappers (qwen3_5/qwen3vl/qwen25vl/glm_ocr/paligemma/smolvlm): concurrent same-model requests collate (left-padded) into one batched generate(), split per request, trimmed to each request's max_new_tokens; serial fallback isolates poisoned requests. Off by default (INFERENCE_MODELS_DYNAMIC_BATCHING_ENABLED).
  2. Dockerfile.onnx.gpu fix (important standalone): the builder installed inference_models dependencies from the repo lock but the package content from PyPI — local changes to inference_models/ silently never shipped in GPU images. Now copies repo source over dist-packages.
  3. glm-ocr fix: its bare tokenizer emits token_type_ids which broke batch collation (silent serial fallback); GLM-4V's forward never reads it — dropped in preprocessing (output-neutral).
  4. HTTP_API_THREADPOOL_WORKERS env to raise the anyio sync-handler cap (hidden default 40).

Staging results — honest

  • smolvlm2: 3.3× (3.35 RPS @ c16).
  • glm-ocr: batches form, but unbounded 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).

hansent added 3 commits June 9, 2026 14:10
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.
@hansent hansent closed this Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant