#                🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
#           This file was automatically generated from src/transformers/models/florence2/modular_florence2.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_florence2.py file directly. One of our CI enforces this.
#                🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
# Copyright 2025 Microsoft and the HuggingFace 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
from ...utils import auto_docstring, logging
from ..auto import CONFIG_MAPPING, AutoConfig


logger = logging.get_logger(__name__)


@auto_docstring(checkpoint="florence-community/Florence-2-base")
@strict
class Florence2VisionConfig(PreTrainedConfig):
    r"""
    depths (`Tuple[int]`, *optional*, defaults to `(1, 1, 9, 1)`):
        The depth of the model.
    patch_stride (`Tuple[int]`, *optional*, defaults to `(4, 2, 2, 2)`):
        The patch stride of the image.
    patch_padding (`Tuple[int]`, *optional*, defaults to `(3, 1, 1, 1)`):
        The patch padding of the image.
    patch_prenorm (`Tuple[bool]`, *optional*, defaults to `(False, True, True, True)`):
        Whether to apply layer normalization before the patch embedding layer.
    num_groups (`Tuple[int]`, *optional*, defaults to `(4, 8, 16, 32)`):
        The number of groups.
    window_size (`int`, *optional*, defaults to 12):
        The window size of the model.
    max_temporal_embeddings (`int`, *optional*, defaults to 100):
        The configuration of the visual temporal embedding.

    Example:

    ```python
    >>> from transformers import Florence2VisionConfig, Florence2VisionModel

    >>> # Initializing a Florence2 Vision style configuration
    >>> configuration = Florence2VisionConfig()

    >>> # Initializing a model (with random weights)
    >>> model = Florence2VisionModel(configuration)

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

    model_type = "florence_vision"

    in_channels: int = 3
    depths: list[int] | tuple[int, ...] = (1, 1, 9, 1)
    patch_size: list[int] | tuple[int, ...] = (7, 3, 3, 3)
    patch_stride: list[int] | tuple[int, ...] = (4, 2, 2, 2)
    patch_padding: list[int] | tuple[int, ...] = (3, 1, 1, 1)
    patch_prenorm: list[bool] | tuple[bool, ...] = (False, True, True, True)
    embed_dim: list[int] | tuple[int, ...] = (128, 256, 512, 1024)
    num_heads: list[int] | tuple[int, ...] = (4, 8, 16, 32)
    num_groups: list[int] | tuple[int, ...] = (4, 8, 16, 32)
    window_size: int = 12
    drop_path_rate: float = 0.1
    mlp_ratio: float = 4.0
    qkv_bias: bool = True
    activation_function: str = "gelu"
    projection_dim: int = 1024
    max_temporal_embeddings: int = 100
    max_position_embeddings: int = 50
    initializer_range: float = 0.02


@auto_docstring(checkpoint="florence-community/Florence-2-base")
@strict
class Florence2Config(PreTrainedConfig):
    r"""
    Example:

    ```python
    >>> from transformers import Florence2ForConditionalGeneration, Florence2Config, CLIPVisionConfig, BartConfig

    >>> # Initializing a clip-like vision config
    >>> vision_config = CLIPVisionConfig()

    >>> # Initializing a Bart config
    >>> text_config = BartConfig()

    >>> # Initializing a Florence-2 configuration
    >>> configuration = Florence2Config(vision_config, text_config)

    >>> # Initializing a model from the florence-2 configuration
    >>> model = Florence2ForConditionalGeneration(configuration)

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

    model_type = "florence2"
    sub_configs = {
        "text_config": AutoConfig,
        "vision_config": Florence2VisionConfig,
    }

    text_config: dict | PreTrainedConfig | None = None
    vision_config: dict | PreTrainedConfig | None = None
    image_token_id: int = 51289
    is_encoder_decoder: bool = True
    tie_word_embeddings: bool = True

    def __post_init__(self, **kwargs):
        if isinstance(self.text_config, dict):
            self.text_config["model_type"] = self.text_config.get("model_type", "bart")
            self.text_config = CONFIG_MAPPING[self.text_config["model_type"]](**self.text_config)
        elif self.text_config is None:
            self.text_config = CONFIG_MAPPING["bart"]()

        if isinstance(self.vision_config, dict):
            self.vision_config = Florence2VisionConfig(**self.vision_config)
        elif self.vision_config is None:
            logger.info("vision_config is None. Initializing the Florence2VisionConfig with default values.")
            self.vision_config = Florence2VisionConfig()

        super().__post_init__(**kwargs)


__all__ = ["Florence2Config", "Florence2VisionConfig"]
