hiyouga/LlamaFactory · error · ValueError
MOSS-VL encountered an incomplete video token block after to
Error message
MOSS-VL encountered an incomplete video token block after tokenization. Please increase `cutoff_len` or reduce `video_maxlen`.
What it means
MOSS-VL post-tokenization check: the token stream ends while still inside a video block (a vision_start was seen with no matching vision_end). The video placeholder was truncated before its terminating token, so frame counting cannot complete.
Source
Thrown at src/llamafactory/data/mm_plugin.py:596
in_video = True
current_video_frames = 0
elif token_id == processor.vision_end_token_id:
if not in_video:
raise ValueError(
"MOSS-VL encountered a video end token without a matching start token after tokenization. "
"Please increase `cutoff_len` if a video placeholder was truncated."
)
video_frame_counts.append(current_video_frames)
in_video = False
elif token_id == processor.image_token_id:
if in_video:
current_video_frames += 1
else:
media_order.append("image")
if in_video:
raise ValueError(
"MOSS-VL encountered an incomplete video token block after tokenization. "
"Please increase `cutoff_len` or reduce `video_maxlen`."
)
if media_order.count("image") != num_images or media_order.count("video") != num_videos:
raise ValueError(
"MOSS-VL media tokens do not match the provided media after tokenization: "
f"order={media_order}, images={num_images}, videos={num_videos}. "
"Please increase `cutoff_len` if a visual placeholder was truncated."
)
if expected_video_frames is not None and video_frame_counts != expected_video_frames:
raise ValueError(
"MOSS-VL video frame tokens do not match the processed video after tokenization: "
f"tokens={video_frame_counts}, frames={expected_video_frames}. "
"Please increase `cutoff_len` or reduce `video_maxlen`."
)
View on GitHub (pinned to f28afaf635)
Solutions
- Increase cutoff_len to cover the largest video placeholder in the dataset.
- Reduce video_maxlen / video_fps so each video yields fewer frame tokens.
- Pre-compute worst-case placeholder length (frames x tokens-per-frame) and set cutoff_len above it.
Example fix
### before cutoff_len: 4096 ### after cutoff_len: 32768 video_maxlen: 128
Defensive patterns
Strategy: validation
Validate before calling
ids = tokenizer(sample_text_with_placeholders).input_ids
open_blocks = 0
for t in ids:
if t == processor.vision_start_token_id: open_blocks += 1
elif t == processor.vision_end_token_id: open_blocks -= 1
assert open_blocks == 0, 'truncated video placeholder; increase cutoff_len / reduce video_maxlen' Prevention
- Budget cutoff_len as max_text_len + total_media_tokens with margin.
- Cap videos per sample when cutoff_len is fixed.
When it happens
Trigger: A MOSS-VL sample whose expanded video placeholder exceeds the remaining cutoff_len budget; the tail of the sequence (containing vision_eos) is dropped. The error message itself points at cutoff_len or video_maxlen.
Common situations: High-resolution / many-frame videos; cutoff_len tuned for text-only data; video_maxlen default too generous for the chosen cutoff.
Related errors
- MOSS-VL encountered nested video token blocks after tokeniza
- MOSS-VL encountered a video end token without a matching sta
- MOSS-VL media tokens do not match the provided media after t
- MOSS-VL video frame tokens do not match the processed video
- MOSS-VL media lengths do not consume all provided inputs.
AI-assisted analysis of hiyouga/LlamaFactory@f28afaf635 (2026-08-14).
Data as JSON: /api/errors/31e4abae2dac9f42.
Report an issue: GitHub.