vltnmmdv commited on
Commit
573192f
·
verified ·
1 Parent(s): 41adb6c

Delete configuration_deepseek_fixed.py

Browse files
Files changed (1) hide show
  1. configuration_deepseek_fixed.py +0 -206
configuration_deepseek_fixed.py DELETED
@@ -1,206 +0,0 @@
1
- from typing import Optional
2
-
3
- from transformers.configuration_utils import PretrainedConfig
4
- from transformers.utils import logging
5
-
6
- logger = logging.get_logger(__name__)
7
-
8
- DEEPSEEK_FIXES_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
9
- class DeepseekFixedConfig(PretrainedConfig):
10
- r"""
11
- This is the configuration class to store the configuration of a DeepseekWithConcentrationekModel`]. It is used to instantiate an DeepSeek
12
- model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
13
- defaults will yield a similar configuration to that of the DeepseekWithConcentration-7B.
14
-
15
- Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
16
- documentation from [`PretrainedConfig`] for more information.
17
-
18
-
19
- Args:
20
- vocab_size (`int`, *optional*, defaults to 102400):
21
- Vocabulary size of the Deep model. Defines the number of different tokens that can be represented by the
22
- `inputs_ids` passed when calling [`DeepseekWithConcentrationModel`]
23
- hidden_size (`int`, *optional*, defaults to 4096):
24
- Dimension of the hidden representations.
25
- intermediate_size (`int`, *optional*, defaults to 11008):
26
- Dimension of the MLP representations.
27
- moe_intermediate_size (`int`, *optional*, defaults to 1407):
28
- Dimension of the MoE representations.
29
- num_hidden_layers (`int`, *optional*, defaults to 32):
30
- Number of hidden layers in the Transformer decoder.
31
- num_attention_heads (`int`, *optional*, defaults to 32):
32
- Number of attention heads for each attention layer in the Transformer decoder.
33
- n_shared_experts (`int`, *optional*, defaults to None):
34
- Number of shared experts, None means dense model.
35
- n_routed_experts (`int`, *optional*, defaults to None):
36
- Number of routed experts, None means dense model.
37
- num_experts_per_tok (`int`, *optional*, defaults to None):
38
- Number of selected experts, None means dense model.
39
- moe_layer_freq (`int`, *optional*, defaults to 1):
40
- The frequency of the MoE layer: one expert layer for every `moe_layer_freq - 1` dense layers.
41
- first_k_dense_replace (`int`, *optional*, defaults to 0):
42
- Number of dense layers in shallow layers(embed->dense->dense->...->dense->moe->moe...->lm_head).
43
- \--k dense layers--/
44
- norm_topk_prob (`bool`, *optional*, defaults to False):
45
- Whether to normalize the weights of the routed experts.
46
- scoring_func (`str`, *optional*, defaults to 'softmax'):
47
- Method of computing expert weights.
48
- aux_loss_alpha (`float`, *optional*, defaults to 0.001):
49
- Auxiliary loss weight coefficient.
50
- seq_aux = (`bool`, *optional*, defaults to True):
51
- Whether to compute the auxiliary loss for each individual sample.
52
- num_key_value_heads (`int`, *optional*):
53
- This is the number of key_value heads that should be used to implement Grouped Query Attention. If
54
- `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
55
- `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
56
- converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
57
- by meanpooling all the original heads within that group. For more details checkout [this
58
- paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
59
- `num_attention_heads`.
60
- hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
61
- The non-linear activation function (function or string) in the decoder.
62
- max_position_embeddings (`int`, *optional*, defaults to 2048):
63
- The maximum sequence length that this model might ever be used with.
64
- initializer_range (`float`, *optional*, defaults to 0.02):
65
- The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
66
- rms_norm_eps (`float`, *optional*, defaults to 1e-06):
67
- The epsilon used by the rms normalization layers.
68
- use_cache (`bool`, *optional*, defaults to `True`):
69
- Whether or not the model should return the last key/values attentions (not used by all models). Only
70
- relevant if `config.is_decoder=True`.
71
- pad_token_id (`int`, *optional*):
72
- Padding token id.
73
- bos_token_id (`int`, *optional*, defaults to 1):
74
- Beginning of stream token id.
75
- eos_token_id (`int`, *optional*, defaults to 2):
76
- End of stream token id.
77
- pretraining_tp (`int`, *optional*, defaults to 1):
78
- Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
79
- document](https://huggingface.co/docs/transformers/parallelism) to understand more about it. This value is
80
- necessary to ensure exact reproducibility of the pretraining results. Please refer to [this
81
- issue](https://github.com/pytorch/pytorch/issues/76232).
82
- tie_word_embeddings (`bool`, *optional*, defaults to `False`):
83
- Whether to tie weight embeddings
84
- rope_theta (`float`, *optional*, defaults to 10000.0):
85
- The base period of the RoPE embeddings.
86
- rope_scaling (`Dict`, *optional*):
87
- Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
88
- strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
89
- `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
90
- `max_position_embeddings` to the expected new maximum.
91
- attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
92
- Whether to use a bias in the query, key, value and output projection layers during self-attention.
93
- attention_dropout (`float`, *optional*, defaults to 0.0):
94
- The dropout ratio for the attention probabilities.
95
-
96
- ```python
97
- >>> from transformers import DeepseekWithConcentrationModel, DeepseekWithConcentrationConfig
98
-
99
- >>> # Initializing a DeepseekWithConcentration DeepseekWithConcentration-7b style configuration
100
- >>> configuration = DeepseekWithConcentrationConfig()
101
-
102
- >>> # Accessing the model configuration
103
- >>> configuration = model.config
104
- ```"""
105
-
106
- model_type = "deepseek_with_concentration"
107
- keys_to_ignore_at_inference = ["past_key_values"]
108
-
109
- def __init__(
110
- self,
111
- vocab_size=102400,
112
- hidden_size=4096,
113
- intermediate_size=11008,
114
- moe_intermediate_size = 1407,
115
- num_hidden_layers=30,
116
- num_attention_heads=32,
117
- num_key_value_heads=32,
118
- n_shared_experts = None,
119
- n_routed_experts = None,
120
- num_experts_per_tok = None,
121
- moe_layer_freq = 1,
122
- first_k_dense_replace = 0,
123
- norm_topk_prob = False,
124
- scoring_func = 'softmax',
125
- aux_loss_alpha = 0.001,
126
- seq_aux = True,
127
- hidden_act="silu",
128
- max_position_embeddings=2048,
129
- initializer_range=0.02,
130
- rms_norm_eps=1e-6,
131
- use_cache=True,
132
- pad_token_id=None,
133
- bos_token_id=100000,
134
- eos_token_id=100001,
135
- pretraining_tp=1,
136
- tie_word_embeddings=False,
137
- rope_theta=10000.0,
138
- rope_scaling=None,
139
- attention_bias=False,
140
- attention_dropout=0.0,
141
- moe_implementation="eager",
142
- **kwargs,
143
- ):
144
- assert moe_implementation in ('eager', 'megablocks'), "Invalid moe_implementation value. Choose from 'eager' or 'megablocks'."
145
- self.vocab_size = vocab_size
146
- self.max_position_embeddings = max_position_embeddings
147
- self.hidden_size = hidden_size
148
- self.intermediate_size = intermediate_size
149
- self.moe_intermediate_size = moe_intermediate_size
150
- self.num_hidden_layers = num_hidden_layers
151
- self.num_attention_heads = num_attention_heads
152
- self.n_shared_experts = n_shared_experts
153
- self.n_routed_experts = n_routed_experts
154
- self.num_experts_per_tok = num_experts_per_tok
155
- self.moe_layer_freq = moe_layer_freq
156
- self.first_k_dense_replace = first_k_dense_replace
157
- self.norm_topk_prob = norm_topk_prob
158
- self.scoring_func = scoring_func
159
- self.aux_loss_alpha = aux_loss_alpha
160
- self.seq_aux = seq_aux
161
-
162
- # for backward compatibility
163
- if num_key_value_heads is None:
164
- num_key_value_heads = num_attention_heads
165
-
166
- self.num_key_value_heads = num_key_value_heads
167
- self.hidden_act = hidden_act
168
- self.initializer_range = initializer_range
169
- self.rms_norm_eps = rms_norm_eps
170
- self.pretraining_tp = pretraining_tp
171
- self.use_cache = use_cache
172
- self.rope_theta = rope_theta
173
- self.rope_scaling = rope_scaling
174
- self._rope_scaling_validation()
175
- self.attention_bias = attention_bias
176
- self.attention_dropout = attention_dropout
177
- self.moe_implementation = moe_implementation
178
-
179
- super().__init__(
180
- pad_token_id=pad_token_id,
181
- bos_token_id=bos_token_id,
182
- eos_token_id=eos_token_id,
183
- tie_word_embeddings=tie_word_embeddings,
184
- **kwargs,
185
- )
186
-
187
- def _rope_scaling_validation(self):
188
- """
189
- Validate the `rope_scaling` configuration.
190
- """
191
- if self.rope_scaling is None:
192
- return
193
-
194
- if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
195
- raise ValueError(
196
- "`rope_scaling` must be a dictionary with with two fields, `type` and `factor`, "
197
- f"got {self.rope_scaling}"
198
- )
199
- rope_scaling_type = self.rope_scaling.get("type", None)
200
- rope_scaling_factor = self.rope_scaling.get("factor", None)
201
- if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
202
- raise ValueError(
203
- f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
204
- )
205
- if rope_scaling_factor is None or not isinstance(rope_scaling_factor, float) or rope_scaling_factor <= 1.0:
206
- raise ValueError(f"`rope_scaling`'s factor field must be a float > 1, got {rope_scaling_factor}")