
    gK$                     p    d Z ddlmZ ddlmZ ddlmZmZ  ej        e	          Z
 G d dee          ZdS )zHiera model configuration   )PretrainedConfig)logging)BackboneConfigMixin*get_aligned_output_features_output_indicesc                        e Zd ZdZdZddiZdddgddgddgd	d	gd
g dg ddd	ddgddgg ddd	dddddddddddf fd	Z xZS )HieraConfigac  
    This is the configuration class to store the configuration of a [`HieraModel`]. It is used to instantiate a Hiera
    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 Hiera
    [facebook/hiera-base-224](https://huggingface.co/facebook/hiera-base-224) architecture.

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

    Args:
        embed_dim (`int`, *optional*, defaults to 96):
            Dimensionality of patch embedding.
        image_size (`list(int)`, *optional*, defaults to `[224, 224]`):
            The size (resolution) of input in the format (height, width) for images
            and (frames, height, width) for videos.
        patch_size (`list(int)`, *optional*, defaults to `[7, 7]`):
            The size (resolution) of each patch.
        patch_stride (`list(int)`, *optional*, defaults to `[4, 4]`):
            The stride of the patch.
        patch_padding (`list(int)`, *optional*, defaults to `[3, 3]`):
            The padding of the patch.
        mlp_ratio (`float`, *optional*, defaults to 4.0):
            The ratio of mlp hidden dim to embedding dim.
        depths (`list(int)`, *optional*, defaults to `[2, 3, 16, 3]`):
            Depth of each layer in the Transformer encoder.
        num_heads (`list(int)`, *optional*, defaults to `[1, 2, 4, 8]`):
            Number of attention heads in each layer of the Transformer encoder.
        embed_dim_multiplier (`float`, *optional*, defaults to 2.0):
            The multiplier to the dimensionality of patch embedding in each layer of the Transformer encoder.
        num_query_pool (`int`, *optional*, defaults to 3):
            The number of query pool stages.
        query_stride (`list(int)`, *optional*, defaults to `[2, 2]`):
            The stride of the query pool.
        masked_unit_size (`list(int)`, *optional*, defaults to `[8, 8]`):
            The size of the masked unit.
        masked_unit_attention (`list(bool)`, *optional*, defaults to `[True, True, False, False]`):
            Whether to use masked unit attention in each layer of the Transformer encoder.
        drop_path_rate (`float`, *optional*, defaults to 0.0):
            The drop path rate.
        num_channels (`int`, *optional*, defaults to 3):
            The number of input channels.
        hidden_act (`str`, *optional*, defaults to `"gelu"`):
            The non-linear activation function (function or string) in the encoder. If string, `"gelu"`, `"relu"`,
            `"selu"` and `"gelu_new"` are supported.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices and
            the zero_initializer for initializing all bias vectors.
        layer_norm_init (`float`, *optional*, defaults to 1.0):
            The initial weight value for layer normalization layers.
        layer_norm_eps (`float`, *optional*, defaults to 1e-06):
            The epsilon used by the layer normalization layers.
        decoder_hidden_size (`int`, *optional*):
            Dimensionality of decoder embeddings for MAE pretraining.
        decoder_depth (`int`, *optional*):
            Depth of the decoder for MAE pretraining.
        decoder_num_heads (`int`, *optional*):
            Number of attention heads in each layer of the decoder for MAE pretraining.
        normalize_pixel_loss (`bool`, *optional*, defaults to `True`):
            Whether to normalize the pixel loss by the number of pixels.
        mask_ratio (`float`, *optional*, defaults to 0.6):
            The ratio of masked tokens in the input.
        out_features (`List[str]`, *optional*):
            If used as backbone, list of features to output. Can be any of `"stem"`, `"stage1"`, `"stage2"`, etc.
            (depending on how many stages the model has). If unset and `out_indices` is set, will default to the
            corresponding stages. If unset and `out_indices` is unset, will default to the last stage. Must be in the
            same order as defined in the `stage_names` attribute.
        out_indices (`List[int]`, *optional*):
            If used as backbone, list of indices of features to output. Can be any of 0, 1, 2, etc. (depending on how
            many stages the model has). If unset and `out_features` is set, will default to the corresponding stages.
            If unset and `out_features` is unset, will default to the last stage. Must be in the
            same order as defined in the `stage_names` attribute.


    Example:

    ```python
    >>> from transformers import HieraConfig, HieraModel

    >>> # Initializing a Hiera hiera-base-patch16-224 style configuration
    >>> configuration = HieraConfig()

    >>> # Initializing a model (with random weights) from the hiera-base-patch16-224 style configuration
    >>> model = HieraModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```hieranum_hidden_layers
num_layers`            r   g      @)   r      r   )   r   r      g       @r   r   )TTFFg        gelug{Gz?g      ?gư>NTg333333?c           
          t                      j        di | |d         |d         t          |          dz
  z  z  dk    r5t          d|d          d|d          dt          |          dz
   d          |
t          |          k    r#t          d|
 dt          |           d          || _        || _        || _        || _        || _        || _	        || _
        || _        t          |          | _        |	| _        |
| _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        t;          ||	t          |          dz
  z  z            | _        d	gd
 t?          dt          |          dz             D             z   | _         tC          ||| j                   \  | _"        | _#        d S )N    r   zmasked_unit_size[0] (z() must be divisible by query_stride[0] (z/) raised to the power of the number of layers ()znum_query_pool (z*) must be less than the number of layers (stemc                     g | ]}d | S )stage ).0idxs     i/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/hiera/configuration_hiera.py
<listcomp>z(HieraConfig.__init__.<locals>.<listcomp>   s    &Z&Z&Z}s}}&Z&Z&Z    )out_featuresout_indicesstage_namesr   )$super__init__len
ValueError	embed_dim
image_size
patch_sizepatch_stridepatch_padding	mlp_ratiodepths	num_headsr   embed_dim_multipliernum_query_poolquery_stridemasked_unit_sizemasked_unit_attentiondrop_path_ratenum_channels
hidden_actinitializer_rangelayer_norm_initlayer_norm_epsdecoder_hidden_sizedecoder_depthdecoder_num_headsnormalize_pixel_loss
mask_ratiointhidden_sizeranger#   r   _out_features_out_indices)selfr(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r!   r"   kwargs	__class__s                               r   r%   zHieraConfig.__init__v   s@   < 	""6"""AaS[[1_!EEJJS(8(; S Seqrset S S@CFaS S S  
 S[[((k>kk]`ag]h]hkkk   #$$(*""f++$8!,( 0%:",($!2.,#6 *!2$8!$ y+?CKKRSO+TTUU"8&Z&ZaVWX@Y@Y&Z&Z&ZZ0Z%;DL\1
 1
 1
-D---r    )__name__
__module____qualname____doc__
model_typeattribute_mapr%   __classcell__)rG   s   @r   r   r      s        V Vp J(,7M :q6V!f}},, VQ888 !7I
 I
 I
 I
 I
 I
 I
 I
 I
 I
r    r   N)rK   configuration_utilsr   utilsr   utils.backbone_utilsr   r   
get_loggerrH   loggerr   r   r    r   <module>rT      s       3 3 3 3 3 3       c c c c c c c c 
	H	%	%f
 f
 f
 f
 f
%'7 f
 f
 f
 f
 f
r    