Prompt48 commited on
Commit
f5b2a58
·
verified ·
1 Parent(s): 91b39fb

Upload edit\Qwen3-TTS-test\qwen_tts\core\tokenizer_25hz\configuration_qwen3_tts_tokenizer_v1.py with huggingface_hub

Browse files
edit//Qwen3-TTS-test//qwen_tts//core//tokenizer_25hz//configuration_qwen3_tts_tokenizer_v1.py ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2026 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
+ """Qwen3TTSTokenizerV1 model configuration"""
16
+
17
+ from transformers.configuration_utils import PretrainedConfig
18
+ from transformers.utils import logging
19
+
20
+
21
+ logger = logging.get_logger(__name__)
22
+
23
+
24
+ class Qwen3TTSTokenizerV1DecoderDiTConfig(PretrainedConfig):
25
+ r"""
26
+ This is the configuration class to store the configuration of the Qwen3TTSTokenizerV1DecoderToken2WavDiT.
27
+ It defines the architecture of the DiT model, which is used for generating mel-spectrograms from tokens.
28
+
29
+ Args:
30
+ hidden_size (`int`, *optional*, defaults to 1024):
31
+ The dimension of the model.
32
+ num_hidden_layers (`int`, *optional*, defaults to 22):
33
+ The number of transformer blocks in the DiT model.
34
+ num_attention_heads (`int`, *optional*, defaults to 16):
35
+ The number of attention heads in each transformer block.
36
+ ff_mult (`int`, *optional*, defaults to 2):
37
+ The multiplier for the feedforward layer in each transformer block.
38
+ emb_dim (`int`, *optional*, defaults to 512):
39
+ The dimension of the embedding layer.
40
+ head_dim (`int`, *optional*, defaults to 64):
41
+ The dimension of each attention head.
42
+ repeats (`int`, *optional*, defaults to 2):
43
+ The number of times the codec embeddings are repeated.
44
+ num_embeds (`int`, *optional*, defaults to 8193):
45
+ The number of unique embeddings in the codec.
46
+ mel_dim (`int`, *optional*, defaults to 80):
47
+ The dimension of the mel-spectrogram.
48
+ dropout (`float`, *optional*, defaults to 0.1):
49
+ The dropout rate for the transformer blocks.
50
+
51
+ enc_emb_dim (`int`, *optional*, defaults to 192):
52
+ The dimension of the pre-trained speaker embedding.
53
+ enc_dim (`int`, *optional*, defaults to 128):
54
+ The dimension of the encoder output.
55
+ enc_channels (`list[int]`, *optional*, defaults to `[256, 256, 256, 256, 768]`):
56
+ A list of output channels for each TDNN/SERes2Net layer in the encoder.
57
+ enc_kernel_sizes (`list[int]`, *optional*, defaults to `[5, 3, 3, 3, 1]`):
58
+ A list of kernel sizes for each layer in the encoder.
59
+ enc_dilations (`list[int]`, *optional*, defaults to `[1, 2, 3, 4, 1]`):
60
+ A list of dilations for each layer in the encoder.
61
+ enc_attention_channels (`int`, *optional*, defaults to 64):
62
+ The number of attention channels in the SqueezeExcitationBlock.
63
+ enc_res2net_scale (`int`, *optional*, defaults to 2):
64
+ The scale of the Res2Net block in the encoder.
65
+ enc_se_channels (`int`, *optional*, defaults to 64):
66
+ The number of output channels after squeeze in the SqueezeExcitationBlock.
67
+ """
68
+
69
+ model_type = "qwen3_tts_tokenizer_v1_decoder_dit"
70
+
71
+ def __init__(
72
+ self,
73
+ hidden_size=1024,
74
+ num_hidden_layers=22,
75
+ num_attention_heads=16,
76
+ ff_mult=2,
77
+ emb_dim=512,
78
+ head_dim=64,
79
+ rope_theta=10000.0,
80
+ max_position_embeddings=32768,
81
+ block_size=24,
82
+ look_ahead_layers=[10],
83
+ look_backward_layers=[0, 20],
84
+ repeats=2,
85
+ num_embeds=8193,
86
+ mel_dim=80,
87
+ dropout=0.1,
88
+ enc_emb_dim=192,
89
+ enc_dim=128,
90
+ enc_channels=[256, 256, 256, 256, 768],
91
+ enc_kernel_sizes=[5, 3, 3, 3, 1],
92
+ enc_dilations=[1, 2, 3, 4, 1],
93
+ enc_attention_channels=64,
94
+ enc_res2net_scale=2,
95
+ enc_se_channels=64,
96
+ **kwargs,
97
+ ):
98
+ self.hidden_size = hidden_size
99
+ self.num_hidden_layers = num_hidden_layers
100
+ self.num_attention_heads = num_attention_heads
101
+ self.ff_mult = ff_mult
102
+ self.emb_dim = emb_dim
103
+ self.head_dim = head_dim
104
+ self.rope_theta = rope_theta
105
+ self.max_position_embeddings = max_position_embeddings
106
+ self.block_size = block_size
107
+ self.look_ahead_layers = look_ahead_layers
108
+ self.look_backward_layers = look_backward_layers
109
+ self.repeats = repeats
110
+ self.num_embeds = num_embeds
111
+ self.mel_dim = mel_dim
112
+ self.dropout = dropout
113
+ self.enc_emb_dim = enc_emb_dim
114
+ self.enc_dim = enc_dim
115
+ self.enc_channels = enc_channels
116
+ self.enc_kernel_sizes = enc_kernel_sizes
117
+ self.enc_dilations = enc_dilations
118
+ self.enc_attention_channels = enc_attention_channels
119
+ self.enc_res2net_scale = enc_res2net_scale
120
+ self.enc_se_channels = enc_se_channels
121
+ super().__init__(**kwargs)
122
+
123
+
124
+ class Qwen3TTSTokenizerV1DecoderBigVGANConfig(PretrainedConfig):
125
+ r"""
126
+ This is the configuration class to store the configuration of the Qwen3TTSTokenizerV1DecoderToken2WavBigVGAN module.
127
+ It defines the architecture of the BigVGAN model, which is used for converting mel-spectrograms to waveforms.
128
+
129
+ Args:
130
+ mel_dim (`int`, *optional*, defaults to 80):
131
+ The dimension of the mel-spectrogram.
132
+ upsample_initial_channel (`int`, *optional*, defaults to 1536):
133
+ The number of channels in the initial upsampling layer.
134
+ resblock_kernel_sizes (`list[int]`, *optional*, defaults to `[3, 7, 11]`):
135
+ A list of kernel sizes for each residual block.
136
+ resblock_dilation_sizes (`list[list[int]]`, *optional*, defaults to `[[1, 3, 5], [1, 3, 5], [1, 3, 5]]`):
137
+ A list of dilation sizes for each residual block.
138
+ upsample_rates (`list[int]`, *optional*, defaults to `[5, 3, 2, 2, 2, 2]`):
139
+ A list of upsampling rates for each upsampling layer.
140
+ upsample_kernel_sizes (`list[int]`, *optional*, defaults to `[11, 7, 4, 4, 4, 4]`):
141
+ A list of kernel sizes for each upsampling layer.
142
+ """
143
+
144
+ model_type = "qwen3_tts_tokenizer_v1_decoder_bigvgan"
145
+
146
+ def __init__(
147
+ self,
148
+ mel_dim=80,
149
+ upsample_initial_channel=1536,
150
+ resblock_kernel_sizes=[3, 7, 11],
151
+ resblock_dilation_sizes=[[1, 3, 5], [1, 3, 5], [1, 3, 5]],
152
+ upsample_rates=[5, 3, 2, 2, 2, 2],
153
+ upsample_kernel_sizes=[11, 7, 4, 4, 4, 4],
154
+ **kwargs,
155
+ ):
156
+ self.mel_dim = mel_dim
157
+ self.upsample_initial_channel = upsample_initial_channel
158
+ self.resblock_kernel_sizes = resblock_kernel_sizes
159
+ self.resblock_dilation_sizes = resblock_dilation_sizes
160
+ self.upsample_rates = upsample_rates
161
+ self.upsample_kernel_sizes = upsample_kernel_sizes
162
+ super().__init__(**kwargs)
163
+
164
+
165
+ class Qwen3TTSTokenizerV1DecoderConfig(PretrainedConfig):
166
+ r"""
167
+ This is the configuration class to store the configuration of a [`Qwen3TTSTokenizerV1DecoderConfig`].
168
+
169
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
170
+ documentation from [`PretrainedConfig`] for more information.
171
+
172
+ Args:
173
+ dit_config ([`DiT_Args`], *optional*):
174
+ Configuration class for the Diffusion Transformer (DiT) module responsible for generating mel-spectrograms.
175
+ bigvgan_config ([`BigVGAN_Args`], *optional*):
176
+ Configuration class for the BigVGAN module responsible for converting mel-spectrograms to waveforms.
177
+ """
178
+
179
+ model_type = "qwen3_tts_tokenizer_v1_decoder"
180
+ sub_configs = {
181
+ "dit_config": Qwen3TTSTokenizerV1DecoderDiTConfig,
182
+ "bigvgan_config": Qwen3TTSTokenizerV1DecoderBigVGANConfig,
183
+ }
184
+
185
+ def __init__(self, dit_config=None, bigvgan_config=None, **kwargs):
186
+ if dit_config is None:
187
+ dit_config = {}
188
+ if bigvgan_config is None:
189
+ bigvgan_config = {}
190
+ self.dit_config = Qwen3TTSTokenizerV1DecoderDiTConfig(**dit_config)
191
+ self.bigvgan_config = Qwen3TTSTokenizerV1DecoderBigVGANConfig(**bigvgan_config)
192
+ super().__init__(**kwargs)
193
+
194
+
195
+ class Qwen3TTSTokenizerV1EncoderConfig(PretrainedConfig):
196
+ r"""
197
+ This is the configuration class to store the configuration of the Qwen3TTSTokenizerV1 Encoder.
198
+
199
+ The encoder typically takes mel-spectrogram features and produces high-level audio representations, then (optionally)
200
+ applies an Audio-VQ module (e.g., GRVQ) to discretize continuous representations into codes.
201
+
202
+ Args:
203
+ n_mels (`int`, *optional*, defaults to 128):
204
+ Number of mel bins in the input mel-spectrogram.
205
+ n_ctx (`int`, *optional*, defaults to 1500):
206
+ Maximum input sequence length (in frames/tokens) for the encoder.
207
+ n_state (`int`, *optional*, defaults to 1280):
208
+ Hidden size (model dimension) of the encoder transformer.
209
+ n_head (`int`, *optional*, defaults to 20):
210
+ Number of attention heads in each transformer layer.
211
+ n_layer (`int`, *optional*, defaults to 32):
212
+ Number of transformer layers.
213
+ n_window (`int`, *optional*, defaults to 100):
214
+ Window size used by the model for local attention / chunking (implementation-dependent).
215
+ output_dim (`int`, *optional*, defaults to 3584):
216
+ Output feature dimension produced by the encoder head (before/after projection, implementation-dependent).
217
+
218
+ grad_checkpointing (`bool`, *optional*, defaults to `False`):
219
+ Whether to enable gradient checkpointing to reduce memory usage during training.
220
+ enable_mp (`bool`, *optional*, defaults to `False`):
221
+ Whether to enable model parallel features (implementation-dependent).
222
+ audio_sequence_parallel (`bool`, *optional*, defaults to `False`):
223
+ Whether to enable sequence parallelism for audio branch (implementation-dependent).
224
+
225
+ audio_vq_type (`str`, *optional*, defaults to `"GRVQ"`):
226
+ Type of audio vector-quantization module. Common choices: `"GRVQ"`, `"RVQ"`, etc.
227
+ audio_vq_layers (`int`, *optional*, defaults to 6):
228
+ Number of VQ layers / quantizers (e.g., number of residual quantizers for RVQ/GRVQ-like designs).
229
+ audio_vq_codebook_size (`int`, *optional*, defaults to 32768):
230
+ Size of each codebook (number of entries).
231
+ audio_vq_codebook_dim (`int`, *optional*, defaults to 1280):
232
+ Dimension of codebook vectors (often equals encoder hidden size).
233
+ audio_vq_pe (`bool`, *optional*, defaults to `True`):
234
+ Whether to use positional encoding (or position embeddings) inside the VQ module.
235
+ audio_vq_ds_rate (`int`, *optional*, defaults to 2):
236
+ Downsampling rate applied before VQ (e.g., temporal downsample factor).
237
+ """
238
+
239
+ model_type = "qwen3_tts_tokenizer_v1_encoder"
240
+
241
+ def __init__(
242
+ self,
243
+ n_mels=128,
244
+ n_ctx=1500,
245
+ n_state=1280,
246
+ n_head=20,
247
+ n_layer=32,
248
+ n_window=100,
249
+ output_dim=3584,
250
+ grad_checkpointing=False,
251
+ enable_mp=False,
252
+ audio_sequence_parallel=False,
253
+ audio_vq_type="GRVQ",
254
+ audio_vq_layers=6,
255
+ audio_vq_codebook_size=32768,
256
+ audio_vq_codebook_dim=1280,
257
+ audio_vq_pe=True,
258
+ audio_vq_ds_rate=2,
259
+ **kwargs,
260
+ ):
261
+ super().__init__(**kwargs)
262
+ self.n_mels = n_mels
263
+ self.n_ctx = n_ctx
264
+ self.n_state = n_state
265
+ self.n_head = n_head
266
+ self.n_layer = n_layer
267
+ self.n_window = n_window
268
+ self.output_dim = output_dim
269
+ self.grad_checkpointing = grad_checkpointing
270
+ self.enable_mp = enable_mp
271
+ self.audio_sequence_parallel = audio_sequence_parallel
272
+ self.audio_vq_type = audio_vq_type
273
+ self.audio_vq_layers = audio_vq_layers
274
+ self.audio_vq_codebook_size = audio_vq_codebook_size
275
+ self.audio_vq_codebook_dim = audio_vq_codebook_dim
276
+ self.audio_vq_pe = audio_vq_pe
277
+ self.audio_vq_ds_rate = audio_vq_ds_rate
278
+
279
+
280
+ class Qwen3TTSTokenizerV1Config(PretrainedConfig):
281
+ """
282
+ This is the configuration class to store the configuration of a [`Qwen3TTSTokenizerV1Config`]. It is used to instantiate a Qwen3TTSTokenizerV1Model
283
+ model according to the specified sub-models configurations, defining the model architecture.
284
+
285
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
286
+ documentation from [`PretrainedConfig`] for more information.
287
+
288
+ Args:
289
+ encoder_config (`dict`, *optional*): Configuration of the underlying encoder sub-model.
290
+ decoder_config (`dict`, *optional*): Configuration of the underlying decoder sub-model.
291
+ """
292
+
293
+ model_type = "qwen3_tts_tokenizer_25hz"
294
+ sub_configs = {
295
+ "encoder_config": Qwen3TTSTokenizerV1EncoderConfig,
296
+ "decoder_config": Qwen3TTSTokenizerV1DecoderConfig,
297
+ }
298
+
299
+ def __init__(
300
+ self,
301
+ encoder_config=None,
302
+ decoder_config=None,
303
+ input_sample_rate=24000,
304
+ output_sample_rate=24000,
305
+ decode_upsample_rate=1920,
306
+ encode_downsample_rate=1920,
307
+ **kwargs,
308
+ ):
309
+ super().__init__(**kwargs)
310
+ if encoder_config is None:
311
+ encoder_config = {}
312
+ logger.info("encoder_config is None. Initializing encoder with default values")
313
+ if decoder_config is None:
314
+ decoder_config = {}
315
+ logger.info("decoder_config is None. Initializing decoder with default values")
316
+
317
+ self.encoder_config = Qwen3TTSTokenizerV1EncoderConfig(**encoder_config)
318
+ self.decoder_config = Qwen3TTSTokenizerV1DecoderConfig(**decoder_config)
319
+
320
+ self.input_sample_rate = input_sample_rate
321
+ self.output_sample_rate = output_sample_rate
322
+ self.decode_upsample_rate = decode_upsample_rate
323
+ self.encode_downsample_rate = encode_downsample_rate
324
+
325
+
326
+ __all__ = [
327
+ "Qwen3TTSTokenizerV1Config",
328
+ "Qwen3TTSTokenizerV1EncoderConfig",
329
+ "Qwen3TTSTokenizerV1DecoderConfig",
330
+ "Qwen3TTSTokenizerV1DecoderBigVGANConfig",
331
+ "Qwen3TTSTokenizerV1DecoderDiTConfig"
332
+ ]