Ë
    T^(hÍ3  ã                   óÜ   — 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 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ddgZy)zLayoutLMv3 model configurationé    )ÚOrderedDict)ÚTYPE_CHECKINGÚAnyÚMappingÚOptional)Úversioné   )ÚPretrainedConfig)Ú
OnnxConfig)Ú compute_effective_axis_dimension)Úlogging)ÚProcessorMixin)Ú
TensorTypec                   ód   ‡ — e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„	Zˆ xZS )ÚLayoutLMv3Configa  
    This is the configuration class to store the configuration of a [`LayoutLMv3Model`]. It is used to instantiate an
    LayoutLMv3 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 LayoutLMv3
    [microsoft/layoutlmv3-base](https://huggingface.co/microsoft/layoutlmv3-base) 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 50265):
            Vocabulary size of the LayoutLMv3 model. Defines the number of different tokens that can be represented by
            the `inputs_ids` passed when calling [`LayoutLMv3Model`].
        hidden_size (`int`, *optional*, defaults to 768):
            Dimension of the encoder layers and the pooler layer.
        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.
        intermediate_size (`int`, *optional*, defaults to 3072):
            Dimension of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
        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"` are supported.
        hidden_dropout_prob (`float`, *optional*, defaults to 0.1):
            The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
        attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):
            The dropout ratio for the attention probabilities.
        max_position_embeddings (`int`, *optional*, defaults to 512):
            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).
        type_vocab_size (`int`, *optional*, defaults to 2):
            The vocabulary size of the `token_type_ids` passed when calling [`LayoutLMv3Model`].
        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.
        max_2d_position_embeddings (`int`, *optional*, defaults to 1024):
            The maximum value that the 2D position embedding might ever be used with. Typically set this to something
            large just in case (e.g., 1024).
        coordinate_size (`int`, *optional*, defaults to `128`):
            Dimension of the coordinate embeddings.
        shape_size (`int`, *optional*, defaults to `128`):
            Dimension of the width and height embeddings.
        has_relative_attention_bias (`bool`, *optional*, defaults to `True`):
            Whether or not to use a relative attention bias in the self-attention mechanism.
        rel_pos_bins (`int`, *optional*, defaults to 32):
            The number of relative position bins to be used in the self-attention mechanism.
        max_rel_pos (`int`, *optional*, defaults to 128):
            The maximum number of relative positions to be used in the self-attention mechanism.
        max_rel_2d_pos (`int`, *optional*, defaults to 256):
            The maximum number of relative 2D positions in the self-attention mechanism.
        rel_2d_pos_bins (`int`, *optional*, defaults to 64):
            The number of 2D relative position bins in the self-attention mechanism.
        has_spatial_attention_bias (`bool`, *optional*, defaults to `True`):
            Whether or not to use a spatial attention bias in the self-attention mechanism.
        visual_embed (`bool`, *optional*, defaults to `True`):
            Whether or not to add patch embeddings.
        input_size (`int`, *optional*, defaults to `224`):
            The size (resolution) of the images.
        num_channels (`int`, *optional*, defaults to `3`):
            The number of channels of the images.
        patch_size (`int`, *optional*, defaults to `16`)
            The size (resolution) of the patches.
        classifier_dropout (`float`, *optional*):
            The dropout ratio for the classification head.

    Example:

    ```python
    >>> from transformers import LayoutLMv3Config, LayoutLMv3Model

    >>> # Initializing a LayoutLMv3 microsoft/layoutlmv3-base style configuration
    >>> configuration = LayoutLMv3Config()

    >>> # Initializing a model (with random weights) from the microsoft/layoutlmv3-base style configuration
    >>> model = LayoutLMv3Model(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Ú
layoutlmv3c                 ó  •— t        ‰ | �  d|||||||||	|
|||||dœ|¤Ž || _        || _        || _        || _        || _        || _        || _        || _	        || _
        || _        || _        || _        || _        || _        || _        y )N)Ú
vocab_sizeÚhidden_sizeÚnum_hidden_layersÚnum_attention_headsÚintermediate_sizeÚ
hidden_actÚhidden_dropout_probÚattention_probs_dropout_probÚmax_position_embeddingsÚtype_vocab_sizeÚinitializer_rangeÚlayer_norm_epsÚpad_token_idÚbos_token_idÚeos_token_id© )ÚsuperÚ__init__Úmax_2d_position_embeddingsÚcoordinate_sizeÚ
shape_sizeÚhas_relative_attention_biasÚrel_pos_binsÚmax_rel_posÚhas_spatial_attention_biasÚrel_2d_pos_binsÚmax_rel_2d_posÚ
text_embedÚvisual_embedÚ
input_sizeÚnum_channelsÚ
patch_sizeÚclassifier_dropout)!Úselfr   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r&   r'   r(   r)   r*   r+   r-   r.   r,   r/   r0   r1   r2   r3   r4   ÚkwargsÚ	__class__s!                                   €úu/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/layoutlmv3/configuration_layoutlmv3.pyr%   zLayoutLMv3Config.__init__y   sÆ   ø€ ôD 	‰Ñð 	
Ø!Ø#Ø/Ø 3Ø/Ø!Ø 3Ø)EØ$;Ø+Ø/Ø)Ø%Ø%Ø%ñ	
ð  ò!	
ð$ +EˆÔ'Ø.ˆÔØ$ˆŒØ+FˆÔ(Ø(ˆÔØ&ˆÔØ*DˆÔ'Ø.ˆÔØ,ˆÔØ$ˆŒØ(ˆÔØ$ˆŒØ(ˆÔØ$ˆŒØ"4ˆÕó    )iYÄ  i   é   r:   i   Úgeluçš™™™™™¹?r<   i   é   g{®Gáz”?çñhãˆµøä>é   r   r=   i   é€   r@   Té    r@   é@   é   TTTéà   r	   é   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
model_typer%   Ú__classcell__)r7   s   @r8   r   r   $   sy   ø„ ñPðd €Jð ØØØØØØØ%(Ø #ØØØØØØØ#'ØØØ$(ØØØØØ#'ØØØØØØ÷?B5ñ B5r9   r   c                   óÒ   — e Zd Z ej                  d«      Zedeeee	ef   f   fd„«       Z
edefd„«       Zede	fd„«       Z	 	 	 	 	 	 	 dddd	e	d
e	deded   de	de	de	deeef   fd„Zy)ÚLayoutLMv3OnnxConfigz1.12Úreturnc                 ó®   — | j                   dv r%t        ddddœfddddœfddddœfddd	d
ddœfg«      S t        ddddœfddddœfddddœfddd	dœfg«      S )N)zquestion-answeringzsequence-classificationÚ	input_idsÚbatchÚsequence)r   r?   Úattention_maskÚbboxÚpixel_valuesr2   ÚheightÚwidth)r   r?   r=   r	   )Útaskr   ©r5   s    r8   ÚinputszLayoutLMv3OnnxConfig.inputsÁ   s¤   € ð �9‰9ÐIÑIÜà  g°*Ñ"=Ð>Ø%¨7°zÑ'BÐCØ ¨ZÑ8Ð9Ø#¨°^ÈÐU\Ñ%]Ð^ð	óð ô à  g°*Ñ"=Ð>Ø ¨ZÑ8Ð9Ø%¨7°zÑ'BÐCØ#¨°^Ñ%DÐEð	óð r9   c                  ó   — y)Nr>   r#   rY   s    r8   Úatol_for_validationz(LayoutLMv3OnnxConfig.atol_for_validation×   s   € àr9   c                  ó   — y)Nr:   r#   rY   s    r8   Údefault_onnx_opsetz'LayoutLMv3OnnxConfig.default_onnx_opsetÛ   s   € àr9   NÚ	processorr   Ú
batch_sizeÚ
seq_lengthÚis_pairÚ	frameworkr   r2   Úimage_widthÚimage_heightc	                 óš  — t        |j                  dd«       t        |t        j                  d¬«      }|j
                  j                  |«      }	t        |t        j                  |	¬«      }dj                  |j
                  j                  g«      |z  gg|z  }
g d¢gg|z  }| j                  ||||«      }t         |||
||¬«      «      }|S )aý  
        Generate inputs to provide to the ONNX exporter for the specific framework

        Args:
            processor ([`ProcessorMixin`]):
                The processor associated with this model configuration.
            batch_size (`int`, *optional*, defaults to -1):
                The batch size to export the model for (-1 means dynamic axis).
            seq_length (`int`, *optional*, defaults to -1):
                The sequence length to export the model for (-1 means dynamic axis).
            is_pair (`bool`, *optional*, defaults to `False`):
                Indicate if the input is a pair (sentence 1, sentence 2).
            framework (`TensorType`, *optional*, defaults to `None`):
                The framework (PyTorch or TensorFlow) that the processor will generate tensors for.
            num_channels (`int`, *optional*, defaults to 3):
                The number of channels of the generated images.
            image_width (`int`, *optional*, defaults to 40):
                The width of the generated images.
            image_height (`int`, *optional*, defaults to 40):
                The height of the generated images.

        Returns:
            Mapping[str, Any]: holding the kwargs to provide to the model's forward function
        Ú	apply_ocrFr   )Úfixed_dimensionÚnum_token_to_addú )é0   éT   éI   r@   )ÚtextÚboxesÚreturn_tensors)ÚsetattrÚimage_processorr   r   Údefault_fixed_batchÚ	tokenizerÚnum_special_tokens_to_addÚdefault_fixed_sequenceÚjoinÚ	unk_tokenÚ_generate_dummy_imagesÚdict)r5   r_   r`   ra   rb   rc   r2   rd   re   Útoken_to_addÚ
dummy_textÚdummy_bboxesÚdummy_imagerZ   s                 r8   Úgenerate_dummy_inputsz*LayoutLMv3OnnxConfig.generate_dummy_inputsß   sá   € ôJ 	�	×)Ñ)¨;¸Ô>ô 6Ø¬
×(FÑ(FÐYZô
ˆ
ð !×*Ñ*×DÑDÀWÓMˆÜ5Ø¬
×(IÑ(IÐ\hô
ˆ
ð —x‘x ×!4Ñ!4×!>Ñ!>Ð ?Ó@À:ÑMÐNÐOÐR\Ñ\ˆ
ò +Ð+Ð,¨zÑ9ˆð ×1Ñ1°*¸lÈLÐZeÓfˆäÙØØØ"Ø(ô	ó
ˆð ˆr9   )éÿÿÿÿr€   FNr	   é(   r�   )rF   rG   rH   r   ÚparseÚtorch_onnx_minimum_versionÚpropertyr   ÚstrÚintrZ   Úfloatr\   r^   Úboolr   r   r   r#   r9   r8   rM   rM   ¾   s  „ Ø!. §¡¨vÓ!6Ðàð˜  W¨S°#¨XÑ%6Ð 6Ñ7ò ó ðð* ð Uò ó ðð ð Cò ó ðð ØØØ,0ØØØñCà#ðCð ðCð ð	Cð
 ðCð ˜LÑ)ðCð ðCð ðCð ðCð 
��c�Ñ	ôCr9   rM   N)rI   Úcollectionsr   Útypingr   r   r   r   Ú	packagingr   Úconfiguration_utilsr
   Úonnxr   Ú
onnx.utilsr   Úutilsr   Úprocessing_utilsr   r   Ú
get_loggerrF   Úloggerr   rM   Ú__all__r#   r9   r8   ú<module>r”      sm   ðñ %å #ß 8Ó 8å å 3Ý Ý :Ý ñ Ý2Ý#ð 
ˆ×	Ñ	˜HÓ	%€ôW5Ð'ô W5ôtd˜:ô dðN Ð5Ð
6�r9   