U
    9%e)                     @   s   d dl mZmZ d dlmZ d dlmZmZmZ erHddl	m
Z
mZmZ G dd deZdeeeedd	d
ZeeedddZeeed  dddZdS )    )c_floatsizeof)Enum)TYPE_CHECKINGOptionalUnion   AutoFeatureExtractorAutoProcessorAutoTokenizerc                   @   s"   e Zd ZeZeedddZdS )ParameterFormat)returnc                 C   s
   t | jS )zf
        Number of byte required for this data type

        Returns:
            Integer > 0
        )r   value)self r   V/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/transformers/onnx/utils.pysize   s    zParameterFormat.sizeN)__name__
__module____qualname__r   Floatpropertyintr   r   r   r   r   r      s   r   )	dimensionfixed_dimensionnum_token_to_addr   c                 C   s   | dkr|} | |8 } | S )ze

    Args:
        dimension:
        fixed_dimension:
        num_token_to_add:

    Returns:

    r   r   )r   r   r   r   r   r    compute_effective_axis_dimension&   s    r   )num_parametersdtyper   c                 C   s
   | |j  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   r   r   r   "compute_serialized_parameters_size9   s    r    )r   r
   r   )
model_namer   c                 C   s   ddl m}m}m} z|| W S  tttfk
r   d\}}z|| }W n ttfk
rd   Y nX z|| }W n ttfk
r   Y nX |dk	r|dk	rtd|  dn.|dkr|dkrY dS |dk	r| Y S | Y S Y nX dS )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   Zfrom_pretrained
ValueErrorOSErrorKeyError)r!   r
   r   r   Z	tokenizerZfeature_extractorr   r   r   get_preprocessorG   s,    
r&   N)r   )ctypesr   r   enumr   typingr   r   r   r"   r
   r   r   r   r   r   r    strr&   r   r   r   r   <module>   s   