hiyouga/LlamaFactory · error · ValueError
MOSS-VL media lengths do not consume all provided inputs.
Error message
MOSS-VL media lengths do not consume all provided inputs.
What it means
MOSS-VL _get_mm_inputs slices images/videos per sample using imglen/vidlen; after the loop, image_offset and video_offset must have consumed exactly all provided images and videos. A mismatch means the per-sample lens (from placeholder counts) disagree with the actual media list lengths.
Source
Thrown at src/llamafactory/data/mm_plugin.py:759
media_nums_per_sample.append(1)
continue
image_index = 0
video_index = 0
for modality in media_order:
if modality == "image":
final_pixel_values.append(image_chunks[image_index])
final_grid_thw.append(image_grids[image_index])
image_index += 1
else:
final_pixel_values.append(video_chunks[video_index])
final_grid_thw.append(video_grids[video_index])
video_index += 1
media_nums_per_sample.append(len(media_order))
if image_offset != len(images) or video_offset != len(videos):
raise ValueError("MOSS-VL media lengths do not consume all provided inputs.")
mm_inputs = {
"pixel_values": torch.cat(final_pixel_values, dim=0),
"grid_thw": torch.stack(final_grid_thw),
"media_nums_per_sample": media_nums_per_sample,
}
mm_inputs["cross_attention_mask"] = self._create_cross_attention_mask(
batch_ids,
mm_inputs["grid_thw"],
media_nums_per_sample,
processor.image_token_id,
padding_side=processor.tokenizer.padding_side,
)
return mm_inputs
def post_process_mossvl_inputs(
self,
features: dict[str, "torch.Tensor"],View on GitHub (pinned to f28afaf635)
Solutions
- Increase cutoff_len so no placeholders are truncated (root cause in most cases).
- Ensure every sample's placeholder counts equal its media list lengths.
- If calling the API manually, precheck sum(imglens) == len(images) and sum(vidlens) == len(videos).
Example fix
### before cutoff_len: 4096 # placeholders truncated -> lens sum < media count ### after cutoff_len: 16384
Defensive patterns
Strategy: validation
Validate before calling
assert sum(imglens) == len(images) and sum(vidlens) == len(videos), 'media lens do not consume all inputs (truncation?)'
Prevention
- This check failing usually means truncation: raise cutoff_len first, then re-examine data.
When it happens
Trigger: imglens summing to less than len(images), or vidlens summing to less than len(videos) — e.g. truncated placeholders lowering per-sample counts while the raw media list still holds all items.
Common situations: cutoff_len truncation removing media placeholders (counts drop) while media lists stay full; inconsistent dataset rows where media counts differ from placeholder counts across samples.
Related errors
- MOSS-VL media tokens do not match the provided media after t
- MOSS-VL encountered nested video token blocks after tokeniza
- MOSS-VL encountered a video end token without a matching sta
- MOSS-VL encountered an incomplete video token block after to
- MOSS-VL video frame tokens do not match the processed video
AI-assisted analysis of hiyouga/LlamaFactory@f28afaf635 (2026-08-14).
Data as JSON: /api/errors/35e956f1e72c9e8f.
Report an issue: GitHub.