
    9jG.                        d dl Z d dlmZmZmZmZmZmZmZm	Z	 d dl
mZ g dZ G d de j                  j                        Z G d de      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d e      Z G d! d"e      Z G d# d$e      Z G d% d&e      Z G d' d(e      Z y))    N)BatchNorm1dBatchNorm2dBatchNorm3dConv1dConv2dConv3dLinearReLU)type_before_parametrizations)
ConvReLU1d
ConvReLU2d
ConvReLU3d
LinearReLUConvBn1dConvBn2dConvBnReLU1dConvBnReLU2dConvBn3dConvBnReLU3dBNReLU2dBNReLU3d
LinearBn1dLinearLeakyReLU
LinearTanh	ConvAdd2dConvAddReLU2dc                       e Zd Zy)_FusedModuleN)__name__
__module____qualname__     c/media/conek/DATA/Code/OCR/venv/lib/python3.12/site-packages/torch/ao/nn/intrinsic/modules/fused.pyr   r   &   s    r#   r   c                   "     e Zd ZdZ fdZ xZS )r   zThis is a sequential container which calls the Conv1d and ReLU modules.
    During quantization this will be replaced with the corresponding fused module.c                     t        |      t        k(  rt        |      t        k(  s7t        dt        |      j                   dt        |      j                         t
        |   ||       y N#Incorrect types for input modules: z and )r   r   r
   AssertionErrorr   super__init__selfconvrelu	__class__s      r$   r+   zConvReLU1d.__init__.   h    (.&8,T2d: 5/5>>?u/5>>?A 
 	t$r#   r   r    r!   __doc__r+   __classcell__r0   s   @r$   r   r   *       V
% 
%r#   r   c                   "     e Zd ZdZ fdZ xZS )r   zThis is a sequential container which calls the Conv2d and ReLU modules.
    During quantization this will be replaced with the corresponding fused module.c                     t        |      t        k(  rt        |      t        k(  s7t        dt        |      j                   dt        |      j                         t
        |   ||       y r'   )r   r   r
   r)   r   r*   r+   r,   s      r$   r+   zConvReLU2d.__init__?   r1   r#   r2   r5   s   @r$   r   r   ;   r6   r#   r   c                   "     e Zd ZdZ fdZ xZS )r   zThis is a sequential container which calls the Conv3d and ReLU modules.
    During quantization this will be replaced with the corresponding fused module.c                     t        |      t        k(  rt        |      t        k(  s7t        dt        |      j                   dt        |      j                         t
        |   ||       y r'   )r   r   r
   r)   r   r*   r+   r,   s      r$   r+   zConvReLU3d.__init__P   r1   r#   r2   r5   s   @r$   r   r   L   r6   r#   r   c                   "     e Zd ZdZ fdZ xZS )r   zThis is a sequential container which calls the Linear and ReLU modules.
    During quantization this will be replaced with the corresponding fused module.c                     t        |      t        k(  rt        |      t        k(  s7t        dt        |      j                   dt        |      j                         t
        |   ||       y r'   )r   r	   r
   r)   r   r*   r+   )r-   linearr/   r0   s      r$   r+   zLinearReLU.__init__a   sh    (0F:,T2d: 5/7@@A/5>>?A 
 	&r#   r2   r5   s   @r$   r   r   ]   s    V
' 
'r#   r   c                   "     e Zd ZdZ fdZ xZS )r   zThis is a sequential container which calls the Conv 1d and Batch Norm 1d modules.
    During quantization this will be replaced with the corresponding fused module.c                     t        |      t        k(  rt        |      t        k(  s7t        dt        |      j                   dt        |      j                         t
        |   ||       y r'   )r   r   r   r)   r   r*   r+   r-   r.   bnr0   s      r$   r+   zConvBn1d.__init__r   g    (.&8,R0K? 5/5>>?u/3<<=? 
 	r"r#   r2   r5   s   @r$   r   r   n       V
# 
#r#   r   c                   "     e Zd ZdZ fdZ xZS )r   zThis is a sequential container which calls the Conv 2d and Batch Norm 2d modules.
    During quantization this will be replaced with the corresponding fused module.c                     t        |      t        k(  rt        |      t        k(  s7t        dt        |      j                   dt        |      j                         t
        |   ||       y r'   )r   r   r   r)   r   r*   r+   r@   s      r$   r+   zConvBn2d.__init__   rB   r#   r2   r5   s   @r$   r   r      rC   r#   r   c                   "     e Zd ZdZ fdZ xZS )r   zThis is a sequential container which calls the Conv 1d, Batch Norm 1d, and ReLU modules.
    During quantization this will be replaced with the corresponding fused module.c           
      .   t        |      t        k(  r$t        |      t        k(  rt        |      t        k(  sMt	        dt        |      j
                   dt        |      j
                   dt        |      j
                         t        |   |||       y Nr(   z, z, and )r   r   r   r
   r)   r   r*   r+   r-   r.   rA   r/   r0   s       r$   r+   zConvBnReLU1d.__init__       (.&8,R0K?,T2d: 5/5>>?r/3<<=V/5>>?A  	r4(r#   r2   r5   s   @r$   r   r          V) )r#   r   c                   "     e Zd ZdZ fdZ xZS )r   zThis is a sequential container which calls the Conv 2d, Batch Norm 2d, and ReLU modules.
    During quantization this will be replaced with the corresponding fused module.c           
      .   t        |      t        k(  r$t        |      t        k(  rt        |      t        k(  sMt	        dt        |      j
                   dt        |      j
                   dt        |      j
                         t        |   |||       y rH   )r   r   r   r
   r)   r   r*   r+   rI   s       r$   r+   zConvBnReLU2d.__init__   rJ   r#   r2   r5   s   @r$   r   r      rK   r#   r   c                   "     e Zd ZdZ fdZ xZS )r   zThis is a sequential container which calls the Conv 3d and Batch Norm 3d modules.
    During quantization this will be replaced with the corresponding fused module.c                     t        |      t        k(  rt        |      t        k(  s7t        dt        |      j                   dt        |      j                         t
        |   ||       y r'   )r   r   r   r)   r   r*   r+   r@   s      r$   r+   zConvBn3d.__init__   rB   r#   r2   r5   s   @r$   r   r      rC   r#   r   c                   "     e Zd ZdZ fdZ xZS )r   zThis is a sequential container which calls the Conv 3d, Batch Norm 3d, and ReLU modules.
    During quantization this will be replaced with the corresponding fused module.c           
      .   t        |      t        k(  r$t        |      t        k(  rt        |      t        k(  sMt	        dt        |      j
                   dt        |      j
                   dt        |      j
                         t        |   |||       y rH   )r   r   r   r
   r)   r   r*   r+   rI   s       r$   r+   zConvBnReLU3d.__init__   rJ   r#   r2   r5   s   @r$   r   r      rK   r#   r   c                   "     e Zd ZdZ fdZ xZS )r   zThis is a sequential container which calls the BatchNorm 2d and ReLU modules.
    During quantization this will be replaced with the corresponding fused module.c                     t        |      t        k(  rt        |      t        k(  s7t        dt        |      j                   dt        |      j                         t
        |   ||       y r'   )r   r   r
   r)   r   r*   r+   r-   
batch_normr/   r0   s      r$   r+   zBNReLU2d.__init__   h    (4C,T2d: 5/
;DDEU/5>>?A 
 	T*r#   r2   r5   s   @r$   r   r          V
+ 
+r#   r   c                   "     e Zd ZdZ fdZ xZS )r   zThis is a sequential container which calls the BatchNorm 3d and ReLU modules.
    During quantization this will be replaced with the corresponding fused module.c                     t        |      t        k(  rt        |      t        k(  s7t        dt        |      j                   dt        |      j                         t
        |   ||       y r'   )r   r   r
   r)   r   r*   r+   rT   s      r$   r+   zBNReLU3d.__init__   rV   r#   r2   r5   s   @r$   r   r      rW   r#   r   c                   "     e Zd ZdZ fdZ xZS )r   zThis is a sequential container which calls the Linear and BatchNorm1d modules.
    During quantization this will be replaced with the corresponding fused module.c                     t        |      t        k(  rt        |      t        k(  s7t        dt        |      j                   dt        |      j                         t
        |   ||       y r'   )r   r	   r   r)   r   r*   r+   )r-   r=   rA   r0   s      r$   r+   zLinearBn1d.__init__   sg    (0F:,R0K? 5/7@@A/3<<=? 
 	$r#   r2   r5   s   @r$   r   r      r6   r#   r   c                   "     e Zd ZdZ fdZ xZS )r   zThis is a sequential container which calls the Linear and LeakyReLU modules.
    During quantization this will be replaced with the corresponding fused module.c                     t        |      t        u r%t        |      t        j                  j                  u s7t        dt        |      j                   dt        |      j                         t        | !  ||       y r'   )	typer	   torchnn	LeakyReLUr)   r   r*   r+   )r-   r=   
leaky_relur0   s      r$   r+   zLinearLeakyReLU.__init__  sn    V&4
+;uxx?Q?Q+Q 5<(()tJ/?/H/H.IK  	,r#   r2   r5   s   @r$   r   r     s    V- -r#   r   c                   "     e Zd ZdZ fdZ xZS )r   zThis is a sequential container which calls the Linear and Tanh modules.
    During quantization this will be replaced with the corresponding fused module.c                     t        |      t        u r%t        |      t        j                  j                  u s7t        dt        |      j                   dt        |      j                         t        | !  ||       y r'   )	r^   r	   r_   r`   Tanhr)   r   r*   r+   )r-   r=   tanhr0   s      r$   r+   zLinearTanh.__init__  sj    V&4:+F 5<(()tDz/B/B.CE  	&r#   r2   r5   s   @r$   r   r     s    V' 'r#   r   c                   (     e Zd ZdZ fdZd Z xZS )r   zThis is a sequential container which calls the Conv2d modules with extra Add.
    During quantization this will be replaced with the corresponding fused module.c                 2    t         |   |       || _        y N)r*   r+   add)r-   r.   rj   r0   s      r$   r+   zConvAdd2d.__init__+  s    r#   c                 8    | j                   | d   |      |      S )z4Applies convolution to x1 and adds the result to x2.r   )rj   r-   x1x2s      r$   forwardzConvAdd2d.forward/  s    xxQR((r#   r   r    r!   r3   r+   ro   r4   r5   s   @r$   r   r   '  s    V)r#   r   c                   (     e Zd ZdZ fdZd Z xZS )r   zThis is a sequential container which calls the Conv2d, add, Relu.
    During quantization this will be replaced with the corresponding fused module.c                 @    t         |   |       || _        || _        y ri   )r*   r+   rj   r/   )r-   r.   rj   r/   r0   s       r$   r+   zConvAddReLU2d.__init__8  s    	r#   c                 V    | j                  | j                   | d   |      |            S )zCApplies convolution to x1, adds the result to x2, and applies ReLU.r   )r/   rj   rl   s      r$   ro   zConvAddReLU2d.forward=  s&    yy'$q'"+r233r#   rp   r5   s   @r$   r   r   4  s    V
4r#   r   )!r_   torch.nnr   r   r   r   r   r   r	   r
   torch.nn.utils.parametrizer   __all__r`   
Sequentialr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r"   r#   r$   <module>rx      s   	 	 	 D,	588&& 	% %"% %"% %"' '"#| #"#| #")< )&)< )&#| #")< )&+| +"+| +"% %"
-l 
-
' 
'
) 
)4L 4r#   