o
    i                     @   sr   d dl mZmZmZmZmZ ddlmZ ddlm	Z	 ededZ
	dddd	d
e
dee dedede
f
ddZdS )    )AnyCallableOptionalTupleTypeVar   )Modeluse_nvtx_range_ModelT)boundN)forward_colorbackprop_colorlayernamer   r   returnc             
      s|   du rj njjdtdtdtdtttf f fdd}dtdtd	tdtffd
d}j||d S )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.
    NmodelXis_trainr   c                    sd   t  d | ||d\} W d    n1 sw   Y  dtdtf fdd}||fS )Nz forward)r   dYr   c                    s<   t  d  | W  d    S 1 sw   Y  d S )Nz	 backpropr	   )r   )r   layer_callbackr    P/home/ubuntu/.local/lib/python3.10/site-packages/thinc/layers/with_nvtx_range.pybackprop   s   $z2with_nvtx_range.<locals>.forward.<locals>.backprop)r
   r   )r   r   r   layer_Yr   )r   r   r   orig_forward)r   r   forward   s
   z with_nvtx_range.<locals>.forward_modelYc                    s   d ur
 ||S  S Nr   )r   r   r   )r   	orig_initr   r   init%   s   zwith_nvtx_range.<locals>.init)r"   )	r   _funcr"   r   r   boolr   r   replace_callbacks)r   r   r   r   r   r"   r   )r   r   r   r   r   r!   r   with_nvtx_range	   s   , 
r&   r    )typingr   r   r   r   r   r   r   utilr
   r   strintr&   r   r   r   r   <module>   s&    