---
title: "Fine-tuning Florence-2 - Microsoft's Cutting-edge Vision Language Models"
description: "Florence-2, Microsoft's small (0.2B/0.7B) sequence-to-sequence vision-language model built from a DaViT encoder, BERT text embeddings and an encoder-decoder transformer pre-trained on the 126M-image FLD-5B dataset, can be fine-tuned to handle visual question answering, a task the released checkpoints don't support."
url: "https://swe.quest/articles/fine-tuning-florence-2-microsoft-s-cutting-edge-vision-language-models-184087851c31370f"
canonical: "https://huggingface.co/blog/finetune-florence2"
source: "Hugging Face"
published: "2024-06-24"
difficulty: "medium"
kind: "How-to"
reading_minutes: 6
tags: ["model-training","computer-vision","python"]
---

# Fine-tuning Florence-2 - Microsoft's Cutting-edge Vision Language Models

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2024-06-24, 6 min read, How-to. Original: [https://huggingface.co/blog/finetune-florence2](https://huggingface.co/blog/finetune-florence2)

## Summary

Florence-2, Microsoft's small (0.2B/0.7B) sequence-to-sequence vision-language model built from a DaViT encoder, BERT text embeddings and an encoder-decoder transformer pre-trained on the 126M-image FLD-5B dataset, can be fine-tuned to handle visual question answering, a task the released checkpoints don't support. Fine-tuning on DocVQA for seven epochs raised validation Levenshtein similarity from 0 to 57.0. The low-resource setup froze the vision encoder and used batch size 6 on a single A100 (or 1 on a T4), while a full fine-tune at batch size 64 took 70 minutes on 8 H100s. A small learning rate of 1e-6 avoided rapid overfitting, and a PyTorch walkthrough covers the dataset, collator and training loop.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

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

## Prerequisites

- PyTorch training loops ([easy posts on Model training](https://swe.quest/tags/model-training.md?difficulty=easy))
- Hugging Face transformers
- transformer encoder-decoder basics

## Keywords

Florence-2, DocVQA, Hugging Face transformers, DaViT, FLD-5B, PyTorch

## Related posts

- [Docmatix - a huge dataset for Document Visual Question Answering](https://swe.quest/articles/docmatix-a-huge-dataset-for-document-visual-question-answering-acf1e0919e3f7459.md): Hugging Face · 2024-07-18 · Medium · 4 min read · Computer vision, Model training, LLMs
  Docmatix is a Document Visual Question Answering dataset with 2.4 million images and 9.5 million Q/A pairs drawn from 1.3 million PDFs, roughly 240x larger than earlier DocVQA datasets.
- [Preference Optimization for Vision Language Models](https://swe.quest/articles/preference-optimization-for-vision-language-models-a84799e96613bf21.md): Hugging Face · 2024-07-10 · Hard · 11 min read · Model training, Computer vision, LLMs, Python
  TRL now supports direct preference optimization (DPO) for vision language models, trained on chosen/rejected answer pairs rather than fixed labels.
- [Zero-shot image-to-text generation with BLIP-2](https://swe.quest/articles/zero-shot-image-to-text-generation-with-blip-2-6253370fee81620e.md): Hugging Face · 2023-02-15 · Medium · 7 min read · Computer vision, LLMs, Machine learning, Python
  BLIP-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.
- [A Dive into Vision-Language Models](https://swe.quest/articles/a-dive-into-vision-language-models-1c708a70976bf2ac.md): Hugging Face · 2023-02-03 · Hard · 18 min read · Computer vision, Model training, Machine learning, LLMs
  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.
- [PaliGemma – Google's Cutting-Edge Open Vision Language Model](https://swe.quest/articles/paligemma-google-s-cutting-edge-open-vision-language-model-eb2d13e0b9bcd3ec.md): Hugging Face · 2024-05-14 · Medium · 11 min read · Computer vision, LLMs, Model training, Inference & serving, Python
  PaliGemma 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.

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)
