Views
No views yet

| Epoch | Loss | Grad Norm | Learning Rate |
|---|---|---|---|
| 0.01 | 2.3776 | 10.40 | 4.8e-05 |
| 0.25 | 0.5029 | 6.10 | 9.5412e-05 |
| 0.50 | 0.434 | 5.74 | 7.5973e-05 |
| 0.75 | 0.4608 | 7.46 | 7.3925e-05 |
| 1.0 | 0.3846 | 4.77 | 5.0369e-05 |
| 1.25 | 0.3226 | 3.63 | 4.9857e-05 |
| 1.5 | 0.3175 | 5.03 | 2.5277e-05 |
| 1.75 | 0.2918 | 5.63 | 2.5789e-05 |
weights | per image | (val/test) | (testmini) | (val) | (test) | (test-dev) | (test) | ||
|---|---|---|---|---|---|---|---|---|---|
| DeepSeek-VL | ✅ | 7B | 576 | 36.6/- | 36.1 | 64.4 | 73.2 | - | 49.6 |
| LLaVa-NeXT-Mistral-7B | ✅ | 7B | 2880 | 35.3/- | 37.7 | 65.7 | 68.7 | 82.2 | - |
| LLaVa-NeXT-13B | ✅ | 13B | 2880 | 36.2/- | 35.3 | 67.1 | 70.0 | 82.8 | - |
| LLaVa-NeXT-34B | ✅ | 34B | 2880 | 51.1/44.7 | 46.5 | 69.5 | 79.3 | 83.7 | - |
| MM1-Chat-7B | ❌ | 7B | 720 | 37.0/35.6 | 35.9 | 72.8 | 72.3 | - | - |
| MM1-Chat-30B | ❌ | 30B | 720 | 44.7/40.3 | 39.4 | 73.5 | 75.1 | 83.7 | |
| Gemini 1.0 Pro | ❌ | 🤷♂️ | 🤷♂️ | 47.9/- | 45.2 | 74.6 | - | 71.2 | 88.1 |
| Gemini 1.5 Pro | ❌ | 🤷♂️ | 🤷♂️ | 58.5/- | 52.1 | 73.5 | - | 73.2 | 86.5 |
| Claude 3 Haiku | ❌ | 🤷♂️ | 🤷♂️ | 50.2/- | 46.4 | - | - | - | 88.8 |
| Idefics1 instruct (32-shots) | ✅ | 80B | - | - | - | 39.3 | - | 68.8 | - |
| Idefics2 (w/o im. split) | ✅ | 8B | 64 | 43.5/37.9 | 51.6 | 70.4 | 76.8 | 80.8 | 67.3 |
| Idefics2 (w/ im. split) | ✅ | 8B | 320 | 43.0/37.7 | 51.4 | 73.0 | 76.7 | 81.2 | 74.0 |
| Idefics2 DocVQA Finetuned (w/ im. split) | ✅ | 8B | 320 | 43.0/37.7 | 52.5 | 72.0 | 77.7 | 81.1 | 72.5 |
do_image_splitting=False when initializing the processor (AutoProcessor.from_pretrained). There are no changes required on the model side. Note that only the SFT model has been trained with image splitting.size={"longest_edge": 448, "shortest_edge": 378} when initializing the processor (AutoProcessor.from_pretrained). In particular, the longest_edge value can be adapted to fit the need (the default value is 980). We recommend using values that are multiples of 14. There are no changes required on the model side.do_image_splitting=True is especially needed to boost performance on OCR tasks where a very large image is used as input. For regular VQA or captioning tasks, this argument can be safely set to False with minimal impact on performance (see the evaluation table above).idefics2-8b-DocVQA-finetuned. Let's first define some common imports and inputs.1import requests
2import torch
3from PIL import Image
4from io import BytesIO
5
6from transformers import AutoProcessor, AutoModelForVision2Seq
7from transformers.image_utils import load_image
8
9DEVICE = "cuda:0"
10
11# Note that passing the image urls (instead of the actual pil images) to the processor is also possible
12image1 = load_image("https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg")
13image2 = load_image("https://cdn.britannica.com/59/94459-050-DBA42467/Skyline-Chicago.jpg")
14image3 = load_image("https://cdn.britannica.com/68/170868-050-8DDE8263/Golden-Gate-Bridge-San-Francisco.jpg")idefics2-8b-base1processor = AutoProcessor.from_pretrained("idefics2-8b-DocVQA-finetuned")
2model = AutoModelForVision2Seq.from_pretrained(
3 "Reverb/idefics2-8b-DocVQA-finetuned",
4).to(DEVICE)
5
6# Create inputs
7prompts = [
8 "<image>In this image, we can see the city of New York, and more specifically the Statue of Liberty.<image>In this image,",
9 "In which city is that bridge located?<image>",
10]
11images = [[image1, image2], [image3]]
12inputs = processor(text=prompts, images=images, padding=True, return_tensors="pt")
13inputs = {k: v.to(DEVICE) for k, v in inputs.items()}
14
15
16# Generate
17generated_ids = model.generate(**inputs, max_new_tokens=500)
18generated_texts = processor.batch_decode(generated_ids, skip_special_tokens=True)
19
20print(generated_texts)
21# ['In this image, we can see the city of New York, and more specifically the Statue of Liberty. In this image, we can see the city of Chicago, and more specifically the skyscrapers of the city.', 'In which city is that bridge located? The Golden Gate Bridge is a suspension bridge spanning the Golden Gate, the one-mile-wide (1.6 km) strait connecting San Francisco Bay and the Pacific Ocean. The structure links the American city of San Francisco, California — the northern tip of the San Francisco Peninsula — to Marin County, carrying both U.S. Route 101 and California State Route 1 across the strait. The bridge is one of the most internationally recognized symbols of San Francisco, California, and the United States. It has been declared one of the Wonders of the Modern World by the American Society of Civil Engineers.\n\nThe Golden Gate Bridge is a suspension bridge spanning the Golden Gate, the one-mile-wide (1.6 km) strait connecting San Francisco Bay and the Pacific Ocean. The structure links the American city of San Francisco, California — the northern tip of the San Francisco Peninsula — to Marin County, carrying both U.S. Route 101 and California State Route 1 across the strait. The bridge is one of the most internationally recognized symbols of San Francisco, California, and the United States. It has been declared one of the Wonders of the Modern World by the American Society of Civil Engineers.\n\nThe Golden Gate Bridge is a suspension bridge spanning the Golden Gate, the one-mile-wide (1.6 km) strait connecting San Francisco Bay and the Pacific Ocean. The structure links the American city of San Francisco, California — the northern tip of the San Francisco Peninsula — to Marin County, carrying both U.S. Route 101 and California State Route 1 across the strait. The bridge is one of the most internationally recognized symbols of San Francisco, California, and the United States. It has been declared one of the Wonders of the Modern World by the American Society of Civil Engineers.\n\nThe Golden Gate Bridge is a suspension bridge spanning the Golden Gate, the one-mile-wide (1.6 km) strait connecting San Francisco Bay and the Pacific Ocean. The structure links the American city of San Francisco, California — the northern tip of the San Francisco Peninsula — to Marin County, carrying both U.S. Route 101 and California State Route 1 across the strait. The bridge is one of the most internationally recognized symbols of San Francisco, California, and']) and no spaces are required before and after. The dialogue utterances can be separated with <end_of_utterance>\n followed by User: or Assistant:. User: is followed by a space if the following characters are real text (no space if followed by an image).torch.float16 or torch.bfloat16).1model = AutoModelForVision2Seq.from_pretrained(
2 "Reverb/idefics2-8b-DocVQA-finetuned",
3+ torch_dtype=torch.float16,
4).to(DEVICE)do_image_splitting=False when initializing the processor (AutoProcessor.from_pretrained). There are no changes required on the model side. Note that only the sft model has been trained with image splitting.size= {"longest_edge": 448, "shortest_edge": 378} when initializing the processor (AutoProcessor.from_pretrained). In particular, the longest_edge value can be adapted to fit the need (the default value is 980). We recommend using values that are multiples of 14. There are no changes required on the model side.do_image_splitting=True is especially needed to boost performance on OCR tasks where a very large image is used as input. For the regular VQA or captioning tasks, this argument can be safely set to False with minimal impact on performance (see the evaluation table above).flash-attn. Refer to the original repository of Flash Attention for the package installation. Simply change the snippet above with:1model = AutoModelForVision2Seq.from_pretrained(
2 "Reverb/idefics2-8b-DocVQA-finetuned",
3+ torch_dtype=torch.float16,
4+ _attn_implementation="flash_attention_2",
5).to(DEVICE)| Flash attention 2 | Image splitting | Float type | 4 bits quantization | Peak GPU memory (GB) | Time for 20 generations (secs) |
|---|---|---|---|---|---|
| No | Yes | fp32 | No | 54.9 | 55.6 |
| No | Yes | bf16 | No | 41.3 | 34.3 |
| No | Yes | fp16 | No | 36.7 | 33.3 |
| Yes | Yes | fp16 | No | 21.0 | 13.3 |
| Yes | Yes | fp16 | bitsandbytes (entire model) | 8.9 | 19.9 |
| No | Yes | fp16 | bitsandbytes (entire model) | 24.7 | 40.4 |
| No | Yes | fp16 | AWQ (LLM only) | 26.4 | 37.1 |
| Yes | Yes | fp16 | AWQ (LLM only) | 10.7 | 16.3 |
| No | Yes | fp16 | AWQ + fusing (LLM only) | 26.0 | 38.4 |
| No | No | fp32 | No | 38.8 | 17.5 |
| No | No | bf16 | No | 22.2 | 14.4 |
| No | No | fp16 | No | 21.3 | 13.9 |
| Yes | No | fp16 | No | 18.1 | 10.4 |
| Yes | No | fp16 | bitsandbytes (entire model) | 6.0 | 17.3 |
| No | No | fp16 | bitsandbytes (entire model) | 9.2 | 20.9 |
| No | No | fp16 | AWQ (LLM only) | 10.9 | 15.9 |
| Yes | No | fp16 | AWQ (LLM only) | 7.8 | 12.3 |
| No | No | fp16 | AWQ + fusing (LLM only) | 10.5 | 19.5 |
Does this X-ray show any medical problems? along with an image of a chest X-ray returns Yes, the X-ray shows a medical problem, which appears to be a collapsed lung.. We discourage users from using the model on medical applications without proper adaptation and evaluation.1@misc{laurencon2023obelics,
2 title={OBELICS: An Open Web-Scale Filtered Dataset of Interleaved Image-Text Documents},
3 author={Hugo Laurençon and Lucile Saulnier and Léo Tronchon and Stas Bekman and Amanpreet Singh and Anton Lozhkov and Thomas Wang and Siddharth Karamcheti and Alexander M. Rush and Douwe Kiela and Matthieu Cord and Victor Sanh},
4 year={2023},
5 eprint={2306.16527},
6 archivePrefix={arXiv},
7 primaryClass={cs.IR}
8}
9
10@misc{laurençon2024matters,
11 title={What matters when building vision-language models?},
12 author={Hugo Laurençon and Léo Tronchon and Matthieu Cord and Victor Sanh},
13 year={2024},
14 eprint={2405.02246},
15 archivePrefix={arXiv},
16 primaryClass={cs.CV}
17}