
    .`i                     R   d Z ddlZddlZddlZddlmZmZ ddlmZm	Z	m
Z
 ddlmZmZ ddlmZ ddlmZ  ee          Z ed          Z ed	          Z ed
edef                   ZdedefdZdeedf         deedf         fdZ	 	 d#dedeeg ef         z  dedz  deegef         fdZddddedeeg ef         z  dedz  deegef         fdZeddddedef         dedededef
d             Zddddedef         d!eeef         dz  dedede eef         f
d"Z!dS )$zh
Contains helpers that are applied to functions.

This is similar in concept to the `functools` module.
    N)CallableMapping)	lru_cachepartialwraps)AnyTypeVar)	ParamSpec)init_loggerPTF.)boundvaluereturnc                     | S )z!Returns the first provided value. )r   kwargss     i/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/utils/func_utils.pyidentityr      s    L    fc                      dt           j        dt           j        dd f fdd_        t	          j                    _        S )Nargsr   r   c                      j         rd S j        5  j         sd_          | i |cd d d            S 	 d d d            d S # 1 swxY w Y   d S )NT)has_runlock)r   r   r   wrappers     r   r   zrun_once.<locals>.wrapper"   s    ? 	F\ 	* 	*? *"&q$)&))	* 	* 	* 	* 	* 	* 	* 	**	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   AA
AF)r   r   r   r   	threadingLockr   )r   r   s   `@r   run_oncer!   !   s]    *qv * *d * * * * * * * GO>##GLNr   Tstart_indexis_deprecatedadditional_messagec                      t                    st          t                    dt          dt          f fd}|S )Nfnr   c                      t          j                   j        }t           j        j        t           j        j        ffd|                                D             t                      fd            }|S )Nc                 ,    g | ]\  }}|j         v |S r   )kind).0kwparam	pos_typess      r   
<listcomp>z3deprecate_args.<locals>.wrapper.<locals>.<listcomp>>   s)    QQQ)"ey9P9P29P9P9Pr   c                                   rLt          |                    }|r3d| d}|d z  }t          j        t          |          d            | i |S )NzThe positional arguments 7 are deprecated and will be removed in a future update.    
stacklevel)lenwarningswarnDeprecationWarning)	r   r   deprecated_argsmsgr$   r&   r#   pos_kwsr"   s	       r   innerz.deprecate_args.<locals>.wrapper.<locals>.inner@   s    } ")+D		*A"B" MO M M M  *57#5777M*3//#$   
 2t&v&&&r   )inspect	signature
parameters	ParameterPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORDitemsr   )r&   paramsr<   r;   r-   r$   r#   r"   s   `  @@r   r   zdeprecate_args.<locals>.wrapper8   s    "2&&1-3
	 RQQQv||~~QQQ	r	' 	' 	' 	' 	' 	' 	' 	' 
	'$ r   )callabler   r   r   )r"   r#   r$   r   s   ``` r   deprecate_argsrF   0   sc    
 M"" 9-88A !        : Nr   )r#   r$   kwsc                      t          |          t                     st          t                      dt          dt          f fd}|S )Nr&   r   c                 D     t                      fd            }|S )Nc                                   rL|                                 z  }|r3d| d}|d z  }t          j        t          |          d            | i |S )NzThe keyword arguments r0   r1   r2   r3   )keysr6   r7   r8   )r   r   deprecated_kwargsr:   r$   deprecated_kwsr&   r#   s       r   r<   z0deprecate_kwargs.<locals>.wrapper.<locals>.innerc   s    } $*KKMMN$B!$ M1B M M M  *57#5777M*3//#$   
 2t&v&&&r   )r   )r&   r<   r$   rM   r#   s   ` r   r   z!deprecate_kwargs.<locals>.wrapperb   sC    	r	' 	' 	' 	' 	' 	' 	' 
	'$ r   )setrE   r   r   r   )r#   r$   rG   r   rM   s   ``  @r   deprecate_kwargsrO   X   sn    
 XXNM"" 9-88A !        , Nr   Frequires_kw_onlyallow_var_kwargsrE   kw_namerQ   rR   c                   t          j        |           j        }|sdS |                    |          }t	          t           j        j        t           j        j        t           j        j        f          }|rK|j	        |v }|r|r|j	        t           j        j        k    rdS |r|j	        t           j        j        k    s|s|rdS |rG|t          t          |                             }|j	        t           j        j        k    o
|j        |k    S dS )zCheck if a keyword is a valid kwarg for a callable; if requires_kw_only
    disallows kwargs names that can also be positional arguments.
    FT)r=   r>   r?   getrN   r@   rA   rB   KEYWORD_ONLYr)   nextreversedVAR_KEYWORDname)	rE   rS   rQ   rR   rD   	param_valpassable_kw_typesis_sig_param
last_params	            r   supports_kwr_   {   s.    x((3F u

7##I -3*	
    ~):: 		 '"3"@@@5 	73D3Q!Q!Q  "R%1 "R 4  
 D&!1!1223
Ow0<< +7*	

 5r   	overridesc                     |si S  fd|                                 D             }|                                |                                z
  }|r9rt                              d|           nt                              d|           |S )a  
    Given a callable which has one or more keyword only params and a dict
    mapping param names to values, drop values that can be not be kwarg
    expanded to overwrite one or more keyword-only args. This is used in a
    few places to handle custom processor overrides for multimodal models,
    e.g., for profiling when processor options provided by the user
    may affect the number of mm tokens per instance.

    Args:
        callable: Callable which takes 0 or more keyword only arguments.
                  If None is provided, all overrides names are allowed.
        overrides: Potential overrides to be used when invoking the callable.
        allow_var_kwargs: Allows overrides that are expandable for var kwargs.

    Returns:
        Dictionary containing the kwargs to be leveraged which may be used
        to overwrite one or more keyword only arguments when invoking the
        callable.
    c                 B    i | ]\  }}t          |           ||S )rP   )r_   )r*   
kwarg_namevalrR   rE   rQ   s      r   
<dictcomp>z4get_allowed_kwarg_only_overrides.<locals>.<dictcomp>   sP     	 	 	J--	
 
 
	C	 	 	r   zRThe following intended overrides are not keyword-only args and will be dropped: %szMThe following intended overrides are not keyword args and will be dropped: %s)rC   rK   loggerwarning)rE   r`   rQ   rR   filtered_overridesdropped_keyss   ` ``  r    get_allowed_kwarg_only_overridesrj      s    4  		 	 	 	 	 	(00	 	 	 >>##&8&=&=&?&??L  	NN*    NN*   r   )TN)"__doc__r=   r   r6   collections.abcr   r   	functoolsr   r   r   typingr   r	   typing_extensionsr
   vllm.loggerr   __name__rf   r   r   r   r   r!   intboolstrrF   rO   objectr_   dictrj   r   r   r   <module>rw      s          - - - - - - - - / / / / / / / / / /         ' ' ' ' ' ' # # # # # #	X		 IcNNGCLLGCxS)***A A    
D! hq$w&7    " 04%)% %%(2t8,,% d
% qc1f	% % % %T 04%)     
 (2t8,,  d
  qc1f	       F 
 #!3 3 3sF{#33 	3
 3 
3 3 3 3t "": : :sF{#:sF{#d*: 	:
 : 
#s(^: : : : : :r   