helenai commited on
Commit
2443586
·
1 Parent(s): 4c3d673
added_tokens.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</box>": 92552,
3
+ "</img>": 92545,
4
+ "</quad>": 92548,
5
+ "</ref>": 92550,
6
+ "<IMG_CONTEXT>": 92546,
7
+ "<box>": 92551,
8
+ "<img>": 92544,
9
+ "<quad>": 92547,
10
+ "<ref>": 92549
11
+ }
config.json ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_attn_implementation_autoset": true,
3
+ "_commit_hash": null,
4
+ "_name_or_path": "/tmp/tmpwve_1r7d",
5
+ "architectures": [
6
+ "InternVLChatModel"
7
+ ],
8
+ "auto_map": {
9
+ "AutoConfig": "configuration_internvl_chat.InternVLChatConfig",
10
+ "AutoModel": "OpenGVLab/InternVL2-2B--modeling_internvl_chat.InternVLChatModel",
11
+ "AutoModelForCausalLM": "OpenGVLab/InternVL2-2B--modeling_internvl_chat.InternVLChatModel"
12
+ },
13
+ "downsample_ratio": 0.5,
14
+ "dynamic_image_size": true,
15
+ "force_image_size": 448,
16
+ "img_context_token_id": 92546,
17
+ "llm_config": {
18
+ "_attn_implementation_autoset": true,
19
+ "_name_or_path": "internlm/internlm2-chat-1_8b",
20
+ "add_cross_attention": false,
21
+ "architectures": [
22
+ "InternLM2ForCausalLM"
23
+ ],
24
+ "attn_implementation": "eager",
25
+ "auto_map": {
26
+ "AutoConfig": "configuration_internlm2.InternLM2Config",
27
+ "AutoModel": "modeling_internlm2.InternLM2ForCausalLM",
28
+ "AutoModelForCausalLM": "modeling_internlm2.InternLM2ForCausalLM"
29
+ },
30
+ "bad_words_ids": null,
31
+ "begin_suppress_tokens": null,
32
+ "bias": false,
33
+ "bos_token_id": 1,
34
+ "chunk_size_feed_forward": 0,
35
+ "cross_attention_hidden_size": null,
36
+ "decoder_start_token_id": null,
37
+ "diversity_penalty": 0.0,
38
+ "do_sample": false,
39
+ "early_stopping": false,
40
+ "encoder_no_repeat_ngram_size": 0,
41
+ "eos_token_id": 2,
42
+ "exponential_decay_length_penalty": null,
43
+ "finetuning_task": null,
44
+ "forced_bos_token_id": null,
45
+ "forced_eos_token_id": null,
46
+ "hidden_act": "silu",
47
+ "hidden_size": 2048,
48
+ "id2label": {
49
+ "0": "LABEL_0",
50
+ "1": "LABEL_1"
51
+ },
52
+ "initializer_range": 0.02,
53
+ "intermediate_size": 8192,
54
+ "is_decoder": false,
55
+ "is_encoder_decoder": false,
56
+ "label2id": {
57
+ "LABEL_0": 0,
58
+ "LABEL_1": 1
59
+ },
60
+ "length_penalty": 1.0,
61
+ "max_length": 20,
62
+ "max_position_embeddings": 32768,
63
+ "min_length": 0,
64
+ "model_type": "internlm2",
65
+ "no_repeat_ngram_size": 0,
66
+ "num_attention_heads": 16,
67
+ "num_beam_groups": 1,
68
+ "num_beams": 1,
69
+ "num_hidden_layers": 24,
70
+ "num_key_value_heads": 8,
71
+ "num_return_sequences": 1,
72
+ "output_attentions": false,
73
+ "output_hidden_states": false,
74
+ "output_scores": false,
75
+ "pad_token_id": 2,
76
+ "prefix": null,
77
+ "problem_type": null,
78
+ "pruned_heads": {},
79
+ "remove_invalid_values": false,
80
+ "repetition_penalty": 1.0,
81
+ "return_dict": true,
82
+ "return_dict_in_generate": false,
83
+ "rms_norm_eps": 1e-05,
84
+ "rope_scaling": {
85
+ "factor": 2.0,
86
+ "type": "dynamic"
87
+ },
88
+ "rope_theta": 1000000,
89
+ "sep_token_id": null,
90
+ "suppress_tokens": null,
91
+ "task_specific_params": null,
92
+ "temperature": 1.0,
93
+ "tf_legacy_loss": false,
94
+ "tie_encoder_decoder": false,
95
+ "tie_word_embeddings": false,
96
+ "tokenizer_class": null,
97
+ "top_k": 50,
98
+ "top_p": 1.0,
99
+ "torch_dtype": "bfloat16",
100
+ "torchscript": false,
101
+ "transformers_version": "4.46.3",
102
+ "typical_p": 1.0,
103
+ "use_bfloat16": true,
104
+ "use_cache": true,
105
+ "vocab_size": 92553
106
+ },
107
+ "max_dynamic_patch": 12,
108
+ "min_dynamic_patch": 1,
109
+ "model_type": "internvl_chat",
110
+ "ps_version": "v2",
111
+ "select_layer": -1,
112
+ "template": "internlm2-chat",
113
+ "transformers_version": null,
114
+ "use_backbone_lora": 0,
115
+ "use_llm_lora": 0,
116
+ "use_thumbnail": true,
117
+ "vision_config": {
118
+ "_attn_implementation_autoset": true,
119
+ "_name_or_path": "",
120
+ "add_cross_attention": false,
121
+ "architectures": [
122
+ "InternVisionModel"
123
+ ],
124
+ "attention_dropout": 0.0,
125
+ "bad_words_ids": null,
126
+ "begin_suppress_tokens": null,
127
+ "bos_token_id": null,
128
+ "chunk_size_feed_forward": 0,
129
+ "cross_attention_hidden_size": null,
130
+ "decoder_start_token_id": null,
131
+ "diversity_penalty": 0.0,
132
+ "do_sample": false,
133
+ "drop_path_rate": 0.0,
134
+ "dropout": 0.0,
135
+ "early_stopping": false,
136
+ "encoder_no_repeat_ngram_size": 0,
137
+ "eos_token_id": null,
138
+ "exponential_decay_length_penalty": null,
139
+ "finetuning_task": null,
140
+ "forced_bos_token_id": null,
141
+ "forced_eos_token_id": null,
142
+ "hidden_act": "gelu",
143
+ "hidden_size": 1024,
144
+ "id2label": {
145
+ "0": "LABEL_0",
146
+ "1": "LABEL_1"
147
+ },
148
+ "image_size": 448,
149
+ "initializer_factor": 1.0,
150
+ "initializer_range": 0.02,
151
+ "intermediate_size": 4096,
152
+ "is_decoder": false,
153
+ "is_encoder_decoder": false,
154
+ "label2id": {
155
+ "LABEL_0": 0,
156
+ "LABEL_1": 1
157
+ },
158
+ "layer_norm_eps": 1e-06,
159
+ "length_penalty": 1.0,
160
+ "max_length": 20,
161
+ "min_length": 0,
162
+ "model_type": "intern_vit_6b",
163
+ "no_repeat_ngram_size": 0,
164
+ "norm_type": "layer_norm",
165
+ "num_attention_heads": 16,
166
+ "num_beam_groups": 1,
167
+ "num_beams": 1,
168
+ "num_channels": 3,
169
+ "num_hidden_layers": 24,
170
+ "num_return_sequences": 1,
171
+ "output_attentions": false,
172
+ "output_hidden_states": false,
173
+ "output_scores": false,
174
+ "pad_token_id": null,
175
+ "patch_size": 14,
176
+ "prefix": null,
177
+ "problem_type": null,
178
+ "pruned_heads": {},
179
+ "qk_normalization": false,
180
+ "qkv_bias": true,
181
+ "remove_invalid_values": false,
182
+ "repetition_penalty": 1.0,
183
+ "return_dict": true,
184
+ "return_dict_in_generate": false,
185
+ "sep_token_id": null,
186
+ "suppress_tokens": null,
187
+ "task_specific_params": null,
188
+ "temperature": 1.0,
189
+ "tf_legacy_loss": false,
190
+ "tie_encoder_decoder": false,
191
+ "tie_word_embeddings": true,
192
+ "tokenizer_class": null,
193
+ "top_k": 50,
194
+ "top_p": 1.0,
195
+ "torch_dtype": "bfloat16",
196
+ "torchscript": false,
197
+ "transformers_version": "4.46.3",
198
+ "typical_p": 1.0,
199
+ "use_bfloat16": true,
200
+ "use_flash_attn": false
201
+ }
202
+ }
configuration_intern_vit.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # --------------------------------------------------------
2
+ # InternVL
3
+ # Copyright (c) 2024 OpenGVLab
4
+ # Licensed under The MIT License [see LICENSE for details]
5
+ # --------------------------------------------------------
6
+
7
+ import os
8
+ from typing import Union
9
+
10
+ from transformers.configuration_utils import PretrainedConfig
11
+ from transformers.utils import logging
12
+
13
+ logger = logging.get_logger(__name__)
14
+
15
+
16
+ class InternVisionConfig(PretrainedConfig):
17
+ r"""
18
+ This is the configuration class to store the configuration of a [`InternVisionModel`]. It is used to
19
+ instantiate a vision encoder according to the specified arguments, defining the model architecture.
20
+
21
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
22
+ documentation from [`PretrainedConfig`] for more information.
23
+
24
+ Args:
25
+ num_channels (`int`, *optional*, defaults to 3):
26
+ Number of color channels in the input images (e.g., 3 for RGB).
27
+ patch_size (`int`, *optional*, defaults to 14):
28
+ The size (resolution) of each patch.
29
+ image_size (`int`, *optional*, defaults to 224):
30
+ The size (resolution) of each image.
31
+ qkv_bias (`bool`, *optional*, defaults to `False`):
32
+ Whether to add a bias to the queries and values in the self-attention layers.
33
+ hidden_size (`int`, *optional*, defaults to 3200):
34
+ Dimensionality of the encoder layers and the pooler layer.
35
+ num_attention_heads (`int`, *optional*, defaults to 25):
36
+ Number of attention heads for each attention layer in the Transformer encoder.
37
+ intermediate_size (`int`, *optional*, defaults to 12800):
38
+ Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
39
+ qk_normalization (`bool`, *optional*, defaults to `True`):
40
+ Whether to normalize the queries and keys in the self-attention layers.
41
+ num_hidden_layers (`int`, *optional*, defaults to 48):
42
+ Number of hidden layers in the Transformer encoder.
43
+ use_flash_attn (`bool`, *optional*, defaults to `True`):
44
+ Whether to use flash attention mechanism.
45
+ hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
46
+ The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
47
+ `"relu"`, `"selu"` and `"gelu_new"` ``"gelu"` are supported.
48
+ layer_norm_eps (`float`, *optional*, defaults to 1e-6):
49
+ The epsilon used by the layer normalization layers.
50
+ dropout (`float`, *optional*, defaults to 0.0):
51
+ The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
52
+ drop_path_rate (`float`, *optional*, defaults to 0.0):
53
+ Dropout rate for stochastic depth.
54
+ attention_dropout (`float`, *optional*, defaults to 0.0):
55
+ The dropout ratio for the attention probabilities.
56
+ initializer_range (`float`, *optional*, defaults to 0.02):
57
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
58
+ initializer_factor (`float`, *optional*, defaults to 0.1):
59
+ A factor for layer scale.
60
+ """
61
+
62
+ model_type = 'intern_vit_6b'
63
+
64
+ def __init__(
65
+ self,
66
+ num_channels=3,
67
+ patch_size=14,
68
+ image_size=224,
69
+ qkv_bias=False,
70
+ hidden_size=3200,
71
+ num_attention_heads=25,
72
+ intermediate_size=12800,
73
+ qk_normalization=True,
74
+ num_hidden_layers=48,
75
+ use_flash_attn=True,
76
+ hidden_act='gelu',
77
+ norm_type='rms_norm',
78
+ layer_norm_eps=1e-6,
79
+ dropout=0.0,
80
+ drop_path_rate=0.0,
81
+ attention_dropout=0.0,
82
+ initializer_range=0.02,
83
+ initializer_factor=0.1,
84
+ **kwargs,
85
+ ):
86
+ super().__init__(**kwargs)
87
+
88
+ self.hidden_size = hidden_size
89
+ self.intermediate_size = intermediate_size
90
+ self.dropout = dropout
91
+ self.drop_path_rate = drop_path_rate
92
+ self.num_hidden_layers = num_hidden_layers
93
+ self.num_attention_heads = num_attention_heads
94
+ self.num_channels = num_channels
95
+ self.patch_size = patch_size
96
+ self.image_size = image_size
97
+ self.initializer_range = initializer_range
98
+ self.initializer_factor = initializer_factor
99
+ self.attention_dropout = attention_dropout
100
+ self.layer_norm_eps = layer_norm_eps
101
+ self.hidden_act = hidden_act
102
+ self.norm_type = norm_type
103
+ self.qkv_bias = qkv_bias
104
+ self.qk_normalization = qk_normalization
105
+ self.use_flash_attn = use_flash_attn
106
+
107
+ @classmethod
108
+ def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs) -> 'PretrainedConfig':
109
+ config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)
110
+
111
+ if 'vision_config' in config_dict:
112
+ config_dict = config_dict['vision_config']
113
+
114
+ if 'model_type' in config_dict and hasattr(cls, 'model_type') and config_dict['model_type'] != cls.model_type:
115
+ logger.warning(
116
+ f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
117
+ f'{cls.model_type}. This is not supported for all configurations of models and can yield errors.'
118
+ )
119
+
120
+ return cls.from_dict(config_dict, **kwargs)
configuration_internlm2.py ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) The InternLM team and The HuggingFace Inc. team. All rights reserved.
2
+ #
3
+ # This code is based on transformers/src/transformers/models/llama/configuration_llama.py
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ """ InternLM2 model configuration"""
17
+
18
+ from transformers.configuration_utils import PretrainedConfig
19
+ from transformers.utils import logging
20
+
21
+ logger = logging.get_logger(__name__)
22
+
23
+ INTERNLM2_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
24
+
25
+
26
+ # Modified from transformers.model.llama.configuration_llama.LlamaConfig
27
+ class InternLM2Config(PretrainedConfig):
28
+ r"""
29
+ This is the configuration class to store the configuration of a [`InternLM2Model`]. It is used to instantiate
30
+ an InternLM2 model according to the specified arguments, defining the model architecture. Instantiating a
31
+ configuration with the defaults will yield a similar configuration to that of the InternLM2-7B.
32
+
33
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
34
+ documentation from [`PretrainedConfig`] for more information.
35
+
36
+
37
+ Args:
38
+ vocab_size (`int`, *optional*, defaults to 32000):
39
+ Vocabulary size of the InternLM2 model. Defines the number of different tokens that can be represented by the
40
+ `inputs_ids` passed when calling [`InternLM2Model`]
41
+ hidden_size (`int`, *optional*, defaults to 4096):
42
+ Dimension of the hidden representations.
43
+ intermediate_size (`int`, *optional*, defaults to 11008):
44
+ Dimension of the MLP representations.
45
+ num_hidden_layers (`int`, *optional*, defaults to 32):
46
+ Number of hidden layers in the Transformer encoder.
47
+ num_attention_heads (`int`, *optional*, defaults to 32):
48
+ Number of attention heads for each attention layer in the Transformer encoder.
49
+ num_key_value_heads (`int`, *optional*):
50
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
51
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
52
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
53
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
54
+ by meanpooling all the original heads within that group. For more details checkout [this
55
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
56
+ `num_attention_heads`.
57
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
58
+ The non-linear activation function (function or string) in the decoder.
59
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
60
+ The maximum sequence length that this model might ever be used with. Typically set this to something large
61
+ just in case (e.g., 512 or 1024 or 2048).
62
+ initializer_range (`float`, *optional*, defaults to 0.02):
63
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
64
+ rms_norm_eps (`float`, *optional*, defaults to 1e-12):
65
+ The epsilon used by the rms normalization layers.
66
+ use_cache (`bool`, *optional*, defaults to `True`):
67
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
68
+ relevant if `config.is_decoder=True`.
69
+ tie_word_embeddings(`bool`, *optional*, defaults to `False`):
70
+ Whether to tie weight embeddings
71
+ Example:
72
+
73
+ """
74
+ model_type = 'internlm2'
75
+ _auto_class = 'AutoConfig'
76
+
77
+ def __init__( # pylint: disable=W0102
78
+ self,
79
+ vocab_size=103168,
80
+ hidden_size=4096,
81
+ intermediate_size=11008,
82
+ num_hidden_layers=32,
83
+ num_attention_heads=32,
84
+ num_key_value_heads=None,
85
+ hidden_act='silu',
86
+ max_position_embeddings=2048,
87
+ initializer_range=0.02,
88
+ rms_norm_eps=1e-6,
89
+ use_cache=True,
90
+ pad_token_id=0,
91
+ bos_token_id=1,
92
+ eos_token_id=2,
93
+ tie_word_embeddings=False,
94
+ bias=True,
95
+ rope_theta=10000,
96
+ rope_scaling=None,
97
+ attn_implementation='eager',
98
+ **kwargs,
99
+ ):
100
+ self.vocab_size = vocab_size
101
+ self.max_position_embeddings = max_position_embeddings
102
+ self.hidden_size = hidden_size
103
+ self.intermediate_size = intermediate_size
104
+ self.num_hidden_layers = num_hidden_layers
105
+ self.num_attention_heads = num_attention_heads
106
+ self.bias = bias
107
+
108
+ if num_key_value_heads is None:
109
+ num_key_value_heads = num_attention_heads
110
+ self.num_key_value_heads = num_key_value_heads
111
+
112
+ self.hidden_act = hidden_act
113
+ self.initializer_range = initializer_range
114
+ self.rms_norm_eps = rms_norm_eps
115
+ self.use_cache = use_cache
116
+ self.rope_theta = rope_theta
117
+ self.rope_scaling = rope_scaling
118
+ self._rope_scaling_validation()
119
+
120
+ self.attn_implementation = attn_implementation
121
+ if self.attn_implementation is None:
122
+ self.attn_implementation = 'eager'
123
+ super().__init__(
124
+ pad_token_id=pad_token_id,
125
+ bos_token_id=bos_token_id,
126
+ eos_token_id=eos_token_id,
127
+ tie_word_embeddings=tie_word_embeddings,
128
+ **kwargs,
129
+ )
130
+
131
+ def _rope_scaling_validation(self):
132
+ """
133
+ Validate the `rope_scaling` configuration.
134
+ """
135
+ if self.rope_scaling is None:
136
+ return
137
+
138
+ if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
139
+ raise ValueError(
140
+ '`rope_scaling` must be a dictionary with with two fields, `type` and `factor`, '
141
+ f'got {self.rope_scaling}'
142
+ )
143
+ rope_scaling_type = self.rope_scaling.get('type', None)
144
+ rope_scaling_factor = self.rope_scaling.get('factor', None)
145
+ if rope_scaling_type is None or rope_scaling_type not in ['linear', 'dynamic']:
146
+ raise ValueError(
147
+ f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
148
+ )
149
+ if rope_scaling_factor is None or not isinstance(rope_scaling_factor, float) or rope_scaling_factor < 1.0:
150
+ raise ValueError(f"`rope_scaling`'s factor field must be a float >= 1, got {rope_scaling_factor}")
configuration_internvl_chat.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # --------------------------------------------------------
2
+ # InternVL
3
+ # Copyright (c) 2024 OpenGVLab
4
+ # Licensed under The MIT License [see LICENSE for details]
5
+ # --------------------------------------------------------
6
+
7
+ import copy
8
+
9
+ from transformers import AutoConfig, LlamaConfig
10
+ from transformers.configuration_utils import PretrainedConfig
11
+ from transformers.utils import logging
12
+
13
+ from .configuration_intern_vit import InternVisionConfig
14
+ from .configuration_internlm2 import InternLM2Config
15
+
16
+ logger = logging.get_logger(__name__)
17
+
18
+
19
+ class InternVLChatConfig(PretrainedConfig):
20
+ model_type = 'internvl_chat'
21
+ is_composition = True
22
+
23
+ def __init__(
24
+ self,
25
+ vision_config=None,
26
+ llm_config=None,
27
+ use_backbone_lora=0,
28
+ use_llm_lora=0,
29
+ select_layer=-1,
30
+ force_image_size=None,
31
+ downsample_ratio=0.5,
32
+ template=None,
33
+ dynamic_image_size=False,
34
+ use_thumbnail=False,
35
+ ps_version='v1',
36
+ min_dynamic_patch=1,
37
+ max_dynamic_patch=6,
38
+ **kwargs):
39
+ super().__init__(**kwargs)
40
+
41
+ if vision_config is None:
42
+ vision_config = {'architectures': ['InternVisionModel']}
43
+ logger.info('vision_config is None. Initializing the InternVisionConfig with default values.')
44
+
45
+ if llm_config is None:
46
+ llm_config = {'architectures': ['InternLM2ForCausalLM']}
47
+ logger.info('llm_config is None. Initializing the LlamaConfig config with default values (`LlamaConfig`).')
48
+
49
+ self.vision_config = InternVisionConfig(**vision_config)
50
+ if llm_config.get('architectures')[0] == 'LlamaForCausalLM':
51
+ self.llm_config = LlamaConfig(**llm_config)
52
+ elif llm_config.get('architectures')[0] == 'InternLM2ForCausalLM':
53
+ self.llm_config = InternLM2Config(**llm_config)
54
+ else:
55
+ raise ValueError('Unsupported architecture: {}'.format(llm_config.get('architectures')[0]))
56
+ self.use_backbone_lora = use_backbone_lora
57
+ self.use_llm_lora = use_llm_lora
58
+ self.select_layer = select_layer
59
+ self.force_image_size = force_image_size
60
+ self.downsample_ratio = downsample_ratio
61
+ self.template = template
62
+ self.dynamic_image_size = dynamic_image_size
63
+ self.use_thumbnail = use_thumbnail
64
+ self.ps_version = ps_version # pixel shuffle version
65
+ self.min_dynamic_patch = min_dynamic_patch
66
+ self.max_dynamic_patch = max_dynamic_patch
67
+
68
+ logger.info(f'vision_select_layer: {self.select_layer}')
69
+ logger.info(f'ps_version: {self.ps_version}')
70
+ logger.info(f'min_dynamic_patch: {self.min_dynamic_patch}')
71
+ logger.info(f'max_dynamic_patch: {self.max_dynamic_patch}')
72
+
73
+ def to_dict(self):
74
+ """
75
+ Serializes this instance to a Python dictionary. Override the default [`~PretrainedConfig.to_dict`].
76
+
77
+ Returns:
78
+ `Dict[str, any]`: Dictionary of all the attributes that make up this configuration instance,
79
+ """
80
+ output = copy.deepcopy(self.__dict__)
81
+ output['vision_config'] = self.vision_config.to_dict()
82
+ output['llm_config'] = self.llm_config.to_dict()
83
+ output['model_type'] = self.__class__.model_type
84
+ output['use_backbone_lora'] = self.use_backbone_lora
85
+ output['use_llm_lora'] = self.use_llm_lora
86
+ output['select_layer'] = self.select_layer
87
+ output['force_image_size'] = self.force_image_size
88
+ output['downsample_ratio'] = self.downsample_ratio
89
+ output['template'] = self.template
90
+ output['dynamic_image_size'] = self.dynamic_image_size
91
+ output['use_thumbnail'] = self.use_thumbnail
92
+ output['ps_version'] = self.ps_version
93
+ output['min_dynamic_patch'] = self.min_dynamic_patch
94
+ output['max_dynamic_patch'] = self.max_dynamic_patch
95
+
96
+ return output
generation_config.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "eos_token_id": [
4
+ 92542,
5
+ 92543
6
+ ],
7
+ "transformers_version": "4.46.3"
8
+ }
openvino_config.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "compression": null,
3
+ "dtype": "int4",
4
+ "input_info": null,
5
+ "optimum_version": "1.23.3",
6
+ "quantization_config": {
7
+ "all_layers": null,
8
+ "backup_precision": null,
9
+ "bits": 4,
10
+ "dataset": null,
11
+ "gptq": null,
12
+ "group_size": 128,
13
+ "ignored_scope": null,
14
+ "lora_correction": null,
15
+ "num_samples": null,
16
+ "processor": null,
17
+ "quant_method": "default",
18
+ "ratio": 1.0,
19
+ "scale_estimation": null,
20
+ "sensitivity_metric": null,
21
+ "sym": false,
22
+ "tokenizer": null,
23
+ "trust_remote_code": false,
24
+ "weight_format": "int4"
25
+ },
26
+ "save_onnx_model": false,
27
+ "transformers_version": "4.46.3"
28
+ }
openvino_detokenizer.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9d99982bd38cc642f98134aabf7650a1ce0d28e7978c945c238d7620a8260d29
3
+ size 1477889
openvino_detokenizer.xml ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <net name="detokenizer" version="11">
3
+ <layers>
4
+ <layer id="0" name="Parameter_193492" type="Parameter" version="opset1">
5
+ <data shape="?,?" element_type="i64" />
6
+ <output>
7
+ <port id="0" precision="I64" names="Parameter_193492">
8
+ <dim>-1</dim>
9
+ <dim>-1</dim>
10
+ </port>
11
+ </output>
12
+ </layer>
13
+ <layer id="1" name="Constant_193415" type="Const" version="opset1">
14
+ <data element_type="u8" shape="1477889" offset="0" size="1477889" />
15
+ <output>
16
+ <port id="0" precision="U8">
17
+ <dim>1477889</dim>
18
+ </port>
19
+ </output>
20
+ </layer>
21
+ <layer id="2" name="Convert_193503" type="Convert" version="opset1">
22
+ <data destination_type="i32" />
23
+ <input>
24
+ <port id="0" precision="I64">
25
+ <dim>-1</dim>
26
+ <dim>-1</dim>
27
+ </port>
28
+ </input>
29
+ <output>
30
+ <port id="1" precision="I32">
31
+ <dim>-1</dim>
32
+ <dim>-1</dim>
33
+ </port>
34
+ </output>
35
+ </layer>
36
+ <layer id="3" name="SentencepieceDetokenizer_193493" type="SentencepieceDetokenizer" version="extension">
37
+ <input>
38
+ <port id="0" precision="U8">
39
+ <dim>1477889</dim>
40
+ </port>
41
+ <port id="1" precision="I32">
42
+ <dim>-1</dim>
43
+ <dim>-1</dim>
44
+ </port>
45
+ </input>
46
+ <output>
47
+ <port id="2" precision="I32">
48
+ <dim>-1</dim>
49
+ </port>
50
+ <port id="3" precision="I32">
51
+ <dim>-1</dim>
52
+ </port>
53
+ <port id="4" precision="U8">
54
+ <dim>-1</dim>
55
+ </port>
56
+ </output>
57
+ </layer>
58
+ <layer id="4" name="UTF8Validate_193494" type="UTF8Validate" version="extension">
59
+ <data replace_mode="true" />
60
+ <input>
61
+ <port id="0" precision="I32">
62
+ <dim>-1</dim>
63
+ </port>
64
+ <port id="1" precision="I32">
65
+ <dim>-1</dim>
66
+ </port>
67
+ <port id="2" precision="U8">
68
+ <dim>-1</dim>
69
+ </port>
70
+ </input>
71
+ <output>
72
+ <port id="3" precision="I32">
73
+ <dim>-1</dim>
74
+ </port>
75
+ <port id="4" precision="I32">
76
+ <dim>-1</dim>
77
+ </port>
78
+ <port id="5" precision="U8">
79
+ <dim>-1</dim>
80
+ </port>
81
+ </output>
82
+ </layer>
83
+ <layer id="5" name="StringTensorPack_193495" type="StringTensorPack" version="extension">
84
+ <data mode="begins_ends" />
85
+ <input>
86
+ <port id="0" precision="I32">
87
+ <dim>-1</dim>
88
+ </port>
89
+ <port id="1" precision="I32">
90
+ <dim>-1</dim>
91
+ </port>
92
+ <port id="2" precision="U8">
93
+ <dim>-1</dim>
94
+ </port>
95
+ </input>
96
+ <output>
97
+ <port id="3" precision="STRING" names="string_output">
98
+ <dim>-1</dim>
99
+ </port>
100
+ </output>
101
+ </layer>
102
+ <layer id="6" name="Result_193496" type="Result" version="opset1">
103
+ <input>
104
+ <port id="0" precision="STRING">
105
+ <dim>-1</dim>
106
+ </port>
107
+ </input>
108
+ </layer>
109
+ </layers>
110
+ <edges>
111
+ <edge from-layer="0" from-port="0" to-layer="2" to-port="0" />
112
+ <edge from-layer="1" from-port="0" to-layer="3" to-port="0" />
113
+ <edge from-layer="2" from-port="1" to-layer="3" to-port="1" />
114
+ <edge from-layer="3" from-port="2" to-layer="4" to-port="0" />
115
+ <edge from-layer="3" from-port="3" to-layer="4" to-port="1" />
116
+ <edge from-layer="3" from-port="4" to-layer="4" to-port="2" />
117
+ <edge from-layer="4" from-port="3" to-layer="5" to-port="0" />
118
+ <edge from-layer="4" from-port="4" to-layer="5" to-port="1" />
119
+ <edge from-layer="4" from-port="5" to-layer="5" to-port="2" />
120
+ <edge from-layer="5" from-port="3" to-layer="6" to-port="0" />
121
+ </edges>
122
+ <rt_info>
123
+ <add_attention_mask value="True" />
124
+ <add_prefix_space />
125
+ <add_special_tokens value="True" />
126
+ <bos_token_id value="1" />
127
+ <chat_template value="{{ bos_token }}{% for message in messages %}{{'&lt;|im_start|>' + message['role'] + '&#10;' + message['content'] + '&lt;|im_end|>' + '&#10;'}}{% endfor %}{% if add_generation_prompt %}{{ '&lt;|im_start|>assistant&#10;' }}{% endif %}" />
128
+ <clean_up_tokenization_spaces value="False" />
129
+ <detokenizer_input_type value="i64" />
130
+ <eos_token_id value="2" />
131
+ <handle_special_tokens_with_re value="True" />
132
+ <number_of_inputs value="1" />
133
+ <openvino_tokenizers_version value="2024.6.0.0" />
134
+ <openvino_version value="2024.6.0" />
135
+ <original_tokenizer_class value="&lt;class 'transformers_modules.OpenGVLab.InternVL2-2B.aec61df8c99ba7c81271877485e038a7b823a399.tokenization_internlm2.InternLM2Tokenizer'>" />
136
+ <pad_token_id value="2" />
137
+ <sentencepiece_version value="0.2.0" />
138
+ <skip_special_tokens value="True" />
139
+ <streaming_detokenizer value="False" />
140
+ <tiktoken_version value="0.8.0" />
141
+ <tokenizer_output_type value="i64" />
142
+ <tokenizers_version value="0.20.3" />
143
+ <transformers_version value="4.46.3" />
144
+ <use_max_padding value="False" />
145
+ <use_sentencepiece_backend value="False" />
146
+ <utf8_replace_mode value="replace" />
147
+ <with_detokenizer value="True" />
148
+ </rt_info>
149
+ </net>
openvino_language_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:712afc5db0a6607d26007736304fb50a315f034a2480ada2b740971c0d838b13
3
+ size 1008248291
openvino_language_model.xml ADDED
The diff for this file is too large to render. See raw diff
 
openvino_text_embeddings_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ebdb511e3d90fc6560bf49883ecead8f05562d83311fdcc806f464b6bed82fc6
3
+ size 189733654
openvino_text_embeddings_model.xml ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <net name="Model6" version="11">
3
+ <layers>
4
+ <layer id="0" name="input" type="Parameter" version="opset1">
5
+ <data shape="?,?" element_type="i64" />
6
+ <output>
7
+ <port id="0" precision="I64" names="input">
8
+ <dim>-1</dim>
9
+ <dim>-1</dim>
10
+ </port>
11
+ </output>
12
+ </layer>
13
+ <layer id="1" name="self.weight" type="Const" version="opset1">
14
+ <data element_type="i8" shape="92553, 2048" offset="0" size="189548544" />
15
+ <output>
16
+ <port id="0" precision="I8">
17
+ <dim>92553</dim>
18
+ <dim>2048</dim>
19
+ </port>
20
+ </output>
21
+ </layer>
22
+ <layer id="2" name="Convert_187523" type="Convert" version="opset1">
23
+ <data destination_type="f16" />
24
+ <input>
25
+ <port id="0" precision="I8">
26
+ <dim>92553</dim>
27
+ <dim>2048</dim>
28
+ </port>
29
+ </input>
30
+ <output>
31
+ <port id="1" precision="FP16">
32
+ <dim>92553</dim>
33
+ <dim>2048</dim>
34
+ </port>
35
+ </output>
36
+ </layer>
37
+ <layer id="3" name="self.weight/scale" type="Const" version="opset1">
38
+ <data element_type="f16" shape="92553, 1" offset="189548544" size="185106" />
39
+ <output>
40
+ <port id="0" precision="FP16">
41
+ <dim>92553</dim>
42
+ <dim>1</dim>
43
+ </port>
44
+ </output>
45
+ </layer>
46
+ <layer id="4" name="self.weight/fq_weights_0" type="Multiply" version="opset1">
47
+ <data auto_broadcast="numpy" />
48
+ <input>
49
+ <port id="0" precision="FP16">
50
+ <dim>92553</dim>
51
+ <dim>2048</dim>
52
+ </port>
53
+ <port id="1" precision="FP16">
54
+ <dim>92553</dim>
55
+ <dim>1</dim>
56
+ </port>
57
+ </input>
58
+ <output>
59
+ <port id="2" precision="FP16">
60
+ <dim>92553</dim>
61
+ <dim>2048</dim>
62
+ </port>
63
+ </output>
64
+ </layer>
65
+ <layer id="5" name="self.weight/fq_weights_0/convert" type="Convert" version="opset1">
66
+ <data destination_type="f32" />
67
+ <input>
68
+ <port id="0" precision="FP16">
69
+ <dim>92553</dim>
70
+ <dim>2048</dim>
71
+ </port>
72
+ </input>
73
+ <output>
74
+ <port id="1" precision="FP32">
75
+ <dim>92553</dim>
76
+ <dim>2048</dim>
77
+ </port>
78
+ </output>
79
+ </layer>
80
+ <layer id="6" name="aten::embedding/Convert" type="Convert" version="opset1">
81
+ <data destination_type="i32" />
82
+ <input>
83
+ <port id="0" precision="I64">
84
+ <dim>-1</dim>
85
+ <dim>-1</dim>
86
+ </port>
87
+ </input>
88
+ <output>
89
+ <port id="1" precision="I32">
90
+ <dim>-1</dim>
91
+ <dim>-1</dim>
92
+ </port>
93
+ </output>
94
+ </layer>
95
+ <layer id="7" name="aten::embedding/Constant" type="Const" version="opset1">
96
+ <data element_type="i32" shape="" offset="189733650" size="4" />
97
+ <output>
98
+ <port id="0" precision="I32" />
99
+ </output>
100
+ </layer>
101
+ <layer id="8" name="aten::embedding/Gather" type="Gather" version="opset8">
102
+ <data batch_dims="0" />
103
+ <input>
104
+ <port id="0" precision="FP32">
105
+ <dim>92553</dim>
106
+ <dim>2048</dim>
107
+ </port>
108
+ <port id="1" precision="I32">
109
+ <dim>-1</dim>
110
+ <dim>-1</dim>
111
+ </port>
112
+ <port id="2" precision="I32" />
113
+ </input>
114
+ <output>
115
+ <port id="3" precision="FP32" names="inputs_embeds">
116
+ <dim>-1</dim>
117
+ <dim>-1</dim>
118
+ <dim>2048</dim>
119
+ </port>
120
+ </output>
121
+ </layer>
122
+ <layer id="9" name="Result_161493" type="Result" version="opset1">
123
+ <input>
124
+ <port id="0" precision="FP32">
125
+ <dim>-1</dim>
126
+ <dim>-1</dim>
127
+ <dim>2048</dim>
128
+ </port>
129
+ </input>
130
+ </layer>
131
+ </layers>
132
+ <edges>
133
+ <edge from-layer="0" from-port="0" to-layer="6" to-port="0" />
134
+ <edge from-layer="1" from-port="0" to-layer="2" to-port="0" />
135
+ <edge from-layer="2" from-port="1" to-layer="4" to-port="0" />
136
+ <edge from-layer="3" from-port="0" to-layer="4" to-port="1" />
137
+ <edge from-layer="4" from-port="2" to-layer="5" to-port="0" />
138
+ <edge from-layer="5" from-port="1" to-layer="8" to-port="0" />
139
+ <edge from-layer="6" from-port="1" to-layer="8" to-port="1" />
140
+ <edge from-layer="7" from-port="0" to-layer="8" to-port="2" />
141
+ <edge from-layer="8" from-port="3" to-layer="9" to-port="0" />
142
+ </edges>
143
+ <rt_info>
144
+ <Runtime_version value="2024.6.0-17404-4c0f47d2335-releases/2024/6" />
145
+ <conversion_parameters>
146
+ <framework value="pytorch" />
147
+ <is_python_object value="True" />
148
+ </conversion_parameters>
149
+ <nncf>
150
+ <friendly_names_were_updated value="True" />
151
+ <weight_compression>
152
+ <advanced_parameters value="{'statistics_path': None, 'awq_params': {'subset_size': 32, 'percent_to_apply': 0.002, 'alpha_min': 0.0, 'alpha_max': 1.0, 'steps': 100}, 'scale_estimation_params': {'subset_size': 64, 'initial_steps': 5, 'scale_steps': 5, 'weight_penalty': -1.0}, 'gptq_params': {'damp_percent': 0.1, 'block_size': 128, 'subset_size': 128}, 'lora_correction_params': {'adapter_rank': 8, 'num_iterations': 3, 'apply_regularization': True, 'subset_size': 128, 'use_int8_adapters': True}}" />
153
+ <all_layers value="False" />
154
+ <awq value="False" />
155
+ <backup_mode value="int8_asym" />
156
+ <gptq value="False" />
157
+ <group_size value="-1" />
158
+ <ignored_scope value="[]" />
159
+ <lora_correction value="False" />
160
+ <mode value="int8_sym" />
161
+ <ratio value="1.0" />
162
+ <scale_estimation value="False" />
163
+ <sensitivity_metric value="weight_quantization_error" />
164
+ </weight_compression>
165
+ </nncf>
166
+ <optimum>
167
+ <optimum_intel_version value="1.22.0.dev0+422ffe0" />
168
+ <optimum_version value="1.23.3" />
169
+ <pytorch_version value="2.5.1+cpu" />
170
+ <transformers_version value="4.46.3" />
171
+ </optimum>
172
+ </rt_info>
173
+ </net>
openvino_tokenizer.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:97a91243736a42ca8d8cd78cc947c18e70875ac6009cad40a3c0664d110d1e55
3
+ size 1478281
openvino_tokenizer.xml ADDED
@@ -0,0 +1,1029 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <net name="tokenizer" version="11">
3
+ <layers>
4
+ <layer id="0" name="string_input" type="Parameter" version="opset1">
5
+ <data shape="?" element_type="string" />
6
+ <output>
7
+ <port id="0" precision="STRING" names="string_input">
8
+ <dim>-1</dim>
9
+ </port>
10
+ </output>
11
+ </layer>
12
+ <layer id="1" name="Constant_193470" type="Const" version="opset1">
13
+ <data element_type="i32" shape="" offset="0" size="4" />
14
+ <output>
15
+ <port id="0" precision="I32" />
16
+ </output>
17
+ </layer>
18
+ <layer id="2" name="Constant_193414" type="Const" version="opset1">
19
+ <data element_type="u8" shape="1477889" offset="4" size="1477889" />
20
+ <output>
21
+ <port id="0" precision="U8">
22
+ <dim>1477889</dim>
23
+ </port>
24
+ </output>
25
+ </layer>
26
+ <layer id="3" name="Constant_193418" type="Const" version="opset1">
27
+ <data element_type="u8" shape="228" offset="1477893" size="228" />
28
+ <output>
29
+ <port id="0" precision="U8">
30
+ <dim>228</dim>
31
+ </port>
32
+ </output>
33
+ </layer>
34
+ <layer id="4" name="StringTensorUnpack_193419" type="StringTensorUnpack" version="extension">
35
+ <data mode="begins_ends" />
36
+ <input>
37
+ <port id="0" precision="U8">
38
+ <dim>228</dim>
39
+ </port>
40
+ </input>
41
+ <output>
42
+ <port id="1" precision="I32">
43
+ <dim>-1</dim>
44
+ </port>
45
+ <port id="2" precision="I32">
46
+ <dim>-1</dim>
47
+ </port>
48
+ <port id="3" precision="U8">
49
+ <dim>-1</dim>
50
+ </port>
51
+ </output>
52
+ </layer>
53
+ <layer id="5" name="Constant_193420" type="Const" version="opset1">
54
+ <data element_type="i32" shape="18" offset="1478121" size="72" />
55
+ <output>
56
+ <port id="0" precision="I32">
57
+ <dim>18</dim>
58
+ </port>
59
+ </output>
60
+ </layer>
61
+ <layer id="6" name="SentencepieceTokenizer_193421" type="SentencepieceTokenizer" version="extension">
62
+ <data nbest_size="0" alpha="0" add_bos="false" add_eos="false" reverse="false" />
63
+ <input>
64
+ <port id="0" precision="U8">
65
+ <dim>1477889</dim>
66
+ </port>
67
+ <port id="1" precision="STRING">
68
+ <dim>-1</dim>
69
+ </port>
70
+ <port id="2" precision="I32">
71
+ <dim>-1</dim>
72
+ </port>
73
+ <port id="3" precision="I32">
74
+ <dim>-1</dim>
75
+ </port>
76
+ <port id="4" precision="U8">
77
+ <dim>-1</dim>
78
+ </port>
79
+ <port id="5" precision="I32">
80
+ <dim>18</dim>
81
+ </port>
82
+ </input>
83
+ <output>
84
+ <port id="6" precision="I64">
85
+ <dim>-1</dim>
86
+ <dim>2</dim>
87
+ </port>
88
+ <port id="7" precision="I32">
89
+ <dim>-1</dim>
90
+ </port>
91
+ <port id="8" precision="I64">
92
+ <dim>2</dim>
93
+ </port>
94
+ </output>
95
+ </layer>
96
+ <layer id="7" name="Constant_193430" type="Const" version="opset1">
97
+ <data element_type="i64" shape="2" offset="1478193" size="16" />
98
+ <output>
99
+ <port id="0" precision="I64">
100
+ <dim>2</dim>
101
+ </port>
102
+ </output>
103
+ </layer>
104
+ <layer id="8" name="Convert_193431" type="Convert" version="opset1">
105
+ <data destination_type="i64" />
106
+ <input>
107
+ <port id="0" precision="I64">
108
+ <dim>2</dim>
109
+ </port>
110
+ </input>
111
+ <output>
112
+ <port id="1" precision="I64">
113
+ <dim>2</dim>
114
+ </port>
115
+ </output>
116
+ </layer>
117
+ <layer id="9" name="Add_193432" type="Add" version="opset1">
118
+ <data auto_broadcast="numpy" />
119
+ <input>
120
+ <port id="0" precision="I64">
121
+ <dim>2</dim>
122
+ </port>
123
+ <port id="1" precision="I64">
124
+ <dim>2</dim>
125
+ </port>
126
+ </input>
127
+ <output>
128
+ <port id="2" precision="I64">
129
+ <dim>2</dim>
130
+ </port>
131
+ </output>
132
+ </layer>
133
+ <layer id="10" name="Constant_193437" type="Const" version="opset1">
134
+ <data element_type="i64" shape="1" offset="1478209" size="8" />
135
+ <output>
136
+ <port id="0" precision="I64">
137
+ <dim>1</dim>
138
+ </port>
139
+ </output>
140
+ </layer>
141
+ <layer id="11" name="Constant_193438" type="Const" version="opset1">
142
+ <data element_type="i64" shape="1" offset="1478217" size="8" />
143
+ <output>
144
+ <port id="0" precision="I64">
145
+ <dim>1</dim>
146
+ </port>
147
+ </output>
148
+ </layer>
149
+ <layer id="12" name="Constant_193439" type="Const" version="opset1">
150
+ <data element_type="i64" shape="1" offset="1478217" size="8" />
151
+ <output>
152
+ <port id="0" precision="I64">
153
+ <dim>1</dim>
154
+ </port>
155
+ </output>
156
+ </layer>
157
+ <layer id="13" name="Constant_193441" type="Const" version="opset1">
158
+ <data element_type="i64" shape="1" offset="1478209" size="8" />
159
+ <output>
160
+ <port id="0" precision="I64">
161
+ <dim>1</dim>
162
+ </port>
163
+ </output>
164
+ </layer>
165
+ <layer id="14" name="Slice_193440" type="Slice" version="opset8">
166
+ <input>
167
+ <port id="0" precision="I64">
168
+ <dim>2</dim>
169
+ </port>
170
+ <port id="1" precision="I64">
171
+ <dim>1</dim>
172
+ </port>
173
+ <port id="2" precision="I64">
174
+ <dim>1</dim>
175
+ </port>
176
+ <port id="3" precision="I64">
177
+ <dim>1</dim>
178
+ </port>
179
+ <port id="4" precision="I64">
180
+ <dim>1</dim>
181
+ </port>
182
+ </input>
183
+ <output>
184
+ <port id="5" precision="I64">
185
+ <dim>1</dim>
186
+ </port>
187
+ </output>
188
+ </layer>
189
+ <layer id="15" name="Constant_193471" type="Const" version="opset1">
190
+ <data element_type="i64" shape="1" offset="1478217" size="8" />
191
+ <output>
192
+ <port id="0" precision="I64">
193
+ <dim>1</dim>
194
+ </port>
195
+ </output>
196
+ </layer>
197
+ <layer id="16" name="Concat_193472" type="Concat" version="opset1">
198
+ <data axis="0" />
199
+ <input>
200
+ <port id="0" precision="I64">
201
+ <dim>1</dim>
202
+ </port>
203
+ <port id="1" precision="I64">
204
+ <dim>1</dim>
205
+ </port>
206
+ </input>
207
+ <output>
208
+ <port id="2" precision="I64">
209
+ <dim>2</dim>
210
+ </port>
211
+ </output>
212
+ </layer>
213
+ <layer id="17" name="Broadcast_193473" type="Broadcast" version="opset3">
214
+ <data mode="numpy" />
215
+ <input>
216
+ <port id="0" precision="I32" />
217
+ <port id="1" precision="I64">
218
+ <dim>2</dim>
219
+ </port>
220
+ </input>
221
+ <output>
222
+ <port id="2" precision="I32">
223
+ <dim>-1</dim>
224
+ <dim>1</dim>
225
+ </port>
226
+ </output>
227
+ </layer>
228
+ <layer id="18" name="Constant_193422" type="Const" version="opset1">
229
+ <data element_type="i32" shape="" offset="1478225" size="4" />
230
+ <output>
231
+ <port id="0" precision="I32" />
232
+ </output>
233
+ </layer>
234
+ <layer id="19" name="Broadcast_193423" type="Broadcast" version="opset3">
235
+ <data mode="numpy" />
236
+ <input>
237
+ <port id="0" precision="I32" />
238
+ <port id="1" precision="I64">
239
+ <dim>2</dim>
240
+ </port>
241
+ </input>
242
+ <output>
243
+ <port id="2" precision="I32">
244
+ <dim>-1</dim>
245
+ <dim>-1</dim>
246
+ </port>
247
+ </output>
248
+ </layer>
249
+ <layer id="20" name="Constant_193424" type="Const" version="opset1">
250
+ <data element_type="i32" shape="" offset="0" size="4" />
251
+ <output>
252
+ <port id="0" precision="I32" />
253
+ </output>
254
+ </layer>
255
+ <layer id="21" name="ShapeOf_193425" type="ShapeOf" version="opset3">
256
+ <data output_type="i64" />
257
+ <input>
258
+ <port id="0" precision="I32">
259
+ <dim>-1</dim>
260
+ </port>
261
+ </input>
262
+ <output>
263
+ <port id="1" precision="I64">
264
+ <dim>1</dim>
265
+ </port>
266
+ </output>
267
+ </layer>
268
+ <layer id="22" name="Broadcast_193426" type="Broadcast" version="opset3">
269
+ <data mode="numpy" />
270
+ <input>
271
+ <port id="0" precision="I32" />
272
+ <port id="1" precision="I64">
273
+ <dim>1</dim>
274
+ </port>
275
+ </input>
276
+ <output>
277
+ <port id="2" precision="I32">
278
+ <dim>-1</dim>
279
+ </port>
280
+ </output>
281
+ </layer>
282
+ <layer id="23" name="ScatterNDUpdate_193429" type="ScatterNDUpdate" version="opset4">
283
+ <input>
284
+ <port id="0" precision="I32">
285
+ <dim>-1</dim>
286
+ <dim>-1</dim>
287
+ </port>
288
+ <port id="1" precision="I64">
289
+ <dim>-1</dim>
290
+ <dim>2</dim>
291
+ </port>
292
+ <port id="2" precision="I32">
293
+ <dim>-1</dim>
294
+ </port>
295
+ </input>
296
+ <output>
297
+ <port id="3" precision="I32">
298
+ <dim>-1</dim>
299
+ <dim>-1</dim>
300
+ </port>
301
+ </output>
302
+ </layer>
303
+ <layer id="24" name="Concat_193474" type="Concat" version="opset1">
304
+ <data axis="1" />
305
+ <input>
306
+ <port id="0" precision="I32">
307
+ <dim>-1</dim>
308
+ <dim>1</dim>
309
+ </port>
310
+ <port id="1" precision="I32">
311
+ <dim>-1</dim>
312
+ <dim>-1</dim>
313
+ </port>
314
+ </input>
315
+ <output>
316
+ <port id="2" precision="I32">
317
+ <dim>-1</dim>
318
+ <dim>-1</dim>
319
+ </port>
320
+ </output>
321
+ </layer>
322
+ <layer id="25" name="Constant_193483" type="Const" version="opset1">
323
+ <data element_type="i64" shape="1" offset="1478209" size="8" />
324
+ <output>
325
+ <port id="0" precision="I64">
326
+ <dim>1</dim>
327
+ </port>
328
+ </output>
329
+ </layer>
330
+ <layer id="26" name="Constant_193484" type="Const" version="opset1">
331
+ <data element_type="i64" shape="1" offset="1478229" size="8" />
332
+ <output>
333
+ <port id="0" precision="I64">
334
+ <dim>1</dim>
335
+ </port>
336
+ </output>
337
+ </layer>
338
+ <layer id="27" name="Constant_193485" type="Const" version="opset1">
339
+ <data element_type="i64" shape="1" offset="1478217" size="8" />
340
+ <output>
341
+ <port id="0" precision="I64">
342
+ <dim>1</dim>
343
+ </port>
344
+ </output>
345
+ </layer>
346
+ <layer id="28" name="Constant_193486" type="Const" version="opset1">
347
+ <data element_type="i64" shape="1" offset="1478237" size="8" />
348
+ <output>
349
+ <port id="0" precision="I64">
350
+ <dim>1</dim>
351
+ </port>
352
+ </output>
353
+ </layer>
354
+ <layer id="29" name="Slice_193487" type="Slice" version="opset8">
355
+ <input>
356
+ <port id="0" precision="I32">
357
+ <dim>-1</dim>
358
+ <dim>-1</dim>
359
+ </port>
360
+ <port id="1" precision="I64">
361
+ <dim>1</dim>
362
+ </port>
363
+ <port id="2" precision="I64">
364
+ <dim>1</dim>
365
+ </port>
366
+ <port id="3" precision="I64">
367
+ <dim>1</dim>
368
+ </port>
369
+ <port id="4" precision="I64">
370
+ <dim>1</dim>
371
+ </port>
372
+ </input>
373
+ <output>
374
+ <port id="5" precision="I32">
375
+ <dim>-1</dim>
376
+ <dim>-1</dim>
377
+ </port>
378
+ </output>
379
+ </layer>
380
+ <layer id="30" name="Slice_193487" type="Convert" version="opset1">
381
+ <data destination_type="i64" />
382
+ <input>
383
+ <port id="0" precision="I32">
384
+ <dim>-1</dim>
385
+ <dim>-1</dim>
386
+ </port>
387
+ </input>
388
+ <output>
389
+ <port id="1" precision="I64" names="attention_mask">
390
+ <dim>-1</dim>
391
+ <dim>-1</dim>
392
+ </port>
393
+ </output>
394
+ </layer>
395
+ <layer id="32" name="Constant_193475" type="Const" version="opset1">
396
+ <data element_type="i32" shape="" offset="1478245" size="4" />
397
+ <output>
398
+ <port id="0" precision="I32" />
399
+ </output>
400
+ </layer>
401
+ <layer id="33" name="Broadcast_193476" type="Broadcast" version="opset3">
402
+ <data mode="bidirectional" />
403
+ <input>
404
+ <port id="0" precision="I32" />
405
+ <port id="1" precision="I64">
406
+ <dim>2</dim>
407
+ </port>
408
+ </input>
409
+ <output>
410
+ <port id="2" precision="I32">
411
+ <dim>-1</dim>
412
+ <dim>-1</dim>
413
+ </port>
414
+ </output>
415
+ </layer>
416
+ <layer id="34" name="Add_193465" type="Add" version="opset1">
417
+ <data auto_broadcast="numpy" />
418
+ <input>
419
+ <port id="0" precision="I64">
420
+ <dim>-1</dim>
421
+ <dim>2</dim>
422
+ </port>
423
+ <port id="1" precision="I64">
424
+ <dim>2</dim>
425
+ </port>
426
+ </input>
427
+ <output>
428
+ <port id="2" precision="I64">
429
+ <dim>-1</dim>
430
+ <dim>2</dim>
431
+ </port>
432
+ </output>
433
+ </layer>
434
+ <layer id="35" name="Constant_193452" type="Const" version="opset1">
435
+ <data element_type="i64" shape="" offset="1478209" size="8" />
436
+ <output>
437
+ <port id="0" precision="I64" />
438
+ </output>
439
+ </layer>
440
+ <layer id="36" name="Constant_193434" type="Const" version="opset1">
441
+ <data element_type="i64" shape="" offset="1478209" size="8" />
442
+ <output>
443
+ <port id="0" precision="I64" />
444
+ </output>
445
+ </layer>
446
+ <layer id="37" name="Constant_193435" type="Const" version="opset1">
447
+ <data element_type="i64" shape="" offset="1478209" size="8" />
448
+ <output>
449
+ <port id="0" precision="I64" />
450
+ </output>
451
+ </layer>
452
+ <layer id="38" name="Gather_193436" type="Gather" version="opset8">
453
+ <data batch_dims="0" />
454
+ <input>
455
+ <port id="0" precision="I64">
456
+ <dim>2</dim>
457
+ </port>
458
+ <port id="1" precision="I64" />
459
+ <port id="2" precision="I64" />
460
+ </input>
461
+ <output>
462
+ <port id="3" precision="I64" />
463
+ </output>
464
+ </layer>
465
+ <layer id="39" name="Constant_193453" type="Const" version="opset1">
466
+ <data element_type="i64" shape="" offset="1478217" size="8" />
467
+ <output>
468
+ <port id="0" precision="I64" />
469
+ </output>
470
+ </layer>
471
+ <layer id="40" name="Range_193454" type="Range" version="opset4">
472
+ <data output_type="i64" />
473
+ <input>
474
+ <port id="0" precision="I64" />
475
+ <port id="1" precision="I64" />
476
+ <port id="2" precision="I64" />
477
+ </input>
478
+ <output>
479
+ <port id="3" precision="I64">
480
+ <dim>-1</dim>
481
+ </port>
482
+ </output>
483
+ </layer>
484
+ <layer id="41" name="Constant_193455" type="Const" version="opset1">
485
+ <data element_type="i64" shape="1" offset="1478217" size="8" />
486
+ <output>
487
+ <port id="0" precision="I64">
488
+ <dim>1</dim>
489
+ </port>
490
+ </output>
491
+ </layer>
492
+ <layer id="42" name="Concat_193456" type="Concat" version="opset1">
493
+ <data axis="0" />
494
+ <input>
495
+ <port id="0" precision="I64">
496
+ <dim>1</dim>
497
+ </port>
498
+ <port id="1" precision="I64">
499
+ <dim>1</dim>
500
+ </port>
501
+ </input>
502
+ <output>
503
+ <port id="2" precision="I64">
504
+ <dim>2</dim>
505
+ </port>
506
+ </output>
507
+ </layer>
508
+ <layer id="43" name="Broadcast_193457" type="Broadcast" version="opset3">
509
+ <data mode="bidirectional" />
510
+ <input>
511
+ <port id="0" precision="I64">
512
+ <dim>-1</dim>
513
+ </port>
514
+ <port id="1" precision="I64">
515
+ <dim>2</dim>
516
+ </port>
517
+ </input>
518
+ <output>
519
+ <port id="2" precision="I64">
520
+ <dim>1</dim>
521
+ <dim>-1</dim>
522
+ </port>
523
+ </output>
524
+ </layer>
525
+ <layer id="44" name="Constant_193458" type="Const" version="opset1">
526
+ <data element_type="i64" shape="2" offset="1478249" size="16" />
527
+ <output>
528
+ <port id="0" precision="I64">
529
+ <dim>2</dim>
530
+ </port>
531
+ </output>
532
+ </layer>
533
+ <layer id="45" name="Transpose_193459" type="Transpose" version="opset1">
534
+ <input>
535
+ <port id="0" precision="I64">
536
+ <dim>1</dim>
537
+ <dim>-1</dim>
538
+ </port>
539
+ <port id="1" precision="I64">
540
+ <dim>2</dim>
541
+ </port>
542
+ </input>
543
+ <output>
544
+ <port id="2" precision="I64">
545
+ <dim>-1</dim>
546
+ <dim>1</dim>
547
+ </port>
548
+ </output>
549
+ </layer>
550
+ <layer id="46" name="Constant_193460" type="Const" version="opset1">
551
+ <data element_type="i64" shape="2" offset="1478265" size="16" />
552
+ <output>
553
+ <port id="0" precision="I64">
554
+ <dim>2</dim>
555
+ </port>
556
+ </output>
557
+ </layer>
558
+ <layer id="47" name="Reshape_193461" type="Reshape" version="opset1">
559
+ <data special_zero="false" />
560
+ <input>
561
+ <port id="0" precision="I64">
562
+ <dim>-1</dim>
563
+ <dim>1</dim>
564
+ </port>
565
+ <port id="1" precision="I64">
566
+ <dim>2</dim>
567
+ </port>
568
+ </input>
569
+ <output>
570
+ <port id="2" precision="I64">
571
+ <dim>-1</dim>
572
+ <dim>1</dim>
573
+ </port>
574
+ </output>
575
+ </layer>
576
+ <layer id="48" name="Constant_193448" type="Const" version="opset1">
577
+ <data element_type="i64" shape="" offset="1478209" size="8" />
578
+ <output>
579
+ <port id="0" precision="I64" />
580
+ </output>
581
+ </layer>
582
+ <layer id="49" name="Constant_193449" type="Const" version="opset1">
583
+ <data element_type="i64" shape="" offset="1478217" size="8" />
584
+ <output>
585
+ <port id="0" precision="I64" />
586
+ </output>
587
+ </layer>
588
+ <layer id="50" name="Constant_193450" type="Const" version="opset1">
589
+ <data element_type="i64" shape="" offset="1478217" size="8" />
590
+ <output>
591
+ <port id="0" precision="I64" />
592
+ </output>
593
+ </layer>
594
+ <layer id="51" name="Range_193451" type="Range" version="opset4">
595
+ <data output_type="i64" />
596
+ <input>
597
+ <port id="0" precision="I64" />
598
+ <port id="1" precision="I64" />
599
+ <port id="2" precision="I64" />
600
+ </input>
601
+ <output>
602
+ <port id="3" precision="I64">
603
+ <dim>1</dim>
604
+ </port>
605
+ </output>
606
+ </layer>
607
+ <layer id="52" name="Constant_193462" type="Const" version="opset1">
608
+ <data element_type="i64" shape="1" offset="1478217" size="8" />
609
+ <output>
610
+ <port id="0" precision="I64">
611
+ <dim>1</dim>
612
+ </port>
613
+ </output>
614
+ </layer>
615
+ <layer id="53" name="Concat_193463" type="Concat" version="opset1">
616
+ <data axis="0" />
617
+ <input>
618
+ <port id="0" precision="I64">
619
+ <dim>1</dim>
620
+ </port>
621
+ <port id="1" precision="I64">
622
+ <dim>1</dim>
623
+ </port>
624
+ </input>
625
+ <output>
626
+ <port id="2" precision="I64">
627
+ <dim>2</dim>
628
+ </port>
629
+ </output>
630
+ </layer>
631
+ <layer id="54" name="Broadcast_193464" type="Broadcast" version="opset3">
632
+ <data mode="bidirectional" />
633
+ <input>
634
+ <port id="0" precision="I64">
635
+ <dim>1</dim>
636
+ </port>
637
+ <port id="1" precision="I64">
638
+ <dim>2</dim>
639
+ </port>
640
+ </input>
641
+ <output>
642
+ <port id="2" precision="I64">
643
+ <dim>-1</dim>
644
+ <dim>1</dim>
645
+ </port>
646
+ </output>
647
+ </layer>
648
+ <layer id="55" name="Constant_193466" type="Const" version="opset1">
649
+ <data element_type="i64" shape="2" offset="1478265" size="16" />
650
+ <output>
651
+ <port id="0" precision="I64">
652
+ <dim>2</dim>
653
+ </port>
654
+ </output>
655
+ </layer>
656
+ <layer id="56" name="Reshape_193467" type="Reshape" version="opset1">
657
+ <data special_zero="false" />
658
+ <input>
659
+ <port id="0" precision="I64">
660
+ <dim>-1</dim>
661
+ <dim>1</dim>
662
+ </port>
663
+ <port id="1" precision="I64">
664
+ <dim>2</dim>
665
+ </port>
666
+ </input>
667
+ <output>
668
+ <port id="2" precision="I64">
669
+ <dim>-1</dim>
670
+ <dim>1</dim>
671
+ </port>
672
+ </output>
673
+ </layer>
674
+ <layer id="57" name="Concat_193468" type="Concat" version="opset1">
675
+ <data axis="1" />
676
+ <input>
677
+ <port id="0" precision="I64">
678
+ <dim>-1</dim>
679
+ <dim>1</dim>
680
+ </port>
681
+ <port id="1" precision="I64">
682
+ <dim>-1</dim>
683
+ <dim>1</dim>
684
+ </port>
685
+ </input>
686
+ <output>
687
+ <port id="2" precision="I64">
688
+ <dim>-1</dim>
689
+ <dim>2</dim>
690
+ </port>
691
+ </output>
692
+ </layer>
693
+ <layer id="58" name="Concat_193469" type="Concat" version="opset1">
694
+ <data axis="0" />
695
+ <input>
696
+ <port id="0" precision="I64">
697
+ <dim>-1</dim>
698
+ <dim>2</dim>
699
+ </port>
700
+ <port id="1" precision="I64">
701
+ <dim>-1</dim>
702
+ <dim>2</dim>
703
+ </port>
704
+ </input>
705
+ <output>
706
+ <port id="2" precision="I64">
707
+ <dim>-1</dim>
708
+ <dim>2</dim>
709
+ </port>
710
+ </output>
711
+ </layer>
712
+ <layer id="59" name="Constant_193433" type="Const" version="opset1">
713
+ <data element_type="i32" shape="1, 1" offset="0" size="4" />
714
+ <output>
715
+ <port id="0" precision="I32">
716
+ <dim>1</dim>
717
+ <dim>1</dim>
718
+ </port>
719
+ </output>
720
+ </layer>
721
+ <layer id="60" name="Constant_193442" type="Const" version="opset1">
722
+ <data element_type="i64" shape="1" offset="1478217" size="8" />
723
+ <output>
724
+ <port id="0" precision="I64">
725
+ <dim>1</dim>
726
+ </port>
727
+ </output>
728
+ </layer>
729
+ <layer id="61" name="Concat_193443" type="Concat" version="opset1">
730
+ <data axis="0" />
731
+ <input>
732
+ <port id="0" precision="I64">
733
+ <dim>1</dim>
734
+ </port>
735
+ <port id="1" precision="I64">
736
+ <dim>1</dim>
737
+ </port>
738
+ </input>
739
+ <output>
740
+ <port id="2" precision="I64">
741
+ <dim>2</dim>
742
+ </port>
743
+ </output>
744
+ </layer>
745
+ <layer id="62" name="Broadcast_193444" type="Broadcast" version="opset3">
746
+ <data mode="bidirectional" />
747
+ <input>
748
+ <port id="0" precision="I32">
749
+ <dim>1</dim>
750
+ <dim>1</dim>
751
+ </port>
752
+ <port id="1" precision="I64">
753
+ <dim>2</dim>
754
+ </port>
755
+ </input>
756
+ <output>
757
+ <port id="2" precision="I32">
758
+ <dim>-1</dim>
759
+ <dim>1</dim>
760
+ </port>
761
+ </output>
762
+ </layer>
763
+ <layer id="63" name="Constant_193445" type="Const" version="opset1">
764
+ <data element_type="i64" shape="1" offset="1478237" size="8" />
765
+ <output>
766
+ <port id="0" precision="I64">
767
+ <dim>1</dim>
768
+ </port>
769
+ </output>
770
+ </layer>
771
+ <layer id="64" name="Reshape_193446" type="Reshape" version="opset1">
772
+ <data special_zero="false" />
773
+ <input>
774
+ <port id="0" precision="I32">
775
+ <dim>-1</dim>
776
+ <dim>1</dim>
777
+ </port>
778
+ <port id="1" precision="I64">
779
+ <dim>1</dim>
780
+ </port>
781
+ </input>
782
+ <output>
783
+ <port id="2" precision="I32">
784
+ <dim>-1</dim>
785
+ </port>
786
+ </output>
787
+ </layer>
788
+ <layer id="65" name="Concat_193447" type="Concat" version="opset1">
789
+ <data axis="0" />
790
+ <input>
791
+ <port id="0" precision="I32">
792
+ <dim>-1</dim>
793
+ </port>
794
+ <port id="1" precision="I32">
795
+ <dim>-1</dim>
796
+ </port>
797
+ </input>
798
+ <output>
799
+ <port id="2" precision="I32">
800
+ <dim>-1</dim>
801
+ </port>
802
+ </output>
803
+ </layer>
804
+ <layer id="66" name="ScatterNDUpdate_193477" type="ScatterNDUpdate" version="opset4">
805
+ <input>
806
+ <port id="0" precision="I32">
807
+ <dim>-1</dim>
808
+ <dim>-1</dim>
809
+ </port>
810
+ <port id="1" precision="I64">
811
+ <dim>-1</dim>
812
+ <dim>2</dim>
813
+ </port>
814
+ <port id="2" precision="I32">
815
+ <dim>-1</dim>
816
+ </port>
817
+ </input>
818
+ <output>
819
+ <port id="3" precision="I32">
820
+ <dim>-1</dim>
821
+ <dim>-1</dim>
822
+ </port>
823
+ </output>
824
+ </layer>
825
+ <layer id="67" name="Constant_193478" type="Const" version="opset1">
826
+ <data element_type="i64" shape="1" offset="1478209" size="8" />
827
+ <output>
828
+ <port id="0" precision="I64">
829
+ <dim>1</dim>
830
+ </port>
831
+ </output>
832
+ </layer>
833
+ <layer id="68" name="Constant_193479" type="Const" version="opset1">
834
+ <data element_type="i64" shape="1" offset="1478229" size="8" />
835
+ <output>
836
+ <port id="0" precision="I64">
837
+ <dim>1</dim>
838
+ </port>
839
+ </output>
840
+ </layer>
841
+ <layer id="69" name="Constant_193480" type="Const" version="opset1">
842
+ <data element_type="i64" shape="1" offset="1478217" size="8" />
843
+ <output>
844
+ <port id="0" precision="I64">
845
+ <dim>1</dim>
846
+ </port>
847
+ </output>
848
+ </layer>
849
+ <layer id="70" name="Constant_193481" type="Const" version="opset1">
850
+ <data element_type="i64" shape="1" offset="1478237" size="8" />
851
+ <output>
852
+ <port id="0" precision="I64">
853
+ <dim>1</dim>
854
+ </port>
855
+ </output>
856
+ </layer>
857
+ <layer id="71" name="Slice_193482" type="Slice" version="opset8">
858
+ <input>
859
+ <port id="0" precision="I32">
860
+ <dim>-1</dim>
861
+ <dim>-1</dim>
862
+ </port>
863
+ <port id="1" precision="I64">
864
+ <dim>1</dim>
865
+ </port>
866
+ <port id="2" precision="I64">
867
+ <dim>1</dim>
868
+ </port>
869
+ <port id="3" precision="I64">
870
+ <dim>1</dim>
871
+ </port>
872
+ <port id="4" precision="I64">
873
+ <dim>1</dim>
874
+ </port>
875
+ </input>
876
+ <output>
877
+ <port id="5" precision="I32">
878
+ <dim>-1</dim>
879
+ <dim>-1</dim>
880
+ </port>
881
+ </output>
882
+ </layer>
883
+ <layer id="72" name="Slice_193482" type="Convert" version="opset1">
884
+ <data destination_type="i64" />
885
+ <input>
886
+ <port id="0" precision="I32">
887
+ <dim>-1</dim>
888
+ <dim>-1</dim>
889
+ </port>
890
+ </input>
891
+ <output>
892
+ <port id="1" precision="I64" names="input_ids">
893
+ <dim>-1</dim>
894
+ <dim>-1</dim>
895
+ </port>
896
+ </output>
897
+ </layer>
898
+ <layer id="73" name="Result_193488" type="Result" version="opset1">
899
+ <input>
900
+ <port id="0" precision="I64">
901
+ <dim>-1</dim>
902
+ <dim>-1</dim>
903
+ </port>
904
+ </input>
905
+ </layer>
906
+ <layer id="31" name="Result_193489" type="Result" version="opset1">
907
+ <input>
908
+ <port id="0" precision="I64">
909
+ <dim>-1</dim>
910
+ <dim>-1</dim>
911
+ </port>
912
+ </input>
913
+ </layer>
914
+ </layers>
915
+ <edges>
916
+ <edge from-layer="0" from-port="0" to-layer="6" to-port="1" />
917
+ <edge from-layer="1" from-port="0" to-layer="17" to-port="0" />
918
+ <edge from-layer="2" from-port="0" to-layer="6" to-port="0" />
919
+ <edge from-layer="3" from-port="0" to-layer="4" to-port="0" />
920
+ <edge from-layer="4" from-port="1" to-layer="6" to-port="2" />
921
+ <edge from-layer="4" from-port="2" to-layer="6" to-port="3" />
922
+ <edge from-layer="4" from-port="3" to-layer="6" to-port="4" />
923
+ <edge from-layer="5" from-port="0" to-layer="6" to-port="5" />
924
+ <edge from-layer="6" from-port="6" to-layer="23" to-port="1" />
925
+ <edge from-layer="6" from-port="7" to-layer="65" to-port="0" />
926
+ <edge from-layer="6" from-port="6" to-layer="34" to-port="0" />
927
+ <edge from-layer="6" from-port="7" to-layer="21" to-port="0" />
928
+ <edge from-layer="6" from-port="8" to-layer="19" to-port="1" />
929
+ <edge from-layer="6" from-port="8" to-layer="9" to-port="0" />
930
+ <edge from-layer="7" from-port="0" to-layer="8" to-port="0" />
931
+ <edge from-layer="7" from-port="0" to-layer="34" to-port="1" />
932
+ <edge from-layer="8" from-port="1" to-layer="9" to-port="1" />
933
+ <edge from-layer="9" from-port="2" to-layer="14" to-port="0" />
934
+ <edge from-layer="9" from-port="2" to-layer="38" to-port="0" />
935
+ <edge from-layer="9" from-port="2" to-layer="33" to-port="1" />
936
+ <edge from-layer="10" from-port="0" to-layer="14" to-port="1" />
937
+ <edge from-layer="11" from-port="0" to-layer="14" to-port="2" />
938
+ <edge from-layer="12" from-port="0" to-layer="14" to-port="3" />
939
+ <edge from-layer="13" from-port="0" to-layer="14" to-port="4" />
940
+ <edge from-layer="14" from-port="5" to-layer="53" to-port="0" />
941
+ <edge from-layer="14" from-port="5" to-layer="42" to-port="1" />
942
+ <edge from-layer="14" from-port="5" to-layer="61" to-port="0" />
943
+ <edge from-layer="14" from-port="5" to-layer="16" to-port="0" />
944
+ <edge from-layer="15" from-port="0" to-layer="16" to-port="1" />
945
+ <edge from-layer="16" from-port="2" to-layer="17" to-port="1" />
946
+ <edge from-layer="17" from-port="2" to-layer="24" to-port="0" />
947
+ <edge from-layer="18" from-port="0" to-layer="19" to-port="0" />
948
+ <edge from-layer="19" from-port="2" to-layer="23" to-port="0" />
949
+ <edge from-layer="20" from-port="0" to-layer="22" to-port="0" />
950
+ <edge from-layer="21" from-port="1" to-layer="22" to-port="1" />
951
+ <edge from-layer="22" from-port="2" to-layer="23" to-port="2" />
952
+ <edge from-layer="23" from-port="3" to-layer="24" to-port="1" />
953
+ <edge from-layer="24" from-port="2" to-layer="29" to-port="0" />
954
+ <edge from-layer="25" from-port="0" to-layer="29" to-port="1" />
955
+ <edge from-layer="26" from-port="0" to-layer="29" to-port="2" />
956
+ <edge from-layer="27" from-port="0" to-layer="29" to-port="3" />
957
+ <edge from-layer="28" from-port="0" to-layer="29" to-port="4" />
958
+ <edge from-layer="29" from-port="5" to-layer="30" to-port="0" />
959
+ <edge from-layer="30" from-port="1" to-layer="31" to-port="0" />
960
+ <edge from-layer="32" from-port="0" to-layer="33" to-port="0" />
961
+ <edge from-layer="33" from-port="2" to-layer="66" to-port="0" />
962
+ <edge from-layer="34" from-port="2" to-layer="58" to-port="0" />
963
+ <edge from-layer="35" from-port="0" to-layer="40" to-port="0" />
964
+ <edge from-layer="36" from-port="0" to-layer="38" to-port="1" />
965
+ <edge from-layer="37" from-port="0" to-layer="38" to-port="2" />
966
+ <edge from-layer="38" from-port="3" to-layer="40" to-port="1" />
967
+ <edge from-layer="39" from-port="0" to-layer="40" to-port="2" />
968
+ <edge from-layer="40" from-port="3" to-layer="43" to-port="0" />
969
+ <edge from-layer="41" from-port="0" to-layer="42" to-port="0" />
970
+ <edge from-layer="42" from-port="2" to-layer="43" to-port="1" />
971
+ <edge from-layer="43" from-port="2" to-layer="45" to-port="0" />
972
+ <edge from-layer="44" from-port="0" to-layer="45" to-port="1" />
973
+ <edge from-layer="45" from-port="2" to-layer="47" to-port="0" />
974
+ <edge from-layer="46" from-port="0" to-layer="47" to-port="1" />
975
+ <edge from-layer="47" from-port="2" to-layer="57" to-port="0" />
976
+ <edge from-layer="48" from-port="0" to-layer="51" to-port="0" />
977
+ <edge from-layer="49" from-port="0" to-layer="51" to-port="1" />
978
+ <edge from-layer="50" from-port="0" to-layer="51" to-port="2" />
979
+ <edge from-layer="51" from-port="3" to-layer="54" to-port="0" />
980
+ <edge from-layer="52" from-port="0" to-layer="53" to-port="1" />
981
+ <edge from-layer="53" from-port="2" to-layer="54" to-port="1" />
982
+ <edge from-layer="54" from-port="2" to-layer="56" to-port="0" />
983
+ <edge from-layer="55" from-port="0" to-layer="56" to-port="1" />
984
+ <edge from-layer="56" from-port="2" to-layer="57" to-port="1" />
985
+ <edge from-layer="57" from-port="2" to-layer="58" to-port="1" />
986
+ <edge from-layer="58" from-port="2" to-layer="66" to-port="1" />
987
+ <edge from-layer="59" from-port="0" to-layer="62" to-port="0" />
988
+ <edge from-layer="60" from-port="0" to-layer="61" to-port="1" />
989
+ <edge from-layer="61" from-port="2" to-layer="62" to-port="1" />
990
+ <edge from-layer="62" from-port="2" to-layer="64" to-port="0" />
991
+ <edge from-layer="63" from-port="0" to-layer="64" to-port="1" />
992
+ <edge from-layer="64" from-port="2" to-layer="65" to-port="1" />
993
+ <edge from-layer="65" from-port="2" to-layer="66" to-port="2" />
994
+ <edge from-layer="66" from-port="3" to-layer="71" to-port="0" />
995
+ <edge from-layer="67" from-port="0" to-layer="71" to-port="1" />
996
+ <edge from-layer="68" from-port="0" to-layer="71" to-port="2" />
997
+ <edge from-layer="69" from-port="0" to-layer="71" to-port="3" />
998
+ <edge from-layer="70" from-port="0" to-layer="71" to-port="4" />
999
+ <edge from-layer="71" from-port="5" to-layer="72" to-port="0" />
1000
+ <edge from-layer="72" from-port="1" to-layer="73" to-port="0" />
1001
+ </edges>
1002
+ <rt_info>
1003
+ <add_attention_mask value="True" />
1004
+ <add_prefix_space />
1005
+ <add_special_tokens value="True" />
1006
+ <bos_token_id value="1" />
1007
+ <chat_template value="{{ bos_token }}{% for message in messages %}{{'&lt;|im_start|>' + message['role'] + '&#10;' + message['content'] + '&lt;|im_end|>' + '&#10;'}}{% endfor %}{% if add_generation_prompt %}{{ '&lt;|im_start|>assistant&#10;' }}{% endif %}" />
1008
+ <clean_up_tokenization_spaces value="False" />
1009
+ <detokenizer_input_type value="i64" />
1010
+ <eos_token_id value="2" />
1011
+ <handle_special_tokens_with_re value="True" />
1012
+ <number_of_inputs value="1" />
1013
+ <openvino_tokenizers_version value="2024.6.0.0" />
1014
+ <openvino_version value="2024.6.0" />
1015
+ <original_tokenizer_class value="&lt;class 'transformers_modules.OpenGVLab.InternVL2-2B.aec61df8c99ba7c81271877485e038a7b823a399.tokenization_internlm2.InternLM2Tokenizer'>" />
1016
+ <pad_token_id value="2" />
1017
+ <sentencepiece_version value="0.2.0" />
1018
+ <skip_special_tokens value="True" />
1019
+ <streaming_detokenizer value="False" />
1020
+ <tiktoken_version value="0.8.0" />
1021
+ <tokenizer_output_type value="i64" />
1022
+ <tokenizers_version value="0.20.3" />
1023
+ <transformers_version value="4.46.3" />
1024
+ <use_max_padding value="False" />
1025
+ <use_sentencepiece_backend value="False" />
1026
+ <utf8_replace_mode value="replace" />
1027
+ <with_detokenizer value="True" />
1028
+ </rt_info>
1029
+ </net>
openvino_vision_embeddings_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:38f0ccf5501d0c30b7d1a61e575902c6cfeecd9f401096852ff913185c1dbfb2
3
+ size 321161628
openvino_vision_embeddings_model.xml ADDED
The diff for this file is too large to render. See raw diff
 
preprocessor_config.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "crop_size": {
3
+ "height": 448,
4
+ "width": 448
5
+ },
6
+ "do_center_crop": true,
7
+ "do_convert_rgb": true,
8
+ "do_normalize": true,
9
+ "do_rescale": true,
10
+ "do_resize": true,
11
+ "image_mean": [
12
+ 0.485,
13
+ 0.456,
14
+ 0.406
15
+ ],
16
+ "image_processor_type": "CLIPFeatureExtractor",
17
+ "image_std": [
18
+ 0.229,
19
+ 0.224,
20
+ 0.225
21
+ ],
22
+ "resample": 3,
23
+ "rescale_factor": 0.00392156862745098,
24
+ "size": {
25
+ "shortest_edge": 448
26
+ }
27
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|action_start|>",
6
+ "<|action_end|>",
7
+ "<|interpreter|>",
8
+ "<|plugin|>",
9
+ "<img>",
10
+ "</img>",
11
+ "<IMG_CONTEXT>",
12
+ "<quad>",
13
+ "</quad>",
14
+ "<ref>",
15
+ "</ref>",
16
+ "<box>",
17
+ "</box>"
18
+ ],
19
+ "bos_token": {
20
+ "content": "<s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false
25
+ },
26
+ "eos_token": {
27
+ "content": "</s>",
28
+ "lstrip": false,
29
+ "normalized": false,
30
+ "rstrip": false,
31
+ "single_word": false
32
+ },
33
+ "pad_token": {
34
+ "content": "</s>",
35
+ "lstrip": false,
36
+ "normalized": false,
37
+ "rstrip": false,
38
+ "single_word": false
39
+ },
40
+ "unk_token": {
41
+ "content": "<unk>",
42
+ "lstrip": false,
43
+ "normalized": false,
44
+ "rstrip": false,
45
+ "single_word": false
46
+ }
47
+ }
tokenization_internlm2.py ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) The InternLM team and The HuggingFace Inc. team. All rights reserved.
2
+ #
3
+ # This code is based on transformers/src/transformers/models/llama/tokenization_llama.py
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ """Tokenization classes for InternLM."""
18
+ import os
19
+ from shutil import copyfile
20
+ from typing import Any, Dict, List, Optional, Tuple
21
+
22
+ import sentencepiece as spm
23
+ from transformers.tokenization_utils import PreTrainedTokenizer
24
+ from transformers.utils import logging
25
+
26
+ logger = logging.get_logger(__name__)
27
+
28
+ VOCAB_FILES_NAMES = {'vocab_file': './tokenizer.model'}
29
+
30
+ PRETRAINED_VOCAB_FILES_MAP = {}
31
+
32
+
33
+ # Modified from transformers.model.llama.tokenization_llama.LlamaTokenizer
34
+ class InternLM2Tokenizer(PreTrainedTokenizer):
35
+ """
36
+ Construct a InternLM2 tokenizer. Based on byte-level Byte-Pair-Encoding.
37
+
38
+ Args:
39
+ vocab_file (`str`):
40
+ Path to the vocabulary file.
41
+ """
42
+
43
+ vocab_files_names = VOCAB_FILES_NAMES
44
+ pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP
45
+ model_input_names = ['input_ids', 'attention_mask']
46
+ _auto_class = 'AutoTokenizer'
47
+
48
+ def __init__(
49
+ self,
50
+ vocab_file,
51
+ unk_token='<unk>',
52
+ bos_token='<s>',
53
+ eos_token='</s>',
54
+ pad_token='</s>',
55
+ sp_model_kwargs: Optional[Dict[str, Any]] = None,
56
+ add_bos_token=True,
57
+ add_eos_token=False,
58
+ decode_with_prefix_space=False,
59
+ clean_up_tokenization_spaces=False,
60
+ **kwargs,
61
+ ):
62
+ self.sp_model_kwargs = {} if sp_model_kwargs is None else sp_model_kwargs
63
+ self.vocab_file = vocab_file
64
+ self.add_bos_token = add_bos_token
65
+ self.add_eos_token = add_eos_token
66
+ self.decode_with_prefix_space = decode_with_prefix_space
67
+ self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
68
+ self.sp_model.Load(vocab_file)
69
+ self._no_prefix_space_tokens = None
70
+ super().__init__(
71
+ bos_token=bos_token,
72
+ eos_token=eos_token,
73
+ unk_token=unk_token,
74
+ pad_token=pad_token,
75
+ clean_up_tokenization_spaces=clean_up_tokenization_spaces,
76
+ **kwargs,
77
+ )
78
+
79
+ @property
80
+ def no_prefix_space_tokens(self):
81
+ if self._no_prefix_space_tokens is None:
82
+ vocab = self.convert_ids_to_tokens(list(range(self.vocab_size)))
83
+ self._no_prefix_space_tokens = {i for i, tok in enumerate(vocab) if not tok.startswith('▁')}
84
+ return self._no_prefix_space_tokens
85
+
86
+ @property
87
+ def vocab_size(self):
88
+ """Returns vocab size"""
89
+ return self.sp_model.get_piece_size()
90
+
91
+ @property
92
+ def bos_token_id(self) -> Optional[int]:
93
+ return self.sp_model.bos_id()
94
+
95
+ @property
96
+ def eos_token_id(self) -> Optional[int]:
97
+ return self.sp_model.eos_id()
98
+
99
+ def get_vocab(self):
100
+ """Returns vocab as a dict"""
101
+ vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)}
102
+ vocab.update(self.added_tokens_encoder)
103
+ return vocab
104
+
105
+ def _tokenize(self, text):
106
+ """Returns a tokenized string."""
107
+ return self.sp_model.encode(text, out_type=str)
108
+
109
+ def _convert_token_to_id(self, token):
110
+ """Converts a token (str) in an id using the vocab."""
111
+ return self.sp_model.piece_to_id(token)
112
+
113
+ def _convert_id_to_token(self, index):
114
+ """Converts an index (integer) in a token (str) using the vocab."""
115
+ token = self.sp_model.IdToPiece(index)
116
+ return token
117
+
118
+ def _maybe_add_prefix_space(self, tokens, decoded):
119
+ if tokens and tokens[0] not in self.no_prefix_space_tokens:
120
+ return ' ' + decoded
121
+ else:
122
+ return decoded
123
+
124
+ def convert_tokens_to_string(self, tokens):
125
+ """Converts a sequence of tokens (string) in a single string."""
126
+ current_sub_tokens = []
127
+ out_string = ''
128
+ prev_is_special = False
129
+ for token in tokens:
130
+ # make sure that special tokens are not decoded using sentencepiece model
131
+ if token in self.all_special_tokens:
132
+ if not prev_is_special:
133
+ out_string += ' '
134
+ out_string += self.sp_model.decode(current_sub_tokens) + token
135
+ prev_is_special = True
136
+ current_sub_tokens = []
137
+ else:
138
+ current_sub_tokens.append(token)
139
+ prev_is_special = False
140
+ out_string += self.sp_model.decode(current_sub_tokens)
141
+ out_string = self.clean_up_tokenization(out_string)
142
+ out_string = self._maybe_add_prefix_space(tokens=tokens, decoded=out_string)
143
+ return out_string[1:]
144
+
145
+ def save_vocabulary(self, save_directory, filename_prefix: Optional[str] = None) -> Tuple[str]:
146
+ """
147
+ Save the vocabulary and special tokens file to a directory.
148
+
149
+ Args:
150
+ save_directory (`str`):
151
+ The directory in which to save the vocabulary.
152
+
153
+ Returns:
154
+ `Tuple(str)`: Paths to the files saved.
155
+ """
156
+ if not os.path.isdir(save_directory):
157
+ logger.error(f'Vocabulary path ({save_directory}) should be a directory')
158
+ return
159
+ out_vocab_file = os.path.join(
160
+ save_directory, (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']
161
+ )
162
+
163
+ if os.path.abspath(self.vocab_file) != os.path.abspath(out_vocab_file) and os.path.isfile(self.vocab_file):
164
+ copyfile(self.vocab_file, out_vocab_file)
165
+ elif not os.path.isfile(self.vocab_file):
166
+ with open(out_vocab_file, 'wb') as fi:
167
+ content_spiece_model = self.sp_model.serialized_model_proto()
168
+ fi.write(content_spiece_model)
169
+
170
+ return (out_vocab_file,)
171
+
172
+ def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
173
+ if self.add_bos_token:
174
+ bos_token_ids = [self.bos_token_id]
175
+ else:
176
+ bos_token_ids = []
177
+
178
+ output = bos_token_ids + token_ids_0
179
+
180
+ if token_ids_1 is not None:
181
+ output = output + token_ids_1
182
+
183
+ if self.add_eos_token:
184
+ output = output + [self.eos_token_id]
185
+
186
+ return output
187
+
188
+ def get_special_tokens_mask(
189
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False
190
+ ) -> List[int]:
191
+ """
192
+ Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
193
+ special tokens using the tokenizer `prepare_for_model` method.
194
+
195
+ Args:
196
+ token_ids_0 (`List[int]`):
197
+ List of IDs.
198
+ token_ids_1 (`List[int]`, *optional*):
199
+ Optional second list of IDs for sequence pairs.
200
+ already_has_special_tokens (`bool`, *optional*, defaults to `False`):
201
+ Whether or not the token list is already formatted with special tokens for the model.
202
+
203
+ Returns:
204
+ `List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
205
+ """
206
+ if already_has_special_tokens:
207
+ return super().get_special_tokens_mask(
208
+ token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True
209
+ )
210
+
211
+ if token_ids_1 is None:
212
+ return [1] + ([0] * len(token_ids_0)) + [1]
213
+ return [1] + ([0] * len(token_ids_0)) + [1, 1] + ([0] * len(token_ids_1)) + [1]
214
+
215
+ def create_token_type_ids_from_sequences(
216
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
217
+ ) -> List[int]:
218
+ """
219
+ Create a mask from the two sequences passed to be used in a sequence-pair classification task. T5 does not make
220
+ use of token type ids, therefore a list of zeros is returned.
221
+
222
+ Args:
223
+ token_ids_0 (`List[int]`):
224
+ List of IDs.
225
+ token_ids_1 (`List[int]`, *optional*):
226
+ Optional second list of IDs for sequence pairs.
227
+
228
+ Returns:
229
+ `List[int]`: List of zeros.
230
+ """
231
+ eos = [self.eos_token_id]
232
+
233
+ if token_ids_1 is None:
234
+ return len(token_ids_0 + eos) * [0]
235
+ return len(token_ids_0 + eos + token_ids_1 + eos) * [0]
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f868398fc4e05ee1e8aeba95ddf18ddcc45b8bce55d5093bead5bbf80429b48b
3
+ size 1477754
tokenizer_config.json ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<unk>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<s>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "92538": {
28
+ "content": "<|plugin|>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "92539": {
36
+ "content": "<|interpreter|>",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ },
43
+ "92540": {
44
+ "content": "<|action_end|>",
45
+ "lstrip": false,
46
+ "normalized": false,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": true
50
+ },
51
+ "92541": {
52
+ "content": "<|action_start|>",
53
+ "lstrip": false,
54
+ "normalized": false,
55
+ "rstrip": false,
56
+ "single_word": false,
57
+ "special": true
58
+ },
59
+ "92542": {
60
+ "content": "<|im_end|>",
61
+ "lstrip": false,
62
+ "normalized": false,
63
+ "rstrip": false,
64
+ "single_word": false,
65
+ "special": true
66
+ },
67
+ "92543": {
68
+ "content": "<|im_start|>",
69
+ "lstrip": false,
70
+ "normalized": false,
71
+ "rstrip": false,
72
+ "single_word": false,
73
+ "special": true
74
+ },
75
+ "92544": {
76
+ "content": "<img>",
77
+ "lstrip": false,
78
+ "normalized": false,
79
+ "rstrip": false,
80
+ "single_word": false,
81
+ "special": true
82
+ },
83
+ "92545": {
84
+ "content": "</img>",
85
+ "lstrip": false,
86
+ "normalized": false,
87
+ "rstrip": false,
88
+ "single_word": false,
89
+ "special": true
90
+ },
91
+ "92546": {
92
+ "content": "<IMG_CONTEXT>",
93
+ "lstrip": false,
94
+ "normalized": false,
95
+ "rstrip": false,
96
+ "single_word": false,
97
+ "special": true
98
+ },
99
+ "92547": {
100
+ "content": "<quad>",
101
+ "lstrip": false,
102
+ "normalized": false,
103
+ "rstrip": false,
104
+ "single_word": false,
105
+ "special": true
106
+ },
107
+ "92548": {
108
+ "content": "</quad>",
109
+ "lstrip": false,
110
+ "normalized": false,
111
+ "rstrip": false,
112
+ "single_word": false,
113
+ "special": true
114
+ },
115
+ "92549": {
116
+ "content": "<ref>",
117
+ "lstrip": false,
118
+ "normalized": false,
119
+ "rstrip": false,
120
+ "single_word": false,
121
+ "special": true
122
+ },
123
+ "92550": {
124
+ "content": "</ref>",
125
+ "lstrip": false,
126
+ "normalized": false,
127
+ "rstrip": false,
128
+ "single_word": false,
129
+ "special": true
130
+ },
131
+ "92551": {
132
+ "content": "<box>",
133
+ "lstrip": false,
134
+ "normalized": false,
135
+ "rstrip": false,
136
+ "single_word": false,
137
+ "special": true
138
+ },
139
+ "92552": {
140
+ "content": "</box>",
141
+ "lstrip": false,
142
+ "normalized": false,
143
+ "rstrip": false,
144
+ "single_word": false,
145
+ "special": true
146
+ }
147
+ },
148
+ "additional_special_tokens": [
149
+ "<|im_start|>",
150
+ "<|im_end|>",
151
+ "<|action_start|>",
152
+ "<|action_end|>",
153
+ "<|interpreter|>",
154
+ "<|plugin|>",
155
+ "<img>",
156
+ "</img>",
157
+ "<IMG_CONTEXT>",
158
+ "<quad>",
159
+ "</quad>",
160
+ "<ref>",
161
+ "</ref>",
162
+ "<box>",
163
+ "</box>"
164
+ ],
165
+ "auto_map": {
166
+ "AutoTokenizer": [
167
+ "tokenization_internlm2.InternLM2Tokenizer",
168
+ null
169
+ ]
170
+ },
171
+ "bos_token": "<s>",
172
+ "chat_template": "{{ bos_token }}{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}",
173
+ "clean_up_tokenization_spaces": false,
174
+ "eos_token": "</s>",
175
+ "model_max_length": 8192,
176
+ "pad_token": "</s>",
177
+ "tokenizer_class": "InternLM2Tokenizer",
178
+ "unk_token": "<unk>"
179
+ }