Ë
    S^(h™K  ã                   óð   — d Z ddlmZ ddlmZmZmZmZ erddlm	Z	 ddl
mZ ddlmZ 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CLIP model configurationé    ©ÚOrderedDict)ÚTYPE_CHECKINGÚAnyÚMappingÚOptionalé   )ÚProcessorMixin)Ú
TensorType)ÚPretrainedConfig)Ú
OnnxConfig)Úloggingc                   óJ   ‡ — e Zd ZdZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„	Zˆ xZS )ÚCLIPTextConfiga¯  
    This is the configuration class to store the configuration of a [`CLIPTextModel`]. It is used to instantiate a CLIP
    text encoder according to the specified arguments, defining the model architecture. Instantiating a configuration
    with the defaults will yield a similar configuration to that of the text encoder of the CLIP
    [openai/clip-vit-base-patch32](https://huggingface.co/openai/clip-vit-base-patch32) 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 CLIP text model. Defines the number of different tokens that can be represented by
            the `inputs_ids` passed when calling [`CLIPModel`].
        hidden_size (`int`, *optional*, defaults to 512):
            Dimensionality of the encoder layers and the pooler layer.
        intermediate_size (`int`, *optional*, defaults to 2048):
            Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
        projection_dim (`int`, *optional*, defaults to 512):
            Dimensionality of text and vision projection layers.
        num_hidden_layers (`int`, *optional*, defaults to 12):
            Number of hidden layers in the Transformer encoder.
        num_attention_heads (`int`, *optional*, defaults to 8):
            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-05):
            The epsilon used by the layer normalization layers.
        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).
        pad_token_id (`int`, *optional*, defaults to 1):
            Padding token id.
        bos_token_id (`int`, *optional*, defaults to 49406):
            Beginning of stream token id.
        eos_token_id (`int`, *optional*, defaults to 49407):
            End of stream token id.

    Example:

    ```python
    >>> from transformers import CLIPTextConfig, CLIPTextModel

    >>> # Initializing a CLIPTextConfig with openai/clip-vit-base-patch32 style configuration
    >>> configuration = CLIPTextConfig()

    >>> # Initializing a CLIPTextModel (with random weights) from the openai/clip-vit-base-patch32 style configuration
    >>> model = CLIPTextModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Úclip_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Úprojection_dimÚ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                    €úi/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/clip/configuration_clip.pyr   zCLIPTextConfig.__init__a   s~   ø€ ô* 	‰ÑÐs lÀÐ\hÑsÐlrÒsà$ˆŒØ&ˆÔØ!2ˆÔØ,ˆÔØ!2ˆÔØ#6ˆÔ Ø'>ˆÔ$Ø,ˆÔØ$ˆŒØ!2ˆÔØ"4ˆÔØ!2ˆÕó    )i Á  é   i   r+   é   é   éM   Ú
quick_geluçñhãˆµøä>ç        ç{®Gáz”?ç      ð?é   iþÀ  iÿÀ  ©Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
model_typeÚbase_config_keyr   Ú__classcell__©r(   s   @r)   r   r   !   sP   ø„ ñ:ðx #€JØ#€Oð ØØØØØØ "ØØØØØð ØØ÷%"3ñ "3r*   r   c                   óF   ‡ — e Zd ZdZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„	Zˆ xZS )ÚCLIPVisionConfigaö  
    This is the configuration class to store the configuration of a [`CLIPVisionModel`]. It is used to instantiate a
    CLIP vision encoder according to the specified arguments, defining the model architecture. Instantiating a
    configuration with the defaults will yield a similar configuration to that of the vision encoder of the CLIP
    [openai/clip-vit-base-patch32](https://huggingface.co/openai/clip-vit-base-patch32) 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 768):
            Dimensionality of the encoder layers and the pooler layer.
        intermediate_size (`int`, *optional*, defaults to 3072):
            Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
        projection_dim (`int`, *optional*, defaults to 512):
            Dimensionality of text and vision projection layers.
        num_hidden_layers (`int`, *optional*, defaults to 12):
            Number of hidden layers in the Transformer encoder.
        num_attention_heads (`int`, *optional*, defaults to 12):
            Number of attention heads for each attention layer in the Transformer encoder.
        num_channels (`int`, *optional*, defaults to 3):
            The number of input channels.
        image_size (`int`, *optional*, defaults to 224):
            The size (resolution) of each image.
        patch_size (`int`, *optional*, defaults to 32):
            The size (resolution) of each patch.
        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-05):
            The epsilon used by the layer normalization layers.
        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 CLIPVisionConfig, CLIPVisionModel

    >>> # Initializing a CLIPVisionConfig with openai/clip-vit-base-patch32 style configuration
    >>> configuration = CLIPVisionConfig()

    >>> # Initializing a CLIPVisionModel (with random weights) from the openai/clip-vit-base-patch32 style configuration
    >>> model = CLIPVisionModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Úclip_vision_modelÚvision_configc                 óÚ   •— t        ‰| �  di |¤Ž || _        || _        || _        || _        || _        || _        || _        || _	        || _
        || _        || _        |
| _        |	| _        y )Nr   )r   r   r   r   r   r   r   Únum_channelsÚ
patch_sizeÚ
image_sizer#   r$   r%   r!   r"   )r&   r   r   r   r   r   rC   rE   rD   r"   r!   r%   r#   r$   r'   r(   s                  €r)   r   zCLIPVisionConfig.__init__À   sz   ø€ ô" 	‰ÑÑ"˜6Ò"à&ˆÔØ!2ˆÔØ,ˆÔØ!2ˆÔØ#6ˆÔ Ø(ˆÔØ$ˆŒØ$ˆŒØ!2ˆÔØ"4ˆÔØ!2ˆÔØ,ˆÔØ$ˆ�r*   )i   i   r+   r,   r,   r	   éà   é    r/   r0   r1   r2   r3   r5   r=   s   @r)   r?   r?   †   sH   ø„ ñ4ðl %€JØ%€Oð ØØØØØØØØØØØØ÷%ñ %r*   r?   c                   óN   ‡ — 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 )	Ú
CLIPConfigaN  
    [`CLIPConfig`] is the configuration class to store the configuration of a [`CLIPModel`]. It is used to instantiate
    a CLIP 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 CLIP
    [openai/clip-vit-base-patch32](https://huggingface.co/openai/clip-vit-base-patch32) 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 [`CLIPTextConfig`].
        vision_config (`dict`, *optional*):
            Dictionary of configuration options used to initialize [`CLIPVisionConfig`].
        projection_dim (`int`, *optional*, defaults to 512):
            Dimensionality 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 CLIP implementation.
        kwargs (*optional*):
            Dictionary of keyword arguments.

    Example:

    ```python
    >>> from transformers import CLIPConfig, CLIPModel

    >>> # Initializing a CLIPConfig with openai/clip-vit-base-patch32 style configuration
    >>> configuration = CLIPConfig()

    >>> # Initializing a CLIPModel (with random weights) from the openai/clip-vit-base-patch32 style configuration
    >>> model = CLIPModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config

    >>> # We can also initialize a CLIPConfig from a CLIPTextConfig and a CLIPVisionConfig
    >>> from transformers import CLIPTextConfig, CLIPVisionConfig

    >>> # Initializing a CLIPText and CLIPVision configuration
    >>> config_text = CLIPTextConfig()
    >>> config_vision = CLIPVisionConfig()

    >>> config = CLIPConfig.from_text_vision_configs(config_text, config_vision)
    ```Úclip©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| _        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.zj`text_config_dict` is provided which will be used to initialize `CLIPTextConfig`. 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["zp`vision_config_dict` is provided which will be used to initialize `CLIPVisionConfig`. The value `vision_config["zO`text_config` is `None`. Initializing the `CLIPTextConfig` with default values.zS`vision_config` is `None`. initializing the `CLIPVisionConfig` with default values.r3   r   )Úpopr   r   r   Úto_dictÚitemsÚloggerÚinfoÚupdater?   Ústrr   rA   r   Úlogit_scale_init_valuer$   )r&   r   rA   r   rY   r'   rM   rN   Ú_text_config_dictÚkeyÚvalueÚmessageÚ_vision_config_dictr(   s                €r)   r   zCLIPConfig.__init__  sp  ø€ ð "Ÿ:™:Ð&8¸$Ó?ÐØ#ŸZ™ZÐ(<¸dÓCÐä‰ÑÑ"˜6Ò"ð
 Ð'ØÐ"Ø �ô !/Ñ BÐ1AÑ B× JÑ JÓ LÐð 0×5Ñ5Ó7ò )‘
��UØ˜+Ò%¨%°;¸sÑ3CÓ*CÈÐSkÒHkàÐ.Ñ.à ˜uð %<Ø<?¸5Ð@Yð[ñ  ð3Ø36°%Ð7NðPð  ô —K‘K Õ(ð)ð" ×ÑÐ0Ô1àÐ)ØÐ$Ø "�ô #3Ñ"HÐ5GÑ"H×"PÑ"PÓ"RÐàÐ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ñ  ð9Ø9<¸Ð=TðVð  ô —K‘K Õ(ð)ð" × Ñ Ð!4Ô5àÐØˆKÜ�K‰KÐiÔjàÐ ØˆMÜ�K‰KÐmÔnä)Ñ8¨KÑ8ˆÔÜ-Ñ>°Ñ>ˆÔà,ˆÔØ&<ˆÔ#Ø"%ˆÕùóK3s   Ã2Gr   rA   c                 óP   —  | d|j                  «       |j                  «       dœ|¤ŽS )zç
        Instantiate a [`CLIPConfig`] (or a derived class) from clip text model configuration and clip vision model
        configuration.

        Returns:
            [`CLIPConfig`]: An instance of a configuration object
        rK   r   )rS   )Úclsr   rA   r'   s       r)   Úfrom_text_vision_configsz#CLIPConfig.from_text_vision_configsk  s,   € ñ Ðf˜{×2Ñ2Ó4ÀM×DYÑDYÓD[ÑfÐ_eÑfÐfr*   )NNr+   gƒ/L¦
F@)r6   r7   r8   r9   r:   r   r?   Úsub_configsr   Úclassmethodra   r<   r=   s   @r)   rI   rI   â   sP   ø„ ñ+ðZ €JØ"0ÐCSÑT€Kð `fõV&ðp ð	g°>ð 	gÐRbò 	gó ô	gr*   rI   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 )ÚCLIPOnnxConfigÚ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_valuesrC   ÚheightÚwidth)r   r4   é   r	   Úattention_maskr   ©r&   s    r)   ÚinputszCLIPOnnxConfig.inputsy  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   ri   Úlogits_per_textÚtext_embedsÚimage_embedsr   rp   s    r)   ÚoutputszCLIPOnnxConfig.outputsƒ  sD   € äà# a¨ \Ð2Ø" Q¨ LÐ1Ø  G Ð-Ø ! W Ð.ð	ó
ð 	
r*   c                  ó   — y)Ng-Cëâ6?r   rp   s    r)   Úatol_for_validationz"CLIPOnnxConfig.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&   rz   r{   r|   r}   Útext_input_dictÚimage_input_dictr(   s          €r)   r   z$CLIPOnnxConfig.generate_dummy_inputs’  s`   ø€ ô  ™'Ñ7Ø×Ñ¨JÀ:ÐYbð 8ó 
ˆô !™7Ñ8Ø×%Ñ%°*È	ð 9ó 
Ðð 7�/Ð6Ð%5Ð6Ð6r*   c                  ó   — y)Né   r   rp   s    r)   Údefault_onnx_opsetz!CLIPOnnxConfig.default_onnx_opset¡  s   € àr*   )éÿÿÿÿr‡   N)r6   r7   r8   Úpropertyr   rX   Úintrq   rw   Úfloatry   r   r   r   r†   r<   r=   s   @r)   re   re   x  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*   re   )rI   re   r   r?   N)r9   Úcollectionsr   Útypingr   r   r   r   Úprocessing_utilsr
   Úutilsr   Úconfiguration_utilsr   Úonnxr   r   Ú
get_loggerr6   rU   r   r?   rI   re   Ú__all__r   r*   r)   ú<module>r“      s‚   ðñ å #ß 8Ó 8ñ Ý2Ý#å 3Ý Ý ð 
ˆ×	Ñ	˜HÓ	%€ôb3Ð%ô b3ôJY%Ð'ô Y%ôxSgÐ!ô Sgôl+�Zô +ò\ Q�r*   