dhirajjoshi116 pengyuan commited on
Commit
da6bbd9
·
verified ·
1 Parent(s): 9207f14

Create README.md (#1)

Browse files

- Create README.md (c39846b47352b030a9f593de19d8af18777c1f90)


Co-authored-by: Pengyuan Li <[email protected]>

Files changed (1) hide show
  1. README.md +183 -3
README.md CHANGED
@@ -1,3 +1,183 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ base_model:
6
+ - ibm-granite/granite-3.1-2b-instruct
7
+ library_name: transformers
8
+ ---
9
+ # granite-vision-3.2-2b
10
+
11
+ **Model Summary:**
12
+ granite-vision-3.2-2b is a compact and efficient vision-language model, specifically designed for visual document understanding, enabling automated content extraction from tables, charts, infographics, plots, diagrams, and more. The model was trained on a meticulously curated instruction-following dataset, comprising diverse public datasets and synthetic datasets tailored to support a wide range of document understanding and general image tasks. It was trained by fine-tuning a Granite large language model (https://huggingface.co/ibm-granite/granite-3.1-2b-instruct) with both image and text modalities.
13
+
14
+
15
+ **Evaluations:**
16
+
17
+ We evaluated Granite Vision 3.2 alongside other vision-language models (VLMs) in the 1B-4B parameter range using the standard llms-eval benchmark. The evaluation spanned multiple public benchmarks, with particular emphasis on document understanding tasks while also including general visual question-answering benchmarks.
18
+
19
+ | | Molmo-E | InternVL2 | Phi3v | Phi3.5v | Granite Vision |
20
+ |-----------|--------------|----------------|-------------|------------|------------|
21
+ | **Document benchmarks** |
22
+ | DocVQA | 0.66 | 0.87 | 0.87 | **0.88** | **0.88** |
23
+ | ChartQA | 0.60 | 0.75 | 0.81 | 0.82 | **0.86** |
24
+ | TextVQA | 0.62 | 0.72 | 0.69 | 0.7 | **0.76** |
25
+ | AI2D | 0.63 | 0.74 | **0.79** | **0.79** | 0.78 |
26
+ | InfoVQA | 0.44 | 0.58 | 0.55 | 0.61 | **0.63** |
27
+ | OCRBench | 0.65 | **0.75** | 0.64 | 0.64 | **0.75** |
28
+ | LiveXiv VQA | 0.47 | 0.51 | **0.61** | - | **0.61** |
29
+ | LiveXiv TQA | 0.36 | 0.38 | 0.48 | - | **0.55** |
30
+ | **Other benchmarks** |
31
+ | MMMU | 0.32 | 0.35 | 0.42 | **0.44** | 0.35 |
32
+ | VQAv2 | 0.57 | 0.75 | 0.76 | 0.77 | **0.81** |
33
+ | RealWorldQA | 0.55 | 0.34 | 0.60 | 0.58 | **0.65** |
34
+ | VizWiz VQA | 0.49 | 0.46 | 0.57 | 0.57 | **0.64** |
35
+ | OK VQA | 0.40 | 0.44 | 0.51 | 0.53 | **0.57** |
36
+
37
+
38
+ - **Paper:** [Granite Vision: a lightweight, open-source multimodal model for enterprise Intelligence](https://arxiv.org/abs/2502.09927)
39
+ - **Release Date**: Feb 26th, 2025
40
+ - **License:** [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
41
+
42
+ **Supported Languages:**
43
+ English
44
+
45
+ **Intended Use:**
46
+ The model is intended to be used in enterprise applications that involve processing visual and text data. In particular, the model is well-suited for a range of visual document understanding tasks, such as analyzing tables and charts, performing optical character recognition (OCR), and answering questions based on document content. Additionally, its capabilities extend to general image understanding, enabling it to be applied to a broader range of business applications. For tasks that exclusively involve text-based input, we suggest using our Granite large language models, which are optimized for text-only processing and offer superior performance compared to this model.
47
+
48
+
49
+ ## Generation:
50
+
51
+ Granite Vision model is supported natively `transformers>=4.49`. Below is a simple example of how to use the `granite-vision-3.2-2b` model.
52
+
53
+ ### Usage with `transformers`
54
+
55
+ First, make sure to build the latest verions of transormers:
56
+ ```shell
57
+ pip install transformers>=4.49
58
+ ```
59
+
60
+ Then run the code:
61
+ ```python
62
+ from transformers import AutoProcessor, AutoModelForVision2Seq
63
+ from huggingface_hub import hf_hub_download
64
+ import torch
65
+
66
+ device = "cuda" if torch.cuda.is_available() else "cpu"
67
+
68
+ model_path = "ibm-granite/granite-vision-3.2-2b"
69
+ processor = AutoProcessor.from_pretrained(model_path)
70
+ model = AutoModelForVision2Seq.from_pretrained(model_path).to(device)
71
+
72
+ # prepare image and text prompt, using the appropriate prompt template
73
+
74
+ img_path = hf_hub_download(repo_id=model_path, filename='example.png')
75
+
76
+ conversation = [
77
+ {
78
+ "role": "user",
79
+ "content": [
80
+ {"type": "image", "url": img_path},
81
+ {"type": "text", "text": "What is the highest scoring model on ChartQA and what is its score?"},
82
+ ],
83
+ },
84
+ ]
85
+ inputs = processor.apply_chat_template(
86
+ conversation,
87
+ add_generation_prompt=True,
88
+ tokenize=True,
89
+ return_dict=True,
90
+ return_tensors="pt"
91
+ ).to(device)
92
+
93
+
94
+ # autoregressively complete prompt
95
+ output = model.generate(**inputs, max_new_tokens=100)
96
+ print(processor.decode(output[0], skip_special_tokens=True))
97
+ ```
98
+
99
+ ### Usage with vLLM
100
+
101
+ The model can also be loaded with `vLLM`. First make sure to install the following libraries:
102
+
103
+ ```shell
104
+ pip install torch torchvision torchaudio
105
+ pip install vllm==0.6.6
106
+ ```
107
+ Then, copy the snippet from the section that is relevant for your use case.
108
+
109
+ ```python
110
+ from vllm import LLM, SamplingParams
111
+ from vllm.assets.image import ImageAsset
112
+ from huggingface_hub import hf_hub_download
113
+ from PIL import Image
114
+
115
+ model_path = "ibm-granite/granite-vision-3.2-2b"
116
+
117
+ model = LLM(
118
+ model=model_path,
119
+ limit_mm_per_prompt={"image": 1},
120
+ )
121
+
122
+ sampling_params = SamplingParams(
123
+ temperature=0.2,
124
+ max_tokens=64,
125
+ )
126
+
127
+ # Define the question we want to answer and format the prompt
128
+ image_token = "<image>"
129
+ system_prompt = "<|system|>\nA chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.\n"
130
+
131
+ question = "What is the highest scoring model on ChartQA and what is its score?"
132
+ prompt = f"{system_prompt}<|user|>\n{image_token}\n{question}\n<|assistant|>\n"
133
+ img_path = hf_hub_download(repo_id=model_path, filename='example.png')
134
+ image = Image.open(img_path).convert("RGB")
135
+ print(image)
136
+
137
+ # Build the inputs to vLLM; the image is passed as `multi_modal_data`.
138
+ inputs = {
139
+ "prompt": prompt,
140
+ "multi_modal_data": {
141
+ "image": image,
142
+ }
143
+ }
144
+
145
+ outputs = model.generate(inputs, sampling_params=sampling_params)
146
+ print(f"Generated text: {outputs[0].outputs[0].text}")
147
+ ```
148
+
149
+ ### Fine-tuning
150
+
151
+ For an example of fine-tuning Granite Vision for new tasks refer to [this notebook](https://huggingface.co/learn/cookbook/en/fine_tuning_granite_vision_sft_trl).
152
+
153
+
154
+
155
+ **Model Architecture:**
156
+
157
+ The architecture of granite-vision-3.2-2b consists of the following components:
158
+
159
+ (1) Vision encoder: SigLIP (https://huggingface.co/docs/transformers/en/model_doc/siglip).
160
+
161
+ (2) Vision-language connector: two-layer MLP with gelu activation function.
162
+
163
+ (3) Large language model: granite-3.1-2b-instruct with 128k context length (https://huggingface.co/ibm-granite/granite-3.1-2b-instruct).
164
+
165
+ We built upon LLaVA (https://llava-vl.github.io) to train our model. We use multi-layer encoder features and a denser grid resolution in AnyRes to enhance the model's ability to understand nuanced visual content, which is essential for accurately interpreting document images.
166
+
167
+
168
+ **Training Data:**
169
+
170
+ Overall, our training data is largely comprised of two key sources: (1) publicly available datasets (2) internally created synthetic data targeting specific capabilities including document understanding tasks. A detailed attribution of datasets can be found in the [technical report](https://arxiv.org/abs/2502.09927).
171
+
172
+
173
+ **Infrastructure:**
174
+ We train Granite Vision using IBM's super computing cluster, Blue Vela, which is outfitted with NVIDIA H100 GPUs. This cluster provides a scalable and efficient infrastructure for training our models over thousands of GPUs.
175
+
176
+ **Ethical Considerations and Limitations:**
177
+ The use of Large Vision and Language Models involves risks and ethical considerations people must be aware of, including but not limited to: bias and fairness, misinformation, and autonomous decision-making. granite-vision-3.2-2b is not the exception in this regard. Although our alignment processes include safety considerations, the model may in some cases produce inaccurate, biased, or unsafe responses to user prompts. Additionally, it remains uncertain whether smaller models might exhibit increased susceptibility to hallucination in generation scenarios by copying text verbatim from the training dataset due to their reduced sizes and memorization capacities. This aspect is currently an active area of research, and we anticipate more rigorous exploration, comprehension, and mitigations in this domain. Regarding ethics, a latent risk associated with all Large Language Models is their malicious utilization. We urge the community to use granite-vision-3.2-2b with ethical intentions and in a responsible way. We recommend using this model for document understanding tasks, and note that more general vision tasks may pose higher inherent risks of triggering biased or harmful output.
178
+
179
+ **Resources**
180
+ - 📄 Read the full technical report [here](https://arxiv.org/abs/2502.09927)
181
+ - ⭐️ Learn about the latest updates with Granite: https://www.ibm.com/granite
182
+ - 🚀 Get started with tutorials, best practices, and prompt engineering advice: https://www.ibm.com/granite/docs/
183
+ - 💡 Learn about the latest Granite learning resources: https://ibm.biz/granite-learning-resources