#                🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
#           This file was automatically generated from src/transformers/models/canary/modular_canary.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_canary.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/canary-1b-v2")
@strict
class CanaryDecoderConfig(PreTrainedConfig):
    r"""
    ```python
    >>> from transformers import CanaryDecoderModel, CanaryDecoderConfig

    >>> # Initializing a CanaryDecoder canary_decoder-7b style configuration
    >>> configuration = CanaryDecoderConfig()

    >>> # Initializing a model from the canary_decoder-7b style configuration
    >>> model = CanaryDecoderModel(configuration)

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

    model_type = "canary_decoder"
    keys_to_ignore_at_inference = ["past_key_values"]

    vocab_size: int = 16384
    hidden_size: int = 1024
    intermediate_size: int = 4096
    num_hidden_layers: int = 8
    num_attention_heads: int = 8
    num_key_value_heads: int = 8
    hidden_act: str = "relu"
    max_position_embeddings: int = 1024
    initializer_range: float = interval(min=0.0, max=1.0)(default=0.02)
    use_cache: bool = True
    pad_token_id: int | None = 2
    bos_token_id: int | None = 4
    eos_token_id: int | None = 3
    attention_bias: bool = True
    attention_dropout: int | float | None = 0.0
    head_dim: int = 128
    is_encoder_decoder: bool = True

    def __post_init__(self, **kwargs):
        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})."
            )


@auto_docstring(checkpoint="nvidia/canary-1b-v2")
@strict
class CanaryConfig(PreTrainedConfig):
    r"""
    encoder_config (`Union[dict, ParakeetEncoderConfig]`, *optional*):
        The config object or dictionary of the FastConformer encoder ([`ParakeetEncoderConfig`]).
    decoder_config (`Union[dict, CanaryDecoderConfig]`, *optional*):
        The config object or dictionary of the Transformer decoder ([`CanaryDecoderConfig`]).
    decoder_start_token_id (`int`, *optional*, defaults to 7):
        The token id that starts decoding (`<|startofcontext|>`, the first token of the multitask prompt).

    Example:

    ```python
    >>> from transformers import CanaryForConditionalGeneration, CanaryConfig

    >>> # Initializing a Canary configuration
    >>> configuration = CanaryConfig()

    >>> # Initializing a model from the configuration
    >>> model = CanaryForConditionalGeneration(configuration)

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

    model_type = "canary"
    keys_to_ignore_at_inference = ["past_key_values"]
    sub_configs_defaults = {
        "encoder_config": SubConfigSpec(
            config_class=AutoConfig,
            model_type="parakeet_encoder",
            init_kwargs={
                "num_hidden_layers": 32,
                "num_mel_bins": 128,
                "scale_input": False,
                "layerdrop": 0.0,
            },
        ),
        "decoder_config": SubConfigSpec(config_class=CanaryDecoderConfig),
    }

    encoder_config: dict | PreTrainedConfig | None = None
    decoder_config: dict | PreTrainedConfig | None = None
    use_cache: bool = True
    is_encoder_decoder: bool = True
    tie_word_embeddings: bool = True
    pad_token_id: int | None = 2
    bos_token_id: int | None = 4
    eos_token_id: int | None = 3
    decoder_start_token_id: int | None = 7
    initializer_range: float = 0.02
    vocab_size: int = 16384

    def validate_architecture(self):
        if self.decoder_config.vocab_size != self.vocab_size:
            raise ValueError(
                f"The decoder config vocabulary size ({self.decoder_config.vocab_size}) does not match the Canary "
                f"config vocabulary size ({self.vocab_size})."
            )

    def get_text_config(self, *args, **kwargs):
        return self.decoder_config


__all__ = ["CanaryConfig", "CanaryDecoderConfig"]
