configuration_aimv2.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  2. # This file was automatically generated from src/transformers/models/aimv2/modular_aimv2.py.
  3. # Do NOT edit this file manually as any edits will be overwritten by the generation of
  4. # the file from the modular. If any change should be done, please apply the change to the
  5. # modular_aimv2.py file directly. One of our CI enforces this.
  6. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  7. # Copyright 2025 Apple Inc. and The HuggingFace Team. All rights reserved.
  8. #
  9. # Licensed under the Apache License, Version 2.0 (the "License");
  10. # you may not use this file except in compliance with the License.
  11. # You may obtain a copy of the License at
  12. #
  13. # http://www.apache.org/licenses/LICENSE-2.0
  14. #
  15. # Unless required by applicable law or agreed to in writing, software
  16. # distributed under the License is distributed on an "AS IS" BASIS,
  17. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. # See the License for the specific language governing permissions and
  19. # limitations under the License.
  20. from huggingface_hub.dataclasses import strict
  21. from ...configuration_utils import PreTrainedConfig
  22. from ...utils import auto_docstring, logging
  23. logger = logging.get_logger(__name__)
  24. @auto_docstring(checkpoint="apple/aimv2-large-patch14-224-lit")
  25. @strict
  26. class Aimv2VisionConfig(PreTrainedConfig):
  27. r"""
  28. use_head (`str`, *optional*, defaults to `True`):
  29. Whether to use Attention Pooling Head or Not.
  30. is_native (`str`, *optional*, defaults to `False`):
  31. Whether to use ckpt trained for image native resolution or not.
  32. Example:
  33. ```python
  34. >>> from transformers import SiglipVisionConfig, SiglipVisionModel
  35. >>> # Initializing a Aimv2VisionConfig with apple/aimv2-large-patch14-224 style configuration
  36. >>> configuration = Aimv2VisionConfig()
  37. >>> # Initializing a Aimv2VisionModel (with random weights) from the apple/aimv2-large-patch14-224 style configuration
  38. >>> model = Aimv2VisionModel(configuration)
  39. >>> # Accessing the model configuration
  40. >>> configuration = model.config
  41. ```"""
  42. model_type = "aimv2_vision_model"
  43. base_config_key = "vision_config"
  44. hidden_size: int = 1024
  45. intermediate_size: int = 2816
  46. num_hidden_layers: int = 24
  47. num_attention_heads: int = 8
  48. num_channels: int = 3
  49. image_size: int | list[int] | tuple[int, int] = 224
  50. patch_size: int | list[int] | tuple[int, int] = 14
  51. hidden_act: str = "silu"
  52. attention_dropout: float | int = 0.0
  53. rms_norm_eps: float = 1e-5
  54. qkv_bias: bool = False
  55. mlp_bias: bool = False
  56. initializer_range: float = 0.02
  57. use_head: bool = True
  58. is_native: bool = False
  59. @auto_docstring(checkpoint="apple/aimv2-large-patch14-224-lit")
  60. @strict
  61. class Aimv2TextConfig(PreTrainedConfig):
  62. r"""
  63. Example:
  64. ```python
  65. >>> from transformers import Aimv2TextConfig, Aimv2TextModel
  66. >>> # Initializing a Aimv2TextConfig with google/aimv2-base-patch16-224 style configuration
  67. >>> configuration = Aimv2TextConfig()
  68. >>> # Initializing a Aimv2TextModel (with random weights) from the google/aimv2-base-patch16-224 style configuration
  69. >>> model = Aimv2TextModel(configuration)
  70. >>> # Accessing the model configuration
  71. >>> configuration = model.config
  72. ```"""
  73. model_type = "aimv2_text_model"
  74. base_config_key = "text_config"
  75. vocab_size: int = 49408
  76. hidden_size: int = 768
  77. intermediate_size: int = 2048
  78. num_hidden_layers: int = 12
  79. num_attention_heads: int = 6
  80. max_position_embeddings: int = 77
  81. hidden_act: str = "silu"
  82. attention_dropout: float | int = 0.0
  83. eos_token_id: int | list[int] | None = 49407
  84. rms_norm_eps: float = 1e-5
  85. qkv_bias: bool = False
  86. mlp_bias: bool = False
  87. initializer_range: float = 0.02
  88. def __post_init__(self, **kwargs):
  89. super().__post_init__(**kwargs)
  90. @auto_docstring(checkpoint="apple/aimv2-large-patch14-224-lit")
  91. @strict
  92. class Aimv2Config(PreTrainedConfig):
  93. r"""
  94. max_logit_scale (`float`, *optional*, defaults to `100.0`):
  95. The maximum logit scale to use
  96. Example:
  97. ```python
  98. >>> from transformers import Aimv2Config, Aimv2Model
  99. >>> # Initializing a Aimv2Config with apple/aimv2-large-patch14-224-lit style configuration
  100. >>> configuration = Aimv2Config()
  101. >>> # Initializing a Aimv2Model (with random weights) from the apple/aimv2-large-patch14-224-lit style configuration
  102. >>> model = Aimv2Model(configuration)
  103. >>> # Accessing the model configuration
  104. >>> configuration = model.config
  105. >>> # We can also initialize a Aimv2Config from a Aimv2TextConfig and a Aimv2VisionConfig
  106. >>> from transformers import Aimv2TextConfig, Aimv2VisionConfig
  107. >>> # Initializing a AIMv2Text and AIMv2Vision configuration
  108. >>> config_text = Aimv2TextConfig()
  109. >>> config_vision = Aimv2VisionConfig()
  110. >>> config = Aimv2Config(text_config=config_text, vision_config=config_vision)
  111. ```"""
  112. model_type = "aimv2"
  113. sub_configs = {"text_config": Aimv2TextConfig, "vision_config": Aimv2VisionConfig}
  114. text_config: dict | PreTrainedConfig | None = None
  115. vision_config: dict | PreTrainedConfig | None = None
  116. initializer_factor: float = 1.0
  117. projection_dim: int = 512
  118. logit_scale_init_value: float = 2.6592
  119. max_logit_scale: float = 100.0
  120. def __post_init__(self, **kwargs):
  121. if self.text_config is None:
  122. self.text_config = Aimv2TextConfig()
  123. logger.info("`text_config` is `None`. Initializing the `Aimv2TextConfig` with default values.")
  124. elif isinstance(self.text_config, dict):
  125. self.text_config = Aimv2TextConfig(**self.text_config)
  126. if self.vision_config is None:
  127. self.vision_config = Aimv2VisionConfig()
  128. logger.info("`vision_config` is `None`. initializing the `Aimv2VisionConfig` with default values.")
  129. elif isinstance(self.vision_config, dict):
  130. self.vision_config = Aimv2VisionConfig(**self.vision_config)
  131. super().__post_init__(**kwargs)
  132. __all__ = ["Aimv2Config", "Aimv2VisionConfig", "Aimv2TextConfig"]