+
    –°³jw#  ã                   óÐ  € R t ^ RIt^ RIt^ RIHt ^ RIHtHtHt ^ RI	H
t
Ht ^ RIt^ RIHu Ht  ^ RIt]! R4      t]! R4      t]'       d   ]
! R]R7      R	 R
 l4       tMR R ltR R ltR R ltR R lt ! R R4      tR R ltR R ltR R lt ! R R4      tR R lt R R  lt!R! R" lt"R# R$ lt#R% R& lt$R/R' R( llt%R) R* lt&R+ R, lt'R- R. lt(R#   ] d    Rt L¯i ; i)0a«  
This module contains utility functions that are explicitly allowed to be called during
TorchDynamo compilation. These functions are carefully vetted to ensure they work
correctly within the TorchDynamo tracing and compilation process.

Key functionality groups:

- Compilation State:
  Functions for checking compilation state (is_compiling)

- Function Wrapping:
  Utilities for wrapping functions (wrap_inline, wrap_numpy) to work with
  TorchDynamo compilation

- Autograd Hooks:
  Functions and classes for handling autograd hooks and backward passes
  (call_hook, FakeBackwardCFunction, etc.)

- Tensor Operations:
  Utility functions for tensor operations and transformations
N)ÚCallable)ÚAnyÚTYPE_CHECKINGÚTypeVar)Ú
deprecatedÚ	ParamSpecÚ_PÚ_Rze`torch._dynamo.external_utils.is_compiling` is deprecated. Use `torch.compiler.is_compiling` instead.)Úcategoryc                ó$   € V ^8„  d   QhR\         /# ©é   Úreturn©Úbool)Úformats   "Ú]/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/_dynamo/external_utils.pyÚ__annotate__r   0   s   € ÷ -ñ -œ$ñ -ó    c                  ó>   € \         P                  P                  4       # ©N©ÚtorchÚcompilerÚis_compiling© r   r   r   r   ,   s   € ô
 �~‰~×*Ñ*Ó,Ð,r   c                ó$   € V ^8„  d   QhR\         /# r   r   )r   s   "r   r   r   5   s   € ÷ -ñ -œ$ñ -r   c                 ó>   € \         P                  P                  4       # )zT
Indicates whether we are tracing/compiling with torch.compile() or torch.export().
r   r   r   r   r   r   5   s   € ô �~‰~×*Ñ*Ó,Ð,r   c                ót   € V ^8„  d   QhR\         \        \        3,          R\         \        \        3,          /# ©r   Úfnr   ©r   r   r	   )r   s   "r   r   r   >   s,   € ÷ 	ñ 	”HœR¤˜VÕ$ð 	¬´"´b°&Õ)9ñ 	r   c                óL   a € \         P                  ! S 4      R V 3R ll4       pV# )z;
Create an extra frame around fn that is not in skipfiles.
c                ód   € V ^8„  d   QhR\         P                  R\         P                  R\        /# ©r   ÚargsÚkwargsr   ©r   r%   r&   r	   )r   s   "r   r   Ú!wrap_inline.<locals>.__annotate__D   s)   € ÷ #ñ #”R—W‘Wð #¬¯	©	ð #´bñ #r   c                  ó   <€ S! V / VB # r   r   ©r%   r&   r    s   *,€r   ÚinnerÚwrap_inline.<locals>.innerC   s   ø€ á�4Ð"˜6Ñ"Ð"r   ©Ú	functoolsÚwraps)r    r+   s   f r   Úwrap_inliner0   >   s'   ø€ ô
 ‡_‚_�RÓ÷#ó ð#ð €Lr   c                ó˜   € V ^8„  d   QhR\         R\        P                  R,          3,          R\        R\        R\        P                  /# )r   Úhook.Nr%   r&   r   )r   r   ÚTensorr   )r   s   "r   r   r   J   sC   € ÷ ñ Ü
�3œŸ™ tÕ+Ð+Õ
,ðÜ58ðÜDGðä
‡\�\ñr   c                ón   € V ! V!  pVf
   V^ ,          # VP                  R4      R8X  d   \        R4      hV# )z:
Used by compiled autograd to handle hook returning None.
Ú	hook_typeÚpost_acc_grad_hookz5Tensor post accumulate grad hooks should return None.)ÚgetÚRuntimeError)r2   r%   r&   Úresults   &*, r   Ú	call_hookr:   J   s>   € ñ �4‰[€FØ‚~Ø�A�wˆØ	�‰�KÓ	 Ð$8Ô	8ÜÐRÓSÐSØ€Mr   c                ót   € V ^8„  d   QhR\         \        \        3,          R\         \        \        3,          /# )r   Úfr   r!   )r   s   "r   r   r   X   s,   € ÷ ñ ”(œ2œr˜6Õ"ð ¤x´´B°Õ'7ñ r   c                óh   a € \         '       g   S # \        P                  ! S 4      R V 3R ll4       pV# )z…Decorator that turns a function from ``np.ndarray``s to ``np.ndarray``s into a function
from ``torch.Tensor``s to ``torch.Tensor``s.
c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\        P                  /# r$   )r   r%   r&   ÚpytreeÚPyTree)r   s   "r   r   Ú wrap_numpy.<locals>.__annotate__`   s2   € ÷ Sñ S”B—G‘Gð S¤r§y¡yð S´V·]±]ñ Sr   c                  ó¶   <€ \         P                  ! \        P                  R  W34      w  rS! V / VB p\         P                  ! \        P
                  R V4      # )c                 ó"   € V P                  4       # r   )Únumpy©Úxs   &r   Ú<lambda>Ú*wrap_numpy.<locals>.wrap.<locals>.<lambda>b   s
   €  A§G¡G¤Ir   c                 ó.   € \         P                  ! V 4      # r   )r   Ú	as_tensorrE   s   &r   rG   rH   f   s   € ¼%¿/º/È!Ô:Lr   )r?   Útree_map_onlyr   r3   ÚnpÚndarray)r%   r&   Úoutr<   s   *, €r   ÚwrapÚwrap_numpy.<locals>.wrap_   sN   ø€ ä×+Ò+Ü�L‰LÑ-°¨~ó
‰ˆñ �Ð ˜Ñ ˆä×#Ò#¤B§J¡JÑ0LÈcÓRÐRr   )rL   r.   r/   )r<   rO   s   f r   Ú
wrap_numpyrQ   X   s3   ø€ ÷ ‹2Øˆä‡_‚_�QÓ÷Só ðSð €Kr   c                   óD   a € ] tR t^kt o V 3R lR ltV 3R lR ltRtV tR# )ÚFakeBackwardCFunctionc                óŠ   <€ V ^8„  d   QhRS[ P                  P                  P                  RS[S[ P
                  ,          RR/# )r   ÚrealÚsaved_tensorsr   N)r   ÚautogradÚfunctionÚBackwardCFunctionÚlistr3   )r   Ú__classdict__s   "€r   r   Ú"FakeBackwardCFunction.__annotate__l   sB   ø€ ÷ +ñ +á�n‰n×%Ñ%×7Ñ7ð+ñ ™EŸL™LÕ)ð+ð 
ñ	+r   c                ó   € Wn         W n        R # r   ©rU   rV   )ÚselfrU   rV   s   &&&r   Ú__init__ÚFakeBackwardCFunction.__init__l   s   € ð
 Œ	Ø*Ör   c                ó&   <€ V ^8„  d   QhRS[ RS[/# )r   Únamer   )Ústrr   )r   r[   s   "€r   r   r\   t   s   ø€ ÷ (ñ (¡ð (©ñ (r   c                óŠ   € VR 8X  d(   \         P                  ! R\        4       V P                  # \	        V P
                  V4      # )Úsaved_variablesz4'saved_variables' is deprecated; use 'saved_tensors')ÚwarningsÚwarnÚDeprecationWarningrV   ÚgetattrrU   )r_   rc   s   &&r   Ú__getattr__Ú!FakeBackwardCFunction.__getattr__t   s<   € ØÐ$Ô$Ü�MŠMØFÜ"ôð ×%Ñ%Ð%ä�t—y‘y $Ó'Ð'r   r^   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r`   rk   Ú__static_attributes__Ú__classdictcell__©r[   s   @r   rS   rS   k   s   ø‡ € ÷+ð +÷(ö (r   rS   c                ó  € V ^8„  d   QhR\         P                  P                  P                  R\        \         P
                  ,          R\        R\         P
                  \        \         P
                  R3,          ,          /# )r   Úbackward_c_functionrV   r%   r   .)r   rW   rX   rY   rZ   r3   r   Útuple)r   s   "r   r   r      s`   € ÷ ñ ÜŸ™×0Ñ0×BÑBðäœŸ™Õ%ðô ðô ‡\�\”Eœ%Ÿ,™,¨Ð+Õ,Õ,ñ	r   c                 óŠ   € \        W4      pVP                  P                  ! V.VO5!  p\        V\        4      '       g   V3pV# r   )rS   Ú_forward_clsÚbackwardÚ
isinstancerv   )ru   rV   r%   ÚfakeÚgradss   &&*  r   Úcall_backwardr}      sC   € ô
 !Ð!4ÓD€DØ×Ñ×&Ò& tÐ3¨dÓ3€Eä�eœU×#Ò#Ø�ˆà€Lr   c                óF   € V ^8„  d   QhR\         R\        \         ,          /# ©r   rF   r   )r   rZ   )r   s   "r   r   r   �   s   € ÷ ñ œð ¤¤c¥ñ r   c                 óz   € \        V \        4      '       d   \        V 4      # \        V \        4      '       d   V # V .# r   )rz   rv   rZ   rE   s   &r   Únormalize_as_listr�   �   s1   € Ü�!”U×ÒÜ�A‹wˆÜ	�A”t×	Ò	ØˆØˆ3€Jr   c                óD   € V ^8„  d   QhR\         P                  R\        /# r   ©r   r3   Úint)r   s   "r   r   r   •   s   € ÷ &ñ &œEŸL™Lð &¬Sñ &r   c                 ó>   € V P                  4       P                  4       # r   )Úuntyped_storageÚsizerE   s   &r   Úuntyped_storage_sizerˆ   •   s   € Ø×ÑÓ×#Ñ#Ó%Ð%r   c                   ót   a € ] tR t^™t o ]V 3R lR l4       t]V 3R lR l4       t]V 3R lR l4       tRtV t	R# )	ÚFakeCompiledAutogradEnginec                ó^   <€ V ^8„  d   QhRS[ S[. R3,          ,          RS[. R3,          RR/# )r   Úfinal_callbacksNÚcbr   ©rZ   r   )r   r[   s   "€r   r   Ú'FakeCompiledAutogradEngine.__annotate__›   s<   ø€ ÷ #ñ #Ù™h r¨4 xÕ0Õ1ð#Ù7?ÀÀDÀÕ7Ið#à	ñ#r   c                ó(   € V P                  V4       R # r   )Úappend)rŒ   r�   s   &&r   Úqueue_callbackÚ)FakeCompiledAutogradEngine.queue_callbackš   s   € ð 	×Ñ˜rÖ"r   c                óF   <€ V ^8„  d   QhRS[ S[. R3,          ,          RR/# )r   rŒ   Nr   rŽ   )r   r[   s   "€r   r   r�   ¡   s)   ø€ ÷  ñ  ©d±8¸BÀ¸HÕ3EÕ.Fð  È4ñ  r   c                ó~   € ^ pV\        V 4      8  d   W,          pV! 4        V^,          pK*  V P                  4        R# )é    N)ÚlenÚclear)rŒ   Úir�   s   &  r   Úexec_final_callbacksÚ/FakeCompiledAutogradEngine.exec_final_callbacks    s6   € àˆØ”#�oÓ&Ô&Ø Õ#ˆBÙŒDØ��FŠAØ×ÑÖr   c                ó   <€ V ^8„  d   QhRR/# )r   r   Nr   )r   r[   s   "€r   r   r�   ª   s   ø€ ÷ ñ ¨ñ r   c                 ó   € R # r   r   r   r   r   Ú_exec_final_callbacks_stubÚ5FakeCompiledAutogradEngine._exec_final_callbacks_stub©   s   € ár   r   N)
rm   rn   ro   rp   Ústaticmethodr’   rš   rž   rq   rr   rs   s   @r   rŠ   rŠ   ™   s?   ø‡ € Ø÷#ó ð#ð
 ÷ ó ð ð ÷ó ör   rŠ   c          
      óT   € V ^8„  d   QhR\         R\         R\        R\         R\         /# )r   r%   Úbw_stateÚ	hook_namer&   r   ©r   rd   )r   s   "r   r   r   ®   s4   € ÷ 9ñ 9Üð9Üð9Ü*-ð9Ü9<ð9äñ9r   c                 ó$   € \        W4      ! V/ VB # r   ©rj   )r¢   r£   r%   r&   s   $$*,r   Úcall_hook_from_backward_stater§   ®   s   € ô �8Ô'¨Ð8°Ñ8Ð8r   c                ól   € V ^8„  d   QhR\         R\         R\         R\         R\        R\        R\         /# )r   Ú_r9   r%   r¢   Ú
hooks_nameÚmodule_namer   r¤   )r   s   "r   r   r   ´   sD   € ÷ 	ñ 	Ü
ð	Üð	Ü #ð	Ü/2ð	Ü@Cð	ÜRUð	äñ	r   c                óh   € \        W$4      p\        W#4      pV F  pV! Wa.VO5!  p	V	f   K  T	pK  	  V# r   r¦   )
r©   r9   r¢   rª   r«   r%   ÚmoduleÚhooksr2   Ú
new_results
   &&$$$*    r   Ú%call_module_hooks_from_backward_stater°   ´   sC   € ô �XÓ+€FÜ�HÓ)€EÛˆÙ˜&Ð0¨4Ó0ˆ
ØÔ!ØŠFñ ð €Mr   c                ót   € V ^8„  d   QhR\         \        \        3,          R\         \        \        3,          /# r   r!   )r   s   "r   r   r   Á   s,   € ÷ (ñ (¬´"´b°&Õ)9ð (¼hÄrÌ2ÀvÕ>Nñ (r   c                 óL   a € \         P                  ! S 4      R  V 3R ll4       pV# )c                ód   € V ^8„  d   QhR\         P                  R\         P                  R\        /# r$   r'   )r   s   "r   r   Ú6get_nonrecursive_disable_wrapper.<locals>.__annotate__Å   s)   € ÷ #ñ #¬B¯G©Gð #¼r¿y¹yð #ÌRñ #r   c                  ór   <€ \         P                  P                  4       '       d   \        R 4      hS! V / VB # )zHNon-recursive torch.compiler.disable is not supported with torch.export.)r   r   Úis_exportingr8   r*   s   *,€r   Únonrecursive_disable_wrapperÚFget_nonrecursive_disable_wrapper.<locals>.nonrecursive_disable_wrapperÄ   s8   ø€ ä�>‰>×&Ñ&×(Ò(ÜØZóð ñ �4Ð"˜6Ñ"Ð"r   r-   )r    r·   s   f r   Ú get_nonrecursive_disable_wrapperr¹   Á   s(   ø€ ô ‡_‚_�RÓ÷#ó ð#ð (Ð'r   c                ó€   € V ^8„  d   QhR\         R\        \        \        3,          R\        \        \        3,          /# )r   r_   Úfuncr   )r   r   r   r	   )r   s   "r   r   r   Ï   s6   € ÷ 
ñ 
¤sð 
´(¼2¼r¸6Õ2Bð 
ÄxÔPRÔTVÐPVÕGWñ 
r   c                ó   a a€ R VV 3R llpV# )z3
Apply self as a ctx manager around a call to func
c                ód   € V ^8„  d   QhR\         P                  R\         P                  R\        /# r$   r'   )r   s   "r   r   Ú2wrap_dunder_call_ctx_manager.<locals>.__annotate__Õ   s)   € ÷ )ñ )”R—W‘Wð )¬¯	©	ð )´bñ )r   c                  óf   <€ S;_uu_ 4        S! V / VB uuR R R 4       #   + '       g   i     R # ; ir   r   )r%   r&   r»   r_   s   *,€€r   r+   Ú+wrap_dunder_call_ctx_manager.<locals>.innerÕ   s!   ø€ ßŠTÙ˜Ð( Ñ(÷ �T�T‹Tús   ŒŸ0	r   )r_   r»   r+   s   ff r   Úwrap_dunder_call_ctx_managerrÁ   Ï   s   ù€ ÷)ñ )ð €Lr   c                óZ   € V ^8„  d   QhR\         P                  \        ,          R\        /# r   rƒ   )r   s   "r   r   r   Þ   s#   € ÷ ñ ¤§¡¬sÕ 2ð ´sñ r   c                 óh   € \        V \        P                  4      '       d   V P                  ^4      # V # )é   )rz   r   r3   r‡   rE   s   &r   Úunwrap_maybe_dynamic_intrÅ   Þ   s&   € Ü�!”U—\‘\×"Ò"à�v‰v�a‹yÐØ€Hr   c                óä   € V ^8„  d   QhR\         P                  R\         P                  R,          R\         P                  \        ,          R\        R,          R\         P                  R,          /# )r   ÚvariableÚvariable_gradNÚgradÚhas_post_hooksr   )r   r3   r   )r   s   "r   r   r   å   s]   € ÷ ñ Ü�l‰lðä—<‘< $Õ&ðô �,‰,œÕ
ðô ˜4•Kð	ô
 ‡\�\�DÕñr   c                 óÜ   € Vf   \        V4      pTpV P                  p\        P                  P                  P
                  P                  V.WV4      pV^ ,          V n        V P                  # r   )r   rÉ   r   Ú_dynamoÚcompiled_autogradÚopsÚAccumulateGrad)rÇ   rÈ   rÉ   rÊ   Úupdated_grads   &&&& r   Úcall_accumulate_gradrÑ   å   sc   € ð Òô ˜d›ˆØˆØ Ÿ™ˆÜ—=‘=×2Ñ2×6Ñ6×EÑEØ	ˆ�¨ó€Lð ! •O€H„MØ�=‰=Ðr   c                ó€   € V ^8„  d   QhR\         \        \        3,          R\        R\         \        \        3,          /# )r   r    Úerror_on_graph_breakr   )r   r   r	   r   )r   s   "r   r   r   ø   s6   € ÷ ñ Ü””R�ÕðÜ04ðäŒb”"ˆfÕñr   c                 ó@   a € V'       d   R  V 3R llpV# R V 3R llpV# )c                ód   € V ^8„  d   QhR\         P                  R\         P                  R\        /# r$   r'   )r   s   "r   r   Ú;wrap_inline_with_error_on_graph_break.<locals>.__annotate__   ó)   € ÷ 	+ñ 	+œ2Ÿ7™7ð 	+¬b¯i©ið 	+¼Bñ 	+r   c                  ó    <€ \         P                  P                  R 4      ;_uu_ 4        S! V / VB uuRRR4       #   + '       g   i     R# ; i)TN©r   rÌ   rÓ   r*   s   *,€r   ÚwrapperÚ6wrap_inline_with_error_on_graph_break.<locals>.wrapper   s4   ø€ Ü—‘×3Ñ3°D×9Õ9Ù˜4Ð* 6Ñ*÷ :×9×9Ó9úó	   ©<¼A	c                ód   € V ^8„  d   QhR\         P                  R\         P                  R\        /# r$   r'   )r   s   "r   r   rÖ     r×   r   c                  ó    <€ \         P                  P                  R 4      ;_uu_ 4        S! V / VB uuRRR4       #   + '       g   i     R# ; i)FNrÙ   r*   s   *,€r   rÚ   rÛ     s4   ø€ Ü—‘×3Ñ3°E×:Õ:Ù˜4Ð* 6Ñ*÷ ;×:×:Ó:úrÜ   r   )r    rÓ   rÚ   s   f& r   Ú%wrap_inline_with_error_on_graph_breakrß   ø   s*   ø€ ÷ ÷	+ð 	+ð €N÷		+ð 	+ð €Nr   c                ó†   € V ^8„  d   QhR\         \        R3,          R\        \        ,          R\         \        R3,          /# )r   Útup.Úmasksr   ©rv   r   rZ   r   )r   s   "r   r   r     s6   € ÷ 	ñ 	¤¤s¨C x¥ð 	¼¼d½ð 	ÌÌcÐSVÈhÍñ 	r   c                ó†   € . p\        V4       F&  w  r4V'       d   K  VP                  W,          4       K(  	  \        V4      # )z|
masks is a list of bools, where True means the corresponding element in tup
is a const value. Filter out the const values.
©Ú	enumerater‘   rv   )rá   râ   rN   Úmask_idxÚmasks   &&   r   Úfilter_out_const_valuesré     s9   € ð
 €CÜ# EÖ*‰ˆß‰tØ�J‰J�s•}Ö%ñ +ô �‹:Ðr   c          
      ó¬   € V ^8„  d   QhR\         \        R3,          R\        \        ,          R\         \        R3,          R\         \        R3,          /# )r   rá   .râ   Úvaluesr   rã   )r   s   "r   r   r     sH   € ÷ ñ Ü	Œs�Cˆx�ðÜ!%¤d¥ðÜ5:¼3À¸8µ_ðä
Œ3�ˆ8…_ñr   c                óÊ   € . p^ p\        V4       FF  w  rVV'       d   VP                  W%,          4       K&  VP                  W,          4       V^,          pKH  	  \        V4      # )zk
masks and values are of same length. For indices where the mask is True, use
the const_values to fill in.
rå   )rá   râ   rë   rN   Úidxrç   rè   s   &&&    r   Úinsert_const_values_with_maskrî     sT   € ð €CØ
€CÜ# EÖ*‰ˆßØ�J‰J�vÕ'Ö(à�J‰J�s•xÔ Ø�1�HŠCñ +ô �‹:Ðr   r   ))Ú__doc__r.   rg   Úcollections.abcr   Útypingr   r   r   Útyping_extensionsr   r   r   Útorch.utils._pytreeÚutilsÚ_pytreer?   rD   rL   ÚModuleNotFoundErrorr   r	   ÚFutureWarningr   r0   r:   rQ   rS   r}   r�   rˆ   rŠ   r§   r°   r¹   rÁ   rÅ   rÑ   rß   ré   rî   r   r   r   Ú<module>rø      sà   ðñó, Û Ý $ß .Ñ .ß 3ã ß $Ð $ðÛñ ˆtƒ_€ÙˆTƒ]€çñ ØoØôô-ó	ñ-õ
-õ	õõ÷&(ñ (õ(õõ&÷ñ õ*9õ	õ(õ
õ÷õ&õ*	÷øðm ô Ø	‚Bðús   ±C Ã	C%Ã$C%