paultltc commited on
Commit
21e384c
·
verified ·
1 Parent(s): b3ff762

Upload folder using huggingface_hub

Browse files
chat_template.jinja ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ <|begin_of_text|>{% for message in messages %}{{message['role'] | capitalize}}{% if message['content'][0]['type'] == 'image' %}{{':'}}{% else %}{{': '}}{% endif %}{% for line in message['content'] %}{% if line['type'] == 'text' %}{{line['text']}}{% elif line['type'] == 'image' %}{{ '<image>' }}{% endif %}{% endfor %}<end_of_utterance>
2
+ {% endfor %}{% if add_generation_prompt %}{{ 'Assistant:' }}{% endif %}
chat_template.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "chat_template": "<|begin_of_text|>{% for message in messages %}{{message['role'] | capitalize}}{% if message['content'][0]['type'] == 'image' %}{{':'}}{% else %}{{': '}}{% endif %}{% for line in message['content'] %}{% if line['type'] == 'text' %}{{line['text']}}{% elif line['type'] == 'image' %}{{ '<image>' }}{% endif %}{% endfor %}<end_of_utterance>\n{% endfor %}{% if add_generation_prompt %}{{ 'Assistant:' }}{% endif %}"
3
+ }
config.json ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_vocab_size": 40,
3
+ "architectures": [
4
+ "VBertForMaskedLM"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_vbert.VBertConfig",
8
+ "AutoModel": "modeling_vbert.VBertModel",
9
+ "AutoModelForMaskedLM": "modeling_vbert.VBertForMaskedLM"
10
+ },
11
+ "freeze_config": {
12
+ "freeze_lm_head": true,
13
+ "freeze_text_layers": true,
14
+ "freeze_vision_layers": true
15
+ },
16
+ "hidden_size": 768,
17
+ "image_token_id": 50407,
18
+ "initializer_range": 0.02,
19
+ "max_position_embeddings": 8192,
20
+ "model_type": "vbert",
21
+ "neftune_noise_alpha": 0.0,
22
+ "output_attentions": false,
23
+ "pixel_shuffle_factor": 4,
24
+ "qk_layer_norms": false,
25
+ "scale_factor": 4,
26
+ "text_config": {
27
+ "hidden_size": 768,
28
+ "intermediate_size": 1152,
29
+ "mlp_bias": false,
30
+ "model_type": "vbert",
31
+ "num_hidden_layers": 22,
32
+ "text_model_name": "jhu-clsp/ettin-encoder-150m",
33
+ "vocab_size": 50368
34
+ },
35
+ "tie_word_embeddings": false,
36
+ "torch_dtype": "float32",
37
+ "transformers_version": null,
38
+ "use_cache": true,
39
+ "use_resampler": false,
40
+ "vision_config": {
41
+ "embed_dim": 768,
42
+ "image_size": 512,
43
+ "intermediate_size": 3072,
44
+ "model_type": "vbert",
45
+ "num_hidden_layers": 12,
46
+ "patch_size": 16,
47
+ "vision_model_name": "google/siglip2-base-patch16-512"
48
+ },
49
+ "vocab_size": 50368
50
+ }
configuration_vbert.py ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import copy
2
+ import os
3
+
4
+ from typing import Union, Any, Dict
5
+
6
+ from transformers.configuration_utils import PretrainedConfig
7
+ from transformers.utils import logging
8
+ from transformers import CONFIG_MAPPING, AutoConfig
9
+
10
+ logger = logging.get_logger(__name__)
11
+
12
+ def collect_arg_in_candidates(config, candidates, default = None) -> Any:
13
+ """ Gets the argument in a config given a list of candidates """
14
+ for c in candidates:
15
+ if hasattr(config, c):
16
+ return getattr(config, c)
17
+ elif c in config:
18
+ return config[c]
19
+ if default is not None:
20
+ return default
21
+ raise ValueError("No matching arguments found in candidates. Candidates: {}, Config: {}".format(candidates, config))
22
+
23
+ class VBertTextConfig(PretrainedConfig):
24
+ r"""
25
+ This is the configuration class to store the configuration of a [`LlamaModel`]. It is used to instantiate an LLaMA
26
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
27
+ defaults will yield a similar configuration to that of the LLaMA-7B.
28
+
29
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
30
+ documentation from [`PretrainedConfig`] for more information.
31
+
32
+ Args:
33
+ embed_dim (`int`, *optional*, defaults to 1152):
34
+ Dimensionality of the encoder layers and the pooler layer. (elsewhere referred to as `embed_dim`)
35
+ image_size (`int`, *optional*, defaults to 384):
36
+ The size (resolution) of each image.
37
+ """
38
+ model_type = "vbert"
39
+
40
+ def __init__(
41
+ self,
42
+ # Case for when vllama3 is from the hub with no vision_model_name
43
+ text_model_name="EuroBERT/EuroBERT-210m",
44
+ **kwargs,
45
+ ):
46
+ self.text_model_name = text_model_name
47
+ text_config = AutoConfig.from_pretrained(text_model_name, trust_remote_code=True)
48
+ if hasattr(text_config, "text_config"):
49
+ text_config = text_config.text_config
50
+
51
+ self.hidden_size = collect_arg_in_candidates(text_config, ["hidden_size", "embed_dim"])
52
+ self.num_hidden_layers = collect_arg_in_candidates(text_config, ["num_hidden_layers", "num_hidden_blocks"])
53
+ self.intermediate_size = collect_arg_in_candidates(text_config, ["intermediate_size", "mlp_dim"])
54
+ self.mlp_bias = collect_arg_in_candidates(text_config, ["mlp_bias", "mlp_hidden_bias"], default = False)
55
+ self.vocab_size = collect_arg_in_candidates(text_config, ["vocab_size"])
56
+
57
+ super().__init__(text_model_name=text_model_name, **kwargs)
58
+
59
+ class VBertVisionConfig(PretrainedConfig):
60
+ r"""
61
+ This is the configuration class to store the configuration of a [`LlamaModel`]. It is used to instantiate an LLaMA
62
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
63
+ defaults will yield a similar configuration to that of the LLaMA-7B.
64
+
65
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
66
+ documentation from [`PretrainedConfig`] for more information.
67
+
68
+ Args:
69
+ embed_dim (`int`, *optional*, defaults to 1152):
70
+ Dimensionality of the encoder layers and the pooler layer. (elsewhere referred to as `embed_dim`)
71
+ image_size (`int`, *optional*, defaults to 384):
72
+ The size (resolution) of each image.
73
+ """
74
+ model_type = "vbert"
75
+ attribute_map = {
76
+ "hidden_size": "embed_dim",
77
+ }
78
+
79
+ def __init__(
80
+ self,
81
+ # Case for when vllama3 is from the hub with no vision_model_name
82
+ vision_model_name="google/siglip2-base-patch16-512",
83
+ **kwargs,
84
+ ):
85
+ self.vision_model_name = vision_model_name
86
+ vision_config = AutoConfig.from_pretrained(vision_model_name, trust_remote_code=True)
87
+ if hasattr(vision_config, "vision_config"):
88
+ vision_config = vision_config.vision_config
89
+
90
+ self.embed_dim = collect_arg_in_candidates(vision_config, ["embed_dim", "hidden_size"])
91
+ self.image_size = collect_arg_in_candidates(vision_config, ["image_size", "img_size"])
92
+ self.patch_size = collect_arg_in_candidates(vision_config, ["patch_size"])
93
+ self.num_hidden_layers = collect_arg_in_candidates(vision_config, ["num_hidden_layers", "num_hidden_blocks"])
94
+ self.intermediate_size = collect_arg_in_candidates(vision_config, ["intermediate_size", "mlp_dim"])
95
+
96
+ super().__init__(vision_model_name=vision_model_name, **kwargs)
97
+
98
+ class VBertConfig(PretrainedConfig):
99
+ r"""
100
+ This is the configuration class to store the configuration of a [`SmolVLMModel`]. It is used to instantiate a
101
+ SmolVLM model according to the specified arguments, defining the model architecture. Instantiating a
102
+ configuration with the defaults will yield a similar configuration to that of the model of the SmolVLM
103
+ [HuggingFaceTB/SmolVLM2-2.2B-Instruct](https://huggingface.co/HuggingFaceTB/SmolVLM2-2.2B-Instruct) architecture.
104
+
105
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
106
+ documentation from [`PretrainedConfig`] for more information.
107
+
108
+ Args:
109
+ use_cache (`bool`, *optional*, defaults to `True`):
110
+ Whether or not the model should cache the key/value pairs of the attention mechanism. Only
111
+ relevant if `config.is_decoder=True`.
112
+ image_token_id (`int`, *optional*, defaults to 128257):
113
+ The id of the "image" token.
114
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
115
+ Whether or not to tie the word embeddings with the token embeddings.
116
+ vision_config (`IdeficsVisionConfig` or `dict`, *optional*, defaults to `IdeficsVisionConfig`):
117
+ Custom vision config or dict for the vision tower
118
+ text_config (`PretrainedConfig` or `dict`, *optional*, defaults to `LlamaConfig`):
119
+ Custom text config or dict for the text model
120
+ scale_factor (`int`, *optional*, defaults to 2):
121
+ The scale factor for the image encoder.
122
+ pad_token_id (`int`, *optional*, defaults to 128002):
123
+ The id of the padding token.
124
+
125
+ Example:
126
+ ```python
127
+ >>> from transformers import SmolVLMModel, SmolVLMConfig
128
+ >>> # Initializing configuration
129
+ >>> configuration = SmolVLMConfig()
130
+ >>> # Initializing a model from the configuration
131
+ >>> model = SmolVLMModel(configuration)
132
+ >>> # Accessing the model configuration
133
+ >>> configuration = model.config
134
+ ```"""
135
+
136
+ model_type = "vbert"
137
+ is_composition = True
138
+ # sub_configs = {"text_config": VBertTextConfig, "vision_config": VBertVisionConfig}
139
+
140
+ DEFAULT_TEXT_MODEL_NAME = "EuroBERT/EuroBERT-210m"
141
+ DEFAULT_VISION_MODEL_NAME = "google/siglip2-base-patch16-512"
142
+
143
+ def __init__(
144
+ self,
145
+ text_config: Union[PretrainedConfig, Dict[str, Any]] = None,
146
+ vision_config: Union[PretrainedConfig, Dict[str, Any]] = None,
147
+ image_token_id: int = 128_257,
148
+ vocab_size=128_256,
149
+ use_cache = True,
150
+ tie_word_embeddings = False,
151
+ freeze_config = None,
152
+ pad_token_id = None,
153
+ initializer_range = 0.02,
154
+ pixel_shuffle_factor = 4,
155
+ use_resampler = False,
156
+ additional_vocab_size = 0,
157
+ neftune_noise_alpha = 0.0,
158
+ **kwargs,
159
+ ):
160
+ self.image_token_id = image_token_id
161
+ self.use_cache = use_cache
162
+ self.tie_word_embeddings = tie_word_embeddings
163
+ self.scale_factor = pixel_shuffle_factor
164
+ self.additional_vocab_size = additional_vocab_size
165
+
166
+ if text_config is None:
167
+ text_config = AutoConfig.from_pretrained(self.DEFAULT_TEXT_MODEL_NAME, trust_remote_code=True)
168
+ elif isinstance(text_config, dict):
169
+ text_config = VBertTextConfig(text_config["text_model_name"])
170
+ self.text_config = text_config
171
+
172
+ if vision_config is None:
173
+ vision_config = AutoConfig.from_pretrained(self.DEFAULT_VISION_MODEL_NAME, trust_remote_code=True)
174
+ elif isinstance(vision_config, dict):
175
+ vision_config = VBertVisionConfig(vision_config["vision_model_name"])
176
+ self.vision_config = vision_config
177
+
178
+ self.freeze_config = freeze_config
179
+
180
+ # Pixel shuffle factor
181
+ self.pixel_shuffle_factor = pixel_shuffle_factor
182
+ self.use_resampler = use_resampler
183
+
184
+ self.neftune_noise_alpha = neftune_noise_alpha
185
+
186
+ self.initializer_range = initializer_range
187
+
188
+ hidden_size = kwargs.pop("hidden_size", self.text_config.hidden_size)
189
+
190
+ super().__init__(
191
+ **kwargs,
192
+ pad_token_id=pad_token_id,
193
+ tie_word_embeddings=tie_word_embeddings,
194
+ vocab_size=vocab_size,
195
+ hidden_size=hidden_size,
196
+ )
197
+
198
+ def to_dict(self):
199
+ """
200
+ Serializes this instance to a Python dictionary. Override the default [`~PretrainedConfig.to_dict`].
201
+ Returns:
202
+ `Dict[str, any]`: Dictionary of all the attributes that make up this configuration instance,
203
+ """
204
+ output = copy.deepcopy(self.__dict__)
205
+
206
+ output["model_type"] = self.__class__.model_type
207
+ output["vision_config"] = self.vision_config.to_dict()
208
+ output["text_config"] = self.text_config.to_dict()
209
+ # output["freeze_config"] = self.freeze_config.to_dict()
210
+
211
+ return output
212
+
213
+ # @classmethod
214
+ # def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs) -> "PretrainedConfig":
215
+ # outputs = super(VBertConfig, cls).from_pretrained(pretrained_model_name_or_path, **kwargs)
216
+ # return outputs
217
+
218
+ @classmethod
219
+ def from_pretrained_models(
220
+ cls,
221
+ text_model_name: Union[str, os.PathLike],
222
+ vision_model_name: Union[str, os.PathLike],
223
+ **kwargs
224
+ ) -> "PretrainedConfig":
225
+ # text_model_config = AutoConfig.from_pretrained(text_model_name, trust_remote_code=True)
226
+ # vision_model_config = AutoConfig.from_pretrained(vision_model_name, trust_remote_code=True)
227
+ text_model_config = VBertTextConfig(text_model_name)
228
+ vision_model_config = VBertVisionConfig(vision_model_name)
229
+ return cls(
230
+ text_config=text_model_config,
231
+ vision_config=vision_model_config,
232
+ **kwargs
233
+ )
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7258bef432f17b1010de6f93d9651d8298da83cea3430dac26b6caf43864162c
3
+ size 1165468824
modeling_vbert.py ADDED
@@ -0,0 +1,633 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+ import torch.nn.functional as F
4
+ from torch.nn import CrossEntropyLoss
5
+ from typing import Optional, Tuple, Union, List
6
+
7
+ from transformers.cache_utils import DynamicCache
8
+
9
+ from .configuration_vbert import VBertConfig
10
+
11
+ from transformers import AutoModel, AutoConfig, AutoModelForMaskedLM, PreTrainedModel
12
+ from transformers.modeling_outputs import BaseModelOutput
13
+ from transformers.models.bert.modeling_bert import BaseModelOutputWithPoolingAndCrossAttentions, MaskedLMOutput
14
+
15
+ from typing import List, Optional, Tuple, Union
16
+
17
+ import torch
18
+ import torch.utils.checkpoint
19
+
20
+ from dataclasses import dataclass
21
+
22
+ from transformers import logging
23
+
24
+ logger = logging.get_logger(__name__)
25
+
26
+
27
+ class DecoupledEmbedding(nn.Embedding):
28
+ # Derived from https://pytorch.org/docs/stable/_modules/torch/nn/modules/sparse.html#Embedding
29
+ """
30
+ Implements a decoupling of parameters to allow freezing (or not) a subset of the embeddings.
31
+ In practise, the regular `weight` can be trained or frozen (i.e. `partially_freeze=True`), and if `num_additional_embeddings` > 0, then it will create `num_additional_embeddings` additional parameters that are always trained.
32
+ If `num_additional_embeddings=0`, then the module defaults back to the regular behavior of `nn.Embedding`.
33
+ """
34
+
35
+ def __init__(
36
+ self,
37
+ num_embeddings,
38
+ num_additional_embeddings,
39
+ embedding_dim,
40
+ partially_freeze=False,
41
+ device=None,
42
+ dtype=None,
43
+ padding_idx=None,
44
+ **kwargs,
45
+ ) -> None:
46
+ """
47
+ num_additional_embeddings: int. Number of additional embeddings. Only useful when you `partially_freeze=True`.
48
+ partially_freeze: bool. If True, the regular `weight` will be frozen. `additional_weight` is never frozen.
49
+
50
+ Note: there are a lot of other parameters to initialize a standard `nn.Embedding` such as `padding_idx`, `max_norm` or `norm_type`. We are not supporting these.
51
+ """
52
+ if padding_idx is not None and padding_idx > num_embeddings:
53
+ raise ValueError(f"padding_idx must be within num_embeddings. Got {padding_idx} and {num_embeddings}")
54
+ super().__init__(
55
+ num_embeddings=num_embeddings,
56
+ embedding_dim=embedding_dim,
57
+ device=device,
58
+ dtype=dtype,
59
+ padding_idx=padding_idx,
60
+ **kwargs,
61
+ )
62
+ self.num_embeddings = num_embeddings
63
+ self.padding_idx = padding_idx
64
+ self.num_additional_embeddings = num_additional_embeddings
65
+ self.partially_freeze = partially_freeze
66
+
67
+ if partially_freeze:
68
+ self.weight.requires_grad_(False)
69
+
70
+ if self.num_additional_embeddings > 0:
71
+ self.additional_embedding = nn.Embedding(
72
+ num_embeddings=self.num_additional_embeddings,
73
+ embedding_dim=embedding_dim,
74
+ device=device,
75
+ dtype=dtype,
76
+ )
77
+
78
+ def forward(self, input_ids):
79
+ """
80
+ we have 2 embeddings, with different indices - one pretrained self.weight and another
81
+ self.additional_embedding.weight that is being trained.
82
+
83
+ in order to make a lookup of the input ids, we:
84
+ 1. find out the indices of the entries belonging to the 2nd embedding
85
+ 2. extract those values while subtracting the size of the first embedding (num_embeddings),
86
+ since the 2nd embedding starts from 0 and not num_embeddings
87
+ 3. perform the 2nd embedding lookup
88
+ 4. now we handle the 1st embedding, we overwrite indices belonging to the 2nd embedding with a padding index
89
+ 5. perform the 1st embedding lookup
90
+ 6. now we overwrite the values in the 1st embedding lookup with the values of the 2nd embedding lookup
91
+
92
+ note: for the 1st embedding lookup we could have looked up only the low indices and not do
93
+ the padding, but then we have to create a new tensor and populate it with 2 tensors that are
94
+ spread out across various indices - i.e. not a simple concat - I haven't benchmarked the
95
+ complex case if it's any faster, given that seqlens are usually relatively short it's
96
+ probably not faster or if faster not by much - but might be a good idea to measure.
97
+
98
+ """
99
+ if self.num_additional_embeddings == 0:
100
+ return self.additional_embedding(input_ids)
101
+
102
+ # Clone so that we don't modify the original input_ids later on
103
+ input_ids = input_ids.clone()
104
+ additional_vocab_indices = torch.where(input_ids >= self.num_embeddings)
105
+ input_ids_additional_vocab = input_ids[additional_vocab_indices]
106
+ additional_embeddings = self.additional_embedding(input_ids_additional_vocab - self.num_embeddings)
107
+
108
+ # for successful lookup replace input_ids with 0, the results of these will be discarded anyway
109
+ input_ids[additional_vocab_indices] = 0
110
+ full_vector = F.embedding(input_ids, self.weight)
111
+
112
+ # overwrite the records with high indices
113
+ full_vector[additional_vocab_indices] = additional_embeddings
114
+
115
+ return full_vector
116
+
117
+ def extra_repr(self) -> str:
118
+ return "num_embeddings={}, num_additional_embeddings={}, embedding_dim={}, partially_freeze={}".format(
119
+ self.num_embeddings,
120
+ self.num_additional_embeddings,
121
+ self.embedding_dim,
122
+ self.partially_freeze,
123
+ )
124
+
125
+ @dataclass
126
+ class VBertBaseModelOutput(BaseModelOutput):
127
+ """
128
+ Base class for SmolVLM model's outputs that may also contain a past key/values (to speed up sequential decoding).
129
+ Args:
130
+ last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
131
+ Sequence of hidden-states at the output of the last layer of the model.
132
+ If `past_key_values` is used only the last hidden-state of the sequences of shape `(batch_size, 1,
133
+ hidden_size)` is output.
134
+ past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
135
+ Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
136
+ `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and optionally if
137
+ `config.is_encoder_decoder=True` 2 additional tensors of shape `(batch_size, num_heads,
138
+ encoder_sequence_length, embed_size_per_head)`.
139
+ Contains pre-computed hidden-states (key and values in the self-attention blocks and optionally if
140
+ `config.is_encoder_decoder=True` in the cross-attention blocks) that can be used (see `past_key_values`
141
+ input) to speed up sequential decoding.
142
+ hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
143
+ Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
144
+ one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.
145
+ Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
146
+ attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
147
+ Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
148
+ sequence_length)`.
149
+ Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
150
+ heads.
151
+ image_hidden_states (`tuple(torch.FloatTensor)`, *optional*):
152
+ Tuple of `torch.FloatTensor` (one for the output of the image embeddings, `(batch_size, num_images,
153
+ sequence_length, hidden_size)`.
154
+ image_hidden_states of the model produced by the vision encoder
155
+ """
156
+
157
+ last_hidden_state: torch.FloatTensor = None
158
+ hidden_states: Optional[Tuple[torch.FloatTensor]] = None
159
+ attentions: Optional[Tuple[torch.FloatTensor]] = None
160
+ image_hidden_states: Optional[Tuple[torch.FloatTensor]] = None
161
+
162
+ @dataclass
163
+ class VBertMaskedLMOutput(MaskedLMOutput):
164
+ """
165
+ Base class for SmolVLM model's outputs that may also contain a past key/values (to speed up sequential decoding).
166
+ Args:
167
+ loss (`torch.FloatTensor`, *optional*, returned when `labels` is provided):
168
+ Masked language modeling (MLM) loss.
169
+ logits (`torch.FloatTensor`):
170
+ Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
171
+ hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
172
+ Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
173
+ one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.
174
+ Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
175
+ attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
176
+ Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
177
+ sequence_length)`.
178
+ Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
179
+ heads.
180
+ image_hidden_states (`tuple(torch.FloatTensor)`, *optional*):
181
+ Tuple of `torch.FloatTensor` (one for the output of the image embeddings, `(batch_size, num_images,
182
+ sequence_length, hidden_size)`.
183
+ image_hidden_states of the model produced by the vision encoder
184
+ """
185
+ loss: Optional[torch.FloatTensor] = None
186
+ logits: torch.FloatTensor = None
187
+ hidden_states: Optional[Tuple[torch.FloatTensor, ...]] = None
188
+ attentions: Optional[Tuple[torch.FloatTensor, ...]] = None
189
+ image_hidden_states: Optional[torch.FloatTensor] = None
190
+
191
+ class VBertSimpleMLP(nn.Module):
192
+ def __init__(self, input_size, output_size):
193
+ super().__init__()
194
+ self.proj = nn.Linear(input_size, output_size, bias=False)
195
+
196
+ def forward(self, x):
197
+ return self.proj(x)
198
+
199
+ class VBertConnector(nn.Module):
200
+ def __init__(self, config):
201
+ super().__init__()
202
+ self.scale_factor = config.pixel_shuffle_factor
203
+ self.modality_projection = VBertSimpleMLP(
204
+ input_size=config.vision_config.hidden_size * (config.scale_factor**2),
205
+ output_size=config.text_config.hidden_size
206
+ )
207
+
208
+ def pixel_shuffle(self, x, scale_factor):
209
+ bsz, seq, embed_dim = x.size()
210
+ height = width = int(seq**0.5)
211
+ x = x.view(bsz, height, width, embed_dim)
212
+ x = x.view(bsz, height, int(width / scale_factor), embed_dim * scale_factor)
213
+ x = x.permute(0, 2, 1, 3)
214
+ x = x.reshape(bsz, int(width / scale_factor), int(height / scale_factor), embed_dim * (scale_factor**2))
215
+ x = x.permute(0, 2, 1, 3)
216
+ x = x.reshape(bsz, int(seq / (scale_factor**2)), embed_dim * (scale_factor**2))
217
+ return x
218
+
219
+ def forward(self, image_hidden_states):
220
+ image_hidden_states = self.pixel_shuffle(image_hidden_states, self.scale_factor)
221
+ image_hidden_states = self.modality_projection(image_hidden_states)
222
+ return image_hidden_states
223
+
224
+ class VBertPreTrainedModel(PreTrainedModel):
225
+ config_class = VBertConfig
226
+ base_model_prefix = "model"
227
+ supports_gradient_checkpointing = True
228
+ _no_split_modules = ["VBertDecoderLayer"]
229
+ _skip_keys_device_placement = "past_key_values"
230
+ _supports_flash_attn_2 = True
231
+ _supports_sdpa = True
232
+ _supports_cache_class = True
233
+
234
+ def _init_weights(self, module):
235
+ """Initialize the weights."""
236
+
237
+ std = (
238
+ self.config.initializer_range
239
+ if hasattr(self.config, "initializer_range")
240
+ else self.config.text_config.initializer_range
241
+ )
242
+
243
+ if hasattr(module, "class_embedding"):
244
+ module.class_embedding.data.normal_(mean=0.0, std=std)
245
+
246
+ if isinstance(module, (nn.Linear, nn.Conv2d)):
247
+ module.weight.data.normal_(mean=0.0, std=std)
248
+ if module.bias is not None:
249
+ module.bias.data.zero_()
250
+ elif isinstance(module, nn.Embedding):
251
+ module.weight.data.normal_(mean=0.0, std=std)
252
+ if module.padding_idx is not None:
253
+ module.weight.data[module.padding_idx].zero_()
254
+
255
+ class VBertModel(VBertPreTrainedModel):
256
+ """
257
+ A subclass of Idefics3Model. We do *not* remove or block the call to inputs_merger
258
+ in forward. Instead, we override inputs_merger here with custom logic.
259
+ """
260
+
261
+ def __init__(self, config: VBertConfig, **kwargs):
262
+ super().__init__(config)
263
+
264
+ self.vision_model = VBertModel.init_vision_model(config, **kwargs)
265
+ self.connector = VBertConnector(config)
266
+ self.text_model = VBertModel.init_language_model(config, **kwargs)
267
+
268
+ self.image_seq_len = int(
269
+ ((config.vision_config.image_size // config.vision_config.patch_size) ** 2) / (config.scale_factor**2)
270
+ )
271
+ self.image_token_id = self.config.image_token_id
272
+
273
+ self.post_init()
274
+
275
+ @staticmethod
276
+ def init_vision_model(config: VBertConfig, **kwargs):
277
+ vision_model_config = AutoConfig.from_pretrained(
278
+ config.vision_config.vision_model_name,
279
+ trust_remote_code=True,
280
+ **kwargs,
281
+ )
282
+
283
+ vision_model = AutoModel.from_config(vision_model_config, trust_remote_code=True, **kwargs)
284
+
285
+ if hasattr(vision_model, "vision_model"):
286
+ # If the model has a vision_model attribute, it means it's a wrapper around another model
287
+ vision_model = vision_model.vision_model
288
+
289
+ return vision_model
290
+
291
+ @staticmethod
292
+ def init_language_model(config: VBertConfig, **kwargs):
293
+ text_model_config = AutoConfig.from_pretrained(
294
+ config.text_config.text_model_name,
295
+ trust_remote_code=True,
296
+ **kwargs,
297
+ )
298
+
299
+ text_model = AutoModel.from_config(text_model_config, trust_remote_code=True, **kwargs)
300
+ # extractor = regex_lookup(language_model_name, language_model_name2model)
301
+
302
+ embed_layer = DecoupledEmbedding(
303
+ num_embeddings=text_model_config.vocab_size,
304
+ num_additional_embeddings=config.additional_vocab_size,
305
+ embedding_dim=config.hidden_size,
306
+ partially_freeze=config.freeze_config["freeze_text_layers"],
307
+ padding_idx=config.pad_token_id,
308
+ )
309
+
310
+ text_model.set_input_embeddings(embed_layer)
311
+
312
+ return text_model
313
+
314
+ def enable_input_require_grads(self):
315
+ """
316
+ Enables the gradients for the input embeddings.
317
+
318
+ This is useful for lora when using gradient checkpointing.
319
+ c.f. https://github.com/huggingface/peft/issues/1402#issuecomment-1913675032
320
+
321
+ Override to set output.requires_grad = True for both the decoder's and vision model's embeddings.
322
+ """
323
+
324
+ def get_lowest_module(module):
325
+ if len(list(module.children())) == 0:
326
+ # If the module has no children, it is a leaf module (e.g., Linear, Conv2d, etc.)
327
+ return module
328
+ else:
329
+ # Recursively call the function on each child module
330
+ return get_lowest_module(list(module.children())[0])
331
+
332
+ def make_inputs_require_grads(module, input, output):
333
+ output.requires_grad_(True)
334
+
335
+ self._text_require_grads_hook = self.get_input_embeddings().register_forward_hook(make_inputs_require_grads)
336
+ self._vision_require_grads_hook = get_lowest_module(self.vision_model).register_forward_hook(
337
+ make_inputs_require_grads
338
+ )
339
+
340
+ def disable_input_require_grads(self):
341
+ self._text_require_grads_hook.remove()
342
+ self._vision_require_grads_hook.remove()
343
+
344
+ def get_input_embeddings(self):
345
+ return self.text_model.get_input_embeddings()
346
+
347
+ def set_input_embeddings(self, value):
348
+ self.text_model.set_input_embeddings(value)
349
+
350
+ def inputs_merger(
351
+ self, input_ids: torch.LongTensor, inputs_embeds: torch.Tensor, image_hidden_states: torch.Tensor
352
+ ):
353
+ """
354
+ This method aims at merging the token embeddings with the image hidden states into one single sequence of vectors that are fed to the transformer LM.
355
+ The merging happens as follows:
356
+ - The text token sequence is: `tok_1 tok_2 tok_3 <fake_token_around_image> <image> <image> ... <image> <fake_token_around_image> tok_4`.
357
+ - We get the image hidden states for the image through the vision encoder and that hidden state, after a pixel shuffle operation, is then projected into the text embedding space.
358
+ We thus have a sequence of image hidden states of size (1, image_seq_len, hidden_dim), where 1 is for batch_size of 1 image and hidden_dim is the hidden_dim of the LM transformer.
359
+ - The merging happens so that we obtain the following sequence: `vector_tok_1 vector_tok_2 vector_tok_3 vector_fake_tok_around_image {sequence of image_seq_len image hidden states} vector_fake_toke_around_image vector_tok_4`. That sequence is fed to the LM.
360
+ - To fit the format of that sequence, `input_ids`, `input_embeds`, `attention_mask` are all 3 adapted to insert the image hidden states.
361
+ """
362
+ _, patch_size, _ = image_hidden_states.shape
363
+
364
+ image_mask = input_ids == self.image_token_id
365
+ num_image_tokens = image_mask.sum(dim=1)
366
+ if not torch.all(num_image_tokens % patch_size == 0):
367
+ raise ValueError("At least one sample has <image> tokens not divisible by patch_size.")
368
+
369
+ blocks_per_sample = num_image_tokens // patch_size
370
+
371
+ offsets = torch.nn.functional.pad(blocks_per_sample.cumsum(dim=0), (1, 0), value=0)
372
+ block_offset = offsets[:-1]
373
+ row_cum = image_mask.cumsum(dim=-1)
374
+ chunk_idx = (row_cum - 1) // patch_size
375
+ local_idx = (row_cum - 1) % patch_size
376
+ block_idx = block_offset.unsqueeze(1) + chunk_idx
377
+
378
+ image_embeds = torch.zeros_like(inputs_embeds)
379
+ image_embeds[image_mask] = image_hidden_states[block_idx[image_mask], local_idx[image_mask], :]
380
+
381
+ merged_embeds = torch.where(image_mask.unsqueeze(-1), image_embeds, inputs_embeds)
382
+ return merged_embeds
383
+
384
+ def forward(
385
+ self,
386
+ input_ids: torch.LongTensor = None,
387
+ attention_mask: Optional[torch.Tensor] = None,
388
+ position_ids: Optional[torch.LongTensor] = None,
389
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
390
+ inputs_embeds: Optional[torch.FloatTensor] = None,
391
+ pixel_values: Optional[torch.FloatTensor] = None,
392
+ pixel_attention_mask: Optional[torch.BoolTensor] = None,
393
+ image_hidden_states: Optional[torch.FloatTensor] = None,
394
+ use_cache: Optional[bool] = None,
395
+ output_attentions: Optional[bool] = None,
396
+ output_hidden_states: Optional[bool] = None,
397
+ return_dict: Optional[bool] = None,
398
+ cache_position: Optional[torch.LongTensor] = None,
399
+ ) -> Union[Tuple, BaseModelOutputWithPoolingAndCrossAttentions]:
400
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
401
+ output_hidden_states = (
402
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
403
+ )
404
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
405
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
406
+
407
+ if self.training and self.text_model.gradient_checkpointing and use_cache:
408
+ logger.warning_once(
409
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
410
+ )
411
+ use_cache = False
412
+
413
+ # retrieve input_ids and inputs_embeds
414
+ if input_ids is not None:
415
+ batch_size, seq_length = input_ids.shape
416
+ elif inputs_embeds is not None:
417
+ batch_size, seq_length, _ = inputs_embeds.shape
418
+ else:
419
+ raise ValueError("You have to specify either input_ids or inputs_embeds")
420
+
421
+ past_seen_tokens = 0
422
+ if use_cache:
423
+ if past_key_values is None:
424
+ past_key_values = DynamicCache()
425
+ past_seen_tokens = past_key_values.get_seq_length()
426
+
427
+ if inputs_embeds is not None and input_ids is None and past_seen_tokens == 0:
428
+ raise ValueError("When first calling the model, if input_embeds are passed, input_ids should not be None.")
429
+
430
+ if inputs_embeds is None:
431
+ inputs_embeds = self.text_model.get_input_embeddings()(input_ids).to(input_ids.device)
432
+
433
+ # START VISUAL INPUTS INTEGRATION
434
+ if pixel_values is not None and image_hidden_states is not None:
435
+ raise ValueError("You cannot specify both pixel_values and image_hidden_states at the same time")
436
+ elif pixel_values is not None:
437
+ batch_size, num_images, num_channels, height, width = pixel_values.shape
438
+ pixel_values = pixel_values
439
+ pixel_values = pixel_values.view(batch_size * num_images, *pixel_values.shape[2:])
440
+
441
+ # Remove padding images - padding images are full 0.
442
+ nb_values_per_image = pixel_values.shape[1:].numel()
443
+ real_images_inds = (pixel_values == 0.0).sum(dim=(-1, -2, -3)) != nb_values_per_image
444
+
445
+ if not any(real_images_inds):
446
+ # no images, leave one empty image.
447
+ real_images_inds[0] = True
448
+
449
+ pixel_values = pixel_values[real_images_inds].contiguous()
450
+
451
+ # Handle the vision attention mask
452
+ if pixel_attention_mask is None:
453
+ pixel_attention_mask = torch.ones(
454
+ size=[pixel_values.shape[i] for i in (0, 2, 3)],
455
+ dtype=torch.bool,
456
+ device=pixel_values.device,
457
+ )
458
+ else:
459
+ # Remove padding images from the mask
460
+ pixel_attention_mask = pixel_attention_mask.view(
461
+ batch_size * num_images, *pixel_attention_mask.shape[2:]
462
+ )
463
+ pixel_attention_mask = pixel_attention_mask[real_images_inds].contiguous()
464
+
465
+ # patch_size = self.config.vision_config.patch_size
466
+ # patches_subgrid = pixel_attention_mask.unfold(dimension=1, size=patch_size, step=patch_size)
467
+ # patches_subgrid = patches_subgrid.unfold(dimension=2, size=patch_size, step=patch_size)
468
+ # patch_attention_mask = (patches_subgrid.sum(dim=(-1, -2)) > 0).bool()
469
+
470
+ # Get sequence from the vision encoder
471
+ image_hidden_states = self.vision_model(
472
+ pixel_values=pixel_values,
473
+ # patch_attention_mask=patch_attention_mask,
474
+ ).last_hidden_state
475
+
476
+ # Modality projection & resampling
477
+ image_hidden_states = self.connector(image_hidden_states)
478
+
479
+ elif image_hidden_states is not None:
480
+ image_hidden_states = image_hidden_states.to(dtype=self.dtype, device=input_ids.device)
481
+
482
+ if inputs_embeds is not None and image_hidden_states is not None:
483
+ # When we embed, we don't want to replace the potential image_token_id that we generated by images
484
+ # that simply don't exist
485
+ inputs_embeds = self.inputs_merger(
486
+ input_ids=input_ids,
487
+ inputs_embeds=inputs_embeds,
488
+ image_hidden_states=image_hidden_states,
489
+ )
490
+
491
+ outputs = self.text_model(
492
+ inputs_embeds=inputs_embeds,
493
+ attention_mask=attention_mask,
494
+ position_ids=position_ids,
495
+ output_attentions=output_attentions,
496
+ output_hidden_states=output_hidden_states,
497
+ return_dict=return_dict,
498
+ # past_key_values=past_key_values,
499
+ # use_cache=use_cache,
500
+ # cache_position=cache_position,
501
+ )
502
+
503
+ if not return_dict:
504
+ return tuple(v for v in [*outputs, image_hidden_states] if v is not None)
505
+
506
+ return VBertBaseModelOutput(
507
+ last_hidden_state=outputs.last_hidden_state,
508
+ hidden_states=outputs.hidden_states,
509
+ attentions=outputs.attentions,
510
+ image_hidden_states=image_hidden_states,
511
+ )
512
+
513
+ class VBertLMHead(nn.Module):
514
+ def __init__(self, config, **kwargs):
515
+ super().__init__()
516
+ pretrained_config = AutoConfig.from_pretrained(
517
+ config.text_config.text_model_name,
518
+ trust_remote_code=True,
519
+ **kwargs,
520
+ )
521
+ pretrained_model = AutoModelForMaskedLM.from_config(pretrained_config, trust_remote_code=True, **kwargs)
522
+
523
+ self.head = pretrained_model.head
524
+ self.decoder = pretrained_model.decoder
525
+
526
+ def forward(self, hidden_states):
527
+ hidden_states = self.head(hidden_states)
528
+ hidden_states = self.decoder(hidden_states)
529
+ return hidden_states
530
+
531
+ class VBertForMaskedLM(VBertPreTrainedModel):
532
+ # _tied_weights_keys = ["predictions.decoder.bias", "cls.predictions.decoder.weight"]
533
+
534
+ def __init__(self, config, **kwargs):
535
+ super().__init__(config)
536
+
537
+ self.image_token_id = config.image_token_id
538
+ self.in_features = config.hidden_size
539
+ self.out_additional_features = config.additional_vocab_size
540
+ self.vocab_size = config.vocab_size
541
+
542
+ if config.is_decoder:
543
+ logger.warning(
544
+ "If you want to use `BertForMaskedLM` make sure `config.is_decoder=False` for "
545
+ "bi-directional self-attention."
546
+ )
547
+
548
+ self.model = VBertModel(config, **kwargs)
549
+ self.lm_head = VBertLMHead(config, **kwargs)
550
+ if self.out_additional_features > 0:
551
+ self.additional_fc = nn.Linear(
552
+ in_features=self.in_features,
553
+ out_features=self.out_additional_features,
554
+ bias=False,
555
+ )
556
+
557
+ # Initialize weights and apply final processing
558
+ self.post_init()
559
+
560
+ def forward(
561
+ self,
562
+ input_ids: torch.LongTensor = None,
563
+ attention_mask: Optional[torch.Tensor] = None,
564
+ position_ids: Optional[torch.LongTensor] = None,
565
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
566
+ inputs_embeds: Optional[torch.FloatTensor] = None,
567
+ pixel_values: Optional[torch.FloatTensor] = None,
568
+ pixel_attention_mask: Optional[torch.BoolTensor] = None,
569
+ image_hidden_states: Optional[torch.FloatTensor] = None,
570
+ labels: Optional[torch.LongTensor] = None,
571
+ use_cache: Optional[bool] = None,
572
+ output_attentions: Optional[bool] = None,
573
+ output_hidden_states: Optional[bool] = None,
574
+ return_dict: Optional[bool] = None,
575
+ ) -> Union[Tuple, VBertMaskedLMOutput]:
576
+ r"""
577
+ Args:
578
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
579
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
580
+ config.vocab_size]` or `model.image_token_id` (where `model` is your instance of `Idefics3ForConditionalGeneration`).
581
+ Tokens with indices set to `model.image_token_id` are ignored (masked), the loss is only
582
+ computed for the tokens with labels in `[0, ..., config.vocab_size]`.
583
+ ```"""
584
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
585
+ output_hidden_states = (
586
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
587
+ )
588
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
589
+
590
+
591
+ # Pass the inputs to VBertModel
592
+ outputs = self.model(
593
+ input_ids=input_ids,
594
+ attention_mask=attention_mask,
595
+ position_ids=position_ids,
596
+ past_key_values=past_key_values,
597
+ inputs_embeds=inputs_embeds,
598
+ pixel_values=pixel_values,
599
+ pixel_attention_mask=pixel_attention_mask,
600
+ image_hidden_states=image_hidden_states,
601
+ use_cache=use_cache,
602
+ output_attentions=output_attentions,
603
+ output_hidden_states=output_hidden_states,
604
+ return_dict=return_dict,
605
+ )
606
+
607
+ # Pass the outputs to the MLM head
608
+ hidden_states = outputs[0]
609
+
610
+ logits = self.lm_head(hidden_states)
611
+ if self.out_additional_features > 0:
612
+ proj_states = self.lm_head.head(hidden_states)
613
+ additional_features = self.additional_fc(proj_states)
614
+ logits = torch.cat((logits, additional_features), -1)
615
+ logits = logits.float()
616
+
617
+ masked_lm_loss = None
618
+ if labels is not None:
619
+ # print the ratio of not ignored tokens
620
+ loss_fct = CrossEntropyLoss()
621
+ masked_lm_loss = loss_fct(logits.view(-1, self.vocab_size + self.out_additional_features), labels.view(-1))
622
+
623
+ if not return_dict:
624
+ output = (logits,) + outputs[2:]
625
+ return ((masked_lm_loss,) + output) if masked_lm_loss is not None else output
626
+
627
+ return VBertMaskedLMOutput(
628
+ loss=masked_lm_loss,
629
+ logits=logits,
630
+ hidden_states=outputs.hidden_states,
631
+ attentions=outputs.attentions,
632
+ image_hidden_states=outputs.image_hidden_states,
633
+ )
preprocessor_config.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_convert_rgb": true,
3
+ "do_image_splitting": true,
4
+ "do_normalize": true,
5
+ "do_pad": true,
6
+ "do_rescale": true,
7
+ "do_resize": true,
8
+ "image_mean": [
9
+ 0.5,
10
+ 0.5,
11
+ 0.5
12
+ ],
13
+ "image_processor_type": "Idefics3ImageProcessor",
14
+ "image_std": [
15
+ 0.5,
16
+ 0.5,
17
+ 0.5
18
+ ],
19
+ "max_image_size": {
20
+ "longest_edge": 512
21
+ },
22
+ "processor_class": "Idefics3Processor",
23
+ "resample": 1,
24
+ "rescale_factor": 0.00392156862745098,
25
+ "size": {
26
+ "longest_edge": 2048
27
+ }
28
+ }
processor_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "image_seq_len": 64,
3
+ "processor_class": "Idefics3Processor"
4
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<global-img>",
4
+ "<row_1_col_1>",
5
+ "<row_1_col_2>",
6
+ "<row_1_col_3>",
7
+ "<row_1_col_4>",
8
+ "<row_1_col_5>",
9
+ "<row_1_col_6>",
10
+ "<row_2_col_1>",
11
+ "<row_2_col_2>",
12
+ "<row_2_col_3>",
13
+ "<row_2_col_4>",
14
+ "<row_2_col_5>",
15
+ "<row_2_col_6>",
16
+ "<row_3_col_1>",
17
+ "<row_3_col_2>",
18
+ "<row_3_col_3>",
19
+ "<row_3_col_4>",
20
+ "<row_3_col_5>",
21
+ "<row_3_col_6>",
22
+ "<row_4_col_1>",
23
+ "<row_4_col_2>",
24
+ "<row_4_col_3>",
25
+ "<row_4_col_4>",
26
+ "<row_4_col_5>",
27
+ "<row_4_col_6>",
28
+ "<row_5_col_1>",
29
+ "<row_5_col_2>",
30
+ "<row_5_col_3>",
31
+ "<row_5_col_4>",
32
+ "<row_5_col_5>",
33
+ "<row_5_col_6>",
34
+ "<row_6_col_1>",
35
+ "<row_6_col_2>",
36
+ "<row_6_col_3>",
37
+ "<row_6_col_4>",
38
+ "<row_6_col_5>",
39
+ "<row_6_col_6>",
40
+ "<end_of_utterance>",
41
+ "<fake_token_around_image>",
42
+ "<image>"
43
+ ],
44
+ "cls_token": {
45
+ "content": "[CLS]",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false
50
+ },
51
+ "mask_token": {
52
+ "content": "[MASK]",
53
+ "lstrip": true,
54
+ "normalized": false,
55
+ "rstrip": false,
56
+ "single_word": false
57
+ },
58
+ "pad_token": {
59
+ "content": "[PAD]",
60
+ "lstrip": false,
61
+ "normalized": false,
62
+ "rstrip": false,
63
+ "single_word": false
64
+ },
65
+ "sep_token": {
66
+ "content": "[SEP]",
67
+ "lstrip": false,
68
+ "normalized": false,
69
+ "rstrip": false,
70
+ "single_word": false
71
+ },
72
+ "unk_token": {
73
+ "content": "[UNK]",
74
+ "lstrip": false,
75
+ "normalized": false,
76
+ "rstrip": false,
77
+ "single_word": false
78
+ }
79
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,1310 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "|||IP_ADDRESS|||",
5
+ "lstrip": false,
6
+ "normalized": true,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": false
10
+ },
11
+ "1": {
12
+ "content": "<|padding|>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "50254": {
20
+ "content": " ",
21
+ "lstrip": false,
22
+ "normalized": true,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": false
26
+ },
27
+ "50255": {
28
+ "content": " ",
29
+ "lstrip": false,
30
+ "normalized": true,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": false
34
+ },
35
+ "50256": {
36
+ "content": " ",
37
+ "lstrip": false,
38
+ "normalized": true,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": false
42
+ },
43
+ "50257": {
44
+ "content": " ",
45
+ "lstrip": false,
46
+ "normalized": true,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": false
50
+ },
51
+ "50258": {
52
+ "content": " ",
53
+ "lstrip": false,
54
+ "normalized": true,
55
+ "rstrip": false,
56
+ "single_word": false,
57
+ "special": false
58
+ },
59
+ "50259": {
60
+ "content": " ",
61
+ "lstrip": false,
62
+ "normalized": true,
63
+ "rstrip": false,
64
+ "single_word": false,
65
+ "special": false
66
+ },
67
+ "50260": {
68
+ "content": " ",
69
+ "lstrip": false,
70
+ "normalized": true,
71
+ "rstrip": false,
72
+ "single_word": false,
73
+ "special": false
74
+ },
75
+ "50261": {
76
+ "content": " ",
77
+ "lstrip": false,
78
+ "normalized": true,
79
+ "rstrip": false,
80
+ "single_word": false,
81
+ "special": false
82
+ },
83
+ "50262": {
84
+ "content": " ",
85
+ "lstrip": false,
86
+ "normalized": true,
87
+ "rstrip": false,
88
+ "single_word": false,
89
+ "special": false
90
+ },
91
+ "50263": {
92
+ "content": " ",
93
+ "lstrip": false,
94
+ "normalized": true,
95
+ "rstrip": false,
96
+ "single_word": false,
97
+ "special": false
98
+ },
99
+ "50264": {
100
+ "content": " ",
101
+ "lstrip": false,
102
+ "normalized": true,
103
+ "rstrip": false,
104
+ "single_word": false,
105
+ "special": false
106
+ },
107
+ "50265": {
108
+ "content": " ",
109
+ "lstrip": false,
110
+ "normalized": true,
111
+ "rstrip": false,
112
+ "single_word": false,
113
+ "special": false
114
+ },
115
+ "50266": {
116
+ "content": " ",
117
+ "lstrip": false,
118
+ "normalized": true,
119
+ "rstrip": false,
120
+ "single_word": false,
121
+ "special": false
122
+ },
123
+ "50267": {
124
+ "content": " ",
125
+ "lstrip": false,
126
+ "normalized": true,
127
+ "rstrip": false,
128
+ "single_word": false,
129
+ "special": false
130
+ },
131
+ "50268": {
132
+ "content": " ",
133
+ "lstrip": false,
134
+ "normalized": true,
135
+ "rstrip": false,
136
+ "single_word": false,
137
+ "special": false
138
+ },
139
+ "50269": {
140
+ "content": " ",
141
+ "lstrip": false,
142
+ "normalized": true,
143
+ "rstrip": false,
144
+ "single_word": false,
145
+ "special": false
146
+ },
147
+ "50270": {
148
+ "content": " ",
149
+ "lstrip": false,
150
+ "normalized": true,
151
+ "rstrip": false,
152
+ "single_word": false,
153
+ "special": false
154
+ },
155
+ "50271": {
156
+ "content": " ",
157
+ "lstrip": false,
158
+ "normalized": true,
159
+ "rstrip": false,
160
+ "single_word": false,
161
+ "special": false
162
+ },
163
+ "50272": {
164
+ "content": " ",
165
+ "lstrip": false,
166
+ "normalized": true,
167
+ "rstrip": false,
168
+ "single_word": false,
169
+ "special": false
170
+ },
171
+ "50273": {
172
+ "content": " ",
173
+ "lstrip": false,
174
+ "normalized": true,
175
+ "rstrip": false,
176
+ "single_word": false,
177
+ "special": false
178
+ },
179
+ "50274": {
180
+ "content": " ",
181
+ "lstrip": false,
182
+ "normalized": true,
183
+ "rstrip": false,
184
+ "single_word": false,
185
+ "special": false
186
+ },
187
+ "50275": {
188
+ "content": " ",
189
+ "lstrip": false,
190
+ "normalized": true,
191
+ "rstrip": false,
192
+ "single_word": false,
193
+ "special": false
194
+ },
195
+ "50276": {
196
+ "content": " ",
197
+ "lstrip": false,
198
+ "normalized": true,
199
+ "rstrip": false,
200
+ "single_word": false,
201
+ "special": false
202
+ },
203
+ "50277": {
204
+ "content": "|||EMAIL_ADDRESS|||",
205
+ "lstrip": false,
206
+ "normalized": true,
207
+ "rstrip": false,
208
+ "single_word": false,
209
+ "special": false
210
+ },
211
+ "50278": {
212
+ "content": "|||PHONE_NUMBER|||",
213
+ "lstrip": false,
214
+ "normalized": true,
215
+ "rstrip": false,
216
+ "single_word": false,
217
+ "special": false
218
+ },
219
+ "50279": {
220
+ "content": "<|endoftext|>",
221
+ "lstrip": false,
222
+ "normalized": false,
223
+ "rstrip": false,
224
+ "single_word": false,
225
+ "special": true
226
+ },
227
+ "50280": {
228
+ "content": "[UNK]",
229
+ "lstrip": false,
230
+ "normalized": false,
231
+ "rstrip": false,
232
+ "single_word": false,
233
+ "special": true
234
+ },
235
+ "50281": {
236
+ "content": "[CLS]",
237
+ "lstrip": false,
238
+ "normalized": false,
239
+ "rstrip": false,
240
+ "single_word": false,
241
+ "special": true
242
+ },
243
+ "50282": {
244
+ "content": "[SEP]",
245
+ "lstrip": false,
246
+ "normalized": false,
247
+ "rstrip": false,
248
+ "single_word": false,
249
+ "special": true
250
+ },
251
+ "50283": {
252
+ "content": "[PAD]",
253
+ "lstrip": false,
254
+ "normalized": false,
255
+ "rstrip": false,
256
+ "single_word": false,
257
+ "special": true
258
+ },
259
+ "50284": {
260
+ "content": "[MASK]",
261
+ "lstrip": true,
262
+ "normalized": false,
263
+ "rstrip": false,
264
+ "single_word": false,
265
+ "special": true
266
+ },
267
+ "50285": {
268
+ "content": "[unused0]",
269
+ "lstrip": false,
270
+ "normalized": true,
271
+ "rstrip": false,
272
+ "single_word": false,
273
+ "special": false
274
+ },
275
+ "50286": {
276
+ "content": "[unused1]",
277
+ "lstrip": false,
278
+ "normalized": true,
279
+ "rstrip": false,
280
+ "single_word": false,
281
+ "special": false
282
+ },
283
+ "50287": {
284
+ "content": "[unused2]",
285
+ "lstrip": false,
286
+ "normalized": true,
287
+ "rstrip": false,
288
+ "single_word": false,
289
+ "special": false
290
+ },
291
+ "50288": {
292
+ "content": "[unused3]",
293
+ "lstrip": false,
294
+ "normalized": true,
295
+ "rstrip": false,
296
+ "single_word": false,
297
+ "special": false
298
+ },
299
+ "50289": {
300
+ "content": "[unused4]",
301
+ "lstrip": false,
302
+ "normalized": true,
303
+ "rstrip": false,
304
+ "single_word": false,
305
+ "special": false
306
+ },
307
+ "50290": {
308
+ "content": "[unused5]",
309
+ "lstrip": false,
310
+ "normalized": true,
311
+ "rstrip": false,
312
+ "single_word": false,
313
+ "special": false
314
+ },
315
+ "50291": {
316
+ "content": "[unused6]",
317
+ "lstrip": false,
318
+ "normalized": true,
319
+ "rstrip": false,
320
+ "single_word": false,
321
+ "special": false
322
+ },
323
+ "50292": {
324
+ "content": "[unused7]",
325
+ "lstrip": false,
326
+ "normalized": true,
327
+ "rstrip": false,
328
+ "single_word": false,
329
+ "special": false
330
+ },
331
+ "50293": {
332
+ "content": "[unused8]",
333
+ "lstrip": false,
334
+ "normalized": true,
335
+ "rstrip": false,
336
+ "single_word": false,
337
+ "special": false
338
+ },
339
+ "50294": {
340
+ "content": "[unused9]",
341
+ "lstrip": false,
342
+ "normalized": true,
343
+ "rstrip": false,
344
+ "single_word": false,
345
+ "special": false
346
+ },
347
+ "50295": {
348
+ "content": "[unused10]",
349
+ "lstrip": false,
350
+ "normalized": true,
351
+ "rstrip": false,
352
+ "single_word": false,
353
+ "special": false
354
+ },
355
+ "50296": {
356
+ "content": "[unused11]",
357
+ "lstrip": false,
358
+ "normalized": true,
359
+ "rstrip": false,
360
+ "single_word": false,
361
+ "special": false
362
+ },
363
+ "50297": {
364
+ "content": "[unused12]",
365
+ "lstrip": false,
366
+ "normalized": true,
367
+ "rstrip": false,
368
+ "single_word": false,
369
+ "special": false
370
+ },
371
+ "50298": {
372
+ "content": "[unused13]",
373
+ "lstrip": false,
374
+ "normalized": true,
375
+ "rstrip": false,
376
+ "single_word": false,
377
+ "special": false
378
+ },
379
+ "50299": {
380
+ "content": "[unused14]",
381
+ "lstrip": false,
382
+ "normalized": true,
383
+ "rstrip": false,
384
+ "single_word": false,
385
+ "special": false
386
+ },
387
+ "50300": {
388
+ "content": "[unused15]",
389
+ "lstrip": false,
390
+ "normalized": true,
391
+ "rstrip": false,
392
+ "single_word": false,
393
+ "special": false
394
+ },
395
+ "50301": {
396
+ "content": "[unused16]",
397
+ "lstrip": false,
398
+ "normalized": true,
399
+ "rstrip": false,
400
+ "single_word": false,
401
+ "special": false
402
+ },
403
+ "50302": {
404
+ "content": "[unused17]",
405
+ "lstrip": false,
406
+ "normalized": true,
407
+ "rstrip": false,
408
+ "single_word": false,
409
+ "special": false
410
+ },
411
+ "50303": {
412
+ "content": "[unused18]",
413
+ "lstrip": false,
414
+ "normalized": true,
415
+ "rstrip": false,
416
+ "single_word": false,
417
+ "special": false
418
+ },
419
+ "50304": {
420
+ "content": "[unused19]",
421
+ "lstrip": false,
422
+ "normalized": true,
423
+ "rstrip": false,
424
+ "single_word": false,
425
+ "special": false
426
+ },
427
+ "50305": {
428
+ "content": "[unused20]",
429
+ "lstrip": false,
430
+ "normalized": true,
431
+ "rstrip": false,
432
+ "single_word": false,
433
+ "special": false
434
+ },
435
+ "50306": {
436
+ "content": "[unused21]",
437
+ "lstrip": false,
438
+ "normalized": true,
439
+ "rstrip": false,
440
+ "single_word": false,
441
+ "special": false
442
+ },
443
+ "50307": {
444
+ "content": "[unused22]",
445
+ "lstrip": false,
446
+ "normalized": true,
447
+ "rstrip": false,
448
+ "single_word": false,
449
+ "special": false
450
+ },
451
+ "50308": {
452
+ "content": "[unused23]",
453
+ "lstrip": false,
454
+ "normalized": true,
455
+ "rstrip": false,
456
+ "single_word": false,
457
+ "special": false
458
+ },
459
+ "50309": {
460
+ "content": "[unused24]",
461
+ "lstrip": false,
462
+ "normalized": true,
463
+ "rstrip": false,
464
+ "single_word": false,
465
+ "special": false
466
+ },
467
+ "50310": {
468
+ "content": "[unused25]",
469
+ "lstrip": false,
470
+ "normalized": true,
471
+ "rstrip": false,
472
+ "single_word": false,
473
+ "special": false
474
+ },
475
+ "50311": {
476
+ "content": "[unused26]",
477
+ "lstrip": false,
478
+ "normalized": true,
479
+ "rstrip": false,
480
+ "single_word": false,
481
+ "special": false
482
+ },
483
+ "50312": {
484
+ "content": "[unused27]",
485
+ "lstrip": false,
486
+ "normalized": true,
487
+ "rstrip": false,
488
+ "single_word": false,
489
+ "special": false
490
+ },
491
+ "50313": {
492
+ "content": "[unused28]",
493
+ "lstrip": false,
494
+ "normalized": true,
495
+ "rstrip": false,
496
+ "single_word": false,
497
+ "special": false
498
+ },
499
+ "50314": {
500
+ "content": "[unused29]",
501
+ "lstrip": false,
502
+ "normalized": true,
503
+ "rstrip": false,
504
+ "single_word": false,
505
+ "special": false
506
+ },
507
+ "50315": {
508
+ "content": "[unused30]",
509
+ "lstrip": false,
510
+ "normalized": true,
511
+ "rstrip": false,
512
+ "single_word": false,
513
+ "special": false
514
+ },
515
+ "50316": {
516
+ "content": "[unused31]",
517
+ "lstrip": false,
518
+ "normalized": true,
519
+ "rstrip": false,
520
+ "single_word": false,
521
+ "special": false
522
+ },
523
+ "50317": {
524
+ "content": "[unused32]",
525
+ "lstrip": false,
526
+ "normalized": true,
527
+ "rstrip": false,
528
+ "single_word": false,
529
+ "special": false
530
+ },
531
+ "50318": {
532
+ "content": "[unused33]",
533
+ "lstrip": false,
534
+ "normalized": true,
535
+ "rstrip": false,
536
+ "single_word": false,
537
+ "special": false
538
+ },
539
+ "50319": {
540
+ "content": "[unused34]",
541
+ "lstrip": false,
542
+ "normalized": true,
543
+ "rstrip": false,
544
+ "single_word": false,
545
+ "special": false
546
+ },
547
+ "50320": {
548
+ "content": "[unused35]",
549
+ "lstrip": false,
550
+ "normalized": true,
551
+ "rstrip": false,
552
+ "single_word": false,
553
+ "special": false
554
+ },
555
+ "50321": {
556
+ "content": "[unused36]",
557
+ "lstrip": false,
558
+ "normalized": true,
559
+ "rstrip": false,
560
+ "single_word": false,
561
+ "special": false
562
+ },
563
+ "50322": {
564
+ "content": "[unused37]",
565
+ "lstrip": false,
566
+ "normalized": true,
567
+ "rstrip": false,
568
+ "single_word": false,
569
+ "special": false
570
+ },
571
+ "50323": {
572
+ "content": "[unused38]",
573
+ "lstrip": false,
574
+ "normalized": true,
575
+ "rstrip": false,
576
+ "single_word": false,
577
+ "special": false
578
+ },
579
+ "50324": {
580
+ "content": "[unused39]",
581
+ "lstrip": false,
582
+ "normalized": true,
583
+ "rstrip": false,
584
+ "single_word": false,
585
+ "special": false
586
+ },
587
+ "50325": {
588
+ "content": "[unused40]",
589
+ "lstrip": false,
590
+ "normalized": true,
591
+ "rstrip": false,
592
+ "single_word": false,
593
+ "special": false
594
+ },
595
+ "50326": {
596
+ "content": "[unused41]",
597
+ "lstrip": false,
598
+ "normalized": true,
599
+ "rstrip": false,
600
+ "single_word": false,
601
+ "special": false
602
+ },
603
+ "50327": {
604
+ "content": "[unused42]",
605
+ "lstrip": false,
606
+ "normalized": true,
607
+ "rstrip": false,
608
+ "single_word": false,
609
+ "special": false
610
+ },
611
+ "50328": {
612
+ "content": "[unused43]",
613
+ "lstrip": false,
614
+ "normalized": true,
615
+ "rstrip": false,
616
+ "single_word": false,
617
+ "special": false
618
+ },
619
+ "50329": {
620
+ "content": "[unused44]",
621
+ "lstrip": false,
622
+ "normalized": true,
623
+ "rstrip": false,
624
+ "single_word": false,
625
+ "special": false
626
+ },
627
+ "50330": {
628
+ "content": "[unused45]",
629
+ "lstrip": false,
630
+ "normalized": true,
631
+ "rstrip": false,
632
+ "single_word": false,
633
+ "special": false
634
+ },
635
+ "50331": {
636
+ "content": "[unused46]",
637
+ "lstrip": false,
638
+ "normalized": true,
639
+ "rstrip": false,
640
+ "single_word": false,
641
+ "special": false
642
+ },
643
+ "50332": {
644
+ "content": "[unused47]",
645
+ "lstrip": false,
646
+ "normalized": true,
647
+ "rstrip": false,
648
+ "single_word": false,
649
+ "special": false
650
+ },
651
+ "50333": {
652
+ "content": "[unused48]",
653
+ "lstrip": false,
654
+ "normalized": true,
655
+ "rstrip": false,
656
+ "single_word": false,
657
+ "special": false
658
+ },
659
+ "50334": {
660
+ "content": "[unused49]",
661
+ "lstrip": false,
662
+ "normalized": true,
663
+ "rstrip": false,
664
+ "single_word": false,
665
+ "special": false
666
+ },
667
+ "50335": {
668
+ "content": "[unused50]",
669
+ "lstrip": false,
670
+ "normalized": true,
671
+ "rstrip": false,
672
+ "single_word": false,
673
+ "special": false
674
+ },
675
+ "50336": {
676
+ "content": "[unused51]",
677
+ "lstrip": false,
678
+ "normalized": true,
679
+ "rstrip": false,
680
+ "single_word": false,
681
+ "special": false
682
+ },
683
+ "50337": {
684
+ "content": "[unused52]",
685
+ "lstrip": false,
686
+ "normalized": true,
687
+ "rstrip": false,
688
+ "single_word": false,
689
+ "special": false
690
+ },
691
+ "50338": {
692
+ "content": "[unused53]",
693
+ "lstrip": false,
694
+ "normalized": true,
695
+ "rstrip": false,
696
+ "single_word": false,
697
+ "special": false
698
+ },
699
+ "50339": {
700
+ "content": "[unused54]",
701
+ "lstrip": false,
702
+ "normalized": true,
703
+ "rstrip": false,
704
+ "single_word": false,
705
+ "special": false
706
+ },
707
+ "50340": {
708
+ "content": "[unused55]",
709
+ "lstrip": false,
710
+ "normalized": true,
711
+ "rstrip": false,
712
+ "single_word": false,
713
+ "special": false
714
+ },
715
+ "50341": {
716
+ "content": "[unused56]",
717
+ "lstrip": false,
718
+ "normalized": true,
719
+ "rstrip": false,
720
+ "single_word": false,
721
+ "special": false
722
+ },
723
+ "50342": {
724
+ "content": "[unused57]",
725
+ "lstrip": false,
726
+ "normalized": true,
727
+ "rstrip": false,
728
+ "single_word": false,
729
+ "special": false
730
+ },
731
+ "50343": {
732
+ "content": "[unused58]",
733
+ "lstrip": false,
734
+ "normalized": true,
735
+ "rstrip": false,
736
+ "single_word": false,
737
+ "special": false
738
+ },
739
+ "50344": {
740
+ "content": "[unused59]",
741
+ "lstrip": false,
742
+ "normalized": true,
743
+ "rstrip": false,
744
+ "single_word": false,
745
+ "special": false
746
+ },
747
+ "50345": {
748
+ "content": "[unused60]",
749
+ "lstrip": false,
750
+ "normalized": true,
751
+ "rstrip": false,
752
+ "single_word": false,
753
+ "special": false
754
+ },
755
+ "50346": {
756
+ "content": "[unused61]",
757
+ "lstrip": false,
758
+ "normalized": true,
759
+ "rstrip": false,
760
+ "single_word": false,
761
+ "special": false
762
+ },
763
+ "50347": {
764
+ "content": "[unused62]",
765
+ "lstrip": false,
766
+ "normalized": true,
767
+ "rstrip": false,
768
+ "single_word": false,
769
+ "special": false
770
+ },
771
+ "50348": {
772
+ "content": "[unused63]",
773
+ "lstrip": false,
774
+ "normalized": true,
775
+ "rstrip": false,
776
+ "single_word": false,
777
+ "special": false
778
+ },
779
+ "50349": {
780
+ "content": "[unused64]",
781
+ "lstrip": false,
782
+ "normalized": true,
783
+ "rstrip": false,
784
+ "single_word": false,
785
+ "special": false
786
+ },
787
+ "50350": {
788
+ "content": "[unused65]",
789
+ "lstrip": false,
790
+ "normalized": true,
791
+ "rstrip": false,
792
+ "single_word": false,
793
+ "special": false
794
+ },
795
+ "50351": {
796
+ "content": "[unused66]",
797
+ "lstrip": false,
798
+ "normalized": true,
799
+ "rstrip": false,
800
+ "single_word": false,
801
+ "special": false
802
+ },
803
+ "50352": {
804
+ "content": "[unused67]",
805
+ "lstrip": false,
806
+ "normalized": true,
807
+ "rstrip": false,
808
+ "single_word": false,
809
+ "special": false
810
+ },
811
+ "50353": {
812
+ "content": "[unused68]",
813
+ "lstrip": false,
814
+ "normalized": true,
815
+ "rstrip": false,
816
+ "single_word": false,
817
+ "special": false
818
+ },
819
+ "50354": {
820
+ "content": "[unused69]",
821
+ "lstrip": false,
822
+ "normalized": true,
823
+ "rstrip": false,
824
+ "single_word": false,
825
+ "special": false
826
+ },
827
+ "50355": {
828
+ "content": "[unused70]",
829
+ "lstrip": false,
830
+ "normalized": true,
831
+ "rstrip": false,
832
+ "single_word": false,
833
+ "special": false
834
+ },
835
+ "50356": {
836
+ "content": "[unused71]",
837
+ "lstrip": false,
838
+ "normalized": true,
839
+ "rstrip": false,
840
+ "single_word": false,
841
+ "special": false
842
+ },
843
+ "50357": {
844
+ "content": "[unused72]",
845
+ "lstrip": false,
846
+ "normalized": true,
847
+ "rstrip": false,
848
+ "single_word": false,
849
+ "special": false
850
+ },
851
+ "50358": {
852
+ "content": "[unused73]",
853
+ "lstrip": false,
854
+ "normalized": true,
855
+ "rstrip": false,
856
+ "single_word": false,
857
+ "special": false
858
+ },
859
+ "50359": {
860
+ "content": "[unused74]",
861
+ "lstrip": false,
862
+ "normalized": true,
863
+ "rstrip": false,
864
+ "single_word": false,
865
+ "special": false
866
+ },
867
+ "50360": {
868
+ "content": "[unused75]",
869
+ "lstrip": false,
870
+ "normalized": true,
871
+ "rstrip": false,
872
+ "single_word": false,
873
+ "special": false
874
+ },
875
+ "50361": {
876
+ "content": "[unused76]",
877
+ "lstrip": false,
878
+ "normalized": true,
879
+ "rstrip": false,
880
+ "single_word": false,
881
+ "special": false
882
+ },
883
+ "50362": {
884
+ "content": "[unused77]",
885
+ "lstrip": false,
886
+ "normalized": true,
887
+ "rstrip": false,
888
+ "single_word": false,
889
+ "special": false
890
+ },
891
+ "50363": {
892
+ "content": "[unused78]",
893
+ "lstrip": false,
894
+ "normalized": true,
895
+ "rstrip": false,
896
+ "single_word": false,
897
+ "special": false
898
+ },
899
+ "50364": {
900
+ "content": "[unused79]",
901
+ "lstrip": false,
902
+ "normalized": true,
903
+ "rstrip": false,
904
+ "single_word": false,
905
+ "special": false
906
+ },
907
+ "50365": {
908
+ "content": "[unused80]",
909
+ "lstrip": false,
910
+ "normalized": true,
911
+ "rstrip": false,
912
+ "single_word": false,
913
+ "special": false
914
+ },
915
+ "50366": {
916
+ "content": "[unused81]",
917
+ "lstrip": false,
918
+ "normalized": true,
919
+ "rstrip": false,
920
+ "single_word": false,
921
+ "special": false
922
+ },
923
+ "50367": {
924
+ "content": "[unused82]",
925
+ "lstrip": false,
926
+ "normalized": true,
927
+ "rstrip": false,
928
+ "single_word": false,
929
+ "special": false
930
+ },
931
+ "50368": {
932
+ "content": "<global-img>",
933
+ "lstrip": false,
934
+ "normalized": false,
935
+ "rstrip": false,
936
+ "single_word": false,
937
+ "special": true
938
+ },
939
+ "50369": {
940
+ "content": "<row_1_col_1>",
941
+ "lstrip": false,
942
+ "normalized": false,
943
+ "rstrip": false,
944
+ "single_word": false,
945
+ "special": true
946
+ },
947
+ "50370": {
948
+ "content": "<row_1_col_2>",
949
+ "lstrip": false,
950
+ "normalized": false,
951
+ "rstrip": false,
952
+ "single_word": false,
953
+ "special": true
954
+ },
955
+ "50371": {
956
+ "content": "<row_1_col_3>",
957
+ "lstrip": false,
958
+ "normalized": false,
959
+ "rstrip": false,
960
+ "single_word": false,
961
+ "special": true
962
+ },
963
+ "50372": {
964
+ "content": "<row_1_col_4>",
965
+ "lstrip": false,
966
+ "normalized": false,
967
+ "rstrip": false,
968
+ "single_word": false,
969
+ "special": true
970
+ },
971
+ "50373": {
972
+ "content": "<row_1_col_5>",
973
+ "lstrip": false,
974
+ "normalized": false,
975
+ "rstrip": false,
976
+ "single_word": false,
977
+ "special": true
978
+ },
979
+ "50374": {
980
+ "content": "<row_1_col_6>",
981
+ "lstrip": false,
982
+ "normalized": false,
983
+ "rstrip": false,
984
+ "single_word": false,
985
+ "special": true
986
+ },
987
+ "50375": {
988
+ "content": "<row_2_col_1>",
989
+ "lstrip": false,
990
+ "normalized": false,
991
+ "rstrip": false,
992
+ "single_word": false,
993
+ "special": true
994
+ },
995
+ "50376": {
996
+ "content": "<row_2_col_2>",
997
+ "lstrip": false,
998
+ "normalized": false,
999
+ "rstrip": false,
1000
+ "single_word": false,
1001
+ "special": true
1002
+ },
1003
+ "50377": {
1004
+ "content": "<row_2_col_3>",
1005
+ "lstrip": false,
1006
+ "normalized": false,
1007
+ "rstrip": false,
1008
+ "single_word": false,
1009
+ "special": true
1010
+ },
1011
+ "50378": {
1012
+ "content": "<row_2_col_4>",
1013
+ "lstrip": false,
1014
+ "normalized": false,
1015
+ "rstrip": false,
1016
+ "single_word": false,
1017
+ "special": true
1018
+ },
1019
+ "50379": {
1020
+ "content": "<row_2_col_5>",
1021
+ "lstrip": false,
1022
+ "normalized": false,
1023
+ "rstrip": false,
1024
+ "single_word": false,
1025
+ "special": true
1026
+ },
1027
+ "50380": {
1028
+ "content": "<row_2_col_6>",
1029
+ "lstrip": false,
1030
+ "normalized": false,
1031
+ "rstrip": false,
1032
+ "single_word": false,
1033
+ "special": true
1034
+ },
1035
+ "50381": {
1036
+ "content": "<row_3_col_1>",
1037
+ "lstrip": false,
1038
+ "normalized": false,
1039
+ "rstrip": false,
1040
+ "single_word": false,
1041
+ "special": true
1042
+ },
1043
+ "50382": {
1044
+ "content": "<row_3_col_2>",
1045
+ "lstrip": false,
1046
+ "normalized": false,
1047
+ "rstrip": false,
1048
+ "single_word": false,
1049
+ "special": true
1050
+ },
1051
+ "50383": {
1052
+ "content": "<row_3_col_3>",
1053
+ "lstrip": false,
1054
+ "normalized": false,
1055
+ "rstrip": false,
1056
+ "single_word": false,
1057
+ "special": true
1058
+ },
1059
+ "50384": {
1060
+ "content": "<row_3_col_4>",
1061
+ "lstrip": false,
1062
+ "normalized": false,
1063
+ "rstrip": false,
1064
+ "single_word": false,
1065
+ "special": true
1066
+ },
1067
+ "50385": {
1068
+ "content": "<row_3_col_5>",
1069
+ "lstrip": false,
1070
+ "normalized": false,
1071
+ "rstrip": false,
1072
+ "single_word": false,
1073
+ "special": true
1074
+ },
1075
+ "50386": {
1076
+ "content": "<row_3_col_6>",
1077
+ "lstrip": false,
1078
+ "normalized": false,
1079
+ "rstrip": false,
1080
+ "single_word": false,
1081
+ "special": true
1082
+ },
1083
+ "50387": {
1084
+ "content": "<row_4_col_1>",
1085
+ "lstrip": false,
1086
+ "normalized": false,
1087
+ "rstrip": false,
1088
+ "single_word": false,
1089
+ "special": true
1090
+ },
1091
+ "50388": {
1092
+ "content": "<row_4_col_2>",
1093
+ "lstrip": false,
1094
+ "normalized": false,
1095
+ "rstrip": false,
1096
+ "single_word": false,
1097
+ "special": true
1098
+ },
1099
+ "50389": {
1100
+ "content": "<row_4_col_3>",
1101
+ "lstrip": false,
1102
+ "normalized": false,
1103
+ "rstrip": false,
1104
+ "single_word": false,
1105
+ "special": true
1106
+ },
1107
+ "50390": {
1108
+ "content": "<row_4_col_4>",
1109
+ "lstrip": false,
1110
+ "normalized": false,
1111
+ "rstrip": false,
1112
+ "single_word": false,
1113
+ "special": true
1114
+ },
1115
+ "50391": {
1116
+ "content": "<row_4_col_5>",
1117
+ "lstrip": false,
1118
+ "normalized": false,
1119
+ "rstrip": false,
1120
+ "single_word": false,
1121
+ "special": true
1122
+ },
1123
+ "50392": {
1124
+ "content": "<row_4_col_6>",
1125
+ "lstrip": false,
1126
+ "normalized": false,
1127
+ "rstrip": false,
1128
+ "single_word": false,
1129
+ "special": true
1130
+ },
1131
+ "50393": {
1132
+ "content": "<row_5_col_1>",
1133
+ "lstrip": false,
1134
+ "normalized": false,
1135
+ "rstrip": false,
1136
+ "single_word": false,
1137
+ "special": true
1138
+ },
1139
+ "50394": {
1140
+ "content": "<row_5_col_2>",
1141
+ "lstrip": false,
1142
+ "normalized": false,
1143
+ "rstrip": false,
1144
+ "single_word": false,
1145
+ "special": true
1146
+ },
1147
+ "50395": {
1148
+ "content": "<row_5_col_3>",
1149
+ "lstrip": false,
1150
+ "normalized": false,
1151
+ "rstrip": false,
1152
+ "single_word": false,
1153
+ "special": true
1154
+ },
1155
+ "50396": {
1156
+ "content": "<row_5_col_4>",
1157
+ "lstrip": false,
1158
+ "normalized": false,
1159
+ "rstrip": false,
1160
+ "single_word": false,
1161
+ "special": true
1162
+ },
1163
+ "50397": {
1164
+ "content": "<row_5_col_5>",
1165
+ "lstrip": false,
1166
+ "normalized": false,
1167
+ "rstrip": false,
1168
+ "single_word": false,
1169
+ "special": true
1170
+ },
1171
+ "50398": {
1172
+ "content": "<row_5_col_6>",
1173
+ "lstrip": false,
1174
+ "normalized": false,
1175
+ "rstrip": false,
1176
+ "single_word": false,
1177
+ "special": true
1178
+ },
1179
+ "50399": {
1180
+ "content": "<row_6_col_1>",
1181
+ "lstrip": false,
1182
+ "normalized": false,
1183
+ "rstrip": false,
1184
+ "single_word": false,
1185
+ "special": true
1186
+ },
1187
+ "50400": {
1188
+ "content": "<row_6_col_2>",
1189
+ "lstrip": false,
1190
+ "normalized": false,
1191
+ "rstrip": false,
1192
+ "single_word": false,
1193
+ "special": true
1194
+ },
1195
+ "50401": {
1196
+ "content": "<row_6_col_3>",
1197
+ "lstrip": false,
1198
+ "normalized": false,
1199
+ "rstrip": false,
1200
+ "single_word": false,
1201
+ "special": true
1202
+ },
1203
+ "50402": {
1204
+ "content": "<row_6_col_4>",
1205
+ "lstrip": false,
1206
+ "normalized": false,
1207
+ "rstrip": false,
1208
+ "single_word": false,
1209
+ "special": true
1210
+ },
1211
+ "50403": {
1212
+ "content": "<row_6_col_5>",
1213
+ "lstrip": false,
1214
+ "normalized": false,
1215
+ "rstrip": false,
1216
+ "single_word": false,
1217
+ "special": true
1218
+ },
1219
+ "50404": {
1220
+ "content": "<row_6_col_6>",
1221
+ "lstrip": false,
1222
+ "normalized": false,
1223
+ "rstrip": false,
1224
+ "single_word": false,
1225
+ "special": true
1226
+ },
1227
+ "50405": {
1228
+ "content": "<end_of_utterance>",
1229
+ "lstrip": false,
1230
+ "normalized": false,
1231
+ "rstrip": false,
1232
+ "single_word": false,
1233
+ "special": true
1234
+ },
1235
+ "50406": {
1236
+ "content": "<fake_token_around_image>",
1237
+ "lstrip": false,
1238
+ "normalized": false,
1239
+ "rstrip": false,
1240
+ "single_word": false,
1241
+ "special": true
1242
+ },
1243
+ "50407": {
1244
+ "content": "<image>",
1245
+ "lstrip": false,
1246
+ "normalized": false,
1247
+ "rstrip": false,
1248
+ "single_word": false,
1249
+ "special": true
1250
+ }
1251
+ },
1252
+ "additional_special_tokens": [
1253
+ "<global-img>",
1254
+ "<row_1_col_1>",
1255
+ "<row_1_col_2>",
1256
+ "<row_1_col_3>",
1257
+ "<row_1_col_4>",
1258
+ "<row_1_col_5>",
1259
+ "<row_1_col_6>",
1260
+ "<row_2_col_1>",
1261
+ "<row_2_col_2>",
1262
+ "<row_2_col_3>",
1263
+ "<row_2_col_4>",
1264
+ "<row_2_col_5>",
1265
+ "<row_2_col_6>",
1266
+ "<row_3_col_1>",
1267
+ "<row_3_col_2>",
1268
+ "<row_3_col_3>",
1269
+ "<row_3_col_4>",
1270
+ "<row_3_col_5>",
1271
+ "<row_3_col_6>",
1272
+ "<row_4_col_1>",
1273
+ "<row_4_col_2>",
1274
+ "<row_4_col_3>",
1275
+ "<row_4_col_4>",
1276
+ "<row_4_col_5>",
1277
+ "<row_4_col_6>",
1278
+ "<row_5_col_1>",
1279
+ "<row_5_col_2>",
1280
+ "<row_5_col_3>",
1281
+ "<row_5_col_4>",
1282
+ "<row_5_col_5>",
1283
+ "<row_5_col_6>",
1284
+ "<row_6_col_1>",
1285
+ "<row_6_col_2>",
1286
+ "<row_6_col_3>",
1287
+ "<row_6_col_4>",
1288
+ "<row_6_col_5>",
1289
+ "<row_6_col_6>",
1290
+ "<end_of_utterance>",
1291
+ "<fake_token_around_image>",
1292
+ "<image>"
1293
+ ],
1294
+ "clean_up_tokenization_spaces": true,
1295
+ "cls_token": "[CLS]",
1296
+ "extra_special_tokens": {},
1297
+ "legacy": false,
1298
+ "mask_token": "[MASK]",
1299
+ "model_input_names": [
1300
+ "input_ids",
1301
+ "attention_mask",
1302
+ "pixel_values",
1303
+ "pixel_attention_mask"
1304
+ ],
1305
+ "model_max_length": 8192,
1306
+ "pad_token": "[PAD]",
1307
+ "sep_token": "[SEP]",
1308
+ "tokenizer_class": "PreTrainedTokenizerFast",
1309
+ "unk_token": "[UNK]"
1310
+ }