hiyouga/LlamaFactory · error · ValueError
MOSS-VL batch metadata must have one entry per sample.
Error message
MOSS-VL batch metadata must have one entry per sample.
What it means
MOSS-VL batching sanity check in _get_mm_inputs: imglens, vidlens and batch_ids must all have the same length (one entry per sample in the batch). These lists are produced internally by the data pipeline; a mismatch indicates corrupted batch metadata rather than user data.
Source
Thrown at src/llamafactory/data/mm_plugin.py:680
@override
def get_mm_inputs(
self,
images: list["ImageInput"],
videos: list["VideoInput"],
audios: list["AudioInput"],
imglens: list[int],
vidlens: list[int],
audlens: list[int],
batch_ids: list[list[int]],
processor: Optional["MMProcessor"],
) -> dict[str, Union[list[int], "torch.Tensor"]]:
self._validate_input(processor, images, videos, audios)
if audios:
raise ValueError("MOSS-VL does not support audio inputs.")
if not (len(imglens) == len(vidlens) == len(batch_ids)):
raise ValueError("MOSS-VL batch metadata must have one entry per sample.")
final_pixel_values = []
final_grid_thw = []
media_nums_per_sample = []
image_offset = 0
video_offset = 0
for imglen, vidlen, input_ids in zip(imglens, vidlens, batch_ids):
sample_images = images[image_offset : image_offset + imglen]
sample_videos = videos[video_offset : video_offset + vidlen]
image_offset += imglen
video_offset += vidlen
image_chunks, image_grids = [], []
if sample_images:
regularized_images = self._regularize_images(
sample_images,
image_max_pixels=2**63 - 1,
image_min_pixels=1,
)["images"]
image_kwargs = {"return_tensors": "pt"}View on GitHub (pinned to f28afaf635)
Solutions
- If calling the API directly, assert len(imglens) == len(vidlens) == len(batch_ids) before the call.
- Remove local patches to the data collator or update them to the current LlamaFactory version.
- Reproduce with stock LlamaFactory data pipeline to confirm the bug is in custom code.
Example fix
# before mm_inputs = plugin._get_mm_inputs(images, videos, audios, imglens, vidlens, audlens, batch_ids, processor) # after assert len(imglens) == len(vidlens) == len(batch_ids), 'per-sample metadata must align' mm_inputs = plugin._get_mm_inputs(images, videos, audios, imglens, vidlens, audlens, batch_ids, processor)
Defensive patterns
Strategy: validation
Validate before calling
assert len(imglens) == len(vidlens) == len(batch_ids), 'per-sample batch metadata must align'
Prevention
- Never build imglens/vidlens by hand; derive them from per-sample placeholder counts in one pass.
- Keep custom collator patches in sync with the LlamaFactory version in use.
When it happens
Trigger: Custom code calling plugin._get_mm_images/videos path with hand-built imglens/vidlens/batch_ids of differing lengths; or a patched data collator that returns mismatched lengths.
Common situations: Users subclassing the trainer/collator for multimodal batching and building the lens lists independently; version skew after upgrading LlamaFactory where collator output changed.
Related errors
- MOSS-VL media lengths do not consume all provided inputs.
- 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 media tokens do not match the provided media after t
AI-assisted analysis of hiyouga/LlamaFactory@f28afaf635 (2026-08-14).
Data as JSON: /api/errors/d9ae57456e60bfb4.
Report an issue: GitHub.