[BugFix]: Fix bagel online inference bug (#1804)
Signed-off-by: princepride <wangzhipeng628@gmail.com>
This commit is contained in:
5 files changed
+115
-13
No files matched your search
@@ -202,6 +202,15 @@ class OmniBagelDataParser(MultiModalDataParser):
|
||||
|
||||
|
||||
class OmniBagelMultiModalProcessor(BaseMultiModalProcessor[OmniBagelProcessingInfo]):
|
||||
IMG2IMG_PLACEHOLDER = "<|fim_middle|>"
|
||||
|
||||
def _cached_apply_hf_processor(self, inputs, timing_ctx):
|
||||
# img2img: prompt text must be modified based on mm data presence,
|
||||
# so text and mm data cannot be tokenized separately — bypass cache.
|
||||
if inputs.mm_data_items.get_all_counts().get("img2img", 0) > 0:
|
||||
return self._apply_hf_processor(inputs, timing_ctx)
|
||||
return super()._cached_apply_hf_processor(inputs, timing_ctx)
|
||||
|
||||
def _get_mm_fields_config(self, hf_inputs, hf_processor_mm_kwargs):
|
||||
return {
|
||||
"pixel_values": MultiModalFieldConfig.batched("image"),
|
||||
@@ -218,6 +227,9 @@ class OmniBagelMultiModalProcessor(BaseMultiModalProcessor[OmniBagelProcessingIn
|
||||
has_image = "images" in mm_data
|
||||
has_img2img = "pixel_values_img2img" in mm_data
|
||||
|
||||
if has_img2img and self.IMG2IMG_PLACEHOLDER not in prompt:
|
||||
prompt = f"{self.IMG2IMG_PLACEHOLDER}{prompt}"
|
||||
|
||||
if has_image and has_img2img:
|
||||
outputs = BatchFeature()
|
||||
|
||||
|
||||
@@ -78,7 +78,11 @@ from vllm.multimodal.inputs import (
|
||||
MultiModalFieldConfig,
|
||||
MultiModalKwargsItems,
|
||||
)
|
||||
from vllm.multimodal.parse import ImageProcessorItems, MultiModalDataItems
|
||||
from vllm.multimodal.parse import (
|
||||
ImageProcessorItems,
|
||||
MultiModalDataItems,
|
||||
MultiModalDataParser,
|
||||
)
|
||||
from vllm.multimodal.processing import (
|
||||
BaseDummyInputsBuilder,
|
||||
BaseMultiModalProcessor,
|
||||
@@ -115,6 +119,15 @@ class GlmImagePixelInputs(TensorSchema):
|
||||
image_grid_thw: Annotated[torch.Tensor, TensorShape("ni", 3)]
|
||||
|
||||
|
||||
class GlmImageDataParser(MultiModalDataParser):
|
||||
"""GLM-Image treats ``img2img`` input identically to ``image``."""
|
||||
|
||||
def _get_subparsers(self):
|
||||
parsers = super()._get_subparsers()
|
||||
parsers["img2img"] = self._parse_image_data
|
||||
return parsers
|
||||
|
||||
|
||||
class GlmImageProcessingInfo(BaseProcessingInfo):
|
||||
"""
|
||||
Processing information for GLM-Image model.
|
||||
@@ -162,14 +175,19 @@ class GlmImageProcessingInfo(BaseProcessingInfo):
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def get_data_parser(self) -> GlmImageDataParser:
|
||||
return GlmImageDataParser(
|
||||
expected_hidden_size=self._get_expected_hidden_size(),
|
||||
)
|
||||
|
||||
def get_supported_mm_limits(self) -> Mapping[str, int | None]:
|
||||
# GLM-Image is an image GENERATION model that supports:
|
||||
# - Text-to-image (t2i): no multimodal input needed
|
||||
# - Image-to-image (i2i): source images provided as input
|
||||
#
|
||||
# For i2i mode, we support up to 1 image as condition.
|
||||
# The model architecture supports multiple images but typical usage is 1.
|
||||
return {"image": 1}
|
||||
# "img2img" is an alias used by the serving layer; parsed as "image".
|
||||
return {"image": 1, "img2img": 1}
|
||||
|
||||
def get_num_image_tokens(
|
||||
self,
|
||||
|
||||
Reference in new issue
Block a user