fix(vl): reduce multimodal feature memory use#4603
Merged
lvhan028 merged 9 commits intoMay 26, 2026
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.
lvhan028
reviewed
May 24, 2026
lvhan028
reviewed
May 24, 2026
lvhan028
reviewed
May 24, 2026
lvhan028
reviewed
May 24, 2026
lvhan028
reviewed
May 24, 2026
lvhan028
reviewed
May 24, 2026
Comment on lines
+37
to
+39
| if backend == 'pytorch': | ||
| model_config = getattr(self.engine, 'model_config', None) | ||
| mm_feature_dtype = getattr(model_config, 'dtype', None) |
Collaborator
There was a problem hiding this comment.
Could we get dtype from the original Transformers config in the class ImageEncoder to benefit both engines?
lvhan028
reviewed
May 24, 2026
lvhan028
approved these changes
May 25, 2026
grimoire
reviewed
May 25, 2026
| """Cast floating processor-output tensors to the target model dtype.""" | ||
| if not isinstance(target_dtype, torch.dtype): | ||
| return output | ||
| if not torch.empty((), dtype=target_dtype).is_floating_point(): |
Collaborator
There was a problem hiding this comment.
dtype has field is_float_point
grimoire
approved these changes
May 26, 2026
lvhan028
pushed a commit
to lvhan028/lmdeploy
that referenced
this pull request
May 27, 2026
* fix(vl): reduce multimodal feature memory use * debug: log vl preprocess duration * fix: address multimodal preprocess review comments * test: remove multimodal preprocess regression test * fix comments * fix: resolve vl mm feature dtype from hf config * chore: remove redundant multimodal cleanup * chore: defer vl preprocess timing logs * chore: simplify vl dtype checks
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
ImageEncoder, including nested text/LLM configs used by recent VLM families.VisionModel._postprocess_mm_output()before expansion to reduce feature memory overhead for bf16/fp16 VLM configs.Validation
Notes
Assistance
Assisted with Codex + GPT-5.5 xHigh