
    g&                     ~    d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	  ej
        e          Z G d	 d
e          ZdS )zTVP model configuration    N   )PretrainedConfig)logging) verify_backbone_config_arguments   )CONFIG_MAPPINGc                   |     e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd	Zedefd            Zd Z	 xZ
S )	TvpConfiga  
    This is the configuration class to store the configuration of a [`TvpModel`]. It is used to instantiate an Tvp
    model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
    defaults will yield a similar configuration to that of the Tvp
    [Intel/tvp-base](https://huggingface.co/Intel/tvp-base) architecture.

    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
    documentation from [`PretrainedConfig`] for more information.


    Args:
        backbone_config (`PretrainedConfig` or `dict`, *optional*):
            The configuration of the backbone model.
        backbone (`str`, *optional*):
            Name of backbone to use when `backbone_config` is `None`. If `use_pretrained_backbone` is `True`, this
            will load the corresponding pretrained weights from the timm or transformers library. If `use_pretrained_backbone`
            is `False`, this loads the backbone's config and uses that to initialize the backbone with random weights.
        use_pretrained_backbone (`bool`, *optional*, defaults to `False`):
            Whether to use pretrained weights for the backbone.
        use_timm_backbone (`bool`, *optional*, defaults to `False`):
            Whether to load `backbone` from the timm library. If `False`, the backbone is loaded from the transformers
            library.
        backbone_kwargs (`dict`, *optional*):
            Keyword arguments to be passed to AutoBackbone when loading from a checkpoint
            e.g. `{'out_indices': (0, 1, 2, 3)}`. Cannot be specified if `backbone_config` is set.
        distance_loss_weight (`float`, *optional*, defaults to 1.0):
            The weight of distance loss.
        duration_loss_weight (`float`, *optional*, defaults to 0.1):
            The weight of duration loss.
        visual_prompter_type (`str`, *optional*, defaults to `"framepad"`):
            Visual prompt type. The type of padding. Framepad means padding on each frame. Should be one of "framepad"
            or "framedownpad"
        visual_prompter_apply (`str`, *optional*, defaults to `"replace"`):
            The way of applying visual prompt. Replace means use the value of prompt to change the original value in
            visual inputs. Should be one of "replace", or "add", or "remove".
        visual_prompt_size (`int`, *optional*, defaults to 96):
            The size of visual prompt.
        max_img_size (`int`, *optional*, defaults to 448):
            The maximum size of frame.
        num_frames (`int`, *optional*, defaults to 48):
            The number of frames extracted from a video.
        vocab_size (`int`, *optional*, defaults to 30522):
            Vocabulary size of the Tvp text model. Defines the number of different tokens that can be represented by
            the `inputs_ids` passed when calling [`TvpModel`].
        hidden_size (`int`, *optional*, defaults to 768):
            Dimensionality of the encoder layers.
        intermediate_size (`int`, *optional*, defaults to 3072):
            Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
        num_hidden_layers (`int`, *optional*, defaults to 12):
            Number of hidden layers in the Transformer encoder.
        num_attention_heads (`int`, *optional*, defaults to 12):
            Number of attention heads for each attention layer in the Transformer encoder.
        max_position_embeddings (`int`, *optional*, defaults to 512):
            The maximum sequence length that this model might ever be used with. Typically set this to something large
            just in case (e.g., 512 or 1024 or 2048).
        max_grid_col_position_embeddings (`int`, *optional*, defaults to 100):
            The largest number of horizontal patches from a video frame.
        max_grid_row_position_embeddings (`int`, *optional*, defaults to 100):
            The largest number of vertical patches from a video frame.
        hidden_dropout_prob (`float`, *optional*, defaults to 0.1):
            The dropout probability of hidden layers.
        hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
            The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
            `"relu"`, `"selu"` and `"gelu_new"` `"quick_gelu"` are supported.
        layer_norm_eps (`float`, *optional*, defaults to 1e-12):
            The epsilon used by the layer normalization layers.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):
            The dropout probability of attention layers.
    tvpNF      ?皙?framepadreplace`     0   :w              d   gelu-q={Gz?c                     t                      j        di | |4|2t                              d           t	          d         dg          }nLt          |t                    r7|                    d          }t          |         }|                    |          }t          |||||           || _
        || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _         || _!        || _"        d S )NzX`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.resnetstage4)out_features
model_type)use_timm_backboneuse_pretrained_backbonebackbonebackbone_configbackbone_kwargs )#super__init__loggerinfor   
isinstancedictget	from_dictr   r$   r#   r"   r!   r%   distance_loss_weightduration_loss_weightvisual_prompter_typevisual_prompter_applyvisual_prompt_sizemax_img_size
num_frames
vocab_sizehidden_sizeintermediate_sizenum_hidden_layersnum_attention_headsmax_position_embeddings max_grid_col_position_embeddings max_grid_row_position_embeddingslayer_norm_epshidden_dropout_prob
hidden_actinitializer_rangeattention_probs_dropout_prob)selfr$   r#   r"   r!   r%   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r?   r@   r>   rA   rB   kwargsbackbone_model_typeconfig_class	__class__s                                e/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/tvp/configuration_tvp.pyr(   zTvpConfig.__init__g   s   : 	""6""""x'7KKrsss,X6XJOOOOO.. 	F"1"5"5l"C"C)*=>L*44_EEO(/$;++	
 	
 	
 	
  / '>$!2.$8!$8!$8!%:""4($$&!2!2#6 '>$0P-0P-,#6 $!2,H)))    r$   c                      | dd|i|S )a+  Instantiate a [`TvpConfig`] (or a derived class) from a pre-trained backbone model configuration.

        Args:
            backbone_config ([`PretrainedConfig`]):
                The backbone configuration.
        Returns:
            [`TvpConfig`]: An instance of a configuration object
        r$   r&   r&   )clsr$   rD   s      rH   from_backbone_configzTvpConfig.from_backbone_config   s     s==?=f===rI   c                     t          j        | j                  }|d         | j                                        |d<   | j        j        |d<   |S )z
        Serializes this instance to a Python dictionary. Override the default [`~PretrainedConfig.to_dict`].

        Returns:
            `Dict[str, any]`: Dictionary of all the attributes that make up this configuration instance,
        r$   Nr    )copydeepcopy__dict__r$   to_dictrG   r    )rC   outputs     rH   rQ   zTvpConfig.to_dict   sO     t}--#$0(,(<(D(D(F(FF$%#~8|rI   )NNFFNr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )__name__
__module____qualname____doc__r    r(   classmethodr   rL   rQ   __classcell__)rG   s   @rH   r
   r
      s        F FP J  %  '' #),),%(5FI FI FI FI FI FIP 	>3C 	> 	> 	> [	>      rI   r
   )rV   rN   configuration_utilsr   utilsr   utils.backbone_utilsr   autor   
get_loggerrS   r)   r
   r&   rI   rH   <module>r^      s       3 3 3 3 3 3       D D D D D D ! ! ! ! ! ! 
	H	%	%j j j j j  j j j j jrI   