o
    i                  	   @   sj   d dl mZmZmZmZmZ ddlmZmZ ddl	m
Z
 ede
dZ	dded	d
dee defddZdS )    )AnyCallableOptionalTupleTypeVar   )has_os_signpostos_signpost)Model_ModelT)boundNlayer
signposterzos_signpost.Signposternamereturnc              
      s   t std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 init, forward and backprop phases using
    signpost intervals for macOS Instruments profiling

    By default, the name of the layer is used as the name of the range,
    followed by the name of the pass.
    z?with_signpost_interval layer requires the 'os_signpost' packageNmodelXis_trainr   c                    sd     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<     d  | W  d    S 1 sw   Y  d S )Nz	 backpropuse_interval)r   )layer_callbackr   r    W/home/ubuntu/.local/lib/python3.10/site-packages/thinc/layers/with_signpost_interval.pybackprop"   s   $z9with_signpost_interval.<locals>.forward.<locals>.backprop)r   r   )r   r   r   layer_Yr   )r   orig_forwardr   )r   r   forward   s
   z'with_signpost_interval.<locals>.forward_modelYc                    sL   d ur$  d  ||W  d    S 1 sw   Y  d S  S )Nz initr   )r   r   r   )r   r   	orig_initr   r   r   init(   s
   
$z$with_signpost_interval.<locals>.init)r!   )r   
ValueErrorr   _funcr!   r
   r   boolr   r   replace_callbacks)r   r   r   r   r!   r   )r   r   r   r    r   r   with_signpost_interval	   s   *$
r&   )N)typingr   r   r   r   r   compatr   r	   r   r
   r   strr&   r   r   r   r   <module>   s    