ó
    Eñi[  ã                   óÖ  • S r SSKrSSKrSSKrSSKJrJr  SSKJr  SSK	J
r
JrJrJr  SSKrSSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJrJrJr  \(       a  SSK J!r!  \RD                  " \#5      r$\S\RJ                  RL                  S\'\RP                     S\
S\S\
4   4S j5       r)S\RT                  RV                  S\S\
4   4S jr,S\\RT                  RV                     S\S\
4   4S jr-\S\RJ                  RL                  S\'\RP                     S\
S\S\
4   4S j5       r.\S\RJ                  RL                  S\'\RP                     S\
S\RJ                  RL                  4S j5       r/\S\RJ                  RL                  S\'\RP                     S\
S\S\
4   4S j5       r0\" SS9S\RJ                  RL                  S\'\RP                     S\Rb                  Rd                  4S j5       r3S\RJ                  RL                  S \'\RP                     S\S\
4   4S! jr4 \S\RJ                  RL                  S\'\RP                     S\
S\S\
4   4S" j5       r5S#\RJ                  RL                  S \'\RP                     S\S\
4   4S$ jr6S#\RJ                  RL                  S \'\RP                     S\RT                  RV                  S\S\
4   4S% jr7 SNS#\RJ                  RL                  S \'\RP                     S&\\\Rp                  Rr                  /\:4      S\S\
4   4S' jjr;S(\Rp                  Rr                  S\:4S) jr<S\\RJ                  RL                  \'\RP                     /\S\
4   4   4S* jr=  SOS\RJ                  RL                  S\'\RP                     S+\\S\
4      S,\\S\
4      S\
S\S\
4   4S- jjr>\" S.\>S/9  \" \6S0S19r?\" S2\?S/9  S\RJ                  RL                  S\'\RP                     S\
S\S\
4   4S3 jr@\" S4\@S/9  S\RJ                  RL                  S\'\RP                     S\
S5\
S\S\
4   4
S6 jrA\" S7\AS/9  S\RJ                  RL                  S\'\RP                     S\
S\S\
4   4S8 jrB\" S9\BS/9  \" \S:9rC\" S;\CS/9   " S< S=\D5      rE " S> S?\D5      rF\S\RJ                  RL                  S \'\RP                     S\RJ                  RL                  4S@ j5       rG\S\RJ                  RL                  S \'\RP                     S\RJ                  RL                  4SA j5       rH\S\RJ                  RL                  S \'\RP                     S\RJ                  RL                  4SB j5       rI\S\RJ                  RL                  S \'\RP                     S\RJ                  RL                  4SC j5       rJ\R–                   " SD SE5      5       rLS\RJ                  RL                  SF\'\RJ                  RL                     SG\MSH\'\'SI      SJ\'\   S\N\RJ                  RL                  \'\RJ                  RL                     \M\'\'SI      \'\   4   4SK jrO " SL SM5      rPg)PaD  
This module provides debugging backends for TorchDynamo to help diagnose and troubleshoot
compilation and execution issues. It includes:

Key Debugging Backends:
- eager: Simple pass-through backend that runs models in eager mode
- eager_noexcept: Similar to eager but with additional exception handling
- eager_debug: Adds schema validation checks for custom operators
- aot_eager: Uses AOT Autograd with nop compiler for debugging
- aot_eager_decomp_partition: Uses TorchInductor decompositions for debugging
- torchscript: Compiles using TorchScript for debugging JIT-related issues

Testing and Development Tools:
- Backends for inducing specific errors (compile/runtime/accuracy)
- ExplainOutput class for detailed graph compilation analysis
- Utilities for cross-referencing and mode management
- Tools for graph detail inspection and break reason analysis

These backends are primarily used for:
1. Debugging graph breaks and compilation failures
2. Testing error handling and recovery mechanisms
3. Analyzing performance bottlenecks
4. Validating operator schemas and decompositions
é    N)ÚCallableÚIterable)Úimport_module)ÚAnyÚOptionalÚTYPE_CHECKINGÚUnion)Ú#min_cut_rematerialization_partition)Ú_guards)ÚGraphCompileReason)Úconfig)Ú
ts_compileé   )Úaot_autograd)Ú
CompiledFnÚ
CompilerFnÚregister_debug_backend)ÚTargetÚgmÚfake_tensor_inputsÚkwargsÚreturn.c                 óÂ   • U(       a  [         R                  SU5        [        R                  R                  R
                  (       a  SSKJn  U" U 5      $ U R                  $ )Nz&eager backend ignoring extra kwargs %sr   )ÚGraphModuleSerializableCallable)	ÚlogÚwarningÚtorchÚ
_functorchr   Úforce_autograd_cacheÚtorch._dynamo.aot_compile_typesr   Úforward)r   r   r   r   s       Ú]/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/_dynamo/backends/debugging.pyÚeagerr#   3   sC   € ö Ü�‰Ð<¸fÔEä×Ñ×Ñ×3×3ÝSá.¨rÓ2Ð2Ø�:‰:Ðó    Úmodec                 ó   • [        U /5      $ ©N)Ú,make_eager_backend_with_torch_function_modes©r%   s    r"   Ú+make_eager_backend_with_torch_function_moder*   A   s   € ô 8¸¸Ó?Ð?r$   Úmodesc           
      ó´   ^ ^• SSK Jm  S[        R                  R                  S[
        [        R                     S[        S[        S[        4   4UU 4S jjnU$ )	zßUsed to trace HOPs (cond and while) for eager execution, the metadata
TF mode mutates vars outside of the scope of the HOP, and we can't have graph breaks
in the HOP, so we need to externally run this mode and not trace it.r   )Ú	ExitStackr   r   r   r   .c                 óB   >^ • S[         S[         S[         4UU U4S jjnU$ )NÚargsr   r   c                  ó    >• T" 5        nT H  nUR                  U5        M     TR                  " U 0 UD6sS S S 5        $ ! , (       d  f       g = fr'   )Úenter_contextr!   )r/   r   Ústackr%   r-   r   r+   s       €€€r"   ÚwrapperÚImake_eager_backend_with_torch_function_modes.<locals>.fn.<locals>.wrapperR   s=   ø€ Ù” Û!�DØ×'Ñ'¨Ö-ñ "à—z’z 4Ð2¨6Ñ2÷ ——úó	   ‰,?¿
A)r   )r   r   r   r3   r-   r+   s   `   €€r"   ÚfnÚ8make_eager_backend_with_torch_function_modes.<locals>.fnO   s)   ù€ ð	3œ3ð 	3¬#ð 	3´#÷ 	3ñ 	3ð ˆr$   )	Ú
contextlibr-   r   ÚfxÚGraphModuleÚlistÚTensorr   r   )r+   r6   r-   s   ` @r"   r(   r(   G   sU   ù€ õ %ð	Ü�H‰H× Ñ ð	Ü6:¼5¿<¹<Ñ6Hð	ÜTWð	ä	�#”s�(Ñ	÷	ð 	ð €Ir$   c                 ój   ^ • U(       a  [         R                  SU5        S[        S[        4U 4S jjnU$ )Nz/eager_noexcept backend ignoring extra kwargs %sr/   r   c                  óˆ   >•  T" U 6 $ ! [          a/  n[        R                  R                  R	                  S5      UeS nAff = f)Nz7Unexpected exception when running generated GraphModule)Ú	Exceptionr   Ú_dynamoÚexcÚTorchDynamoException)r/   Úer   s     €r"   ÚinnerÚeager_noexcept.<locals>.innerf   sE   ø€ ð	Ù�t�9ÐøÜó 	Ü—-‘-×#Ñ#×8Ñ8ØIóàðûð	ús   ƒ ˆ
A’*<¼A)r   r   r   )r   r   r   rD   s   `   r"   Úeager_noexceptrF   ]   s1   ø€ ö Ü�‰ÐEÀvÔNð”Sð œS÷ ð €Lr$   c                 óª   ^ • U(       a  [         R                  SU5        SSKJn  S[        S[        4U 4S jjnU" USS9" U6 nUR                  5         U$ )	Nz3pre_dispatch_eager backend ignoring extra kwargs %sr   )Úmake_fxr/   r   c                  ó\   >• [         R                  R                  T5      R                  " U 6 $ r'   ©r   r9   ÚInterpreterÚrun)r/   r   s    €r"   Úrunnable_gmÚ'pre_dispatch_eager.<locals>.runnable_gmz   s#   ø€ Ü�x‰x×#Ñ# BÓ'×+Ò+¨TÐ2Ð2r$   T)Úpre_dispatch)r   r   Ú"torch.fx.experimental.proxy_tensorrH   r   Úprint_readable)r   r   r   rH   rM   Úpre_dispatch_gms   `     r"   Úpre_dispatch_eagerrS   q   sS   ø€ ö Ü�‰ÐIÈ6ÔRå:ð3œ3ð 3¤3÷ 3ñ ˜k¸Ò=Ð?QÐR€OØ×"Ñ"Ô$àÐr$   c                 óz   ^ ^• U(       a  [         R                  SU5        SSKJm  S[        S[        4UU 4S jjnU$ )Nz,eager_debug backend ignoring extra kwargs %sr   )ÚSchemaCheckModer/   r   c                  ó    >• T" 5          [         R                  R                  T5      R                  " U 6 sS S S 5        $ ! , (       d  f       g = fr'   rJ   )r/   rU   r   s    €€r"   rD   Úeager_debug.<locals>.inner�   s2   ø€ ÙÕÜ—8‘8×'Ñ'¨Ó+×/Ò/°Ð6÷ ××úr5   )r   r   Ú#torch._subclasses.schema_check_moderU   r   )r   r   r   rD   rU   s   `   @r"   Úeager_debugrY   ƒ   s9   ù€ ö Ü�‰ÐBÀFÔKåCð
7”Sð 7œS÷ 7ð 7ð €Lr$   Úts)Únamec                 ó@   • [         R                  R                  U 5      $ r'   )r   ÚjitÚscript)r   r   s     r"   Útorchscriptr_   –   s   € ô �9‰9×Ñ˜BÓÐr$   ÚsubgraphÚexample_inputsc                 óÖ   ^ ^^• SSK Jn  SSKJm  U[        R
                  R                  S[        S[        4UU 4S jj5       5       mS[        [           S[        4U4S jjnS	Ul	        U$ )
zðInner compiler that wraps forward/backward graphs in invoke_subgraph HOP.

This is used as the fw_compiler/bw_compiler for aot_autograd. When the resulting
function is traced by make_fx, it emits an invoke_subgraph HOP instead of inlining.
r   )Údisable)Úinvoke_subgraph_inferÚoperandsr   c                  ó   >• T" T/U Q76 $ r'   © )re   rd   r`   s    €€r"   Úinvoke_subgraph_wrapper_unboxedÚGinvoke_subgraph_inner_compiler.<locals>.invoke_subgraph_wrapper_unboxed¨   s   ø€ ñ % XÐ9°Ò9Ð9r$   r/   c                 ó   >• T" U 6 $ r'   rg   )r/   rh   s    €r"   Úinvoke_subgraph_wrapperÚ?invoke_subgraph_inner_compiler.<locals>.invoke_subgraph_wrapper¯   s   ø€ Ù.°Ð5Ð5r$   T)
Útorch._dynamorc   Ú'torch._higher_order_ops.invoke_subgraphrd   r   r@   Úallow_in_graphr   r;   Ú_boxed_call)r`   ra   rc   rk   rd   rh   s   `   @@r"   Úinvoke_subgraph_inner_compilerrq   �   se   ú€ õ &ÝMàÜ
‡]�]×!Ñ!ð:´3ð :¼3÷ :ó "ó ð:ð
6¤d¬3¡ið 6´C÷ 6ð +/ÐÔ'à"Ð"r$   c                 óx   • U(       a  [         R                  SU5        [        [        [        [        SS9" X5      $ )aø  Backend that wraps forward/backward graphs in invoke_subgraph HOP when traced by make_fx.

This backend uses AOTAutograd to partition into forward/backward graphs, then wraps
each in an invoke_subgraph HOP. This is useful for recursive Dynamo tracing scenarios
where you want the compiled subgraph to appear as invoke_subgraph HOPs in the outer
trace rather than being inlined.

Requires:
- torch._dynamo.config.force_compile_during_fx_trace = True
  (this implicitly overrides error_on_nested_fx_trace)
z0invoke_subgraph backend ignoring extra kwargs %sT©Úfw_compilerÚbw_compilerÚpartition_fnÚkeep_inference_input_mutations)r   r   r   rq   r
   )r   r   r   s      r"   Úinvoke_subgraphrx   ì   s;   € ö Ü�‰ÐFÈÔOô Ü2Ü2Ü8Ø'+ò	ð
 	óð r$   Úfx_gc                 óÆ   ^ ^• SSK Jn  T R                  R                  U" 5       5        T R	                  5         T R
                  mS[        S[        4UU 4S jjnSUl        U$ )Nr   ©Ú_BoxedCodeGenr/   r   c                 ó„   >• SSK JnJn  U" 5       =n b%  UR                  (       a  U" TSS9R                  " U 6 $ T" U 5      $ )Nr   )ÚDebugInterpreterÚget_active_debug_modeÚ	aot_eager)Úbackend)Útorch.utils._debug_moder~   r   Úrun_compile_with_interpreterrL   )r/   r~   r   Ú
debug_modeÚ
forward_fnry   s       €€r"   rL   Úboxed_nop.<locals>.run  sG   ø€ ßSñ 0Ó1Ð1ˆJØñà$×A×AÙ# D°+Ñ>×BÒBÀDÐIÐIÙ˜$ÓÐr$   T©Útorch.fx.graphr|   ÚgraphÚset_codegenÚ	recompiler!   r   rp   )ry   ra   r|   rL   r…   s   `   @r"   Ú	boxed_noprŒ     sY   ù€ õ -ð 	‡J�J×Ñ™=›?Ô+Ø‡N�NÔð —‘€Jð ”#ð  œ#÷  ð  ð €C„OØ€Jr$   c                óÆ   ^^• SSK Jn  U R                  R                  U" 5       5        U R	                  5         U R
                  mS[        S[        4UU4S jjnSUl        U$ )Nr   r{   r/   r   c                 óN   >• T   T" U 5      sS S S 5        $ ! , (       d  f       g = fr'   rg   )r/   r…   r%   s    €€r"   rL   Ú boxed_nop_with_mode.<locals>.run0  s   ø€ ÚÙ˜dÓ#÷ �T�Tús   „–
$Tr‡   )ry   ra   r%   r|   rL   r…   s     `  @r"   Úboxed_nop_with_moder�   !  sY   ù€ õ -ð 	‡J�J×Ñ™=›?Ô+Ø‡N�NÔð —‘€Jð$”#ð $œ#÷ $ð $ð €C„OØ€Jr$   Úignore_op_fnc                 óÆ   ^^• SSK Jn  U R                  R                  U" 5       5        U R	                  5         U R
                  mS[        S[        4UU4S jjnSUl        U$ )Nr   r{   r/   r   c                 óˆ   >• [         R                  R                  T5         T" U 5      sS S S 5        $ ! , (       d  f       g = fr'   )r   Ú_subclassesÚCrossRefFakeMode)r/   r…   r‘   s    €€r"   rL   Ú$fake_crossref_boxed_nop.<locals>.runF  s+   ø€ Ü×Ñ×/Ñ/°Õ=Ù˜dÓ#÷ >×=×=ús	   ¡3³
ATr‡   )ry   ra   r‘   r|   rL   r…   s     `  @r"   Úfake_crossref_boxed_nopr—   8  sY   ù€ õ
 -ð 	‡J�J×Ñ™=›?Ô+Ø‡N�NÔð —‘€Jð$”#ð $œ#÷ $ð $ð €C„OØ€Jr$   Úopc                 ó    • U R                   S;   $ )N)ÚatenÚprimsÚprim)Ú	namespace)r˜   s    r"   Úignore_builtinsrž   N  s   € Ø�<‰<Ð4Ñ4Ð4r$   c                  óJ  • [         R                  R                  R                  (       d  [        $ [         R                  R                  R                  S:X  a  [
        $ [         R                  R                  R                  S:X  d   e[        R                  " [
        [        S9$ )NÚallÚ
custom_ops)r‘   )	r   r   r   Úfake_tensor_crossrefrŒ   r—   Ú	functoolsÚpartialrž   rg   r$   r"   Úget_nop_funcr¥   R  ss   € ô ×Ñ×"Ñ"×7×7ÜÐÜ	×	Ñ	×	 Ñ	 ×	5Ñ	5¸Ó	>Ü&Ð&ä×Ñ×&Ñ&×;Ñ;¸|ÓKÐKÐKÜ× Ò Ô!8ÄÑWÐWr$   rt   ru   c                 ód   • [        U=(       d    [        U=(       d    [        [        SS9" X40 UD6$ )NTrs   )r   rŒ   r
   )r   r   rt   ru   r   s        r"   r€   r€   `  s;   € ô Ø×,¤9Ø×,¤9Ü8Ø'+ò	ð
 	ñ(ð
 !'ñ(ð (r$   r€   )r[   Úcompiler_fnT)rt   rw   Úaot_eager_default_partitionerc                 óx  • U(       a  [         R                  SU5        SSKJn  SS0nUR	                  S5      =n(       a  UR                  U5        [        R                  " U5         [        [        5       [        5       S [        R                  " [        SS	9S
9" X5      sS S S 5        $ ! , (       d  f       g = f)Nz;aot_eager_decomp_partition backend ignoring extra kwargs %sr   )ÚCompilerBisectorÚunlift_effect_tokensTÚaot_eager_decomp_partitionc                  ó4   • [        S5      R                  5       $ ©Nztorch._inductor.compile_fx©r   Úselect_decomp_tablerg   r$   r"   Ú<lambda>Ú,aot_eager_decomp_partition.<locals>.<lambda>“  s   € ¤=Ø,ó$ç!Ñ!Ó#ð$$r$   Úinductor©Úcompiler©rt   ru   Údecompositionsrv   )r   r   Ú!torch._inductor.compiler_bisectorrª   Úget_config_changeÚupdateÚfunctorch_configÚpatchr   r¥   r£   r¤   r
   )r   r   r   rª   Úconfig_patchesÚbisect_changess         r"   r¬   r¬   }  s¥   € ö Ü�‰ØIÈ6ô	
õ Cà,¨dÐ3€NØ)×;Ñ;Ø$óð €~õ ð 	×Ñ˜nÔ-ä	×	Ò	 Õ	/Üä$›Ü$›ñ$ô #×*Ò*Ü3¸jñò
ð ó"÷ 
0×	/×	/ús   Á':B+Â+
B9r¬   Úkwargc           
      ó²   • [        [        R                  " [        US9[        R                  " [        US9S [        R                  " [        SS9S9" X5      $ )Nr)   c                  ó4   • [        S5      R                  5       $ r®   r¯   rg   r$   r"   r±   Ú6aot_eager_decomp_partition_with_mode.<locals>.<lambda>®  s   € œ}Ø(ó 
ç
Ñ
Ó
ð  r$   r³   r´   r¶   )r   r£   r¤   r�   r
   )r   r   r%   r¿   s       r"   Ú$aot_eager_decomp_partition_with_moderÃ   £  sW   € ô ä×%Ò%Ô&9ÀÑEÜ×%Ò%Ô&9ÀÑEñ ô ×&Ò&Ü/¸*ñ
òð 	óð r$   rÃ   c                 óÆ   • [         R                  (       d  SO[         R                  n[         R                  " US9   [        X40 UD6sS S S 5        $ ! , (       d  f       g = f)Nr¡   )r¢   )r»   r¢   r¼   r¬   )r   r   r   Ú
config_vals       r"   Ú#aot_eager_decomp_partition_crossrefrÆ   ½  sJ   € ô  ×4×4ñ 	ä×2Ñ2ð ô
 
×	Ò	°ZÓ	@Ü)¨"ÑKÀFÑK÷ 
A×	@×	@ús   ¼AÁ
A rÆ   )rt   Úaot_tsc                   ó   • \ rS rSrSrg)ÚReluCompileErroriÜ  rg   N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__rg   r$   r"   rÉ   rÉ   Ü  ó   † Úr$   rÉ   c                   ó   • \ rS rSrSrg)ÚTestingOnlyCompileErrorià  rg   NrÊ   rg   r$   r"   rÒ   rÒ   à  rÐ   r$   rÒ   c                 ó†   • U R                   R                   H&  nUR                  [        R                  L d  M"  [
        e   U $ r'   )r‰   ÚnodesÚtargetr   ÚrelurÉ   ©r   ra   Únodes      r"   Úrelu_compile_error_TESTING_ONLYrÙ   ä  s3   € ð —‘—”ˆØ�;‰;œ%Ÿ*™*Ô$Ü"Ð"ñ ð €Ir$   c                 óÖ   • U R                   R                   H>  nUR                  [        R                  L d  M"  [        R
                  Ul        SUl        M@     U R                  5         U $ )N)FÚReluRuntimeError)r‰   rÔ   rÕ   r   rÖ   Ú_assertr/   r‹   r×   s      r"   Úrelu_runtime_error_TESTING_ONLYrÝ   î  sH   € ð —‘—”ˆØ�;‰;œ%Ÿ*™*Ô$ÜŸ-™-ˆDŒKØ3ˆDŽIñ ð ‡L�L„NØ€Ir$   c                 óô   • U R                   R                   HM  nUR                  [        R                  L d  M"  [        R
                  Ul        UR                  S   S4Ul        MO     U R                  5         U $ )Nr   r   )r‰   rÔ   rÕ   r   rÖ   Úaddr/   r‹   r×   s      r"   Ú relu_accuracy_error_TESTING_ONLYrà   ú  sU   € ð —‘—”ˆØ�;‰;œ%Ÿ*™*Ô$ÜŸ)™)ˆDŒKØŸ™ 1™ qÐ)ˆDŽIñ ð ‡L�L„Nà€Ir$   c                 ó¨   • U R                   R                   H  nUR                  S:X  d  M    O   U $ U H  nUR                  (       a  M  [        e   U $ )NÚcall_function)r‰   rÔ   r˜   Úis_leafrÒ   )r   ra   rØ   Úts       r"   Ú#non_leaf_compile_error_TESTING_ONLYrå     sL   € ð —‘—”ˆØ�7‰7�oÕ%Ùñ ð ˆ	ÛˆØ�y�y‰yÜ)Ð)ñ ð €Ir$   c                   óð   • \ rS rSr% Sr\\R                  R                     \	S'   \
\	S'   \
\	S'   \\   \	S'   \
\	S'   Sr\\\S	         \	S
'   Sr\\\R                         \	S'   Sr\\   \	S'   S\4S jrSrg)ÚExplainOutputi  zi
This is the output of :func:`torch._dynamo.explain()`
There is no reason to create this class directly.
ÚgraphsÚgraph_countÚgraph_break_countÚbreak_reasonsÚop_countNr   Úops_per_graphÚ
out_guardsÚcompile_timesr   c                 ó®  • SU R                    S3nUSU R                   S3-  nUSU R                   S3-  nUS-  n[        U R                  5       HE  u  p#USUS-    S3-  nUS	UR
                   S3-  nUS
-  nUR                   H  nUSU S3-  nM     MG     U R                  bA  US-  n[        U R                  5       H#  u  p%USUS-    S3-  nU H  nUSU S3-  nM     M%     U R                  b@  US-  n[        U R                  5       H"  u  pxUSUS-    S3-  nUS[        U5       3-  nM$     U R                  b  USU R                   S3-  nU$ )NzGraph Count: Ú
zGraph Break Count: z
Op Count: zBreak Reasons:
z  Break Reason r   z:
z    Reason: z    User Stack:
z      zOps per Graph:
z  Ops z    zOut Guards:
z  Guard zCompile Times: )ré   rê   rì   Ú	enumeraterë   ÚreasonÚ
user_stackrí   rî   Ústrrï   )	ÚselfÚoutputÚidxÚbreak_reasonÚframe_summaryÚopsr˜   ÚiÚguards	            r"   Ú__str__ÚExplainOutput.__str__(  s²  € Ø  ×!1Ñ!1Ð 2°"Ð5ˆØÐ'¨×(>Ñ(>Ð'?¸rÐBÑBˆØ�J˜tŸ}™}˜o¨RÐ0Ñ0ˆàÐ$Ñ$ˆÜ!*¨4×+=Ñ+=Ö!>ÑˆCØ˜¨¨a© y°Ð4Ñ4ˆFØ˜ \×%8Ñ%8Ð$9¸Ð<Ñ<ˆFØÐ)Ñ)ˆFØ!-×!8Ô!8�Ø˜F = /°Ð4Ñ4’ó "9ñ	 "?ð ×ÑÑ)ØÐ(Ñ(ˆFÜ% d×&8Ñ&8Ö9‘�Ø˜F 3¨¡7 )¨3Ð/Ñ/�Û�BØ  R D¨˜mÑ+’Fó ñ :ð
 �?‰?Ñ&Ø�oÑ%ˆFÜ% d§o¡oÖ6‘�Ø˜H Q¨¡U G¨3Ð/Ñ/�Ø˜D¤ U£ Ð-Ñ-’ñ 7ð ×ÑÑ)Ø˜¨×(:Ñ(:Ð';¸2Ð>Ñ>ˆFØˆr$   rg   )rË   rÌ   rÍ   rÎ   Ú__doc__r;   r   r9   r:   Ú__annotations__Úintr   rí   r   rî   r   ÚGuardrï   rõ   rþ   rÏ   rg   r$   r"   rç   rç     s…   ‡ ñð
 �—‘×%Ñ%Ñ&Ó&ØÓØÓØÐ*Ñ+Ó+ØƒMØ48€M�8˜D  h¡Ñ0Ñ1Ó8Ø04€J�˜˜gŸm™mÑ,Ñ-Ó4Ø#'€M�8˜C‘=Ó'ð˜÷ r$   rç   rè   rì   rí   r   rë   c                 ód  • UR                  U 5        U R                  R                   Vs/ s H   oUR                  S:X  d  M  UR                  PM"     nnU[        U5      -  nUR                  U5        U R                  R                  (       a  UR                  U R                  5        XX#U4$ s  snf )ap  
This function is a utility which processes a torch.fx.GraphModule and
accumulates information about its ops, graph breaks, and other details. It
is intended to be used by the ExplainWithBackend class and
`torch._dynamo.explain()` to provide details from Dynamo's graph capture.

Parameters:
    gm (torch.fx.GraphModule): The GraphModule to be processed.
    graphs (list): A list that accumulates all the GraphModules processed.
    op_count (int): The total count of operations in all GraphModules processed so far.
    ops_per_graph (list): A list that accumulates the operations of each GraphModule.
    break_reasons (list): A list that accumulates the reasons for breaks in each GraphModule.

Returns:
    tuple: A tuple containing the processed GraphModule, the updated lists of graphs,
           operations per graph, and break reasons, and the updated operation count.
râ   )Úappendr‰   rÔ   r˜   rÕ   ÚlenÚcompile_subgraph_reasonÚgraph_break)r   rè   rì   rí   rë   rØ   rû   s          r"   Ú_explain_graph_detailr	  G  s�   € ð< ‡M�M�"ÔØ#%§8¡8§>¢>Ó
P¢>˜4·W±WÀÑ5O‹;ˆ4�;Œ;¡>€CÐ
PØ”�C“Ñ€HØ×Ñ˜ÔØ	×!Ñ!×-×-Ø×Ñ˜R×7Ñ7Ô8à�x°Ð=Ð=ùò Qs   ªB-ÁB-c                   óš   • \ rS rSrSrS\\\4   SS4S jrS\	R                  R                  S\\	R                     S\4S	 jrS\4S
 jrSrg)ÚExplainWithBackendio  a3  
This class is intended to be used as a backend for `torch.compile`. It is
composable with other backends. When used in this way, it accumulates
information about graph breaks, ops, and other info and provides a string
representation summarizing this information.

Attributes:
    backend (str): The name of the backend to use for optimization.
    graphs (list): A list of the graphs captured by TorchDynamo.
    op_count (int): The total number of operations in all optimized graphs.
    break_reasons (list): A list of graph break reasons with stack traces.

Example Usage:
    def fn(x):
        x = torch.sigmoid(x)
        return x

    torch._dynamo.reset()
    eb = ExplainWithBackend("inductor")
    optimized_fn = torch.compile(fn, backend=eb)
    result = optimized_fn(torch.randn(5))
    print(eb.output())
r�   r   Nc                 óT   • SSK Jn  U" U5      U l        / U l        SU l        / U l        g )Nr   )Úlookup_backendr   )Úregistryr  r�   rè   rì   rë   )rö   r�   r  s      r"   Ú__init__ÚExplainWithBackend.__init__ˆ  s'   € Ý,á% gÓ.ˆŒØ24ˆŒØˆŒØ79ˆÕr$   r   ra   c                 ó¤   • / n[        XR                  U R                  X0R                  5      u  ol        U l        o@l        U R	                  X5      $ r'   )r	  rè   rì   rë   r�   )rö   r   ra   rí   Ú_s        r"   Ú__call__ÚExplainWithBackend.__call__�  sH   € ð -/ˆÜ@UØ—‘˜TŸ]™]¨M×;MÑ;MóA
Ñ=ˆŒK˜œ¨Ô+=ð �|‰|˜BÓ/Ð/r$   c                 ó�   • [        U R                  5      n[        U R                  UUS-
  U R                  U R                  5      nU$ )Nr   )r  rè   rç   rë   rì   )rö   ré   r÷   s      r"   r÷   ÚExplainWithBackend.output™  sB   € Ü˜$Ÿ+™+Ó&ˆÜØ�K‰KØØ˜!‰OØ×ÑØ�M‰Mó
ˆð ˆr$   )r�   rë   rè   rì   )rË   rÌ   rÍ   rÎ   r   r	   r   rõ   r  r   r9   r:   r;   r<   r   r  rç   r÷   rÏ   rg   r$   r"   r  r  o  s_   † ñð0:  j°# oÑ 6ð :¸4ô :ð0Ø—(‘(×&Ñ&ð0Ø8<¸U¿\¹\Ñ8Jð0à	ô0ð
˜÷ 
r$   r  r'   )NN)Qr   Údataclassesr£   ÚloggingÚcollections.abcr   r   Ú	importlibr   Útypingr   r   r   r	   r   Úfunctorch.compiler
   r   Útorch._dynamo.output_graphr   Útorch._functorchr   r»   Útorch._functorch.compilersr   Úcommonr   r  r   r   r   Úregister_backendÚtorch.fx.noder   Ú	getLoggerrË   r   r9   r:   r;   r<   r#   Ú	overridesÚTorchFunctionModer*   r(   rF   rS   rY   r]   ÚScriptModuler_   rq   rx   rŒ   r�   Ú_opsÚ
OpOverloadÚboolr—   rž   r¥   r€   r¨   r¬   rÃ   rÆ   rÇ   r?   rÉ   rÒ   rÙ   rÝ   rà   rå   Ú	dataclassrç   r  Útupler	  r  rg   r$   r"   Ú<module>r,     sç  ðñó2 Û Û ß .Ý #ß 6Ó 6ã Ý AÝ Ý 9Ý 7Ý 1å  ß XÑ Xö Ý$ð ×Ò˜Ó!€ð ð
Ø�‰×Ñð
Ø26°u·|±|Ñ2Dð
ØPSð
àˆc�3ˆhÑó
ó ð
ð@Ø
�/‰/×
+Ñ
+ð@àˆc�3ˆhÑô@ðØ�E—O‘O×5Ñ5Ñ6ðàˆc�3ˆhÑôð, ðØ�‰×ÑðØ26°u·|±|Ñ2DðØPSðàˆc�3ˆhÑóó ðð& ðØ�‰×ÑðØ26°u·|±|Ñ2DðØPSðà
‡X�X×Ñóó ðð" ðØ�‰×ÑðØ26°u·|±|Ñ2DðØPSðàˆc�3ˆhÑóó ðñ$ �tÑð Ø�‰×Ñð Ø26°u·|±|Ñ2Dð à
‡Y�Y×Ñó ó ð ð#Ø�h‰h×"Ñ"ð#Ø48¸¿¹Ñ4Fð#àˆc�3ˆhÑô#ð:/ðd ðØ�‰×ÑðØ26°u·|±|Ñ2DðØPSðàˆc�3ˆhÑóó ðð6Ø
�(‰(×
Ñ
ðØ04°U·\±\Ñ0Bðàˆc�3ˆhÑôð2Ø
�(‰(×
Ñ
ðà˜Ÿ™Ñ&ðð �/‰/×
+Ñ
+ð	ð
 ˆc�3ˆhÑôð4 GKñØ
�(‰(×
Ñ
ðà˜Ÿ™Ñ&ðð ˜8 U§Z¡Z×%:Ñ%:Ð$;¸TÐ$AÑBÑCðð ˆc�3ˆhÑõ	ð,5˜Ÿ
™
×-Ñ-ð 5°$ô 5ð	X�hØ
‡X�X×Ñ˜4 §¡Ñ-Ð.°¸¸c¸Ñ0BÐBñô 	Xð" 15Ø04ñ	(Ø�‰×Ñð(à˜UŸ\™\Ñ*ð(ð ˜( 3¨ 8Ñ,Ñ-ð(ð ˜( 3¨ 8Ñ,Ñ-ð	(ð
 ð(ð ˆc�3ˆhÑõ(ñ �k¨yÒ 9á ,Ø¸$ñ!Ð ñ Ø	(Ð6Sòð"Ø�‰×Ñð"Ø26°u·|±|Ñ2Dð"ØPSð"àˆc�3ˆhÑô"ñ> Ø	%Ð3MòðØ�‰×Ñðà˜UŸ\™\Ñ*ðð ðð ð	ð
 ˆc�3ˆhÑôñ( Ø	/Ø4òðLØ�‰×ÑðLØ26°u·|±|Ñ2DðLØPSðLàˆc�3ˆhÑôLñ Ø	.Ø3òñ 
 *Ñ	-€Ù �h¨FÒ 3ô	�yô 	ô	˜iô 	ð ðØ�‰×ÑðØ.2°5·<±<Ñ.@ðà
‡X�X×Ñóó ðð ðØ�‰×ÑðØ.2°5·<±<Ñ.@ðà
‡X�X×Ñóó ðð ð	Ø�‰×Ñð	Ø.2°5·<±<Ñ.@ð	à
‡X�X×Ñó	ó ð	ð ðØ�‰×ÑðØ.2°5·<±<Ñ.@ðà
‡X�X×Ñóó ðð  ×Ñ÷+ð +ó ð+ð\%>Ø�‰×Ñð%>à�—‘×%Ñ%Ñ&ð%>ð ð%>ð ˜˜X™Ñ'ð	%>ð
 Ð*Ñ+ð%>ð Ø	‡H�H×ÑØˆ�‰×	Ñ	ÑØØˆˆh‰ÑØÐ	Ñð	ñô%>÷P4ò 4r$   