o
    NeÝ	  ã                   @   sB   d dl Z d dlZd dlmZmZ G dd„ dƒZdd„ Zdd„ ZdS )	é    N)Údefault_main_programÚ_non_static_modec                   @   s   e Zd ZdZddd„ZdS )ÚLayerOpsRecoderz=
    Record generated operators information in nn.Layer.
    éÿÿÿÿNFc                 C   s"   || _ || _|| _|| _|| _d S )N)ÚstartÚendÚopsÚis_validÚhooks)Úselfr   r   r   r	   r
   © r   úPD:\Projects\ConvertPro\env\Lib\site-packages\paddle/fluid/dygraph/layer_hooks.pyÚ__init__   s
   
zLayerOpsRecoder.__init__)r   r   NFN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s    r   c                 C   sP   t ƒ s&| jjdk rttƒ  ¡ jƒ| j_d| j_dS d| j_t 	d 
| j¡¡ dS )zC
    A pre-hook to mark op numbers before enter layer.forward.
    r   TFzZ{} has recorded the op information before. Please check whether you call this layer twice.N)r   Ú_op_recorderr   Úlenr   Úcurrent_blockr   r	   ÚwarningsÚwarnÚformatZ
_full_name)ÚlayerÚinputsr   r   r   Úrecord_program_ops_pre_hook"   s   
ÿûþr   c           
      C   s¤   t ƒ sP| jjrP| jj}ttƒ  ¡ jƒ}|dkr||ksJ ‚tƒ  ¡ j||… }|| j_|| j_|D ]}t	 
| j¡D ]
\}}| ||¡ q9q1| jjD ]}	|	 ¡  qIdS )zd
    A post-hook to append customized attributes into all operators generated in current layer.
    r   N)r   r   r	   r   r   r   r   r   r   ÚsixÚ	iteritemsZ_customized_attrsZ	_set_attrr
   Úremove)
r   r   Zoutputsr   r   r   ÚopZ	attr_nameÚvalZhook_helperr   r   r   Ú!set_op_customized_attrs_post_hook4   s   ÿ
r!   )r   r   Zpaddle.fluid.frameworkr   r   r   r   r!   r   r   r   r   Ú<module>   s   