o
    Zhg$                     @   sR   d Z ddlmZ ddlmZ ddlmZmZ ee	Z
G dd deeZdgZdS )zHiera model configuration   )PretrainedConfig)logging)BackboneConfigMixin*get_aligned_output_features_output_indicesc                       s   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d	Z  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
    ```ZhieraZnum_hidden_layers
num_layers`            r   g      @)   r      r   )   r   r      g       @r   r   )TTFFg        Zgelug{Gz?g      ?gư>NTg333333?c                    sx  t  jdi | |d |d t|d   dkr/td|d  d|d  dt|d  d|
t|krBtd|
 dt| d|| _|| _|| _|| _|| _|| _	|| _
|| _t|| _|	| _|
| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _t||	t|d   | _d	gd
d tdt|d D  | _ t!||| j d\| _"| _#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                 S   s   g | ]}d | qS )Zstage ).0idxr   r   \/var/www/auris/lib/python3.10/site-packages/transformers/models/hiera/configuration_hiera.py
<listcomp>   s    z(HieraConfig.__init__.<locals>.<listcomp>)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intZhidden_sizeranger   r   Z_out_featuresZ_out_indices)selfr   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r   r   kwargs	__class__r   r   r   v   sR    

$zHieraConfig.__init__)__name__
__module____qualname____doc__Z
model_typeZattribute_mapr   __classcell__r   r   r;   r   r      s>    Xr   N)r@   Zconfiguration_utilsr   utilsr   Zutils.backbone_utilsr   r   Z
get_loggerr=   loggerr   __all__r   r   r   r   <module>   s   
 
*