HugoLaurencon commited on
Commit
7344bb1
·
verified ·
1 Parent(s): 6a10ffe

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +150 -140
README.md CHANGED
@@ -1,199 +1,209 @@
1
  ---
2
- library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
 
 
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
10
 
 
11
 
12
- ## Model Details
13
 
14
- ### Model Description
15
 
16
- <!-- Provide a longer summary of what this model is. -->
 
 
 
 
 
 
 
 
 
 
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
29
 
30
- <!-- Provide the basic links for the model. -->
 
 
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
 
36
- ## Uses
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
 
 
 
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
 
44
- [More Information Needed]
 
 
45
 
46
- ### Downstream Use [optional]
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
 
50
- [More Information Needed]
51
 
52
- ### Out-of-Scope Use
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
 
 
 
55
 
56
- [More Information Needed]
 
57
 
58
- ## Bias, Risks, and Limitations
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
 
 
 
61
 
62
- [More Information Needed]
 
 
 
63
 
64
- ### Recommendations
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
 
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
 
 
69
 
70
- ## How to Get Started with the Model
 
71
 
72
- Use the code below to get started with the model.
73
 
74
- [More Information Needed]
75
 
76
- ## Training Details
77
 
78
- ### Training Data
79
 
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
 
82
- [More Information Needed]
 
 
 
 
 
83
 
84
- ### Training Procedure
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
 
 
 
87
 
88
- #### Preprocessing [optional]
89
 
90
- [More Information Needed]
91
 
 
92
 
93
- #### Training Hyperparameters
 
 
 
 
 
 
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
 
97
- #### Speeds, Sizes, Times [optional]
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
 
101
- [More Information Needed]
 
 
102
 
103
- ## Evaluation
 
 
 
 
 
 
 
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
 
107
- ### Testing Data, Factors & Metrics
108
 
109
- #### Testing Data
110
 
111
- <!-- This should link to a Dataset Card if possible. -->
112
 
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
 
175
  **BibTeX:**
176
 
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
 
197
- ## Model Card Contact
198
 
199
- [More Information Needed]
 
1
  ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - HuggingFaceM4/OBELICS
5
+ - HuggingFaceM4/the_cauldron
6
+ - HuggingFaceM4/WebSight
7
+ - HuggingFaceM4/Docmatix
8
+ language:
9
+ - en
10
+ tags:
11
+ - multimodal
12
+ - vision
13
+ - image-text-to-text
14
  ---
15
 
16
+ <p align="center">
17
+ <img src="https://huggingface.co/HuggingFaceM4/idefics-80b/resolve/main/assets/IDEFICS.png" alt="Idefics-Obelics logo" width="200" height="100">
18
+ </p>
19
 
20
+ **Transformers version**, until the next Transformers pypi release, please install Transformers from source to be able to use Idefics3. TODO: change when new version.
21
 
22
+ # Idefics3
23
 
24
+ Idefics2 is an open multimodal model that accepts arbitrary sequences of image and text inputs and produces text outputs. The model can answer questions about images, describe visual content, create stories grounded on multiple images, or simply behave as a pure language model without visual inputs. It improves upon [Idefics1](https://huggingface.co/HuggingFaceM4/idefics-80b-instruct) and [Idefics2](https://huggingface.co/HuggingFaceM4/idefics2-8b), significantly enhancing capabilities around OCR, document understanding and visual reasoning.
25
 
26
+ We release the checkpoints under the Apache 2.0.
27
 
28
+ # Model Summary
29
 
30
+ - **Developed by:** Hugging Face
31
+ - **Model type:** Multi-modal model (image+text)
32
+ - **Language(s) (NLP):** en
33
+ - **License:** Apache 2.0
34
+ - **Parent Models:** [google/siglip-so400m-patch14-384](https://huggingface.co/google/siglip-so400m-patch14-384) and [meta-llama/Meta-Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct)
35
+ - **Resources for more information:**
36
+ - Idefics1 paper: [OBELICS: An Open Web-Scale Filtered Dataset of Interleaved Image-Text Documents
37
+ ](https://huggingface.co/papers/2306.16527)
38
+ - Idefics2 paper: [What matters when building vision-language models?
39
+ ](https://huggingface.co/papers/2405.02246)
40
+ - Idefics3 paper: Coming soon
41
 
42
+ # Uses
43
 
44
+ `Idefics3-8B` can be used to perform inference on multimodal (image + text) tasks in which the input is composed of a text query along with one (or multiple) image(s). Text and images can be arbitrarily interleaved. That includes image captioning, visual question answering, etc. These model does not support image generation.
 
 
 
 
 
 
45
 
46
+ The post-training of Idefics3-8B involves only a supervised fine-tuning stage, without RLHF alignment. As a result, the model may produce short answers or require prompt iterations to fully address the user's request. Adding a prefix to the assistant's response, such as "Let's fix this step by step" has been found to effectively influence the generated output.
47
 
48
+ To fine-tune `Idefics3-8B` on a specific task, we provide fine-tuning codes for Idefics2 that can be adapted (with almost no changes) to Idefics3:
49
+ - With the [TRL library](https://github.com/huggingface/trl): [Script](https://gist.github.com/edbeeching/228652fc6c2b29a1641be5a5778223cb)
50
+ - With the [Hugging Face Trainer](https://huggingface.co/docs/transformers/main/en/main_classes/trainer#api-reference%20][%20transformers.Trainer): [Tutorial notebook](https://colab.research.google.com/drive/1NtcTgRbSBKN7pYD3Vdx1j9m8pt3fhFDB?usp=sharing)
51
 
 
 
 
52
 
53
+ # Technical summary
54
 
55
+ Idefics3 demonstrates a net improvement over Idefics2, especially in document understanding tasks. It serves as a strong foundation for various use-case specific fine-tunings.
56
 
57
+ | Model | MMMU <br>(val) | MathVista <br>(test) | MMStar <br>(val) | DocVQA <br>(test) | TextVQA <br>(val) |
58
+ |:---------------:|:----------------:|:----------------------:|:-------------------:|:--------------------:|:-----------------:|
59
+ | **Idefics2-8B** | 45.2 | 52.2 | 49.5 | 74.0 | 73.0 |
60
+ | **Idefics3-8B** | 45.2 | 52.2 | 49.5 | 74.0 | 73.0 |
61
 
 
62
 
63
+ **Idefics2 introduces several changes compared to Idefics2:**
64
+ - We use 169 visual tokens to encode a image of size 364x364. Each image is divided into several sub images of sizes at most 364x364, which are then encoded separately.
65
+ - For the fine-tuning datasets, we have extended [The Cauldron](https://huggingface.co/datasets/HuggingFaceM4/the_cauldron) and added several datasets, including [Docmatix](HuggingFaceM4/Docmatix). We will push soon these datasets to the same repo of The Cauldron (TODO).
66
 
67
+ More details about the training of the model will be available in our upcoming technical report (TODO).
68
 
 
69
 
70
+ # How to Get Started
71
 
72
+ This section shows snippets of code for generation for `Idefics3-8B`.
73
 
74
+ ```python
75
+ import requests
76
+ import torch
77
+ from PIL import Image
78
+ from io import BytesIO
79
 
80
+ from transformers import AutoProcessor, AutoModelForVision2Seq
81
+ from transformers.image_utils import load_image
82
 
83
+ DEVICE = "cuda:0"
84
 
85
+ # Note that passing the image urls (instead of the actual pil images) to the processor is also possible
86
+ image1 = load_image("https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg")
87
+ image2 = load_image("https://cdn.britannica.com/59/94459-050-DBA42467/Skyline-Chicago.jpg")
88
+ image3 = load_image("https://cdn.britannica.com/68/170868-050-8DDE8263/Golden-Gate-Bridge-San-Francisco.jpg")
89
 
90
+ processor = AutoProcessor.from_pretrained("HuggingFaceM4/Idefics3-8B-Llama3")
91
+ model = AutoModelForVision2Seq.from_pretrained(
92
+ "HuggingFaceM4/Idefics3-8B-Llama3",
93
+ ).to(DEVICE)
94
 
95
+ # Create inputs
96
+ messages = [
97
+ {
98
+ "role": "user",
99
+ "content": [
100
+ {"type": "image"},
101
+ {"type": "text", "text": "What do we see in this image?"},
102
+ ]
103
+ },
104
+ {
105
+ "role": "assistant",
106
+ "content": [
107
+ {"type": "text", "text": "In this image, we can see the city of New York, and more specifically the Statue of Liberty."},
108
+ ]
109
+ },
110
+ {
111
+ "role": "user",
112
+ "content": [
113
+ {"type": "image"},
114
+ {"type": "text", "text": "And how about this image?"},
115
+ ]
116
+ },
117
+ ]
118
+ prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
119
+ inputs = processor(text=prompt, images=[image1, image2], return_tensors="pt")
120
+ inputs = {k: v.to(DEVICE) for k, v in inputs.items()}
121
 
 
122
 
123
+ # Generate
124
+ generated_ids = model.generate(**inputs, max_new_tokens=500)
125
+ generated_texts = processor.batch_decode(generated_ids, skip_special_tokens=True)
126
 
127
+ print(generated_texts)
128
+ ```
129
 
130
+ </details>
131
 
132
+ **Text generation inference**
133
 
134
+ TODO.
135
 
136
+ # Model optimizations
137
 
138
+ If your GPU allows, we first recommend loading (and running inference) in half precision (`torch.float16` or `torch.bfloat16`).
139
 
140
+ ```diff
141
+ model = AutoModelForVision2Seq.from_pretrained(
142
+ "HuggingFaceM4/Idefics3-8B-Llama3",
143
+ + torch_dtype=torch.bfloat16,
144
+ ).to(DEVICE)
145
+ ```
146
 
147
+ **Vision encoder efficiency**
148
 
149
+ You can choose the default resolution the images will be rescaled to by adding `size= {"longest_edge": N*364}` when initializing the processor (`AutoProcessor.from_pretrained`), with `N` your desired value.
150
+ `N=4` works best in practice (this is the default value), but for very large images, it could be interesting to pass `N=5`.
151
+ This will have an impact on the number of visual tokens passed to the language model.
152
+ If you are GPU-memory-constrained, you can decrease `N`, and choose for example `N=3` or `N=2`, especially for low resolution images.
153
 
154
+ **Using Flash-attention 2 to speed up generation**
155
 
156
+ <details><summary>Click to expand.</summary>
157
 
158
+ First, make sure to install `flash-attn`. Refer to the [original repository of Flash Attention](https://github.com/Dao-AILab/flash-attention) for the package installation. Simply change the snippet above with:
159
 
160
+ ```diff
161
+ model = AutoModelForVision2Seq.from_pretrained(
162
+ "HuggingFaceM4/Idefics3-8B-Llama3",
163
+ + torch_dtype=torch.bfloat16,
164
+ + _attn_implementation="flash_attention_2",
165
+ ).to(DEVICE)
166
+ ```
167
 
168
+ </details>
169
 
 
170
 
171
+ # Misuse and Out-of-scope use
172
 
173
+ Using the model in [high-stakes](https://huggingface.co/bigscience/bloom/blob/main/README.md#glossary-and-calculations) settings is out of scope for this model. The model is not designed for [critical decisions](https://huggingface.co/bigscience/bloom/blob/main/README.md#glossary-and-calculations) nor uses with any material consequences on an individual's livelihood or wellbeing. The model outputs content that appears factual but may not be correct. Out-of-scope uses include:
174
+ - Usage for evaluating or scoring individuals, such as for employment, education, or credit
175
+ - Applying the model for critical automatic decisions, generating factual content, creating reliable summaries, or generating predictions that must be correct
176
 
177
+ Intentionally using the model for harm, violating [human rights](https://huggingface.co/bigscience/bloom/blob/main/README.md#glossary-and-calculations), or other kinds of malicious activities, is a misuse of this model. This includes:
178
+ - Spam generation
179
+ - Disinformation and influence operations
180
+ - Disparagement and defamation
181
+ - Harassment and abuse
182
+ - [Deception](https://huggingface.co/bigscience/bloom/blob/main/README.md#glossary-and-calculations)
183
+ - Unconsented impersonation and imitation
184
+ - Unconsented surveillance
185
 
 
186
 
187
+ # License
188
 
189
+ The model is built on top of two pre-trained models: [google/siglip-so400m-patch14-384](https://huggingface.co/google/siglip-so400m-patch14-384) and [meta-llama/Meta-Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct). We release the Idefics3 checkpoints under the Apache 2.0 license.
190
 
 
191
 
192
+ # Citation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
 
194
  **BibTeX:**
195
 
196
+ ```bibtex
197
+ @misc{laurençon2024matters,
198
+ title={What matters when building vision-language models?},
199
+ author={Hugo Laurençon and Léo Tronchon and Matthieu Cord and Victor Sanh},
200
+ year={2024},
201
+ eprint={2405.02246},
202
+ archivePrefix={arXiv},
203
+ primaryClass={cs.CV}
204
+ }
205
+ ```
 
 
 
 
 
 
 
 
 
206
 
207
+ # Acknowledgements
208
 
209
+ We thank @amyeroberts for helping on the integration in Transformers.