{"record":{"id":"b9e3f98955f3f4c0","repo":"sgl-project/sglang","slug":"kimi-k3-encoder-mode-supports-image-input-only","errorCode":null,"errorMessage":"Kimi-K3 encoder mode supports image input only","messagePattern":"Kimi-K3 encoder mode supports image input only","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/kimi_k3.py","lineNumber":3340,"sourceCode":"    def set_dspark_layers_to_capture(self, layer_ids: list[int]) -> None:\n        if self.language_model is None:\n            raise AttributeError(\n                \"DSPARK layer capture is not available in encoder-only mode\"\n            )\n        self.language_model.set_dspark_layers_to_capture(layer_ids)\n\n    def preprocess_mm_for_encoder(\n        self,\n        mm_data,\n        modality,\n        config,\n        *,\n        image_processor=None,\n        use_gpu_preprocessing=False,\n    ):\n        \"\"\"Prepare per-image raw inputs for owner-side EPD preprocessing.\"\"\"\n        if modality != Modality.IMAGE:\n            raise ValueError(\"Kimi-K3 encoder mode supports image input only\")\n        if image_processor is None:\n            raise ValueError(\"Kimi-K3 encoder preprocessing needs an image processor\")\n\n        from sglang.srt.multimodal.kimi_k3_image_processing import (\n            prepare_kimi_k3_encoder_inputs,\n        )\n\n        self._encoder_image_processor = image_processor\n        return prepare_kimi_k3_encoder_inputs(\n            mm_data,\n            image_processor,\n            use_gpu_preprocessing=use_gpu_preprocessing,\n        )\n\n    def get_image_feature(self, items: List[MultimodalDataItem]) -> torch.Tensor:\n        device = self.vision_tower.device\n        target_dtype = self.vision_tower.patch_embed.proj.weight.dtype\n        image_grid_thws = []","sourceCodeStart":3322,"sourceCodeEnd":3358,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/kimi_k3.py#L3322-L3358","documentation":"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.","triggerScenarios":"Calling preprocess_mm_for_encoder(modality=Modality.VIDEO, ...) or any non-image Modality on the Kimi-K3 model.","commonSituations":"Routing multimodal requests containing video/audio to an encoder-only Kimi-K3 EPD server; generic multimodal dispatch that forwards all modalities it recognizes.","solutions":["Filter requests to image-only before sending to Kimi-K3 encoder preprocessing","Return a 400 for non-image modalities at the request-validation layer","Verify the modality enum value being passed matches what the model supports"],"exampleFix":"// before\ninputs = model.preprocess_mm_for_encoder(modality=Modality.VIDEO, ...)\n\n// after\nif modality != Modality.IMAGE:\n    raise HTTPException(400, \"Kimi-K3 encoder mode supports images only\")\ninputs = model.preprocess_mm_for_encoder(modality=modality, ...)","handlingStrategy":"validation","validationCode":"from sglang.srt.multimodal.base import Modality\nif modality != Modality.IMAGE:\n    reject_request(\"Kimi-K3 encoder mode supports image input only\")","typeGuard":"def is_supported_modality(m) -> bool:\n    return m == Modality.IMAGE","tryCatchPattern":"try:\n    model.preprocess_mm_for_encoder(modality=modality, ...)\nexcept ValueError as e:\n    if \"image input only\" in str(e):\n        return bad_request(e)\n    raise","preventionTips":["Advertise supported modalities per model in routing config","Validate modality at request admission, not deep in the model"],"tags":["kimi-k3","multimodal","modality-mismatch","validation"],"backgroundTag":"unsupported-modality","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}