+
    "Ý³jõ  ã                   óÄ   € ^ RI t ^ RIt^ RIHu Ht ^ RIHt R.tRt	 ! R R]P                  P                  4      tR R ltR	 R
 ltR R ltR R ltR R ltR R ltR# )é    N)Ú_assert_and_get_unique_deviceÚmodel_is_exportedÚ_exported_trainingc                   ó<   a a€ ] tR t^t oRtV 3R ltR tRtVtV ;t	# )ÚWrapperModulezjClass to wrap a callable in an :class:`torch.nn.Module`. Use this if you
are trying to export a callable.
c                ó0   <€ \         SV `  4        Wn        R # ©N)ÚsuperÚ__init__Úfn)Úselfr   Ú	__class__s   &&€Úg/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torchao/quantization/pt2e/export_utils.pyr   ÚWrapperModule.__init__   s   ø€ Ü‰ÑÔØŽó    c                ó&   € V P                   ! V/ VB # )zUSimple forward that just calls the ``fn`` provided to :meth:`WrapperModule.__init__`.©r   )r   ÚargsÚkwargss   &*,r   ÚforwardÚWrapperModule.forward   s   € à�wŠw˜Ð' Ñ'Ð'r   r   )
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r   Ú__classdict__s   @@r   r   r      s   ù‡ € ñõ÷(ò (r   r   c                óX   € V ^8„  d   QhR\         P                  P                  R\        /# )é   ÚmÚreturn)ÚtorchÚnnÚModuleÚbool)Úformats   "r   Ú__annotate__r*   $   s"   € ÷ ñ œŸ™Ÿ™ð ¬Tñ r   c                ó  € \        V \        P                  P                  4      ;'       d]    \        ;QJ d0    R V P
                  P                   4       F  '       g   K   R# 	  R# ! R V P
                  P                   4       4      # )z‰
Return True if the `torch.nn.Module` was exported, False otherwise
(e.g. if the model was FX symbolically traced or not traced at all).
c              3   ó@   "  € T F  pR VP                   9   x € K  	  R# 5i)ÚvalN)Úmeta)Ú.0Úns   & r   Ú	<genexpr>Ú$model_is_exported.<locals>.<genexpr>)   s   é € ð 7Ù!.˜Aˆ�—‘Ž£ùs   ‚TF)Ú
isinstancer%   ÚfxÚGraphModuleÚanyÚgraphÚnodes)r#   s   &r   r   r   $   sl   € ô
 �aœŸ™×-Ñ-Ó.÷ ð ·3³3ñ 7Ø!"§¡§¢ó7·3´3ð ²3ð °3ñ 7Ø!"§¡§¢ó7ó 4ð r   c                óX   € V ^8„  d   QhR\         P                  P                  R\        /# ©r"   r#   Útrain_to_eval©r%   r4   r5   r(   )r)   s   "r   r*   r*   .   s$   € ÷ 7ñ 7œŸ™×,Ñ,ð 7¼Tñ 7r   c           	     ó¨  a	€ ^RI Hp V P                  P                  4        V P	                  4        R Fš  o	V	3R lpV	3R lp\
        P                  ! ^4      3pV'       d&   V! \        V4      V4      pV! \        V4      V4      pM$V! \        V4      V4      pV! \        V4      V4      p^ RIH	p V! V VV. RR7       V P	                  4        Kœ  	  R# )	až  
Switch dropout patterns in the model between train and eval modes.

Dropout has different behavior in train vs eval mode. For exported models,
however, calling `model.train()` or `model.eval()` does not automatically switch
the dropout behavior between the two modes, so here we need to rewrite the aten
dropout patterns manually to achieve the same effect.

See https://github.com/pytorch/pytorch/issues/103681.
©Ú"_get_aten_graph_module_for_patternTc                 ó8   <€ \         P                  ! V R RSR7      # )ç      à?T©ÚpÚtrainingÚinplace©ÚFÚdropout©ÚxrE   s   &€r   Údropout_trainÚ'_replace_dropout.<locals>.dropout_trainB   s   ø€ Ü—9’9˜Q #°¸gÔFÐFr   c                 ó8   <€ \         P                  ! V R RSR7      # )rA   FrB   rF   rI   s   &€r   Údropout_evalÚ&_replace_dropout.<locals>.dropout_evalE   s   ø€ Ü—9’9˜Q #°¸wÔGÐGr   ©Úreplace_pattern_with_filters©Úmatch_filtersÚignore_literalsN)FT)
Úutilsr?   r7   Úeliminate_dead_codeÚ	recompiler%   Úrandnr   Útorch.fx.subgraph_rewriterrQ   )
r#   r;   r?   rK   rN   Úexample_inputsÚmatch_patternÚreplacement_patternrQ   rE   s
   &&       @r   Ú_replace_dropoutr]   .   sÕ   ø€ õ :ð ‡G�G×ÑÔ!Ø‡K�K„Mã ˆõ	Gõ	Hô  Ÿ+š+ a›.Ð*ˆßÙ>Ü˜mÓ,ØóˆMñ #EÜ˜lÓ+Øó#Ññ
 ?Ü˜lÓ+ØóˆMñ #EÜ˜mÓ,Øó#Ðõ
 	Lá$ØØØØØ õ	
ð 	
�‰ŽóK !r   c                óX   € V ^8„  d   QhR\         P                  P                  R\        /# r:   r<   )r)   s   "r   r*   r*   h   s(   € ÷ Nñ Nœ%Ÿ(™(×.Ñ.ð N¼tñ Nr   c                óZ  € ^RI Hp V P                  P                  4        V P	                  4        R R lpR R lp\
        P                  ! ^^^^4      \
        P                  ! ^4      \
        P                  ! ^4      \
        P                  ! ^4      \
        P                  ! ^4      3p\        V 4      pVRJ;'       d    VP                  R8H  pV! \        V4      VV4      pV! \        V4      VV4      p	V'       d   Tp
T	pMT	p
Tp^ RI
Hp V! V V
V. R	R
7       V P	                  4        R# )ao  
Switch batchnorm patterns in the model between train and eval modes.

Batchnorm has different behavior in train vs eval mode. For exported models,
however, calling `model.train()` or `model.eval()` does not automatically switch
the batchnorm behavior between the two modes, so here we need to rewrite the aten
batchnorm patterns manually to achieve the same effect.
r>   c          
      ó¸   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\         P                  R\         P                  /# ©r"   rJ   Ú	bn_weightÚbn_biasÚbn_running_meanÚbn_running_var©r%   ÚTensor)r)   s   "r   r*   Ú(_replace_batchnorm.<locals>.__annotate__{   óN   € ÷ 	
ñ 	
Ü�<‰<ð	
ä—<‘<ð	
ô —‘ð	
ô Ÿ™ð		
ô
 Ÿ™ñ	
r   c           	      ó6   € \         P                  ! WWAVR R7      # )T©rD   ©rG   Ú
batch_norm©rJ   rb   rc   rd   re   s   &&&&&r   Úbn_trainÚ$_replace_batchnorm.<locals>.bn_train{   s   € ô �|Š|Ø ¸7ÈTô
ð 	
r   c          
      ó¸   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\         P                  R\         P                  /# ra   rf   )r)   s   "r   r*   rh   †   ri   r   c           	      ó6   € \         P                  ! WWAVR R7      # )Frk   rl   rn   s   &&&&&r   Úbn_evalÚ#_replace_batchnorm.<locals>.bn_eval†   s   € ô �|Š|Ø ¸7ÈUô
ð 	
r   NÚcudarP   TrR   )rU   r?   r7   rV   rW   r%   rX   r   Útyper   rY   rQ   )r#   r;   r?   ro   rs   rZ   ÚdeviceÚis_cudaÚbn_train_atenÚbn_eval_atenr[   r\   rQ   s   &&           r   Ú_replace_batchnormr{   h   s  € õ :ð ‡G�G×ÑÔ!Ø‡K�K„Mõ	
õ	
ô 	�Š�A�q˜!˜QÓÜ�Š�A‹Ü�Š�A‹Ü�Š�A‹Ü�Š�A‹ð€Nô +¨1Ó-€FØ˜DÐ ×:Ð: V§[¡[°FÑ%:€GÙ6Ü�hÓØØó€Mñ
 6Ü�gÓØØó€L÷ Ø%ˆØ*Ñà$ˆØ+ÐåGá Ø	ØØØØõð ‡K�K†Mr   c                óL   € V ^8„  d   QhR\         P                  P                  /# ©r"   Úmodel©r%   r4   r5   )r)   s   "r   r*   r*   º   s   € ÷ ñ ¬¯©×(<Ñ(<ñ r   c                ó’   € \        V \        R4      pV'       g   V # \        V \        R4       \        V RR7       \	        V RR7       V # )a$  
Move an exported GraphModule to eval mode.

This is equivalent to model.eval() but only for certain special ops like dropout, batchnorm.
QAT users should call this before performing inference on the model.

This call is idempotent; if the model is already in eval mode, nothing will happen.
TF©r;   ©ÚgetattrÚ_EXPORTED_TRAINING_ATTRÚsetattrr]   r{   ©r~   Úis_trainings   & r   Ú_move_exported_model_to_evalrˆ   º   sA   € ô ˜%Ô!8¸$Ó?€KßØˆÜˆEÔ*¨EÔ2Ü�U¨$Õ/Ü�u¨DÕ1Ø€Lr   c                óL   € V ^8„  d   QhR\         P                  P                  /# r}   r   )r)   s   "r   r*   r*   Ì   s   € ÷ ñ ¬¯©×)=Ñ)=ñ r   c                ó’   € \        V \        R4      pV'       d   V # \        V \        R4       \        V RR7       \	        V RR7       V # )a&  
Move an exported GraphModule to train mode.

This is equivalent to model.train() but only for certain special ops like dropout, batchnorm.
QAT users should call this before performing training on the model.

This call is idempotent; if the model is already in train mode, nothing will happen.
FTr�   r‚   r†   s   & r   Ú_move_exported_model_to_trainr‹   Ì   sA   € ô ˜%Ô!8¸%Ó@€KßØˆÜˆEÔ*¨DÔ1Ü�U¨%Õ0Ü�u¨EÕ2Ø€Lr   c                óL   € V ^8„  d   QhR\         P                  P                  /# r}   r   )r)   s   "r   r*   r*   Þ   s   € ÷ ñ ¬E¯H©H×,@Ñ,@ñ r   c                óˆ   € RR R llpR p\         P                  ! W4      V n        \         P                  ! W 4      V n        V # )a€  
Allow users to call `model.train()` and `model.eval()` on an exported model,
but with the effect of changing behavior between the two modes limited to special
ops only, which are currently dropout and batchnorm.

Note: This does not achieve the same effect as what `model.train()` and `model.eval()`
does in eager models, but only provides an approximation. In particular, user code
branching on `training` flag will not function correctly in general because the branch
is already specialized at export time. Additionally, other ops beyond dropout and batchnorm
that have different train/eval behavior will also not be converted properly.
c                ó$   € V ^8„  d   QhR\         /# )r"   Úmode)r(   )r)   s   "r   r*   Ú6_allow_exported_model_train_eval.<locals>.__annotate__ë   s   € ÷ /ñ /œ4ñ /r   c                 óF   € V'       d   \        V 4       R # \        V 4       R # r	   )r‹   rˆ   )r   r�   s   &&r   Ú_trainÚ0_allow_exported_model_train_eval.<locals>._trainë   s   € ßÜ)¨$Ö/ä(¨Ö.r   c                 ó   € \        V 4       R # r	   )rˆ   )r   s   &r   Ú_evalÚ/_allow_exported_model_train_eval.<locals>._evalñ   s
   € Ü$ TÖ*r   )T)ÚtypesÚ
MethodTypeÚtrainÚeval)r~   r’   r•   s   &  r   Ú _allow_exported_model_train_evalr›   Þ   s7   € ÷/ò+ô ×"Ò" 6Ó1€E„KÜ×!Ò! %Ó/€E„JØ€Lr   )r—   r%   Útorch.nn.functionalr&   Ú
functionalrG   Útorchao.utilsr   Ú__all__r„   r'   r   r   r]   r{   rˆ   r‹   r›   © r   r   Ú<module>r¡      s_   ðó ã ß Ð å 7ð ð€ð /Ð ô(�E—H‘H—O‘Oô (õõ7õtNõdõ$÷$r   