dongxq commited on
Commit
1c4d99f
1 Parent(s): 4a517d1

Upload configuration_deltalm.py

Browse files
Files changed (1) hide show
  1. configuration_deltalm.py +170 -0
configuration_deltalm.py ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """ deltalm model configuration"""
5
+
6
+ import warnings
7
+ from transformers.configuration_utils import PretrainedConfig
8
+ from transformers.utils import logging
9
+ logger = logging.get_logger(__name__)
10
+
11
+ BART_PRETRAINED_CONFIG_ARCHIVE_MAP = {
12
+ "IDEA/Deltalm": "https://huggingface.co/facebook/bart-large/resolve/main/config.json",
13
+ # See all deltalm models at https://huggingface.co/models?filter=deltam
14
+ }
15
+
16
+
17
+ class DeltalmConfig(PretrainedConfig):
18
+ r"""
19
+ This is the configuration class to store the configuration of a [`DeltalmModel`]. It is used to instantiate a Deltalm
20
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
21
+ defaults will yield a similar configuration to that of the BART
22
+ [facebook/bart-large](https://huggingface.co/facebook/bart-large) architecture.
23
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
24
+ documentation from [`PretrainedConfig`] for more information.
25
+ Args:
26
+ vocab_size (`int`, *optional*, defaults to 50265):
27
+ Vocabulary size of the BART model. Defines the number of different tokens that can be represented by the
28
+ `inputs_ids` passed when calling [`BartModel`] or [`TFBartModel`].
29
+ d_model (`int`, *optional*, defaults to 1024):
30
+ Dimensionality of the layers and the pooler layer.
31
+ encoder_layers (`int`, *optional*, defaults to 12):
32
+ Number of encoder layers.
33
+ decoder_layers (`int`, *optional*, defaults to 12):
34
+ Number of decoder layers.
35
+ encoder_attention_heads (`int`, *optional*, defaults to 16):
36
+ Number of attention heads for each attention layer in the Transformer encoder.
37
+ decoder_attention_heads (`int`, *optional*, defaults to 16):
38
+ Number of attention heads for each attention layer in the Transformer decoder.
39
+ decoder_ffn_dim (`int`, *optional*, defaults to 4096):
40
+ Dimensionality of the "intermediate" (often named feed-forward) layer in decoder.
41
+ encoder_ffn_dim (`int`, *optional*, defaults to 4096):
42
+ Dimensionality of the "intermediate" (often named feed-forward) layer in decoder.
43
+ activation_function (`str` or `function`, *optional*, defaults to `"gelu"`):
44
+ The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
45
+ `"relu"`, `"silu"` and `"gelu_new"` are supported.
46
+ dropout (`float`, *optional*, defaults to 0.1):
47
+ The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
48
+ attention_dropout (`float`, *optional*, defaults to 0.0):
49
+ The dropout ratio for the attention probabilities.
50
+ activation_dropout (`float`, *optional*, defaults to 0.0):
51
+ The dropout ratio for activations inside the fully connected layer.
52
+ classifier_dropout (`float`, *optional*, defaults to 0.0):
53
+ The dropout ratio for classifier.
54
+ max_position_embeddings (`int`, *optional*, defaults to 1024):
55
+ The maximum sequence length that this model might ever be used with. Typically set this to something large
56
+ just in case (e.g., 512 or 1024 or 2048).
57
+ init_std (`float`, *optional*, defaults to 0.02):
58
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
59
+ encoder_layerdrop: (`float`, *optional*, defaults to 0.0):
60
+ The LayerDrop probability for the encoder. See the [LayerDrop paper](see https://arxiv.org/abs/1909.11556)
61
+ for more details.
62
+ decoder_layerdrop: (`float`, *optional*, defaults to 0.0):
63
+ The LayerDrop probability for the decoder. See the [LayerDrop paper](see https://arxiv.org/abs/1909.11556)
64
+ for more details.
65
+ scale_embedding (`bool`, *optional*, defaults to `False`):
66
+ Scale embeddings by diving by sqrt(d_model).
67
+ use_cache (`bool`, *optional*, defaults to `True`):
68
+ Whether or not the model should return the last key/values attentions (not used by all models).
69
+ num_labels: (`int`, *optional*, defaults to 3):
70
+ The number of labels to use in [`BartForSequenceClassification`].
71
+ forced_eos_token_id (`int`, *optional*, defaults to 2):
72
+ The id of the token to force as the last generated token when `max_length` is reached. Usually set to
73
+ `eos_token_id`.
74
+ Example:
75
+ ```python
76
+ >>> from transformers import BartModel, BartConfig
77
+ >>> # Initializing a BART facebook/bart-large style configuration
78
+ >>> configuration = BartConfig()
79
+ >>> # Initializing a model from the facebook/bart-large style configuration
80
+ >>> model = BartModel(configuration)
81
+ >>> # Accessing the model configuration
82
+ >>> configuration = model.config
83
+ ```"""
84
+ model_type = "Deltalm"
85
+ keys_to_ignore_at_inference = ["past_key_values"]
86
+ attribute_map = {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}
87
+
88
+ def __init__(
89
+ self,
90
+ vocab_size=250001,
91
+ max_position_embeddings=1024,
92
+ encoder_layers=12,
93
+ encoder_ffn_dim=3072,
94
+ encoder_attention_heads=12,
95
+ decoder_layers=6,
96
+ decoder_ffn_dim=3072,
97
+ decoder_attention_heads=12,
98
+ encoder_layerdrop=0.0,
99
+ decoder_layerdrop=0.0,
100
+ activation_function="gelu",
101
+ d_model=1024,
102
+ dropout=0.1,
103
+ attention_dropout=0.0,
104
+ activation_dropout=0.0,
105
+ init_std=0.02,
106
+ classifier_dropout=0.0,
107
+ scale_embedding=False,
108
+ use_cache=True,
109
+ num_labels=3,
110
+ pad_token_id=1,
111
+ bos_token_id=0,
112
+ eos_token_id=2,
113
+ is_encoder_decoder=True,
114
+ decoder_start_token_id=0,
115
+ forced_eos_token_id=2,
116
+ label_smoothing=0.1,
117
+ length_penalty=1.0,
118
+ encoder_normalize_before=False,
119
+ **kwargs
120
+ ):
121
+ self.vocab_size = vocab_size
122
+ self.max_position_embeddings = max_position_embeddings
123
+ self.d_model = d_model
124
+ self.encoder_ffn_dim = encoder_ffn_dim
125
+ self.encoder_layers = encoder_layers
126
+ self.encoder_attention_heads = encoder_attention_heads
127
+ self.decoder_ffn_dim = decoder_ffn_dim
128
+ self.decoder_layers = decoder_layers
129
+ self.decoder_attention_heads = decoder_attention_heads
130
+ self.dropout = dropout
131
+ self.attention_dropout = attention_dropout
132
+ self.activation_dropout = activation_dropout
133
+ self.activation_function = activation_function
134
+ self.init_std = init_std
135
+ self.encoder_layerdrop = encoder_layerdrop
136
+ self.decoder_layerdrop = decoder_layerdrop
137
+ self.classifier_dropout = classifier_dropout
138
+ self.use_cache = use_cache
139
+ self.num_hidden_layers = encoder_layers
140
+ self.scale_embedding = scale_embedding # scale factor will be sqrt(d_model) if True
141
+ self.label_smoothing = label_smoothing
142
+ self.encoder_normalize_before = encoder_normalize_before
143
+
144
+ super().__init__(
145
+ num_labels=num_labels,
146
+ pad_token_id=pad_token_id,
147
+ bos_token_id=bos_token_id,
148
+ eos_token_id=eos_token_id,
149
+ is_encoder_decoder=is_encoder_decoder,
150
+ decoder_start_token_id=decoder_start_token_id,
151
+ forced_eos_token_id=forced_eos_token_id,
152
+ length_penalty=length_penalty,
153
+ **kwargs,
154
+ )
155
+
156
+ # ensure backward compatibility for BART CNN models
157
+ if self.forced_bos_token_id is None and kwargs.get("force_bos_token_to_be_generated", False):
158
+ self.forced_bos_token_id = self.bos_token_id
159
+ warnings.warn(
160
+ f"Please make sure the config includes `forced_bos_token_id={self.bos_token_id}` in future versions. "
161
+ "The config can simply be saved and uploaded again to be fixed."
162
+ )
163
+
164
+ @property
165
+ def num_attention_heads(self) -> int:
166
+ return self.encoder_attention_heads
167
+
168
+ @property
169
+ def hidden_size(self) -> int:
170
+ return self.d_model