
    h                     z    S SK JrJrJrJrJr  SSKJr  SSKJ	r	  \" S\S9r
 SSSS	.S
\
S\\   S\S\S\
4
S jjjrg)    )AnyCallableOptionalTupleTypeVar   )Modeluse_nvtx_range_ModelT)boundN)forward_colorbackprop_colorlayernamer   r   returnc          
      $  ^ ^^^^^ Tc  T R                   OTmT R                  mT R                  mS[        S[        S[
        S[        [        [        4   4UUUU4S jjnS[        S[        S[        S[        4U U4S jjnT R                  XES	9  T $ )
zWraps any layer and marks the forward and backprop phases as
NVTX ranges for CUDA profiling.

By default, the name of the layer is used as the name of the range,
followed by the name of the pass.
modelXis_trainr   c                    >^ [        T S3T5         T	" XUS9u  nmS S S 5        S[        S[        4UUU4S jjnWU4$ ! , (       d  f       N(= f)Nz forward)r   dYr   c                 h   > [        T S3T5         T" U 5      sS S S 5        $ ! , (       d  f       g = f)Nz	 backpropr
   )r   r   layer_callbackr   s    V/home/james-whalen/.local/lib/python3.13/site-packages/thinc/layers/with_nvtx_range.pybackprop2with_nvtx_range.<locals>.forward.<locals>.backprop   s)    4&	 2NC%b) DCCs   #
1)r   r   )
r   r   r   layer_Yr   r   r   r   r   orig_forwards
        @r   forward with_nvtx_range.<locals>.forward   sX    tfH-}=&25h&O#G^ >	* 	* 	* 	*    >=s	   ?
A_modelYc                     > Tb	  T" TX5      $ T$ N )r#   r   r$   r   	orig_inits      r   initwith_nvtx_range.<locals>.init%   s     UA))L    )r)   )	r   _funcr)   r	   r   boolr   r   replace_callbacks)r   r   r   r   r!   r)   r    r(   s   ````  @@r   with_nvtx_ranger/   	   s     5::4D;;L

I!u ! ! !sH}9M ! !U s s u   
G/Lr+   r&   )typingr   r   r   r   r   r   r	   utilr   r   strintr/   r'   r+   r   <module>r4      sf    : :  !
)5
)
 $ $$
3-$ 	$
 $ $r+   