
    `i                    r    d dl mZ d dlmZmZ d dlmZ ddlmZ erd dl	m
Z
 ddlmZmZ ddlmZmZ d!dZd S )"    )annotations)TYPE_CHECKINGUnion)trace_structured   )estimate_peak_memory_allocfree)
OrderedSet)FreeableInputBufferSNodeMemory)BaseSchedulerNodeSchedulerBuffer	candidater   gnslist[BaseSchedulerNode]group_namesstrsnodesname_to_freeable_input_bufdict[str, FreeableInputBuffer]graph_outputsOrderedSet[str]peak_memoryintiter_curr_memory(dict[BaseSchedulerNode, tuple[int, int]]snodes_allocfree$dict[BaseSchedulerNode, SNodeMemory]tlparse_namegn_to_bufs_last_useJdict[BaseSchedulerNode, list[Union[FreeableInputBuffer, SchedulerBuffer]]]returnboolc                   d}|          }t          |||          \  }}}t          t          ||                    |          }|          }d||k    rdd}||k    rdd}t          |          D ]4\  }}|         }|         }||k    rd|                                 d}5|rd|                                  d| d	| d
| d|                                  d| d| d| d|           z  d}t          |          D ]]\  }\  }}||k    rO||         }d| d| d| dt          |           d|                                 d|                                 } n^d}t          |          D ]\  }}|         }|         }|d| d|                                 d| d|                                 d| d| d|                                 d| d| d|          d| d|          z  }|z  |z  d|
 z  d                    fdt          |          D                       z  |	 dt           d            t          dfd fd!"           |S )#NF zITERATIVE PEAK DOES NOT MATCHTz.ITERATIVE CURR MEMORY CANDIDATE DOES NOT MATCHz(ITERATIVE GN CURR MEMORY DOES NOT MATCH:z
CANDIDATE:z
GROUP:z
PEAK_MEMORY_BEFORE:z
PEAK_MEMORY_AFTER_SWAP:z
CANDIDATE_ITER_CURR_MEMORY:z
CANDIDATE_NEW__CURR_MEMORY:z
CANDIDATE_ITER_ALLOCFREE:z
CANDIDATE_NEW_ALLOCFREE:z

NEW_PEAK:z(BASE:z
) @ SNODE[/z]: z
GROUP_NODE[z] ITER_GNM[z] ESTM_GNM[z] ITER_allocfree:z] ESTM_allocfree:z
GN_TO_BUFS_LAST_USE:z

c                    g | ]C\  }}d | d|                                  d|          d|          d|          d|          DS )z
SNODE[z]
z
ITER_cur_mem:z
ESTM_cur_mem:z
ITER_allocfree:z
ESTM_allocfree:)	debug_str).0inest_curr_memoryr   r   s      o/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torch/_inductor/comms_debug.py
<listcomp>z5_debug_iterative_memory_recompute.<locals>.<listcomp>[   s     	 	 	 Aq>q > >Q[[]] > >&6q&9> >&5a&8> > )9(;> > )9(;	> >	 	 	    _ITERATIVE_RECOMPUTE_ERRORz:
artifactc                      ddS )Nstring)nameencoding )tnames   r-   <lambda>z3_debug_iterative_memory_recompute.<locals>.<lambda>j   s    $! ! r/   c                      S )Nr6   )logs   r-   r8   z3_debug_iterative_memory_recompute.<locals>.<lambda>n   s    s r/   )metadata_fn
payload_fn)
r   dictzip	enumerateget_namer(   lenjoinprintr   )r   r   r   r   r   r   r   r   r   r   r   iterative_recompute_errorcandidate_allocfreeest_peak_memorysnodes_curr_memory_iter_cmnew_cmr*   gniter_gnmnew_gnmpeak_logprepostr+   	group_logr,   r:   r7   s          ``                  @@@r-   !_debug_iterative_memory_recomputerR      s    !&*95&.	
 	
 =O')91
 3v'9::;;Oy)GY'F
C$$-$(!&>$(!3 - -2#B'!"%wLR[[]]LLC(,%  8
G9--// G G"G G$/G G )8G G %..00	G G
 -4G G -3G G +>G G *:))DG G
	
 '(:;; 	 	NA{T#%%1IR/ R R R R !R R$'KKR R34::<<R RBC++--R R   & 	s^^ 		 		EAr'+H%b)GK K KR\\^^ K K !K K.0kkmmK K?GK K !K K.0kkmmK K?FK K !"K K 5ER4HK K !"	K K 5ER4H	K KII 	xy=(;===v{{	 	 	 	 	 	 &f--	 	 	
 
 	
  ;;;  3  !!!    #{{{	
 	
 	
 	
 %$r/   N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   )
__future__r   typingr   r   torch._loggingr   memoryr   torch.utils._ordered_setr	   r
   r   	schedulerr   r   rR   r6   r/   r-   <module>rY      s    " " " " " " ' ' ' ' ' ' ' ' + + + + + + 2 2 2 2 2 2  >33333388888888========_% _% _% _% _% _%r/   