
    .`i                     X   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	 d dlmZ d d	lmZ n@# e$ r8  ed
          Ze                    d          Ze                    d          ZY nw xY wddedee         fdZdedefdZ G 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                      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   s    w/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/transformers_utils/runai_utils.pyr   r      s     "$'''    model_or_pathc                 t    |                                                      t          t                              S N)lower
startswithtupleSUPPORTED_SCHEMES)r   s    r   is_runai_obj_urir   (   s+      ++E2C,D,DEEEr   c            	       v    e Zd ZdZdeddfdZddZddZ	 	 	 dd	ed
ee         dz  dee         dz  ddf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           	         t           j        rWt          j        t          j        fD ]>}t          j        |          }t          j        ||                     |                     ?t          j        	                    t                      dt          j        t          |                                                                                    d d                   }t          j                            |          rt#          j        |           t          j        |           || _        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_names        r   __init__zObjectStorageModel.__init__8   s   - 	Lv~6 L L#)#3C#8#8 c4#8#89I#J#JKKKK7<<OON3s88??,,--7799"1"=
 

 7>>(## 	$M(###
HCXNNNNNr   c                     t           j                            | j                  rt	          j        | j                   d S d S r   )r%   r   r,   r0   r-   r.   )r3   s    r   _closezObjectStorageModel._closeI   s<    7>>$(## 	$M$(#####	$ 	$r   c                       fd}|S )Nc                 P                                      r | |           d S d S r   )r9   )signumframer5   r3   s     r   new_handlerz8ObjectStorageModel._close_by_signal.<locals>.new_handlerN   s;    KKMMM 0  /////0 0r    )r3   r5   r>   s   `` r   r$   z#ObjectStorageModel._close_by_signalM   s*    	0 	0 	0 	0 	0 	0
 r   r
   
model_pathallow_patternignore_patternc                 h    |                     d          s|dz   }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_filesr0   )r3   r@   rA   rB   s       r   r   zObjectStorageModel.pull_filesU   s@     ""3'' 	*#c)JTX}nMMMMMr   )r   Nr   )r
   NN)
__name__
__module____qualname____doc__r)   r7   r9   r$   listr   r?   r   r   r   r   ,   s        	 	OC OD O O O O"$ $ $ $    *.+/	N NN Cy4'N S	D(	N
 
N N N N N Nr   r   )r
   )r'   r%   r-   r    vllmr   vllm.assets.baser   vllm.loggerr   vllm.utils.import_utilsr   rG   r1   r   r	   r   r   r   rF   ImportErrorplaceholder_attrr)   rK   boolr   r   r?   r   r   <module>rS      s    				         * * * * * * # # # # # # 5 5 5 5 5 5	X		g& WOOOOOOCCCCCCC W W W,,-CDD+<<\JJ1BBCUVVW
( 
(3 
(S	 
( 
( 
( 
(FC FD F F F F:N :N :N :N :N :N :N :N :N :Ns   A :BB