Online DPO VLM training fails for processors with 5D pixel values, such as Idefics2: RuntimeError: Number of dimensions of repeat dims can not be smaller than number of dimensions of tensor
I found this while investigating #7701. Training a VLM whose processor returns 5D pixel_values, such as Idefics2, Idefics3 or SmolVLM, with OnlineDPOTrainer fails on the first step:
RuntimeError: Number of dimensions of repeat dims can not be smaller than number of dimensions of tensor
Reproducer: the one from #7701, with tiny-Idefics2ForConditionalGeneration instead of tiny-LlavaForConditionalGeneration.
Traceback:
Traceback (most recent call last):
File "repro.py", line 26, in <module>
trainer.train()
File "/fsx/albert/dev/transformers/src/transformers/trainer.py", line 1562, in train
return inner_training_loop(
File "/fsx/albert/dev/transformers/src/transformers/trainer.py", line 1646, in _inner_training_loop
self._run_epoch(
File "/fsx/albert/dev/transformers/src/transformers/trainer.py", line 1892, in _run_epoch
tr_loss_step = self.training_step(model, inputs, num_items_in_batch)
File "/fsx/albert/dev/trl/trl/experimental/online_dpo/online_dpo_trainer.py", line 1170, in training_step
prompt_ids, prompt_mask, completion_ids, completion_mask = self._generate(model, prompts, images)
File "/fsx/albert/dev/trl/trl/experimental/online_dpo/online_dpo_trainer.py", line 1020, in _generate
vision_generation_kwargs["pixel_values"] = prompt_inputs["pixel_values"].repeat(2, 1, 1, 1)
RuntimeError: Number of dimensions of repeat dims can not be smaller than number of dimensions of tensor
Root cause
Two independent problems in Online DPO's image handling:
- To generate 2 completions per prompt, the vision inputs are duplicated with
.repeat(2, 1, 1, 1)forpixel_valuesand.repeat(2, 1)forpixel_attention_mask, in both_generateandtraining_step. That only works for 4Dpixel_valuesand 2D masks. Idefics2 returns 5Dpixel_values(batch, images, channels, height, width)and a 4Dpixel_attention_mask. - After that, for the forward pass,
training_steprebuilds the image features by calling the processor withtext="". The Idefics2 processor rejects this:ValueError: The number of images in the text [0] and images [1] should be the same.
I independently reproduced the reported Idefics2 failure with the 5D pixel_values dimensionality error. My Llava control failed with a different CPU-only error, so I cannot claim a clean control pass or working workaround.
Reproduction and limitations: https://aibadgr.com/evidence/trl-7702-online-dpo-vlm-5d-pixel-values-repeat-error
I tested this as part of Badgr's GPU execution verification work. If you're running multimodal training or evaluation and want to try a bounded GPU job without provisioning it manually, I can offer $5 in eligible Badgr trial credits for a small workload. Is there a particular VLM run you'd like verified?