DoruC/Grounded-Segment-Anything
0
1# coding=utf-82# Copyright 2018 Salesforce and HuggingFace Inc. team.3# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.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""" Salesforce CTRL configuration"""16 17from ...configuration_utils import PretrainedConfig18from ...utils import logging19 20 21logger = logging.get_logger(__name__)22 23CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP = {24 "Salesforce/ctrl": "https://huggingface.co/Salesforce/ctrl/resolve/main/config.json"25}26 27 28class CTRLConfig(PretrainedConfig):29 """30 This is the configuration class to store the configuration of a [`CTRLModel`] or a [`TFCTRLModel`]. It is used to31 instantiate a CTRL model according to the specified arguments, defining the model architecture. Instantiating a32 configuration with the defaults will yield a similar configuration to that of the33 [Salesforce/ctrl](https://huggingface.co/Salesforce/ctrl) architecture from SalesForce.34 35 Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the36 documentation from [`PretrainedConfig`] for more information.37 38 Args:39 vocab_size (`int`, *optional*, defaults to 246534):40 Vocabulary size of the CTRL model. Defines the number of different tokens that can be represented by the41 `inputs_ids` passed when calling [`CTRLModel`] or [`TFCTRLModel`].42 n_positions (`int`, *optional*, defaults to 256):43 The maximum sequence length that this model might ever be used with. Typically set this to something large44 just in case (e.g., 512 or 1024 or 2048).45 n_embd (`int`, *optional*, defaults to 1280):46 Dimensionality of the embeddings and hidden states.47 dff (`int`, *optional*, defaults to 8192):48 Dimensionality of the inner dimension of the feed forward networks (FFN).49 n_layer (`int`, *optional*, defaults to 48):50 Number of hidden layers in the Transformer encoder.51 n_head (`int`, *optional*, defaults to 16):52 Number of attention heads for each attention layer in the Transformer encoder.53 resid_pdrop (`float`, *optional*, defaults to 0.1):54 The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.55 embd_pdrop (`int`, *optional*, defaults to 0.1):56 The dropout ratio for the embeddings.57 layer_norm_epsilon (`float`, *optional*, defaults to 1e-06):58 The epsilon to use in the layer normalization layers59 initializer_range (`float`, *optional*, defaults to 0.02):60 The standard deviation of the truncated_normal_initializer for initializing all weight matrices.61 use_cache (`bool`, *optional*, defaults to `True`):62 Whether or not the model should return the last key/values attentions (not used by all models).63 64 65 Examples:66 67 ```python68 >>> from transformers import CTRLConfig, CTRLModel69 70 >>> # Initializing a CTRL configuration71 >>> configuration = CTRLConfig()72 73 >>> # Initializing a model (with random weights) from the configuration74 >>> model = CTRLModel(configuration)75 76 >>> # Accessing the model configuration77 >>> configuration = model.config78 ```"""79 80 model_type = "ctrl"81 keys_to_ignore_at_inference = ["past_key_values"]82 attribute_map = {83 "max_position_embeddings": "n_positions",84 "hidden_size": "n_embd",85 "num_attention_heads": "n_head",86 "num_hidden_layers": "n_layer",87 }88 89 def __init__(90 self,91 vocab_size=246534,92 n_positions=256,93 n_embd=1280,94 dff=8192,95 n_layer=48,96 n_head=16,97 resid_pdrop=0.1,98 embd_pdrop=0.1,99 layer_norm_epsilon=1e-6,100 initializer_range=0.02,101 use_cache=True,102 **kwargs,103 ):104 self.vocab_size = vocab_size105 self.n_positions = n_positions106 self.n_embd = n_embd107 self.n_layer = n_layer108 self.n_head = n_head109 self.dff = dff110 self.resid_pdrop = resid_pdrop111 self.embd_pdrop = embd_pdrop112 self.layer_norm_epsilon = layer_norm_epsilon113 self.initializer_range = initializer_range114 115 self.use_cache = use_cache116 117 super().__init__(**kwargs)118 