hiyouga/LlamaFactory · error · ValueError
MOSS-VL encountered a video end token without a matching sta
Error message
MOSS-VL encountered a video end token without a matching start token after tokenization. Please increase `cutoff_len` if a video placeholder was truncated.
What it means
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.
Source
Thrown at src/llamafactory/data/mm_plugin.py:582
) -> list[str]:
media_order = []
video_frame_counts = []
in_video = False
current_video_frames = 0
for token_id in input_ids:
if token_id == processor.vision_start_token_id:
if in_video:
raise ValueError(
"MOSS-VL encountered nested video token blocks after tokenization. "
"Please increase `cutoff_len` if a video placeholder was truncated."
)
media_order.append("video")
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`."
)
View on GitHub (pinned to f28afaf635)
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.
Example fix
### before cutoff_len: 4096 # too small for the video placeholder ### after cutoff_len: 16384
Defensive patterns
Strategy: validation
Validate before calling
ids = tokenizer(text).input_ids
starts = ids.count(processor.vision_start_token_id)
ends = ids.count(processor.vision_end_token_id)
assert starts == ends, f'media block mismatch ({starts} vs {ends}); raise cutoff_len' Prevention
- 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.
When it happens
Trigger: 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.
Common situations: cutoff_len too small relative to expanded image/video placeholders; packing/tokenization settings that drop leading tokens of long multimodal samples.
Related errors
- MOSS-VL encountered nested video token blocks after tokeniza
- MOSS-VL encountered an incomplete video token block after to
- 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/1d6079d34d1b933a.
Report an issue: GitHub.