a
    f                  Z   @   sT  d dl T d dlT ddlmZ 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'e(ej)e(ej*e(ej+e,ej-e,ej.e,ej/e0ej1e	ej2e3ej4e3ej5e3ej6e7ej8e9ej:e;ej<e=ej>e?ej@eAejBe	ejCe	ejDei-ZEdddZFdejGd	d
dZHdS )    )*   )prRedNTFc                    s4  g t   du ri  rd fdd}| j}|   | | t  | |  W d   n1 sp0    Y  d}d}|  D ]&}	t|	 rq||	j	7 }||	j
7 }q| }| }| | D ]}
|
  q|  D ]D\}}	t|	 rqd|	jv r|	jd d|	jv r|	jd q||fS )z^Profiles a PyTorch model's operations and parameters, applying either custom or default hooks.NTc                    sT  t |  rd S t| ds$t| dr6tdt|   | dtjdt	d | dtjdt	d | 
 D ]}|  jt| g7  _qjt| }d }| v r̈ | }|vrʈrtd|j d| d n\|tv rt| }|vr(r(td	|j d
| d n |vr(r(td| d |d urF| |}| | d S )N	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 () .[INFO] Register () for [WARN] Cannot find rule for (. Treat it as zero Macs and zero Params.)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 H/var/www/html/django/DPS/env/lib/python3.9/site-packages/thop/profile.py	add_hooksB   s8    



z!profile_origin.<locals>.add_hooksr   r   r   )settrainingevalapplyr   no_gradmodulesr   r   r   r   itemtrainremoveZnamed_modules_bufferspop)modelinputsr'   r+   r)   r.   r0   r   r   r!   r%   nr,   r&   r-   profile_origin9   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 )zdProfiles a PyTorch model, returning total operations, parameters, and optionally layer-wise details.NT)r!   c                    s   |  dtjdtjd |  dtjdtjd t| }d}| v rr | }|vrĈrtd|j d| d nR|tv rt| }|vrĈrtd	|j d
| d n|vrĈrtd| d |dur| 	|| 	t
f| < | dS )zTRegisters hooks to a neural network module to track total operations and parameters.r   r   r   r   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 )zfRecursively counts the total operations and parameters of the given PyTorch module and its submodules.r   r?   )prefix)r   r5   Znamed_children
isinstancenn
SequentialZ
ModuleListr   )
r@   rB   r   r   ret_dictr<   r!   Z	next_dictZm_opsZm_params)	dfs_countr(   r,   r-   rG      s    
zprofile.<locals>.dfs_countr   r   )r?   )r/   rD   Moduler0   r1   r2   r   r3   intr6   itemsr7   r8   r9   )r:   r;   r'   r+   Zret_layer_infor)   r.   Zprev_training_statusr   r   rF   r!   Z
op_handlerZparams_handlerr,   )r'   rG   r(   r)   r*   r+   r-   profile   s.    	

&

rK   )NTF)NTFF)IZthop.rnn_hooksZthop.vision.basic_hooksutilsr   r   r>   r   rD   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_lstmrE   ZPixelShuffleZSyncBatchNormr   r=   rH   rK   r,   r,   r,   r-   <module>   sr   1
T    