Q-bert commited on
Commit
d5a95ac
·
1 Parent(s): 0c5c972

Create configuration_xglm.py

Browse files
Files changed (1) hide show
  1. configuration_xglm.py +141 -0
configuration_xglm.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 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 at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # 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 and
14
+ # limitations under the License.
15
+ """ XGLM model configuration"""
16
+
17
+ from ...configuration_utils import PretrainedConfig
18
+ from ...utils import logging
19
+
20
+
21
+ logger = logging.get_logger(__name__)
22
+
23
+ XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP = {
24
+ "facebook/xglm-564M": "https://huggingface.co/facebook/xglm-564M/resolve/main/config.json",
25
+ # See all XGLM models at https://huggingface.co/models?filter=xglm
26
+ }
27
+
28
+
29
+ class XGLMConfig(PretrainedConfig):
30
+ r"""
31
+ This is the configuration class to store the configuration of a [`XGLMModel`]. It is used to instantiate an XGLM
32
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
33
+ defaults will yield a similar configuration to that of the XGLM
34
+ [facebook/xglm-564M](https://huggingface.co/facebook/xglm-564M) architecture.
35
+
36
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
37
+ documentation from [`PretrainedConfig`] for more information.
38
+
39
+
40
+ Args:
41
+ vocab_size (`int`, *optional*, defaults to 256008):
42
+ Vocabulary size of the XGLM model. Defines the number of different tokens that can be represented by the
43
+ `inputs_ids` passed when calling [`XGLMModel`] or [`FlaxXGLMModel`].
44
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
45
+ The maximum sequence length that this model might ever be used with. Typically set this to something large
46
+ just in case (e.g., 512 or 1024 or 2048).
47
+ d_model (`int`, *optional*, defaults to 1024):
48
+ Dimension of the layers and the pooler layer.
49
+ ffn_dim (`int`, *optional*, defaults to 4096):
50
+ Dimension of the "intermediate" (often named feed-forward) layer in decoder.
51
+ num_layers (`int`, *optional*, defaults to 24):
52
+ Number of hidden layers Transformer decoder.
53
+ attention_heads (`int`, *optional*, defaults to 16):
54
+ Number of attention heads for each attention layer in the Transformer decoder.
55
+ activation_function (`str` or `function`, *optional*, defaults to `"gelu"`):
56
+ The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
57
+ `"relu"`, `"silu"` and `"gelu_new"` are supported.
58
+ dropout (`float`, *optional*, defaults to 0.1):
59
+ The dropout probability for all fully connected layers in the embeddings, dencoder, and pooler.
60
+ attention_dropout (`float`, *optional*, defaults to 0.1):
61
+ The dropout ratio for the attention probabilities.
62
+ activation_dropout (`float`, *optional*, defaults to 0.0):
63
+ The dropout ratio for activations inside the fully connected layer.
64
+ layerdrop (`float`, *optional*, defaults to 0.0):
65
+ The LayerDrop probability for the encoder. See the [LayerDrop paper](see https://arxiv.org/abs/1909.11556)
66
+ for more details.
67
+ init_std (`float`, *optional*, defaults to 0.02):
68
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
69
+ scale_embedding (`bool`, *optional*, defaults to `True`):
70
+ Scale embeddings by diving by sqrt(d_model).
71
+ use_cache (`bool`, *optional*, defaults to `True`):
72
+ Whether or not the model should return the last key/values attentions (not used by all models).
73
+
74
+ Example:
75
+
76
+ ```python
77
+ >>> from transformers import XGLMModel, XGLMConfig
78
+
79
+ >>> # Initializing a XGLM facebook/xglm-564M style configuration
80
+ >>> configuration = XGLMConfig()
81
+
82
+ >>> # Initializing a model from the facebook/xglm-564M style configuration
83
+ >>> model = XGLMModel(configuration)
84
+
85
+ >>> # Accessing the model configuration
86
+ >>> configuration = model.config
87
+ ```"""
88
+
89
+ model_type = "xglm"
90
+ keys_to_ignore_at_inference = ["past_key_values"]
91
+
92
+ attribute_map = {
93
+ "num_attention_heads": "attention_heads",
94
+ "hidden_size": "d_model",
95
+ "num_hidden_layers": "num_layers",
96
+ }
97
+
98
+ def __init__(
99
+ self,
100
+ vocab_size=256008,
101
+ max_position_embeddings=2048,
102
+ d_model=1024,
103
+ ffn_dim=4096,
104
+ num_layers=24,
105
+ attention_heads=16,
106
+ activation_function="gelu",
107
+ dropout=0.1,
108
+ attention_dropout=0.1,
109
+ activation_dropout=0.0,
110
+ layerdrop=0.0,
111
+ init_std=0.02,
112
+ scale_embedding=True,
113
+ use_cache=True,
114
+ decoder_start_token_id=2,
115
+ pad_token_id=1,
116
+ bos_token_id=0,
117
+ eos_token_id=2,
118
+ **kwargs,
119
+ ):
120
+ self.vocab_size = vocab_size
121
+ self.max_position_embeddings = max_position_embeddings
122
+ self.d_model = d_model
123
+ self.ffn_dim = ffn_dim
124
+ self.num_layers = num_layers
125
+ self.attention_heads = attention_heads
126
+ self.activation_function = activation_function
127
+ self.dropout = dropout
128
+ self.attention_dropout = attention_dropout
129
+ self.activation_dropout = activation_dropout
130
+ self.layerdrop = layerdrop
131
+ self.init_std = init_std
132
+ self.scale_embedding = scale_embedding # scale factor will be sqrt(d_model) if True
133
+ self.use_cache = use_cache
134
+
135
+ super().__init__(
136
+ pad_token_id=pad_token_id,
137
+ bos_token_id=bos_token_id,
138
+ eos_token_id=eos_token_id,
139
+ decoder_start_token_id=decoder_start_token_id,
140
+ **kwargs,
141
+ )