{"record":{"id":"2a12319d72660381","repo":"hiyouga/LlamaFactory","slug":"moss-vl-media-tokens-do-not-match-the-provided-med","errorCode":null,"errorMessage":"MOSS-VL media tokens do not match the provided media after tokenization: order={media_order}, images={num_images}, videos={num_videos}. Please increase `cutoff_len` if a visual placeholder was truncated.","messagePattern":"MOSS-VL media tokens do not match the provided media after tokenization: order=(.+?), images=(.+?), videos=(.+?)\\. Please increase `cutoff_len` if a visual placeholder was truncated\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/data/mm_plugin.py","lineNumber":602,"sourceCode":"                        \"Please increase `cutoff_len` if a video placeholder was truncated.\"\n                    )\n\n                video_frame_counts.append(current_video_frames)\n                in_video = False\n            elif token_id == processor.image_token_id:\n                if in_video:\n                    current_video_frames += 1\n                else:\n                    media_order.append(\"image\")\n\n        if in_video:\n            raise ValueError(\n                \"MOSS-VL encountered an incomplete video token block after tokenization. \"\n                \"Please increase `cutoff_len` or reduce `video_maxlen`.\"\n            )\n\n        if media_order.count(\"image\") != num_images or media_order.count(\"video\") != num_videos:\n            raise ValueError(\n                \"MOSS-VL media tokens do not match the provided media after tokenization: \"\n                f\"order={media_order}, images={num_images}, videos={num_videos}. \"\n                \"Please increase `cutoff_len` if a visual placeholder was truncated.\"\n            )\n\n        if expected_video_frames is not None and video_frame_counts != expected_video_frames:\n            raise ValueError(\n                \"MOSS-VL video frame tokens do not match the processed video after tokenization: \"\n                f\"tokens={video_frame_counts}, frames={expected_video_frames}. \"\n                \"Please increase `cutoff_len` or reduce `video_maxlen`.\"\n            )\n\n        return media_order\n\n    @override\n    def process_messages(\n        self,\n        messages: list[dict[str, str]],","sourceCodeStart":584,"sourceCodeEnd":620,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/data/mm_plugin.py#L584-L620","documentation":"MOSS-VL post-tokenization check: after reconstructing the media order from input_ids, the counts of image and video blocks do not equal the num_images / num_videos passed in. Some placeholders were truncated away (or never expanded), so the model would attend to fewer media than provided.","triggerScenarios":"Calling MOSS-VL process_messages/process_token_ids where truncation removed entire media placeholders, or where placeholder counts in the text differ from the media lists (then _validate_messages usually fires first, but truncation bypasses it).","commonSituations":"cutoff_len smaller than the total media placeholder budget of a sample with several images/videos; samples with many images (image count high, each block large).","solutions":["Increase cutoff_len so every image/video placeholder survives tokenization.","Reduce the number of media per sample or their token footprint (smaller images, lower video_maxlen).","Verify placeholder counts in messages match the images/videos lists (guards the non-truncation path)."],"exampleFix":"### before\n# 8 images per sample, cutoff_len 2048 -> placeholders truncated\ncutoff_len: 2048\n### after\ncutoff_len: 16384","handlingStrategy":"validation","validationCode":"order = []\nfor t in ids:\n    if t == processor.vision_start_token_id: order.append('video')\n    elif t == processor.image_token_id and (not order or order[-1] != 'video_open'): pass\n# simpler: count blocks\nn_img = sum(1 for t in ids if t == processor.image_token_id)\nassert order.count('image') == expected_images and order.count('video') == expected_videos","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep media-per-sample counts modest so placeholders never approach cutoff_len.","Unit-test your dataset with the plugin's process_messages before a training run."],"tags":["multimodal","moss-vl","truncation","cutoff-len","media-count"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}