{"record":{"id":"1d6079d34d1b933a","repo":"hiyouga/LlamaFactory","slug":"moss-vl-encountered-a-video-end-token-without-a-ma","errorCode":null,"errorMessage":"MOSS-VL encountered a video end token without a matching start token after tokenization. Please increase `cutoff_len` if a video placeholder was truncated.","messagePattern":"MOSS-VL encountered a video end token without a matching start token after tokenization\\. Please increase `cutoff_len` if a video placeholder was truncated\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/data/mm_plugin.py","lineNumber":582,"sourceCode":"    ) -> list[str]:\n        media_order = []\n        video_frame_counts = []\n        in_video = False\n        current_video_frames = 0\n        for token_id in input_ids:\n            if token_id == processor.vision_start_token_id:\n                if in_video:\n                    raise ValueError(\n                        \"MOSS-VL encountered nested video token blocks after tokenization. \"\n                        \"Please increase `cutoff_len` if a video placeholder was truncated.\"\n                    )\n\n                media_order.append(\"video\")\n                in_video = True\n                current_video_frames = 0\n            elif token_id == processor.vision_end_token_id:\n                if not in_video:\n                    raise ValueError(\n                        \"MOSS-VL encountered a video end token without a matching start token after tokenization. \"\n                        \"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","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/data/mm_plugin.py#L564-L600","documentation":"MOSS-VL post-tokenization check: a vision_end token id appears in input_ids without a preceding vision_start token. This asymmetric state arises when truncation removes the start token of a media block but leaves its end token, corrupting the media-order reconstruction.","triggerScenarios":"Same root cause as the nested-block error: cutoff_len truncates a MOSS-VL sample so that a media block's start token is cut while its end token (or a later block's end token) survives in the tokenized sequence.","commonSituations":"cutoff_len too small relative to expanded image/video placeholders; packing/tokenization settings that drop leading tokens of long multimodal samples.","solutions":["Increase cutoff_len so no visual placeholder is truncated.","Reduce media token budget: fewer/smaller images, lower video_maxlen.","Inspect the offending sample (enable data debugging logs) and cap its media count."],"exampleFix":"### before\ncutoff_len: 4096  # too small for the video placeholder\n### after\ncutoff_len: 16384","handlingStrategy":"validation","validationCode":"ids = tokenizer(text).input_ids\nstarts = ids.count(processor.vision_start_token_id)\nends = ids.count(processor.vision_end_token_id)\nassert starts == ends, f'media block mismatch ({starts} vs {ends}); raise cutoff_len'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat any 'after tokenization' MOSS-VL error as a truncation symptom; fix cutoff_len first.","Log per-sample token lengths during preprocessing to catch outliers early."],"tags":["multimodal","moss-vl","video","truncation","cutoff-len"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}