khang119966 commited on
Commit
9c1902b
1 Parent(s): 4757622

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +254 -184
README.md CHANGED
@@ -1,199 +1,269 @@
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
  library_name: transformers
3
+ license: apache-2.0
4
+ language:
5
+ - vi
6
+ - en
7
+ - zh
8
+ base_model:
9
+ - Qwen/Qwen2.5-32B-Instruct
10
+ - OpenGVLab/InternViT-300M-448px
11
+ pipeline_tag: visual-question-answering
12
  ---
13
+ ## Vintern-3B-beta ❄️ - The LLaVA 🌋 Challenger
14
 
15
+ **What's new in Vintern-3B-beta!**
16
+ - **We successfully reproduced the training process of InternVL from scratch.**
17
+ - The model is the result of integrating [Qwen/Qwen2.5-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-3B-Instruct) and [InternViT-300M-448px](https://huggingface.co/OpenGVLab/InternViT-300M-448px) through an MLP layer.
18
+ - Trained with more than 10 Milion Vietnamese QnAs, Descriptions, and 10% English Data from [OpenGVLab/InternVL-Chat-V1-2-SFT-Data](https://huggingface.co/datasets/OpenGVLab/InternVL-Chat-V1-2-SFT-Data).
 
19
 
20
  ## Model Details
21
 
22
+ | Model Name | Vision Part | Language Part |
23
+ | :------------------: | :---------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------: |
24
+ | Vintern-3B-beta | [InternViT-300M-448px](https://huggingface.co/OpenGVLab/InternViT-300M-448px) | [Qwen2.5-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-3B-Instruct) |
25
+
26
+
27
+ ## Bytedance/MTVQA Benchmark
28
+
29
+ We surpassed GPT-4o and are approaching Gemini 1.5 Pro on the MTVQA dataset for Vietnamese.
30
+ The benchmark result in [MTVQA](https://github.com/bytedance/MTVQA/tree/main) from [open_vlm_leaderboard](https://huggingface.co/spaces/opencompass/open_vlm_leaderboard).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
+ | Rank | Method | Param (B) | Language Model | Vision Model | VI |
33
+ |:----:|:----------------------------|:---------:|:---------------------------|:---------------------:|:------:|
34
+ | 1 | Gemini-1.5-Pro | | | | 41.3 |
35
+ | 2 | **Vintern-3B-beta** | **3** | **Qwen2.5-3B-Instruct** | **InternViT-300M** | **41.289** |
36
+ | 2 | GPT-4o (0513, detail-h...) | | | | 39.6 |
37
+ | 3 | GPT-4o (0806, detail-h...) | | | | 38.9 |
38
+ | 4 | Gemini-1.5-Flash | | | | 38.9 |
39
+ | 5 | Qwen-VL-Max-0809 | 72 | Qwen2-72B | ViT-600M | 36.9 |
40
+ | 6 | GPT-4o (0513, detail-lo...) | | | | 26.1 |
41
+ | 7 | Qwen-VL-Plus-0809 | | | | 27.8 |
42
+ | 8 | GLM-4v-9B | 9 | GLM-4-9B | EVA-02-5B | 26.6 |
43
+ | 9 | InternVL2-Llama3-76B | 76 | Llama-3-70B-Instruct | InternViT-6B | 26.7 |
44
+ | 10 | Step-1.5V | | Step-1.5 | stepencoder | 18.4 |
45
+ | 11 | InternVL2-40B | 40 | Nous-Hermes-2-Yi-34B | InternViT-6B | 21.2 |
46
+ | 12 | Pixtral-12B | 13 | Nemo-12B | ViT-400M | 19.7 |
47
 
 
48
 
49
+ ## Zalo VMLU Benchmark
50
+ The Vintern-3B-beta achieved a score of **52.98** on the Zalo VMLU Benchmark.
51
+ <div align="center">
52
+ <img src="vmlu_score.png" width="700"/>
53
+ </div>
54
 
55
+ ```
56
+ generation_config = dict(max_new_tokens= 64, do_sample=False, num_beams = 1, repetition_penalty=3.5)
57
+ question = "Bạn là thầy giáo giải trắc nghiệm rất chính xác. Bạn biết chắc chắn đáp án đúng nhất. Chỉ đưa ra chữ cái đứng trước câu trả lời đúng của câu hỏi trắc nghiệm sau: Một doanh nghiệp có vốn đầu tư nước ngoài có trụ sở chính ở Việt Nam, thì: Lựa Chọn: A. Được ĐKDN và HĐKD theo pháp luật Việt Nam B. Được ĐKDN và HĐKD theo pháp luật nước ngoài C. Được ĐKDN và HĐKD theo pháp luật Việt Nam và pháp luật nước ngoài tùy theo từng vấn đề cụ thể D. Cả A, B và C đều sai"
58
+ model.chat(tokenizer, None, question, generation_config)
59
+ ```
60
 
61
+ ## open_vlm_leaderboard Benchmark
62
 
63
+ We are creating a pull request for the OpenCompass team to test once more and make the metrics public on the [open_vlm_leaderboard](https://huggingface.co/spaces/opencompass/open_vlm_leaderboard)..
64
+ The current metrics are at an acceptable level, and we are expanding the training set in English and other languages to approach global models within a comparable parameter range.
65
 
66
+ "The table is referenced from the repo [Qwen/Qwen2-VL-2B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-2B-Instruct)."
67
 
68
+ | Benchmark | InternVL2-2B | MiniCPM-V 2.0 | Qwen2-VL-2B | Vintern-3B-beta |
69
+ |:-----------------|:------------:|:-------------:|:-----------:|:---------------:|
70
+ | MMMUval | 36.3 | 38.2 | 41.1 | 43.55 |
71
+ | DocVQAtest | 86.9 | - | 90.1 | 80.47 |
72
+ | InfoVQAtest | 58.9 | - | 65.5 | 48.28 |
73
+ | ChartQAtest | 76.2 | - | 73.5 | 68.32 |
74
+ | TextVQAval | 73.4 | - | 79.7 | 67.09 |
75
+ | OCRBench | 781 | 605 | 794 | 619 |
76
+ | MTVQA | - | - | 20.0 | 23.58 |
77
+ | RealWorldQA | 57.3 | 55.8 | 62.9 | 57.9 |
78
+ | MMEsum | 1876.8 | 1808.6 | 1872.0 | 1772.9 |
79
+ | MMBench-ENtest | 73.2 | 69.1 | 74.9 | 70.62 |
80
+ | MMStar | 49.8 | 39.1 | 48.0 | 43.2 |
81
+ | HallBenchavg | 38.0 | 36.1 | 41.7 | 64.98 |
82
+ | MathVistatestmini| 46.0 | 39.8 | 43.0 | 43.9 |
83
+
84
+
85
+ <!-- ## VLSP2023: ViVRC Challenge Benchmark
86
+
87
+ | **Name** | **F1** |
88
+ |:----------------------:|:-----------:|
89
+ | ICNLP | 3.6384 |
90
+ | **Vintern-4B-v1** | 3.5514 |
91
+ | **Vintern-3B-beta** | **3.5266** |
92
+ | **Vintern-1B-v2** | 3.4616 |
93
+ | linh | 3.4293 |
94
+ | DS@ViVRC | 3.4121 |
95
+ | DS@UIT Dynasty | 3.3172 |
96
+ | NTQ Solution | 3.2926 |
97
+ | I, Me & Myself | 3.2396 |
98
+ | AVQA_AIO | 2.9018 |
99
+ | **Vintern-1B-v1** | 2.7256 |
100
+ | NguyenLe | 2.7053 |
101
+ | nowj2 | 1.6808 | -->
102
+
103
+
104
+ <!-- ## Examples
105
+
106
+ <div align="center">
107
+ <img src="https://drscdn.500px.org/photo/1100852428/q%3D90_m%3D2048/v2?sig=7a6df43806315966517e2506394d71561f113321e0a4efc7d442e7303b5e97c7" width="400"/>
108
+ </div>
109
+
110
+ ```
111
+
112
+ ```
113
+
114
+ <div align="center">
115
+ <img src="https://drscdn.500px.org/photo/1100852641/q%3D90_m%3D2048/v2?sig=aba53dbde6a7e50d6c3d45289d47145c1a2c5c6708e3fb4b6fad721d4fc8a195" width="400"/>
116
+ </div>
117
+
118
+ ```
119
+
120
+ ```
121
+
122
+ <div align="center">
123
+ <img src="https://drscdn.500px.org/photo/1100852792/q%3D90_m%3D2048/v2?sig=d88c04be7beee1eebca7081251c11d0daeafa558bee0aa8a6fd3103b1556c5f5" width="400"/>
124
+ </div>
125
+
126
+ ```
127
+
128
+ ```
129
+
130
+ <div align="center">
131
+ <img src="https://drscdn.500px.org/photo/1100854004/q%3D90_m%3D2048/v2?sig=98a4d4f1fbbaec8994c71daed7a72d14d771bdbce481a91583b5955336bc08dd" width="400"/>
132
+ </div>
133
+
134
+ ```
135
+
136
+ ```
137
+
138
+ <div align="center">
139
+ <img src="https://drscdn.500px.org/photo/1100854109/q%3D90_m%3D2048/v2?sig=192a484e7207aafd7b827b1b42ceb24fdb740e2f6aab15cec21bd64ce0268d15" width="400"/>
140
+ </div>
141
+
142
+ ```
143
+
144
+ ``` -->
145
+
146
+ ## Quickstart
147
+
148
+ Here provides a code snippet to show you how to load the tokenizer and model and how to generate contents.
149
+ To run inference using the model, follow the steps outlined in our Colab inference notebook
150
+
151
+ ```python
152
+ import numpy as np
153
+ import torch
154
+ import torchvision.transforms as T
155
+ # from decord import VideoReader, cpu
156
+ from PIL import Image
157
+ from torchvision.transforms.functional import InterpolationMode
158
+ from transformers import AutoModel, AutoTokenizer
159
+
160
+ IMAGENET_MEAN = (0.485, 0.456, 0.406)
161
+ IMAGENET_STD = (0.229, 0.224, 0.225)
162
+
163
+ def build_transform(input_size):
164
+ MEAN, STD = IMAGENET_MEAN, IMAGENET_STD
165
+ transform = T.Compose([
166
+ T.Lambda(lambda img: img.convert('RGB') if img.mode != 'RGB' else img),
167
+ T.Resize((input_size, input_size), interpolation=InterpolationMode.BICUBIC),
168
+ T.ToTensor(),
169
+ T.Normalize(mean=MEAN, std=STD)
170
+ ])
171
+ return transform
172
+
173
+ def find_closest_aspect_ratio(aspect_ratio, target_ratios, width, height, image_size):
174
+ best_ratio_diff = float('inf')
175
+ best_ratio = (1, 1)
176
+ area = width * height
177
+ for ratio in target_ratios:
178
+ target_aspect_ratio = ratio[0] / ratio[1]
179
+ ratio_diff = abs(aspect_ratio - target_aspect_ratio)
180
+ if ratio_diff < best_ratio_diff:
181
+ best_ratio_diff = ratio_diff
182
+ best_ratio = ratio
183
+ elif ratio_diff == best_ratio_diff:
184
+ if area > 0.5 * image_size * image_size * ratio[0] * ratio[1]:
185
+ best_ratio = ratio
186
+ return best_ratio
187
+
188
+ def dynamic_preprocess(image, min_num=1, max_num=12, image_size=448, use_thumbnail=False):
189
+ orig_width, orig_height = image.size
190
+ aspect_ratio = orig_width / orig_height
191
+
192
+ # calculate the existing image aspect ratio
193
+ target_ratios = set(
194
+ (i, j) for n in range(min_num, max_num + 1) for i in range(1, n + 1) for j in range(1, n + 1) if
195
+ i * j <= max_num and i * j >= min_num)
196
+ target_ratios = sorted(target_ratios, key=lambda x: x[0] * x[1])
197
+
198
+ # find the closest aspect ratio to the target
199
+ target_aspect_ratio = find_closest_aspect_ratio(
200
+ aspect_ratio, target_ratios, orig_width, orig_height, image_size)
201
+
202
+ # calculate the target width and height
203
+ target_width = image_size * target_aspect_ratio[0]
204
+ target_height = image_size * target_aspect_ratio[1]
205
+ blocks = target_aspect_ratio[0] * target_aspect_ratio[1]
206
+
207
+ # resize the image
208
+ resized_img = image.resize((target_width, target_height))
209
+ processed_images = []
210
+ for i in range(blocks):
211
+ box = (
212
+ (i % (target_width // image_size)) * image_size,
213
+ (i // (target_width // image_size)) * image_size,
214
+ ((i % (target_width // image_size)) + 1) * image_size,
215
+ ((i // (target_width // image_size)) + 1) * image_size
216
+ )
217
+ # split the image
218
+ split_img = resized_img.crop(box)
219
+ processed_images.append(split_img)
220
+ assert len(processed_images) == blocks
221
+ if use_thumbnail and len(processed_images) != 1:
222
+ thumbnail_img = image.resize((image_size, image_size))
223
+ processed_images.append(thumbnail_img)
224
+ return processed_images
225
+
226
+ def load_image(image_file, input_size=448, max_num=12):
227
+ image = Image.open(image_file).convert('RGB')
228
+ transform = build_transform(input_size=input_size)
229
+ images = dynamic_preprocess(image, image_size=input_size, use_thumbnail=True, max_num=max_num)
230
+ pixel_values = [transform(image) for image in images]
231
+ pixel_values = torch.stack(pixel_values)
232
+ return pixel_values
233
+
234
+ model = AutoModel.from_pretrained(
235
+ "5CD-AI/Vintern-3B-beta",
236
+ torch_dtype=torch.bfloat16,
237
+ low_cpu_mem_usage=True,
238
+ trust_remote_code=True,
239
+ ).eval().cuda()
240
+ tokenizer = AutoTokenizer.from_pretrained("5CD-AI/Vintern-3B-beta", trust_remote_code=True, use_fast=False)
241
+
242
+ test_image = 'test-image.jpg'
243
+
244
+ pixel_values = load_image(test_image, max_num=6).to(torch.bfloat16).cuda()
245
+ generation_config = dict(max_new_tokens= 512, do_sample=False, num_beams = 3, repetition_penalty=3.5)
246
+
247
+ question = '<image>\nMô tả hình ảnh một cách chi tiết.'
248
+
249
+ response, history = model.chat(tokenizer, pixel_values, question, generation_config, history=None, return_history=True)
250
+ print(f'User: {question}\nAssistant: {response}')
251
+
252
+ #question = "Câu hỏi khác ......"
253
+ #response, history = model.chat(tokenizer, pixel_values, question, generation_config, history=history, return_history=True)
254
+ #print(f'User: {question}\nAssistant: {response}')
255
+ ```
256
+
257
+ ## Citation
258
+
259
+ ```
260
+ @misc{doan2024vintern1befficientmultimodallarge,
261
+ title={Vintern-1B: An Efficient Multimodal Large Language Model for Vietnamese},
262
+ author={Khang T. Doan and Bao G. Huynh and Dung T. Hoang and Thuc D. Pham and Nhat H. Pham and Quan T. M. Nguyen and Bang Q. Vo and Suong N. Hoang},
263
+ year={2024},
264
+ eprint={2408.12480},
265
+ archivePrefix={arXiv},
266
+ primaryClass={cs.LG},
267
+ url={https://arxiv.org/abs/2408.12480},
268
+ }
269
+ ```