
    ёi,                     r   S SK r 0 qS rS\S\S\S\4S jrS r\" S	5      S
 5       r\" S5      S 5       r	\" S5      S 5       r
S r\" S5      S 5       r\" S5      S 5       r\" S5      S 5       r\" S5      S 5       r\" S5      S 5       r\" S5      S 5       r\" S5      S 5       rS r\" S5      S  5       r\" S!5      S" 5       r\" S#5      S$ 5       r\" S%5      S& 5       r\" S'5      S( 5       r\" S)5      S* 5       r\" S+5      S, 5       r\" S-5      S. 5       r\" S/5      S0 5       r\" S15      S2 5       rg)3    Nc                 $    SnU  H  nX-  nM	     U$ )N    )spvs      R/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/utils/flops.pyprodr
      s    	A	 H    op_typeinput_shapesattrsreturnc                 n    U [         ;  a  g[         U    n U" X5      nU$ ! [         a
  n SnAgSnAff = f)z
count FLOPs for operation.

Args:
    op_type (str): the type of operation.
    input_shapes (dict): the shapes of inputs.
    attrs (dict): the attributes of the operation.

Returns:
    the total FLOPs of the operation.
r   N)_FLOPS_COMPUTE_FUNC_MAP	Exception)r   r   r   funcflopses         r	   r   r      sE     --&w/	-E   		s     
44c                    ^  U 4S jnU$ )z4
register flops computation function for operation.
c                    > U [         T'   U $ N)r   )r   r   s    r	   register register_flops.<locals>.register8   s    +/(r   r   )r   r   s   ` r	   register_flopsr   3   s    

 Or   c_embeddingc                     g)zVFLOPs computation for c_embedding op.
For c_embedding(input):
    equation: flops = 0
r   r   r   r   s     r	   _c_embedding_flopsr   @        r   conv2dc                 p   [        U R                  S5      5      S:  a  U R                  S5      S   OSnU R                  S5      S   nU R                  S5      S   nUR                  S5      nUR                  S5      nUR                  S5      nUR                  S	5      nUS   n	US
   n
US   n[        USS 5      n[        USS 5      n[        U5      n[        U[        5      (       a  UOU/U-  n[        U[        5      (       a  UOU/U-  n[        U[        5      (       a  UOU/U-  n/ n[	        U5       H=  u  nnUSUU   -  -   UU   UU   S
-
  -  S
-   -
  UU   -  S
-   nUR                  U5        M?     X-  n[        U5      U
-  U-  nU	[        U5      -  nUU-  nSU-  nSnUb  UU-  nUU-   $ )a  FLOPs computation for conv2d op.
For conv2d(input,filter):
    active_elements = batch_size * numel(output)
    conv_flops = 2 * macs_per_position_conv * active_elements
    bias_flops = out_channels * active_elements
    equation: flops = conv_flops + bias_flops
Biasr   NInputFilterpaddingsstrides	dilationsgroupsr      )lengetlist
isinstance	enumerateappendr
   )r   r   biasinputweightpaddingstridedilationr)   
batch_sizein_channelsout_channelskernel_dims
input_dimslengthr&   r'   r(   output_dimsidx	input_dim
output_dimfilters_per_channelmacs_conv_per_positionactive_elementsoverall_conv_macsoverall_conv_flopsoverall_bias_flopss                               r	   _conv2d_flopsrG   I   sM    |'(1, 	 # 	
 W%a(Eh'*Fii
#GYYy!Fyy%HYYx FqJ(K!9Lvabz"KeABiJ_F gt$$ 	 
   fd## 	 
   h%% 	 
   K#J/Y(3- ~S!1A!56:< S\	 	

 	:& 0 '0[K'*==  !4#44O.@..)O; 222r   dropoutc                     g)zNFLOPs computation for dropout op.
For dropout(input):
    equation: flops = 0
r   r   r   s     r	   _dropout_flopsrJ      r    r   c                 J   U R                  S5      S   nU R                  S5      S   n[        U5      n[        U5      n[        XE5      n/ n[        U5       H?  nX:  a
  X$S-
  U-
     OSn	X:  a
  X5S-
  U-
     OSn
UR	                  [        X5      5        MA     [        U5      $ )NXr   Yr   )r,   r+   maxranger0   r
   )r   r   input_xinput_ydim_xdim_y
dim_outputoutputiin_xin_ys              r	   _elementwise_flops_computerY      s    s#A&Gs#A&GLELEU"JF:)*wqy1}%)*wqy1}%c$o&  <r   elementwise_addc                     [        X5      $ )a  FLOPs computation for elementwise_add op.
For elementwise_add(input,other):
    input_shapes = [shape_of_input, shape_of_other]
    shape_of_input = [dim1, dim2, dim3 ...]
    shape_of_other = [odim1, odim2, odim3...]
    equation: flops = max(dim1, odim1) * max(dim2, odim2) * max()...
rY   r   s     r	   _elementwise_add_flopsr]           &l::r   elementwise_mulc                     [        X5      $ )a  FLOPs computation for elementwise_mul op.
For elementwise_mul(input,other):
    input_shapes = [shape_of_input, shape_of_other]
    shape_of_input = [dim1, dim2, dim3 ...]
    shape_of_other = [odim1, odim2, odim3...]
    equation: flops = max(dim1, odim1) * max(dim2, odim2)* max()...
r\   r   s     r	   _elementwise_mul_flopsra      r^   r   elementwise_divc                     [        X5      $ )a  FLOPs computation for elementwise_div op.
For elementwise_div(input,other):
    input_shapes = [shape_of_input, shape_of_other]
    shape_of_input = [dim1, dim2, dim3 ...]
    shape_of_other = [odim1, odim2, odim3...]
    equation: flops = max(dim1,odim1)*max(dim2,odim2)*max()...
r\   r   s     r	   _elementwise_div_flopsrd      r^   r   geluc                 F    U R                  S5      S   n[        U5      S-  $ )zFLOPs computation for gelu op.
For gelu(input):
    equation: flops = 5 * (numel)total number of elements in the input tensor.
rL   r      r,   r
   r   r   r2   s      r	   _gelu_flopsrj      '     S!!$E;?r   
layer_normc                     U R                  S5      S   n[        U5      S-  nUR                  S5      (       a  U[        U5      -  nU$ )zFLOPs computation for layer_norm op.
For layer_norm(input):
    equation:
    1): WITHOUT epsilon flops = 7 * (numel)total number of elements in the input tensor.
    2): WITH epsilon flops = 8 * (numel)total number of elements in the input tensor.
rL   r      epsilonrh   )r   r   r2   r   s       r	   _layer_norm_flopsrp      sH     S!!$EK!OEyyeLr   matmulc           	          [         R                  " U R                  SU R                  SS//5      5      S   5      n[         R                  " U R                  SU R                  SS//5      5      S   5      nUR                  S5      (       d  UR                  S5      (       a  US   US	   sUS	'   US'   UR                  S
5      (       d  UR                  S5      (       a  US   US	   sUS	'   US'   [        U5      n[        U5      n[	        XE5      n/ n[        USS	5       H9  nX::  a  X$U-
     OSn	X::  a  X5U-
     OSn
UR                  [	        X5      5        M;     [        U5      US   -  US	   -  US	   -  nSU-  $ )a  FLOPs computation for matmul op.
For matmul(input,other):
    input_shapes = [shape_of_input, shape_of_other]
    shape_of_input =                  [dim1,dim2 ...dim_n_1,dim_n]  length:n
    shape_of_other = [odim1,odim2 ... odim(n-m)... odim_m_1,dim_m]  length:m
    suppose n > m and dim_n = odim_m_1:
    shape_of_output = [dim1, dim2 ... max(dim(n-m), odim(n-m)), max(dim(n-m+1), odim(n-m+1)) ... dim_n_1, dim_m]
    equation: flops = 2 * numel(output) * dim_n
rL   xr   rM   ytranspose_Xtranspose_xtranspose_Ytranspose_yr*   r   copydeepcopyr,   r+   rN   rO   r0   r
   r   r   x_shapey_shaperR   rS   
output_lenoutput_shaper>   x_idxy_idxmacss               r	   _matmul_flopsr      s}    mml..saSE:;A>G mml..saSE:;A>G yy599]#;#;#*2; WR[yy599]#;#;#*2; WR[LELEU"JLZB'(+$!(+$!C-. (
 +gbk9GBKGDt8Or   	matmul_v2c                 \   [         R                  " U R                  S5      S   5      n[         R                  " U R                  S5      S   5      nUR                  S5      (       a  US   US   sUS'   US'   UR                  S5      (       a  US   US   sUS'   US'   [        U5      n[        U5      n[	        XE5      n/ n[        USS5       H9  nX::  a  X$U-
     OS	n	X::  a  X5U-
     OS	n
UR                  [	        X5      5        M;     [        U5      US   -  US   -  US   -  nSU-  $ )
a  FLOPs computation for matmul_v2 op.
For matmul_v2(input,other):
    input_shapes = [shape_of_input, shape_of_other]
    shape_of_input =                   [dim1, dim2 ...dim_n_1, dim_n] length:n
    shape_of_other = [odim1, odim2 ... odim(n-m) ... odim_m_1, dim_m] length:m
    suppose n > m and dim_n = odim_m_1:
    shape_of_output = [dim1, dim2 ... max(dim(n-m), odim(n-m)), max(dim(n-m+1), odim(n-m+1))...dim_n_1, dim_m]
    equation: flops = 2 * numel(outputs) * dim_n
rL   r   rM   trans_xrw   rx   trans_yr*   r   r{   r~   s               r	   _matmul_v2_flopsr     s1    mmL,,S1!45GmmL,,S1!45Gyy#*2; WR[yy#*2; WR[LELEU"JLZB'(+$!(+$!C-. (
 +gbk9GBKGDt8Or   c                 @    U R                  S5      S   n[        U5      $ )zFLOPs computation for relu_like ops.
For elu/leaky_relu/prelu/relu/relu6/silu (input):
    equation: flops = (numel)total number of elements in the input tensor.
rL   r   rh   ri   s      r	   _relu_class_flopsr   /  s#    
 S!!$E;r   eluc                     [        X5      $ r   r   r   s     r	   
_elu_flopsr   8      \11r   
leaky_reluc                     [        X5      $ r   r   r   s     r	   _leaky_relu_flopsr   =  r   r   preluc                     [        X5      $ r   r   r   s     r	   _prelu_flopsr   B  r   r   reluc                     [        X5      $ r   r   r   s     r	   _relu_flopsr   G  r   r   relu6c                     [        X5      $ r   r   r   s     r	   _relu6_flopsr   L  r   r   siluc                     [        X5      $ r   r   r   s     r	   _silu_flopsr   Q  r   r   reshape2c                     g)zPFLOPs computation for reshape2 op.
For reshape2(input):
    equation: flops = 0
r   r   r   s     r	   _reshape2_flopsr   V  r    r   softmaxc                 F    U R                  S5      S   n[        U5      S-  $ )zFLOPs computation for softmax op.
For softmax(input):
    equation: flops = 3 * (numel)total number of elements in the input tensor.
rL   r      rh   ri   s      r	   _softmax_flopsr   _  rk   r   
transpose2c                     g)zTFLOPs computation for transpose2 op.
For transpose2(input):
    equation: flops = 0
r   r   r   s     r	   _transpose2_flopsr   i  r    r   poolc                 @    U R                  S5      S   n[        U5      $ )z{FLOPs computation for pool op.
For pool(input):
    equation: flops = (numel)total number of elements in the input tensor.
rL   r   rh   ri   s      r	   _pool_flopsr   r  s#     S!!$E;r   )r|   r   r
   strdictintr   r   r   rG   rJ   rY   r]   ra   rd   rj   rp   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   <module>r      s@    3 d 4 C 0
   K3 K3\ 	  !"; #; !"; #; !"; #;     ! !H  : 2 2 2 2 2 2 2 2 2 2 2 2 
  	     r   