| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
- # This file was automatically generated from src/transformers/models/smolvlm/modular_smolvlm.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_smolvlm.py file directly. One of our CI enforces this.
- # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
- # Copyright 2025 the HuggingFace Inc. team. All rights reserved.
- # Written by Orr Zohar
- #
- # 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="HuggingFaceTB/SmolVLM2-2.2B-Instruct")
- @strict
- class SmolVLMVisionConfig(PreTrainedConfig):
- r"""
- Example:
- ```python
- >>> from transformers.models.smolvlm.modeling_smolvlm import SmolVLMVisionTransformer
- >>> from transformers.models.smolvlm.configuration_smolvlm import SmolVLMVisionConfig
- >>> # Initializing a SmolVLMVisionConfig with google/siglip-so400m-patch14-384 style configuration
- >>> configuration = SmolVLMVisionConfig()
- >>> # Initializing a SmolVLMVisionTransformer (with random weights) from the google/siglip-so400m-patch14-384 style configuration
- >>> model = SmolVLMVisionTransformer(configuration)
- >>> # Accessing the model configuration
- >>> configuration = model.config
- ```"""
- model_type = "smolvlm_vision"
- base_config_key = "vision_config"
- hidden_size: int = 1152
- intermediate_size: int = 3072
- num_hidden_layers: int = 12
- num_attention_heads: int = 16
- num_channels: int = 3
- image_size: int | list[int] | tuple[int, int] = 224
- patch_size: int | list[int] | tuple[int, int] = 32
- hidden_act: str = "gelu_pytorch_tanh"
- layer_norm_eps: float = 1e-6
- attention_dropout: float | int = 0.0
- initializer_range: float = 0.02
- @auto_docstring(checkpoint="HuggingFaceTB/SmolVLM2-2.2B-Instruct")
- @strict
- class SmolVLMConfig(PreTrainedConfig):
- r"""
- scale_factor (`int`, *optional*, defaults to 2):
- The scale factor for the image encoder.
- Example:
- ```python
- >>> from transformers import SmolVLMModel, SmolVLMConfig
- >>> # Initializing configuration
- >>> configuration = SmolVLMConfig()
- >>> # Initializing a model from the configuration
- >>> model = SmolVLMModel(configuration)
- >>> # Accessing the model configuration
- >>> configuration = model.config
- ```"""
- model_type = "smolvlm"
- sub_configs = {"text_config": AutoConfig, "vision_config": SmolVLMVisionConfig}
- use_cache: bool = True
- image_token_id: int = 128257
- tie_word_embeddings: bool = False
- vision_config: dict | PreTrainedConfig | None = None
- text_config: dict | PreTrainedConfig | None = None
- scale_factor: int = 2
- pad_token_id: int | None = 128_002
- def __post_init__(self, **kwargs):
- if self.vision_config is None:
- self.vision_config = SmolVLMVisionConfig()
- logger.info("vision_config is None, using default vision config")
- elif isinstance(self.vision_config, dict):
- self.vision_config = SmolVLMVisionConfig(**self.vision_config)
- if isinstance(self.text_config, dict):
- self.text_config["model_type"] = self.text_config.get("model_type", "llama")
- self.text_config = CONFIG_MAPPING[self.text_config["model_type"]](**self.text_config)
- elif self.text_config is None:
- logger.info("text_config is None, using default Llama text config")
- self.text_config = CONFIG_MAPPING["llama"](
- rms_norm_eps=1e-5,
- pad_token_id=self.pad_token_id,
- )
- super().__post_init__(**kwargs)
- __all__ = ["SmolVLMVisionConfig", "SmolVLMConfig"]
|