-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
[Core] Move multimodal placeholder from chat utils to model definition #20355
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
[Core] Move multimodal placeholder from chat utils to model definition #20355
Conversation
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
@@ -661,7 +661,7 @@ def architecture(self) -> str: | |||
return self._architecture | |||
|
|||
@property | |||
def model_info(self) -> dict[str, Any]: |
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.
The type annotation is incorrect, so I removed it
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.
Summary of Changes
Hello @DarkLight1337, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a significant refactoring effort aimed at improving the modularity and maintainability of multimodal and transcription model logic. The core change involves decentralizing model-specific placeholder string generation and transcription utility methods from shared utility files into their respective model class definitions. This approach makes it easier to add new models and ensures that model-specific behaviors are co-located with their implementations.
Highlights
- Refactoring Multimodal Placeholder Logic: The centralized
_placeholder_str
function invllm/entrypoints/chat_utils.py
, which contained the logic for determining multimodal placeholder strings (e.g.,<image>
,<audio>
) for all models, has been removed. - Model-Specific Placeholder Definition: Each model class that implements the
SupportsMultiModal
interface now includes a new@classmethod
calledget_placeholder_str
. This method is responsible for returning the correct placeholder string specific to that model and its supported modalities, encapsulating the logic directly within the model definition. - Updated MultiModal Interface: The
SupportsMultiModal
protocol invllm/model_executor/models/interfaces.py
has been updated to include theget_placeholder_str
method, enforcing that all conforming multimodal models provide this functionality. - Refactoring Transcription Logic: Following a similar pattern, the
validate_language
andget_decoder_prompt
methods for transcription models (specifically the Whisper model) have been moved fromvllm/entrypoints/openai/speech_to_text.py
into theWhisperForConditionalGeneration
model class itself, improving modularity and consistency. - New Model Class Helper: A new helper function,
get_model_cls
, has been introduced invllm/model_executor/model_loader/utils.py
to simplify the process of retrieving the model class from aModelConfig
.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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 is a significant and valuable refactoring that moves the responsibility of providing multimodal placeholder strings from a centralized utility in chat_utils.py
to the individual model definitions. This greatly improves modularity and makes the codebase cleaner and easier to maintain, especially for adding new multimodal models.
My review focuses on ensuring the correctness of this refactoring. I've found one likely bug where a placeholder string seems to have been copied incorrectly, and I've also pointed out a couple of areas where the changes, while simplifying the code, might reduce type safety or robustness. Overall, the changes are a positive step forward for the project's architecture.
@classmethod | ||
def get_placeholder_str(cls, modality: str, i: int) -> Optional[str]: | ||
if modality.startswith("image"): | ||
return "<|begin_of_image|><|endoftext|><|end_of_image|>" |
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.
There seems to be a copy-paste error in the placeholder string for glm4v
. The previous implementation used <|begin_of_image|><|image|><|end_of_image|>
, but the new implementation uses <|begin_of_image|><|endoftext|><|end_of_image|>
. The new string appears to be the placeholder for chatglm
, not glm4v
. This is likely a bug that will cause incorrect prompt construction for glm4v
models.
return "<|begin_of_image|><|endoftext|><|end_of_image|>" | |
return "<|begin_of_image|><|image|><|end_of_image|>" |
@@ -661,7 +661,7 @@ def architecture(self) -> str: | |||
return self._architecture | |||
|
|||
@property | |||
def model_info(self) -> dict[str, Any]: | |||
def model_info(self): |
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.
The type hint for the model_info
property was removed. For better code clarity and type safety, it's recommended to restore it. The property returns self._model_info
, which is a dictionary, so -> dict[str, Any]
would be the correct type hint.
def model_info(self): | |
def model_info(self) -> dict[str, Any]: |
if modality.startswith("image"): | ||
return "<image>" |
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.
This change hardcodes the image placeholder to <image>
. The previous implementation dynamically resolved it from the tokenizer using hf_config.image_token_index
. While this simplification removes the dependency on the tokenizer instance, it introduces a risk of incorrect behavior if a LLaVA variant uses a different special token for images. This is a behavior change that reduces robustness.
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
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.
Overall LGTM! Thanks for cleaning up this!
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add 🚀 |
@@ -88,12 +92,14 @@ async def _preprocess_speech_to_text( | |||
request: SpeechToTextRequest, | |||
audio_data: bytes, | |||
) -> tuple[list[PromptType], float]: | |||
model_cls = self.model_cls |
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.
Is this change needed?
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.
It avoids the need to type: ignore
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
Signed-off-by: Kyle Huang <kylhuang@nvidia.com>
vllm-project#20355) Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
vllm-project#20355) Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
vllm-project#20355) Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
vllm-project#20355) Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk> Signed-off-by: avigny <47987522+avigny@users.noreply.github.com>
vllm-project#20355) Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
vllm-project#20355) Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk> Signed-off-by: Jinzhen Lin <linjinzhen@hotmail.com>
vllm-project#20355) Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
Essential Elements of an Effective PR Description Checklist
supported_models.md
andexamples
for a new model.Purpose
This PR introduces
SupportsMultiModal.get_placeholder_str
so we don't have to add the placeholder token inchat_utils.py
separately (which is very easy to forget) for new models to work in online serving.Follow-up to #20105
Test Plan
Test Result
(Optional) Documentation Update
Update the New Model guide with instructions to implement
SupportsMultiModal.get_placeholder_str
.