o
    diP                  	   @   s   d Z ddlZddlmZ ddlmZmZ ddlmZm	Z	m
Z
mZ eeZ	ddeeef d	ed
edefddZ		ddeeef deeef ded
efddZdS )z"Utilities related to saving files.    N)Path)ListUnion)AutoFeatureExtractorAutoImageProcessorAutoProcessorAutoTokenizer Fsrc_name_or_path	subfoldertrust_remote_codereturnc                 C   s   g }z| tj| ||d W n	 ty   Y nw z| tj| ||d W n	 ty/   Y nw z| tj| ||d W n	 tyF   Y nw z| tj| ||d W |S  ty_   Y |S w )Nr   r   )appendr   from_pretrained	Exceptionr   r   r   )r
   r   r   preprocessors r   f/lsinfo/ai/hellotax_ai/llm_service/venv_embed/lib/python3.10/site-packages/optimum/utils/save_utils.pymaybe_load_preprocessors   sF   r   dest_dirsrc_subfolderc                 C   s@   t |ts	t|}|jdd t| ||dD ]}|| qdS )a  
    Saves the tokenizer, the processor and the feature extractor when found in `src_dir` in `dest_dir`.

    Args:
        src_dir (`Union[str, Path]`):
            The source directory from which to copy the files.
        dest_dir (`Union[str, Path]`):
            The destination directory to copy the files to.
        src_subfolder (`str`, defaults to `""`):
            In case the preprocessor files are located inside a subfolder of the model directory / repo on the Hugging
            Face Hub, you can specify the subfolder name here.
        trust_remote_code (`bool`, defaults to `False`):
            Whether to allow to save preprocessors that is allowed to run arbitrary code. Use this option at your own risk.
    T)exist_okr   N)
isinstancer   mkdirr   save_pretrained)r
   r   r   r   preprocessorr   r   r   maybe_save_preprocessorsA   s   

r   )r	   F)__doc__loggingpathlibr   typingr   r   transformersr   r   r   r   	getLogger__name__loggerstrboolr   r   r   r   r   r   <module>   s6   


)

