
    sh%                     :   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UnionN)_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   4   S
\\S4   S\S\\S4   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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__qconfigweightweight_fake_quant)selfr   r   r   r   r   r   r   r   r   r   r   r'   r    r!   r"   s                   p/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/torch/ao/nn/qat/modules/conv.pyr&   _ConvNd.__init__   s~    " %+;


((	
 	
 AAAw!(~!N    c                 l    U R                  XR                  U R                  5      U R                  5      $ N_conv_forwardr)   r(   r   r*   inputs     r+   forward_ConvNd.forward6   (    !!%)?)?)LdiiXXr-   c                 l   [        U5      U R                  :X  d.   SU R                  -   S-   U R                  R                  -   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 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   __name__hasattrr'   
issubclassr   r   r   r   r   r   r   r   r   r   r(   )clsmoduse_precomputed_fake_quantr'   qat_convs        r+   
from_float_ConvNd.from_float9   s    CyC--- 	
ll+, (()	
- sI&&V(VV&{{JJJ{d3i..a&C++OOOO::KK\\::%))
 **r-   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      (       ac  U/n[%        US5      (       d   eUR'                  5       nUR)                  U5        UR*                  " U6 nUR-                  U R.                  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_MODULE)r8   _FLOAT_CONV_MODULEr   r   r   r   r   r   r   r   r   torchr#   	Parameterr(   detachr;   r   r:   rC   appendr   traintraining)r*   r<   r%   r$   relufuseds         r+   to_float_ConvNd.to_float\   s'    4j%%KKLLMMKKIIT!

 hh((););)=>99 **499+;+;+=>DIc<((fG3 45555))+DNN4 %%w/EKK&LKr-   )r'   r)   )NNNF)r9   
__module____qualname____firstlineno__r   r8   r#   r$   r%   r   __annotations__inttupler   strboolr&   r4   staticmethodr@   rM   __static_attributes__ r-   r+   r   r      s   D!8!89:: #O#O #O 38_	#O
 c3h#O sE#s(O+,#O S/#O #O c3h#O #O #O #O  
!#OJY    Dr-   r   c                     ^  \ rS rSr% Sr\R                  r\\	\R                        \
S'   \R                  r\\	\R                        \
S'            SS\S\S\S	\S
\\\4   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   rD   Nr   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
   
isinstancerV   superr&   r*   r   r   r   r   r   r   r   r   r   r'   r    r!   kernel_size_stride_padding_	dilation_	__class__s                    r+   r&   Conv1d.__init__   z     {+&/(#667GG<LH%	"1:% 	 	
r-   c                     > [         TU ]  XUS9$ N)r>   r`   r@   r<   r=   r>   rf   s      r+   r@   Conv1d.from_float        w!1K " 
 	
r-   rZ   	   r   rp   rp   TzerosNNNrO   )r9   rP   rQ   rR   __doc__r#   r   r   r   r8   rS   rD   rT   r   r   rV   rW   r&   classmethodr@   rY   __classcell__rf   s   @r+   r   r   |   s     02yyM8DO,846IIbii1= )*#"
"
 "
 	"

 "
 sI~&"
 "
 "
 "
 "
 
"
 "
H 
 
r-   r   c                     ^  \ rS rSr% Sr\R                  r\\	\R                        \
S'   \R                  r\\	\R                        \
S'            SS\S\S\S	\S
\\\4   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   rD   Nr   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 r^   )r	   r_   rV   r`   r&   ra   s                    r+   r&   Conv2d.__init__   sx     [)-(#667E'N(O	 8% 	 	
r-   c                 l    U R                  XR                  U R                  5      U R                  5      $ r/   r0   r2   s     r+   r4   Conv2d.forward   r6   r-   c                     > [         TU ]  XUS9$ rj   rk   rl   s      r+   r@   Conv2d.from_float   rn   r-   rZ   ro   rO   )r9   rP   rQ   rR   rr   r#   r   r   r   r8   rS   rD   rT   r   r   rV   rW   r&   r4   rs   r@   rY   rt   ru   s   @r+   r   r           02yyM8DO,846IIbii1= )*#"
"
 "
 	"

 "
 sI~&"
 "
 "
 "
 "
 
"
 "
HY 
 
r-   r   c                     ^  \ rS rSr% Sr\R                  r\\	\R                        \
S'   \R                  r\\	\R                        \
S'            SS\S\S\S	\S
\\\4   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   rD   Nr   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 r^   )r   r_   rV   r`   r&   ra   s                    r+   r&   Conv3d.__init__	  rh   r-   c                 l    U R                  XR                  U R                  5      U R                  5      $ r/   r0   r2   s     r+   r4   Conv3d.forward-  r6   r-   c                     > [         TU ]  XUS9$ rj   rk   rl   s      r+   r@   Conv3d.from_float0  rn   r-   rZ   ro   rO   )r9   rP   rQ   rR   rr   r#   r   r   r   r8   rS   rD   rT   r   r   rV   rW   r&   r4   rs   r@   rY   rt   ru   s   @r+   r   r      r~   r-   r   )typingr   r   rE   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   rZ   r-   r+   <module>r      sy    "   . A A : : )kbjjoo%% k\8
Wbii 8
v=
Wbii =
@=
Wbii =
r-   