-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[Refactor] simplify multimodal data processing #8107
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
Merged
zhyncs
merged 31 commits into
sgl-project:main
from
JustinTong0323:feat-simlify-multimodal-dataitem-processing
Jul 21, 2025
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
554d3c2
refactor: simplify multimodal data processing
JustinTong0323 75dd9fd
revert modification for mllama4
JustinTong0323 ce0dceb
fix lint
JustinTong0323 077163b
Merge branch 'main' into feat-simlify-multimodal-dataitem-processing
JustinTong0323 a5b1108
refactor: update type hints for model_specific_data and items in sche…
JustinTong0323 4cdae8f
Refactors how model-specific multimodal data is handled.
JustinTong0323 88a27e3
Merge branch 'main' into feat-simlify-multimodal-dataitem-processing
JustinTong0323 b764985
fix: restore change fot models/mllama.py
JustinTong0323 607ec41
fix: unify multimodal token handling across processors
JustinTong0323 241a664
misc: enhance type hints in base_processor.py
JustinTong0323 4b31269
fix: use get method for model_specific_data access in multiple models
JustinTong0323 7bfb3f5
Removes `max_req_input_len` from multimodal processor calls.
JustinTong0323 2eacc3e
Merge branch 'main' into feat-simlify-multimodal-dataitem-processing
JustinTong0323 2bdbd62
fix after merge main:
JustinTong0323 4ed0be3
Refactors audio processing in Qwen2
JustinTong0323 3e405d7
Refactors multimodal token handling
JustinTong0323 13131ca
Rename `precomputed_features` to `precomputed_embeddings`
JustinTong0323 62c663d
Remove `image_sizes` as common MultimodalDataItem attributes
JustinTong0323 287baac
fix: deepseek vl related issue
JustinTong0323 d1d643b
Refactors MultimodalDataItem attr access and usage
JustinTong0323 840ddfe
misc: remove redundant attr in MllamaImageProcessor
JustinTong0323 3f63a14
fix: update attribute access in MllamaForConditionalGeneration
JustinTong0323 edc67d6
fix lint
JustinTong0323 d2ab9d4
fix llama atttr
JustinTong0323 a5c64ed
Temporarily disable MllamaServer tests due to instability
JustinTong0323 d8776da
fix: qwen vl video attr error
JustinTong0323 8360efd
fix lint
JustinTong0323 609c6f9
Merge branch 'main' into feat-simlify-multimodal-dataitem-processing
JustinTong0323 a8385dc
Streamlines access to `MultimodalDataItem` attributes by using `__get…
JustinTong0323 9691f9c
Merge branch 'main' into feat-simlify-multimodal-dataitem-processing
JustinTong0323 d106df8
Merge branch 'main' into feat-simlify-multimodal-dataitem-processing
JustinTong0323 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,33 @@ | ||
| from typing import List, Union | ||
|
|
||
| from sglang.srt.managers.schedule_batch import Modality, MultimodalDataItem | ||
| from sglang.srt.models.mllama import MllamaForConditionalGeneration | ||
| from sglang.srt.multimodal.processors.base_processor import BaseMultimodalProcessor | ||
| from sglang.srt.utils import load_image | ||
| from sglang.srt.multimodal.processors.base_processor import ( | ||
| BaseMultimodalProcessor, | ||
| MultimodalSpecialTokens, | ||
| ) | ||
|
|
||
|
|
||
| class MllamaImageProcessor(BaseMultimodalProcessor): | ||
| models = [MllamaForConditionalGeneration] | ||
|
|
||
| def __init__(self, hf_config, server_args, _processor): | ||
| super().__init__(hf_config, server_args, _processor) | ||
| self.IM_TOKEN = self._processor.image_token | ||
| self.IM_TOKEN_ID = self._processor.image_token_id | ||
|
|
||
| async def process_mm_data_async( | ||
| self, image_data: List[Union[str, bytes]], input_text, *args, **kwargs | ||
| ): | ||
| if isinstance(input_text, list): | ||
| assert len(input_text) and isinstance(input_text[0], int) | ||
| input_text = self._processor.tokenizer.decode(input_text) | ||
| base_out = self.load_mm_data( | ||
| prompt=input_text, | ||
| image_data=image_data, | ||
| multimodal_tokens=MultimodalSpecialTokens(image_token=self.IM_TOKEN), | ||
| ) | ||
|
|
||
| images = [load_image(image)[0] for image in image_data] | ||
| image_inputs = self.process_mm_data(input_text=input_text, images=images) | ||
| image_inputs["input_ids"] = image_inputs["input_ids"].tolist()[0] | ||
| image_inputs["mm_items"] = [ | ||
| MultimodalDataItem( | ||
| feature=image_inputs["pixel_values"], | ||
| aspect_ratio_id=image_inputs["aspect_ratio_ids"], | ||
| aspect_ratio_mask=image_inputs["aspect_ratio_mask"], | ||
| modality=Modality.IMAGE, | ||
| ) | ||
| ] | ||
| mm_items, input_ids, _ = self.process_and_combine_mm_data(base_out) | ||
|
JustinTong0323 marked this conversation as resolved.
Outdated
|
||
|
|
||
| return image_inputs | ||
| return { | ||
| "mm_items": mm_items, | ||
| "input_ids": input_ids.tolist(), | ||
| "im_token_id": self.IM_TOKEN_ID, | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.