| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
- # This file was automatically generated from src/transformers/models/siglip2/modular_siglip2.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_siglip2.py file directly. One of our CI enforces this.
- # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
- # Copyright 2025 The HuggingFace Inc. team.
- #
- # 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
- logger = logging.get_logger(__name__)
- @auto_docstring(checkpoint="google/siglip2-base-patch16-naflex")
- @strict
- class Siglip2TextConfig(PreTrainedConfig):
- r"""
- Example:
- ```python
- >>> from transformers import Siglip2TextConfig, Siglip2TextModel
- >>> # Initializing a Siglip2TextConfig with google/siglip2-base-patch16-224 style configuration
- >>> configuration = Siglip2TextConfig()
- >>> # Initializing a Siglip2TextModel (with random weights) from the google/siglip2-base-patch16-224 style configuration
- >>> model = Siglip2TextModel(configuration)
- >>> # Accessing the model configuration
- >>> configuration = model.config
- ```"""
- model_type = "siglip2_text_model"
- base_config_key = "text_config"
- vocab_size: int = 32000
- hidden_size: int = 768
- intermediate_size: int = 3072
- num_hidden_layers: int = 12
- num_attention_heads: int = 12
- max_position_embeddings: int = 64
- hidden_act: str = "gelu_pytorch_tanh"
- layer_norm_eps: float = 1e-6
- attention_dropout: float | int = 0.0
- # This differs from `CLIPTokenizer`'s default and from openai/siglip2
- # See https://github.com/huggingface/transformers/pull/24773#issuecomment-1632287538
- pad_token_id: int | None = 1
- bos_token_id: int | None = 49406
- eos_token_id: int | list[int] | None = 49407
- projection_size: int | None = None
- def __post_init__(self, **kwargs):
- self.projection_size = self.projection_size if self.projection_size is not None else self.hidden_size
- super().__post_init__(**kwargs)
- @auto_docstring(checkpoint="google/siglip2-base-patch16-naflex")
- @strict
- class Siglip2VisionConfig(PreTrainedConfig):
- r"""
- num_patches (`int`, *optional*, defaults to 256):
- The number of patches in the image with the size of (`patch_size`, `patch_size`).
- The image is resized to fill maximum of this number of patches, and to preserve
- the aspect ratio. In case the resulted number of patches is lower, the image is
- padded in "patch" dimension.
- Example:
- ```python
- >>> from transformers import Siglip2VisionConfig, Siglip2VisionModel
- >>> # Initializing a Siglip2VisionConfig with google/siglip2-base-patch16-naflex style configuration
- >>> configuration = Siglip2VisionConfig()
- >>> # Initializing a Siglip2VisionModel (with random weights) from the google/siglip2-base-patch16-naflex style configuration
- >>> model = Siglip2VisionModel(configuration)
- >>> # Accessing the model configuration
- >>> configuration = model.config
- ```"""
- model_type = "siglip2_vision_model"
- 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
- 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
- num_patches: int = 256
- @auto_docstring(checkpoint="google/siglip2-base-patch16-naflex")
- @strict
- class Siglip2Config(PreTrainedConfig):
- r"""
- Example:
- ```python
- >>> from transformers import Siglip2Config, Siglip2Model
- >>> # Initializing a Siglip2Config with google/siglip2-base-patch16-224 style configuration
- >>> configuration = Siglip2Config()
- >>> # Initializing a Siglip2Model (with random weights) from the google/siglip2-base-patch16-224 style configuration
- >>> model = Siglip2Model(configuration)
- >>> # Accessing the model configuration
- >>> configuration = model.config
- >>> # We can also initialize a Siglip2Config from a Siglip2TextConfig and a Siglip2VisionConfig
- >>> from transformers import Siglip2TextConfig, Siglip2VisionConfig
- >>> # Initializing a Siglip2Text and Siglip2Vision configuration
- >>> config_text = Siglip2TextConfig()
- >>> config_vision = Siglip2VisionConfig()
- >>> config = Siglip2Config(text_config=config_text, vision_config=config_vision)
- ```"""
- model_type = "siglip2"
- sub_configs = {"text_config": Siglip2TextConfig, "vision_config": Siglip2VisionConfig}
- text_config: dict | PreTrainedConfig | None = None
- vision_config: dict | PreTrainedConfig | None = None
- initializer_factor: float = 1.0
- def __post_init__(self, **kwargs):
- if self.text_config is None:
- self.text_config = Siglip2TextConfig()
- logger.info("`text_config` is `None`. Initializing the `Siglip2TextConfig` with default values.")
- elif isinstance(self.text_config, dict):
- self.text_config = Siglip2TextConfig(**self.text_config)
- if self.vision_config is None:
- self.vision_config = Siglip2VisionConfig()
- logger.info("`vision_config` is `None`. initializing the `Siglip2VisionConfig` with default values.")
- elif isinstance(self.vision_config, dict):
- self.vision_config = Siglip2VisionConfig(**self.vision_config)
- super().__post_init__(**kwargs)
- __all__ = ["Siglip2Config", "Siglip2TextConfig", "Siglip2VisionConfig"]
|