DoruC/Grounded-Segment-Anything
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""" Data2VecText configuration"""16from collections import OrderedDict17from typing import Mapping18 19from ...configuration_utils import PretrainedConfig20from ...onnx import OnnxConfig21from ...utils import logging22 23 24logger = logging.get_logger(__name__)25 26DATA2VEC_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP = {27 "facebook/data2vec-text-base": "https://huggingface.co/data2vec/resolve/main/config.json",28}29 30 31class Data2VecTextConfig(PretrainedConfig):32 r"""33 This is the configuration class to store the configuration of a [`Data2VecTextModel`] and [`Data2VecTextModel`]. It34 is used to instantiate a Data2VecText model according to the specified arguments, defining the model architecture.35 Instantiating a configuration with the defaults will yield a similar configuration to that of the Data2VecText36 [facebook/data2vec-text-base](https://huggingface.co/facebook/data2vec-text-base) architecture.37 38 Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the39 documentation from [`PretrainedConfig`] for more information.40 41 42 Args:43 vocab_size (`int`, *optional*, defaults to 30522):44 Vocabulary size of the DATA2VEC model. Defines the number of different tokens that can be represented by45 the `inputs_ids` passed when calling [`Data2VecModel`].46 hidden_size (`int`, *optional*, defaults to 768):47 Dimensionality of the encoder layers and the pooler layer.48 num_hidden_layers (`int`, *optional*, defaults to 12):49 Number of hidden layers in the Transformer encoder.50 num_attention_heads (`int`, *optional*, defaults to 12):51 Number of attention heads for each attention layer in the Transformer encoder.52 intermediate_size (`int`, *optional*, defaults to 3072):53 Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.54 hidden_act (`str` or `Callable`, *optional*, defaults to `"gelu"`):55 The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,56 `"relu"`, `"silu"` and `"gelu_new"` are supported.57 hidden_dropout_prob (`float`, *optional*, defaults to 0.1):58 The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.59 attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):60 The dropout ratio for the attention probabilities.61 max_position_embeddings (`int`, *optional*, defaults to 512):62 The maximum sequence length that this model might ever be used with. Typically set this to something large63 just in case (e.g., 512 or 1024 or 2048).64 type_vocab_size (`int`, *optional*, defaults to 2):65 The vocabulary size of the `token_type_ids` passed when calling [`Data2VecModel`].66 initializer_range (`float`, *optional*, defaults to 0.02):67 The standard deviation of the truncated_normal_initializer for initializing all weight matrices.68 layer_norm_eps (`float`, *optional*, defaults to 1e-12):69 The epsilon used by the layer normalization layers.70 position_embedding_type (`str`, *optional*, defaults to `"absolute"`):71 Type of position embedding. Choose one of `"absolute"`, `"relative_key"`, `"relative_key_query"`. For72 positional embeddings use `"absolute"`. For more information on `"relative_key"`, please refer to73 [Self-Attention with Relative Position Representations (Shaw et al.)](https://arxiv.org/abs/1803.02155).74 For more information on `"relative_key_query"`, please refer to *Method 4* in [Improve Transformer Models75 with Better Relative Position Embeddings (Huang et al.)](https://arxiv.org/abs/2009.13658).76 is_decoder (`bool`, *optional*, defaults to `False`):77 Whether the model is used as a decoder or not. If `False`, the model is used as an encoder.78 use_cache (`bool`, *optional*, defaults to `True`):79 Whether or not the model should return the last key/values attentions (not used by all models). Only80 relevant if `config.is_decoder=True`.81 classifier_dropout (`float`, *optional*):82 The dropout ratio for the classification head.83 84 Examples:85 86 ```python87 >>> from transformers import Data2VecTextConfig, Data2VecTextModel88 89 >>> # Initializing a Data2VecText facebook/data2vec-text-base style configuration90 >>> configuration = Data2VecTextConfig()91 92 >>> # Initializing a model (with random weights) from the facebook/data2vec-text-base style configuration93 >>> model = Data2VecTextModel(configuration)94 95 >>> # Accessing the model configuration96 >>> configuration = model.config97 ```"""98 model_type = "data2vec-text"99 100 def __init__(101 self,102 vocab_size=30522,103 hidden_size=768,104 num_hidden_layers=12,105 num_attention_heads=12,106 intermediate_size=3072,107 hidden_act="gelu",108 hidden_dropout_prob=0.1,109 attention_probs_dropout_prob=0.1,110 max_position_embeddings=512,111 type_vocab_size=2,112 initializer_range=0.02,113 layer_norm_eps=1e-12,114 pad_token_id=1,115 bos_token_id=0,116 eos_token_id=2,117 position_embedding_type="absolute",118 use_cache=True,119 classifier_dropout=None,120 **kwargs,121 ):122 super().__init__(pad_token_id=pad_token_id, bos_token_id=bos_token_id, eos_token_id=eos_token_id, **kwargs)123 124 self.vocab_size = vocab_size125 self.hidden_size = hidden_size126 self.num_hidden_layers = num_hidden_layers127 self.num_attention_heads = num_attention_heads128 self.hidden_act = hidden_act129 self.intermediate_size = intermediate_size130 self.hidden_dropout_prob = hidden_dropout_prob131 self.attention_probs_dropout_prob = attention_probs_dropout_prob132 self.max_position_embeddings = max_position_embeddings133 self.type_vocab_size = type_vocab_size134 self.initializer_range = initializer_range135 self.layer_norm_eps = layer_norm_eps136 self.position_embedding_type = position_embedding_type137 self.use_cache = use_cache138 self.classifier_dropout = classifier_dropout139 140 141class Data2VecTextOnnxConfig(OnnxConfig):142 @property143 def inputs(self) -> Mapping[str, Mapping[int, str]]:144 if self.task == "multiple-choice":145 dynamic_axis = {0: "batch", 1: "choice", 2: "sequence"}146 else:147 dynamic_axis = {0: "batch", 1: "sequence"}148 return OrderedDict(149 [150 ("input_ids", dynamic_axis),151 ("attention_mask", dynamic_axis),152 ]153 )154 