o
    Fôj)  ã                	   @   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   új/var/www/html/academy/tools/voices/clone/cosy-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   