[MM] Add flag to force Kimi image preprocessing onto CPU (#39148)
Co-authored-by: Byron Hsu <byron+per@periodiclabs.ai>
This commit is contained in:
@@ -1344,6 +1344,8 @@ class Envs:
|
|||||||
# set False to fall back to the per-image loop.
|
# set False to fall back to the per-image loop.
|
||||||
SGLANG_VIT_ENABLE_VECTORIZED_POS_EMBED = EnvBool(True)
|
SGLANG_VIT_ENABLE_VECTORIZED_POS_EMBED = EnvBool(True)
|
||||||
SGLANG_MM_SKIP_COMPUTE_HASH = EnvBool(False)
|
SGLANG_MM_SKIP_COMPUTE_HASH = EnvBool(False)
|
||||||
|
# Currently supported by the Kimi-K2.5 image processor only.
|
||||||
|
SGLANG_FORCE_CPU_IMAGE_PREPROCESSING = EnvBool(False)
|
||||||
# For pre-tokenized (list[int]) multimodal prompts,
|
# For pre-tokenized (list[int]) multimodal prompts,
|
||||||
# preserve the user's original tokens to avoid retokenization drift.
|
# preserve the user's original tokens to avoid retokenization drift.
|
||||||
SGLANG_MM_AVOID_RETOKENIZE = EnvBool(True)
|
SGLANG_MM_AVOID_RETOKENIZE = EnvBool(True)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import torch.nn.functional as F
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from sglang.kernels.ops.mm.process import normalize_and_patchify
|
from sglang.kernels.ops.mm.process import normalize_and_patchify
|
||||||
|
from sglang.srt.environ import envs
|
||||||
from sglang.srt.managers.schedule_batch import (
|
from sglang.srt.managers.schedule_batch import (
|
||||||
MultimodalProcessorOutput,
|
MultimodalProcessorOutput,
|
||||||
)
|
)
|
||||||
@@ -25,6 +26,8 @@ from sglang.srt.multimodal.transport.cuda_ipc import (
|
|||||||
)
|
)
|
||||||
from sglang.srt.runtime_context import get_mm
|
from sglang.srt.runtime_context import get_mm
|
||||||
|
|
||||||
|
_FORCE_CPU_IMAGE_PREPROCESSING = envs.SGLANG_FORCE_CPU_IMAGE_PREPROCESSING.get()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# GPU image preprocessing utilities (resize, pad, normalize, patchify on CUDA)
|
# GPU image preprocessing utilities (resize, pad, normalize, patchify on CUDA)
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -389,7 +392,7 @@ class KimiGPUProcessorWrapper:
|
|||||||
images = images or kwargs.pop("images", None)
|
images = images or kwargs.pop("images", None)
|
||||||
original_input_ids = kwargs.pop("sglang_original_input_ids", None)
|
original_input_ids = kwargs.pop("sglang_original_input_ids", None)
|
||||||
|
|
||||||
if images and torch.cuda.is_available():
|
if images and not _FORCE_CPU_IMAGE_PREPROCESSING and torch.cuda.is_available():
|
||||||
return self._gpu_call(text, images, original_input_ids)
|
return self._gpu_call(text, images, original_input_ids)
|
||||||
return self._cpu_call(text, images, original_input_ids, **kwargs)
|
return self._cpu_call(text, images, original_input_ids, **kwargs)
|
||||||
|
|
||||||
@@ -510,7 +513,7 @@ class KimiGPUProcessorWrapper:
|
|||||||
# Compatible with KimiVLForConditionalGeneration
|
# Compatible with KimiVLForConditionalGeneration
|
||||||
class KimiK2_5VLImageProcessor(KimiGridMMDataMixin, SGLangBaseProcessor):
|
class KimiK2_5VLImageProcessor(KimiGridMMDataMixin, SGLangBaseProcessor):
|
||||||
models = [KimiK25ForConditionalGeneration]
|
models = [KimiK25ForConditionalGeneration]
|
||||||
gpu_image_decode = True # nvJPEG for JPEG, PIL fallback for others
|
gpu_image_decode = not _FORCE_CPU_IMAGE_PREPROCESSING
|
||||||
prefer_tokenized_input = True
|
prefer_tokenized_input = True
|
||||||
precompute_hash_before_cpu_transfer = True
|
precompute_hash_before_cpu_transfer = True
|
||||||
# The GPU wrapper expands placeholders from the request's own token IDs.
|
# The GPU wrapper expands placeholders from the request's own token IDs.
|
||||||
|
|||||||
Reference in New Issue
Block a user