§
    ž²Åj›8  ã                   óš  — 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 d dl	m
Z
mZ d dlZd dlZd dlmZ d dlmZ d dlmc mZ d dlmZ d dlmZ d dlmZ dd	lmZmZmZ dd
lm Z  ddl!m"Z"m#Z#m$Z$  ej%        e&¦  «        Z'd„ Z(ed„ ¦   «         Z)edej*        de
fd„¦   «         Z+d"d„Z,d„ Z-edej*        de
fd„¦   «         Z. G d„ dej/        ¦  «        Z0edej*        de
fd„¦   «         Z1ed„ ¦   «         Z2d„ Z3ej4        j5        Z5e5j6        e5j7        e5j8        e5j9        e5j:        e5j;        e5j<        e5j=        e5j>        e5j?        e5j@        e5jA        e5jB        e5jC        jD        e5jC        jE        e5jF        e5jG        e5jH        e5jI        e5jJ        e5jK        e5jL        hZM eeM¦  «        ZMed„ ¦   «         ZNdee
ejO        f         fd„ZPd„ ZQd aRd„ ZSd„ ZTd#d!„ZUdS )$é    N)Úcontextmanager)Úpartial)ÚCallableÚUnion)ÚSymInt)Úget_decompositions)Úbind_symbolsé   )Úaot_functionÚ
aot_moduleÚmake_boxed_compiler)Ústrip_overloads)Údefault_partitionÚ
draw_graphÚ#min_cut_rematerialization_partitionc                 óÊ   — | j                              dt          j        j        j        ¬¦  «        D ]}t          j        j        j        |_        Œ|                      ¦   «          | S )NÚcall_function©ÚopÚtarget)	ÚgraphÚ
find_nodesÚtorchÚopsÚatenÚ_to_copyÚtor   Ú	recompile)Úfx_gÚnodes     úKC:\Projects\Historical\venv\Lib\site-packages\torch/_functorch/compilers.pyÚ_canonicalizer"   $   s[   € Ø”
×%Ò%Ø¥5¤9¤>Ô#:ð &ñ ô ð (ð (ˆõ ”i”nÔ'ˆŒˆØ‡N‚NÑÔÐØ€Kó    c               #   óØ   K  — t           j                             d¦  «        } 	 d V — t           j                             | ¦  «         d S # t           j                             | ¦  «         w xY w)NF)r   Ú_CÚ_jit_set_autocast_mode)Úold_jit_autocast_flags    r!   Ú_disable_jit_autocastr(   -   sd   è è € å!œH×;Ò;¸EÑBÔBÐð?ØˆˆˆåŒ×'Ò'Ð(=Ñ>Ô>Ð>Ð>Ð>ø�Œ×'Ò'Ð(=Ñ>Ô>Ð>Ð>øøøs   £A Á!A)r   Úreturnc                 óô  — t          ¦   «         5  t          | ¦  «         | j                             dt          j        j        j        ¬¦  «        D ]V}t          |j	        ¦  «        dk    r<t          |j
        ¦  «        dk    r$d|j
        v rt          j        j        j        |_        ŒW| j        j        D ]P}i }|j
                             ¦   «         D ]+\  }}t          |t          j        ¦  «        r|j        }|||<   Œ,||_
        ŒQ| j                             ¦   «          |                      ¦   «          t          j                             | ¦  «        }t          j                             |j        ¦  «         t          j                             |                     ¦   «         ¦  «        }t          j                             |¦  «        }t7          d„ |D ¦   «         ¦  «        s ||Ž  ddd¦  «         n# 1 swxY w Y   |S )a  
    Compiles the :attr:`fx_g` with Torchscript compiler.

    .. warning::
        This API is experimental and likely to change.

    Args:
        fx_g(fx.GraphModule): The input Fx graph module to be compiled.

    Returns:
        Torch scripted model.
    r   r   r
   Údtypec              3   óT   K  — | ]#}t          |t          j        j        ¦  «        V — Œ$d S ©N)Ú
isinstancer   Ú_subclassesÚ
FakeTensor)Ú.0Úts     r!   ú	<genexpr>zts_compile.<locals>.<genexpr>`   s2   è è € ÐMÐMÀ1•:˜a¥Ô!2Ô!=Ñ>Ô>ÐMÐMÐMÐMÐMÐMr#   N)r(   r   r   r   r   r   r   r   ÚlenÚargsÚkwargsr   r   ÚnodesÚitemsr.   ÚdeviceÚtypeÚlintr   ÚjitÚscriptr%   Ú_jit_pass_remove_mutationÚfreezeÚevalÚoptimize_for_inferenceÚany)r   Úinpsr    Ú
new_kwargsÚkÚvÚfs          r!   Ú
ts_compilerH   6   s  € õ 
Ñ	 Ô	 ð ð Ý˜ÑÔÐà”J×)Ò)Ø¥u¤y¤~Ô'>ð *ñ 
ô 
ð 	0ð 	0ˆDõ �4”9‰~Œ~ Ò"Ð"¥s¨4¬;Ñ'7Ô'7¸1Ò'<Ð'<ÀÈDÌKÐAWÐAWÝ#œiœnÔ/�”øà”JÔ$ð 	%ð 	%ˆDØˆJØœ×)Ò)Ñ+Ô+ð "ð "‘��1Ý˜a¥¤Ñ.Ô.ð Øœ�AØ !�
˜1‘�Ø$ˆDŒKˆKàŒ
�ŠÑÔÐà�ŠÑÔÐåŒI×Ò˜TÑ"Ô"ˆåŒ×*Ò*¨1¬7Ñ3Ô3Ð3åŒI×Ò˜QŸVšV™XœXÑ&Ô&ˆÝŒI×,Ò,¨QÑ/Ô/ˆÝÐMÐMÈÐMÑMÔMÑMÔMð 	ØˆAˆtˆHˆHð9ð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð: €Hs   �GG-Ç-G1Ç4G1Tc                 óR   — t          | j        ¦  «         t          | ||¬¦  «         | S )N)Ú
clear_meta)ÚprintÚcoder   )r   Ú_ÚnamerJ   s       r!   Ú_draw_graph_compilerO   e   s,   € Ý	ˆ$Œ)ÑÔÐÝˆt�T jÐ1Ñ1Ô1Ð1Ø€Kr#   c                 óH   — t          t          t          | ¬¦  «        ¦  «        S )N©rN   )r   r   rO   rQ   s    r!   Údraw_graph_compilerR   k   s   € Ý�wÕ':ÀÐFÑFÔFÑGÔGÐGr#   c                 ó   — | S )zÆ
    Returns the :attr:`fx_g` Fx graph module as it is. This is a no-op compiler
    and can be used to check accuracy.

    .. warning::
        This API is experimental and likely to change.

    © ©r   rM   s     r!   ÚnoprV   o   s	   € ð €Kr#   c                   ó(   ‡ — e Zd Zˆ fd„Zˆ fd„Zˆ xZS )ÚDebugInterpreterc                 ób   •— t          | j        g|¢R Ž | _         t          ¦   «         j        |Ž  d S r-   )r	   ÚmoduleÚsymbol_mappingÚsuperÚrun)Úselfr5   Ú	__class__s     €r!   r]   zDebugInterpreter.run}   s6   ø€ Ý*¨4¬;Ð>¸Ð>Ð>Ð>ˆÔØ�‰ŒŒ�TÐÐÐÐr#   c                 óP  •‡ ‡
‡‡‡— ˆ fd„Šˆfd„Šˆfd„Š
ˆ
ˆfd„}t          ¦   «                              |¦  «        }d|j        v ràt          j        |j        d         ¦  «        \  }}t          j        |¦  «        \  }}t          |¦  «        t          |¦  «        k    s)J t          |¦  «        › dt          |¦  «        › �¦   «         ‚t          t          t          |¦  «        ¦  «        ||¦  «        D ]2\  Š}}	t          |	t          j
        ¦  «        sŒ! |||	ˆˆ fd„¦  «         Œ3|S )Nc                 óÞ   •— t          | t          ¦  «        s| S t          j        | j        j                             ‰j        ¦  «        ¦  «        }|j        s
J |¦   «         ‚t          |¦  «        S r-   )
r.   r   ÚsympyÚexpandr    ÚexprÚxreplacer[   Ú	is_numberÚint)ÚniÚrr^   s     €r!   Úsubst_symintz/DebugInterpreter.run_node.<locals>.subst_symint‚   s^   ø€ Ý˜b¥&Ñ)Ô)ð Ø�	Ý”˜RœWœ\×2Ò2°4Ô3FÑGÔGÑHÔHˆAØ”;Ð!Ð! Ñ!Ô!�;Ý�q‘6”6ˆMr#   c                 ó:   •— t          ˆfd„| D ¦   «         ¦  «        S )Nc              3   ó.   •K  — | ]} ‰|¦  «        V — Œd S r-   rT   )r1   rh   rj   s     €r!   r3   zHDebugInterpreter.run_node.<locals>.subst_symint_tuple.<locals>.<genexpr>Š   s-   øè è € Ð8Ð8¨b˜˜ bÑ)Ô)Ð8Ð8Ð8Ð8Ð8Ð8r#   )Útuple)Únisrj   s    €r!   Úsubst_symint_tuplez5DebugInterpreter.run_node.<locals>.subst_symint_tuple‰   s&   ø€ ÝÐ8Ð8Ð8Ð8°CÐ8Ñ8Ô8Ñ8Ô8Ð8r#   c                 ó,  •—  ‰|                       ¦   «         ¦  «        dk    rqt          | j        ¦  «        D ]\} ‰|                      |¦  «        ¦  «        |                     |¦  «        k    r% ‰|                      |¦  «        ¦  «        dk    r dS Œ]dS )Nr   r
   FT)ÚnumelÚrangeÚndimÚstrideÚsize)ÚaÚbÚidxrj   s      €r!   Úcheck_significant_stridesz<DebugInterpreter.run_node.<locals>.check_significant_stridesŒ   sŒ   ø€ Øˆ|˜AŸGšG™IœIÑ&Ô&¨Ò*Ð*Ý  ¤™=œ=ð %ð %�Cà$˜ Q§X¢X¨c¡]¤]Ñ3Ô3°q·x²xÀ±}´}ÒDÐDØ(˜L¨¯ª°©¬Ñ5Ô5¸Ò9Ð9à$˜u˜uøØ�4r#   c           	      ó„  •— t          |¦  «        sJ ‚| j        |j        k    s$J  |¦   «         › d| j        › d|j        › �¦   «         ‚ ‰|                      ¦   «         ¦  «        |                     ¦   «         k    s\J  |¦   «         › d|                      ¦   «         › d ‰|                      ¦   «         ¦  «        › d|                     ¦   «         › �¦   «         ‚ ‰| |¦  «        }|s\J  |¦   «         › d|                      ¦   «         › d ‰|                      ¦   «         ¦  «        › d|                     ¦   «         › �¦   «         ‚d S )Nz: ú != z aka )Úcallabler+   ru   rt   )ÚnvÚrvÚdescÚsame_stridesry   ro   s       €€r!   Úcheckz(DebugInterpreter.run_node.<locals>.check–   s\  ø€ Ý˜D‘>”>Ð!Ð!�>Ø”8˜rœxÒ'Ð'Ð'¨D¨D©F¬FÐ)NÐ)N°b´hÐ)NÐ)NÀBÄHÐ)NÐ)NÑ'Ô'Ð'à"Ð" 2§7¢7¡9¤9Ñ-Ô-°·²±´Ò:Ð:Ð:Ø�$‘&”&ÐZÐZ˜BŸGšG™IœIÐZÐZÐ,>Ð,>¸r¿wºw¹y¼yÑ,IÔ,IÐZÐZÈrÏwÊwÉyÌyÐZÐZñ ;Ô:Ð:à4Ð4°R¸Ñ<Ô<ˆLàðað aà�$‘&”&Ð`Ð`˜BŸIšI™KœKÐ`Ð`Ð.@Ð.@ÀÇÂÁÄÑ.MÔ.MÐ`Ð`ÐSU×S\ÒS\ÑS^ÔS^Ð`Ð`ñaô aØðað ar#   Úvalr{   c                  ó   •— d‰ › d‰j         › �S )Nzoutput z where )r[   )Úir^   s   €€r!   ú<lambda>z+DebugInterpreter.run_node.<locals>.<lambda>¯   s   ø€ Ð&O°Ð&OÐ&O¸$Ô:MÐ&OÐ&O€ r#   )r\   Úrun_nodeÚmetaÚpytreeÚtree_flattenr4   Úziprr   r.   r   ÚTensor)r^   Únr�   ri   Ún_valsÚn_specÚr_valsÚr_specr}   r~   ry   r„   rj   ro   r_   s   `         @@@@€r!   r†   zDebugInterpreter.run_node�   s{  øøøøøø€ ð	ð 	ð 	ð 	ð 	ð	9ð 	9ð 	9ð 	9ð 	9ð	ð 	ð 	ð 	ð 	ð		að 		að 		að 		að 		að 		aõ ‰GŒG×Ò˜QÑÔˆØ�A”Fˆ?ˆ?Ý#Ô0°´¸´Ñ?Ô?‰NˆF�FÝ#Ô0°Ñ3Ô3‰NˆF�Fõ �v‘;”;¥# f¡+¤+Ò-Ð-Ð-µ#°f±+´+Ð/PÐ/PÅ3ÀvÁ;Ä;Ð/PÐ/PÑ-Ô-Ð-Ý ¥¥s¨6¡{¤{Ñ!3Ô!3°V¸VÑDÔDð Qð Q‘	��2�rÝ! "¥e¤lÑ3Ô3ð ØØ��b˜"ÐOÐOÐOÐOÐOÑPÔPÐPÐPØˆr#   )Ú__name__Ú
__module__Ú__qualname__r]   r†   Ú__classcell__)r_   s   @r!   rX   rX   |   sQ   ø€ € € € € ðð ð ð ð ð/ð /ð /ð /ð /ð /ð /ð /ð /r#   rX   c                 ó*   — t          | ¦  «        j        S )z¨
    Returns a (slow) interpreter over the FX graph module that also checks
    various debugging properties (e.g., that tracing strides matched real
    strides.)
    )rX   r]   rU   s     r!   Ú	debug_nopr–   ³   s   € õ ˜DÑ!Ô!Ô%Ð%r#   c                 óÄ   — t          | ¦  «         t          j                             | ¦  «        }t          j                             |                     ¦   «         ¦  «        }|S r-   )r   r   r<   r=   r?   r@   )r   rM   rG   s      r!   Úsimple_ts_compiler˜   ½   sG   € å�DÑÔÐÝŒ	×Ò˜ÑÔ€AÝŒ	×Ò˜Ÿš™œÑ"Ô"€AØ€Hr#   c                 ó,   — t          | t          ¦  «        S r-   )r   r˜   )rG   s    r!   Únnc_jitrš   Å   s   € Ý˜Õ,Ñ-Ô-Ð-r#   c                 ó.   — t          | j        ¦  «         | S r-   )rK   rL   rU   s     r!   Úprint_compilerœ   æ   s   € å	ˆ$Œ)ÑÔÐØ€Kr#   Úfnc                 óÔ   — t           t           t          t          dœ}|                     |¦  «         t	          | t
          j        j        ¦  «        rt          | fi |¤ŽS t          | fi |¤ŽS )a  
    Wrapper function over :func:`aot_function` and :func:`aot_module` to perform
    memory efficient fusion. It uses the
    :func:`min_cut_rematerialization_partition` partitioner to perform efficient
    recomputation. It uses NVFuser to compile the generated forward and backward
    graphs.

    .. warning::
        This API is experimental and likely to change.

    Args:
        fn (Union[Callable, nn.Module]): A Python function or a ``nn.Module``
            that takes one ore more arguments. Must return one or more Tensors.
        **kwargs: Any other overrides you want to make to the settings

    Returns:
        Returns a ``Callable``  or ``nn.Module`` that retains the eager behavior
        of the original :attr:`fn`, but whose forward and backward graphs have
        gone through recomputation optimizations, and the graphs have been
        compiled with nvfuser.

    ©Úfw_compilerÚbw_compilerÚpartition_fnÚdecompositions)
rH   r   Údefault_decompositionsÚupdater.   r   ÚnnÚModuler   r   )r�   r6   Úconfigs      r!   Úmemory_efficient_fusionr©   ì   sr   € õ6 "Ý!Ý;Ý0ð	ð €Fð ‡M‚M�&ÑÔÐÝ�"•e”h”oÑ&Ô&ð *Ý˜"Ð'Ð' Ð'Ð'Ð'å˜BÐ)Ð) &Ð)Ð)Ð)r#   c                 óÐ   — |                       d¦  «         t          dd„ |D ¦   «         › d�¦  «         ddlm}   |¦   «                              ¦   «         |Ž  t          | |¦  «        S )NÚfooaQ  
##############################################################
# To minimize FX graph, copy and paste the below and run it  #
##############################################################

import torch
import torch.fx as fx
from functorch.compile import minifier, check_nvfuser_subprocess, check_nvfuser_correctness_subprocess

inps = c                 ó*   — g | ]}|j         |j        f‘ŒS rT   )Úshaper+   )r1   r„   s     r!   ú
<listcomp>z!debug_compile.<locals>.<listcomp>  s!   € Ð*Ð*Ð* ˆ!Œ'�1”7Ð	Ð*Ð*Ð*r#   a?  
inps = [torch.ones(shape, dtype=dtype, device='cuda') for (shape, dtype) in inps]
from foo import FxModule
mod = FxModule().cuda()

with torch.jit.fuser("fuser2"):
  # check_nvfuser_subprocess can be replaced with check_nvfuser_correctness_subprocess
  minifier(fx.symbolic_trace(mod), inps, check_nvfuser_subprocess)
r   )ÚFxModule)Ú	to_folderrK   r«   r¯   ÚcudarH   )r   rC   r¯   s      r!   Údebug_compiler²     sŽ   € Ø‡N‚N�5ÑÔÐÝ	ð	ð 	+Ð* TÐ*Ñ*Ô*ð	ð 	ð 	ñô ð ð( ÐÐÐÐÐà€H€H�J„J‡O‚OÑÔ�tÐÐå�d˜DÑ!Ô!Ð!r#   c                 ó6  — g }t          | d¦  «        5 }t          j        |¦  «        }g }|D ]Ô}t          |¦  «        dk    r|} |t	          j        ¦   «         ¦  «        }n‹|\  }}}}	}
|	t          j        t          j        t          j	        t          j
        t          j        t          j        t          t          hv rt          j        dd||	|
¬¦  «        }nt          j        ||	|
¬¦  «        }|                     |¦  «         ŒÕ	 ddd¦  «         n# 1 swxY w Y   |S )zZ
    Return a random input for the given inputs meta generated from _save_fx_default.
    Úrbr
   r   )r+   r9   N)ÚopenÚpickleÚloadr4   ÚrandomÚrandr   rg   Úint32Úint64ÚboolÚuint8ÚfloatÚrandintÚappend)Úinput_data_pathÚinputsrG   Úinputs_metar‡   r:   Úinputr­   rt   r+   r9   s              r!   Ú
get_inputsrÅ   3  sR  € ð €FÝ	ˆo˜tÑ	$Ô	$ð !¨Ý”k !‘n”nˆØˆØð 	!ð 	!ˆDÝ�4‰yŒy˜AŠ~ˆ~Ø�Ø˜�Vœ[™]œ]Ñ+Ô+��à59Ñ2��e˜V U¨FØÝ”IÝ”KÝ”KÝ”JÝ”IÝ”KÝÝð	ð 	ð 	õ "œM¨!¨Q°¸UÈ6ÐRÑRÔR�E�Eå!œJ u°EÀ&ÐIÑIÔI�EØ�MŠM˜%Ñ Ô Ð Ð ð'	!ð!ð !ð !ñ !ô !ð !ð !ð !ð !ð !ð !øøøð !ð !ð !ð !ð. €Ms   “C.DÄDÄDc                 ó|   ‡ ‡‡‡	‡
— ddl m} ˆ	fd„Š	ˆ ˆˆˆ	fd„Š
ˆ
fd„}ˆ
fd„}ˆ
fd„} ||||||t          ¬¦  «        S )	aO  
    The forward, backward, and joint computation graph will be stored in
    {folder_name}/{current_name}/{current_name}_forward_{graph_index},
    {folder_name}/{current_name}/{current_name}_backward_{graph_index}, and
    {folder_name}/{current_name}/{current_name}_joint_{graph_index} respectively.
    The input shape of the graphs will be stored in the .input files.
    These files can be loaded with pickle,
    and is a list of format (type, shape, stride, dtype, device).
    In the case of type = int or float, it is just (type,).
    For joint graph input, it is a nested list [[],[]]
    where the two inner lists have the same format.
    If dump_example_input is True, example_inputs will be stored in .pt file.
    Since each function might produce multiple graphs,
    the graph_index is used to distinguish difference graphs
    r   )Úaot_module_simplifiedc                 óþ  •— g }t          | ¦  «        dk    rEt          | d         t          ¦  «        r*| ‰| d         ¦  «        z  }| ‰| d         ¦  «        z  }|S | D ]ž}t          |¦  «        t          k    st          |¦  «        t
          k    r$|                     t          |¦  «        f¦  «         ŒV|                     t          |¦  «        |j        |                     ¦   «         |j	        |j
        f¦  «         ŒŸ|S )Nr   r
   )r4   r.   rm   r:   rg   r¾   rÀ   r­   rt   r+   r9   )r5   Ú
input_metaÚargÚget_input_metas      €r!   rË   z(_save_fx_default.<locals>.get_input_metad  sõ   ø€ Øˆ
Ýˆt‰9Œ9�qŠ=ˆ=�Z¨¨Q¬µÑ7Ô7ˆ=Ø˜.˜.¨¨a¬Ñ1Ô1Ñ1ˆJØ˜.˜.¨¨a¬Ñ1Ô1Ñ1ˆJØÐØð 	ð 	ˆCÝ�C‰yŒy�CÒÐ¥4¨¡9¤9µÒ#5Ð#5Ø×!Ò!¥4¨¡9¤9 ,Ñ/Ô/Ð/Ð/à×!Ò!Ý˜#‘Y”Y ¤	¨3¯:ª:©<¬<¸¼ÀCÄJÐOñô ð ð ð Ðr#   c                 ó  •— t          | j        j        ¦  «        dk    r/t                               t          j        d‰|t          ¦  «         d S t          j        | ¦  «        }|j         	                    t          j        j                             ¦   «         ¦  «         |                     ¦   «           ‰|¦  «        }t          j        ‰› d‰› �d¬¦  «         |                     ‰› d‰› d‰› d|› dt          › �	¦  «         t#          j        |t'          ‰› d‰› d‰› d|› dt          › d‰› d|› dt          › d�d¦  «        ¦  «         ‰r9t          j        |‰› d‰› d‰› d|› dt          › d‰› d|› dt          › d	�¦  «         d S d S )
Nr   z!No nodes in graph {%s}_{%s}_{%s}.ú/T)Úexist_okrM   z.inputÚwbz.pt)r4   r   r7   ÚlogÚloggingÚWARNINGÚgraph_indexÚcopyÚdeepcopyÚset_codegenr   ÚfxÚCodeGenr   ÚosÚmakedirsr°   r¶   Údumprµ   Úsave)	Ú
gm_to_saver5   Ú	type_nameÚgmrÉ   Úcurrent_nameÚdump_example_inputÚfolder_namerË   s	        €€€€r!   Úgraph_saver_helperz,_save_fx_default.<locals>.graph_saver_helpers  sO  ø€ åˆzÔÔ%Ñ&Ô&¨!Ò+Ð+Ý�GŠGÝ”Ø3ØØÝñô ð ð ˆFåŒ]˜:Ñ&Ô&ˆØ
Œ×Ò�UœXœ^×3Ò3Ñ5Ô5Ñ6Ô6Ð6Ø
�Š‰Œˆà#�^ DÑ)Ô)ˆ
å
Œ�{Ð3Ð3 \Ð3Ð3¸dÐCÑCÔCÐCØ
�ŠØÐTÐT˜\ÐTÐT¨LÐTÐT¸9ÐTÐTÅ{ÐTÐTñ	
ô 	
ð 	
õ 	ŒØÝØð  Hð  H ð  Hð  H°ð  Hð  H¸yð  Hð  HÍ;ð  Hð  HÐYeð  Hð  HÐhqð  Hð  HÕtð  Hð  Hð  HØñô ñ	
ô 	
ð 	
ð ð 	ÝŒJØØð  Eð  E ð  Eð  E°ð  Eð  E¸yð  Eð  EÍ;ð  Eð  EÐYeð  Eð  EÐhqð  Eð  EÕtð  Eð  Eð  Eñô ð ð ð ð	ð 	r#   c                 ó"   •—  ‰| |d¦  «         | S )NÚforwardrT   )rß   Úfw_argsrã   s     €r!   Úgraph_saver_forwardz-_save_fx_default.<locals>.graph_saver_forward–  s   ø€ ØÐ˜2˜w¨	Ñ2Ô2Ð2Øˆ	r#   c                 ó6   •—  ‰| |d¦  «         t           dz  a | S )NÚbackwardr
   )rÓ   )rß   Úbw_argsrã   s     €r!   Úgraph_saver_backwardz._save_fx_default.<locals>.graph_saver_backwardš  s'   ø€ ØÐ˜2˜w¨
Ñ3Ô3Ð3å�qÑˆØˆ	r#   c                 ó>   •—  ‰| |d¦  «         t          | |¦  «        S )NÚjoint)r   )rß   Ú
joint_argsrã   s     €r!   Úgraph_saver_jointz+_save_fx_default.<locals>.graph_saver_joint   s(   ø€ ØÐ˜2˜z¨7Ñ3Ô3Ð3Ý   ZÑ0Ô0Ð0r#   rŸ   )Úfunctorch.compilerÇ   r¤   )rà   râ   rá   rß   Úexample_inputsrÇ   rç   rë   rï   rË   rã   s   ```      @@r!   Ú_save_fx_defaultrò   R  sÖ   øøøøø€ ð  8Ð7Ð7Ð7Ð7Ð7ðð ð ð ð ð!ð !ð !ð !ð !ð !ð !ð !ðFð ð ð ð ðð ð ð ð ð1ð 1ð 1ð 1ð 1ð !Ð Ø
ØØ'Ø(Ø&Ý-ðñ ô ð r#   Fc                 ó4   — da t          t          | ||¦  «        S )as  
    Dump the forward, backward, and joint computation graph.
    Example Usage:
    save_fx_func = graph_dumper_aot(current_name, folder_name, dump_example_input = False)
    optimize_ctx = torchdynamo.optimize(
        save_fx_func
    )
    with torch.enable_grad():
        with optimize_ctx:
            result = forward_and_backward_pass(model, example_inputs)
    r   )rÓ   r   rò   )rà   râ   rá   s      r!   Úgraph_dumper_aotrô   ¯  s   € ð €KÝÕ# \°;Ð@RÑSÔSÐSr#   )T)F)VrÔ   rÑ   rÙ   r¶   r¸   Ú
contextlibr   Ú	functoolsr   Útypingr   r   rb   r   Útorch.fxr×   Útorch.nnr¦   Útorch.utils._pytreeÚutilsÚ_pytreerˆ   r   Útorch._decompr   Ú%torch.fx.experimental.symbolic_shapesr	   Úaot_autogradr   r   r   Úcompile_utilsr   Úpartitionersr   r   r   Ú	getLoggerr‘   rÐ   r"   r(   ÚGraphModulerH   rO   rR   rV   ÚInterpreterrX   r–   r˜   rš   r   r   ÚdetachÚgelu_backwardÚleaky_relu_backwardÚsigmoid_backwardÚthreshold_backwardÚhardtanh_backwardÚhardsigmoid_backwardÚhardswish_backwardÚtanh_backwardÚsilu_backwardÚelu_backwardÚcudnn_batch_normÚcudnn_batch_norm_backwardÚmasked_fillÚScalarr‹   ÚeluÚ
leaky_reluÚhardtanhÚ	hardswishÚhardsigmoidÚconj_physicalÚis_same_sizer¤   rœ   r§   r©   r²   rÓ   rÅ   rò   rô   rT   r#   r!   ú<module>r     sö  ðð €€€Ø €€€Ø 	€	€	€	Ø €€€Ø €€€Ø %Ð %Ð %Ð %Ð %Ð %Ø Ð Ð Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "à €€€à €€€Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø >Ð >Ð >Ð >Ð >Ð >à GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GØ *Ð *Ð *Ð *Ð *Ð *ðð ð ð ð ð ð ð ð ð ð €gÔ˜Ñ!Ô!€ð
ð ð ð ð?ð ?ñ „ð?ð ð+�R”^ð +¨hð +ð +ð +ñ Ôð+ð\ð ð ð ðHð Hð Hð ð	ˆbŒnð 	 Hð 	ð 	ð 	ñ Ôð	ð4ð 4ð 4ð 4ð 4�r”~ñ 4ô 4ð 4ðn ð&�B”Nð &¨(ð &ð &ð &ñ Ôð&ð ðð ñ Ôðð.ð .ð .ð „y„~€à„KØÔØÔØÔØÔØÔØÔØÔØÔØÔØÔØÔØÔ"ØÔÔØÔÔØ„HØ„OØ„MØ„NØÔØÔØÔð-Ð ð2 ,Ð+Ð,BÑCÔCÐ ð ðð ñ Ôðð
$*Øˆh˜œ	Ð!Ô"ð$*ð $*ð $*ð $*ðN"ð "ð "ð: €ðð ð ð>Yð Yð YðzTð Tð Tð Tð Tð Tr#   