o
    Ih?&                     @   sl  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 de jjZG dd deZG d	d
 d
eZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZG d#d$ d$eZG d%d& d&eZG d'd( d(eZ dS ))    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                   @   s   e Zd ZdS )_FusedModuleN)__name__
__module____qualname__ r    r    W/var/www/vscode/kcb/lib/python3.10/site-packages/torch/ao/nn/intrinsic/modules/fused.pyr   &   s    r   c                           e Zd ZdZ fddZ  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                    D   t |tkrt |tksJ dt | t | t || d S Nz!Incorrect types for input modules)r
   r   r	   super__init__selfconvrelu	__class__r    r!   r&   .   
   zConvReLU1d.__init__r   r   r   __doc__r&   __classcell__r    r    r+   r!   r   *       r   c                       r"   )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                    r#   r$   )r
   r   r	   r%   r&   r'   r+   r    r!   r&   :   r-   zConvReLU2d.__init__r.   r    r    r+   r!   r   6   r1   r   c                       r"   )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                    r#   r$   )r
   r   r	   r%   r&   r'   r+   r    r!   r&   F   r-   zConvReLU3d.__init__r.   r    r    r+   r!   r   B   r1   r   c                       r"   )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                    r#   r$   )r
   r   r	   r%   r&   )r(   linearr*   r+   r    r!   r&   R   r-   zLinearReLU.__init__r.   r    r    r+   r!   r   N   r1   r   c                       r"   )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                    r#   r$   )r
   r   r   r%   r&   r(   r)   bnr+   r    r!   r&   ^   r-   zConvBn1d.__init__r.   r    r    r+   r!   r   Z   r1   r   c                       r"   )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                    r#   r$   )r
   r   r   r%   r&   r3   r+   r    r!   r&   j   r-   zConvBn2d.__init__r.   r    r    r+   r!   r   f   r1   r   c                       r"   )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                    Z   t |tkrt |tkrt |tks#J dt | t | t | t ||| d S r$   )r
   r   r   r	   r%   r&   r(   r)   r4   r*   r+   r    r!   r&   v      zConvBnReLU1d.__init__r.   r    r    r+   r!   r   r   r1   r   c                       r"   )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                    r5   r$   )r
   r   r   r	   r%   r&   r6   r+   r    r!   r&      r7   zConvBnReLU2d.__init__r.   r    r    r+   r!   r      r1   r   c                       r"   )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                    r#   r$   )r
   r   r   r%   r&   r3   r+   r    r!   r&      r-   zConvBn3d.__init__r.   r    r    r+   r!   r      r1   r   c                       r"   )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                    r5   r$   )r
   r   r   r	   r%   r&   r6   r+   r    r!   r&      r7   zConvBnReLU3d.__init__r.   r    r    r+   r!   r      r1   r   c                       r"   )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                    r#   r$   )r
   r   r	   r%   r&   r(   
batch_normr*   r+   r    r!   r&      r-   zBNReLU2d.__init__r.   r    r    r+   r!   r      r1   r   c                       r"   )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                    r#   r$   )r
   r   r	   r%   r&   r8   r+   r    r!   r&      r-   zBNReLU3d.__init__r.   r    r    r+   r!   r      r1   r   c                       r"   )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                    r#   r$   )r
   r   r   r%   r&   )r(   r2   r4   r+   r    r!   r&      r-   zLinearBn1d.__init__r.   r    r    r+   r!   r      r1   r   c                       r"   )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                    H   t |tkrt |tjjksJ dt | t | t || d S r$   )typer   torchnn	LeakyReLUr%   r&   )r(   r2   
leaky_relur+   r    r!   r&         zLinearLeakyReLU.__init__r.   r    r    r+   r!   r      r1   r   c                       r"   )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                    r:   r$   )r;   r   r<   r=   Tanhr%   r&   )r(   r2   tanhr+   r    r!   r&      r@   zLinearTanh.__init__r.   r    r    r+   r!   r      r1   r   c                       (   e Zd ZdZ fddZdd Z  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                    s   t  | || _d S N)r%   r&   add)r(   r)   rE   r+   r    r!   r&      s   
zConvAdd2d.__init__c                 C   s   |  | d ||S Nr   )rE   r(   x1x2r    r    r!   forward   s   zConvAdd2d.forwardr   r   r   r/   r&   rJ   r0   r    r    r+   r!   r      s    r   c                       rC   )r   zThis is a sequential container which calls the Conv2d, add, Relu.
    During quantization this will be replaced with the corresponding fused module.c                    s   t  | || _|| _d S rD   )r%   r&   rE   r*   )r(   r)   rE   r*   r+   r    r!   r&      s   
zConvAddReLU2d.__init__c                 C   s   |  | | d ||S rF   )r*   rE   rG   r    r    r!   rJ      s   zConvAddReLU2d.forwardrK   r    r    r+   r!   r      s    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    r!   <module>   s,   (
