o
    -i                     @   s   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ e	eZddgZzd dlmZ d d	lmZ W n eyU   ed
ZedZedZY nw ddedee fddZdedefddZG dd dZdS )    N)envs)get_cache_dir)init_logger)PlaceholderModulezs3://zgs://)list_safetensors)
pull_filesrunai_model_streamerr   r    pathreturnc                 C   s   t | S )z
    List full file names from object path and filter by allow pattern.

    Args:
        path: The object storage path to list from.

    Returns:
        list[str]: List of full object storage paths allowed by the pattern
    )runai_list_safetensors)r
    r   `/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/vllm/transformers_utils/runai_utils.pyr      s   
model_or_pathc                 C   s   |   ttS N)lower
startswithtupleSUPPORTED_SCHEMES)r   r   r   r   is_runai_obj_uri(   s   r   c                	   @   sh   e Zd ZdZdeddfddZdddZdd	d
Z			ddedee dB dee dB ddfddZ	dS )ObjectStorageModelz
    A class representing an ObjectStorage model mirrored into a
    temporary directory.

    Attributes:
        dir: The temporary created directory.

    Methods:
        pull_files(): Pull model from object storage to the temporary directory.
    urlr   Nc                 C   s   t jrtjtjfD ]}t|}t|| | q	tj	t
 dtt|  d d }tj|r;t| t| || _td| d S )Nmodel_streamer   z,Init object storage, model cache path is: %s)r   VLLM_ASSETS_CACHE_MODEL_CLEANsignalSIGINTSIGTERM	getsignal_close_by_signalosr
   joinr   hashlibsha256strencode	hexdigestexistsshutilrmtreemakedirsdirloggerdebug)selfr   sigexisting_handlerdir_namer   r   r   __init__8   s   


zObjectStorageModel.__init__c                 C   s"   t j| jrt| j d S d S r   )r    r
   r'   r+   r(   r)   )r.   r   r   r   _closeI   s   zObjectStorageModel._closec                    s    fdd}|S )Nc                    s       r | | d S d S r   )r3   )signumframer0   r.   r   r   new_handlerN   s   z8ObjectStorageModel._close_by_signal.<locals>.new_handlerr   )r.   r0   r7   r   r6   r   r   M   s   z#ObjectStorageModel._close_by_signalr	   
model_pathallow_patternignore_patternc                 C   s&   | ds	|d }t|| j|| dS )a-  
        Pull files from object storage into the temporary directory.

        Args:
            model_path: The object storage path of the model.
            allow_pattern: A list of patterns of which files to pull.
            ignore_pattern: A list of patterns of which files not to pull.

        /N)endswithrunai_pull_filesr+   )r.   r8   r9   r:   r   r   r   r   U   s   
zObjectStorageModel.pull_files)r   Nr   )r	   NN)
__name__
__module____qualname____doc__r$   r2   r3   r   listr   r   r   r   r   r   ,   s"    




r   )r	   )r"   r    r(   r   vllmr   vllm.assets.baser   vllm.loggerr   vllm.utils.import_utilsr   r>   r,   r   r   r   r   r   r=   ImportErrorplaceholder_attrr$   rB   boolr   r   r   r   r   r   <module>   s*   
