Vision Language Model Alignment in TRL ⚡️
TRL adds vision language model support for several alignment methods. New are Mixed Preference Optimization (MPO), Group Relative Policy Optimization (GRPO) and its sequence-level variant GSPO, alongside multimodal RLOO, Online DPO and native SFTTrainer support. MPO is implemented in DPOTrainer as a weighted combination of DPO sigmoid, BCO and SFT losses, which the MPO paper reports gives a 6.2-point MathVista gain. GRPO uses custom format and accuracy reward functions. GSPO is enabled through GRPOConfig with sequence-level importance sampling, which is mainly useful for MoE models. Code snippets show each trainer config, and a vibe-check comparison on Qwen2.5-VL-3B shows the GRPO and GSPO runs reaching the correct geometry answer where the base and MPO models do not.
Related posts
- Preference Optimization for Vision Language Models
Hugging Face hardMasterTRL now supports direct preference optimization (DPO) for vision language models, trained on chosen/rejected answer pairs rather than fixed labels. A walkthrough fine-tunes Idefics2-8b on the RLAIF-V dataset, formatting image-plus-question prompts with the processor's chat template. Full float32 DPO training would need about 160 GB (policy, reference model, gradients, AdamW states), but bfloat16 plus LoRA cuts trainable parameters to 55M and memory to roughly 32 GB. Batch size 2 with 32 gradient accumulation steps and gradient checkpointing fits activations, and training is judged by rising accuracy and reward margin.
- Preference Tuning LLMs with Direct Preference Optimization Methods
Hugging Face hardMasterAn empirical comparison of three RL-free preference alignment methods (DPO, IPO and KTO) on two SFT'd 7B models, Zephyr-7b-beta-sft and OpenHermes-2.5-Mistral-7B, sweeping β from 0.01 to 0.9 with TRL's DPOTrainer and scoring the results on MT-Bench. After a fix to TRL's IPO implementation, which now averages rather than sums log-likelihoods, DPO and IPO perform comparably and both beat KTO in the paired-preference setting. The best β varies sharply by model and algorithm: 0.01 works best for Zephyr, while OpenHermes favours 0.6, 0.3 and 0.01. That makes β tuning essential. KTO remains attractive because it only needs thumbs-up/down labels rather than paired preferences, and configs and sweep scripts are published in the alignment-handbook.
- TRL v1.0: Post-Training Library Built to Move with the Field
Hugging Face mediumAdeptTRL v1.0 turns Hugging Face's post-training codebase, now covering 75+ methods and downloaded 3M times a month, into a library with an explicit stability contract. A semver-governed stable core (SFT, DPO, reward modeling, RLOO, GRPO trainers) sits alongside a fast-moving trl.experimental namespace. Methods are promoted based on the ratio of usage to maintenance cost. Because post-training paradigms keep shifting (PPO to DPO to RLVR/GRPO), the design deliberately avoids shared base classes and generic abstractions and accepts near line-for-line duplication between trainers like RLOO and GRPO, illustrated by the failed Judge abstraction. A comparison against OpenRLHF, veRL, PRIME-RL, Tinker, LLaMA-Factory and others positions TRL as broad, low-infrastructure and stable but lacking native tensor parallelism, with asynchronous GRPO planned next.
- Vision Language Models Explained
Hugging Face mediumAdeptVision language models combine an image encoder, a projector that aligns image features with text embeddings, and a text decoder that generates text from both inputs. LLaVA trains in two stages: first only the projector with the encoder and decoder frozen, then the projector together with an unfrozen decoder. KOSMOS-2 instead trains end to end, and Fuyu-8B skips the image encoder entirely. The guide compares open VLMs by license, size and resolution, explains model selection via Vision Arena, the Open VLM Leaderboard and benchmarks like MMMU and MMBench, then shows inference with transformers' LlavaNext and supervised fine-tuning of Llava 1.5 using TRL's new experimental VLM support in SFTTrainer.
- Putting RL back in RLHF
Hugging Face hardMasterRLOO (REINFORCE Leave-One-Out) is now available as a trainer in Hugging Face TRL. It is an online RLHF algorithm that drops PPO's value model. It treats the whole completion as a single action, uses the REINFORCE loss, and computes each sample's baseline as the mean reward of the other k−1 completions for the same prompt. That cuts vRAM by roughly 50-70% and makes training 2-3x faster than PPO on Pythia 1B and 6.9B, while matching PPO's GPT-4-judged win rate (78.7% for 6.9B on TL;DR) and beating DPO. Code walkthroughs show the advantage computation and that REINFORCE is a special case of the PPO loss. There is a caveat: bf16 numerical mismatches between generation and training logprobs hurt RLOO more than PPO.