# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # This file was automatically generated from src/transformers/models/xcodec2/modular_xcodec2.py. # Do NOT edit this file manually as any edits will be overwritten by the generation of # the file from the modular. If any change should be done, please apply the change to the # modular_xcodec2.py file directly. One of our CI enforces this. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # Copyright 2026 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import numpy as np from huggingface_hub.dataclasses import strict from ...configuration_utils import PreTrainedConfig from ...modeling_rope_utils import RopeParameters from ...utils import auto_docstring from ...utils.type_validators import interval from ..auto import CONFIG_MAPPING, AutoConfig @auto_docstring(checkpoint="HKUSTAudio/xcodec2-hf") @strict class Xcodec2Config(PreTrainedConfig): r""" downsampling_ratios (`list[int]`, *optional*, defaults to `[2, 2, 4, 4, 5]`): Ratios for downsampling in the encoder. semantic_model_config (`Union[Dict, Wav2Vec2BertConfig]`, *optional*): An instance of the configuration object for the semantic (Wav2Vec2BertConfig) model. quantization_dim (`int`, *optional*, defaults to 2048): Dimension for the vector quantization codebook. quantization_levels (`list[int]`, *optional*, defaults to `[4, 4, 4, 4, 4, 4, 4, 4]`): Levels for the vector quantization codebook. Example: ```python >>> from transformers import Xcodec2Config, Xcodec2Model >>> # Initializing configuration >>> configuration = Xcodec2Config() >>> # Initializing a model (with random weights) from the configuration >>> model = Xcodec2Model(configuration) >>> # Accessing the model configuration >>> configuration = model.config ```""" model_type = "xcodec2" keys_to_ignore_at_inference = ["past_key_values"] hidden_size: int = 1024 intermediate_size: int = 4096 num_hidden_layers: int = 12 num_attention_heads: int = 16 num_key_value_heads: int = 16 hidden_act: str = "silu" max_position_embeddings: int = 4096 initializer_range: float = interval(min=0.0, max=1.0)(default=0.02) rms_norm_eps: float = 1e-6 pad_token_id: int | None = None tie_word_embeddings: bool = False rope_parameters: RopeParameters | dict | None = None attention_bias: bool = False attention_dropout: int | float | None = 0.0 head_dim: int = 64 sub_configs = {"semantic_model_config": AutoConfig} encoder_hidden_size: int = 48 downsampling_ratios: list[int] | tuple[int, ...] = (2, 2, 4, 4, 5) semantic_model_config: dict | PreTrainedConfig | None = None sampling_rate: int = 16000 activation_dropout: float = 0.1 quantization_dim: int = 2048 quantization_levels: list[int] | tuple[int, ...] = (4, 4, 4, 4, 4, 4, 4, 4) def __post_init__(self, **kwargs): if isinstance(self.semantic_model_config, dict): self.semantic_model_config["model_type"] = self.semantic_model_config.get("model_type", "wav2vec2-bert") self.semantic_model_config = CONFIG_MAPPING[self.semantic_model_config["model_type"]]( **self.semantic_model_config ) elif self.semantic_model_config is None: self.semantic_model_config = CONFIG_MAPPING["wav2vec2-bert"](num_hidden_layers=16) if self.head_dim is None: self.head_dim = self.hidden_size // self.num_attention_heads if self.num_key_value_heads is None: self.num_key_value_heads = self.num_attention_heads super().__post_init__(**kwargs) def validate_architecture(self): """Part of `@strict`-powered validation. Validates the architecture of the config.""" if self.hidden_size % self.num_attention_heads != 0: raise ValueError( f"The hidden size ({self.hidden_size}) is not a multiple of the number of attention " f"heads ({self.num_attention_heads})." ) @property def hop_length(self) -> int: return int(np.prod(self.downsampling_ratios)) @property def n_fft(self) -> int: return self.hop_length * 4 __all__ = ["Xcodec2Config"]