#                🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
#           This file was automatically generated from src/transformers/models/nemotron3_5_transcribe/modular_nemotron3_5_transcribe.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_nemotron3_5_transcribe.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.

from huggingface_hub.dataclasses import strict

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


@auto_docstring(checkpoint="nvidia/NVIDIA-Nemotron-3.5-Transcribe-30B-A4B")
@strict
class Nemotron3_5TranscribeAsrAudioConfig(PreTrainedConfig):
    r"""
    subsampling_factor (`int`, *optional*, defaults to 8):
        Number of consecutive spectrogram frames stacked into one encoder frame.

    Example:

    ```python
    >>> from transformers import Nemotron3_5TranscribeAsrAudioModel, Nemotron3_5TranscribeAsrAudioConfig

    >>> # Initializing a Nemotron3_5TranscribeAsrAudioModel configuration
    >>> configuration = Nemotron3_5TranscribeAsrAudioConfig()

    >>> # Initializing a model (with random weights) from the configuration
    >>> model = Nemotron3_5TranscribeAsrAudioModel(configuration)

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

    model_type = "nemotron3_5_transcribe_asr_audio"

    hidden_size: int = 1280
    intermediate_size: int = 5120
    num_hidden_layers: int = 32
    num_attention_heads: int = 10
    num_key_value_heads: int | None = None
    hidden_act: str = "gelu"
    max_position_embeddings: int = 5000
    initializer_range: float = 0.02
    rope_parameters: dict | None = None
    attention_dropout: float | int = 0.0
    num_mel_bins: int = 128
    base_config_key = "asr_config"
    subsampling_factor: int = 8

    def __post_init__(self, **kwargs):
        if self.rope_parameters is None:
            self.rope_parameters = {"rope_type": "default", "rope_theta": 10000.0, "partial_rotary_factor": 0.5}
        kwargs.setdefault("partial_rotary_factor", 1.0)
        if self.num_key_value_heads is None:
            self.num_key_value_heads = self.num_attention_heads

        kwargs.setdefault("partial_rotary_factor", 0.5)
        super().__post_init__(**kwargs)

    def validate_architecture(self):
        if self.hidden_size % self.num_attention_heads != 0:
            raise ValueError(
                f"`hidden_size` ({self.hidden_size}) must be divisible by `num_attention_heads` "
                f"({self.num_attention_heads})."
            )


@auto_docstring(checkpoint="nvidia/NVIDIA-Nemotron-3.5-Transcribe-30B-A4B")
@strict
class Nemotron3_5TranscribeWordTimestampConfig(PreTrainedConfig):
    r"""
    vocab_size (`int`, *optional*, defaults to 23863):
        Number of classes of the word timestamp head: the pieces of its alignment tokenizer, then the blank.
    blank_token_id (`int`, *optional*, defaults to 23862):
        Index of the blank class, after the pieces of the alignment tokenizer.
    residual_scale (`float`, *optional*, defaults to 0.1):
        Scale of the transformer output added to the speech recognition encoder states before the classifier.
    upsampling_factor (`int`, *optional*, defaults to 2):
        Number of head frames per encoder frame, made by a transposed convolution before the transformer: 2 gives
        40 ms frames from the 80 ms encoder frames.

    Example:

    ```python
    >>> from transformers import Nemotron3_5TranscribeConfig, Nemotron3_5TranscribeWordTimestampConfig

    >>> # Initializing a Nemotron3_5TranscribeWordTimestamp configuration
    >>> configuration = Nemotron3_5TranscribeWordTimestampConfig()

    >>> # Using it as the word timestamp head of the model
    >>> model_configuration = Nemotron3_5TranscribeConfig(word_timestamp_config=configuration)
    ```
    """

    model_type = "nemotron3_5_transcribe_word_timestamp"
    base_config_key = "word_timestamp_config"

    hidden_size: int = 1280
    intermediate_size: int = 640
    num_hidden_layers: int = 2
    num_attention_heads: int = 16
    num_key_value_heads: int | None = None
    hidden_act: str = "gelu"
    max_position_embeddings: int = 5000
    initializer_range: float = 0.02
    rope_parameters: dict | None = None
    attention_dropout: float | int = 0.0
    vocab_size: int = 23863
    blank_token_id: int = 23862
    residual_scale: float = interval(min=0.0)(default=0.1)
    upsampling_factor: int = interval(min=1)(default=2)

    def __post_init__(self, **kwargs):
        if self.num_key_value_heads is None:
            self.num_key_value_heads = self.num_attention_heads
        if self.rope_parameters is None:
            self.rope_parameters = {"rope_type": "default", "rope_theta": 10000.0, "partial_rotary_factor": 0.5}
        super().__post_init__(**kwargs)

    def validate_architecture(self):
        if self.hidden_size % self.num_attention_heads != 0:
            raise ValueError(
                f"`hidden_size` ({self.hidden_size}) must be divisible by `num_attention_heads` "
                f"({self.num_attention_heads})."
            )
        if not 0 <= self.blank_token_id < self.vocab_size:
            raise ValueError(
                f"`blank_token_id` ({self.blank_token_id}) must be a class below `vocab_size` ({self.vocab_size})."
            )


@auto_docstring(checkpoint="nvidia/NVIDIA-Nemotron-3.5-Transcribe-30B-A4B")
@strict
class Nemotron3_5TranscribeAudioConfig(PreTrainedConfig):
    r"""
    asr_config (`Union[dict, Nemotron3_5TranscribeAsrAudioConfig]`, *optional*):
        Configuration of the speech recognition encoder.
    diarization_config (`Union[dict, Nemotron3DiarizationConfig]`, *optional*):
        Configuration of the speaker diarization model, whose speaker activities are added to the speech recognition
        encoder outputs.
    speaker_activity_threshold (`float`, *optional*, defaults to 0.5):
        A speaker is active in an encoder frame when its probability is above this threshold.

    Example:

    ```python
    >>> from transformers import Nemotron3_5TranscribeAudioModel, Nemotron3_5TranscribeAudioConfig

    >>> # Initializing a Nemotron3_5TranscribeAudioModel configuration
    >>> configuration = Nemotron3_5TranscribeAudioConfig()

    >>> # Initializing a model (with random weights) from the configuration
    >>> model = Nemotron3_5TranscribeAudioModel(configuration)

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

    model_type = "nemotron3_5_transcribe_audio"
    base_config_key = "audio_config"
    sub_configs_defaults = {
        "asr_config": Nemotron3_5TranscribeAsrAudioConfig,
        "diarization_config": SubConfigSpec(
            config_class=AutoConfig,
            model_type="nemotron3_diarization",
            init_kwargs={
                "chunk_length": 500,
                "chunk_left_context": 50,
                "chunk_right_context": 50,
                "fifo_length": 40,
                "speaker_cache_update_period": 300,
                "streaming_config": {"speaker_cache_length": 188},
            },
        ),
    }

    asr_config: dict | PreTrainedConfig | None = None
    diarization_config: dict | PreTrainedConfig | None = None
    speaker_activity_threshold: float = interval(min=0.0, max=1.0)(default=0.5)

    @property
    def hidden_size(self) -> int:
        return self.asr_config.hidden_size

    @property
    def num_speakers(self) -> int:
        return self.diarization_config.head_config.num_speakers

    @property
    def subsampling_factor(self) -> int:
        return self.asr_config.subsampling_factor

    def validate_architecture(self):
        if self.asr_config.subsampling_factor != self.diarization_config.audio_config.subsampling_factor:
            raise ValueError(
                f"The speech recognition encoder (`subsampling_factor={self.asr_config.subsampling_factor}`) and the "
                "diarization model (`subsampling_factor="
                f"{self.diarization_config.audio_config.subsampling_factor}`) must have the same frame rate."
            )


@auto_docstring(checkpoint="nvidia/NVIDIA-Nemotron-3.5-Transcribe-30B-A4B")
@strict
class Nemotron3_5TranscribeConfig(PreTrainedConfig):
    r"""
    audio_token_id (`int`, *optional*, defaults to 131072):
        The audio token index used as a placeholder for the audio embeddings. The original checkpoint appends it after
        the language model's vocabulary, with no embedding row: it is embedded as token 0, then replaced by the audio.
    word_timestamp_config (`Union[dict, Nemotron3_5TranscribeWordTimestampConfig]`, *optional*):
        Configuration of the word timestamp encoder and head, which predict alignment tokenizer pieces from the speech
        recognition encoder states.

    Example:

    ```python
    >>> from transformers import Nemotron3_5TranscribeForConditionalGeneration, Nemotron3_5TranscribeConfig

    >>> # Initializing a Nemotron3_5Transcribe configuration
    >>> configuration = Nemotron3_5TranscribeConfig()

    >>> # Initializing a model (with random weights) from the configuration
    >>> model = Nemotron3_5TranscribeForConditionalGeneration(configuration)

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

    model_type = "nemo_speechlm"
    sub_configs_defaults = {
        "audio_config": Nemotron3_5TranscribeAudioConfig,
        "text_config": SubConfigSpec(
            config_class=AutoConfig,
            model_type="nemotron_h",
            init_kwargs={
                "hidden_size": 2688,
                "intermediate_size": 1856,
                "hybrid_override_pattern": "MEMEM*EMEMEM*EMEMEM*EMEMEM*EMEMEM*EMEMEMEM*EMEMEMEME",
                "mamba_num_heads": 64,
                "max_position_embeddings": 262144,
                "moe_intermediate_size": 1856,
                "moe_shared_expert_intermediate_size": 3712,
                "n_routed_experts": 128,
                "num_experts_per_tok": 6,
                "num_key_value_heads": 2,
                "routed_scaling_factor": 2.5,
            },
        ),
        "word_timestamp_config": Nemotron3_5TranscribeWordTimestampConfig,
    }

    audio_config: dict | PreTrainedConfig | None = None
    text_config: dict | PreTrainedConfig | None = None
    audio_token_id: int = 131072
    word_timestamp_config: dict | PreTrainedConfig | None = None


__all__ = [
    "Nemotron3_5TranscribeAsrAudioConfig",
    "Nemotron3_5TranscribeAudioConfig",
    "Nemotron3_5TranscribeConfig",
    "Nemotron3_5TranscribeWordTimestampConfig",
]
