fix: gate multimodal preprocessing concurrency#4687
Open
CUHKSZzxy wants to merge 10 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces an optional concurrency gate to limit how many multimodal requests can be in the media preprocessing / API→engine handoff stage concurrently, aiming to reduce CPU RSS spikes from large pixel_values under high request concurrency.
Changes:
- Add
VisionConfig.max_mm_preprocess_concurrencyand a serve CLI flag--max-mm-preprocess-concurrency. - Introduce
MultimodalPreprocessGate/lease and acquire it only when multimodal input is detected; release timing differs for PyTorch MP vs non-PyTorch. - Propagate the gate through OpenAI (chat/generate/responses) and Anthropic messages paths, plus add focused tests (gate behavior + MP callback propagation).
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_lmdeploy/serve/test_mm_preprocess_gate.py | Adds unit tests for gate blocking/release and MP callback locality. |
| tests/test_lmdeploy/serve/anthropic/test_endpoints.py | Verifies Anthropic endpoint passes mm_preprocess_gate (including direct endpoint call). |
| tests/pytorch/engine/test_zmq_rpc.py | Updates MP streaming RPC signature to accept a local “request accepted” callback. |
| lmdeploy/serve/utils/mm_preprocess.py | New gate + lease implementation (asyncio semaphore-based). |
| lmdeploy/serve/processors/multimodal.py | Reuses a centralized multimodal-input detector and makes it more robust to input types. |
| lmdeploy/serve/openai/responses/serving.py | Passes the gate into the Responses API generation call. |
| lmdeploy/serve/openai/api_server.py | Creates/configures the gate from VisionConfig and forwards it into chat/generate. |
| lmdeploy/serve/core/async_engine.py | Acquires/releases the gate around prompt preprocessing + adds PyTorch MP handoff callback release. |
| lmdeploy/serve/anthropic/endpoints/messages.py | Forwards the gate into Anthropic message generation. |
| lmdeploy/pytorch/engine/mp_engine/zmq_rpc.py | Triggers the local “request accepted” callback once the stream is established. |
| lmdeploy/pytorch/engine/mp_engine/zmq_engine.py | Threads the local callback through to the RPC client streaming call. |
| lmdeploy/pytorch/engine/mp_engine/ray_engine.py | Triggers the local “request accepted” callback once the stream is established. |
| lmdeploy/pytorch/engine/mp_engine/base.py | Ensures the callback stays local (not pickled/sent to engine process). |
| lmdeploy/messages.py | Extends VisionConfig with max_mm_preprocess_concurrency. |
| lmdeploy/cli/utils.py | Adds the CLI argument helper for --max-mm-preprocess-concurrency. |
| lmdeploy/cli/serve.py | Wires the new CLI flag into VisionConfig creation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ntrol # Conflicts: # lmdeploy/serve/core/async_engine.py
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.
Summary
Add an optional multimodal preprocessing concurrency gate for serving requests.
This limits how many multimodal requests can be in the media preprocessing / API-to-engine handoff stage at the same time. It is intended to reduce CPU RSS spikes from very large
pixel_valuestensors under high request concurrency, wheremax_batch_sizedoes not help because the pressure happens before engine batching.Main changes:
--max-mm-preprocess-concurrencytoVisionConfig/ serve CLIMultimodalPreprocessGateand lease helper for request-scoped slot ownershipBenchmark
Single-run image payload pressure test, PyTorch backend, TP=2, MP engine, client concurrency=128, total requests=128,
max_tokens=1.Takeaway:
gate=1gave the strongest CPU memory reduction with only noise-level throughput change for this workload.gate=2is a more balanced setting if the machine can tolerate higher CPU RSS.Notes:
Tests
Assistance
Assisted with Codex + GPT-5.5 xHigh Fast, reviewed manually