o
    0j                     @   s   d dl Z d dlZd dlmZmZ d dlZdZdZdZdZ	dZ
dZd	Zd
ZdZdZdZdZ			ddedeeef dee fddZe jdddZdd ZdS )    N)OptionalUnionz@min_scalesz@max_scalesz@scaleszconfig.jsonzmodel_config.jsonzmodel_state.pdparamszmodel_state.pdparams.index.jsonzpytorch_model.bin.index.jsonzpytorch_model.binzmodel.safetensors.index.jsonzmodel.safetensorszgeneration_config.jsonpretrained_model_name_or_path	filenames	subfolderc                 K   s   | dusJ d|dusJ d|dur|nd}t |tr |g}tj| r(| S tj| rwt|D ]B\}}tjtj| ||rbtjtj| ||sXt	|  d| dtj| ||  S |t
|d k rkq2td| d	|  dS td
)zr
    This is a load function, mainly called by the from_pretrained function.
    Adapt for PaddleX inference.
    Nz,pretrained_model_name_or_path cannot be Nonezfilenames cannot be None z$ does not appear to have file named .   zplease make sure one of the z under the dir zQplease make sure `pretrained_model_name_or_path` is either a file or a directory.)
isinstancestrospathisfileisdir	enumerateexistsjoinEnvironmentErrorlenFileNotFoundError
ValueError)r   r   r   kwargsindexfilename r   s/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddlex/inference/models/common/transformers/utils.pyresolve_file_path#   s<   

r   cpuc              	   c   s^    t j }| dkrt |  n| dv rt d| | zd V  W t | d S t | w )Nr   )gpuxpunpuz{}:{})paddledeviceZ
get_deviceZ
set_deviceformat)r"   Zdev_idZorigin_devicer   r   r   device_guardR   s   
r$   c                   C   sX   t  rdS dt j v rdS dt j v rdS t  rdS t  r$dS t  r*dS dS )z8
    Return the device name of running environment.
    r   r    ZgcuZrocmr   Z	metax_gpur   )r!   Zis_compiled_with_cudar"   Zget_all_custom_device_typeZis_compiled_with_rocmZis_compiled_with_xpuZis_compiled_with_macar   r   r   r   get_env_device_   s   r%   )NNN)r   r   )
contextlibr   typingr   r   r!   ZASYMMETRY_QUANT_SCALE_MINZASYMMETRY_QUANT_SCALE_MAXZSYMMETRY_QUANT_SCALEZCONFIG_NAMEZLEGACY_CONFIG_NAMEZPADDLE_WEIGHTS_NAMEZPADDLE_WEIGHTS_INDEX_NAMEZPYTORCH_WEIGHTS_INDEX_NAMEZPYTORCH_WEIGHTS_NAMEZSAFE_WEIGHTS_INDEX_NAMEZSAFE_WEIGHTS_NAMEZGENERATION_CONFIG_NAMEr   listr   contextmanagerr$   r%   r   r   r   r   <module>   s:   

/