
    YTh                         S SK r S SKr\ R                  S 5       r\ R                  S 5       r\R
                  R                  rS rS r	S r
S\\\\4      4S jrg)	    Nc              #     #    [         R                  R                  5       n[         R                  R                  U 5         Sv   [         R                  R                  U5        g! [         R                  R                  U5        f = f7f)zlContext manager that controls whether the JIT's executor will run optimizations before executing a function.N)torch_C_get_graph_executor_optimize_set_graph_executor_optimize)should_optimizestored_flags     H/var/www/auris/envauris/lib/python3.13/site-packages/torch/jit/_fuser.pyoptimized_executionr      sW      ((779K	HH))/:;--k:--k:s   >B	A%  B	%!BB	c              #   8  #    [         R                  R                  5       n[         R                  R                  5       n[         R                  R	                  5       n[         R                  R                  5       n[         R                  R                  5       nU S:X  a  [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        GOU S:X  a  [         R                  R                  S5      n[         R                  R                  S5      n[         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        GO4U S:X  a  [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        GOU S:X  a  [         R                  R                  S5      n[         R                  R                  S5      n[         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        OU S:X  a  [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        O[        SU  S	35      e S
v   U S;   a>  [         R                  R                  W5        [         R                  R                  W5        [         R                  R                  U5        [         R                  R                  U5        [         R                  R                  U5        [         R                  R                  U5        [         R                  R                  U5        g
! U S;   a>  [         R                  R                  W5        [         R                  R                  W5        [         R                  R                  U5        [         R                  R                  U5        [         R                  R                  U5        [         R                  R                  U5        [         R                  R                  U5        f = f7f)zContext manager that facilitates switching between backend fusers.

Valid names:
* ``fuser0`` - enables only legacy fuser
* ``fuser1`` - enables only NNC
* ``fuser2`` - enables only nvFuser
* ``fuser3`` - enables oneDNN Graph
fuser0TFfuser1fuser2fuser3nonez!unrecognized fuser option (name: )N)r   r   )r   r   _jit_can_fuse_on_cpu_jit_can_fuse_on_gpu_jit_texpr_fuser_enabled_jit_nvfuser_enabled_jit_llga_enabled_jit_override_can_fuse_on_cpu_jit_override_can_fuse_on_gpu_jit_set_texpr_fuser_enabled_jit_set_nvfuser_enabled_jit_set_llga_enabled_jit_set_profiling_executorr   	Exception)nameold_cpu_fuseold_gpu_fuseold_texpr_fuser_stateold_nvfuser_stateold_llga_stateold_profiling_executorold_profiling_modes           r
   fuserr'      s     88002L88002L!HH==?557XX//1Nx..t4..t4--e4))%0&&u-		!&!E!Ed!K"XXBB4H..t4..t4--d3))%0&&u-		..u5..u5--e4))$/&&u-		!&!E!Ed!K"XXBB4H..t4..u5--d3))%0&&t,	..u5..u5--e4))%0&&u-;D6CDD7''HH001GHHH112DE..|<..|<--.CD))*;<&&~6 ''HH001GHHH112DE..|<..|<--.CD))*;<&&~6s    QXT6 C X6C!XXc                     U R                  5       S:X  a  UR                  U 5        g U R                  5        H%  nUR                  5        H  n[	        X15        M     M'     g )Nzprim::DifferentiableGraph)kindappendblocksnodes_get_differentiable_graph_node)node	diff_nodeblockns       r
   r-   r-   V   sG    yy{11[[]E[[].q< # #    c                      [        X /UQ70 UD6$ )N)_script_method_graph_for)selfargskwargss      r
   
_graph_forr8   _   s    #D@@@@r2   c                     UR                  5       n[        UR                  R                  5       5      n[	        U5      S:X  d   eUS   R
                  R                  5       nUS   R                  R                  5       n/ nUR                  5        H  n	[        X5        M     [	        U5      [	        U5      :X  d   e[        X5       HX  u  p[        U
R                  R                  5       5      n[	        U5      S:X  d  M9  U	R                  SUS   R
                  5        MZ     U$ ! [         a    U " U0 UD6  [        5       s $ f = f)N   r   Subgraph)get_debug_statelistexecution_plansvalueslengraphcopycode!differentiable_op_executor_statesr,   r-   zipg_r   last_executed_optimized_graph)r5   parentr6   r7   dbsepsrA   	fw_states
diff_nodesr1   statefw_execution_planss               r
   r4   r4   c   s$   /$$&3&&--/03x1}}A!!# FKKAAC	*,
A*19  9~Z000J2HA!%e&;&;&B&B&D!E %&!+Z!3A!6!<!<= 3  / 	df,..	/s   C<D' $D' 'EEstrategyc                 @    [         R                  R                  U 5      $ )a  Set the type and number of specializations that can occur during fusion.

Usage: provide a list of pairs (type, depth) where type is one of "STATIC" or "DYNAMIC"
and depth is an integer.

Behavior - static vs dynamic:
    In STATIC fusion, fused ops are compiled to have fixed input shapes. The shape is determined
    based on some initial profiling runs.
    In DYNAMIC fusion, fused ops are compiled to have variable input shapes, so that multiple
    shapes are possible.

In both cases, we also recompile on new striding behavior, device, or dtype.

Behavior - fallback functions & depth:
    When an input doesn't match the format required by the specialized compiled op, it will run
    a fallback function. Fallback functions are recursively be compiled and specialized based
    on the observed tensor shapes. Since compilation can be slow, the "depth" parameter is provided to
    limit the number of specializations that can be compiled, before giving up on recompiling and
    falling back to a completely un-fused, un-specialized implementation.

The list of (type, depth) pairs controls the type of specializations and the number of
specializations. For example: [("STATIC", 2), ("DYNAMIC", 2)] indicates that the first
two specializations will use static fusions, the following two specializations will use
dynamic fusion, and any inputs that satisfy none of the 4 options will run an
unfused implementation.

NB: in the future, if more as more fusion backends are added there may be more granular
apis for specific fusers.
)r   r   _jit_set_fusion_strategy)rO   s    r
   set_fusion_strategyrR      s    < 88,,X66r2   )
contextlibr   contextmanagerr   r'   r   _last_executed_optimized_graphrG   r-   r8   r4   r=   tuplestrintrR    r2   r
   <module>rZ      s{      ; ; =7 =7@ !& G G =A/>7$uS#X"7 7r2   