U
    Kc:                      @   s~   d dl Z dddddgZG dd de jjZG dd de jjZG d	d de jjZG d
d de jjZG dd de jjZdS )    N	LayerNorm	GroupNormInstanceNorm1dInstanceNorm2dInstanceNorm3dc                       sP   e Zd ZdZddd fddZdd	 Zd
d Zedd Zedd Z	  Z
S )r   zThis is the quantized version of :class:`~torch.nn.LayerNorm`.

    Additional args:
        * **scale** - quantization scale of the output, type: double.
        * **zero_point** - quantization zero point of the output, type: long.

    h㈵>TNreturnc
                    sd   ||	d}
t t| j|f||d|
 || _|| _| dtj|f|
 | dtj|f|
 d S )Ndevicedtype)epselementwise_affinescale
zero_point)superr   __init__weightbiasregister_buffertorchtensor)selfnormalized_shaper   r   r   r   r   r   r   r   factory_kwargs	__class__ O/tmp/pip-unpacked-wheel-gikjz4vx/torch/ao/nn/quantized/modules/normalization.pyr      s    

 zLayerNorm.__init__c              	   C   s(   t jjj|| j| j| j| j| j| j	dS )N)r   r   r   Zoutput_scaleZoutput_zero_point)
r   ops	quantizedZ
layer_normr   r   r   r   r   r   r   inputr   r   r   forward   s         zLayerNorm.forwardc                 C   s   dS )NZQuantizedLayerNormr   r   r   r   r   	_get_name   s    zLayerNorm._get_namec                 C   s8   |j  \}}| |j|j|jt|t||j|j}|S N)	activation_post_processcalculate_qparamsr   r   r   floatintr   r   clsmodr   r   new_modr   r   r   
from_float!   s         zLayerNorm.from_floatc                 C   s&   | |j |j|jt|t||j|jS r&   )r   r   r   r)   r*   r   r   r,   r-   r   r   r   r   r   from_reference)   s         zLayerNorm.from_reference)r   TNN__name__
__module____qualname____doc__r   r#   r%   classmethodr/   r1   __classcell__r   r   r   r   r      s         
c                       sP   e Zd ZdZddddgZddd	 fd
dZdd Zdd Zedd Z	  Z
S )r   zThis is the quantized version of :class:`~torch.nn.GroupNorm`.

    Additional args:
        * **scale** - quantization scale of the output, type: double.
        * **zero_point** - quantization zero point of the output, type: long.

    
num_groupsnum_channelsr   affiner   TNr   c                    s`   |	|
d}t t| j||||f| || _|| _| dtj|f| | dtj|f| d S Nr
   r   r   )r   r   r   r   r   r   r   r   )r   r9   r:   r   r   r   r   r   r;   r   r   r   r   r   r   r   9   s    
zGroupNorm.__init__c              	   C   s&   t jj|| j| j| j| j| j| j	S r&   )
r   r   r    Z
group_normr9   r   r   r   r   r   r!   r   r   r   r#   C   s         zGroupNorm.forwardc                 C   s   dS )NZQuantizedGroupNormr   r$   r   r   r   r%   H   s    zGroupNorm._get_namec              	   C   s<   |j  \}}| |j|j|j|jt|t||j|j	}|S r&   )
r'   r(   r9   r:   r   r   r)   r*   r   r;   r+   r   r   r   r/   K   s          zGroupNorm.from_float)r   TNN)r3   r4   r5   r6   Z__constants__r   r#   r%   r7   r/   r8   r   r   r   r   r   /   s         
c                       sP   e Zd ZdZddd fddZd	d
 Zdd Zedd Zedd Z	  Z
S )r   zThis is the quantized version of :class:`~torch.nn.InstanceNorm1d`.

    Additional args:
        * **scale** - quantization scale of the output, type: double.
        * **zero_point** - quantization zero point of the output, type: long.

    r   皙?FNr   c                    sb   |
|d}t t| j|||||	f| || _|| _| dtj|f| | dtj|f| d S r<   )r   r   r   r   r   r   r   r   r   num_featuresr   r   r   r   r   Zmomentumr;   Ztrack_running_statsr   r   r   r   r   r   r   [   s    

    zInstanceNorm1d.__init__c                 C   s"   t jj|| j| j| j| j| jS r&   	r   r   r    Zinstance_normr   r   r   r   r   r!   r   r   r   r#   f   s        zInstanceNorm1d.forwardc                 C   s   dS )NZQuantizedInstanceNorm1dr   r$   r   r   r   r%   k   s    zInstanceNorm1d._get_namec                 C   s8   |j  \}}| |j|j|jt|t||j|j}|S r&   	r'   r(   r?   r   r   r)   r*   r   r;   r+   r   r   r   r/   n   s         zInstanceNorm1d.from_floatc                 C   s&   | |j |j|jt|t||j|jS r&   r?   r   r   r)   r*   r   r;   r0   r   r   r   r1   v   s         zInstanceNorm1d.from_reference)r   r=   FFNNr2   r   r   r   r   r   S   s              
c                       sP   e Zd ZdZddd fddZd	d
 Zdd Zedd Zedd Z	  Z
S )r   zThis is the quantized version of :class:`~torch.nn.InstanceNorm2d`.

    Additional args:
        * **scale** - quantization scale of the output, type: double.
        * **zero_point** - quantization zero point of the output, type: long.

    r   r=   FNr   c                    sb   |
|d}t t| j|||||	f| || _|| _| dtj|f| | dtj|f| d S r<   )r   r   r   r   r   r   r   r   r>   r   r   r   r      s    

    zInstanceNorm2d.__init__c                 C   s"   t jj|| j| j| j| j| jS r&   r@   r!   r   r   r   r#      s        zInstanceNorm2d.forwardc                 C   s   dS )NZQuantizedInstanceNorm2dr   r$   r   r   r   r%      s    zInstanceNorm2d._get_namec                 C   s8   |j  \}}| |j|j|jt|t||j|j}|S r&   rA   r+   r   r   r   r/      s         zInstanceNorm2d.from_floatc                 C   s&   | |j |j|jt|t||j|jS r&   rB   r0   r   r   r   r1      s         zInstanceNorm2d.from_reference)r   r=   FFNNr2   r   r   r   r   r   |   s              
c                       sP   e Zd ZdZddd fddZd	d
 Zdd Zedd Zedd Z	  Z
S )r   zThis is the quantized version of :class:`~torch.nn.InstanceNorm3d`.

    Additional args:
        * **scale** - quantization scale of the output, type: double.
        * **zero_point** - quantization zero point of the output, type: long.

    r   r=   FNr   c                    sb   |
|d}t t| j|||||	f| || _|| _| dtj|f| | dtj|f| d S r<   )r   r   r   r   r   r   r   r   r>   r   r   r   r      s    

    zInstanceNorm3d.__init__c                 C   s"   t jj|| j| j| j| j| jS r&   r@   r!   r   r   r   r#      s        zInstanceNorm3d.forwardc                 C   s   dS )NZQuantizedInstanceNorm3dr   r$   r   r   r   r%      s    zInstanceNorm3d._get_namec                 C   s8   |j  \}}| |j|j|jt|t||j|j}|S r&   rA   r+   r   r   r   r/      s         zInstanceNorm3d.from_floatc                 C   s&   | |j |j|jt|t||j|jS r&   rB   r0   r   r   r   r1      s         zInstanceNorm3d.from_reference)r   r=   FFNNr2   r   r   r   r   r      s              
)r   __all__nnr   r   r   r   r   r   r   r   r   <module>   s   *$))