+
    –°³j�  ã                  ó   € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIHtHt ^ RI	H
t
HtHtHtHt ^ RIHt ^ RIt^ RIHt ^ RIHt ^ RIHtHtHt ^ R	IHtHt ^ R
IHt ]'       d   ^ RIH t H!t!H"t" ^ RI#H$t$ ^ RI%H&t& ]PN                  ! ](4      t)]
! R4      t*]! R4      t+ ! R R]RR7      t, ! R R4      t-R R lt.R R lt/R R lt0R R lt1R R lt2R# ) a†  
This module provides common utilities and base classes for TorchDynamo backends.

Key components:
- AotAutograd: Base class for implementing AOT (Ahead-of-Time) autograd backends
- Backend utilities for handling:
  - Fake tensor conversion
  - Device/dtype detection from inputs
  - Memory efficient fusion
  - Graph flattening
  - Common compiler configurations

The utilities here are used by various backend implementations to handle
common operations and provide consistent behavior across different backends.
AOT autograd functionality is particularly important as it enables ahead-of-time
optimization of both forward and backward passes.
)ÚannotationsN)ÚAnyÚTYPE_CHECKING)Ú	ParamSpecÚRequiredÚ	TypedDictÚTypeVarÚUnpack)Úpatch©Údisable)ÚTensorifyScalarRestartAnalysis)ÚcountersÚdefakeÚflatten_graph_inputs)Úaot_module_simplifiedÚSerializableAOTDispatchCompiler)Ú_disable_current_modes)ÚCallableÚIterableÚSequence)ÚCompilerConfigExtra)Ú
OpOverloadÚPÚRc                  óŠ   € ] tR t^4t$ RtR]R&   R]R&   R]R&   R]R&   R	]R
&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   RtR# )ÚAotAutogradKwargsa  Keyword arguments accepted by AotAutograd and forwarded verbatim to
aot_module_simplified. decompositions may also be a zero-arg thunk returning
the decomposition table (a workaround for circular imports); AotAutograd
resolves it to the table before forwarding.zRequired[Callable[..., Any]]Úfw_compilerzCallable[..., Any] | NoneÚbw_compilerÚinference_compilerúCallable[..., Any]Úpartition_fnzYdict[OpOverload, Callable[..., Any]] | Callable[[], dict[OpOverload, Callable[..., Any]]]ÚdecompositionsÚboolÚkeep_inference_input_mutationszCompilerConfigExtra | NoneÚcompiler_config_extraÚignore_shape_envÚdisable_functionalizationÚpre_grad_passesz
str | NoneÚcompile_region_name© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú__static_attributes__r*   ó    Ú^/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/_dynamo/backends/common.pyr   r   4   sQ   ‡ ñ3ð
 .Ó-Ø*Ó*Ø1Ó1Ø$Ó$ð	=óð %)Ó(Ø5Ó5ØÓØ#Ó#Ø.Ó.Ø#×#r2   r   F)Útotalc                  ó.   € ] tR t^JtR R ltR R ltRtR# )ÚAotAutogradc               ó    € V ^8„  d   QhRRRR/# )é   ÚkwargsúUnpack[AotAutogradKwargs]ÚreturnÚNoner*   )Úformats   "r3   Ú__annotate__ÚAotAutograd.__annotate__K   s   € ÷ 0ñ 0Ð!:ð 0¸tñ 0r2   c                	ó    € R V n         Wn        R# )Úcompiler_fnN©r+   r9   )Úselfr9   s   &,r3   Ú__init__ÚAotAutograd.__init__K   s   € Ø%ˆŒØ)/Žr2   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r8   Úgmztorch.fx.GraphModuleÚexample_inputszSequence[Any]r9   r   r;   r    r*   )r=   s   "r3   r>   r?   O   s2   € ÷ Rñ RØ&ðRØ8EðRØQTðRà	ñRr2   c           	     	óÎ  € V'       d   \         P                  R V4       \        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   \        VVV 4      # V P                  P                  R4      p\        V4      '       d   V! 4       V P                  R&   \        R,          R;;,          ^,          uu&   R R lpV P                  P                  R	4      ;'       g    V P                  R
,          p\        V\        4      '       d6   \        VP                  RR4      '       g   V! VP                  4      Vn        M\        VRR4      '       g	   V! V4      pW`P                  R	&   V P                  P                  R4      ;'       g    V P                  R
,          T P                  R&   ^ RIHp ^ RIHp V P                  P                  R
R4      VJ d   \!        RR4      p	M\"        P$                  ! 4       p	 V! 4       ;_uu_ 4        V	;_uu_ 4        \'        VV3/ V P                  B p
\        R,          R;;,          ^,          uu&   \)        V
RR7      uuRRR4       uuRRR4       #   + '       g   i     M; iRRR4       R#   + '       g   i     R# ; i  \*         d    h \,         d#    \        R,          R;;,          ^,          uu&   h i ; i)z3aot_autograd-based backend ignoring extra kwargs %sc              3  óX   "  € T F   p\        V\        \        \        34      x € K"  	  R # 5i©N)Ú
isinstanceÚlistÚtupleÚdict)Ú.0Úxs   & r3   Ú	<genexpr>Ú'AotAutograd.__call__.<locals>.<genexpr>U   s!   é € ÐJ¹>°aŒz˜!œd¤E¬4Ð0×1Ð1»>ùs   ‚(*TFr"   Úaot_autogradr4   c               ó    € V ^8„  d   QhRRRR/# )r8   Úbw_compiler_fnzCallable[P, R]r;   zCallable[..., R]r*   )r=   s   "r3   r>   Ú*AotAutograd.__call__.<locals>.__annotate__d   s   € ÷ 	(ñ 	(¨^ð 	(Ð@Pñ 	(r2   c                ó(   a € R  V 3R llpRVn         V# )c               ó$   € V ^8„  d   QhRRRRRR/# )r8   ÚargszP.argsr9   zP.kwargsr;   r   r*   )r=   s   "r3   r>   ÚDAotAutograd.__call__.<locals>.wrap_bw_compiler.<locals>.__annotate__e   s!   € ÷ ñ ¨Fð ¸hð È1ñ r2   c                 ó@   <€ \        \        SR R7      ! V / VB RR7      # )z'do not trace backward compiler function©Úreasonz%do not trace generated backwards passr   )rZ   r9   rV   s   *,€r3   Ú_wrapped_bw_compilerÚLAotAutograd.__call__.<locals>.wrap_bw_compiler.<locals>._wrapped_bw_compilere   s6   ø€ ô ÜØ&Ð/Xõàð'à%ñ'ð Cô	ð r2   T)Ú_is_wrapped_bw_compiler)rV   r_   s   f r3   Úwrap_bw_compilerÚ.AotAutograd.__call__.<locals>.wrap_bw_compilerd   s"   ø€ ÷ð ð ð !Ô8ð (Ð'r2   r   r   ra   r   )Únop)Úenable_aot_loggingNz%functorch.compile.config.debug_assertÚokzdo not trace AOT-compiled graphr]   Únot_ok)ÚlogÚwarningÚanyr   r9   ÚgetÚcallabler   rL   r   ÚgetattrrA   Úfunctorch.compilerd   Útorch._inductor.debugre   r
   Ú
contextlibÚnullcontextr   r   r   Ú	Exception)rC   rG   rH   r9   r"   rb   r   rd   re   Úpatch_configÚcgs   &&&,       r3   Ú__call__ÚAotAutograd.__call__O   s6  € ÷ Ü�K‰KÐMÈvÔVç‹3ÑJ¹>ÓJ�3�3Š3ÑJ¹>ÓJ×JÒJÜ'ØØØóð ð Ÿ™Ÿ™Ð)9Ó:ˆÜ�N×#Ò#Ù,:Ó,<ˆD�K‰KÐ(Ñ)ô 	�Õ  ×)¨QÕ.Ó)õ	(ð& —k‘k—o‘o mÓ4×RÐR¸¿¹ÀMÕ8Rˆä�kÔ#B×CÒCÜ˜;×2Ñ2Ð4MÈu×UÒUÙ*:¸;×;RÑ;RÓ*S�Ô'øÜ˜Ð&?À×GÒGÙ*¨;Ó7ˆKà%0�‰�MÑ"à�K‰K�O‰OÐ0Ó1×OÐO°T·[±[ÀÕ5Oð 	�‰Ð(Ñ)õ 	*Ý<ð �;‰;�?‰?˜=¨$Ó/°3Ó6ÜCHØ7¸óD‰Lô &×1Ò1Ó3ˆLð	á#×%Õ%§|¢|ô +ØØ"ñð —k‘kñ�ô
 ˜Õ(¨×.°!Õ3Ó.Ü˜rÐ*KÔL÷ (4¡|×%Ò%§|§|ú×%×%×%Ò%ûô .ô 	ØÜô 	Ü�^Õ$ X×.°!Õ3Ó.Øð	úsO   ÈJ, ÈJÈ"AI;	É&
JÉ0
J, É;JÊJÊJ, ÊJ)	Ê#J, Ê)J, Ê,K$Ë#K$rB   N)r+   r,   r-   r.   rD   ru   r1   r*   r2   r3   r6   r6   J   s   † õ0÷Rñ Rr2   r6   c               ó    € V ^8„  d   QhRRRR/# )r8   r9   r:   r;   r6   r*   )r=   s   "r3   r>   r>   ¤   s   € ÷ !ñ !Ð4ð !¸ñ !r2   c                 ó   € \        R/ V B # )Nr*   )r6   )r9   s   ,r3   rT   rT   ¤   s   € ÜÑ ˜Ñ Ð r2   c               ó    € V ^8„  d   QhRRRR/# )r8   Úuse_decompsr#   r;   zdict[str, Any]r*   )r=   s   "r3   r>   r>   ¨   s   € ÷ ñ ¨Tð °nñ r2   c                óB   € ^ RI HpHpHp RVRVRV/pV '       d   WR&   V# )é    )Údefault_decompositionsÚ#min_cut_rematerialization_partitionÚ
ts_compiler   r   r!   r"   )rn   r}   r~   r   )rz   r}   r~   r   r9   s   &    r3   Úmem_efficient_fusion_kwargsr€   ¨   s8   € ÷ñ ð 	�zØ�zØÐ;ð	€F÷ à#9ÐÑ à€Mr2   c               ó    € V ^8„  d   QhRRRR/# )r8   Úfnz"Callable[[Any, list[Any], Any], R]r;   r   r*   )r=   s   "r3   r>   r>   ½   s   € ÷ ñ Ð Bð Àsñ r2   c                óL   a € \         P                  ! S 4      R V 3R ll4       pV# )z[
Decorator for backends that need real inputs.  We swap out fake
tensors for zero tensors.
c               ó(   € V ^8„  d   QhRRRRRRRR/# )r8   Úmodelr   Úinputsr9   r;   r*   )r=   s   "r3   r>   Ú-fake_tensor_unsupported.<locals>.__annotate__Ä   s(   € ÷ /ñ /�sð / Cð /°3ð /¸3ñ /r2   c                óª   <€ \        4       ;_uu_ 4        \        \        \        V4      4      pS! W3/ VB uuR R R 4       #   + '       g   i     R # ; irK   )r   rM   Úmapr   )r…   r†   r9   r‚   s   &&,€r3   ÚwrapperÚ(fake_tensor_unsupported.<locals>.wrapperÃ   s9   ø€ ä#×%Õ%Üœ#œf fÓ-Ó.ˆFÙ�eÑ. vÑ.÷ &×%×%Ó%ús   ”"AÁA	)Ú	functoolsÚwraps)r‚   rŠ   s   f r3   Úfake_tensor_unsupportedrŽ   ½   s'   ø€ ô ‡_‚_�RÓ÷/ó ð/ð
 €Nr2   c               ó    € V ^8„  d   QhRRRR/# )r8   rH   úIterable[Any]r;   ztorch.devicer*   )r=   s   "r3   r>   r>   Ì   s   € ÷ ñ  }ð ¸ñ r2   c                óœ   € V  F1  p\        V\        P                  4      '       g   K%  VP                  u # 	  \        P                  ! R 4      # )Úcpu)rL   ÚtorchÚTensorÚdevice©rH   rQ   s   & r3   Údevice_from_inputsr—   Ì   s7   € ÛˆÜ�aœŸ™×&Ô&Ø—8‘8ŠOñ ô �<Š<˜ÓÐr2   c               ó    € V ^8„  d   QhRRRR/# )r8   rH   r�   r;   ztorch.dtyper*   )r=   s   "r3   r>   r>   Ó   s   € ÷ ñ  mð ¸ñ r2   c                ó�   € V  F1  p\        V\        P                  4      '       g   K%  VP                  u # 	  \        P                  # rK   )rL   r“   r”   ÚdtypeÚfloat32r–   s   & r3   Údtype_from_inputsrœ   Ó   s2   € ÛˆÜ�aœŸ™×&Ô&Ø—7‘7ŠNñ ô �=‰=Ðr2   )3r/   Ú
__future__r   rp   rŒ   ÚloggingÚtypingr   r   Útyping_extensionsr   r   r   r   r	   Úunittest.mockr
   r“   Útorch._dynamor   Útorch._dynamo.excr   Útorch._dynamo.utilsr   r   r   Útorch._functorch.aot_autogradr   r   Útorch.utils._python_dispatchr   Úcollections.abcr   r   r   Útorch._inductor.compile_fxr   Ú
torch._opsr   Ú	getLoggerr+   rh   r   r   r   r6   rT   r€   rŽ   r—   rœ   r*   r2   r3   Ú<module>r«      s§   ðñõ$ #ã Û Û ß %ß MÕ MÝ ã Ý !Ý <ß FÑ F÷õ @÷ ß<Ñ<å>Ý%ð ×Ò˜Ó!€áˆcƒN€ÙˆCƒL€ô$˜	¨õ $÷,Wñ Wõt!õõ*õ÷r2   