Model reference · open weights
Florence-2-large is an open-weight language model from microsoft. Florence-2-large (FP16) weighs 1.6 GB; the smallest configuration that runs it is RTX 3060 12 GB.
Summary of the microsoft/Florence-2-large model card, 2026-10-01
What it is
| Released by | microsoft |
|---|---|
| Released | 2024-06-15 |
| Parameters | 777M |
| VRAM | 1.6 GB for the weights |
What it runs on
How much memory each request adds isn't estimated yet for this architecture. The weights need at least the cards below, plus room for the context.
| Card | Weights alone |
|---|---|
| RTX 3060 12 GB | fits |
| RTX 4060 Ti 16 GB | fits |
| RTX 3090 24 GB | fits |
| RTX 4090 24 GB | fits |
| RTX 5090 32 GB | fits |
| L40S 48 GB | fits |
| A100 80 GB | fits |
| H100 80 GB | fits |
| RTX PRO 6000 Blackwell 96 GB | fits |
| DGX Spark (GB10) 128 GB unified | fits |
| H200 141 GB | fits |
| B200 180 GB | fits |
From the model card
This is a continued pretrained version of Florence-2-large model with 4k context length, only 0.1B samples are used for continue pretraining, thus it might not be trained well. In addition, OCR task has been updated with line separator ('\n'). COCO OD AP 39.8
This Hub repository contains a HuggingFace's transformers implementation of Florence-2 model from Microsoft.
Florence-2 is an advanced vision foundation model that uses a prompt-based approach to handle a wide range of vision and vision-language tasks. Florence-2 can interpret simple text prompts to perform tasks like captioning, object detection, and segmentation. It leverages our FLD-5B dataset, containing 5.4 billion annotations across 126 million images, to master multi-task learning. The model's sequence-to-sequence architecture enables it to excel in both zero-shot and fine-tuned settings, proving to be a competitive vision foundation model.
Resources and Technical Documentation:
| Model | Model size | Model Description |
|---|---|---|
| Florence-2-base[HF] | 0.23B | Pretrained model with FLD-5B |
| Florence-2-large[HF] | 0.77B | Pretrained model with FLD-5B |
| Florence-2-base-ft[HF] | 0.23B | Finetuned model on a colletion of downstream tasks |
| Florence-2-large-ft[HF] | 0.77B | Finetuned model on a colletion of downstream tasks |
Use the code below to get started with the model. All models are trained with float16.
import requests
import torch
from PIL import Image
from transformers import AutoProcessor, AutoModelForCausalLM
device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-large", torch_dtype=torch_dtype, trust_remote_code=True).to(device)
processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large", trust_remote_code=True)
prompt = ""
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
image = Image.open(requests.get(url, stream=True).raw)
inputs = processor(text=prompt, images=image, return_tensors="pt").to(device, torch_dtype)
generated_ids = model.generate(
input_ids=inputs["input_ids"],
pixel_values=inputs["pixel_values"],
max_new_tokens=4096,
num_beams=3,
do_sample=False
)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
parsed_answer = processor.post_process_generation(generated_text, task="", image_size=(image.width, image.height))
print(parsed_answer)
This model is capable of performing different tasks through changing the prompts.
First, let's define a function to run a prompt.
import requests
import torch
from PIL import Image
from transformers import AutoProcessor, AutoModelForCausalLM
device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-large", torch_dtype=torch_dtype, trust_remote_code=True).to(device)
processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large", trust_remote_code=True)
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
image = Image.open(requests.get(url, stream=True).raw)
def run_example(task_prompt, text_input=None):
if text_input is None:
prompt = task_prompt
else:
prompt = task_prompt + text_input
inputs = processor(text=prompt, images=image, return_tensors="pt").to(device, torch_dtype)
generated_ids = model.generate(
input_ids=inputs["input_ids"],
pixel_values=inputs["pixel_values"],
max_new_tokens=1024,
num_beams=3
)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
parsed_answer = processor.post_process_generation(generated_text, task=task_prompt, image_size=(image.width, image.height))
print(parsed_answer)
Here are the tasks Florence-2 could perform:
prompt = ""
run_example(prompt)
prompt = ""
run_example(prompt)
prompt = ""
run_example(prompt)
caption to phrase grounding task requires additional text input, i.e. caption.
Caption to phrase grounding results format: {'': {'bboxes': [[x1, y1, x2, y2], ...], 'labels': ['', '', ...]}}
task_prompt = ""
results = run_example(task_prompt, text_input="A green car parked in front of a yellow building.")
OD results format: {'': {'bboxes': [[x1, y1, x2, y2], ...], 'labels': ['label1', 'label2', ...]} }
prompt = ""
run_example(prompt)
Dense region caption results format: {'' : {'bboxes': [[x1, y1, x2, y2], ...], 'labels': ['label1', 'label2', ...]} }
prompt = ""
run_example(prompt)
Dense region caption results format: {'': {'bboxes': [[x1, y1, x2, y2], ...], 'labels': ['', '', ...]}}
prompt = ""
run_example(prompt)
prompt = ""
run_example(prompt)
OCR with region output format: {'': {'quad_boxes': [[x1, y1, x2, y2, x3, y3, x4, y4], ...], 'labels': ['text1', ...]}}
prompt = ""
run_example(prompt)
Quoted from the model card on Hugging Face. The full card is behind the Hugging Face link above.