{"record":{"id":"43182e13527a3014","repo":"sgl-project/sglang","slug":"kimi-k3-processor-feature-length-does-not-match-im","errorCode":null,"errorMessage":"Kimi-K3 processor feature length does not match image grids: {pixel_values.shape[0]} != {sum(patch_counts)}","messagePattern":"Kimi-K3 processor feature length does not match image grids: (.+?) != (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/multimodal/processors/kimi_k3.py","lineNumber":354,"sourceCode":"                image_bias,\n                self._patch_size,\n                to_chw=_k3_to_cuda_chw,\n                post_resize=lambda x: _fill_transparent_bg(\n                    x, self._transparent_bg_config\n                ),\n            )\n        else:\n            # The checkpoint CPU processor couples prompt composition with media\n            # preprocessing. A synthetic prompt keeps that API but is discarded;\n            # image features and grids are independent of its text.\n            output = self._cpu_call(self._image_token * len(images), images)\n            pixel_values = output[\"pixel_values\"]\n            grid_thws = output[\"image_grid_thw\"]\n\n        grids = [tuple(int(value) for value in grid) for grid in grid_thws.tolist()]\n        patch_counts = [math.prod(grid) for grid in grids]\n        if sum(patch_counts) != pixel_values.shape[0]:\n            raise ValueError(\n                \"Kimi-K3 processor feature length does not match image grids: \"\n                f\"{pixel_values.shape[0]} != {sum(patch_counts)}\"\n            )\n        return (\n            list(pixel_values.split(patch_counts)),\n            image_sizes,\n            resize_configs,\n            grids,\n        )\n\n\nclass KimiK3ImageProcessor(\n    KimiGridMMDataMixin,\n    MediaArtifactCacheMixin,\n    SGLangBaseProcessor,\n):\n    models = [KimiK3ForConditionalGeneration]\n    artifact_modality = Modality.IMAGE","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/multimodal/processors/kimi_k3.py#L336-L372","documentation":"Raised in prepare_image_features when the first dimension of pixel_values returned by the HF processor does not equal the sum of patch counts derived from image_grid_thw. The processor output must be internally consistent because features are split per image by these counts.","triggerScenarios":"Calling the HF image processor (or prepare_artifact_batch) with images whose returned pixel_values rows != math.prod(grid) summed over image_grid_thw; happens with patched/partial vision backends that drop rows or return merged grids.","commonSituations":"Mismatched transformers/processor version emitting different patch merging (e.g. spatial_merge_size change); passing pre-resized images with inconsistent resize configs; a custom processor overriding image_grid_thw.","solutions":["Pin/upgrade transformers to the version matching the Kimi-K3 processor config","Pass raw images and let the processor resize; don't mix precomputed grids with fresh pixel_values","Log grid_thw and pixel_values.shape[0] to identify which image breaks the invariant"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"import math\ndef check_processor_output(output):\n    grids = output[\"image_grid_thw\"].tolist()\n    expected = sum(math.prod(g) for g in grids)\n    return output[\"pixel_values\"].shape[0] == expected","typeGuard":null,"tryCatchPattern":"try:\n    feats = prepare_image_features(batch)\nexcept ValueError:\n    feats = [prepare_image_features([img])[0] for img in batch]  # per-image fallback","preventionTips":["Pin the transformers version matching the model's processor","Don't mix precomputed grids with freshly computed pixel_values"],"tags":["multimodal","kimi-k3","processor-mismatch","shape-mismatch"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}