U
    zh                     @   s  U d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZ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mZmZmZmZmZ d dlmZ d dlmZ d dlmZ zd dlZ W n e!k
r   dZ Y nX d dl"Z"d dl#Z"d dl$m%Z%m&Z&m'Z'm(Z( d dl#m)Z) d d	lm*Z*m+Z+ d d
l,m-Z-m.Z. d dl/m0Z1 d dl2m3Z3 d dl4m5Z5 d dlm6Z6 ddl7m8Z8m9Z9m:Z: ddl;m<Z< ddl=m>Z>m?Z? ddl@mAZAmBZBmCZCmDZDmEZE ddlFmGZGmHZHmIZImJZJ ddlKmLZLmMZMmNZN ddl9mOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZV ddlWmXZXmYZYmZZZ ddl[m\Z\ ddl]m^Z^ ddl_m`Z`maZa ddl:mbZb ddlmcZc ddldmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZu evewZxe"jyzewdZ{e"jyzewdZ|e"j}j~jWjZe ZG d d! d!Ze Ze Zdaee ed"< ee1d#d$ Zd%d& ZeNjd'd( ZdQd*d+Zd ae  Zeje ed,< d-d. Zd/d0 ZG d1d2 d2ZdRe<eed4d5d6Zd d7l mZ d d8lmZ ejrdd9lmZ e Zeeecf ed:< eced;d<d=Ze*d>d?ee8jdSd d@ejeeef eeef eeef e<eee\eGeej eeeZ dAdBd>ZG dCdD dDZe<e\dEdFdGZdHdI ZdJdK ZG dLdM dMZe\dNdOdPZdS )T    N)Path)AnyCallableDictListOptionalSet)#maybe_upload_prof_stats_to_manifold)_use_lazy_graph_module)CapturedTraceback)compile_contextCompileContext	CompileIdtracing)
structured)compile_time_strobelight_metasignpost_event)ConstraintViolationErrorGuardOnDataDependentSymNode)_forward_from_src)DistributedDataParallel)_disable_current_modes)format_traceback_short   )configexctrace_rules)
CompilerFn)remove_dead_coderemove_pointless_jumps) check_inst_exn_tab_entries_validInstructionis_generator propagate_inst_exn_table_entriestransform_code_object)CacheSizeRelevantForFramecompute_cache_sizeexceeds_cache_size_limitis_recompilation)always_optimize_code_objects	skip_codeTorchPatcher)augment_exc_messageBackendCompilerFailedformat_error_msgInternalTorchDynamoErrorTorchRuntimeErrorUncapturedHigherOrderOpErrorunimplementedUnsupported)CheckFunctionManager&get_and_maybe_log_recompilation_reasonGuardedCode)Hooks)ExecutionRecord)InstructionTranslatorSpeculationLog)is_numpy)BytecodeHook)CleanupManagerCompilationMetricscountersdynamo_timedformat_bytecodeframe_phase_timinggen_record_file_nameincrement_frameis_namedtupleistype
LazyStringorig_code_maprecord_compilation_metricsreset_graph_break_dup_checkersetup_compile_debugtroubleshooting_urlwrite_record_to_filebytecodeZgraph_breaksc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
Trackerc                 C   s   g | _ t | _d S N)seensetseen_idsself rV   M/var/www/html/venv/lib/python3.8/site-packages/torch/_dynamo/convert_frame.py__init__r   s    zTracker.__init__c                    sD   t |  jkr@t| fdd}j| j  d S )Nc                    s   j  S rP   )rS   remove)_idxrU   rV   rW   <lambda>y       zTracker.add.<locals>.<lambda>)idrS   weakrefrefrQ   appendadd)rU   Z
strong_objobjrV   r[   rW   rc   v   s
    
zTracker.addc                 C   s   t || jkS rP   )r_   rS   )rU   itemrV   rV   rW   __contains__}   s    zTracker.__contains__c                 C   s   | j   | j  d S rP   )rQ   clearrS   rT   rV   rV   rW   rg      s    
zTracker.clearN)__name__
__module____qualname__rX   rc   rf   rg   rV   rV   rV   rW   rO   q   s   rO   initial_global_statec                  O   s   t | |}t|j |S rP   )original_forward_from_srcr*   __code__)argskwargsresultrV   rV   rW   fx_forward_from_src_skip_result   s    

rq   c                    s    t   fdd} |_|S )z
    Context manager to:
        1) Save/restore torch.is_grad_enabled() state
        2) Save/restore python random state
        3) Save/restore torch random state
        4) Monkey patch torch.fx.graph_module._forward_from_src
    c                     s:  t  }t }tj  t }t }t }t	 }tj
 }tj rZtj
 }	tj }
tjjj}ttjj_t }z | |W W  5 Q R  S |  tj| tjj| tj||d t| tj| tj rtj|	 tj|
 |tjj_| s*td|  dX W 5 Q R X d S )N)Z	warn_onlyzGlobal z7state changed while dynamo tracing, please report a bug)GlobalStateGuardtorchZis_grad_enabled_CZ_PreserveDispatchKeyGuardZis_inference_mode_enabledZ$are_deterministic_algorithms_enabledZ-is_deterministic_algorithms_warn_only_enabledrandomgetstateZget_rng_statecudaZis_availableZ_get_cublas_allow_tf32ZfxZgraph_moduler   rq   rK   closeZ_set_grad_enabledZautogradZ	grad_modeZ_enter_inference_modeZuse_deterministic_algorithmssetstateZset_rng_stateZ_set_cublas_allow_tf32checkAssertionErrorreason)rn   ro   guardsZprior_grad_modeZprior_inference_modeZprior_deterministicZprior_warn_onlyZpy_rng_stateZtorch_rng_stateZcuda_rng_stateZ
allow_tf32Zprior_fwd_from_srccleanupfnrV   rW   _fn   sB    





 


z"preserve_global_state.<locals>._fn)	functoolswraps_torchdynamo_orig_callable)r   r   rV   r   rW   preserve_global_state   s    	&r   c                    s   | j tkrdS | j jD ]^}|| jkr| j| }t|tjrT|jdsN|t	krT dS t
rtjr|t
ksnt|r dS qt  fdd | j D ]} |r dS qtd| j j| j j| j j dS )z+Check if the frame has torch.* related bitsTztorch.c                    sf  t  }|kr| S d|< t tjtjjfsLt tr\t tjjr\d|< | S t	j
rtrt tjs~t tjrd|< | S t ttfrtfdd D |< | S t t rt  }tfdd|D |< | S t ttttdtfr"d|< | S t r^t dr^t fdd jD |< | S dS dS )	z)Recursively check if the obj has a tensorFTc                 3   s   | ]} |V  qd S rP   rV   .0v
has_tensorrV   rW   	<genexpr>   s     z:has_tensor_in_frame.<locals>.has_tensor.<locals>.<genexpr>c                 3   s   | ]} |V  qd S rP   rV   r   r   rV   rW   r      s     N_fieldsc                 3   s   | ]} t |V  qd S rP   )getattrr   )r   rd   rV   rW   r      s     )r_   
isinstancers   ZTensornnModulerF   type
issubclassr   trace_numpynpZndarrayZgenericlisttupleanydictvaluesstrintfloatboolrE   hasattrr   )rd   obj_idr   r   rS   )rd   rW   r      sF    

z'has_tensor_in_frame.<locals>.has_tensorz0skipping because no torch.* %s             %s %sF)f_coder)   co_names	f_globalsr   types
ModuleTyperh   
startswithrs   r   r   r   r;   r   f_localsr   logdebugco_nameco_filenameco_firstlineno)framer   rd   valuerV   r   rW   has_tensor_in_frame   s2    



+r   Fc                 C   s:   d }t | dr*t| |}t|| j || _t| |d d S )Nexec_recordexport)r   rC   rM   r   record_filenamer,   )ecoder   r   r   rV   rV   rW   exception_handler  s    

r   FRAME_COMPILE_COUNTERc                 C   s   t jrt| S | S rP   )r   Zcprofilecprofile_wrapperfuncrV   rV   rW   maybe_cprofile%  s    r   c                    s   t   fdd}|S )Nc               	      s  t  }|stdtdj dt|dd d}t }|	  t

 }|jf| |}t

 | }|  tdj|| t|}z|| W n$ tk
r   tdt| Y nX |d}	zRtjd	d
ddddt|gtjd}
tjdddt|	g|
jd tdt|	 W nH tk
rj   td |tjjd |tjjd Y nX tt|  rt j!"d fdd |S )NzTrace id is Nonez/tmp/rZ   /z.profilez7### Cprofile for %s trace id [%s] took %.3f seconds ###zCannot write to %sz.svgZ	gprof2dotz-fpstatsz"--node-label=total-time-percentagez!--node-label=self-time-percentagez--node-label=total-time)stdoutdotz-Tsvgz-o)stdinz Generated SVG from profile at %szxFailed to generate SVG from profile -- dumping stats instead.Try installing gprof2dot and dot for a better visualization   linkc                      s
   d dS )NZcprofile_manifold_url)nameurlrV   rV   Zmanifold_linkrV   rW   r]   d  r^   z;cprofile_wrapper.<locals>.profile_wrapper.<locals>.<lambda>)#r   Zcurrent_trace_idr{   r   rh   r   replacecProfileZProfileenabletimeZruncalldisabler   warningr   ZStatsZ
dump_statsPermissionErrorwith_suffix
subprocessPopenPIPE
check_callr   FileNotFoundErrorZ
sort_statsZSortKeyZTIMEZprint_statsZ
CUMULATIVEr	   rs   _loggingtrace_structured)rn   ro   Ztrace_idZprofile_pathZprofZstart_tsretvalZprofile_latencyZpsZsvg_pathZgprof2dot_processr   r   rW   profile_wrapper,  sl    

	

z)cprofile_wrapper.<locals>.profile_wrapper)r   r   )r   r   rV   r   rW   r   +  s    ;r   c                   @   sF   e Zd ZdeeedddZedd Zd	d
ej	e
edddZdS )ConvertFrameAssertTFNcompiler_fn	one_graphr   c                 C   s"   t   || _|| _|| _|| _d S rP   )rJ   r   
_one_graph_export_export_constraints)rU   r   r   r   export_constraintsrV   rV   rW   rX   l  s
    zConvertFrameAssert.__init__c                    s    fddS )Nc                    s   t |  j j jS rP   )convert_frame_assertr   r   r   backendrT   rV   rW   r]   {  s
      z8ConvertFrameAssert._clone_with_backend.<locals>.<lambda>rV   rT   rV   rT   rW   _clone_with_backendy  s    z&ConvertFrameAssert._clone_with_backendr   skipr   hooksr   c                C   s  t   |j}t||}t| |tkr,d S tjdrNtjd|j	krNd S |j	dkrh|j
drhd S |j	dkrvd S |j	dkr|j
tjtjjrd S |j	dkr|j
dkrd S |j	dkr|j
dkrt|jsd S t|rtd	 t|sd S t ad
|krt|d
< td7 a|d
 }t| }	t|  d7  < t||	}
tdd|j	|j
|j|j|jd t |j|j!|j"|j| j#| j$| j%| j&||||||
|d dS )NZTORCHDYNAMO_DEBUG_FUNCTIONz	<genexpr>)ztransformers/file_utils.pyztransformers/utils/generic.pyzdiffusers/utils/outputs.py__setattr__rX   z<module><string>z<lambda>	generatorZ_idr   Zdynamoz_convert_frame_assert._compile)r   r   r   
cache_sizeZaccumulated_cache_size)frame_state
compile_idr   )'rD   r   r&   input_codesrc   output_codesosenvirongetr   r   endswithr   pathdirnamers   Zoptim__file__r   
f_builtinsr"   r2   r   rr   rk   FRAME_COUNTERr   r   r   r   +num_cache_entries_with_same_id_matched_objsnum_cache_entries_compiler   r   r   r   r   r   )rU   r   cache_entryr   r   r   r   r   Zframe_idZframe_compile_idr   rV   rV   rW   __call__  s    	





zConvertFrameAssert.__call__)TFN)rh   ri   rj   r   r   rX   propertyr   r   	FrameTyper7   r   r   rV   rV   rV   rW   r   k  s       
r   Tr   c                 C   s   t | |||S )z&Fully convert a frame into an FX graph)r   )r   r   r   r   rV   rV   rW   r     s    r   )OrderedDict)RemovableHandle)OutputGraph_bytecode_hooks)hookreturnc                 C   s   t t}| t|j< |S )zRegister hooks for bytecode generated by Dynamo. The hook can do some
    logging, as well as return a new code object to be used. Please refer
    to `BytecodeHook` for the hook signature.
    )r   r  r_   )r  handlerV   rV   rW   register_bytecode_hook   s    
r  r   Z
phase_namer   )r   globalslocalsbuiltinsr   r   r   r   r   r   r   r  c          ,   #      sT  ddl m m}mm} dt d d t 
t tjj	
  t 	
fdd}tddttjttttt tttf gtf tt dfd	d
}tt| d t|
r|rt|	|t|
\}}|r6dd }fdd}t d|t!t"||| t# t$| d t%dj&j'j(d d)t*j+d d,  tj-.dfdd t// }d }d }d }d }d }z(z&|||}|W W W  5 Q R  S  tDtEtFtGtHtI|tJ|f	k
rD }+ zLttK|+}t|+}tL|+|d  |+jMd k	r,|+jMjN}|+jMjO}||+_P W 5 d }+~+X Y n tQk
r }+ z`ttK|+}t|+}tL|+|d  |+jMd k	r|+jMjN}|+jMjO}||+_PtRt|+S|+jTd W 5 d }+~+X Y nX W 5 ri j0_1ddl2m3} t|}|d krd k	r|t4krt5j6}t5j7j6} 8 }!t5j9j:}"t5j;}#t4| <dd }$t4| <dd }%t4| <dd }&t4| <dd }'dd j=D }(dd j>D })nFd }d } d }!d }"d }#d }$d }%d }&d }'ti }(ti })t t// | t?t||j&j'j(|
j@|
jA|| |!|"|#||$|%|&|'|||||(|)|d k	}*tB|* tjj	C  X W 5 Q R X d S )!Nr   )bisectBisectValidationExceptiontranslation_validation_enabledValidationExceptiong        c                    s>     t| |
	dzz8tjj"     W 5 Q R X W 5 Q R X W nb tj	k
r   
   Y nD tjtjfk
r    Y n( tk
r    r jj  Y nX W 5 j  X jd k	stjstj| d d < |j tjr:t|  t|  tt| | d d < d S )N)r   speculation_log)Zrestartr9   outputZcall_cleanup_hooksr   Ztracing_contextZset_current_txrunr   ZUnspecializeRestartAnalysisrg   ZSpeculationRestartAnalysis	SkipFrame	Exception	shape_envr{   Zoutput_instructionsupdatecode_optionsr   Zdead_code_eliminationr#   r    r   r   )Zinstructionsr  )r  r
  r   r   r   r   r   r  r	  mutated_closure_cell_contentsr   r  r  tracerr  rV   rW   	transform/  sL     
z_compile.<locals>.transformZentire_frame_compiler  )r   r   r   r  r  c                    s  t    }}dd }|d| j| j| j|  t D ]}|t _zt	| |}W  qW q2 t
jk
r }	 zHtdtt|	j |	jptt|	 t   }|dkrtd W 5 d }	~	X Y q2 t
jk
r }	 z2td|	| j| j| j |rtd W Y  d S d }	~	X Y q2X q2|d	| j| j| j| t D ]}
|
| |}|d k	r2|}q2| t|< t| ||  d k	sztd
d }|| }||}d}|d| jd |  d7 }|d|jd |  7 }| jd | |jd | kst|d}|d| j d7 }|d|j 7 }| j|jks*t|d}|d| j d7 }|d|j 7 }| j|jksft|j r|! r|d S j"d k	stj#t$j%|< t&|r|j'nd }t(||j)}! s|j*d k	r|*j" |S )Nc                 S   s&   t tjr"t t| |||| d S rP   )bytecode_logisEnabledForloggingDEBUGr   rA   )prefixr   filenameline_nor   rV   rV   rW   log_bytecodek  s    z5_compile.<locals>.compile_inner.<locals>.log_bytecodezORIGINAL BYTECODEzRestarting analysis due to %sd   z100+ RestartAnalysis() callsz.Skipping frame %s %s                     %s %sz%No graph captured with one_graph=TruezMODIFIED BYTECODEc                 S   s4   dd l }| j| j t| j|j@  t| j|j@  S )Nr   )inspectco_argcountco_kwonlyargcountr   co_flags
CO_VARARGSCO_VARKEYWORDS)r   r#  rV   rV   rW   
count_args  s    z3_compile.<locals>.compile_inner.<locals>.count_argszarg mismatch: zold code object has args z, znew code object has args zfree var mismatch: zold code object has free var znew code object has free var zcell var mismatch: zold code object has cell var znew code object has cell var )+r   r   r   r   	itertoolscountr   r   attemptr$   r   ZRestartAnalysisr   inforG   r   __traceback__rc   Zrestart_reasonr   r   r2   r  r   r  r   rH   r   r{   co_varnamesco_freevarsco_cellvarsr   Zis_empty_graphr}   Zcleanupsr=   instancer4   Zguard_fail_fnr6   check_fnZguard_export_fn)r   r   r   r  Zlast_attempt_start_time
start_timer!  r,  Zout_coder   r  Zhook_outputr)  Ztotal_argcount_oldZtotal_argcount_newmsgr3  guarded_code)dynamo_time_before_restartr  restart_reasonsrV   rW   compile_inner^  s    







z_compile.<locals>.compile_innerc                 S   s   d| j  d| j d| j dS )N'z' (:))r   r   r   )r   rV   rV   rW   format_func_info  s    z"_compile.<locals>.format_func_infoc                      s    sdS  d S )Nz$Unable to find recompilation reasonsrV   rV   )recompile_reasonsrV   rW   format_guard_failures  s    z'_compile.<locals>.format_guard_failuresztorch._dynamo hit config.%s (%s)
   function: %s
   last reason: %s
To log all recompilation reasons, use TORCH_LOGS="recompiles".
To diagnose recompilation issues, see %s.z reachedzBtorchdynamo start compiling %s %s:%s, stack (elided %s frames):
%s    r   Zdynamo_startc                      s   dt tjd  d iS )Nstack   r   )r   from_tracebackr   extractsummaryrV   r   rV   rW   r]   $  s
     z_compile.<locals>.<lambda>r   )
curr_frameZbackend_compileZinductor_compileZcode_genc                 S   s   h | ]
}|j qS rV   rj   r   oprV   rV   rW   	<setcomp>l  s     z_compile.<locals>.<setcomp>c                 S   s   h | ]
}|j qS rV   rI  rJ  rV   rV   rW   rL  m  s    r   )UZtorch.fx.experimental.validatorr  r  r  r  rR   r:   rs   _dynamoZcallback_handlerZrun_start_callbacksr   r@   r   r   CodeTyper   r7   r   r   r!   r   r   r   r   r6   r   r   r(   r5   r'   r   r   r   r   rL   r2   r   r   r   r   joinr   rF  formatr   r   r   r  Zlocal_scopeutilsrH  rB   lenr}   r  Zcount_callsgraphZnodesZplaceholdersr   non_compliant_opscompliant_custom_opsr>   r   r   rI   Zrun_end_callbacksr3   r0   r-   r{   r   r   r1   r   r   Zinnermost_user_frame_summaryr  linenor   r  r/   with_tracebackr.  ),r   r  r	  r
  r   r   r   r   r   r   r   r   r   r   r   r  r  r  r9  ZexceededZ
limit_typer=  r@  r4  Z	fail_typeZfail_reasonZfail_user_frame_filenameZfail_user_frame_linenor6  rH  Z	frame_keyZguard_countZshape_env_guard_countZgraph_op_countZgraph_node_countZgraph_input_countZentire_frame_compile_timeZbackend_compile_timeZinductor_compile_timeZcode_gen_timerT  rU  Zmetricsr   rV   )r  r
  r   r   r7  r   r   r   r  r	  r  r   r  r?  r8  r   r  r  r  rW   r   
  sN   *.  


   c                   @   s>   e Zd ZeedddZedd Zdej	ee
ddd	Zd
S )ConvertFramer   r   c                 C   s   || _ t|dd| _|| _d S )NF)r   )r   r   _inner_convert_hooks)rU   r   r   rV   rV   rW   rX     s    zConvertFrame.__init__c                    s    fddS )Nc                    s   t |  jS rP   )convert_framer[  r   rT   rV   rW   r]     r^   z2ConvertFrame._clone_with_backend.<locals>.<lambda>rV   rT   rV   rT   rW   r     s    z ConvertFrame._clone_with_backendr   r   c                 C   s6  t d d  d7  < z2| j|||||d d}t d d  d7  < |W S  tk
r0 } zt|trf t|t}t|trttj	rt
|drtt|j, |j}	dt|	}
tjd|
d	d
 W 5 Q R X tjs|s܂ t|dd }|j}t||||}|rtj|d	d
 ntj|d	d
 W 5 d }~X Y nX d S )Nframestotalr   r   okr   rB  z(Graph break: skip: from user code at:
%sT)exc_infor   )r?   rZ  r  r   r1   r3   graph_break_logr  r  r  r   r   r   r   Z
real_stackrO  	tracebackformat_listr   r   Zsuppress_errorsr   r   r.   r   r-  r   )rU   r   r   r   r   r   rp   r   Z	soft_failZ
user_stackZuser_stack_formattedr   r   	error_msgrV   rV   rW   r     sL        



 zConvertFrame.__call__N)r   )rh   ri   rj   r   r7   rX   r   r   r   r   r   r   rV   rV   rV   rW   rX    s   
	 rX  rY  c                 C   s
   t | |S )zHTry to convert a frame into an FX graph, if error leave frame unmodified)rX  rY  rV   rV   rW   r\    s    r\  c                 C   s   ddl m} tj}dt_t| d}t|}W 5 Q R X tt	|j
 t
  |_
z4t|j|j
|j|j|ddd t tddd i d W 5 |t_X d S )Nr   )eagerFrbr   )r   r   r   r   r   r   r   r   )Zbackends.debuggingre  r   Zreplay_record_enabledopenr8   loadr   r*  chainr  itemsr   r   r	  r
  r7   r%   )r  re  Zoriginal_replay_valin_filerecordrV   rV   rW   replay  s,    
rm  c                 C   sB   t jdk rdS t| D ]}|jdkr|jd   S qtdd S )N)      r   RESUMErA  z$RESUME instruction not found in code)sysversion_infodisget_instructionsopnameoffsetRuntimeError)r   instrV   rV   rW   first_real_inst_idx  s    

ry  c                   @   s   e Zd Zdd Zdd ZdS )CatchErrorsWrapperc                 C   s   t ||  || _|| _d S rP   )r   r   r   r   )rU   callbackr   rV   rV   rW   rX   !  s    zCatchErrorsWrapper.__init__c           
      C   sr  |d k	st t|j}|jt|jks2|s2tjrt	t
jr~|jt|jkrRdnt|jrbdnd}td|jj||jj d S |jjdkr|jjdkrd S t dkr"t }|r"t^ dd	lm} ||j| jjd
}t| jdst d| j|j}	|	||| j|W  5 Q R  S Q R X tB t 0 | j||| j|ddW  5 Q R  W  5 Q R  S Q R X W 5 Q R X d S )Nztraced frame alreadyzin skipfileszdynamo tracing is disabledz#skipping: %s (reason: %s, file: %s)r   __new__ddp_optimizerr   )DDPOptimizer)bucket_bytes_capZbackend_compile_fnr   zJDDPOptimizer only supports callback fns that know how to clone themselves.r   r   )r{   r   rz   r   f_lastiry  r   r   r   r  r  r  r   r   r   Z_get_optimize_ddp_moder   Z_get_active_ddp_modulecompile_lockZ"torch._dynamo.backends.distributedr~  r  r   r   r   Z
compile_fnr   r   )
rU   r   r   r   Zis_skipfileskip_reasonZ
ddp_moduler~  r}  Zhijacked_callbackrV   rV   rW   r   &  sr    
	        zCatchErrorsWrapper.__call__N)rh   ri   rj   rX   r   rV   rV   rV   rW   rz     s   rz  )r   c                 C   s
   t | |S rP   )rz  )r{  r   rV   rV   rW   catch_errors_wrappera  s    r  )NF)TFN)NNN)collectionsr   rs  r   r*  r  r   r   ru   r   rq  	threadingr   rb  r   typingr`   pathlibr   r   r   r   r   r   r   Ztorch._utils_internalr	   Ztorch.fx._lazy_graph_moduler
   Ztorch.utils._tracebackr   numpyr   ModuleNotFoundErrorrs   Ztorch._loggingZtorch._guardsr   r   r   r   r   r   r   Z%torch.fx.experimental.symbolic_shapesr   r   Ztorch.fx.graph_moduler   rl   Ztorch.nn.parallel.distributedr   Ztorch.utils._python_dispatchr   r   rB  r   r   r   Zbackends.registryr   Zbytecode_analysisr   r   Zbytecode_transformationr    r!   r"   r#   r$   r   r%   r&   r'   r(   Z
eval_framer)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r}   r4   r5   r6   r   r7   Zreplay_recordr8   Zsymbolic_convertr9   r:   r;   r<   rQ  r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   	getLoggerrh   r   r   ZgetArtifactLoggerr  ra  rt   rM  rr   RLockr  rO   r   r   rk   __annotations__r   rq   r   Z#suppress_torch_distributed_warningsr   r   r   Counterr   r   r   r   r   r   r   r   Ztorch.utils.hooksr   TYPE_CHECKINGZoutput_graphr  r  r  Zuse_lazy_graph_modulerN  r   objectr   r   rX  r\  rm  ry  rz  r  rV   rV   rV   rW   <module>   s     
(
L

4
N

@    

   


   U	A