configuration_vjepa2.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright 2025 The HuggingFace Inc. team. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """VJEPA 2 model configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ...configuration_utils import PreTrainedConfig
  17. from ...utils import auto_docstring
  18. @auto_docstring(checkpoint="facebook/vjepa2-vitl-fpc64-256")
  19. @strict
  20. class VJEPA2Config(PreTrainedConfig):
  21. r"""
  22. crop_size (`int`, *optional*, defaults to 256):
  23. Input resolution of the model
  24. frames_per_clip (`int`, *optional*, defaults to 64):
  25. The number of frames the model has been pretrained with. Does not impact inference.
  26. tubelet_size (`int`, *optional*, defaults to 2):
  27. The number of temporal frames used for a single rastor, check paper for more information.
  28. num_pooler_layers (`int`, *optional*, defaults to 3):
  29. The number of self-attention layers in the pooler.
  30. pred_hidden_size (`int`, *optional*, defaults to 384):
  31. Dimensionality of the predictor layers
  32. pred_num_attention_heads (`int`, *optional*, defaults to 12):
  33. Number of attention heads for each attention layer in the Predictor
  34. pred_num_hidden_layers (`int`, *optional*, defaults to 12):
  35. Number of hidden layers in the Predictor
  36. pred_num_mask_tokens (`int`, *optional*, defaults to 10):
  37. Define the number of mask tokens to use in the Predictor
  38. pred_zero_init_mask_tokens (`bool`, *optional*, defaults to `True`):
  39. Initialize the mask tokens in the predictor with 0.
  40. pred_mlp_ratio (`float`, *optional*, defaults to 4.0):
  41. Ratio of the hidden size of the MLPs used in Predictor relative to the `pred_hidden_size`.
  42. Example:
  43. ```python
  44. >>> from transformers import VJEPA2Config, VJEPA2Model
  45. >>> # Initializing a VJEPA2 vjepa2-vitl-fpc64-256 style configuration
  46. >>> configuration = VJEPA2Config()
  47. >>> # Initializing a model (with random weights) from the vjepa2-vitl-fpc64-256 style configuration
  48. >>> model = VJEPA2Model(configuration)
  49. >>> # Accessing the model configuration
  50. >>> configuration = model.config
  51. ```"""
  52. model_type = "vjepa2"
  53. patch_size: int | list[int] | tuple[int, int] = 16
  54. crop_size: int = 256
  55. frames_per_clip: int = 64
  56. tubelet_size: int = 2
  57. hidden_size: int = 1024
  58. in_chans: int = 3
  59. num_attention_heads: int = 16
  60. num_hidden_layers: int = 24
  61. drop_path_rate: float | int = 0.0
  62. mlp_ratio: int | float = 4.0
  63. layer_norm_eps: float = 1e-6
  64. qkv_bias: bool = True
  65. attention_probs_dropout_prob: float | int = 0.0
  66. hidden_act: str = "gelu"
  67. initializer_range: float = 0.02
  68. attention_dropout: float | int = 0.0
  69. num_pooler_layers: int = 3
  70. pred_hidden_size: int = 384
  71. pred_num_attention_heads: int = 12
  72. pred_num_hidden_layers: int = 12
  73. pred_num_mask_tokens: int = 10
  74. pred_zero_init_mask_tokens: bool = True
  75. pred_mlp_ratio: int | float = 4.0
  76. __all__ = ["VJEPA2Config"]