Update configuration_internvl_chat.py
Browse files- configuration_internvl_chat.py +108 -2
configuration_internvl_chat.py
CHANGED
@@ -4,17 +4,123 @@
|
|
4 |
# Licensed under The MIT License [see LICENSE for details]
|
5 |
# --------------------------------------------------------
|
6 |
|
|
|
7 |
import copy
|
|
|
8 |
|
9 |
from transformers import LlamaConfig
|
10 |
from transformers.configuration_utils import PretrainedConfig
|
11 |
from transformers.utils import logging
|
12 |
|
13 |
-
from .configuration_intern_vit import InternVisionConfig
|
14 |
-
|
15 |
logger = logging.get_logger(__name__)
|
16 |
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
class InternVLChatConfig(PretrainedConfig):
|
19 |
model_type = 'internvl_chat'
|
20 |
is_composition = True
|
|
|
4 |
# Licensed under The MIT License [see LICENSE for details]
|
5 |
# --------------------------------------------------------
|
6 |
|
7 |
+
import os
|
8 |
import copy
|
9 |
+
from typing import Union
|
10 |
|
11 |
from transformers import LlamaConfig
|
12 |
from transformers.configuration_utils import PretrainedConfig
|
13 |
from transformers.utils import logging
|
14 |
|
|
|
|
|
15 |
logger = logging.get_logger(__name__)
|
16 |
|
17 |
|
18 |
+
class InternVisionConfig(PretrainedConfig):
|
19 |
+
r"""
|
20 |
+
This is the configuration class to store the configuration of a [`InternVisionModel`]. It is used to
|
21 |
+
instantiate a vision encoder according to the specified arguments, defining the model architecture.
|
22 |
+
|
23 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
24 |
+
documentation from [`PretrainedConfig`] for more information.
|
25 |
+
|
26 |
+
Args:
|
27 |
+
num_channels (`int`, *optional*, defaults to 3):
|
28 |
+
Number of color channels in the input images (e.g., 3 for RGB).
|
29 |
+
patch_size (`int`, *optional*, defaults to 14):
|
30 |
+
The size (resolution) of each patch.
|
31 |
+
image_size (`int`, *optional*, defaults to 224):
|
32 |
+
The size (resolution) of each image.
|
33 |
+
qkv_bias (`bool`, *optional*, defaults to `False`):
|
34 |
+
Whether to add a bias to the queries and values in the self-attention layers.
|
35 |
+
hidden_size (`int`, *optional*, defaults to 3200):
|
36 |
+
Dimensionality of the encoder layers and the pooler layer.
|
37 |
+
num_attention_heads (`int`, *optional*, defaults to 25):
|
38 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
39 |
+
intermediate_size (`int`, *optional*, defaults to 12800):
|
40 |
+
Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
|
41 |
+
qk_normalization (`bool`, *optional*, defaults to `True`):
|
42 |
+
Whether to normalize the queries and keys in the self-attention layers.
|
43 |
+
num_hidden_layers (`int`, *optional*, defaults to 48):
|
44 |
+
Number of hidden layers in the Transformer encoder.
|
45 |
+
use_flash_attn (`bool`, *optional*, defaults to `True`):
|
46 |
+
Whether to use flash attention mechanism.
|
47 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
|
48 |
+
The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
|
49 |
+
`"relu"`, `"selu"` and `"gelu_new"` ``"gelu"` are supported.
|
50 |
+
layer_norm_eps (`float`, *optional*, defaults to 1e-6):
|
51 |
+
The epsilon used by the layer normalization layers.
|
52 |
+
dropout (`float`, *optional*, defaults to 0.0):
|
53 |
+
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
|
54 |
+
drop_path_rate (`float`, *optional*, defaults to 0.0):
|
55 |
+
Dropout rate for stochastic depth.
|
56 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
57 |
+
The dropout ratio for the attention probabilities.
|
58 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
59 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
60 |
+
initializer_factor (`float`, *optional*, defaults to 0.1):
|
61 |
+
A factor for layer scale.
|
62 |
+
"""
|
63 |
+
|
64 |
+
model_type = 'intern_vit_6b'
|
65 |
+
|
66 |
+
def __init__(
|
67 |
+
self,
|
68 |
+
num_channels=3,
|
69 |
+
patch_size=14,
|
70 |
+
image_size=224,
|
71 |
+
qkv_bias=False,
|
72 |
+
hidden_size=3200,
|
73 |
+
num_attention_heads=25,
|
74 |
+
intermediate_size=12800,
|
75 |
+
qk_normalization=True,
|
76 |
+
num_hidden_layers=48,
|
77 |
+
use_flash_attn=True,
|
78 |
+
hidden_act='gelu',
|
79 |
+
layer_norm_eps=1e-6,
|
80 |
+
dropout=0.0,
|
81 |
+
drop_path_rate=0.0,
|
82 |
+
attention_dropout=0.0,
|
83 |
+
initializer_range=0.02,
|
84 |
+
initializer_factor=0.1,
|
85 |
+
**kwargs,
|
86 |
+
):
|
87 |
+
super().__init__(**kwargs)
|
88 |
+
|
89 |
+
self.hidden_size = hidden_size
|
90 |
+
self.intermediate_size = intermediate_size
|
91 |
+
self.dropout = dropout
|
92 |
+
self.drop_path_rate = drop_path_rate
|
93 |
+
self.num_hidden_layers = num_hidden_layers
|
94 |
+
self.num_attention_heads = num_attention_heads
|
95 |
+
self.num_channels = num_channels
|
96 |
+
self.patch_size = patch_size
|
97 |
+
self.image_size = image_size
|
98 |
+
self.initializer_range = initializer_range
|
99 |
+
self.initializer_factor = initializer_factor
|
100 |
+
self.attention_dropout = attention_dropout
|
101 |
+
self.layer_norm_eps = layer_norm_eps
|
102 |
+
self.hidden_act = hidden_act
|
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)
|
121 |
+
|
122 |
+
|
123 |
+
|
124 |
class InternVLChatConfig(PretrainedConfig):
|
125 |
model_type = 'internvl_chat'
|
126 |
is_composition = True
|