Aluode/PerceptionLabPortable
0
1# coding=utf-82# Copyright 2022 The HuggingFace Inc. team. All rights reserved.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15 16 17from ...configuration_utils import PretrainedConfig18from ...utils import logging19 20 21logger = logging.get_logger(__name__)22 23 24class GitVisionConfig(PretrainedConfig):25 r"""26 This is the configuration class to store the configuration of a [`GitVisionModel`]. It is used to instantiate a GIT27 vision encoder according to the specified arguments, defining the model architecture. Instantiating a configuration28 with the defaults will yield a similar configuration to that of the vision encoder of the GIT29 [microsoft/git-base](https://huggingface.co/microsoft/git-base) architecture.30 31 Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the32 documentation from [`PretrainedConfig`] for more information.33 34 Args:35 hidden_size (`int`, *optional*, defaults to 768):36 Dimensionality of the encoder layers and the pooler layer.37 intermediate_size (`int`, *optional*, defaults to 3072):38 Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.39 num_hidden_layers (`int`, *optional*, defaults to 12):40 Number of hidden layers in the Transformer encoder.41 num_attention_heads (`int`, *optional*, defaults to 12):42 Number of attention heads for each attention layer in the Transformer encoder.43 image_size (`int`, *optional*, defaults to 224):44 The size (resolution) of each image.45 patch_size (`int`, *optional*, defaults to 16):46 The size (resolution) of each patch.47 hidden_act (`str` or `function`, *optional*, defaults to `"quick_gelu"`):48 The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,49 `"relu"`, `"selu"` and `"gelu_new"` `"quick_gelu"` are supported.50 layer_norm_eps (`float`, *optional*, defaults to 1e-5):51 The epsilon used by the layer normalization layers.52 attention_dropout (`float`, *optional*, defaults to 0.0):53 The dropout ratio for the attention probabilities.54 initializer_range (`float`, *optional*, defaults to 0.02):55 The standard deviation of the truncated_normal_initializer for initializing all weight matrices.56 57 Example:58 59 ```python60 >>> from transformers import GitVisionConfig, GitVisionModel61 62 >>> # Initializing a GitVisionConfig with microsoft/git-base style configuration63 >>> configuration = GitVisionConfig()64 65 >>> # Initializing a GitVisionModel (with random weights) from the microsoft/git-base style configuration66 >>> model = GitVisionModel(configuration)67 68 >>> # Accessing the model configuration69 >>> configuration = model.config70 ```"""71 72 model_type = "git_vision_model"73 base_config_key = "vision_config"74 75 def __init__(76 self,77 hidden_size=768,78 intermediate_size=3072,79 num_hidden_layers=12,80 num_attention_heads=12,81 num_channels=3,82 image_size=224,83 patch_size=16,84 hidden_act="quick_gelu",85 layer_norm_eps=1e-5,86 attention_dropout=0.0,87 initializer_range=0.02,88 **kwargs,89 ):90 super().__init__(**kwargs)91 92 self.hidden_size = hidden_size93 self.intermediate_size = intermediate_size94 self.num_hidden_layers = num_hidden_layers95 self.num_attention_heads = num_attention_heads96 self.num_channels = num_channels97 self.patch_size = patch_size98 self.image_size = image_size99 self.initializer_range = initializer_range100 self.attention_dropout = attention_dropout101 self.layer_norm_eps = layer_norm_eps102 self.hidden_act = hidden_act103 104 105class GitConfig(PretrainedConfig):106 r"""107 This is the configuration class to store the configuration of a [`GitModel`]. It is used to instantiate a GIT model108 according to the specified arguments, defining the model architecture. Instantiating a configuration with the109 defaults will yield a similar configuration to that of the GIT110 [microsoft/git-base](https://huggingface.co/microsoft/git-base) architecture.111 112 Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the113 documentation from [`PretrainedConfig`] for more information.114 115 Args:116 vision_config (`dict`, *optional*):117 Dictionary of configuration options used to initialize [`GitVisionConfig`].118 vocab_size (`int`, *optional*, defaults to 30522):119 Vocabulary size of the GIT model. Defines the number of different tokens that can be represented by the120 `inputs_ids` passed when calling [`GitModel`].121 hidden_size (`int`, *optional*, defaults to 768):122 Dimensionality of the encoder layers and the pooler layer.123 num_hidden_layers (`int`, *optional*, defaults to 6):124 Number of hidden layers in the Transformer encoder.125 num_attention_heads (`int`, *optional*, defaults to 12):126 Number of attention heads for each attention layer in the Transformer encoder.127 intermediate_size (`int`, *optional*, defaults to 3072):128 Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.129 hidden_act (`str` or `Callable`, *optional*, defaults to `"gelu"`):130 The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,131 `"relu"`, `"silu"` and `"gelu_new"` are supported.132 hidden_dropout_prob (`float`, *optional*, defaults to 0.1):133 The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.134 attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):135 The dropout ratio for the attention probabilities.136 max_position_embeddings (`int`, *optional*, defaults to 1024):137 The maximum sequence length that this model might ever be used with. Typically set this to something large138 just in case (e.g., 512 or 1024 or 2048).139 initializer_range (`float`, *optional*, defaults to 0.02):140 The standard deviation of the truncated_normal_initializer for initializing all weight matrices.141 layer_norm_eps (`float`, *optional*, defaults to 1e-12):142 The epsilon used by the layer normalization layers.143 position_embedding_type (`str`, *optional*, defaults to `"absolute"`):144 Type of position embedding. Choose one of `"absolute"`, `"relative_key"`, `"relative_key_query"`. For145 positional embeddings use `"absolute"`. For more information on `"relative_key"`, please refer to146 [Self-Attention with Relative Position Representations (Shaw et al.)](https://huggingface.co/papers/1803.02155).147 For more information on `"relative_key_query"`, please refer to *Method 4* in [Improve Transformer Models148 with Better Relative Position Embeddings (Huang et al.)](https://huggingface.co/papers/2009.13658).149 use_cache (`bool`, *optional*, defaults to `True`):150 Whether or not the model should return the last key/values attentions (not used by all models).151 num_image_with_embedding (`int`, *optional*):152 The number of temporal embeddings to add, in case the model is used for video captioning/VQA.153 154 Examples:155 156 ```python157 >>> from transformers import GitConfig, GitModel158 159 >>> # Initializing a GIT microsoft/git-base style configuration160 >>> configuration = GitConfig()161 162 >>> # Initializing a model (with random weights) from the microsoft/git-base style configuration163 >>> model = GitModel(configuration)164 165 >>> # Accessing the model configuration166 >>> configuration = model.config167 ```"""168 169 model_type = "git"170 sub_configs = {"vision_config": GitVisionConfig}171 172 def __init__(173 self,174 vision_config=None,175 vocab_size=30522,176 hidden_size=768,177 num_hidden_layers=6,178 num_attention_heads=12,179 intermediate_size=3072,180 hidden_act="gelu",181 hidden_dropout_prob=0.1,182 attention_probs_dropout_prob=0.1,183 max_position_embeddings=1024,184 initializer_range=0.02,185 layer_norm_eps=1e-12,186 pad_token_id=0,187 position_embedding_type="absolute",188 use_cache=True,189 tie_word_embeddings=False,190 bos_token_id=101,191 eos_token_id=102,192 num_image_with_embedding=None,193 **kwargs,194 ):195 super().__init__(bos_token_id=bos_token_id, eos_token_id=eos_token_id, pad_token_id=pad_token_id, **kwargs)196 197 if vision_config is None:198 vision_config = {}199 logger.info("vision_config is None. initializing the GitVisionConfig with default values.")200 201 self.vision_config = GitVisionConfig(**vision_config)202 self.vocab_size = vocab_size203 self.hidden_size = hidden_size204 self.num_hidden_layers = num_hidden_layers205 self.num_attention_heads = num_attention_heads206 self.hidden_act = hidden_act207 self.intermediate_size = intermediate_size208 self.hidden_dropout_prob = hidden_dropout_prob209 self.attention_probs_dropout_prob = attention_probs_dropout_prob210 self.max_position_embeddings = max_position_embeddings211 self.initializer_range = initializer_range212 self.layer_norm_eps = layer_norm_eps213 self.position_embedding_type = position_embedding_type214 self.use_cache = use_cache215 self.tie_word_embeddings = tie_word_embeddings216 self.num_image_with_embedding = num_image_with_embedding217 218 self.bos_token_id = bos_token_id219 self.eos_token_id = eos_token_id220 221 222__all__ = ["GitConfig", "GitVisionConfig"]223 