Ë
    Dêñig  ã                   óŒ  — d dl Z d dlmZ d dlmZ dd„Zdej                  de j                  de j                  fd„Zdd„Z	dej                  de j                  de j                  fd	„Zdd
„Zdej                  de j                  de j                  fd„Zdej                  fd„Zdej"                  fd„Zdej&                  fd„Zy)é    N)ÚPackedSequencec                 ó0   — || |z   z  |z   }|r||dz  z  }|S )z`Calculate the total operations for an RNN cell given input size, hidden size, and optional bias.é   © )Ú
input_sizeÚhidden_sizeÚbiasÚ	total_opss       úP/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/thop/rnn_hooks.pyÚ_count_rnn_cellr      s-   € à˜z¨KÑ7Ñ8¸;ÑF€IÙØ�[ 1‘_Ñ$ˆ	àÐó    ÚmÚxÚyc                 óð   — t        | j                  | j                  | j                  «      }|d   j	                  d«      }||z  }| xj
                  t        j                  t        |«      g«      z  c_        y)z^Counts the total RNN cell operations based on input tensor, hidden size, bias, and batch size.r   N)	r   r   r   r	   Úsizer
   ÚtorchÚDoubleTensorÚint©r   r   r   r
   Ú
batch_sizes        r   Úcount_rnn_cellr      óW   € ä §¡¨a¯m©m¸Q¿V¹VÓD€Ià�1‘—‘˜1“€JØ�Ñ€Ià‡K‚K”5×%Ñ%¤s¨9£~Ð&6Ó7Ñ7†Kr   c                 óŽ   — d}|| z   |z  |z   }|r||dz  z  }||dz  z  }||| z   |z  |z   z  }|r||dz  z  }||z  }||dz  z  }|S )zdCounts the total operations for a GRU cell based on input size, hidden size, and bias configuration.r   r   é   r   ©r   r   r	   r
   Ú	state_opss        r   Ú_count_gru_cellr      sˆ   € à€Ið ˜zÑ)¨[Ñ8¸;ÑF€IÙØ�[ 1‘_Ñ$ˆ	Ø�˜Q‘Ñ€Ið �+ 
Ñ*¨kÑ9¸KÑGÑG€IÙØ�[ 1‘_Ñ$ˆ	à�Ñ€Ið �˜q‘Ñ €IàÐr   c                 óð   — t        | j                  | j                  | j                  «      }|d   j	                  d«      }||z  }| xj
                  t        j                  t        |«      g«      z  c_        y)z\Calculates and updates the total operations for a GRU cell in a mini-batch during inference.r   N)	r   r   r   r	   r   r
   r   r   r   r   s        r   Úcount_gru_cellr    3   r   r   c                 ó^   — d}| |z   |z  |z   }|r||dz  z  }||dz  z  }||dz  z  }||z  }|S )zfCounts LSTM cell operations during inference based on input size, hidden size, and bias configuration.r   r   é   r   r   r   s        r   Ú_count_lstm_cellr#   =   s^   € à€Ið ˜kÑ)¨[Ñ8¸;ÑF€IÙØ�[ 1‘_Ñ$ˆ	Ø�˜Q‘Ñ€Ið �˜q‘Ñ €Ið �Ñ€IàÐr   c                 óð   — t        | j                  | j                  | j                  «      }|d   j	                  d«      }||z  }| xj
                  t        j                  t        |«      g«      z  c_        y)zZCounts and updates the total operations for an LSTM cell in a mini-batch during inference.r   N)	r#   r   r   r	   r   r
   r   r   r   r   s        r   Úcount_lstm_cellr%   T   sW   € ä  §¡¨q¯}©}¸a¿f¹fÓE€Ià�1‘—‘˜1“€JØ�Ñ€Ià‡K‚K”5×%Ñ%¤s¨9£~Ð&6Ó7Ñ7†Kr   c                 ó&  — | j                   }| j                  }| j                  }| j                  }t	        |d   t
        «      rAt        j                  |d   j                  «      }|d   j                  j                  d«      }n]| j                  r)|d   j                  d«      }|d   j                  d«      }n(|d   j                  d«      }|d   j                  d«      }d}	| j                  r|	t        |||«      dz  z  }	n|	t        |||«      z  }	t        |dz
  «      D ]1  }
|	| j                  rt        |dz  ||«      dz  nt        |||«      z  }	Œ3 |	|z  }	|	|z  }	| xj                  t        j                  t!        |	«      g«      z  c_        y)zWCalculate and update the total number of operations for each RNN cell in a given batch.r   é   r   N)r	   r   r   Ú
num_layersÚ
isinstancer   r   ÚmaxÚbatch_sizesr   Úbatch_firstÚbidirectionalr   Úranger
   r   r   ©r   r   r   r	   r   r   r(   r   Ú	num_stepsr
   Ú_s              r   Ú	count_rnnr2   ^   ój  € à�6‰6€DØ—‘€JØ—-‘-€KØ—‘€Jä�!�A‘$œÔ'Ü—Y‘Y˜q ™t×/Ñ/Ó0ˆ
Ø�a‘D×$Ñ$×)Ñ)¨!Ó,‰	Ø	
�ŠØ�q‘T—Y‘Y˜q“\ˆ
Ø�a‘D—I‘I˜a“L‰	à�q‘T—Y‘Y˜q“\ˆ
Ø�a‘D—I‘I˜a“Lˆ	à€IØ‡‚Ø”_ Z°¸dÓCÀaÑGÑG‰	à”_ Z°¸dÓCÑCˆ	ä�: ‘>Ó"ò 
ˆØà�Šô ˜K¨!™O¨[¸$Ó?À!ÒCä  ¨k¸4Ó@ñ	
‰	ð
ð �Ñ€Ià�Ñ€Ià‡K‚K”5×%Ñ%¤s¨9£~Ð&6Ó7Ñ7†Kr   c                 ó&  — | j                   }| j                  }| j                  }| j                  }t	        |d   t
        «      rAt        j                  |d   j                  «      }|d   j                  j                  d«      }n]| j                  r)|d   j                  d«      }|d   j                  d«      }n(|d   j                  d«      }|d   j                  d«      }d}	| j                  r|	t        |||«      dz  z  }	n|	t        |||«      z  }	t        |dz
  «      D ]1  }
|	| j                  rt        |dz  ||«      dz  nt        |||«      z  }	Œ3 |	|z  }	|	|z  }	| xj                  t        j                  t!        |	«      g«      z  c_        y)zfCalculates total operations for a GRU layer, updating the model's operation count based on batch size.r   r'   r   N)r	   r   r   r(   r)   r   r   r*   r+   r   r,   r-   r   r.   r
   r   r   r/   s              r   Ú	count_grur5   ƒ   r3   r   c                 ó&  — | j                   }| j                  }| j                  }| j                  }t	        |d   t
        «      rAt        j                  |d   j                  «      }|d   j                  j                  d«      }n]| j                  r)|d   j                  d«      }|d   j                  d«      }n(|d   j                  d«      }|d   j                  d«      }d}	| j                  r|	t        |||«      dz  z  }	n|	t        |||«      z  }	t        |dz
  «      D ]1  }
|	| j                  rt        |dz  ||«      dz  nt        |||«      z  }	Œ3 |	|z  }	|	|z  }	| xj                  t        j                  t!        |	«      g«      z  c_        y)zgCalculate total operations for LSTM layers, including bidirectional, updating model's total operations.r   r'   r   N)r	   r   r   r(   r)   r   r   r*   r+   r   r,   r-   r#   r.   r
   r   r   r/   s              r   Ú
count_lstmr7   ¨   sl  € à�6‰6€DØ—‘€JØ—-‘-€KØ—‘€Jä�!�A‘$œÔ'Ü—Y‘Y˜q ™t×/Ñ/Ó0ˆ
Ø�a‘D×$Ñ$×)Ñ)¨!Ó,‰	Ø	
�ŠØ�q‘T—Y‘Y˜q“\ˆ
Ø�a‘D—I‘I˜a“L‰	à�q‘T—Y‘Y˜q“\ˆ
Ø�a‘D—I‘I˜a“Lˆ	à€IØ‡‚ØÔ% j°+¸tÓDÀqÑHÑH‰	àÔ% j°+¸tÓDÑDˆ	ä�: ‘>Ó"ò 
ˆØà�Šô ˜[¨1™_¨k¸4Ó@À1ÒDä! +¨{¸DÓAñ	
‰	ð
ð �Ñ€Ià�Ñ€Ià‡K‚K”5×%Ñ%¤s¨9£~Ð&6Ó7Ñ7†Kr   )T)r   Útorch.nnÚnnÚtorch.nn.utils.rnnr   r   ÚRNNCellÚTensorr   r   ÚGRUCellr    r#   ÚLSTMCellr%   ÚRNNr2   ÚGRUr5   ÚLSTMr7   r   r   r   ú<module>rB      sÃ   ðó Ý Ý -óð8�b—j‘jð 8 U§\¡\ð 8°e·l±ló 8óð08�b—j‘jð 8 U§\¡\ð 8°e·l±ló 8óð.8�r—{‘{ð 8 u§|¡|ð 8¸¿¹ó 8ð"8�—‘ó "8ðJ"8�—‘ó "8ðJ"8�"—'‘'ô "8r   