hgissbkh commited on
Commit
dde9b50
·
verified ·
1 Parent(s): 4669334

Upload modeling files

Browse files
Files changed (1) hide show
  1. configuration_sl_model.py +177 -0
configuration_sl_model.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers.utils import logging
2
+ from transformers.models.llama import LlamaConfig
3
+
4
+
5
+ logger = logging.get_logger(__name__)
6
+
7
+
8
+ class SLModelConfig(LlamaConfig):
9
+ r"""
10
+ This is the configuration class to store the configuration of a [`SLModelModel`]. It is used to instantiate an SLModel
11
+ model according to the specified arguments, defining the model architecture.
12
+
13
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
14
+ documentation from [`PretrainedConfig`] for more information.
15
+
16
+
17
+ Args:
18
+ vocab_size (`int`, *optional*, defaults to 128256):
19
+ Vocabulary size of the SLModel model. Defines the number of different tokens that can be represented by the
20
+ `inputs_ids` passed when calling [`SLModel`]
21
+ hidden_size (`int`, *optional*, defaults to 768):
22
+ Dimensionality of the encoder layers and the pooler layer.
23
+ intermediate_size (`int`, *optional*, defaults to 3072):
24
+ Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
25
+ num_hidden_layers (`int`, *optional*, defaults to 12):
26
+ Number of hidden layers in the Transformer encoder.
27
+ num_attention_heads (`int`, *optional*, defaults to 12):
28
+ Number of attention heads for each attention layer in the Transformer encoder.
29
+ num_key_value_heads (`int`, *optional*):
30
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
31
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
32
+ `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
33
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
34
+ by meanpooling all the original heads within that group. For more details checkout [this
35
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
36
+ `num_attention_heads`.
37
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
38
+ The non-linear activation function (function or string) in the encoder and pooler.
39
+ max_position_embeddings (`int`, *optional*, defaults to 8192):
40
+ The maximum sequence length that this model might ever be used with.
41
+ initializer_range (`float`, *optional*, defaults to 0.02):
42
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
43
+ rms_norm_eps (`float`, *optional*, defaults to 1e-05):
44
+ The epsilon used by the rms normalization layers.
45
+ bos_token_id (`int`, *optional*, defaults to 128000):
46
+ Beginning of stream token id.
47
+ eos_token_id (`int`, *optional*, defaults to 128001):
48
+ End of stream token id.
49
+ pad_token_id (`int`, *optional*, defaults to 128001):
50
+ Padding token id.
51
+ mask_token_id (`int`, *optional*, defaults to 128002):
52
+ Mask token id.
53
+ pretraining_tp (`int`, *optional*, defaults to 1):
54
+ Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
55
+ document](https://huggingface.co/docs/transformers/main/perf_train_gpu_many#tensor-parallelism) to
56
+ understand more about it. This value is necessary to ensure exact reproducibility of the pretraining
57
+ results. Please refer to [this issue](https://github.com/pytorch/pytorch/issues/76232).
58
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
59
+ Whether to tie weight embeddings
60
+ rope_theta (`float`, *optional*, defaults to 250000.0):
61
+ The base period of the RoPE embeddings.
62
+ rope_scaling (`Dict`, *optional*):
63
+ Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
64
+ and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
65
+ accordingly.
66
+ Expected contents:
67
+ `rope_type` (`str`):
68
+ The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope'],
69
+ with 'default' being the original RoPE implementation.
70
+ `factor` (`float`, *optional*):
71
+ Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
72
+ most scaling types, a `factor` of x will enable the model to handle sequences of length x *
73
+ original maximum pre-trained length.
74
+ `original_max_position_embeddings` (`int`, *optional*):
75
+ Used with 'dynamic', 'longrope'. The original max position embeddings used during
76
+ pretraining.
77
+ `attention_factor` (`float`, *optional*):
78
+ Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
79
+ computation. If unspecified, it defaults to value recommended by the implementation, using the
80
+ `factor` field to infer the suggested value.
81
+ `beta_fast` (`float`, *optional*):
82
+ Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
83
+ ramp function. If unspecified, it defaults to 32.
84
+ `beta_slow` (`float`, *optional*):
85
+ Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
86
+ ramp function. If unspecified, it defaults to 1.
87
+ `short_factor` (`List[float]`, *optional*):
88
+ Only used with 'longrope'. The scaling factor to be applied to short contexts (<
89
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
90
+ size divided by the number of attention heads divided by 2
91
+ `long_factor` (`List[float]`, *optional*):
92
+ Only used with 'longrope'. The scaling factor to be applied to long contexts (<
93
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
94
+ size divided by the number of attention heads divided by 2
95
+ attention_bias (`bool`, *optional*, defaults to `False`):
96
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
97
+ attention_dropout (`float`, *optional*, defaults to 0.0):
98
+ The dropout ratio for the attention probabilities.
99
+ mlp_bias (`bool`, *optional*, defaults to `False`):
100
+ Whether to use a bias in up_proj, down_proj and gate_proj layers in the MLP layers.
101
+ head_dim (`int`, *optional*):
102
+ The attention head dimension. If None, it will default to hidden_size // num_attention_heads
103
+ classifier_pooling (`str`, *optional*, defaults to `"late"`):
104
+ The pooling strategy to use for the classifier. Can be one of ['mean', 'eos'].
105
+ retrieval_pooling (`str`, *optional*, defaults to `"late"`):
106
+ The pooling strategy to use for the retriever. Can be one of ['mean', 'eos'].
107
+ """
108
+
109
+ model_type = "sl_model"
110
+
111
+ def __init__(
112
+ self,
113
+ vocab_size=128256,
114
+ hidden_size=768,
115
+ intermediate_size=3072,
116
+ num_hidden_layers=12,
117
+ num_attention_heads=12,
118
+ num_key_value_heads=None,
119
+ hidden_act="silu",
120
+ max_position_embeddings=8192,
121
+ initializer_range=0.02,
122
+ rms_norm_eps=1e-05,
123
+ bos_token_id=128000,
124
+ eos_token_id=128001,
125
+ pad_token_id=128001,
126
+ mask_token_id=128002,
127
+ pretraining_tp=1,
128
+ tie_word_embeddings=False,
129
+ rope_theta=250000.0,
130
+ rope_scaling=None,
131
+ attention_bias=False,
132
+ attention_dropout=0.0,
133
+ mlp_bias=False,
134
+ head_dim=None,
135
+ classifier_pooling="mean",
136
+ retrieval_pooling="mean",
137
+ is_causal=False,
138
+ **kwargs,
139
+ ):
140
+ if num_key_value_heads is None:
141
+ num_key_value_heads = num_attention_heads
142
+
143
+ if "use_cache" in kwargs:
144
+ kwargs.pop("use_cache", None)
145
+
146
+ super().__init__(
147
+ vocab_size=vocab_size,
148
+ hidden_size=hidden_size,
149
+ intermediate_size=intermediate_size,
150
+ num_hidden_layers=num_hidden_layers,
151
+ num_attention_heads=num_attention_heads,
152
+ num_key_value_heads=num_key_value_heads,
153
+ hidden_act=hidden_act,
154
+ max_position_embeddings=max_position_embeddings,
155
+ initializer_range=initializer_range,
156
+ rms_norm_eps=rms_norm_eps,
157
+ use_cache=False,
158
+ bos_token_id=bos_token_id,
159
+ eos_token_id=eos_token_id,
160
+ pad_token_id=pad_token_id,
161
+ pretraining_tp=pretraining_tp,
162
+ tie_word_embeddings=tie_word_embeddings,
163
+ rope_theta=rope_theta,
164
+ rope_scaling=rope_scaling,
165
+ attention_bias=attention_bias,
166
+ attention_dropout=attention_dropout,
167
+ mlp_bias=mlp_bias,
168
+ head_dim=head_dim,
169
+ **kwargs,
170
+ )
171
+ self.mask_token_id = mask_token_id
172
+ self.classifier_pooling = classifier_pooling
173
+ self.retrieval_pooling = retrieval_pooling
174
+ self.is_causal = is_causal
175
+
176
+
177
+ __all__ = ["SLModelConfig"]