
    sg)              	           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y)    )c_floatsizeof)Enum)TYPE_CHECKINGOptionalUnion   AutoFeatureExtractorAutoProcessorAutoTokenizerc                   &    e Zd ZeZedefd       Zy)ParameterFormatreturnc                 ,    t        | j                        S )zf
        Number of byte required for this data type

        Returns:
            Integer > 0
        )r   value)selfs    J/var/www/html/venv/lib/python3.12/site-packages/transformers/onnx/utils.pysizezParameterFormat.size   s     djj!!    N)__name__
__module____qualname__r   Floatpropertyintr    r   r   r   r      s     E"c " "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     EJJ&&r   
model_name)r   r   r   c                 `   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 y||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   s     FE%,},,Z88* %'1$	$	555jAI" 			 D 4 D DZ P" 		  %6%B8Duv  #4#<"$$)%sb    B-A
B-AB-AB-!A43B-4BB-BB-"B-(B-,B-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 EE"d " c ]` il &'s '? 'WZ '&% &%%8p2q)r &%r   