§
    ŠŠtjJ  ã                   óò  — d dl Z d dlZd dlZd dlmZ d dlZd dlmc mZ	 d dl
mc mZ d dlmZmZmZ d dlmZmZ d dlmZmZ  e j        e¦  «        Zdej        j        deej        j                 fd„Zd	ej        j        ddfd
„Zdej        j        ddfd„Zdej        j        dede e!ej        j        f         de"e#ej        j                 e e!ej        j        f         f         fd„Z$dej        j        de#ej        j                 de e!ej        j        f         dej%        j&        de!dej        j        fd„Z'dej        j        dedej        j        de e!ej        j        f         de"ej        j        df         ddfd„Z(dej        j        de e!ej%        j&        f         de e!ef         dej        j        fd„Z)dej        j        deddfd„Z*dede e!ej%        j&        f         dej        j        fd„Z+dS )é    N)Údefaultdict)ÚConstantArgumentÚExportedProgramÚModuleCallSignature)Úlegalize_graphÚNodeList)Úerase_nodesÚfuse_as_graphmoduleÚnodeÚreturnc                 óh  — t          | j                             ¦   «         ¦  «        }t          ¦   «         }|D ]z}|j        dk    rŒ|j        dk    r|j        t          j        u st          d| › d|› �¦  «        ‚| 	                    t          |j                             ¦   «         ¦  «        ¦  «         Œ{|S )NÚoutputÚcall_functionz"Expected getitem node as user for z, instead got )
ÚlistÚusersÚkeysÚsetÚopÚtargetÚoperatorÚgetitemÚAssertionErrorÚupdate)r   Ú
node_usersÚgetitem_usersÚusers       úP/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/export/_swap.pyÚ_get_getitem_usersr      s·   € Ý�d”j—o’oÑ'Ô'Ñ(Ô(€JÝ‘E”E€MØð 6ð 6ˆØŒ7�hÒÐØà”˜?Ò*Ð*¨t¬{½hÔ>NÐ/NÐ/NÝ ØO°TÐOÐOÈÐOÐOñô ð ð 	×Ò�T $¤*§/¢/Ñ"3Ô"3Ñ4Ô4Ñ5Ô5Ð5Ð5ØÐó    Úcurr_module_nodec                 ó°  — t                                d| ¦  «         t          | j                             ¦   «         ¦  «        }t          |¦  «        dk    rt          dt          |¦  «        › �¦  «        ‚|d         }|j        dk    r|j        t          j
        u st          d|j        › d|j        › �¦  «        ‚t          |¦  «        }t          |¦  «        dk    rt                                d||¦  «         d	S t          t          |¦  «        ¦  «        }|j        dk    r|j        t          j        u st                                d
||¦  «         d	S t!          |j        d         ¦  «        D ]‘\  }}||j        vr*t                                d| |j        d         ¦  «          d	S |j        dk    r$|j        t$          j        u r|j        d         |k    s*t                                d| |j        d         ¦  «          d	S Œ’t)          ¦   «         }t          |¦  «        }|D ];}	|                     t          |	j                             ¦   «         ¦  «        ¦  «         Œ<t          |¦  «        dk    rt                                d||¦  «         d	S t          t          |¦  «        ¦  «        }
|
j        dk    rt                                d||
¦  «         d	S | f|
_        d	S )a9  
    We want to try to remove extraneous pytree flatten/unflatten calls between modules
    calls. Instead of having the following:
    graph():
        ...
        %foo : [num_users=1] = call_module[target=foo](args = (%getitem_1, %getitem_2), kwargs = {})
        %tree_flatten_spec : [num_users=1] = call_function[target=torch.fx._pytree.tree_flatten_spec](args = (%foo, %_spec_1), kwargs = {})
        %getitem_4 : [num_users=1] = call_function[target=operator.getitem](args = (%tree_flatten_spec, 0), kwargs = {})
        %tree_unflatten_1 : [num_users=2] = call_function[target=torch.utils._pytree.tree_unflatten](args = ([%getitem_4], %_spec_2), kwargs = {})
        %getitem_5 : [num_users=1] = call_function[target=operator.getitem](args = (%tree_unflatten_1, 0), kwargs = {})
        %getitem_7 : [num_users=0] = call_function[target=operator.getitem](args = (%tree_unflatten_1, 1), kwargs = {})
        %getitem_6 : [num_users=1] = call_function[target=operator.getitem](args = (%getitem_5, 0), kwargs = {})
        %bar : [num_users=1] = call_module[target=bar](args = (%getitem_6,), kwargs = {})
        ...

    We could do the following, if we know that all the outputs of `foo` feed into `bar`:
    graph():
        ...
        %foo : [num_users=1] = call_module[target=foo](args = (%getitem_1, %getitem_2), kwargs = {})
        %bar : [num_users=1] = call_module[target=bar](args = (%getitem_6,), kwargs = {})
        ...

    Currently this optimization only works for the case where all of the outputs
    of `foo` go directly into `bar`, and `bar` has no other inputs.
    z+Trying to remove pytrees for module call %sé   z4Expected only one user for module node, instead got r   r   zVExpected flatten_node to be a call_function with target tree_flatten_spec, but got op=z	, target=zaMore than one user found for flatten node, %s: %s. Unable to fuse it with another unflatten call.NzTFlatten node %s's user is not a pytree.tree_unflatten. Instead it is: %s. Passing...z°Module %s's outputs are not all directly used as inputs to the subsequent module. Unable to fuse the connecting flatten/unflatten. The inputs to the subsequent module are: %s. z¬Module %s's outputs are not all directly used in the same order as outputted. Unable to fuse the connecting flatten/unflatten. The inputs to the subsequent module are: %s. zaMore than one user found for unflatten node, %s: %s. Unable to fuse it with another flatten call.Úcall_modulezLUnflatten node %s's user is not a call_module. Instead it is: %s. Passing...)ÚlogÚdebugr   r   r   Úlenr   r   r   Ú	fx_pytreeÚtree_flatten_specr   ÚnextÚiterÚpytreeÚtree_unflattenÚ	enumerateÚargsr   r   r   r   )r    Úcurr_module_usersÚflatten_nodeÚflatten_getitem_usersÚunflatten_nodeÚiÚargÚunflatten_getitem_getitem_usersÚunflatten_getitem_usersÚunflatten_getitem_userÚnext_module_nodes              r   Ú_try_remove_connecting_pytreesr9   $   sP  € õ6 ‡I‚IÐ;Ð=MÑNÔNÐNåÐ-Ô3×8Ò8Ñ:Ô:Ñ;Ô;ÐÝ
ÐÑÔ Ò"Ð"ÝØ\Å4ÐHYÑCZÔCZÐ\Ð\ñ
ô 
ð 	
ð % QÔ'€LàŒ˜?Ò*Ð*ØÔ¥9Ô#>Ð>Ð>åðJØ&œ/ðJð JØ4@Ô4GðJð Jñ
ô 
ð 	
õ
 /¨|Ñ<Ô<ÐÝ
Ð Ñ!Ô! QÒ&Ð&Ý�	Š	ð=àØ!ñ		
ô 	
ð 	
ð 	ˆå�$Ð4Ñ5Ô5Ñ6Ô6€NàÔ˜_Ò,Ð,ØÔ!¥VÔ%:Ð:Ð:å�	Š	ð,àØñ		
ô 	
ð 	
ð 	ˆå˜NÔ/°Ô2Ñ3Ô3ð ð ‰ˆˆ3Ø�lÔ(Ð(Ð(Ý�IŠIðSð !ØÔ# AÔ&ñô ð ð ˆFˆFð ŒF�oÒ%Ð%à”
�hÔ.Ð.Ð.à”˜”˜qÒ Ð å�IŠIð.ð !ØÔ# AÔ&ñô ð ð ˆFˆFð !õ '*¡e¤eÐ#Ý0°Ñ@Ô@ÐØ"9ð 
ð 
ÐØ'×.Ò.ÝÐ'Ô-×2Ò2Ñ4Ô4Ñ5Ô5ñ	
ô 	
ð 	
ð 	
õ Ð*Ñ+Ô+¨qÒ0Ð0Ý�	Š	ð;àØ+ñ		
ô 	
ð 	
ð 	ˆå�DÐ!@ÑAÔAÑBÔBÐØÔ˜mÒ+Ð+Ý�	Š	ð,àØñ		
ô 	
ð 	
ð 	ˆð .Ð/ÐÔÐÐr   Úgmc                 ó    — | j         j        D ]'}|j        dk    r|j        dk    rt	          |¦  «         Œ(| j                              ¦   «          dS )a)  
    Remove extraneous pytree flatten/unflatten calls.

    We try a couple of optimizations here:
        1. Remove pytree flatten/unflatten calls between modules
        2. TODO: Remove module's in_spec + initial unflatten call
        3. TODO: Remove module's out_spec + final flatten call
    r#   Ú
_guards_fnN)ÚgraphÚnodesr   r   r9   Úeliminate_dead_code)r:   r   s     r   Ú_remove_extraneous_pytreesr@   £   sY   € ð ””ð 1ð 1ˆØŒ7�mÒ#Ð#¨¬°|Ò(CÐ(CÝ*¨4Ñ0Ô0Ð0øà„H× Ò Ñ"Ô"Ð"Ð"Ð"r   Ú	signatureÚnode_name_mapc                 óÂ  ‡ ‡‡— g }|j         D ]s}t          |t          ¦  «        r|j        €|                     d ¦  «         Œ4|j        |vr|                     d ¦  «         ŒS|                     ||j                 ¦  «         Œtddlm}  |‰ ||j        ¦  «        }|j        j	        dk    rt          d|j        j	        › �¦  «        ‚|j        j        t          urt          d|j        j        › �¦  «        ‚|j                             ¦   «         \  }}|j        t          urt          d|j        › �¦  «        ‚|j        t          urt          d|j        › �¦  «        ‚‰ j                             t"          j        |df¦  «        Šˆˆ fd	„t'          |j	        ¦  «        D ¦   «         }	‰ j                             t"          j        |df¦  «        Šˆ ˆfd
„|j        D ¦   «         }
|	|
fS )Nr"   )Ú_generate_unflattené   ú-Expected in_spec to have 2 children, but got z+Expected in_spec type to be tuple, but got z-Expected args_spec type to be tuple, but got z.Expected kwargs_spec type to be dict, but got r   c                 ó^   •— g | ])}‰j                              t          j        ‰|f¦  «        ‘Œ*S © ©r=   r   r   r   )Ú.0r3   Ú	args_noder:   s     €€r   ú
<listcomp>z%_construct_inputs.<locals>.<listcomp>Ý   sB   ø€ ð ð ð àð 	Œ×Ò�xÔ/°)¸Q°Ñ@Ô@ðð ð r   c                 ó`   •— i | ]*}|‰j                              t          j        ‰|f¦  «        “Œ+S rH   rI   )rJ   Úkr:   Úkwargs_nodes     €€r   ú
<dictcomp>z%_construct_inputs.<locals>.<dictcomp>â   sE   ø€ ð ð ð àð 	
ˆ2Œ8×!Ò!¥(Ô"2°[À!Ð4DÑEÔEðð ð r   )ÚinputsÚ
isinstancer   ÚvalueÚappendÚnameÚ	unflattenrD   Úin_specÚnum_childrenr   ÚtypeÚtupleÚchildrenÚdictr=   r   r   r   ÚrangeÚcontext)r:   rA   rB   Útree_unflatten_argsÚinput_rD   r2   Ú	args_specÚkwargs_specÚ
args_nodesÚkwargs_nodesrK   rO   s   `          @@r   Ú_construct_inputsre   ´   s[  øøø€ ð
 79ÐØÔ"ð 	Cð 	CˆÝ�fÕ.Ñ/Ô/ð 	C°F´LÐ4Hð  ×&Ò& tÑ,Ô,Ð,Ð,ØŒ[ Ð-Ð-à×&Ò& tÑ,Ô,Ð,Ð,à×&Ò& }°V´[Ô'AÑBÔBÐBÐBð /Ð.Ð.Ð.Ð.Ð.à(Ð(¨Ð-@À)ÔBSÑTÔT€NàÔÔ%¨Ò*Ð*ÝØ\¸IÔ<MÔ<ZÐ\Ð\ñ
ô 
ð 	
ð ÔÔ¥UÐ*Ð*ÝØR¸)Ô:KÔ:PÐRÐRñ
ô 
ð 	
ð 'Ô.×7Ò7Ñ9Ô9Ñ€Iˆ{Ø„~�UÐ"Ð"ÝØL¸I¼NÐLÐLñ
ô 
ð 	
ð Ô�tÐ#Ð#ÝØO¸[Ô=MÐOÐOñ
ô 
ð 	
ð ”×&Ò&¥xÔ'7¸.È!Ð9LÑMÔM€Iðð ð ð ð å�yÔ-Ñ.Ô.ðñ ô €Jð ”(×(Ò(­Ô)9¸NÈAÐ;NÑOÔO€Kðð ð ð ð àÔ$ðñ ô €Lð �|Ð#Ð#r   rc   rd   Úmodule_to_swaprU   c                 óŽ   — ddl m}m}  ||| ||j        ¦  «         | j                             |t          |¦  «        |¦  «        }|S )Nr"   )Ú_assign_attrÚ	_AttrKind)rV   rh   ri   ÚMODULEr=   r#   rZ   )r:   rc   rd   rf   rU   rh   ri   Úmodule_nodes           r   Ú_insert_call_modulerl   é   s\   € ð 3Ð2Ð2Ð2Ð2Ð2Ð2Ð2à€L�  T¨9Ô+;Ñ<Ô<Ð<Ø”(×&Ò& t­U°:Ñ->Ô->ÀÑMÔM€KØÐr   rk   Úorig_outputs.c                 óö   — ddl m}  || ||j        ¦  «        }t          |¦  «        D ]P\  }}t          j                             |¦  «        |         j        }	|                     |	d¬¦  «         |	||j	        <   ŒQd S )Nr"   )Ú_generate_flatten_specT)Úpropagate_meta)
rV   ro   Úout_specr-   ÚtorchÚfxÚProxyr   Úreplace_all_uses_withrU   )
r:   rA   rk   rB   rm   ro   r0   r3   Úorig_outputÚ	proxy_outs
             r   Ú_deconstruct_outputsrx   ÷   s–   € ð 2Ð1Ð1Ð1Ð1Ð1à)Ð)¨"¨k¸9Ô;MÑNÔN€Lå# LÑ1Ô1ð 4ð 4‰ˆˆ;å”H—N’N <Ñ0Ô0°Ô3Ô8ˆ	Ø×)Ò)¨)ÀDÐ)ÑIÔIÐIà*3ˆ�kÔ&Ñ'Ð'ð4ð 4r   Úmodules_to_swapÚmodule_call_graphc                 ó$  — t                                d¦  «         t                                | j        ¦  «         t          | ¦  «         t	          t
          ¦  «        }d„ | j        j        D ¦   «         }| j        j        D ]Y}|j                             d¦  «        x}r;| 	                    ¦   «         D ]&\  }}||v r||          
                    |¦  «          nŒ'ŒZ|                     ¦   «         D ]þ\  }	}
	 |	                     dd¦  «        }t          | |
d|› �¦  «        \  }}}t                                d¦  «         t                                |j        ¦  «         ||	         }t          | ||¦  «        \  }}t          | ||||	         |	¦  «        }t!          | ||||¦  «         t#          | |
¦  «         t                                d¦  «         t                                | j        ¦  «         Œÿt          | ¦  «         t                                d	¦  «         t                                | j        ¦  «         t%          | ¦  «         t                                d
¦  «         t                                | j        ¦  «         |                      ¦   «          | S )NzStarting graph:c                 ó   — i | ]
}|j         |“ŒS rH   )rU   ©rJ   r   s     r   rP   z'_swap_module_helper.<locals>.<dictcomp>  s)   € ð /ð /ð /Ø ˆŒ	�4ð/ð /ð /r   Únn_module_stackú.Ú_Úfused_zFused subgraph nodes:zSwapped graph:z#Before removing extraneous pytrees:z"After removing extraneous pytrees:)r$   r%   r=   r   r   r   r>   ÚmetaÚgetÚvaluesrT   ÚitemsÚreplacer
   re   rl   rx   r	   r@   Ú	recompile)r:   ry   rz   Ú
partitionsrB   r   r~   Úpathr€   rU   r>   Úsubmod_nameÚsub_gmÚorig_inputsrm   rA   rc   rd   rk   s                      r   Ú_swap_module_helperr�   
  s  € õ
 ‡I‚IÐÑ Ô Ð Ý‡I‚IˆbŒhÑÔÐå�2ÑÔÐå&1µ$Ñ&7Ô&7€Jð/ð /Ø$&¤H¤Nð/ñ /ô /€Mð
 ””ð ð ˆØ"œiŸmšmÐ,=Ñ>Ô>Ð>ˆ?ð 	Ø*×1Ò1Ñ3Ô3ð ð ‘��aØ˜?Ð*Ð*Ø˜tÔ$×+Ò+¨DÑ1Ô1Ð1Ø�Eð +øð "×'Ò'Ñ)Ô)ð >ð >‰ˆˆeð(	ðT —l’l 3¨Ñ,Ô,ˆÝ,?Ø�Ð- Ð-Ð-ñ-
ô -
Ñ)ˆ�˜\õ 	�	Š	Ð)Ñ*Ô*Ð*Ý�	Š	�&”,ÑÔÐà):¸4Ô)@ˆ	å#4°R¸ÀMÑ#RÔ#RÑ ˆ
�LÝ)Ø�
˜L¨/¸$Ô*?Àñ
ô 
ˆõ 	˜R ¨K¸ÈÑUÔUÐUå�B˜ÑÔÐå�	Š	Ð"Ñ#Ô#Ð#Ý�	Š	�"”(ÑÔÐÐå�2ÑÔÐå‡I‚IÐ3Ñ4Ô4Ð4Ý‡I‚IˆbŒhÑÔÐå˜rÑ"Ô"Ð"Ý‡I‚IÐ2Ñ3Ô3Ð3Ý‡I‚IˆbŒhÑÔÐà‡L‚L�N„N€Nà€Ir   c                 óœ  — ddl m}m} t          j        j                             ¦   «         | j        _        d„ | j        j        D ¦   «         }g }|j	        }|€õg }|j
        j        dk    rt          d|j
        j        › �¦  «        ‚|j
                             d¦  «        }|j
                             d¦  «        }|j        t          urt          d|j        › �¦  «        ‚|j        t           urt          d	|j        › �¦  «        ‚t#          |j        ¦  «        D ]}	|                     d
|	› �¦  «         Œ|                     |j        ¦  «         |D ]g}
| j                             |d         ¦  «        5  |                     | j                             |
¦  «        ¦  «         ddd¦  «         n# 1 swxY w Y   Œh| j                             |d         ¦  «        5   || t          |¦  «        ¦  «        }t/          |¦  «        D ]&\  }	}d|_        t2          j        |_        ||	f|_        Œ'	 ddd¦  «         n# 1 swxY w Y   t;          d„ | j        j        D ¦   «         ¦  «        }| j                             |¦  «        5   || |j        d         |j        ¦  «        }|f|_        ddd¦  «         n# 1 swxY w Y   |                      ¦   «          dS )a`  
    Given the unlifted module from calling ep.module(), we want to remove the
    pytree processing from the graph module's PyTreeCodeGen and instead make it
    nodes inside of the graph. This allows us to do some optimizations, like
    remove these pytree calls if it is unnecessary, and makes the PyTree part
    more obvious to graph passes.
    r   )Ú_generate_flattenrD   c                 ó(   — g | ]}|j         d k    ¯|‘ŒS )Úplaceholder©r   r}   s     r   rL   z/_fix_input_output_signature.<locals>.<listcomp>€  s$   € ÐTÐTÐT ¸4¼7ÀmÒ;SÐ;S˜Ð;SÐ;SÐ;Sr   NrE   rF   r"   z,Expected arg_spec type to be tuple, but got z-Expected kwarg_spec type to be dict, but got Úarg_r   c              3   ó0   K  — | ]}|j         d k    ¯|V — ŒdS )r   Nr’   r}   s     r   ú	<genexpr>z._fix_input_output_signature.<locals>.<genexpr>¥  s.   è è € ÐNÐN ¸$¼'ÀXÒ:MÐ:M�tÐ:MÐ:MÐ:MÐ:MÐNÐNr   ) Útorch.export.unflattenr�   rD   rr   rs   r=   ÚCodeGenÚ_codegenr>   Úforward_arg_namesrW   rX   r   ÚchildrY   rZ   r\   r]   rT   Úextendr^   Úinserting_beforer‘   r-   r   r   r   r   r.   r)   rq   r‡   )r:   rA   r�   rD   Úold_placeholdersÚnew_placeholdersr™   Úarg_specÚ
kwarg_specr3   r4   Ú	flat_nodeÚold_placeholderÚoutput_nodeÚunflats                  r   Ú_fix_input_output_signaturer¥   p  s¸  € ð NÐMÐMÐMÐMÐMÐMÐMõ œœ×.Ò.Ñ0Ô0€B„HÔàTÐT¨¬¬ÐTÑTÔTÐàÐØ!Ô3ÐØÐ ØÐØÔÔ)¨QÒ.Ð.Ý Ø`À	Ô@QÔ@^Ð`Ð`ñô ð ð Ô$×*Ò*¨1Ñ-Ô-ˆØÔ&×,Ò,¨QÑ/Ô/ˆ
ØŒ=¥Ð%Ð%Ý ØN¸x¼}ÐNÐNñô ð ð Œ?¥$Ð&Ð&Ý ØQÀ
ÄÐQÐQñô ð õ �xÔ,Ñ-Ô-ð 	1ð 	1ˆAØ×$Ò$ Z¨A Z ZÑ0Ô0Ð0Ð0Ø× Ò  Ô!3Ñ4Ô4Ð4à ð ?ð ?ˆØŒX×&Ò&Ð'7¸Ô':Ñ;Ô;ð 	?ð 	?Ø×#Ò# B¤H×$8Ò$8¸Ñ$=Ô$=Ñ>Ô>Ð>ð	?ð 	?ð 	?ñ 	?ô 	?ð 	?ð 	?ð 	?ð 	?ð 	?ð 	?øøøð 	?ð 	?ð 	?ð 	?øð 
Œ×	"Ò	"Ð#3°AÔ#6Ñ	7Ô	7ð 2ð 2Ø%Ð% b­%Ð0@Ñ*AÔ*AÑBÔBˆ	Ý"+Ð,<Ñ"=Ô"=ð 	2ð 	2ÑˆAˆØ!0ˆOÔÝ%-Ô%5ˆOÔ"Ø$-¨q >ˆOÔ Ð ð	2ð2ð 2ð 2ñ 2ô 2ð 2ð 2ð 2ð 2ð 2ð 2øøøð 2ð 2ð 2ð 2õ ÐNÐN¨¬¬ÐNÑNÔNÑNÔN€KØ	Œ×	"Ò	" ;Ñ	/Ô	/ð %ð %Ø$Ð$ R¨Ô)9¸!Ô)<¸iÔ>PÑQÔQˆØ"˜9ˆÔð%ð %ð %ñ %ô %ð %ð %ð %ð %ð %ð %øøøð %ð %ð %ð %ð ‡L‚L�N„N€N€N€Ns7   Å0.F*Æ*F.	Æ1F.	ÇAH3È3H7È:H7É;&J-Ê-J1Ê4J1Úepc                 ó²  — d„ | j         D ¦   «         }|                      ¦   «         }d|_        |j                             ¦   «          t          |t          j        j        ¦  «        st          dt          |¦  «        › �¦  «        ‚t          || j         d         j        ¦  «         | j         |_         t          j        t          |¦  «        j        |¦  «        |_        t          j        t          |¦  «        j        |¦  «        |_        t          |t          j        j        ¦  «        st          dt          |¦  «        › �¦  «        ‚t#          |||¦  «        }|S )ab  
    Unlifts the given ExportedProgram into a fx.GraphModule, and then swaps
    previously traced modules with new eager modules specified. Returns a
    fx.GraphModule with a custom forward function.

    Args:
        ep (ExportedProgram): Exported program to modify
        modules_to_swap (Dict[str, torch.nn.Module]): Mapping from module fqn to
            eager module to swap with. The specified module fqn should have also
            been specified in the `preserve_module_call_signature` argument to
            torch.export so that we know how to restore the calling convention
            to this argument.
        run_with_interpreter: Whether or not to run the graph using
            fx.Interpreter. Setting to true will help result in better error
            messages and easier debugging, but it has found to result in a QPS
            drop.
    c                 ó6   — i | ]}|j         ¯	|j        |j         “ŒS rH   )rA   Úfqn)rJ   Úentrys     r   rP   z!_swap_modules.<locals>.<dictcomp>Á  s5   € ð ð ð Ø',ÈÌðØŒ	�5”?ðð ð r   Fz2Expected gm to be a torch.fx.GraphModule, but got r   )rz   ÚmoduleÚvalidate_inputsr=   r?   rR   rr   rs   ÚGraphModuler   rY   r¥   rA   ÚtypesÚ
MethodTypeÚtrainÚevalr�   )r¦   ry   rz   r:   s       r   Ú_swap_modulesr²   ­  s<  € ð(ð Ø02Ô0Dðñ ô Ðð 
�Š‰Œ€BØ€BÔØ„H× Ò Ñ"Ô"Ð"Ý�b�%œ(Ô.Ñ/Ô/ð 
ÝØKÅÀbÁÄÐKÐKñ
ô 
ð 	
õ    BÔ$8¸Ô$;Ô$EÑFÔFÐFàÔ/€BÔÝÔ¥ R¡¤¤°Ñ3Ô3€B„HÝÔ�t B™xœxœ}¨bÑ1Ô1€B„Gå�b�%œ(Ô.Ñ/Ô/ð 
ÝØKÅÀbÁÄÐKÐKñ
ô 
ð 	
õ 
˜R Ð2CÑ	DÔ	D€Bà€Ir   ),Úloggingr   r®   Úcollectionsr   rr   Útorch.fx._pytreers   Ú_pytreer'   Útorch.utils._pytreeÚutilsr+   Útorch.export.exported_programr   r   r   Útorch.fx.passes.tools_commonr   r   Ú!torch.fx.passes.utils.fuser_utilsr	   r
   Ú	getLoggerÚ__name__r$   ÚNoder   r   r9   r­   r@   r\   ÚstrrZ   r   re   ÚnnÚModulerl   rx   r�   r¥   r²   rH   r   r   ú<module>rÂ      sš  ðØ €€€Ø €€€Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #à €€€Ø $Ð $Ð $Ð $Ð $Ð $Ð $Ð $Ð $Ø $Ð $Ð $Ð $Ð $Ð $Ð $Ð $Ð $ðð ð ð ð ð ð ð ð ð ð
 BÐ AÐ AÐ AÐ AÐ AÐ AÐ AØ NÐ NÐ NÐ NÐ NÐ NÐ NÐ Nð €gÔ˜Ñ!Ô!€ð˜UœXœ]ð ¨s°5´8´=Ô/Að ð ð ð ð|0°U´X´]ð |0Àtð |0ð |0ð |0ð |0ð~# 5¤8Ô#7ð #¸Dð #ð #ð #ð #ð"2$ØŒÔð2$à"ð2$ð ˜˜UœXœ]Ð*Ô+ð2$ð ˆ4�””Ô  S¨%¬(¬-Ð%7Ô 8Ð8Ô9ð	2$ð 2$ð 2$ð 2$ðjØŒÔðà�U”X”]Ô#ðð �s˜EœHœMÐ)Ô*ðð ”H”Oð	ð
 ðð „X„]ðð ð ð ð4ØŒÔð4à"ð4ð ””ð4ð ˜˜UœXœ]Ð*Ô+ð	4ð
 ˜œœ sÐ*Ô+ð4ð 
ð4ð 4ð 4ð 4ð&cØŒÔðcà˜#˜uœxœÐ.Ô/ðcð ˜CÐ!4Ð4Ô5ðcð „XÔð	cð cð cð cðL:ØŒÔð:Ø)<ð:à	ð:ð :ð :ð :ðz+Øð+Ø*.¨s°E´H´OÐ/CÔ*Dð+à
„XÔð+ð +ð +ð +ð +ð +r   