[Fix] Carry the backend on Kimi-K3 deferred preprocessing configs (#34766)

This commit is contained in:
Liangsheng Yin
2026-08-13 13:30:33 -07:00
committed by GitHub
parent 8ad04a9bee
commit 8554d9a5bc
6 changed files with 80 additions and 51 deletions
@@ -188,8 +188,8 @@ def test_kimi_k3_epd_preprocess_preserves_raw_per_image_items():
assert item.hash is not None
assert item.pad_value is not None
deferred = item.model_specific_data[DEFERRED_PREPROCESSING_KEY]
assert deferred["image_mean"] == [0.5, 0.5, 0.5]
assert deferred["image_std"] == [0.5, 0.5, 0.5]
assert deferred.image_mean == [0.5, 0.5, 0.5]
assert deferred.image_std == [0.5, 0.5, 0.5]
def test_kimi_k3_epd_model_preprocessor_receives_image_processor():
@@ -289,7 +289,7 @@ def test_kimi_k3_epd_default_cpu_materialization_is_owner_only_and_exact():
assert len(processor.calls[0]) == 1
assert processor.calls[0][0]["image"].getpixel((0, 0)) == (11, 0, 0)
assert torch.all(materialized == 11)
assert items[0].model_specific_data[DEFERRED_PREPROCESSING_KEY]["backend"] == "cpu"
assert items[0].model_specific_data[DEFERRED_PREPROCESSING_KEY].backend == "cpu"
def test_encoder_preprocess_materializes_only_local_size_balanced_items():
+16 -9
View File
@@ -1,6 +1,7 @@
"""CPU coverage for Kimi-K2.5/K2.7 encoder-DP wiring."""
import asyncio
import functools
from types import SimpleNamespace
from unittest.mock import AsyncMock, Mock, patch
@@ -690,6 +691,7 @@ def test_kimi_k3_epd_rebuild_uses_the_same_media_contract():
def test_kimi_k3_cpu_transport_defers_gpu_preprocessing():
from sglang.srt.multimodal.kimi_k3_image_processing import (
DEFERRED_PREPROCESSING_KEY,
KimiK3DeferredPreprocessing,
)
processor = object.__new__(KimiK3ImageProcessor)
@@ -717,11 +719,13 @@ def test_kimi_k3_cpu_transport_defers_gpu_preprocessing():
"pad_height": 2,
},
],
{
"image_mean": [0.5, 0.5, 0.5],
"image_std": [0.5, 0.5, 0.5],
"transparent_bg_config": None,
},
functools.partial(
KimiK3DeferredPreprocessing,
backend="gpu",
image_mean=[0.5, 0.5, 0.5],
image_std=[0.5, 0.5, 0.5],
transparent_bg_config=None,
),
)
),
)
@@ -751,10 +755,13 @@ def test_kimi_k3_cpu_transport_defers_gpu_preprocessing():
]
assert all(item.hash is not None for item in output.mm_items)
assert all(item.pad_value is not None for item in output.mm_items)
assert all(
DEFERRED_PREPROCESSING_KEY in item.model_specific_data
for item in output.mm_items
)
deferred = [
item.model_specific_data[DEFERRED_PREPROCESSING_KEY] for item in output.mm_items
]
# The staged features are CHW uint8, so the config has to route them to the
# GPU arm of `materialize_item_features`.
assert [config.backend for config in deferred] == ["gpu", "gpu"]
assert [config.resize_config["new_width"] for config in deferred] == [4, 2]
@pytest.mark.parametrize(
@@ -509,6 +509,7 @@ def test_kimi_k3_preprocesses_only_dp_owner_images(monkeypatch):
from sglang.srt.models.kimi_k3 import KimiK3ForConditionalGeneration
from sglang.srt.multimodal.kimi_k3_image_processing import (
DEFERRED_PREPROCESSING_KEY,
KimiK3DeferredPreprocessing,
)
model = KimiK3ForConditionalGeneration.__new__(KimiK3ForConditionalGeneration)
@@ -517,20 +518,19 @@ def test_kimi_k3_preprocesses_only_dp_owner_images(monkeypatch):
model.vision_tower = _K3TowerStub()
model.mm_projector = lambda image_embeds: image_embeds
deferred_config = {
"backend": "gpu",
"feature_layout": "chw",
"image_mean": [0.5, 0.5, 0.5],
"image_std": [0.5, 0.5, 0.5],
"transparent_bg_config": None,
"resize_config": {
deferred_config = KimiK3DeferredPreprocessing(
backend="gpu",
image_mean=[0.5, 0.5, 0.5],
image_std=[0.5, 0.5, 0.5],
transparent_bg_config=None,
resize_config={
"num_tokens": 1,
"new_width": 2,
"new_height": 2,
"pad_width": 0,
"pad_height": 0,
},
}
)
items = [
MultimodalDataItem(
modality=Modality.IMAGE,