o
    h)                  	   @   s   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 deZdded	ed
edefddZdededefddZdedeed  fddZdS )    )c_floatsizeof)Enum)TYPE_CHECKINGOptionalUnion   AutoFeatureExtractorAutoProcessorAutoTokenizerc                   @   s"   e Zd ZeZedef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   k/var/www/html/construction_image-detection-poc/venv/lib/python3.10/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dtypec                 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    
model_name)r   r
   r   c                 C   s   ddl m}m}m} z|| W S  tttfyk   d\}}z|| }W n ttfy0   Y nw z|| }W n ttfyC   Y nw |durT|durTtd|  d|du r_|du r_Y dS |durg| Y S | Y S 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_extractorr   r   r   get_preprocessorG   s2   
r)   N)r   )ctypesr   r   enumr   typingr   r   r   r"   r
   r   r   r   r   r   r    strr)   r   r   r   r   <module>   s   