A Dive into Vision-Language Models
Vision-language models pair an image encoder and a text encoder with a strategy for fusing the two, and the pre-training objective determines which downstream tasks they handle well. The main families are contrastive learning (CLIP, ALIGN, LiT), PrefixLM and frozen PrefixLM (SimVLM, Frozen, ClipCap, Flamingo), cross-attention fusion into language model layers (VisualGPT, FIBER), combined masked-language modeling and image-text matching (VisualBERT, FLAVA), and training-free methods (MaGiC, ASIF). Frozen-backbone approaches let teams train with limited aligned image-text data, while PrefixLM-only models are mostly limited to captioning and VQA. The post also surveys common pre-training datasets and shows how to experiment with these models in 🤗 Transformers.
Related posts
- 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.
- Zero-shot image-to-text generation with BLIP-2
Hugging Face mediumAdeptBLIP-2 connects a frozen pre-trained image encoder (ViT) to a frozen LLM (OPT or Flan-T5) through a lightweight Querying Transformer (Q-Former), the only trainable component. This cuts trainable parameters and pre-training cost while reaching state-of-the-art results on visual-language tasks. Q-Former is pre-trained in two stages. The first uses image-text contrastive, image-grounded generation and image-text matching losses. The second feeds its query outputs to the LLM as a visual prefix under a causal LM loss. Code examples with Hugging Face Transformers show zero-shot image captioning, prompted captioning, visual question answering with a "Question: Answer:" template, and chat-style prompting, which must stay within the 512-token context.
- SigLIP 2: A better multilingual vision language encoder
Hugging Face mediumAdeptSigLIP 2 is Google's new family of multilingual vision-language encoders that extends SigLIP's sigmoid loss with extra training objectives. These are a text decoder for captioning and region grounding, plus self-distillation with global-local and masked-prediction losses added after 80% of training. Together they improve localization and dense features, and the models outperform SigLIP at every scale on zero-shot classification, retrieval and VLM transfer. New releases include a 1B giant size and NaFlex dynamic-resolution variants that preserve native aspect ratios, along with transformers code for zero-shot classification and image embedding.
- 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.
- PaliGemma – Google's Cutting-Edge Open Vision Language Model
Hugging Face mediumAdeptPaliGemma is Google's open vision-language model family that pairs a SigLIP-So400m image encoder with a Gemma-2B text decoder through a linear projector. It ships as pretrained, mix and task-specific fine-tuned checkpoints at 224, 448 and 896 resolutions. Behaviour is steered with task prefixes such as "detect" and "segment", and detections come back as <loc> tokens normalized to 1024. Images become 256 to 4096 prefix tokens with full attention over the image and prompt, so higher resolutions cost much more memory while helping mainly fine-grained tasks like OCR. The post includes transformers code for inference, 4-bit loading, and fine-tuning the decoder with full training or QLoRA, plus big_vision transfer configs.