U
    ,-eM                     @   sT   d Z ddlmZ ddlmZ ddlmZmZ ee	Z
ddiZG dd deeZd	S )
z FocalNet model configuration   )PretrainedConfig)logging)BackboneConfigMixin*get_aligned_output_features_output_indiceszmicrosoft/focalnet-tinyzGhttps://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.jsonc                       st   e Zd ZdZdZddddddd	d
d
gddddgddddgddddgddddddddddddddf fdd	Z  ZS )FocalNetConfiga  
    This is the configuration class to store the configuration of a [`FocalNetModel`]. It is used to instantiate a
    FocalNet 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 FocalNet
    [microsoft/focalnet-tiny](https://huggingface.co/microsoft/focalnet-tiny) architecture.

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

    Args:
        image_size (`int`, *optional*, defaults to 224):
            The size (resolution) of each image.
        patch_size (`int`, *optional*, defaults to 4):
            The size (resolution) of each patch in the embeddings layer.
        num_channels (`int`, *optional*, defaults to 3):
            The number of input channels.
        embed_dim (`int`, *optional*, defaults to 96):
            Dimensionality of patch embedding.
        use_conv_embed (`bool`, *optional*, defaults to `False`):
            Whether to use convolutional embedding. The authors noted that using convolutional embedding usually
            improve the performance, but it's not used by default.
        hidden_sizes (`List[int]`, *optional*, defaults to `[192, 384, 768, 768]`):
            Dimensionality (hidden size) at each stage.
        depths (`list(int)`, *optional*, defaults to `[2, 2, 6, 2]`):
            Depth (number of layers) of each stage in the encoder.
        focal_levels (`list(int)`, *optional*, defaults to `[2, 2, 2, 2]`):
            Number of focal levels in each layer of the respective stages in the encoder.
        focal_windows (`list(int)`, *optional*, defaults to `[3, 3, 3, 3]`):
            Focal window size in each layer of the respective stages in the encoder.
        hidden_act (`str` or `function`, *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.
        mlp_ratio (`float`, *optional*, defaults to 4.0):
            Ratio of MLP hidden dimensionality to embedding dimensionality.
        hidden_dropout_prob (`float`, *optional*, defaults to 0.0):
            The dropout probability for all fully connected layers in the embeddings and encoder.
        drop_path_rate (`float`, *optional*, defaults to 0.1):
            Stochastic depth rate.
        use_layerscale (`bool`, *optional*, defaults to `False`):
            Whether to use layer scale in the encoder.
        layerscale_value (`float`, *optional*, defaults to 1e-4):
            The initial value of the layer scale.
        use_post_layernorm (`bool`, *optional*, defaults to `False`):
            Whether to use post layer normalization in the encoder.
        use_post_layernorm_in_modulation (`bool`, *optional*, defaults to `False`):
            Whether to use post layer normalization in the modulation layer.
        normalize_modulator (`bool`, *optional*, defaults to `False`):
            Whether to normalize the modulator.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        layer_norm_eps (`float`, *optional*, defaults to 1e-5):
            The epsilon used by the layer normalization layers.
        encoder_stride (`int`, `optional`, defaults to 32):
            Factor to increase the spatial resolution by in the decoder head for masked image modeling.
        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.
        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.

    Example:

    ```python
    >>> from transformers import FocalNetConfig, FocalNetModel

    >>> # Initializing a FocalNet microsoft/focalnet-tiny style configuration
    >>> configuration = FocalNetConfig()

    >>> # Initializing a model (with random weights) from the microsoft/focalnet-tiny style configuration
    >>> model = FocalNetModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Zfocalnet      r   `   F   i  i         Zgelug      @g        g?g-C6?g{Gz?gh㈵>    Nc                    s   t  jf | || _|| _|| _|| _|| _|| _|| _|| _	|	| _
|
| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _dgdd tdt| jd D  | _t||| jd\| _| _d S )Nstemc                 S   s   g | ]}d | qS )Zstage ).0idxr   r   t/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/transformers/models/focalnet/configuration_focalnet.py
<listcomp>   s     z+FocalNetConfig.__init__.<locals>.<listcomp>   )out_featuresout_indicesstage_names)super__init__
image_size
patch_sizenum_channels	embed_dimuse_conv_embedhidden_sizesdepthsfocal_levelsfocal_windows
hidden_act	mlp_ratiohidden_dropout_probdrop_path_rateuse_layerscalelayerscale_valueuse_post_layernorm use_post_layernorm_in_modulationnormalize_modulatorinitializer_rangelayer_norm_epsencoder_striderangelenr   r   Z_out_featuresZ_out_indices)selfr   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r   r   kwargs	__class__r   r   r   m   s8    &  zFocalNetConfig.__init__)__name__
__module____qualname____doc__Z
model_typer   __classcell__r   r   r3   r   r      s4   M



r   N)r8   Zconfiguration_utilsr   utilsr   Zutils.backbone_utilsr   r   Z
get_loggerr5   loggerZ&FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAPr   r   r   r   r   <module>   s   
 