|
| 1 | +# coding=utf-8 |
| 2 | +# Copyright 2025 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 | +"""VJEPA 2 model configuration""" |
| 16 | + |
| 17 | +from ...configuration_utils import PretrainedConfig |
| 18 | + |
| 19 | + |
| 20 | +class VJEPA2Config(PretrainedConfig): |
| 21 | + r""" |
| 22 | + This is the configuration class to store the configuration of a [`VJEPA2Model`]. It is used to instantiate an |
| 23 | + VJEPA2 model according to the specified arguments, defining the model architecture. Instantiating a configuration |
| 24 | + with the defaults will yield a similar configuration to that of the VJEPA2 |
| 25 | + [facebook/vjepa2-vitl-fpc64-256](https://huggingface.co/facebook/vjepa2-vitl-fpc64-256) architecture. |
| 26 | +
|
| 27 | + Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the |
| 28 | + documentation from [`PretrainedConfig`] for more information. |
| 29 | +
|
| 30 | + Args: |
| 31 | + patch_size (`int`, *optional*, defaults to 16): |
| 32 | + The size (resolution) of each patch. |
| 33 | + crop_size (`int`, *optional*, defaults to 256): |
| 34 | + Input resolution of the model |
| 35 | + frames_per_clip (`int`, *optional*, defaults to 64): |
| 36 | + The number of frames the model has been pretrained with. Does not impact inference. |
| 37 | + tubelet_size (`int`, *optional*, defaults to 2): |
| 38 | + The number of temporal frames used for a single rastor, check paper for more information. |
| 39 | + hidden_size (`int`, *optional*, defaults to 1024): |
| 40 | + Dimensionality of the encoder layers |
| 41 | + in_chans (`int`, *optional*, defaults to 3): |
| 42 | + The number of input channels |
| 43 | + num_attention_heads (`int`, *optional*, defaults to 16): |
| 44 | + Number of attention heads for each attention layer in the Encoder |
| 45 | + num_hidden_layers (`int`, *optional*, defaults to 24): |
| 46 | + The number of hidden layers |
| 47 | + drop_path_rate (`float`, *optional*, defaults to 0.0): |
| 48 | + Stochastic depth rate per sample (when applied in the main path of residual layers). |
| 49 | + mlp_ratio (`float`, *optional*, defaults to 4.0): |
| 50 | + Ratio of the hidden size of the MLPs used in Encoder relative to the `hidden_size`. |
| 51 | + layer_norm_eps (`float`, *optional*, defaults to 1e-06): |
| 52 | + The epsilon used by the layer normalization layers. |
| 53 | + qkv_bias (`bool`, *optional*, defaults to `True`): |
| 54 | + Whether to add a bias to the queries, keys and values. |
| 55 | + attention_probs_dropout_prob (`float`, *optional*, defaults to 0.0): |
| 56 | + The dropout probability for attentions. |
| 57 | + The dropout probability for all fully connected layers. |
| 58 | + hidden_act (`str`, *optional*, defaults to `"gelu"`): |
| 59 | + The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`, |
| 60 | + `"relu"`, `"selu"` and `"gelu_new"` are supported. |
| 61 | + initializer_range (`float`, *optional*, defaults to 0.02): |
| 62 | + The standard deviation of the truncated_normal_initializer for initializing all weight matrices. |
| 63 | + pred_hidden_size (`int`, *optional*, defaults to 384): |
| 64 | + Dimensionality of the predictor layers |
| 65 | + pred_num_attention_heads (`int`, *optional*, defaults to 12): |
| 66 | + Number of attention heads for each attention layer in the Predictor |
| 67 | + pred_num_hidden_layers (`int`, *optional*, defaults to 12): |
| 68 | + Number of hidden layers in the Predictor |
| 69 | + pred_num_mask_tokens (`int`, *optional*, defaults to 10): |
| 70 | + Define the number of mask tokens to use in the Predictor |
| 71 | + pred_zero_init_mask_tokens (`bool`, *optional*, defaults to `True`): |
| 72 | + Initialize the mask tokens in the predictor with 0. |
| 73 | + pred_mlp_ratio (`float`, *optional*, defaults to 4.0): |
| 74 | + Ratio of the hidden size of the MLPs used in Predictor relative to the `pred_hidden_size`. |
| 75 | +
|
| 76 | + Example: |
| 77 | +
|
| 78 | + ```python |
| 79 | + >>> from transformers import VJEPA2Config, VJEPA2Model |
| 80 | +
|
| 81 | + >>> # Initializing a VJEPA2 vjepa2-vitl-fpc64-256 style configuration |
| 82 | + >>> configuration = VJEPA2Config() |
| 83 | +
|
| 84 | + >>> # Initializing a model (with random weights) from the vjepa2-vitl-fpc64-256 style configuration |
| 85 | + >>> model = VJEPA2Model(configuration) |
| 86 | +
|
| 87 | + >>> # Accessing the model configuration |
| 88 | + >>> configuration = model.config |
| 89 | + ```""" |
| 90 | + |
| 91 | + model_type = "vjepa2" |
| 92 | + |
| 93 | + def __init__( |
| 94 | + self, |
| 95 | + patch_size=16, |
| 96 | + crop_size=256, |
| 97 | + frames_per_clip=64, |
| 98 | + tubelet_size=2, |
| 99 | + hidden_size=1024, |
| 100 | + in_chans=3, |
| 101 | + num_attention_heads=16, |
| 102 | + num_hidden_layers=24, |
| 103 | + drop_path_rate=0.0, |
| 104 | + mlp_ratio=4.0, |
| 105 | + layer_norm_eps=1e-6, |
| 106 | + qkv_bias=True, |
| 107 | + attention_probs_dropout_prob=0.0, |
| 108 | + hidden_act="gelu", |
| 109 | + initializer_range=0.02, |
| 110 | + # predictor params |
| 111 | + pred_hidden_size=384, |
| 112 | + pred_num_attention_heads=12, |
| 113 | + pred_num_hidden_layers=12, |
| 114 | + pred_num_mask_tokens=10, |
| 115 | + pred_zero_init_mask_tokens=True, |
| 116 | + pred_mlp_ratio=4.0, |
| 117 | + **kwargs, |
| 118 | + ): |
| 119 | + super().__init__(**kwargs) |
| 120 | + |
| 121 | + self.crop_size = crop_size |
| 122 | + self.frames_per_clip = frames_per_clip |
| 123 | + self.patch_size = patch_size |
| 124 | + self.tubelet_size = tubelet_size |
| 125 | + self.hidden_size = hidden_size |
| 126 | + self.in_chans = in_chans |
| 127 | + self.num_attention_heads = num_attention_heads |
| 128 | + self.num_hidden_layers = num_hidden_layers |
| 129 | + self.drop_path_rate = drop_path_rate |
| 130 | + self.mlp_ratio = mlp_ratio |
| 131 | + self.layer_norm_eps = layer_norm_eps |
| 132 | + self.qkv_bias = qkv_bias |
| 133 | + self.attention_probs_dropout_prob = attention_probs_dropout_prob |
| 134 | + self.hidden_act = hidden_act |
| 135 | + self.initializer_range = initializer_range |
| 136 | + self.image_size = crop_size |
| 137 | + # predictor params |
| 138 | + self.pred_hidden_size = pred_hidden_size |
| 139 | + self.pred_num_attention_heads = pred_num_attention_heads |
| 140 | + self.pred_num_hidden_layers = pred_num_hidden_layers |
| 141 | + self.pred_num_mask_tokens = pred_num_mask_tokens |
| 142 | + self.pred_zero_init_mask_tokens = pred_zero_init_mask_tokens |
| 143 | + self.pred_mlp_ratio = pred_mlp_ratio |
| 144 | + |
| 145 | + |
| 146 | +__all__ = ["VJEPA2Config"] |
0 commit comments