Aluode/PerceptionLabPortable
0
1# coding=utf-82# Copyright 2020 The Trax Authors and The HuggingFace Inc. team.3# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.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 at8#9# http://www.apache.org/licenses/LICENSE-2.010#11# Unless required by applicable law or agreed to in writing, software12# 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 and15# limitations under the License.16"""Reformer model configuration"""17 18from ...configuration_utils import PretrainedConfig19from ...utils import logging20 21 22logger = logging.get_logger(__name__)23 24 25class ReformerConfig(PretrainedConfig):26 r"""27 This is the configuration class to store the configuration of a [`ReformerModel`]. It is used to instantiate a28 Reformer model according to the specified arguments, defining the model architecture. Instantiating a configuration29 with the defaults will yield a similar configuration to that of the ReFormer30 [google/reformer-crime-and-punishment](https://huggingface.co/google/reformer-crime-and-punishment) architecture.31 32 Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the33 documentation from [`PretrainedConfig`] for more information.34 35 Args:36 attention_head_size (`int`, *optional*, defaults to 64):37 Dimensionality of the projected key, query and value vectors38 attn_layers (`list[str]`, *optional*, defaults to `["local", "lsh", "local", "lsh", "local", "lsh"]`):39 List of attention layer types in ascending order. It can be chosen between a LSHSelfAttention layer40 (`"lsh"`) and a LocalSelfAttention layer (`"local"`).41 42 For more information on LSHSelfAttention layer, see [LSH Self Attention](reformer#lsh-self-attention). For43 more information on LocalSelfAttention layer, see [Local Self Attention](reformer#local-self-attention).44 axial_pos_embds (`bool`, *optional*, defaults to `True`):45 Whether or not to use axial position embeddings. For more information on how axial position embeddings46 work, see [Axial Position Encodings](reformer#axial-positional-encodings).47 axial_norm_std (`float`, *optional*, defaults to 1.0):48 The standard deviation of the normal_initializer for initializing the weight matrices of the axial49 positional encodings.50 axial_pos_shape (`list[int]`, *optional*, defaults to `[64, 64]`):51 The position dims of the axial position encodings. During training, the product of the position dims has to52 be equal to the sequence length.53 54 For more information on how axial position embeddings work, see [Axial Position55 Encodings](reformer#axial-positional-encodings).56 axial_pos_embds_dim (`list[int]`, *optional*, defaults to `[64, 192]`):57 The embedding dims of the axial position encodings. The sum of the embedding dims has to be equal to the58 hidden size.59 60 For more information on how axial position embeddings work, see [Axial Position61 Encodings](reformer#axial-positional-encodings).62 chunk_size_lm_head (`int`, *optional*, defaults to 0):63 The chunk size of the final language model feed forward head layer. A chunk size of 0 means that the feed64 forward layer is not chunked. A chunk size of n means that the feed forward layer processes n <65 sequence_length embeddings at a time.66 67 For more information on feed forward chunking, see [How does Feed Forward Chunking68 work?](../glossary#feed-forward-chunking).69 eos_token_id (`int`, *optional*, defaults to 2):70 The token id for the end-of-sentence token.71 feed_forward_size (`int`, *optional*, defaults to 512):72 Dimensionality of the feed_forward layer in the residual attention block.73 hash_seed (`int`, *optional*):74 Seed that can be used to make local sensitive hashing in `LSHSelfAttention` deterministic. This should only75 be set for testing purposed. For evaluation and training purposes `hash_seed` should be left as `None` to76 ensure fully random rotations in local sensitive hashing scheme.77 hidden_act (`str` or `Callable`, *optional*, defaults to `"relu"`):78 The non-linear activation function (function or string) in the feed forward layer in the residual attention79 block. If string, `"gelu"`, `"relu"`, `"silu"` and `"gelu_new"` are supported.80 hidden_dropout_prob (`float`, *optional*, defaults to 0.05):81 The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.82 hidden_size (`int`, *optional*, defaults to 256):83 Dimensionality of the output hidden states of the residual attention blocks.84 initializer_range (`float`, *optional*, defaults to 0.02):85 The standard deviation of the truncated_normal_initializer for initializing all weight matrices.86 is_decoder (`bool`, *optional*, defaults to `False`):87 Whether or not to use a causal mask in addition to the `attention_mask` passed to [`ReformerModel`]. When88 using the Reformer for causal language modeling, this argument should be set to `True`.89 layer_norm_eps (`float`, *optional*, defaults to 1e-12):90 The epsilon used by the layer normalization layers.91 local_chunk_length (`int`, *optional*, defaults to 64):92 Length of chunk which attends to itself in `LocalSelfAttention`. Chunking reduces memory complexity from93 sequence length x sequence length (self attention) to chunk length x chunk length x sequence length / chunk94 length (chunked self attention).95 local_num_chunks_before (`int`, *optional*, defaults to 1):96 Number of previous neighbouring chunks to attend to in `LocalSelfAttention` layer to itself.97 local_num_chunks_after (`int`, *optional*, defaults to 0):98 Number of following neighbouring chunks to attend to in `LocalSelfAttention` layer in addition to itself.99 local_attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):100 The dropout ratio for the attention probabilities in `LocalSelfAttention`.101 lsh_attn_chunk_length (`int`, *optional*, defaults to 64):102 Length of chunk which attends to itself in `LSHSelfAttention`. Chunking reduces memory complexity from103 sequence length x sequence length (self attention) to chunk length x chunk length x sequence length / chunk104 length (chunked self attention).105 lsh_num_chunks_before (`int`, *optional*, defaults to 1):106 Number of previous neighbouring chunks to attend to in `LSHSelfAttention` layer to itself.107 lsh_num_chunks_after (`int`, *optional*, defaults to 0):108 Number of following neighbouring chunks to attend to in `LSHSelfAttention` layer to itself.109 lsh_attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):110 The dropout ratio for the attention probabilities in `LSHSelfAttention`.111 max_position_embeddings (`int`, *optional*, defaults to 4096):112 The maximum sequence length that this model might ever be used with. Typically set this to something large113 just in case (e.g., 512 or 1024 or 2048).114 num_attention_heads (`int`, *optional*, defaults to 12):115 Number of attention heads for each attention layer in the Transformer encoder.116 num_buckets (`int` or `list[int]`, *optional*):117 Number of buckets, the key query vectors can be "hashed into" using the locality sensitive hashing scheme.118 Each query key vector is hashed into a hash in `1, ..., num_buckets`. The number of buckets can also be119 factorized into a list for improved memory complexity. In this case, each query key vector is hashed into a120 hash in `1-1, 1-2, ..., num_buckets[0]-1, ..., num_buckets[0]-num_buckets[1]` if `num_buckets` is121 factorized into two factors. The number of buckets (or the product the factors) should approximately equal122 sequence length / lsh_chunk_length. If `num_buckets` not set, a good value is calculated on the fly.123 num_hashes (`int`, *optional*, defaults to 1):124 Number of hashing rounds (e.g., number of random rotations) in Local Sensitive Hashing scheme. The higher125 `num_hashes`, the more accurate the `LSHSelfAttention` becomes, but also the more memory and time intensive126 the hashing becomes.127 pad_token_id (`int`, *optional*, defaults to 0):128 The token id for the padding token.129 vocab_size (`int`, *optional*, defaults to 320):\130 Vocabulary size of the Reformer model. Defines the number of different tokens that can be represented by131 the `inputs_ids` passed when calling [`ReformerModel`].132 tie_word_embeddings (`bool`, *optional*, defaults to `False`):133 Whether to tie input and output embeddings.134 use_cache (`bool`, *optional*, defaults to `True`):135 Whether or not the model should return the last key/values attentions (not used by all models).136 classifier_dropout (`float`, *optional*):137 The dropout ratio for the classification head.138 139 Examples:140 141 ```python142 >>> from transformers import ReformerConfig, ReformerModel143 144 >>> # Initializing a Reformer configuration145 >>> configuration = ReformerConfig()146 147 >>> # Initializing a Reformer model (with random weights)148 >>> model = ReformerModel(configuration)149 150 >>> # Accessing the model configuration151 >>> configuration = model.config152 ```153"""154 155 model_type = "reformer"156 keys_to_ignore_at_inference = ["past_buckets_states"]157 attribute_map = {}158 159 def __init__(160 self,161 attention_head_size=64,162 attn_layers=["local", "lsh", "local", "lsh", "local", "lsh"],163 axial_norm_std=1.0,164 axial_pos_embds=True,165 axial_pos_shape=[64, 64],166 axial_pos_embds_dim=[64, 192],167 chunk_size_lm_head=0,168 eos_token_id=2,169 feed_forward_size=512,170 hash_seed=None,171 hidden_act="relu",172 hidden_dropout_prob=0.05,173 hidden_size=256,174 initializer_range=0.02,175 is_decoder=False,176 layer_norm_eps=1e-12,177 local_num_chunks_before=1,178 local_num_chunks_after=0,179 local_attention_probs_dropout_prob=0.05,180 local_attn_chunk_length=64,181 lsh_attn_chunk_length=64,182 lsh_attention_probs_dropout_prob=0.0,183 lsh_num_chunks_before=1,184 lsh_num_chunks_after=0,185 max_position_embeddings=4096,186 num_attention_heads=12,187 num_buckets=None,188 num_hashes=1,189 pad_token_id=0,190 vocab_size=320,191 tie_word_embeddings=False,192 use_cache=True,193 classifier_dropout=None,194 **kwargs,195 ):196 self.hash_seed = hash_seed197 self.vocab_size = vocab_size198 self.attention_head_size = attention_head_size199 self.hidden_size = hidden_size200 self.num_attention_heads = num_attention_heads201 self.num_hashes = num_hashes202 self.num_hidden_layers = len(attn_layers)203 self.num_buckets = tuple(num_buckets) if isinstance(num_buckets, list) else num_buckets204 self.lsh_attn_chunk_length = lsh_attn_chunk_length205 self.local_attn_chunk_length = local_attn_chunk_length206 self.lsh_num_chunks_after = lsh_num_chunks_after207 self.lsh_num_chunks_before = lsh_num_chunks_before208 self.local_num_chunks_after = local_num_chunks_after209 self.local_num_chunks_before = local_num_chunks_before210 self.hidden_act = hidden_act211 self.feed_forward_size = feed_forward_size212 self.hidden_dropout_prob = hidden_dropout_prob213 self.lsh_attention_probs_dropout_prob = lsh_attention_probs_dropout_prob214 self.local_attention_probs_dropout_prob = local_attention_probs_dropout_prob215 self.max_position_embeddings = max_position_embeddings216 self.initializer_range = initializer_range217 self.layer_norm_eps = layer_norm_eps218 self.axial_pos_embds = axial_pos_embds219 self.axial_pos_shape = tuple(axial_pos_shape)220 self.axial_pos_embds_dim = tuple(axial_pos_embds_dim)221 self.axial_norm_std = axial_norm_std222 self.chunk_size_lm_head = chunk_size_lm_head223 self.attn_layers = attn_layers224 self.use_cache = use_cache225 self.classifier_dropout = classifier_dropout226 super().__init__(227 pad_token_id=pad_token_id,228 eos_token_id=eos_token_id,229 is_decoder=is_decoder,230 tie_word_embeddings=tie_word_embeddings,231 **kwargs,232 )233 234 235__all__ = ["ReformerConfig"]236 