---
title: "Preference Optimization for Vision Language Models"
description: "TRL now supports direct preference optimization (DPO) for vision language models, trained on chosen/rejected answer pairs rather than fixed labels."
url: "https://swe.quest/articles/preference-optimization-for-vision-language-models-a84799e96613bf21"
canonical: "https://huggingface.co/blog/dpo_vlm"
source: "Hugging Face"
published: "2024-07-10"
difficulty: "hard"
kind: "How-to"
reading_minutes: 11
tags: ["model-training","computer-vision","llms","python"]
---

# Preference Optimization for Vision Language Models

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2024-07-10, 11 min read, How-to. Original: [https://huggingface.co/blog/dpo\_vlm](https://huggingface.co/blog/dpo_vlm)

## Summary

TRL 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.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Computer vision](https://swe.quest/tags/computer-vision.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- LLM fine-tuning basics ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))
- PyTorch and Hugging Face Transformers
- GPU memory constraints ([easy posts on Hardware](https://swe.quest/tags/hardware.md?difficulty=easy))

## Keywords

TRL, DPO, Idefics2, LoRA, PEFT, RLAIF-V, bfloat16

## Related posts

- [Vision Language Model Alignment in TRL ⚡️](https://swe.quest/articles/vision-language-model-alignment-in-trl-e64e05c10318c68f.md): Hugging Face · 2025-08-07 · Hard · 12 min read · Model training, LLMs, Computer vision, Python
  TRL adds vision language model support for several alignment methods.
- [Vision Language Models Explained](https://swe.quest/articles/vision-language-models-explained-92cc71897cd36570.md): Hugging Face · 2024-04-11 · Medium · 8 min read · Computer vision, LLMs, Model training, Evaluation, Python
  Vision 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.
- [Fine-tune Llama 2 with DPO](https://swe.quest/articles/fine-tune-llama-2-with-dpo-68d2e917aae1caca.md): Hugging Face · 2023-08-08 · Hard · 7 min read · Model training, LLMs, Python
  Direct Preference Optimization (DPO) replaces the reward-model and RL steps of RLHF with a simple binary cross-entropy loss over preference pairs, using a frozen reference model to provide an implicit reward.
- [LoRA training scripts of the world, unite!](https://swe.quest/articles/lora-training-scripts-of-the-world-unite-73f0d15365f25313.md): Hugging Face · 2024-01-02 · Hard · 18 min read · Model training, Computer vision, Machine learning
  Combining Pivotal Tuning (textual inversion of newly inserted tokens, then LoRA fine-tuning) with the adaptive Prodigy optimizer produces strong SDXL Dreambooth LoRA results, and both are now available in a diffusers training script.
- [Finetune Stable Diffusion Models with DDPO via TRL](https://swe.quest/articles/finetune-stable-diffusion-models-with-ddpo-via-trl-08d1757d4cd09bc2.md): Hugging Face · 2023-09-29 · Hard · 9 min read · Model training, Computer vision, Machine learning, Python
  Denoising Diffusion Policy Optimization (DDPO) fine-tunes diffusion models with reinforcement learning by treating the full denoising process as a multistep MDP.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
