{"record":{"id":"b29658eaac9755bf","repo":"hiyouga/LlamaFactory","slug":"moss-vl-encountered-nested-video-token-blocks-afte","errorCode":null,"errorMessage":"MOSS-VL encountered nested video token blocks after tokenization. Please increase `cutoff_len` if a video placeholder was truncated.","messagePattern":"MOSS-VL encountered nested video token blocks 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":572,"sourceCode":"\n        return dict(processor.video_processor(videos=videos, **video_kwargs))\n\n    def _get_media_order_from_ids(\n        self,\n        input_ids: list[int],\n        processor: \"MMProcessor\",\n        num_images: int,\n        num_videos: int,\n        expected_video_frames: Optional[list[int]] = None,\n    ) -> 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:","sourceCodeStart":554,"sourceCodeEnd":590,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/data/mm_plugin.py#L554-L590","documentation":"MOSS-VL plugin post-validates tokenized input_ids: after the tokenizer expands placeholders, a vision_start token encountered while already inside a video block means two video blocks overlap — i.e. the token stream is corrupted, almost always because cutoff_len truncated a video placeholder mid-block, leaving an unterminated start token adjacent to the next media block.","triggerScenarios":"Training/chat with MOSS-VL where cutoff_len is smaller than the expanded video placeholder (vision_bos + N image tokens + vision_eos), so truncation cuts off the end token and the next sample's/media's start token appears inside the still-open block.","commonSituations":"Long videos with high frame counts (video_maxlen large) plus a modest cutoff_len (e.g. 2048); sharing a config across models where MOSS-VL needs far more tokens per video than the model it was copied from.","solutions":["Increase cutoff_len in the training/inference YAML so a full video placeholder plus text fits.","Reduce video_maxlen (or video_fps) so each video expands to fewer tokens.","Shorten the text portion of affected samples."],"exampleFix":"### before\ncutoff_len: 2048\nvideo_maxlen: 256\n### after\ncutoff_len: 8192\nvideo_maxlen: 64","handlingStrategy":"validation","validationCode":"# estimate worst-case tokens before training\nframes = video_maxlen\ntokens_per_frame = 196  # MOSS-VL tiles; use your measured value\nest = frames * tokens_per_frame + 32\nassert cutoff_len > est + 512, 'raise cutoff_len or lower video_maxlen'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair MOSS-VL video configs with a cutoff_len comfortably larger than max placeholder expansion.","Start with small video_maxlen, raise only after a successful dry run."],"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"}