
    Fg                        S SK r S SKrS SKrS SKJr  S SKJr  \" \R                  5      \" S5      :  a   \ R                  " S\R                   S35        S r	S r
S rS	 rS
SKJr  S rS\R                   4S jrS\R                   4S jrS\R&                  4S jrS\R*                  4S jr\R.                  \R0                  \R2                  \R4                  \R6                  \R8                  4r\R<                  \\R&                  \\R*                  \S\S\	S\S\S\S\
S\
0
r\ H  r \\\ '   M
     0 r!S SK"J#r#  S SK$J%r%  S
SK&J'r'J(r(J)r)  S r*S)S\R                   S\RV                  4S  jjr,\-S!:X  a_   " S" S#\R                   5      r. " S$ S%\R                  R                   5      r/\/" 5       r0\Rb                  " S&S'5      r2\," \0\2SS(9r3\4" \35        gg)*    N)LooseVersionz1.8.0zVtorch.fx requires version higher than 1.8.0. But You are using an old version PyTorch z. c                     gNr    input_shapesoutput_shapess     `/Users/admin/workspace/ai/PDFMathTranslate/myenv/lib/python3.13/site-packages/thop/fx_profile.pycount_clampr              c                 (    US   R                  5       $ r   numelr   s     r
   	count_mulr      s    !!##r   c                 H    U S   nUS   nUS   nUR                  5       nXE-  $ )Nr   r   )r   r	   in_shape	out_shapein_featuresnum_elementss         r
   count_matmulr      s3    AHa I2,K??$L%%r   c                 N    [        X5      nSU;   a  US   R                  5       nU$ )Nbiasr   )r   r   )r   r	   argskwargs	mul_flops	add_flopss         r
   count_fn_linearr      s-    \9I!!$**,	r      )calculate_convc                    Uu  pEpgpn
[        U 5      S:X  a  U u  pO[        U 5      S:X  a  U u  pnUS   nWSS  R                  5       nSnWS   n[        UXR                  5       UU
5      R                  5       n[	        U5      $ )N      r   r    )lenr   r!   itemint)r   r	   r   r   inputsweightr   stridepaddingdilationgroupsx_shapek_shapeb_shaper   kernel_parametersbias_op
in_channel	total_opss                      r
   count_fn_conv2dr5   )   s    >B;FD'V
<A'	\	a	$0!'a I))+GJ"OO$5z6
df  y>r   modulec                     [        X5      $ N)r   )r6   r   r	   s      r
   count_nn_linearr9   ;   s    44r   c                     gr   r   )r6   r   r	   r   r   s        r
   count_zero_opsr;   ?   r   r   c                    U R                   b  SOSnUS   nU R                  nU R                  nU R                  R                  SS  R                  5       n[        X7UR                  5       XV5      R                  5       n[        U5      $ )Nr    r   r#   )	r   in_channelsr-   r)   shaper   r!   r&   r'   )	r6   r   r	   r2   r   r3   r-   
kernel_opsr4   s	            r
   count_nn_conv2dr@   C   s}    ;;*aGa I##J]]F$$QR(..0JY__.

df  y>r   c                 b    [        U5      S:X  d   S5       eUS   nSUR                  5       -  nU$ )Nr    z*nn.BatchNorm2d should only have one outputr   r#   )r%   r   )r6   r   r	   yr4   s        r
   count_nn_bn2drC   P   s:    }"P$PP"aAAGGIIr   zfunction linearclampzbuilt-in function addzbuilt-in method flz%built-in method conv2d of type objectzbuilt-in function mulzbuilt-in function truediv)symbolic_trace)	ShapeProp)prGreenprRedprYellowc                      g r8   r   )r   r   s     r
   
null_printrK   x   s    
r   Fmodinputc                    [        U 5      nUR                  n[        U5      R                  U5        [        nU(       a  [
        n0 nSnUR                  R                   GH  nU" SUR                   SUR                   SUR                   SUR                   35        S n	/ n
/ nU" SSS9  UR                   HE  n[        U5      U;  a  M  U" U[        U5          SS9  U
R                  U[        U5         5        MG     U" 5         U" S	UR                  S
   R                   35        UR                  UR                  S
   R                  5        UR                  S;   a  Sn	GOKUR                  S:X  a  [        UR                  5      R                  S5      S   R!                  SS5      R!                  SS5      R#                  5       nU[$        ;   a)  [$        U   " X/UR                  Q70 UR&                  D6n	GOUR                  U4[(        U'   [+        SU S35        GOUR                  S:X  aU  [        UR                  5      nU[$        ;   a  [$        U   " X5      n	GOMUR                  U4[(        U'   [+        U S35        GO(UR                  S:X  Ga  U R-                  UR                  5      n[/        U5      nU" [/        U5      [/        U5      [$        ;   5        [/        U5      [$        ;   a  [$        [/        U5         " XU5      n	O"UR                  4[(        U'   [+        U S35        [        S[/        U5      5        [1        U[2        5      (       a  [        S5        OJ[        [/        U5      5        [        SU R5                  5       UR                  S-      R                   35        UR                  S
   R                  U[        UR                  5      '   U	b  Xy-  n[7        SU	 SU 35        U" S5        GM     [9        [(        R;                  5       5      S:  a  SSKJn  [        S5        U" [(        5        U$ )Nr   zNodeOP:z	,	Target:z,	NodeName:z,	NodeArgs:zinput_shape:	)endzoutput_shape:	tensor_meta)outputplaceholdercall_functionat< >|z| is missingcall_methodz is missingcall_modulezmodule type:zweight_shape: Nonezweight_shape: z.weightzCurrent node's FLOPs: z, total FLOPs: zP================================================================================)pprintzMissing operators: )rE   graphrF   	propagaterK   printnodesoptargetnamer   strappendmetar>   splitreplacestrip	count_mapr   missing_mapsrH   get_submoduletype
isinstancezero_ops
state_dictrI   r%   keysr\   )rL   rM   verbosegmgfprintv_mapstotal_flopsnode
node_flopsr   r	   argkeymr\   s                   r
   
fx_profiler}   |   s   -c2B
AbME"FFKdggYj\$))LY]YbYbXcd	
 
~4(99C3xv%fSX&'d3s3x 01	 
 	=!9!?!? @ABTYY}5;;<77//JWW' DKK tQ b!b!  i&s^ 26))?C{{
 &*WWcNS!#l+,WW% dkk"Ci&s^LH
%)WWcNS![)*WW% !!$++.Aq'C47DGy01Aw)#&tAw/O
%)WWJS![)*.$q'*!X&&*,d1g$S^^%5dkkI6M%N%T%T$UV "&=!9!?!?s499~!%K)*_[MRSyO R <!#!#$|r   __main__c                       \ rS rSrS rSrg)MyOP   c                     US-  $ )Nr    r   )selfrM   s     r
   forwardMyOP.forward   s    19r   r   N)__name__
__module____qualname____firstlineno__r   __static_attributes__r   r   r
   r   r      s    	r   r   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )MyModule   c                    > [         TU ]  5         [        R                  R	                  SS5      U l        [        R                  R	                  SS5      U l        [        5       U l        g )N   r$   )	super__init__torchnnLinearlinear1linear2r   myop)r   	__class__s    r
   r   MyModule.__init__   sC    G 88??1a0DL 88??1a0DLDIr   c                     U R                  U5      nU R                  U5      R                  SSS9nU R                  X#-   5      $ )Ng        g      ?)minmax)r   r   rD   r   )r   xout1out2s       r
   r   MyModule.forward   s=    <<?D<<?((Sc(:D99T[))r   )r   r   r   )r   r   r   r   r   r   r   __classcell__)r   s   @r
   r   r      s    		* 	*r   r      r   )rr   )F)5loggingr   thtorch.nnr   distutils.versionr   __version__warningr   r   r   r   vision.calc_funcr!   r5   Moduler9   r;   Conv2dr@   BatchNorm2drC   ReLUReLU6Dropout	MaxPool2d	AvgPool2dAdaptiveAvgPool2dro   r   rj   krk   torch.fxrE   torch.fx.passes.shape_proprF   utilsrG   rH   rI   rK   Tensorr}   r   r   r   netrandndataflopsr_   r   r   r
   <module>r      s       *!!"\'%::OO4494E4E3Fb	J$
& -$5BII 5299 
BII 
"..  GGHHJJLLLL IIIINNM[^.+_Y	 
A!IaL 
  # 0 + +YBII Ybii Yx zryy 
*588?? 
* *C88B?DsD%0E	%L+ r   