{"record":{"id":"35e956f1e72c9e8f","repo":"hiyouga/LlamaFactory","slug":"moss-vl-media-lengths-do-not-consume-all-provided","errorCode":null,"errorMessage":"MOSS-VL media lengths do not consume all provided inputs.","messagePattern":"MOSS-VL media lengths do not consume all provided inputs\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/data/mm_plugin.py","lineNumber":759,"sourceCode":"                media_nums_per_sample.append(1)\n                continue\n\n            image_index = 0\n            video_index = 0\n            for modality in media_order:\n                if modality == \"image\":\n                    final_pixel_values.append(image_chunks[image_index])\n                    final_grid_thw.append(image_grids[image_index])\n                    image_index += 1\n                else:\n                    final_pixel_values.append(video_chunks[video_index])\n                    final_grid_thw.append(video_grids[video_index])\n                    video_index += 1\n\n            media_nums_per_sample.append(len(media_order))\n\n        if image_offset != len(images) or video_offset != len(videos):\n            raise ValueError(\"MOSS-VL media lengths do not consume all provided inputs.\")\n\n        mm_inputs = {\n            \"pixel_values\": torch.cat(final_pixel_values, dim=0),\n            \"grid_thw\": torch.stack(final_grid_thw),\n            \"media_nums_per_sample\": media_nums_per_sample,\n        }\n        mm_inputs[\"cross_attention_mask\"] = self._create_cross_attention_mask(\n            batch_ids,\n            mm_inputs[\"grid_thw\"],\n            media_nums_per_sample,\n            processor.image_token_id,\n            padding_side=processor.tokenizer.padding_side,\n        )\n        return mm_inputs\n\n    def post_process_mossvl_inputs(\n        self,\n        features: dict[str, \"torch.Tensor\"],","sourceCodeStart":741,"sourceCodeEnd":777,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/data/mm_plugin.py#L741-L777","documentation":"MOSS-VL _get_mm_inputs slices images/videos per sample using imglen/vidlen; after the loop, image_offset and video_offset must have consumed exactly all provided images and videos. A mismatch means the per-sample lens (from placeholder counts) disagree with the actual media list lengths.","triggerScenarios":"imglens summing to less than len(images), or vidlens summing to less than len(videos) — e.g. truncated placeholders lowering per-sample counts while the raw media list still holds all items.","commonSituations":"cutoff_len truncation removing media placeholders (counts drop) while media lists stay full; inconsistent dataset rows where media counts differ from placeholder counts across samples.","solutions":["Increase cutoff_len so no placeholders are truncated (root cause in most cases).","Ensure every sample's placeholder counts equal its media list lengths.","If calling the API manually, precheck sum(imglens) == len(images) and sum(vidlens) == len(videos)."],"exampleFix":"### before\ncutoff_len: 4096  # placeholders truncated -> lens sum < media count\n### after\ncutoff_len: 16384","handlingStrategy":"validation","validationCode":"assert sum(imglens) == len(images) and sum(vidlens) == len(videos), 'media lens do not consume all inputs (truncation?)'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["This check failing usually means truncation: raise cutoff_len first, then re-examine data."],"tags":["multimodal","moss-vl","batching","truncation","media-count"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}