
    iz                     R    d Z ddlZddlmZmZmZm	Z
 d Zd Zd Z	d Zdadadad	 Zy)
z
This module contains pre-dispatch wrappers for functorch operations
that enable proper tracing in PT2 non-strict export/compile fx graph.
    N)_add_batch_dim_remove_batch_dim_vmap_decrement_nesting_vmap_increment_nestingc                     ddl m}  |       }|r(t        j                  j	                  t
        | f| ||      S t        | ||      }|S )zn
    Thin wrapper around torch._C._add_batch_dim that is used to proxy in
    PT2 export/compile fx graph
    r   +_maybe_find_pre_dispatch_tf_mode_for_export)torch._export.utilsr	   torch	overrideshandle_torch_functionr   _add_batch_dim_impl)self	batch_dimlevelr	   moderess         V/var/www/html/engine/venv/lib/python3.12/site-packages/torch/_functorch/predispatch.pyr   r      sL    
 P68D44TGT9e
 	
 dIu
5CJ    c                     ddl m}  |       }|r)t        j                  j	                  t
        | f| |||      S t        | |||      }|S )zq
    Thin wrapper around torch._C._remove_batch_dim that is used to proxy in
    PT2 export/compile fx graph
    r   r   )r
   r	   r   r   r   r   _remove_batch_dim_impl)r   r   
batch_sizeout_dimr	   r   r   s          r   r   r   )   sP    
 P68D44weZ
 	
 !uj'
BCJr   c                     ddl m}  |       }|r't        j                  j	                  t
        | f| |      S t        | |      }|S )p
    Thin wrapper around torch._C._vmap_increment_nesting that is used
    to proxy in export/compile graph
    r   r   )r
   r	   r   r   r   r   _vmap_increment_nesting_impl)r   
randomnessr	   r   r   s        r   r   r   ;   sH    
 P68D44#j]J

 	
 'z:
>CJr   c                  |    ddl m}   |        }|r$t        j                  j	                  t
        d      S t               S )r   r   r    )r
   r	   r   r   r   r   _vmap_decrement_nesting_impl)r	   r   s     r   r   r   L   s;    
 P68D44#
 	
 ())r   Fc                      ddl m}   |        }|r$t        j                  j	                  t
        d      S t        ryt        ddl}|j                         at        5  t        r
	 ddd       yddl
}|j                  j                  dd      dk(  rnda	 ddd       yt        j                  j                  dd	d
      addlm fd} |t        j$                  j&                  j(                  j*                          |t        j$                  j&                  j,                  j*                          |t        j$                  j&                  j.                  j*                          |t        j$                  j&                  j0                  j*                          |t        j$                  j&                  j2                  j*                          |t        j$                  j&                  j4                  j*                          |t        j$                  j&                  j6                  j*                          |t        j$                  j&                  j8                  j*                         daddd       y# 1 sw Y   yxY w)zH
    Lazy loading of vmap decompositions with pre-dispatch support.
    r   r   r   NPYTORCH_JIT1TatenIMPLFuncTorchBatched)decomposition_tablec                 \    | v rt         j                  | |           y t        d|        )Nz!could not find decomposition for )VMAP_DECOMPOSITIONS_LIBimplRuntimeError)decompr'   s    r   #_register_python_decomposition_vmapzElazy_load_decompositions.<locals>._register_python_decomposition_vmap   s5    ,,',,V5H5PQ"%Fvh#OPPr   )r
   r	   r   r   r   lazy_load_decompositionsDECOMPOSITIONS_LOADEDDECOMPOSITIONS_LOCK	threadingLockosenvirongetlibraryLibraryr)   torch._decompr'   opsr$   mse_loss_backwarddefaultsmooth_l1_loss_backwardhuber_loss_backwardnll_loss_forwardnll_loss2d_forwardnll_loss_backwardnll_loss2d_backwardaddr)r	   r   r1   r3   r-   r'   s        @r   r.   r.   c   s    P68D445MrRR  "'nn.	 %% %% %% 	

}c2c9i$(!%% %% #(--"7"7F.#
 	6	Q 	,EIINN,L,L,T,TU+IINN22::	
 	,EIINN,N,N,V,VW+EIINN,K,K,S,ST+EIINN,M,M,U,UV+EIINN,L,L,T,TU+EIINN,N,N,V,VW+EIINN,?,?,G,GH $K%% %% %%s   I4-'I4GI44I=)__doc__r   torch._C._functorchr   r   r   r   r   r    r   r   r/   r0   r)   r.   r   r   r   <module>rE      sF   
  $$"*$    ;%r   