
    ȅi0'                     :   S SK JrJr  S SKrS SKJr  S SKJr  S SKJ	r	J
r
Jr  S SKJrJrJr  / SQr " S S\R"                  R$                  R&                  5      r " S	 S
\\R(                  5      r " S S\\R*                  5      r " S S\\R,                  5      rg)    )ClassVarLiteralN)_FusedModule)	_size_1_t	_size_2_t	_size_3_t)_pair_single_triple)Conv1dConv2dConv3dc                   
   \ rS rSr% \\\R                  R                  R                        \
S'      SS\S\S\\S4   S\\S4   S	\\\S4   -  S
\\S4   S\S\\S4   S\S\S\S   SS4S jjrS r\SS j5       rS rSrg)_ConvNd   _FLOAT_MODULENin_channelsout_channelskernel_size.stridepaddingdilation
transposedoutput_paddinggroupsbiaspadding_modezerosreflect	replicatecircularreturnc                     XS.n[         R                  R                  R                  R                  " U UUUUUUUUU	U
U40 UD6  U(       d  [        S5      eXl        UR                  US9U l        g )N)devicedtypez'qconfig must be provided for QAT module)factory_kwargs)	nnmodulesconvr   __init__AssertionErrorqconfigweightweight_fake_quant)selfr   r   r   r   r   r   r   r   r   r   r   r-   r%   r&   r'   s                   V/home/james-whalen/.local/lib/python3.13/site-packages/torch/ao/nn/qat/modules/conv.pyr+   _ConvNd.__init__   s    " %+;


((	
 	
  !JKK!(~!N    c                 l    U R                  XR                  U R                  5      U R                  5      $ N_conv_forwardr/   r.   r   r0   inputs     r1   forward_ConvNd.forward7   (    !!%)?)?)LdiiXXr3   c                    [        U5      U R                  LaE  [        SU R                   SU R                  R                   S[        U5      R                   35      e[	        US5      (       d  [        S5      eUR
                  (       d  [        S5      e[        [        U5      [        5      (       a  US   nUR
                  nU " UR                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  SLUR                   US	9
nUR"                  Ul        UR                  Ul        U$ )
zCreate a qat module from a float module

Args:
   `mod`: a float module, either produced by torch.ao.quantization utilities
   or directly from user
zqat.z.from_float only works for z, got r-   z,Input float module must have qconfig definedz,Input float module must have a valid qconfigr   N)r   r   r   r   r   r   r-   )typer   r,   __name__hasattrr-   
issubclassr   r   r   r   r   r   r   r   r   r   r.   )clsmoduse_precomputed_fake_quantr-   qat_convs        r1   
from_float_ConvNd.from_float:   s    9C--- s||n$?$$--.fT#Y5G5G4HJ  sI&& !OPP{{ !OPPd3i..a&C++OOOO::KK\\::%))
 **r3   c                 ,   [        U 5      nUR                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  SLU R                  5	      n[        R                  R                  U R                  R                  5       5      Ul        U R                  b<  [        R                  R                  U R                  R                  5       5      Ul	        [!        U["        5      (       ay  U/n[%        US5      (       d  ['        UR(                   S35      eUR+                  5       nUR-                  U5        UR.                  " U6 nUR1                  U R2                  5        U$ U$ )zzThis works for both single qat conv, and the qat conv - relu modules
to convert the qat module to a floating point module
N_FLOAT_RELU_MODULEz' must have _FLOAT_RELU_MODULE attribute)r>   _FLOAT_CONV_MODULEr   r   r   r   r   r   r   r   r   torchr(   	Parameterr.   detachrA   r   r@   r,   r?   rI   appendr   traintraining)r0   rB   r*   r)   relufuseds         r1   to_float_ConvNd.to_float^   s?    4j%%KKLLMMKKIIT!

 hh((););)=>99 **499+;+;+=>DIc<((fG3 455$||n$KL  ))+DNN4 %%w/EKK&LKr3   )r-   r/   )NNNF)r?   
__module____qualname____firstlineno__r   r>   r(   r)   r*   r   __annotations__inttuplestrboolr   r+   r:   staticmethodrF   rS   __static_attributes__ r3   r1   r   r      s   D!8!89:: $O$O $O 38_	$O
 c3h$O uS#X&$O S/$O $O c3h$O $O $O IJ$O  
!$OLY ! !F!r3   r   c                     ^  \ rS rSr% Sr\R                  r\\	\R                        \
S'   \R                  r\\	\R                        \
S'            SS\S\S\S	\S
\\-  S\S\S\S\S   SS4U 4S jjjr\SU 4S jj5       rSrU =r$ )r      a:  
A Conv1d module attached with FakeQuantize modules for weight,
used for quantization aware training.

We adopt the same interface as :class:`~torch.nn.Conv1d`

Similar to :class:`~torch.nn.Conv2d`, with FakeQuantize modules initialized to
default.

Attributes:
    weight_fake_quant: fake quant module for weight
r   rJ   Nr   r   r   r   r   r   r   r   r   r   r#   c                    > [        U5      n[        U5      n[        U[        5      (       a  UO
[        U5      n[        U5      n[        TU ]  UUUUUUS[        S5      UUU	U
UUS9  g NFr   )r   r   r   r   r   r   r   r   r-   r%   r&   )r
   
isinstancer\   superr+   r0   r   r   r   r   r   r   r   r   r   r-   r%   r&   kernel_size_stride_padding_	dilation_	__class__s                    r1   r+   Conv1d.__init__   z     {+&/(#667GG<LH%	"1:% 	 	
r3   c                     > [         TU ]  XUS9$ N)rD   rf   rF   rB   rC   rD   rl   s      r1   rF   Conv1d.from_float        w!1K " 
 	
r3   r`   	   r   rv   rv   Tr   NNNrU   )r?   rV   rW   rX   __doc__r(   r   r   r   r>   rY   rJ   rZ   r   r\   r]   r   r+   classmethodrF   r_   __classcell__rl   s   @r1   r   r      s     02yyM8DO,846IIbii1= #$MT"
"
 "
 	"

 "
 y"
 "
 "
 "
 IJ"
 
"
 "
H 
 
r3   r   c                      ^  \ rS rSr% Sr\R                  r\\	\R                        \
S'   \R                  r\\	\R                        \
S'            SS\S\S\S	\S
\\-  S\S\S\S\S   SS4U 4S jjjrS r\SU 4S jj5       rSrU =r$ )r      a  
A Conv2d module attached with FakeQuantize modules for weight,
used for quantization aware training.

We adopt the same interface as `torch.nn.Conv2d`, please see
https://pytorch.org/docs/stable/nn.html?highlight=conv2d#torch.nn.Conv2d
for documentation.

Similar to `torch.nn.Conv2d`, with FakeQuantize modules initialized to
default.

Attributes:
    weight_fake_quant: fake quant module for weight
r   rJ   Nr   r   r   r   r   r   r   r   r   r   r#   c                    > [        U5      n[        U5      n[        U[        5      (       a  UO
[        U5      n[        U5      n[        TU ]  UUUUUUS[        S5      UUU	U
UUS9  g rd   )r	   re   r\   rf   r+   rg   s                    r1   r+   Conv2d.__init__   sx     [)-(#667E'N(O	 8% 	 	
r3   c                 l    U R                  XR                  U R                  5      U R                  5      $ r5   r6   r8   s     r1   r:   Conv2d.forward   r<   r3   c                     > [         TU ]  XUS9$ rp   rq   rr   s      r1   rF   Conv2d.from_float   rt   r3   r`   ru   rU   )r?   rV   rW   rX   rw   r(   r   r   r   r>   rY   rJ   rZ   r   r\   r]   r   r+   r:   rx   rF   r_   ry   rz   s   @r1   r   r           02yyM8DO,846IIbii1= #$MT"
"
 "
 	"

 "
 y"
 "
 "
 "
 IJ"
 
"
 "
HY 
 
r3   r   c                      ^  \ rS rSr% Sr\R                  r\\	\R                        \
S'   \R                  r\\	\R                        \
S'            SS\S\S\S	\S
\\-  S\S\S\S\S   SS4U 4S jjjrS r\SU 4S jj5       rSrU =r$ )r      a  
A Conv3d module attached with FakeQuantize modules for weight,
used for quantization aware training.

We adopt the same interface as `torch.nn.Conv3d`, please see
https://pytorch.org/docs/stable/nn.html?highlight=conv3d#torch.nn.Conv3d
for documentation.

Similar to `torch.nn.Conv3d`, with FakeQuantize modules initialized to
default.

Attributes:
    weight_fake_quant: fake quant module for weight
r   rJ   Nr   r   r   r   r   r   r   r   r   r   r#   c                    > [        U5      n[        U5      n[        U[        5      (       a  UO
[        U5      n[        U5      n[        TU ]  UUUUUUS[        S5      UUU	U
UUS9  g rd   )r   re   r\   rf   r+   rg   s                    r1   r+   Conv3d.__init__  rn   r3   c                 l    U R                  XR                  U R                  5      U R                  5      $ r5   r6   r8   s     r1   r:   Conv3d.forward6  r<   r3   c                     > [         TU ]  XUS9$ rp   rq   rr   s      r1   rF   Conv3d.from_float9  rt   r3   r`   ru   rU   )r?   rV   rW   rX   rw   r(   r   r   r   r>   rY   rJ   rZ   r   r\   r]   r   r+   r:   rx   rF   r_   ry   rz   s   @r1   r   r      r   r3   r   )typingr   r   rK   torch.nnr(   torch.ao.nn.intrinsicr   torch.nn.common_typesr   r   r   torch.nn.modules.utilsr	   r
   r   __all__r)   r*   r   r   r   r   r`   r3   r1   <module>r      sy    $   . A A : : )qbjjoo%% qh9
Wbii 9
x>
Wbii >
B>
Wbii >
r3   