-
Notifications
You must be signed in to change notification settings - Fork 624
[Bugfix] Resolve the interface compatibility issue of get_input_embeddings in MM #4638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bugfix] Resolve the interface compatibility issue of get_input_embeddings in MM #4638
Conversation
…dings in MM Signed-off-by: Levi-JQ <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request resolves an interface compatibility issue in multimodal models by checking if the get_input_embeddings function supports the is_multimodal parameter before calling it. This is a good approach for ensuring backward compatibility. However, the implementation uses inspect.signature within the _prepare_inputs method, which is a performance-critical path. My review includes a suggestion to cache the result of this check to avoid repeated overhead, improving the overall efficiency.
| has_is_multimodal = 'is_multimodal' in inspect.signature(self.model.get_input_embeddings).parameters | ||
| if has_is_multimodal: | ||
| inputs_embeds = self.model.get_input_embeddings( | ||
| input_ids, | ||
| multimodal_embeddings=mm_embeds, | ||
| is_multimodal=is_mm_embed, | ||
| ) | ||
| else: | ||
| if mm_embeds: | ||
| inputs_embeds = self.model.get_input_embeddings( | ||
| input_ids, mm_embeds) | ||
| else: | ||
| inputs_embeds = self.model.get_input_embeddings(input_ids) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using inspect.signature inside _prepare_inputs can introduce a performance overhead, as this method is on a hot path and reflection is generally slow. This check should be performed only once and the result should be cached.
A better approach would be to perform this check once and store the result in an instance attribute. You can add a new attribute, for example _has_is_multimodal_in_get_input_embeddings, and compute it once within _prepare_inputs using lazy initialization.
| has_is_multimodal = 'is_multimodal' in inspect.signature(self.model.get_input_embeddings).parameters | |
| if has_is_multimodal: | |
| inputs_embeds = self.model.get_input_embeddings( | |
| input_ids, | |
| multimodal_embeddings=mm_embeds, | |
| is_multimodal=is_mm_embed, | |
| ) | |
| else: | |
| if mm_embeds: | |
| inputs_embeds = self.model.get_input_embeddings( | |
| input_ids, mm_embeds) | |
| else: | |
| inputs_embeds = self.model.get_input_embeddings(input_ids) | |
| if not hasattr(self, "_has_is_multimodal_in_get_input_embeddings"): | |
| self._has_is_multimodal_in_get_input_embeddings = ( | |
| 'is_multimodal' in inspect.signature( | |
| self.model.get_input_embeddings).parameters) | |
| if self._has_is_multimodal_in_get_input_embeddings: | |
| inputs_embeds = self.model.get_input_embeddings( | |
| input_ids, | |
| multimodal_embeddings=mm_embeds, | |
| is_multimodal=is_mm_embed, | |
| ) | |
| else: | |
| if mm_embeds: | |
| inputs_embeds = self.model.get_input_embeddings( | |
| input_ids, mm_embeds) | |
| else: | |
| inputs_embeds = self.model.get_input_embeddings(input_ids) |
| multimodal_embeddings=mm_embeds, | ||
| is_multimodal=is_mm_embed, | ||
| ) | ||
| has_is_multimodal = 'is_multimodal' in inspect.signature(self.model.get_input_embeddings).parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have checked that is_multimodal is not included in vLLM v0.11.0, thus only the custom Qwen2_5_vl in vllm-ascend have this arg. Maybe we can just check the model_type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
|
👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:
If CI fails, you can run linting and testing checks locally according Contributing and Testing. |
Signed-off-by: Levi-JQ <[email protected]>
|
I think this pr is okay to merge as the broken test case tests/e2e/singlecard/test_vlm.py::test_multimodal_audio has already passed. https://github.com/vllm-project/vllm-ascend/actions/runs/19857925293/job/56900838462?pr=4638 |
What this PR does / why we need it?
Resolve the interface compatibility issue of get_input_embeddings in MM, because the get_input_embeddings func of other model does not have the is_multimodal parameter
Does this PR introduce any user-facing change?
How was this patch tested?