Ë
    S^(hÙJ  ã                   óð   — d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ erddlmZ dd	lmZ  ej"                  e«      Z G d
„ de	«      Z G d„ de	«      Z G d„ de	«      Z G d„ de«      Zg d¢Zy)zGroupViT model configurationé    ©ÚOrderedDict)ÚTYPE_CHECKINGÚAnyÚMappingÚOptionalé   )ÚPretrainedConfig)Ú
OnnxConfig)Úlogging)ÚProcessorMixin)Ú
TensorTypec                   óJ   ‡ — e Zd ZdZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„	Zˆ xZS )ÚGroupViTTextConfiga>  
    This is the configuration class to store the configuration of a [`GroupViTTextModel`]. It is used to instantiate an
    GroupViT 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 GroupViT
    [nvidia/groupvit-gcc-yfcc](https://huggingface.co/nvidia/groupvit-gcc-yfcc) architecture.

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

    Args:
        vocab_size (`int`, *optional*, defaults to 49408):
            Vocabulary size of the GroupViT text model. Defines the number of different tokens that can be represented
            by the `inputs_ids` passed when calling [`GroupViTModel`].
        hidden_size (`int`, *optional*, defaults to 256):
            Dimensionality of the encoder layers and the pooler layer.
        intermediate_size (`int`, *optional*, defaults to 1024):
            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 4):
            Number of attention heads for each attention layer in the Transformer encoder.
        max_position_embeddings (`int`, *optional*, defaults to 77):
            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).
        hidden_act (`str` or `function`, *optional*, defaults to `"quick_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-5):
            The epsilon used by the layer normalization layers.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for the attention probabilities.
        dropout (`float`, *optional*, defaults to 0.0):
            The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        initializer_factor (`float`, *optional*, defaults to 1.0):
            A factor for initializing all weight matrices (should be kept to 1, used internally for initialization
            testing).

    Example:

    ```python
    >>> from transformers import GroupViTTextConfig, GroupViTTextModel

    >>> # Initializing a GroupViTTextModel with nvidia/groupvit-gcc-yfcc style configuration
    >>> configuration = GroupViTTextConfig()

    >>> model = GroupViTTextModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Úgroupvit_text_modelÚtext_configc                 óÔ   •— t        ‰| �  d|||dœ|¤Ž || _        || _        || _        |	| _        || _        || _        || _        || _	        || _
        || _        || _        |
| _        y )N)Úpad_token_idÚbos_token_idÚeos_token_id© )ÚsuperÚ__init__Ú
vocab_sizeÚhidden_sizeÚintermediate_sizeÚdropoutÚnum_hidden_layersÚnum_attention_headsÚmax_position_embeddingsÚlayer_norm_epsÚ
hidden_actÚinitializer_rangeÚinitializer_factorÚattention_dropout)Úselfr   r   r   r   r   r    r"   r!   r   r%   r#   r$   r   r   r   ÚkwargsÚ	__class__s                    €úq/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/groupvit/configuration_groupvit.pyr   zGroupViTTextConfig.__init__Z   s}   ø€ ô& 	‰ÑÐs lÀÐ\hÑsÐlrÒsà$ˆŒØ&ˆÔØ!2ˆÔØˆŒØ!2ˆÔØ#6ˆÔ Ø'>ˆÔ$Ø,ˆÔØ$ˆŒØ!2ˆÔØ"4ˆÔØ!2ˆÕó    )i Á  é   i   é   é   éM   Ú
quick_geluçñhãˆµøä>ç        r1   ç{®Gáz”?ç      ð?é   iþÀ  iÿÀ  ©Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
model_typeÚbase_config_keyr   Ú__classcell__©r(   s   @r)   r   r   !   sN   ø„ ñ3ðj '€JØ#€Oð ØØØØØ "ØØØØØØØØØ÷! 3ñ  3r*   r   c                   ó`   ‡ — e Zd ZdZdZdZddg d¢dg d¢g d	¢d
ddddddddddddgfˆ fd„	Zˆ xZS )ÚGroupViTVisionConfiga@  
    This is the configuration class to store the configuration of a [`GroupViTVisionModel`]. It is used to instantiate
    an GroupViT 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 GroupViT
    [nvidia/groupvit-gcc-yfcc](https://huggingface.co/nvidia/groupvit-gcc-yfcc) architecture.

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

    Args:
        hidden_size (`int`, *optional*, defaults to 384):
            Dimensionality of the encoder layers and the pooler layer.
        intermediate_size (`int`, *optional*, defaults to 1536):
            Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
        depths (`List[int]`, *optional*, defaults to [6, 3, 3]):
            The number of layers in each encoder block.
        num_group_tokens (`List[int]`, *optional*, defaults to [64, 8, 0]):
            The number of group tokens for each stage.
        num_output_groups (`List[int]`, *optional*, defaults to [64, 8, 8]):
            The number of output groups for each stage, 0 means no group.
        num_attention_heads (`int`, *optional*, defaults to 6):
            Number of attention heads for each attention layer in the Transformer encoder.
        image_size (`int`, *optional*, defaults to 224):
            The size (resolution) of each image.
        patch_size (`int`, *optional*, defaults to 16):
            The size (resolution) of each patch.
        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-5):
            The epsilon used by the layer normalization layers.
        dropout (`float`, *optional*, defaults to 0.0):
            The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for the attention probabilities.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        initializer_factor (`float`, *optional*, defaults to 1.0):
            A factor for initializing all weight matrices (should be kept to 1, used internally for initialization
            testing).

    Example:

    ```python
    >>> from transformers import GroupViTVisionConfig, GroupViTVisionModel

    >>> # Initializing a GroupViTVisionModel with nvidia/groupvit-gcc-yfcc style configuration
    >>> configuration = GroupViTVisionConfig()

    >>> model = GroupViTVisionModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Úgroupvit_vision_modelÚvision_configi€  i   )é   r	   r	   r,   )é@   é   r   )rC   rD   rD   rB   éà   é   r	   Úgelur0   r1   r2   r3   g      à?r-   c                 ó„  •— t        ‰| �  di |¤Ž || _        || _        || _        |t        |«      k7  r$t        j                  d|› dt        |«      › �«       || _        || _	        || _
        || _        || _        |	| _        |
| _        || _        || _        || _        || _        || _        || _        || _        || _        y )Nz&Manually setting num_hidden_layers to z1, but we expect num_hidden_layers = sum(depth) = r   )r   r   r   r   ÚdepthsÚsumÚloggerÚwarningr   Únum_group_tokensÚnum_output_groupsr   Ú
image_sizeÚ
patch_sizeÚnum_channelsr"   r!   r   r%   r#   r$   Ú
assign_epsÚassign_mlp_ratio)r&   r   r   rI   r   rM   rN   r   rO   rP   rQ   r"   r!   r   r%   r#   r$   rR   rS   r'   r(   s                       €r)   r   zGroupViTVisionConfig.__init__¸   sÖ   ø€ ô, 	‰ÑÑ"˜6Ò"à&ˆÔØ!2ˆÔØˆŒØ¤ F£Ò+Ü�N‰NØ8Ð9JÐ8Kð L!Ü!$ V£ ð/ôð "3ˆÔØ 0ˆÔØ!2ˆÔØ#6ˆÔ Ø$ˆŒØ$ˆŒØ(ˆÔØ$ˆŒØ,ˆÔØˆŒØ!2ˆÔØ!2ˆÔØ"4ˆÔØ$ˆŒØ 0ˆÕr*   r5   r=   s   @r)   r?   r?   }   s[   ø„ ñ5ðn )€JØ%€Oð ØÚØÚ#Ú$ØØØØØØØØØØØØ˜q˜÷'.1ñ .1r*   r?   c                   óV   ‡ — e Zd ZdZdZeedœZ	 	 	 	 	 dˆ fd„	Ze	dedefd„«       Z
ˆ xZS )	ÚGroupViTConfigaÈ  
    [`GroupViTConfig`] is the configuration class to store the configuration of a [`GroupViTModel`]. It is used to
    instantiate a GroupViT model according to the specified arguments, defining the text model and vision model
    configs. Instantiating a configuration with the defaults will yield a similar configuration to that of the GroupViT
    [nvidia/groupvit-gcc-yfcc](https://huggingface.co/nvidia/groupvit-gcc-yfcc) architecture.

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

    Args:
        text_config (`dict`, *optional*):
            Dictionary of configuration options used to initialize [`GroupViTTextConfig`].
        vision_config (`dict`, *optional*):
            Dictionary of configuration options used to initialize [`GroupViTVisionConfig`].
        projection_dim (`int`, *optional*, defaults to 256):
            Dimensionality of text and vision projection layers.
        projection_intermediate_dim (`int`, *optional*, defaults to 4096):
            Dimensionality of intermediate layer of text and vision projection layers.
        logit_scale_init_value (`float`, *optional*, defaults to 2.6592):
            The initial value of the *logit_scale* parameter. Default is used as per the original GroupViT
            implementation.
        kwargs (*optional*):
            Dictionary of keyword arguments.
    Úgroupvit©r   rA   c                 óî  •— |j                  dd «      }|j                  dd «      }t        ‰| �  di |¤Ž |�‚|€i }t        di |¤Žj	                  «       }	|	j                  «       D ]A  \  }
}|
|v sŒ|||
   k7  sŒ|
dvsŒ|
|v r
d|
› d|
› d�}nd|
› d�}t        j                  |«       ŒC |j                  |	«       |�¹|€i }t        di |¤Žj	                  «       }d	|v r3|d	   j                  «       D �
�ci c]  \  }
}t        |
«      |“Œ c}}
|d	<   |j                  «       D ]A  \  }
}|
|v sŒ|||
   k7  sŒ|
dvsŒ|
|v r
d|
› d
|
› d�}nd|
› d�}t        j                  |«       ŒC |j                  |«       |€i }t        j                  d«       |€i }t        j                  d«       t        di |¤Ž| _        t        di |¤Ž| _        || _        || _        || _        d| _        d| _        d| _        y c c}}
w )NÚtext_config_dictÚvision_config_dict)Útransformers_versionú`zp` is found in both `text_config_dict` and `text_config` but with different values. The value `text_config_dict["z"]` will be used instead.zn`text_config_dict` is provided which will be used to initialize `GroupViTTextConfig`. The value `text_config["z"]` will be overridden.Úid2labelzv` is found in both `vision_config_dict` and `vision_config` but with different values. The value `vision_config_dict["zt`vision_config_dict` is provided which will be used to initialize `GroupViTVisionConfig`. The value `vision_config["zS`text_config` is `None`. Initializing the `GroupViTTextConfig` with default values.zW`vision_config` is `None`. initializing the `GroupViTVisionConfig` with default values.r2   r3   Fr   )Úpopr   r   r   Úto_dictÚitemsrK   ÚinfoÚupdater?   Ústrr   rA   Úprojection_dimÚprojection_intermediate_dimÚlogit_scale_init_valuer#   r$   Úoutput_segmentation)r&   r   rA   rd   re   rf   r'   rY   rZ   Ú_text_config_dictÚkeyÚvalueÚmessageÚ_vision_config_dictr(   s                 €r)   r   zGroupViTConfig.__init__  sˆ  ø€ ð "Ÿ:™:Ð&8¸$Ó?ÐØ#ŸZ™ZÐ(<¸dÓCÐä‰ÑÑ"˜6Ò"ð
 Ð'ØÐ"Ø �ô !3Ñ FÐ5EÑ F× NÑ NÓ PÐð 0×5Ñ5Ó7ò )‘
��UØ˜+Ò%¨%°;¸sÑ3CÓ*CÈÐSkÒHkàÐ.Ñ.à ˜uð %<Ø<?¸5Ð@Yð[ñ  ð7Ø7:°eÐ;RðTð  ô —K‘K Õ(ð)ð" ×ÑÐ0Ô1àÐ)ØÐ$Ø "�ô #7Ñ"LÐ9KÑ"L×"TÑ"TÓ"VÐàÐ0Ñ0à6IÈ*Ñ6U×6[Ñ6[Ó6]÷3Ù(2¨¨U”C˜“H˜e‘Oó3Ð# JÑ/ð
 2×7Ñ7Ó9ò )‘
��UØ˜-Ò'¨E°]À3Ñ5GÓ,GÈCÐWoÒLoàÐ0Ñ0à ˜uð %FØFIÀUÐJcðeñ  ð:Ø:=¸Ð>UðWð  ô —K‘K Õ(ð)ð" × Ñ Ð!4Ô5àÐØˆKÜ�K‰KÐmÔnàÐ ØˆMÜ�K‰KÐqÔrä-Ñ<°Ñ<ˆÔÜ1ÑB°MÑBˆÔà,ˆÔØ+FˆÔ(Ø&<ˆÔ#Ø!%ˆÔØ"%ˆÔØ#(ˆÕ ùóQ3s   Ã2G1r   rA   c                 óP   —  | d|j                  «       |j                  «       dœ|¤ŽS )z÷
        Instantiate a [`GroupViTConfig`] (or a derived class) from groupvit text model configuration and groupvit
        vision model configuration.

        Returns:
            [`GroupViTConfig`]: An instance of a configuration object
        rW   r   )r_   )Úclsr   rA   r'   s       r)   Úfrom_text_vision_configsz'GroupViTConfig.from_text_vision_configsg  s,   € ñ Ðf˜{×2Ñ2Ó4ÀM×DYÑDYÓD[ÑfÐ_eÑfÐfr*   )NNr+   i   gƒ/L¦
F@)r6   r7   r8   r9   r:   r   r?   Úsub_configsr   Úclassmethodro   r<   r=   s   @r)   rU   rU   é   sZ   ø„ ñð2 €JØ"4ÐG[Ñ\€Kð ØØØ$(Ø%õ_)ðB ð	gÐ3Eð 	gÐVjò 	gó ô	gr*   rU   c                   óÌ   ‡ — e Zd Zedeeeeef   f   fd„«       Zedeeeeef   f   fd„«       Zede	fd„«       Z
	 	 	 ddddeded	ed
   deeef   f
ˆ fd„Zedefd„«       Zˆ xZS )ÚGroupViTOnnxConfigÚreturnc           	      ó@   — t        ddddœfdddddd	œfd
dddœfg«      S )NÚ	input_idsÚbatchÚsequence)r   r4   Úpixel_valuesrQ   ÚheightÚwidth)r   r4   é   r	   Úattention_maskr   ©r&   s    r)   ÚinputszGroupViTOnnxConfig.inputsu  s@   € äà '¨jÑ9Ð:Ø W°ÀHÐQXÑ!YÐZØ! w°:Ñ#>Ð?ðó
ð 	
r*   c                 ó@   — t        dddifdddifdddifdddifg«      S )NÚlogits_per_imager   rw   Úlogits_per_textÚtext_embedsÚimage_embedsr   r~   s    r)   ÚoutputszGroupViTOnnxConfig.outputs  sD   € äà# a¨ \Ð2Ø" Q¨ LÐ1Ø  G Ð-Ø ! W Ð.ð	ó
ð 	
r*   c                  ó   — y)Ng-Cëâ6?r   r~   s    r)   Úatol_for_validationz&GroupViTOnnxConfig.atol_for_validationŠ  s   € àr*   Ú	processorr   Ú
batch_sizeÚ
seq_lengthÚ	frameworkr   c                 ó‚   •— t         ‰| �  |j                  |||¬«      }t         ‰| �  |j                  ||¬«      }i |¥|¥S )N)r‰   rŠ   r‹   )r‰   r‹   )r   Úgenerate_dummy_inputsÚ	tokenizerÚimage_processor)r&   rˆ   r‰   rŠ   r‹   Útext_input_dictÚimage_input_dictr(   s          €r)   r�   z(GroupViTOnnxConfig.generate_dummy_inputsŽ  s`   ø€ ô  ™'Ñ7Ø×Ñ¨JÀ:ÐYbð 8ó 
ˆô !™7Ñ8Ø×%Ñ%°*È	ð 9ó 
Ðð 7�/Ð6Ð%5Ð6Ð6r*   c                  ó   — y)Né   r   r~   s    r)   Údefault_onnx_opsetz%GroupViTOnnxConfig.default_onnx_opset�  s   € àr*   )éÿÿÿÿr•   N)r6   r7   r8   Úpropertyr   rc   Úintr   r…   Úfloatr‡   r   r   r�   r”   r<   r=   s   @r)   rs   rs   t  sá   ø„ Øð
˜  W¨S°#¨XÑ%6Ð 6Ñ7ò 
ó ð
ð ð
˜  g¨c°3¨hÑ&7Ð!7Ñ8ò 
ó ð
ð ð Uò ó ðð ØØ,0ñ7à#ð7ð ð7ð ð	7ð
 ˜LÑ)ð7ð 
��c�Ñ	õ7ð ð Cò ó ôr*   rs   )rU   rs   r   r?   N)r9   Úcollectionsr   Útypingr   r   r   r   Úconfiguration_utilsr
   Úonnxr   Úutilsr   Úprocessing_utilsr   r   Ú
get_loggerr6   rK   r   r?   rU   rs   Ú__all__r   r*   r)   ú<module>r¡      s‚   ðñ #å #ß 8Ó 8å 3Ý Ý ñ Ý2Ý#ð 
ˆ×	Ñ	˜HÓ	%€ôY3Ð)ô Y3ôxi1Ð+ô i1ôXHgÐ%ô HgôV+˜ô +ò\ a�r*   