{"record":{"id":"d9ae57456e60bfb4","repo":"hiyouga/LlamaFactory","slug":"moss-vl-batch-metadata-must-have-one-entry-per-sam","errorCode":null,"errorMessage":"MOSS-VL batch metadata must have one entry per sample.","messagePattern":"MOSS-VL batch metadata must have one entry per sample\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/data/mm_plugin.py","lineNumber":680,"sourceCode":"\n    @override\n    def get_mm_inputs(\n        self,\n        images: list[\"ImageInput\"],\n        videos: list[\"VideoInput\"],\n        audios: list[\"AudioInput\"],\n        imglens: list[int],\n        vidlens: list[int],\n        audlens: list[int],\n        batch_ids: list[list[int]],\n        processor: Optional[\"MMProcessor\"],\n    ) -> dict[str, Union[list[int], \"torch.Tensor\"]]:\n        self._validate_input(processor, images, videos, audios)\n        if audios:\n            raise ValueError(\"MOSS-VL does not support audio inputs.\")\n\n        if not (len(imglens) == len(vidlens) == len(batch_ids)):\n            raise ValueError(\"MOSS-VL batch metadata must have one entry per sample.\")\n        final_pixel_values = []\n        final_grid_thw = []\n        media_nums_per_sample = []\n        image_offset = 0\n        video_offset = 0\n        for imglen, vidlen, input_ids in zip(imglens, vidlens, batch_ids):\n            sample_images = images[image_offset : image_offset + imglen]\n            sample_videos = videos[video_offset : video_offset + vidlen]\n            image_offset += imglen\n            video_offset += vidlen\n            image_chunks, image_grids = [], []\n            if sample_images:\n                regularized_images = self._regularize_images(\n                    sample_images,\n                    image_max_pixels=2**63 - 1,\n                    image_min_pixels=1,\n                )[\"images\"]\n                image_kwargs = {\"return_tensors\": \"pt\"}","sourceCodeStart":662,"sourceCodeEnd":698,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/data/mm_plugin.py#L662-L698","documentation":"MOSS-VL batching sanity check in _get_mm_inputs: imglens, vidlens and batch_ids must all have the same length (one entry per sample in the batch). These lists are produced internally by the data pipeline; a mismatch indicates corrupted batch metadata rather than user data.","triggerScenarios":"Custom code calling plugin._get_mm_images/videos path with hand-built imglens/vidlens/batch_ids of differing lengths; or a patched data collator that returns mismatched lengths.","commonSituations":"Users subclassing the trainer/collator for multimodal batching and building the lens lists independently; version skew after upgrading LlamaFactory where collator output changed.","solutions":["If calling the API directly, assert len(imglens) == len(vidlens) == len(batch_ids) before the call.","Remove local patches to the data collator or update them to the current LlamaFactory version.","Reproduce with stock LlamaFactory data pipeline to confirm the bug is in custom code."],"exampleFix":"# before\nmm_inputs = plugin._get_mm_inputs(images, videos, audios, imglens, vidlens, audlens, batch_ids, processor)\n# after\nassert len(imglens) == len(vidlens) == len(batch_ids), 'per-sample metadata must align'\nmm_inputs = plugin._get_mm_inputs(images, videos, audios, imglens, vidlens, audlens, batch_ids, processor)","handlingStrategy":"validation","validationCode":"assert len(imglens) == len(vidlens) == len(batch_ids), 'per-sample batch metadata must align'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never build imglens/vidlens by hand; derive them from per-sample placeholder counts in one pass.","Keep custom collator patches in sync with the LlamaFactory version in use."],"tags":["multimodal","moss-vl","batching","internal-invariant"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}