#                🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
#           This file was automatically generated from src/transformers/models/vibevoice_asr/modular_vibevoice_asr.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_vibevoice_asr.py file directly. One of our CI enforces this.
#                🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
# Copyright 2026 Microsoft and 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 math

from huggingface_hub.dataclasses import strict

from ...configuration_utils import PreTrainedConfig, SubConfigSpec
from ...utils import auto_docstring
from ..auto import AutoConfig


@auto_docstring(checkpoint="microsoft/VibeVoice-ASR-HF")
@strict
class VibeVoiceAsrConfig(PreTrainedConfig):
    r"""
    acoustic_tokenizer_encoder_config (`Union[VibeVoiceAcousticTokenizerConfig, dict]`, *optional*):
        The config object or dictionary of the acoustic tokenizer. This tokenizer extracts acoustic features from audio.
    semantic_tokenizer_encoder_config (`Union[VibeVoiceAcousticTokenizerConfig, dict]`, *optional*):
        The config object or dictionary of the semantic tokenizer. This tokenizer extracts semantic features from audio.
    audio_bos_token_id (`int`, *optional*, defaults to 151646):
        The audio begin-of-sequence token index.
    audio_eos_token_id (`int`, *optional*, defaults to 151647):
        The audio end-of-sequence token index.
    acoustic_tokenizer_chunk_size (`int`, *optional*, defaults to 1440000):
        The chunk size (in number of samples) to use when tokenizer audio inputs. Default corresponds to 60 seconds at 24kHz.

    Example:

    ```python
    >>> from transformers import VibeVoiceAsrForConditionalGeneration, VibeVoiceAsrConfig, VibeVoiceAcousticTokenizerEncoderConfig, Qwen2Config

    >>> # Initializing VibeVoice acoustic and semantic encoder configs
    >>> acoustic_config = VibeVoiceAcousticTokenizerEncoderConfig()
    >>> semantic_config = VibeVoiceAcousticTokenizerEncoderConfig(hidden_size=128)

    >>> # Initializing a Qwen2 config
    >>> text_config = Qwen2Config()

    >>> # Initializing a VibeVoice ASR configuration
    >>> configuration = VibeVoiceAsrConfig(acoustic_config, semantic_config, text_config)

    >>> # Initializing a model from the vibevoice_asr style configuration
    >>> model = VibeVoiceAsrForConditionalGeneration(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```"""

    model_type = "vibevoice_asr"
    sub_configs_defaults = {
        "text_config": SubConfigSpec(config_class=AutoConfig, model_type="qwen2"),
        "semantic_tokenizer_encoder_config": SubConfigSpec(
            config_class=AutoConfig,
            model_type="vibevoice_acoustic_tokenizer_encoder",
            init_kwargs={"hidden_size": 128},
        ),
        "acoustic_tokenizer_encoder_config": SubConfigSpec(
            config_class=AutoConfig, model_type="vibevoice_acoustic_tokenizer_encoder"
        ),
    }

    acoustic_tokenizer_encoder_config: dict | PreTrainedConfig | None = None
    semantic_tokenizer_encoder_config: dict | PreTrainedConfig | None = None
    text_config: dict | PreTrainedConfig | None = None
    audio_token_id: int = 151648
    audio_bos_token_id: int = 151646
    audio_eos_token_id: int = 151647
    acoustic_tokenizer_chunk_size: int = 1440000

    def validate_architecture(self):
        """Part of `@strict`-powered validation. Validates the architecture of the config."""
        hop_length = self.acoustic_tokenizer_encoder_config.hop_length
        if self.acoustic_tokenizer_chunk_size % hop_length != 0:
            raise ValueError(
                f"`acoustic_tokenizer_chunk_size` must be a multiple of hop length "
                f"({hop_length}), got {self.acoustic_tokenizer_chunk_size}."
            )

    @property
    def max_position_embeddings(self) -> int:
        return math.ceil(self.acoustic_tokenizer_chunk_size / self.acoustic_tokenizer_encoder_config.hop_length)

    @max_position_embeddings.setter
    def max_position_embeddings(self, value: int):
        if value <= 0:
            raise ValueError(f"Attempted to set `max_position_embeddings` to {value}; you need a positive value!")

        hop_length = self.acoustic_tokenizer_encoder_config.hop_length
        self.acoustic_tokenizer_chunk_size = int(value) * hop_length


__all__ = ["VibeVoiceAsrConfig"]
