sgl-project/sglang · error · ValueError

Kimi-K3 encoder mode supports image input only

Error message

Kimi-K3 encoder mode supports image input only

What it means

preprocess_mm_for_encoder() only accepts Modality.IMAGE for Kimi-K3 encoder-mode preprocessing; passing video, audio, or any other modality raises ValueError. The encoder pipeline downstream (prepare_kimi_k3_encoder_inputs) is image-specific.

Source

Thrown at python/sglang/srt/models/kimi_k3.py:3340

    def set_dspark_layers_to_capture(self, layer_ids: list[int]) -> None:
        if self.language_model is None:
            raise AttributeError(
                "DSPARK layer capture is not available in encoder-only mode"
            )
        self.language_model.set_dspark_layers_to_capture(layer_ids)

    def preprocess_mm_for_encoder(
        self,
        mm_data,
        modality,
        config,
        *,
        image_processor=None,
        use_gpu_preprocessing=False,
    ):
        """Prepare per-image raw inputs for owner-side EPD preprocessing."""
        if modality != Modality.IMAGE:
            raise ValueError("Kimi-K3 encoder mode supports image input only")
        if image_processor is None:
            raise ValueError("Kimi-K3 encoder preprocessing needs an image processor")

        from sglang.srt.multimodal.kimi_k3_image_processing import (
            prepare_kimi_k3_encoder_inputs,
        )

        self._encoder_image_processor = image_processor
        return prepare_kimi_k3_encoder_inputs(
            mm_data,
            image_processor,
            use_gpu_preprocessing=use_gpu_preprocessing,
        )

    def get_image_feature(self, items: List[MultimodalDataItem]) -> torch.Tensor:
        device = self.vision_tower.device
        target_dtype = self.vision_tower.patch_embed.proj.weight.dtype
        image_grid_thws = []

View on GitHub (pinned to 0132848349)

Solutions

  1. Filter requests to image-only before sending to Kimi-K3 encoder preprocessing
  2. Return a 400 for non-image modalities at the request-validation layer
  3. Verify the modality enum value being passed matches what the model supports

Example fix

// before
inputs = model.preprocess_mm_for_encoder(modality=Modality.VIDEO, ...)

// after
if modality != Modality.IMAGE:
    raise HTTPException(400, "Kimi-K3 encoder mode supports images only")
inputs = model.preprocess_mm_for_encoder(modality=modality, ...)
Defensive patterns

Strategy: validation

Validate before calling

from sglang.srt.multimodal.base import Modality
if modality != Modality.IMAGE:
    reject_request("Kimi-K3 encoder mode supports image input only")

Type guard

def is_supported_modality(m) -> bool:
    return m == Modality.IMAGE

Try / catch

try:
    model.preprocess_mm_for_encoder(modality=modality, ...)
except ValueError as e:
    if "image input only" in str(e):
        return bad_request(e)
    raise

Prevention

When it happens

Trigger: Calling preprocess_mm_for_encoder(modality=Modality.VIDEO, ...) or any non-image Modality on the Kimi-K3 model.

Common situations: Routing multimodal requests containing video/audio to an encoder-only Kimi-K3 EPD server; generic multimodal dispatch that forwards all modalities it recognizes.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/b9e3f98955f3f4c0. Report an issue: GitHub.