{"record":{"id":"0ef27edeb48d4e13","repo":"sgl-project/sglang","slug":"kimi-k3-encoder-preprocessing-needs-an-image-proce","errorCode":null,"errorMessage":"Kimi-K3 encoder preprocessing needs an image processor","messagePattern":"Kimi-K3 encoder preprocessing needs an image processor","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/kimi_k3.py","lineNumber":3342,"sourceCode":"            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 = []\n        for item in items:\n            grid_thw = item.model_specific_data.get(\"image_grid_thw\")","sourceCodeStart":3324,"sourceCodeEnd":3360,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/kimi_k3.py#L3324-L3360","documentation":"Kimi-K3's encoder preprocessing requires an image processor; passing image_processor=None to preprocess_mm_for_encoder() raises ValueError. The processor is stored and later used by prepare_kimi_k3_encoder_inputs and CPU/GPU feature materialization.","triggerScenarios":"Calling preprocess_mm_for_encoder(...) without supplying image_processor, e.g. a caller that lazily loads processors or assumed the model holds its own.","commonSituations":"Custom serving harnesses that build the processor conditionally; encoder-only deployments where the processor was not initialized alongside the model.","solutions":["Load the model's HF image processor and pass it into the call","Initialize the processor at model load time and thread it through the preprocessing path","Add a startup assertion that the processor exists before serving"],"exampleFix":"// before\nmodel.preprocess_mm_for_encoder(modality=m, data=d, image_processor=None)\n\n// after\nmodel.preprocess_mm_for_encoder(modality=m, data=d, image_processor=processor)","handlingStrategy":"validation","validationCode":"if image_processor is None:\n    image_processor = load_kimi_k3_image_processor(model_config)\nassert image_processor is not None","typeGuard":"def has_image_processor(p) -> bool:\n    return p is not None and hasattr(p, \"preprocess\")","tryCatchPattern":null,"preventionTips":["Initialize the image processor at model load and store it alongside the model","Fail fast at startup if the processor config is missing"],"tags":["kimi-k3","image-processor","missing-argument"],"backgroundTag":"missing-preprocessor","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}