[Model] Fused mm preprocess normalisation on the Device (#50411)

Signed-off-by: wang.yuqi <yuqi.wang@daocloud.io>
Signed-off-by: wang.yuqi <noooop@126.com>
Co-authored-by: Cyrus Leung <cyrus.tl.leung@gmail.com>
This commit is contained in:
wang.yuqi
2026-08-06 03:11:14 -07:00
committed by GitHub
co-authored by Cyrus Leung
parent 9c22668436
commit 2fa490470d
13 changed files with 359 additions and 11 deletions
+9
View File
@@ -144,6 +144,11 @@ class MultiModalConfig:
For example, for Phi-3-Vision:
`{"num_crops": 4}`."""
mm_device_do_normalize: bool | None = True
"""
Move the do_normalize computation in the mm preprocessing to before the ViT,
and let the device do it, so that CPU computation can be saved.
"""
mm_processor_cache_gb: float = Field(default=4, ge=0)
"""The size (in GiB) of the multi-modal processor cache, which is used to
avoid re-processing past multi-modal inputs.
@@ -474,6 +479,7 @@ class MultiModalConfig:
self.mm_encoder_tp_mode,
self.mm_encoder_attn_dtype,
self.mm_encoder_fp8_scale_path,
self.mm_device_do_normalize,
]
hash_str = safe_hash(str(factors).encode(), usedforsecurity=False).hexdigest()
return hash_str
@@ -503,6 +509,9 @@ class MultiModalConfig:
according to the extra arguments passed during inference.
"""
kwargs = self.mm_processor_kwargs or {}
if self.mm_device_do_normalize:
kwargs["do_normalize"] = False
kwargs["do_rescale"] = False
return kwargs | dict(inference_kwargs)
def use_gpu_video_backend(self) -> bool: