trl icon indicating copy to clipboard operation
trl copied to clipboard

Online DPO: Qwen2-VL fails because mm_token_type_ids is not passed

Open eliem08 opened this issue 1 month ago • 1 comments

Reproduction

OnlineDPOTrainer fails on Qwen2-VL because mm_token_type_ids is never passed to the model. Found while checking the Online DPO VLM fixes from #7704 / #7703 (not from a production run). Adding Qwen2-VL to the existing VLM test reproduces it:

# tests/experimental/test_online_dpo_trainer.py, TestOnlineDPOVisionTrainer.test_online_dpo_vlm_trainer
model_id = "trl-internal-testing/tiny-Qwen2VLForConditionalGeneration"
ValueError: Multimodal data was passed (via `image_grid_thw` or `video_grid_thw`) but `mm_token_type_ids` is missing.

The processor returns mm_token_type_ids alongside input_ids, but _generate only forwards pixel_values, pixel_attention_mask, image_sizes and image_grid_thw, and _forward builds its model kwargs the same way. The other trainers that forward image_grid_thw (GRPO, RLOO, DPO, KTO, SFT, distillation, GOLD, GMPO) already handle mm_token_type_ids.

A fix following GRPOTrainer (duplicate them for generation, extend them with zeros for the completion in the forward pass) is 8 lines; with it, the Idefics2, Llava and Qwen2-VL VLM tests all pass. I'd like to open a PR for it if that's welcome; could this be assigned to me?

System Info

TRL main (bc11e51), transformers 5.20.2, torch 2.11 (CPU), Python 3.12, Windows 11

eliem08 avatar Oct 20 '26 14:10 eliem08

Hey @eliem08, thanks for the report and the fix. Sorry your PR got auto-closed by the first-time-contributor check before anyone could assign you. #7859 fixed this by passing mm_token_type_ids through generation and the forward pass, the same way GRPO does:

https://github.com/huggingface/trl/blob/620635a3d97c8b179a8b141d5305447b0c4c39ed/trl/experimental/online_dpo/online_dpo_trainer.py#L1128-L1133

It shipped in v1.17.0, and the VLM test now covers Qwen2-VL, Qwen2.5-VL and Qwen3-VL. Closing as fixed. Please re-open if you still hit this on a current version.

qgallouedec avatar Oct 30 '26 11:10 qgallouedec