
    VhB%                     J   d dl Z g dZ G d de j                  j                        Z G d de j                  j                        Z G d de j                  j
                        Z G d	 d
e j                  j                        Z G d de j                  j                        Zy)    N)	LayerNorm	GroupNormInstanceNorm1dInstanceNorm2dInstanceNorm3dc                   ^     e Zd ZdZ	 	 	 	 d	 d fdZd Zd Zed	d       Zed        Z	 x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.

    c
                     ||	d}
t        |   |f||d|
 || _        || _        | j	                  dt        j                  |fi |
       | j	                  dt        j                  |fi |
       y )Ndevicedtype)epselementwise_affinescale
zero_pointsuper__init__weightbiasregister_buffertorchtensor)selfnormalized_shaper   r   r   r   r   r   r   r   factory_kwargs	__class__s              [/home/dcms/DCMS/lib/python3.12/site-packages/torch/ao/nn/quantized/modules/normalization.pyr   zLayerNorm.__init__   s     %+U;	
1	
 		
 	Well5&KN&KL\5<<
+Un+UV    c           	          t         j                  j                  j                  || j                  | j
                  | j                  | j                  | j                  | j                        S )N)r   r   r   output_scaleoutput_zero_point)
r   ops	quantized
layer_normr   r   r   r   r   r   r   inputs     r   forwardzLayerNorm.forward/   sS    yy""--!!;;"oo . 
 	
r   c                      y)NQuantizedLayerNorm r   s    r   	_get_namezLayerNorm._get_name:       #r   c           	          |j                   j                         \  }} | |j                  |j                  |j                  t        |      t        |      |j                  |j                        }|S N)	activation_post_processcalculate_qparamsr   r   r   floatintr   r   clsmoduse_precomputed_fake_quantr   r   new_mods         r   
from_floatzLayerNorm.from_float=   sa    77IIKz  JJHH%L
OGG""
 r   c           	           | |j                   |j                  |j                  t        |      t	        |      |j
                  |j                        S r/   )r   r   r   r2   r3   r   r   r5   r6   r   r   s       r   from_referencezLayerNorm.from_referenceK   sD      JJHH%L
OGG""
 	
r   h㈵>TNNreturnNF__name__
__module____qualname____doc__r   r'   r,   classmethodr9   r<   __classcell__r   s   @r   r   r      sY     W 
W0	
$   	
 	
r   r   c                   V     e Zd ZdZg dZ	 	 	 	 d	 d fdZd Zd Zed	d       Z	 x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   affinec                     |	|
d}t        |   ||||fi | || _        || _        | j	                  dt        j                  |fi |       | j	                  dt        j                  |fi |       y Nr
   r   r   r   )r   rK   rL   r   r   r   r   r   rM   r   r   r   r   s               r   r   zGroupNorm.__init__b   sq     %+U;\3Q.Q	Well5&KN&KL\5<<
+Un+UVr   c           	          t         j                  j                  j                  || j                  | j
                  | j                  | j                  | j                  | j                        S r/   )
r   r"   r#   
group_normrK   r   r   r   r   r   r%   s     r   r'   zGroupNorm.forwardv   sL    yy""--OOKKIIHHJJOO
 	
r   c                      y)NQuantizedGroupNormr*   r+   s    r   r,   zGroupNorm._get_name   r-   r   c           
          |j                   j                         \  }} | |j                  |j                  |j                  |j
                  t        |      t        |      |j                  |j                        }|S r/   )
r0   r1   rK   rL   r   r   r2   r3   r   rM   r4   s         r   r9   zGroupNorm.from_float   sf    77IIKzNNJJHH%L
OGGJJ	
 r   r=   r?   rA   )rC   rD   rE   rF   __constants__r   r'   r,   rG   r9   rH   rI   s   @r   r   r   X   sM     DM W 
W(	
$  r   r   c                   b     e Zd ZdZ	 	 	 	 	 	 d	 d fdZd Zd Zed	d       Zed        Z	 x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.

    c                     |
|d}t        |   |||||	fi | || _        || _        | j	                  dt        j                  |fi |       | j	                  dt        j                  |fi |       y rO   r   r   num_featuresr   r   r   r   r   momentumrM   track_running_statsr   r   r   r   s                r   r   zInstanceNorm1d.__init__   |     %+U;#x1D	
HV	
 	Well5&KN&KL\5<<
+Un+UVr   c                     t         j                  j                  j                  || j                  | j
                  | j                  | j                  | j                        S r/   	r   r"   r#   instance_normr   r   r   r   r   r%   s     r   r'   zInstanceNorm1d.forward   @    yy""004;;		488TZZ
 	
r   c                      y)NQuantizedInstanceNorm1dr*   r+   s    r   r,   zInstanceNorm1d._get_name       (r   c           	          |j                   j                         \  }} | |j                  |j                  |j                  t        |      t        |      |j                  |j                        }|S r/   	r0   r1   rY   r   r   r2   r3   r   rM   r4   s         r   r9   zInstanceNorm1d.from_float   _    77IIKzJJHH%L
OGGJJ
 r   c           	           | |j                   |j                  |j                  t        |      t	        |      |j
                  |j                        S r/   rY   r   r   r2   r3   r   rM   r;   s       r   r<   zInstanceNorm1d.from_reference   B    JJHH%L
OGGJJ
 	
r   r>   g?FFNNr?   rA   rB   rI   s   @r   r   r      _     !W 
W.

)   	
 	
r   r   c                   b     e Zd ZdZ	 	 	 	 	 	 d	 d fdZd Zd Zed	d       Zed        Z	 x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.

    c                     |
|d}t        |   |||||	fi | || _        || _        | j	                  dt        j                  |fi |       | j	                  dt        j                  |fi |       y rO   r   rX   s                r   r   zInstanceNorm2d.__init__   r\   r   c                     t         j                  j                  j                  || j                  | j
                  | j                  | j                  | j                        S r/   r^   r%   s     r   r'   zInstanceNorm2d.forward   r`   r   c                      y)NQuantizedInstanceNorm2dr*   r+   s    r   r,   zInstanceNorm2d._get_name   rc   r   c           	          |j                   j                         \  }} | |j                  |j                  |j                  t        |      t        |      |j                  |j                        }|S r/   re   r4   s         r   r9   zInstanceNorm2d.from_float   rf   r   c           	           | |j                   |j                  |j                  t        |      t	        |      |j
                  |j                        S r/   rh   r;   s       r   r<   zInstanceNorm2d.from_reference  ri   r   rj   r?   rA   rB   rI   s   @r   r   r      rk   r   r   c                   b     e Zd ZdZ	 	 	 	 	 	 d	 d fdZd Zd Zed	d       Zed        Z	 x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.

    c                     |
|d}t        |   |||||	fi | || _        || _        | j	                  dt        j                  |fi |       | j	                  dt        j                  |fi |       y rO   r   rX   s                r   r   zInstanceNorm3d.__init__#  r\   r   c                     t         j                  j                  j                  || j                  | j
                  | j                  | j                  | j                        S r/   r^   r%   s     r   r'   zInstanceNorm3d.forward:  r`   r   c                      y)NQuantizedInstanceNorm3dr*   r+   s    r   r,   zInstanceNorm3d._get_name?  rc   r   c           	          |j                   j                         \  }} | |j                  |j                  |j                  t        |      t        |      |j                  |j                        }|S r/   re   r4   s         r   r9   zInstanceNorm3d.from_floatB  rf   r   c           	           | |j                   |j                  |j                  t        |      t	        |      |j
                  |j                        S r/   rh   r;   s       r   r<   zInstanceNorm3d.from_referenceP  ri   r   rj   r?   rA   rB   rI   s   @r   r   r     rk   r   r   )r   __all__nnr   r   r   r   r   r*   r   r   <module>r|      s    G
"" G
T9"" 9x@
UXX,, @
F@
UXX,, @
F@
UXX,, @
r   