a
    5Df                  X   @   s  d dl mZ d dlT d dlT ddlmZmZmZ eej	edk rVe
djej	d ejZejeejeejeejeejeejeejeejeejeejeejeejeejeej eej!e"ej#e$ej%eej&eej'e(ej)eej*eej+eej,eej-eej.eej/e0ej1e0ej2e0ej3e4ej5e4ej6e4ej7e8ej9eej:e;ej<e;ej=e;ej>e?ej@eAejBeCejDeEejFeGejHeIejJeejKei,ZLeej	edkreLMejNei dddZOdejPdddZQd	S )    )LooseVersion)*   )prGreenprRedprYellowz1.0.0zLYou are using an old version PyTorch {version}, which THOP does NOT support.)versionz1.1.0NTFc                    sF  g t   d u ri  rd fdd}| j}|   | | t  | |  W d    n1 sp0    Y  d}d}|  D ].}	tt|		 dkrq||	j
7 }||	j7 }q| }| }| | D ]}
|
  q|  D ]N\}}	tt|		 dkrqd|	jv r&|	jd d|	jv r|	jd q||fS )NTc                    sF  t t|  dkrd S t| ds,t| dr>tdt|   | dtj	dt
d | dtj	dt
d |  D ]}|  jt| g7  _qrt| }d }| v rΈ | }|vr̈rtd|j|f  nL|tv rt| }|vrrtd|j|f  n|vrrtd	|  |d ur8| |}| | d S )
Nr   	total_opstotal_paramsznEither .total_ops or .total_params is already defined in %s. Be careful, it might change your code's behavior.r   Zdtype[INFO] Customize rule %s() %s.[INFO] Register %s() for %s.F[WARN] Cannot find rule for %s. Treat it as zero Macs and zero Params.)lenlistchildrenhasattrloggingwarningstrregister_buffertorchzerosdefault_dtype
parametersr
   ZDoubleTensorZnumeltypeprint__qualname__register_hooksr   register_forward_hookappendadd)mpm_typefnhandler
custom_opshandler_collectionreport_missingtypes_collectionverbose Y/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/thop/profile.py	add_hooksP   sB    


z!profile_origin.<locals>.add_hooksr   r	   r
   )settrainingevalapplyr   no_gradmodulesr   r   r   r	   r
   itemtrainremoveZnamed_modules_bufferspop)modelinputsr(   r,   r*   r/   r1   r	   r
   r"   r&   nr-   r'   r.   profile_originH   s@    )

&



r>   )r;   c                    s  i t   d u ri  rdtjd fdd}| j}|   | | t  | |  W d    n1 sx0    Y  dtjttfdfdd| \}}	}
| 	| 
 D ]4\}\}}|  |  |jd	 |jd
 q|r||	|
fS ||	fS )NT)r"   c                    s   |  dtjdtjd |  dtjdtjd t| }d }| v rl | }|vrrtd|j|f  nH|tv rt| }|vrrtd|j|f  n|vrrtd|  |d ur| 	|| 	t
f| < | d S )Nr	   r   r   r
   r   r   r   )r   r   r   float64r   r   r   r   r   r   Zcount_parametersr!   )r"   r$   r%   r'   r-   r.   r/      s.    zprofile.<locals>.add_hooks	)modulereturnc           
         s   | j  d }}i }|  D ]r\}}i }|v rZt|tjtjfsZ|j  |j  }}	n ||d d\}}	}||	|f||< ||7 }||	7 }q|||fS )Nr   r@   )prefix)r	   r6   Znamed_children
isinstancenn
SequentialZ
ModuleListr
   )
rA   rC   r	   r
   ret_dictr=   r"   Z	next_dictZm_opsZm_params)	dfs_countr)   r-   r.   rH      s    

zprofile.<locals>.dfs_countr	   r
   )r@   )r0   rE   Moduler1   r2   r3   r   r4   intr7   itemsr8   r9   r:   )r;   r<   r(   r,   Zret_layer_infor*   r/   Zprev_training_statusr	   r
   rG   r"   Z
op_handlerZparams_handlerr-   )r(   rH   r)   r*   r+   r,   r.   profile   s.    !

&

rL   )NTF)NTFF)RZdistutils.versionr   Zthop.vision.basic_hooksZthop.rnn_hooksutilsr   r   r   r   __version__r   r   formatr?   r   rE   Z	ZeroPad2dZzero_opsZConv1dZcount_convNdZConv2dZConv3dZConvTranspose1dZConvTranspose2dZConvTranspose3dZBatchNorm1dZcount_normalizationZBatchNorm2dZBatchNorm3dZ	LayerNormZInstanceNorm1dZInstanceNorm2dZInstanceNorm3dZPReLUZcount_preluZSoftmaxZcount_softmaxZReLUZReLU6Z	LeakyReLUZ
count_reluZ	MaxPool1dZ	MaxPool2dZ	MaxPool3dZAdaptiveMaxPool1dZAdaptiveMaxPool2dZAdaptiveMaxPool3dZ	AvgPool1dZcount_avgpoolZ	AvgPool2dZ	AvgPool3dZAdaptiveAvgPool1dZcount_adap_avgpoolZAdaptiveAvgPool2dZAdaptiveAvgPool3dZLinearZcount_linearZDropoutZUpsampleZcount_upsampleZUpsamplingBilinear2dZUpsamplingNearest2dZRNNCellZcount_rnn_cellZGRUCellZcount_gru_cellZLSTMCellZcount_lstm_cellZRNNZ	count_rnnZGRUZ	count_gruZLSTMZ
count_lstmrF   ZPixelShuffler   updateZSyncBatchNormr>   rI   rL   r-   r-   r-   r.   <module>   s   /
X    