
    -`i              
           d Z ddlmZ dej        defdZdej        defdZdee         defd	Z		 	 ddej        dededee         fdZ
dej        defdZdS )z$Model inspection utilities for vLLM.    Nmodulereturnc                    t          |           j        }g }t          | dd          }|Wt          |          j        }t          | dd          }|t          |          j        }d|vr|                    d|            t	          | d          r;|                    |                                                     dd                     |r| d	d
                    |           dS t          |           S )zGet info string for a module.quant_methodNschemeUnquantizedzquant=
extra_repr
 (, ))	type__name__getattrappendhasattrr	   replacejoinstr)r   
class_namepartsr   
quant_namer   s         i/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/model_inspection.py_get_module_infor      s   f&JE 6>488L,''0
400f.J
**LL.*../// v|$$ <V&&((00r::;;; 322tyy//2222 v;;    childc                     g }|                                  D ],\  }}|                    | dt          |                      -d                    |          S )z8Get a signature for a child module to detect duplicates.:r
   )named_modulesr   r   r   )r   linesname	submodules       r   _get_child_signaturer$   $   sd    E ..00 > >i<</	::<<====99Ur   indicesc                 X   t          |           } g }| d         x}}| dd         D ]A}||dz   k    r|}|                    ||k    rt          |          n| d|            |x}}B|                    ||k    rt          |          n| d|            d                    |          S )zGFormat indices into range notation (e.g., [0,1,2,4,5,6] -> '0-2, 4-6').r      N-r   )sortedr   r   r   )r%   rangesstartendidxs        r   _format_index_rangesr.   ,   s    WooGF!*ECqrr{  #'>>CCMM#e***U:J:JS:J:JKKKECC
MM#e***U2B2BS2B2BCCC99Vr   r   r"   indentc           	         g }d|z  }t          |                                           }|s6t          |           }|                    |r
| d| d| n| |            |S t          |           }|                    |r| d| d| dn| | d           g }g }|D ]Q\  }	}
	 |                    t	          |	          |
f           +# t
          $ r |                    |	|
f           Y Nw xY w|r#i }|D ]?\  }}
t          |
          }|                    |g                               ||
f           @t          |	                                d           D ]}d |D             }|d         d         }t          |d	|dz             }|d                                         }d|dz   z  }t          |          dk    r-t          |          }| d| dt          |           d
| |d<   n| d|d          d| |d<   |                    |           |D ],\  }	}
|                    t          |
|	|dz                        -|                    | d           |S )a!  Format a module tree with indentation, grouping identical layers.

    Produces output like:
        (layers): ModuleList(
          (0-27, 29-47): 47 x LlamaDecoderLayer(
            ...
          )
          (28, 48): 2 x DifferentDecoderLayer(
            ...
          )
        )
    z  r   z): c                     | d         d         S )Nr    )gs    r   <lambda>z%_format_module_tree.<locals>.<lambda>n   s    1a r   )keyc                     g | ]\  }}|S r2   r2   ).0r-   _s      r   
<listcomp>z'_format_module_tree.<locals>.<listcomp>o   s    ///vsAs///r   r   r'   r   z x r   )listnamed_childrenr   r   int
ValueErrorr$   
setdefaultr)   values_format_module_treelstriplenr.   extend)r   r"   r/   r!   prefixchildreninfonumberednon_numbered
child_namechild_modulesig_to_groupr-   siggroupr%   representativechild_lines
first_linechild_prefix	range_strs                        r   r@   r@   =   s   " EF]FF))++,,H  ''DO0000$000>O>O>OPPP F##D	LLMF--T--d----f;Md;M;M;MNNN -/H02L$, < < 
L	<OOS__l;<<<< 	< 	< 	<\ :;;;;;	<
  &?A!) 	I 	IC&|44C##C,,33S,4GHHHH L//117H7HIII 	& 	&E/////G"1Xa[N-nb&1*MMK$Q..00J6A:.L7||a099	#QQiQQCLLQQZQQ A %1!N!N71:!N!N*!N!NALL%%%% %1 P P 
L(z6A:NNOOOO	LLFLs   #$C!C,+C,modelc                 F    d                     t          |                     S )z=Format a model into a transformers-style hierarchical string.r
   )r   r@   )rS   s    r   format_model_inspectionrU      s    99(//000r   )r   r   )__doc__torch.nnnnModuler   r   r$   r:   r<   r.   r@   rU   r2   r   r   <module>rZ      s   + *      RY 3    8	 c    $s)     & F FIF
F F 
#Y	F F F FR129 1 1 1 1 1 1 1r   