configuration_ijepa.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # coding=utf-8
  2. # Copyright 2024 The HuggingFace Inc. team. All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. """I-JEPA model configuration"""
  16. from ...configuration_utils import PretrainedConfig
  17. class IJepaConfig(PretrainedConfig):
  18. r"""
  19. This is the configuration class to store the configuration of a [`IJepaModel`]. It is used to instantiate an IJEPA
  20. model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
  21. defaults will yield a similar configuration to that of the I-JEPA
  22. [facebook/ijepa_vith14_1k](https://huggingface.co/facebook/ijepa_vith14_1k) architecture.
  23. Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
  24. documentation from [`PretrainedConfig`] for more information.
  25. Args:
  26. hidden_size (`int`, *optional*, defaults to 768):
  27. Dimensionality of the encoder layers and the pooler layer.
  28. num_hidden_layers (`int`, *optional*, defaults to 12):
  29. Number of hidden layers in the Transformer encoder.
  30. num_attention_heads (`int`, *optional*, defaults to 12):
  31. Number of attention heads for each attention layer in the Transformer encoder.
  32. intermediate_size (`int`, *optional*, defaults to 3072):
  33. Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
  34. hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
  35. The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
  36. `"relu"`, `"selu"` and `"gelu_new"` are supported.
  37. hidden_dropout_prob (`float`, *optional*, defaults to 0.0):
  38. The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
  39. attention_probs_dropout_prob (`float`, *optional*, defaults to 0.0):
  40. The dropout ratio for the attention probabilities.
  41. initializer_range (`float`, *optional*, defaults to 0.02):
  42. The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
  43. layer_norm_eps (`float`, *optional*, defaults to 1e-12):
  44. The epsilon used by the layer normalization layers.
  45. image_size (`int`, *optional*, defaults to 224):
  46. The size (resolution) of each image.
  47. patch_size (`int`, *optional*, defaults to 16):
  48. The size (resolution) of each patch.
  49. num_channels (`int`, *optional*, defaults to 3):
  50. The number of input channels.
  51. qkv_bias (`bool`, *optional*, defaults to `True`):
  52. Whether to add a bias to the queries, keys and values.
  53. pooler_output_size (`int`, *optional*):
  54. Dimensionality of the pooler layer. If None, defaults to `hidden_size`.
  55. pooler_act (`str`, *optional*, defaults to `"tanh"`):
  56. The activation function to be used by the pooler. Keys of ACT2FN are supported for Flax and
  57. Pytorch, and elements of https://www.tensorflow.org/api_docs/python/tf/keras/activations are
  58. supported for Tensorflow.
  59. Example:
  60. ```python
  61. >>> from transformers import IJepaConfig, IJepaModel
  62. >>> # Initializing a IJEPA ijepa-base-patch16-224 style configuration
  63. >>> configuration = IJepaConfig()
  64. >>> # Initializing a model (with random weights) from the ijepa-base-patch16-224 style configuration
  65. >>> model = IJepaModel(configuration)
  66. >>> # Accessing the model configuration
  67. >>> configuration = model.config
  68. ```"""
  69. model_type = "ijepa"
  70. def __init__(
  71. self,
  72. hidden_size=768,
  73. num_hidden_layers=12,
  74. num_attention_heads=12,
  75. intermediate_size=3072,
  76. hidden_act="gelu",
  77. hidden_dropout_prob=0.0,
  78. attention_probs_dropout_prob=0.0,
  79. initializer_range=0.02,
  80. layer_norm_eps=1e-12,
  81. image_size=224,
  82. patch_size=16,
  83. num_channels=3,
  84. qkv_bias=True,
  85. pooler_output_size=None,
  86. pooler_act="tanh",
  87. **kwargs,
  88. ):
  89. super().__init__(**kwargs)
  90. self.hidden_size = hidden_size
  91. self.num_hidden_layers = num_hidden_layers
  92. self.num_attention_heads = num_attention_heads
  93. self.intermediate_size = intermediate_size
  94. self.hidden_act = hidden_act
  95. self.hidden_dropout_prob = hidden_dropout_prob
  96. self.attention_probs_dropout_prob = attention_probs_dropout_prob
  97. self.initializer_range = initializer_range
  98. self.layer_norm_eps = layer_norm_eps
  99. self.image_size = image_size
  100. self.patch_size = patch_size
  101. self.num_channels = num_channels
  102. self.qkv_bias = qkv_bias
  103. self.pooler_output_size = pooler_output_size if pooler_output_size else hidden_size
  104. self.pooler_act = pooler_act
  105. __all__ = ["IJepaConfig"]