
    g)              	           d dl mZmZ d dlmZ d dlmZmZmZ er
ddl	m
Z
mZmZ  G d de          Zdded	ed
edefdZdededefdZdedeed                  fdZdS )    )c_floatsizeof)Enum)TYPE_CHECKINGOptionalUnion   AutoFeatureExtractorAutoProcessorAutoTokenizerc                   .    e Zd ZeZedefd            ZdS )ParameterFormatreturnc                 *    t          | j                  S )zf
        Number of byte required for this data type

        Returns:
            Integer > 0
        )r   value)selfs    S/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/onnx/utils.pysizezParameterFormat.size   s     dj!!!    N)__name__
__module____qualname__r   Floatpropertyintr    r   r   r   r      s>        E"c " " " X" " "r   r   	dimensionfixed_dimensionnum_token_to_addr   c                      | dk    r|} | |z  } | S )ze

    Args:
        dimension:
        fixed_dimension:
        num_token_to_add:

    Returns:

    r   r   )r   r   r    s      r    compute_effective_axis_dimensionr"   &   s#     A~~#	!!Ir   num_parametersdtypec                     | |j         z  S )a7  
    Compute the size taken by all the parameters in the given the storage format when serializing the model

    Args:
        num_parameters: Number of parameters to be saved
        dtype: The data format each parameter will be saved

    Returns:
        Size (in byte) taken to save all the parameters
    )r   )r#   r$   s     r   "compute_serialized_parameters_sizer&   9   s     EJ&&r   
model_name)r   r   r   c                 l   ddl m}m}m} 	  |j        |           S # t
          t          t          f$ r d\  }}	  |j        |           }n# t          t          f$ r Y nw xY w	  |j        |           }n# t          t          f$ r Y nw xY w||t          d|  d          ||Y dS ||cY S |cY S w xY w)a>  
    Gets a preprocessor (tokenizer, feature extractor or processor) that is available for `model_name`.

    Args:
        model_name (`str`): Name of the model for which a preprocessor are loaded.

    Returns:
        `Optional[Union[AutoTokenizer, AutoFeatureExtractor, AutoProcessor]]`:
            If a processor is found, it is returned. Otherwise, if a tokenizer or a feature extractor exists, it is
            returned. If both a tokenizer and a feature extractor exist, an error is raised. The function returns
            `None` if no preprocessor is found.
    r	   r
   )NNNz&Couldn't auto-detect preprocessor for z1. Found both a tokenizer and a feature extractor.) r   r   r   from_pretrained
ValueErrorOSErrorKeyError)r'   r   r   r   	tokenizerfeature_extractors         r   get_preprocessorr0   G   sH    FEEEEEEEEE%,},Z888* % % %'1$	$	55jAAII" 	 	 	D		 D 4 DZ P P" 	 	 	D	  %6%Bvvvv   #4#<44"$$$$)%sb    B3A
	B3
AB3AB3"A32B33BB3BB3(B3.B32B3N)r   )ctypesr   r   enumr   typingr   r   r   r)   r   r   r   r   r   r"   r&   strr0   r   r   r   <module>r5      s:   # " " " " " " "       1 1 1 1 1 1 1 1 1 1  FEEEEEEEEEE" " " " "d " " "  c ]` il    &'s '? 'WZ ' ' ' '&% &%%8p2q)r &% &% &% &% &% &%r   