[Model] Extend device-side mm normalization to Kimi K2.5 / K3 (#59278)
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
This commit is contained in:
@@ -26,6 +26,8 @@ class KimiK25Processor(ProcessorMixin):
|
||||
text: str | list[str] | None = None,
|
||||
vision_chunks: list[VisionChunk] | None = None,
|
||||
return_tensors: str | TensorType | None = None,
|
||||
do_rescale: bool = True,
|
||||
do_normalize: bool = True,
|
||||
**kwargs,
|
||||
) -> BatchFeature:
|
||||
"""Args:
|
||||
@@ -49,6 +51,8 @@ class KimiK25Processor(ProcessorMixin):
|
||||
mm_inputs = self.image_processor.preprocess(
|
||||
vision_chunks,
|
||||
return_tensors=return_tensors,
|
||||
do_rescale=do_rescale,
|
||||
do_normalize=do_normalize,
|
||||
)
|
||||
else:
|
||||
mm_inputs = {}
|
||||
|
||||
@@ -18,6 +18,8 @@ from vllm.multimodal.image import open_image
|
||||
from vllm.utils.import_utils import is_numba_available
|
||||
from vllm.utils.jit_monitor import numba_workqueue_threading_layer
|
||||
|
||||
_IDENTITY_LUT = np.tile(np.arange(256, dtype=np.uint8)[:, None], (1, 3))
|
||||
|
||||
if is_numba_available():
|
||||
from numba import njit, prange
|
||||
|
||||
@@ -239,7 +241,12 @@ class KimiK25FusedVisionProcessor(BaseImageProcessor):
|
||||
self,
|
||||
medias: list[dict[str, Any]],
|
||||
return_tensors: str | TensorType | None = None,
|
||||
do_rescale: bool = True,
|
||||
do_normalize: bool = True,
|
||||
) -> BatchFeature:
|
||||
assert do_rescale == do_normalize
|
||||
device_normalize = not do_normalize
|
||||
|
||||
if not isinstance(medias, list):
|
||||
medias = [medias]
|
||||
if not medias:
|
||||
@@ -297,8 +304,9 @@ class KimiK25FusedVisionProcessor(BaseImageProcessor):
|
||||
)
|
||||
total_patches += num_patches
|
||||
|
||||
lut = _IDENTITY_LUT if device_normalize else self.normalize_lut
|
||||
pixel_values_np = np.empty(
|
||||
(total_patches, 3, patch_size, patch_size), dtype=np.float32
|
||||
(total_patches, 3, patch_size, patch_size), dtype=lut.dtype
|
||||
)
|
||||
out_offset = 0
|
||||
with numba_workqueue_threading_layer():
|
||||
@@ -319,7 +327,7 @@ class KimiK25FusedVisionProcessor(BaseImageProcessor):
|
||||
padded_height,
|
||||
padded_width,
|
||||
patch_size,
|
||||
self.normalize_lut,
|
||||
lut,
|
||||
)
|
||||
out_offset += num_patches
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@ class KimiK3Processor(ProcessorMixin):
|
||||
text: str | list[str] | None = None,
|
||||
images: object | list[object] | None = None,
|
||||
return_tensors: str | TensorType | None = None,
|
||||
do_rescale: bool = True,
|
||||
do_normalize: bool = True,
|
||||
**kwargs,
|
||||
) -> BatchFeature:
|
||||
if images is not None:
|
||||
@@ -44,6 +46,8 @@ class KimiK3Processor(ProcessorMixin):
|
||||
mm_inputs = self.image_processor.preprocess(
|
||||
medias,
|
||||
return_tensors=return_tensors,
|
||||
do_rescale=do_rescale,
|
||||
do_normalize=do_normalize,
|
||||
)
|
||||
else:
|
||||
mm_inputs = {}
|
||||
|
||||
Reference in New Issue
Block a user