fix(vl): reduce multimodal feature memory use#4603
Open
CUHKSZzxy wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces memory pressure in the VL (multimodal) serving path by aligning multimodal feature tensor dtypes with the resolved PyTorch model dtype, and by dropping large multimodal references earlier after handoff through the scheduler/RPC layers.
Changes:
- Cast floating multimodal processor outputs (e.g.,
pixel_values) to the resolved model dtype during VL preprocessing. - Drop large
multimodal/RPC payload references earlier in async serving and MP-engine RPC to lower peak memory. - Expose MP-engine
model_configto enable VL dtype selection, and add timing logs + focused tests for dtype handling.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_lmdeploy/test_vl/test_mm_feature_dtype.py | Adds tests for casting only floating MM tensors + MP engine model_config exposure. |
| lmdeploy/vl/model/base.py | Introduces MM feature dtype normalization/casting during preprocessing. |
| lmdeploy/vl/engine.py | Adds mm_feature_dtype plumbing into ImageEncoder and logs preprocess duration. |
| lmdeploy/serve/processors/multimodal.py | Threads request_id into VL preprocessing calls (but has a positional-arg bug). |
| lmdeploy/serve/core/vl_async_engine.py | Picks resolved model dtype from engine model_config and passes to ImageEncoder. |
| lmdeploy/serve/core/async_engine.py | Drops multimodal from kwargs after generator creation; passes request_id into prompt processing. |
| lmdeploy/pytorch/engine/mp_engine/zmq_rpc.py | Clears large RPC payload references (e.g., multimodal, pickled blobs) after handoff. |
| lmdeploy/pytorch/engine/mp_engine/base.py | Exposes model_config and drops multimodal from streaming kwargs. |
| lmdeploy/pytorch/engine/mp_engine/base_worker.py | Adds worker RPC method to return resolved model_config. |
| lmdeploy/pytorch/engine/engine_instance.py | Clears local references to msg/multimodal after enqueueing request. |
Comments suppressed due to low confidence (1)
lmdeploy/serve/processors/multimodal.py:406
- Same positional-argument issue as above:
vl_encoder.preprocess(messages, mm_processor_kwargs, ...)bindsmm_processor_kwargstoinput_prompt. This will fail for models that use the new preprocess API. Use keyword arguments (mm_processor_kwargs=...) or explicitly passinput_prompt=Noneand keepmm_processor_kwargsas the third arg.
else:
results = await self.vl_encoder.preprocess(messages, mm_processor_kwargs, request_id=request_id)
results = await self.vl_encoder.wrap_for_pytorch(messages=results,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Validation
Assistance
Assisted with Codex + GPT-5.5 xHigh