AEmotionStudio commited on
Commit
e90e72a
·
verified ·
1 Parent(s): eae2aef

Mirror configuration_acestep_v15.py from ACE-Step/acestep-v15-base

Browse files
checkpoints/acestep-v15-base/configuration_acestep_v15.py ADDED
@@ -0,0 +1,263 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2024 The Qwen team, Alibaba Group and 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
+ """AceStep model configuration"""
16
+
17
+ from transformers.configuration_utils import PretrainedConfig, layer_type_validation
18
+ from transformers.modeling_rope_utils import rope_config_validation
19
+ from transformers.utils import logging
20
+
21
+
22
+ logger = logging.get_logger(__name__)
23
+
24
+
25
+ class AceStepConfig(PretrainedConfig):
26
+ r"""
27
+ This is the configuration class to store the configuration of a [`AceStepModel`]. It is used to instantiate an
28
+ AceStep model according to the specified arguments, defining the model architecture.
29
+
30
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
31
+ documentation from [`PretrainedConfig`] for more information.
32
+
33
+ Args:
34
+ vocab_size (`int`, *optional*, defaults to 64003):
35
+ Vocabulary size of the AceStep model. Defines the number of different tokens that can be represented by the
36
+ `inputs_ids` passed when calling the model.
37
+ hidden_size (`int`, *optional*, defaults to 4096):
38
+ Dimension of the hidden representations.
39
+ intermediate_size (`int`, *optional*, defaults to 22016):
40
+ Dimension of the MLP representations.
41
+ num_hidden_layers (`int`, *optional*, defaults to 32):
42
+ Number of hidden layers in the Transformer encoder.
43
+ num_attention_heads (`int`, *optional*, defaults to 32):
44
+ Number of attention heads for each attention layer in the Transformer encoder.
45
+ num_key_value_heads (`int`, *optional*, defaults to 32):
46
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
47
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
48
+ `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
49
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
50
+ by meanpooling all the original heads within that group. For more details, check out [this
51
+ paper](https://huggingface.co/papers/2305.13245). If it is not specified, will default to `32`.
52
+ head_dim (`int`, *optional*, defaults to 128):
53
+ The attention head dimension.
54
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
55
+ The non-linear activation function (function or string) in the decoder.
56
+ max_position_embeddings (`int`, *optional*, defaults to 32768):
57
+ The maximum sequence length that this model might ever be used with.
58
+ initializer_range (`float`, *optional*, defaults to 0.02):
59
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
60
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
61
+ The epsilon used by the rms normalization layers.
62
+ use_cache (`bool`, *optional*, defaults to `True`):
63
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
64
+ relevant if `config.is_decoder=True`.
65
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
66
+ Whether the model's input and output word embeddings should be tied.
67
+ rope_theta (`float`, *optional*, defaults to 10000.0):
68
+ The base period of the RoPE embeddings.
69
+ rope_scaling (`Dict`, *optional*):
70
+ Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
71
+ and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
72
+ accordingly.
73
+ Expected contents:
74
+ `rope_type` (`str`):
75
+ The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
76
+ 'llama3'], with 'default' being the original RoPE implementation.
77
+ `factor` (`float`, *optional*):
78
+ Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
79
+ most scaling types, a `factor` of x will enable the model to handle sequences of length x *
80
+ original maximum pre-trained length.
81
+ `original_max_position_embeddings` (`int`, *optional*):
82
+ Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during
83
+ pretraining.
84
+ `attention_factor` (`float`, *optional*):
85
+ Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
86
+ computation. If unspecified, it defaults to value recommended by the implementation, using the
87
+ `factor` field to infer the suggested value.
88
+ `beta_fast` (`float`, *optional*):
89
+ Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
90
+ ramp function. If unspecified, it defaults to 32.
91
+ `beta_slow` (`float`, *optional*):
92
+ Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
93
+ ramp function. If unspecified, it defaults to 1.
94
+ `short_factor` (`list[float]`, *optional*):
95
+ Only used with 'longrope'. The scaling factor to be applied to short contexts (<
96
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
97
+ size divided by the number of attention heads divided by 2
98
+ `long_factor` (`list[float]`, *optional*):
99
+ Only used with 'longrope'. The scaling factor to be applied to long contexts (<
100
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
101
+ size divided by the number of attention heads divided by 2
102
+ `low_freq_factor` (`float`, *optional*):
103
+ Only used with 'llama3'. Scaling factor applied to low frequency components of the RoPE
104
+ `high_freq_factor` (`float`, *optional*):
105
+ Only used with 'llama3'. Scaling factor applied to high frequency components of the RoPE
106
+ attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
107
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
108
+ use_sliding_window (`bool`, *optional*, defaults to `False`):
109
+ Whether to use sliding window attention.
110
+ sliding_window (`int`, *optional*, defaults to 4096):
111
+ Sliding window attention (SWA) window size. If not specified, will default to `4096`.
112
+ layer_types (`list`, *optional*):
113
+ Attention pattern for each layer.
114
+ attention_dropout (`float`, *optional*, defaults to 0.0):
115
+ The dropout ratio for the attention probabilities.
116
+
117
+ ```python
118
+ >>> from acestep.models import AceStepConfig
119
+
120
+ >>> # Initializing an AceStep configuration
121
+ >>> configuration = AceStepConfig()
122
+
123
+ >>> # Initializing a model from the configuration
124
+ >>> model = AceStepConditionGenerationModel(configuration)
125
+
126
+ >>> # Accessing the model configuration
127
+ >>> configuration = model.config
128
+ ```"""
129
+
130
+ model_type = "acestep"
131
+ keys_to_ignore_at_inference = ["past_key_values"]
132
+
133
+ # Default tensor parallel plan for the base model
134
+ base_model_tp_plan = {
135
+ "layers.*.self_attn.q_proj": "colwise",
136
+ "layers.*.self_attn.k_proj": "colwise",
137
+ "layers.*.self_attn.v_proj": "colwise",
138
+ "layers.*.self_attn.o_proj": "rowwise",
139
+ "layers.*.mlp.gate_proj": "colwise",
140
+ "layers.*.mlp.up_proj": "colwise",
141
+ "layers.*.mlp.down_proj": "rowwise",
142
+ }
143
+ base_model_pp_plan = {
144
+ "embed_tokens": (["input_ids"], ["inputs_embeds"]),
145
+ "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
146
+ "norm": (["hidden_states"], ["hidden_states"]),
147
+ }
148
+ def __init__(
149
+ self,
150
+ vocab_size=64003,
151
+ fsq_dim=2048,
152
+ fsq_input_levels=[8, 8, 8, 5, 5, 5],
153
+ fsq_input_num_quantizers=1,
154
+ hidden_size=2048,
155
+ intermediate_size=6144,
156
+ num_hidden_layers=24,
157
+ num_attention_heads=16,
158
+ num_key_value_heads=8,
159
+ head_dim=128,
160
+ hidden_act="silu",
161
+ max_position_embeddings=32768,
162
+ initializer_range=0.02,
163
+ rms_norm_eps=1e-6,
164
+ use_cache=True,
165
+ tie_word_embeddings=True,
166
+ rope_theta=1000000,
167
+ rope_scaling=None,
168
+ attention_bias=False,
169
+ use_sliding_window=True,
170
+ sliding_window=128,
171
+ layer_types=None,
172
+ attention_dropout=0.0,
173
+ num_lyric_encoder_hidden_layers=8,
174
+ audio_acoustic_hidden_dim=64,
175
+ pool_window_size=5,
176
+ text_hidden_dim=1024,
177
+ in_channels=192,
178
+ data_proportion=0.5,
179
+ timestep_mu=-0.4,
180
+ timestep_sigma=1.0,
181
+ timbre_hidden_dim=64,
182
+ num_timbre_encoder_hidden_layers=4,
183
+ timbre_fix_frame=750,
184
+ patch_size=2,
185
+ num_attention_pooler_hidden_layers=2,
186
+ num_audio_decoder_hidden_layers=24,
187
+ model_version="turbo",
188
+ **kwargs,
189
+ ):
190
+ self.max_position_embeddings = max_position_embeddings
191
+ self.hidden_size = hidden_size
192
+ self.intermediate_size = intermediate_size
193
+ self.num_hidden_layers = num_hidden_layers
194
+ self.num_attention_heads = num_attention_heads
195
+ self.use_sliding_window = use_sliding_window
196
+ self.sliding_window = sliding_window if self.use_sliding_window else None
197
+
198
+ # Text encoder configuration
199
+ self.text_hidden_dim = text_hidden_dim
200
+
201
+ # Lyric encoder configuration
202
+ self.num_lyric_encoder_hidden_layers = num_lyric_encoder_hidden_layers
203
+ self.patch_size = patch_size
204
+
205
+ # Audio semantic token generation configuration
206
+ self.audio_acoustic_hidden_dim = audio_acoustic_hidden_dim
207
+ self.pool_window_size = pool_window_size
208
+ self.in_channels = in_channels
209
+ self.data_proportion = data_proportion
210
+ self.timestep_mu = timestep_mu
211
+ self.timestep_sigma = timestep_sigma
212
+
213
+ # FSQ (Finite Scalar Quantization) configuration
214
+ self.fsq_dim = fsq_dim
215
+ self.fsq_input_levels = fsq_input_levels
216
+ self.fsq_input_num_quantizers = fsq_input_num_quantizers
217
+
218
+ # Timbre encoder configuration
219
+ self.timbre_hidden_dim = timbre_hidden_dim
220
+ self.num_timbre_encoder_hidden_layers = num_timbre_encoder_hidden_layers
221
+ self.timbre_fix_frame = timbre_fix_frame
222
+ self.num_attention_pooler_hidden_layers = num_attention_pooler_hidden_layers
223
+ self.num_audio_decoder_hidden_layers = num_audio_decoder_hidden_layers
224
+ self.vocab_size = vocab_size
225
+
226
+ # Backward compatibility: ensure num_key_value_heads is set
227
+ if num_key_value_heads is None:
228
+ num_key_value_heads = num_attention_heads
229
+
230
+ self.num_key_value_heads = num_key_value_heads
231
+ self.head_dim = head_dim
232
+ self.hidden_act = hidden_act
233
+ self.initializer_range = initializer_range
234
+ self.rms_norm_eps = rms_norm_eps
235
+ self.use_cache = use_cache
236
+ self.rope_theta = rope_theta
237
+ self.rope_scaling = rope_scaling
238
+ self.attention_bias = attention_bias
239
+ self.attention_dropout = attention_dropout
240
+ self.model_version = model_version
241
+
242
+ # Validate rotary position embeddings parameters
243
+ # Backward compatibility: if there is a 'type' field, move it to 'rope_type'
244
+ if self.rope_scaling is not None and "type" in self.rope_scaling:
245
+ self.rope_scaling["rope_type"] = self.rope_scaling["type"]
246
+ rope_config_validation(self)
247
+
248
+ self.layer_types = layer_types
249
+
250
+ # Set default layer types if not specified
251
+ if self.layer_types is None:
252
+ self.layer_types = [
253
+ "sliding_attention" if bool((i + 1) % 2) else "full_attention" for i in range(self.num_hidden_layers)
254
+ ]
255
+ layer_type_validation(self.layer_types)
256
+
257
+ super().__init__(
258
+ tie_word_embeddings=tie_word_embeddings,
259
+ **kwargs,
260
+ )
261
+
262
+
263
+ __all__ = ["AceStepConfig"]