
    gZ                     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FocalNet model configuration   )PretrainedConfig)logging)BackboneConfigMixin*get_aligned_output_features_output_indicesc                   f     e Zd ZdZdZdddddg dg d	g d
g dddddddddddddddf fd	Z x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 0.0001):
            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-05):
            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. 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 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
    ```focalnet      r   `   F)   i     r   )   r      r   )r   r   r   r   )r   r   r   r   gelug      @g        g?g-C6?g{Gz?gh㈵>    Nc                     t                      j        di | || _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        dgd t/          dt1          | j                  dz             D             z   | _        t5          ||| j                  \  | _        | _        d S )Nstemc                     g | ]}d | S )stage ).0idxs     o/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/focalnet/configuration_focalnet.py
<listcomp>z+FocalNetConfig.__init__.<locals>.<listcomp>   s    &_&_&_}s}}&_&_&_       )out_featuresout_indicesstage_namesr   )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   _out_features_out_indices)selfr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r   r   kwargs	__class__s                            r   r"   zFocalNetConfig.__init__l   s+   6 	""6"""$$(",((*$"#6 ,, 0"40P-#6 !2,,"8&_&_aT[IYIY\]I]@^@^&_&_&__0Z%;DL\1
 1
 1
-D---r   )__name__
__module____qualname____doc__
model_typer"   __classcell__)r>   s   @r   r   r      s        N N` J )))||!\\"ll ).!15
 5
 5
 5
 5
 5
 5
 5
 5
 5
r   r   N)rB   configuration_utilsr   utilsr   utils.backbone_utilsr   r   
get_loggerr?   loggerr   r   r   r   <module>rJ      s    # " 3 3 3 3 3 3       c c c c c c c c 
	H	%	%H
 H
 H
 H
 H
(*: H
 H
 H
 H
 H
r   