#                🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
#           This file was automatically generated from src/transformers/models/minicpmv4_7/modular_minicpmv4_7.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_minicpmv4_7.py file directly. One of our CI enforces this.
#                🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
# Copyright 2026 OpenBMB 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.


from huggingface_hub.dataclasses import strict

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


@auto_docstring(checkpoint="openbmb/MiniCPM-V-4.7-1B")
@strict
class MiniCPMV4_7VisionConfig(PreTrainedConfig):
    r"""
    insert_layer_id (`int`, *optional*, defaults to 6):
        Vision encoder layer index after which the window-attention merger is applied.
    window_kernel_size (`tuple[int, int]`, *optional*, defaults to `(2, 2)`):
        Window size `(h, w)` for the intermediate window-attention merger.
    """

    model_type = "minicpmv4_7_vision"
    base_config_key = "vision_config"

    hidden_size: int = 768
    intermediate_size: int = 3072
    num_hidden_layers: int = 12
    num_attention_heads: int = 12
    num_channels: int = 3
    image_size: int | list[int] | tuple[int, int] = 224
    patch_size: int | list[int] | tuple[int, int] = 16
    hidden_act: str = "gelu_pytorch_tanh"
    layer_norm_eps: float = 1e-6
    attention_dropout: float | int = 0.0
    insert_layer_id: int = 6
    window_kernel_size: tuple[int, int] | list[int] = (2, 2)

    @property
    def window_hidden_size(self) -> int:
        return self.hidden_size * self.window_kernel_size[0] * self.window_kernel_size[1]

    @property
    def window_intermediate_size(self) -> int:
        return self.intermediate_size * self.window_kernel_size[0] * self.window_kernel_size[1]


@auto_docstring(checkpoint="openbmb/MiniCPM-V-4.7-1B")
@strict
class MiniCPMV4_7Config(PreTrainedConfig):
    r"""
    insert_layer_id (`int`, *optional*, defaults to 6):
        Vision encoder layer index after which the window-attention merger is applied.
    downsample_mode (`str`, *optional*, defaults to `"16x"`):
        Visual token downsampling ratio. `"4x"` keeps 4× more tokens.
    merge_kernel_size (`tuple[int, int]`, *optional*, defaults to `(2, 2)`):
        Kernel size `(h, w)` for merging adjacent visual patches in the Merger.
    merger_times (`int`, *optional*, defaults to 1):
        Number of iterative merge rounds in the Merger.
    image_start_id (`int`, *optional*):
        Token id of the image-start marker (`<image>`). Canvas M-RoPE pins it to the halo just
        outside the top-left corner of the image canvas. Resolved from the tokenizer by the
        conversion script and stored in `config.json`; required for image or video inputs.
    image_end_id (`int`, *optional*):
        Token id of the image-end marker (`</image>`). Canvas M-RoPE pins it to the far corner of
        the image canvas. Resolved from the tokenizer by the conversion script and stored in
        `config.json`; required for image or video inputs.
    slice_start_id (`int`, *optional*):
        Token id of the slice-start marker (`<slice>`). Canvas M-RoPE pins it to the top-left
        corner of the slice it opens. Resolved from the tokenizer by the conversion script and
        stored in `config.json`; required for image or video inputs.
    slice_end_id (`int`, *optional*):
        Token id of the slice-end marker (`</slice>`). Canvas M-RoPE pins it to the bottom-right
        corner of the slice it closes. Resolved from the tokenizer by the conversion script and
        stored in `config.json`; required for image or video inputs.
    newline_id (`int`, *optional*):
        Token id of the newline (`"\n"`) that separates slice rows. Canvas M-RoPE pins it just
        past the right edge of the row it ends. Resolved from the tokenizer by the conversion
        script and stored in `config.json`; required for image or video inputs.
    """

    model_type = "minicpmv4_7"
    sub_configs_defaults = {
        "text_config": SubConfigSpec(config_class=AutoConfig, model_type="qwen3_5_text"),
        "vision_config": SubConfigSpec(config_class=MiniCPMV4_7VisionConfig),
    }

    text_config: dict | PreTrainedConfig | None = None
    vision_config: dict | PreTrainedConfig | None = None
    insert_layer_id: int = 6
    image_size: int = 448
    image_token_id: int | None = None
    video_token_id: int | None = None
    tie_word_embeddings: bool = False
    downsample_mode: str = "16x"
    merge_kernel_size: tuple[int, int] | list[int] = (2, 2)
    merger_times: int = 1

    image_start_id: int | None = None
    image_end_id: int | None = None
    slice_start_id: int | None = None
    slice_end_id: int | None = None
    newline_id: int | None = None

    def __post_init__(self, **kwargs):
        super().__post_init__(**kwargs)
        self.vision_config.insert_layer_id = self.insert_layer_id
        self.patch_size = self.vision_config.patch_size


__all__ = ["MiniCPMV4_7Config", "MiniCPMV4_7VisionConfig"]
