
    9jK                        U d Z ddlmZ ddlmZ ddlZddlmZm	Z
mZmZ erddlZddZ	 	 	 	 	 	 	 	 	 	 ddZ	ddZdd	Zd
aded<   daded<   daded<   d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.
    )annotations)TYPE_CHECKINGN)_add_batch_dim_remove_batch_dim_vmap_decrement_nesting_vmap_increment_nestingc                    ddl m}  |       }|dk  r| j                  |z   n|}|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   ndimtorch	overrideshandle_torch_functionr   _add_batch_dim_impl)self	batch_dimlevelr   moderess         \/media/conek/DATA/Code/OCR/venv/lib/python3.12/site-packages/torch/_functorch/predispatch.pyr   r      sb    
 P68D)2Q		I%II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   0   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   D   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   U   s;    
 P68D44#
 	
 ())r   FboolDECOMPOSITIONS_LOADEDzthreading.Lock | NoneDECOMPOSITIONS_LOCKztorch.library.Library | NoneVMAP_DECOMPOSITIONS_LIBc                    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 d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                ~    t         t        d      | v rt         j                  | |           y t        d|        )Nz(VMAP_DECOMPOSITIONS_LIB must not be Nonez!could not find decomposition for )r'   AssertionErrorimplRuntimeError)decompr.   s    r   #_register_python_decomposition_vmapzElazy_load_decompositions.<locals>._register_python_decomposition_vmap   sG    &.$%OPP,,',,V5H5PQ"%Fvh#OPPr   )r3   ztorch._ops.OpOverloadreturnNone)r   r   r   r   r   lazy_load_decompositionsr%   r&   	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   r8   r:   r4   r.   s        @r   r7   r7   l   s    P68D445MrRR  ",inn.	 '% '% '% 	

}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 $O'% '% '%s   I6.'I6GI66I?)r   torch.Tensorr   intr   rK   r5   rJ   )
r   rJ   r   rK   r   rK   r   rK   r5   rJ   )r   rK   r    strr5   rK   )r5   rK   )r5   r6   )__doc__
__future__r   typingr   r   torch._C._functorchr   r   r   r   r   r#   r   r   r8   r%   __annotations__r&   r'   r7   r"   r   r   <module>rR      s   
 #     &
"03>A("*$ $ t #-1 * 18< 5 <=%r   