
    hl}                     z   % S SK r S SKJr  S SKJrJrJrJr  S SKrS SK	J
r
  S SKJrJrJrJr  S SKJr  \" S\40 5      r\\S'   \ R*                  " \5      r\R0                  \R2                  \R4                  \R6                  1r\R:                  S\R<                  S	\R>                  S
\R@                  S\RB                  S\RD                  S\RF                  S0r$ \RJ                  S\RL                  S\RN                  S\RP                  S0r)\*\\RV                  \4   \,\-\-4   4   \S'   \)R]                  \$5        S\RV                  S\/4S jr0S r1S r2SSSSSS\Rf                  4S\Rh                  S\Rh                  S\S\,\-S4   S\RV                  S \\-   S!\\-   S"\\5   S#\\RV                     S$\\RV                     S%\/S&\\   S\,\Rh                  \Rh                  4   4S' jjr6         S;S(\\Rh                     S\7S\\-   S\RV                  S \\\-\5\/4      S!\\\-\5\/4      S"\\5   S#\\RV                     S$\\RV                     S%\/S&\\7   S\\Rh                     S\\Rh                     S\,\Rh                  \Rh                  4   4S) jjr8\Rr                  " 5       SS\Rf                  4S(\Rh                  S\,\-S4   S*\Rh                  S+\\Rh                     S,\RV                  S \\\-\54      S!\\\-\54      S&\\   S\Rh                  4S- jj5       r:SS\Rf                  Rv                  4S(\Rh                  S\<\-   S*\Rh                  S+\\Rh                     S,\RV                  S \\\-\5\/4      S!\\\-\5\/4      S&\\7   S\Rh                  4S. jjr=\Rf                  Rv                  4S(\Rh                  S\<\-   S*\Rh                  S+\\Rh                     S \\-\54   S!\\-\54   S&\\7   S\Rh                  4S/ jjr>SS\Rf                  4\R~                  S0.S(\Rh                  S\,\-S4   S*\Rh                  S+\\Rh                     S1\RV                  S \\\-\54      S!\\\-\54      S&\S,\RV                  S\Rh                  4S2 jjjr@SS\Rf                  Rv                  \R~                  4S(\Rh                  S\<\-   S*\Rh                  S+\\Rh                     S1\RV                  S \\\-\5\/4      S!\\\-\5\/4      S&\\7   S,\RV                  S\Rh                  4S3 jjrA\Rf                  Rv                  \R~                  4S(\Rh                  S\<\-   S*\Rh                  S+\\Rh                     S \\-\54   S!\\-\54   S&\\7   S,\RV                  S\Rh                  4S4 jjrB " S5 S6\5      rC " S7 S8\5      rD " S9 S:\5      rEg)<    N)ABCMeta)AnyListOptionalUnion)Granularity)AffineQuantizedObserverBaseMappingTypeTorchAODTypeZeroPointDomain)get_block_sizeABC)r      )r      )r      )r      )r      )r   ?   )r      )r      )ir   )i i  )i   i_DTYPE_TO_QVALUE_BOUNDSdtypereturnc                     [         R                  [         R                  [         R                  [         R                  1nX;   $ N)torchfloat8_e4m3fnfloat8_e4m3fnuzfloat8_e5m2float8_e5m2fnuz)r   	fp8_typess     h/home/james-whalen/.local/lib/python3.13/site-packages/torchao/quantization/pt2e/_affine_quantization.py_is_float8_typer#   :   s8    	I     c                 >   U [         ;   a@  [        R                  " U 5      R                  [        R                  " U 5      R                  pCO#U [
        ;  a  [        SU  35      e[
        U    u  p4Uc  UnUc  UnX:  d   SU SU 35       eX$::  d   SU SU 35       eX4$ )zGet quant_min and quant_max args based on dtype and also
verify that they are within the range of possible quant_min/quant_max
for dtype
zUnsupported dtype: z9quant_min out of bound for dtype, quant_min_lower_bound: z quant_min: z9quant_max out of bound for dtype, quant_max_upper_bound: z quant_max: )	FP8_TYPESr   finfominmaxr   
ValueError)r   	quant_min	quant_maxquant_min_lower_boundquant_max_upper_bounds        r"   _get_and_check_qmin_qmaxr/   E   s    
 	KK""KK""  5 
-	-.ug6777Nu7U4)	)	- 	""7!8YK	Q-
 - 	""7!8YK	Q- r$   c                    [        U 5      [        U5      :X  d   e/ n/ nSn[        [        U 5      5       H  nX   X   :w  ar  X   S:  aj  X   X   -  S:X  d   SU SX    SU SX    35       eUR                  X   X   -  5        UR                  X   5        UR                  US-   5        US-  nM  UR                  X   5        X   S:w  a  UR                  U5        US-  nM     X#4$ )a  Given block_size and input size find the parameters for reduction:

Output:
    shape_for_reduction: the shape we use to `view` input to prepare it for reduction
    reduction_dims: the dims we'll do reduction over

Example::
    Input:
      block_size: (3, 3, 2, 10)
      input_size: (3, 3, 10, 10)

    Output:
      shape_for_reduction: (3, 3, 5, 2, 10)
      reduction_dim: [0, 1, 3, 4]
r   r   zExpecting input size at z dimension: z" to be divisible by block_size at    )lenrangeappend)
block_size
input_sizeshape_for_reductionreduction_dimscur_dimis         r"   _get_reduction_paramsr;   d   s     z?c*o---NG3z?#=JM)jma.?=:=0A5 *1#\=/!CA3lS]S`Rac5  &&z}
'EF&&z}5!!'A+.qLG  &&z}5 }!%%g.qLG% $& ..r$   Tmin_valmax_valmapping_typer5   .target_dtyper+   r,   epsscale_dtypezero_point_dtypepreserve_zerozero_point_domainc                 n    [        SUR                  UUUUUUU	U
Ub  UR                  U U5      $ SU U5      $ )aL  A variant of :func:`~torchao.quantization.quant_primitives.choose_qparams_affine`
operator that pass in min_val and max_val directly instead of deriving these from a single input.
This is used for observers in static quantization where min_val and max_val may be obtained through
tracking all the data in calibration data set.

Args:
  Mostly same as :func:`~torchao.quantization.quant_primitives.choose_qparams_affine`. with one
  difference: instead of passing in `input` Tensor and use that to calculate min_val/max_val
  and then scale/zero_point, we pass in min_val/max_val directly
N)_choose_qparams_affinename)r<   r=   r>   r5   r?   r+   r,   r@   rA   rB   rC   rD   s               r"   "choose_qparams_affine_with_min_maxrH      sa    0 ""3"?  FJ r$   inputc                 \	   [        X4U5      u  pEU[        R                  R                  [        R                  R                  [        R
                  R                  4;   d
   SU 35       eU[        ;   a(  U[        R                  R                  :X  d
   SU 35       eU b  Uc  U R                  nUc  U R                  nUc*  [        R                  " U R                  5      R                  n[        U5      U R                  5       :X  d   SU R                  5        SU 35       e[        X R                  5       5      u  pU R                  U5      n [        R                   " XSS9n[        R"                  " XSS9nOyUb  Uc   S5       eUR                  UR                  :X  d   S	5       eUc  UR                  nUc  UR                  nUc*  [        R                  " UR                  5      R                  nU	(       aW  [        R$                  " U[        R&                  " U5      5      n[        R(                  " U[        R&                  " U5      5      nOUnUnU[        R                  R                  :X  d  U[        R                  R                  :X  Ga  U[        R                  R                  :X  a,  [        R(                  " U* U5      nU[+        XT-
  5      S
-  -  nOYU[        R                  R                  :X  d   eU[+        U5      -  nU[+        U5      -  nUU:  n[        R,                  " UUU5      nU	(       d  [/        S5      eU
b)  U
[0        R2                  R                  :w  a  [/        S5      e[        R4                  " UUS9n[        R6                  " U[9        XT-   S-   S
-  5      5      nOU[        R
                  R                  :X  d   eUU-
  [+        XT-
  5      -  n[        R4                  " UUS9nU
[0        R:                  R                  :X  a  SnOrU	(       a4  U[        R<                  " UU-  5      -
  n[        R4                  " UXE5      nO7U
[0        R>                  R                  :X  d   S5       eXT-   S-   S
-  nUUU-  -   nUb  URA                  US9nURA                  US9U4$ )aW  op definition that has compatible signatures with custom op library

The op does the following:
1. figure out the dimension for reduction based on block_size
2. find min_val/max_val based on the dimension for reduction
3. calculate quantization parameters based on min_val/max_val based on args like `preserve_zero`
   and `zero_point_domain`
zUnsupported mapping type: z<Only symmetric quantization is supported for FP8 types, got NGot input dim:, block_size: FdimkeepdimzUNeed to provide `min_val` and `max_val` when `input` is None, got: {min_val, max_val}z]Expecting `min_val` and `max_val` to have the same dtype, got: {min_val.dtype, max_val.dtype}r1   zBpreserve_zero == False is not supported for symmetric quantizationzTzero_point_domain != ZeroPointDomain.INT is not supported for symmetric quantization)r(   r   z8if not preserve_zero, zero_point must be in FLOAT domain)r   )!r/   r
   	SYMMETRICrG   SYMMETRIC_NO_CLIPPING_ERR
ASYMMETRICr&   r   r   r'   r@   r2   rN   r;   sizeviewaminamaxr(   
zeros_liker)   floatwherer*   r   INTclamp	full_likeintNONEroundFLOATto)rI   r>   r5   r?   r+   r,   r@   rA   rB   rC   rD   r<   r=   r7   r8   min_val_negmax_val_posscalesminsmaxmask
zero_point	mid_points                          r"   rF   rF      sI   . 4LYWI""--22##  3 
$L>2	3 
 y {44999 	
J<.Y	
9 ++K#${{;++ekk*..C:%))+- 	
UYY[M
|D	
- /D

/
+ 

./**UF**UF"w': 	
c	
: }}- 	
k	
- !--K#&}};++gmm,00Cii)9)9')BCii)9)9')BC 	--222;@@EEE ;00555))[L+>K5)>#?!#CDE;#H#H#M#MMMM y!11Dy!11D$;DKKdD1ET  )!_%8%8%=%==f  Es+__UC1F1Ja0O,PQ
{55:::::{*eI4I.JJEs+ 4 4 9 99J&[55H)II
"[[YJ
(O,A,A,F,FF NF '2Q6!;	(59+<<
]])9]:
88+8&
22r$   rd   rh   output_dtypec           
      L    [        U UUUUUUUb  UR                  5      $ S5      $ )a  
Args:
  input (torch.Tensor): original float32, float16 or bfloat16 Tensor
  block_size: (Tuple[int, ...]): granularity of quantization,
       this means the size of the tensor elements that's sharing the same qparam
       e.g. when size is the same as the input tensor dimension, we are using per tensor quantization
  scale (float): quantization parameter for affine quantization
  zero_point (int): quantization parameter for affine quantization
  output_dtype (torch.dtype): requested dtype (e.g. torch.uint8) for output Tensor
  quant_min (Optional[int]): minimum quantized value for output Tensor, if not specified, it will be derived from dtype
  quant_max (Optional[int]): maximum quantized value for output Tensor, if not specified, it will be derived from dtype
  zero_point_domain (ZeroPointDomain): the domain that zero_point is in, should be either integer or float
    if zero_point is in integer domain, zero point is added to the quantized integer value during
    quantization
    if zero_point is in floating point domain, zero point is subtracted from the floating point (unquantized)
    value during quantization
    default is ZeroPointDomain.INT

Note:
  How can block_size represent different granularities?
  let's say we have a Tensor of size: (3, 3, 10, 10), here is the table showing how block_size represents different
  granularities:

   granularity type       |     block_size
     per_tensor           |    (3, 3, 10, 10)
     per_axis (axis=0)    |    (1, 3, 10, 10)
     per_axis (axis=1)    |    (3, 1, 10, 10)
 per_group (groupsize=2)  |    (3, 3, 10, 2)
 per_group (groupsize=2) for axis = 3 | (3, 3, 2, 10)


Output:
  quantized tensor with requested dtype
N)_quantize_affinerG   rI   r5   rd   rh   rj   r+   r,   rD   s           r"   quantize_affinern   :  sG    Z "3"?	 	 FJ	 	r$   c           	          [        XEU5      u  pVU[        ;   a  [        R                  n[	        U UUUUUU5      R                  U5      $ )a  op definition that has compatible signatures with custom op library

Note:
    zero_point_domain is optional specifies how we quantize the floating point to quantized data:
    INT: quantized_val = (float_val / scale) (integer) + zero_point (integer)
    FLOAT: quantized_val = (float_val - (zero_point (float) - scale * mid_point)) / scale
    None: quantized_val = (float_val / scale) | this is primarily used for floatx quantization
        Where we do not want to round values to nearest integer and instead scale and cast.
)r/   _SUB_BYTE_UINT_BOUNDSr   uint8_quantize_affine_no_dtype_castra   rm   s           r"   rl   rl   s  sU    & 4LYWI ,,{{) 	br$   c                    U R                   [        R                  [        R                  [        R                  4;   d   SU R                    35       e[        U5      U R                  5       :X  d   SU R                  5        SU 35       e[        XR                  5       5      u  pxU R                  n	U R                  U5      n Un
U H  nSX'   M	     UR                  U
5      nUb  UR                  U
5      nU[        R                  R                  :X  a5  [        R                  " [        R                  " U SU-  -  5      U-   XE5      nOU[        R                   R                  :X  a<  Ub   S5       e[        R                  " [        R                  " U SU-  -  5      XE5      nOUc2  Ub   S5       e[        R                  " XR#                  5       -  XE5      nOaU[        R$                  R                  :X  d   eXT-   S-   S-  nX2U-  -
  n[        R                  " [        R                  " X-
  U-  5      XE5      nUR                  U	5      nU$ )	a?  
The op does the following:
1. figure out the dimension for reduction based on block_size, also reshape the input to align with
   the shape after reduction
2. quantize the input based on the quantization parameters scale and zero_point and args like zero_point_domain
3. reshape the quantized result to origianl shape
zUnsupported input dtype: rK   rL   r   g      ?8zero_point should be None when zero_point_domain is NONE8zero_point should be None when zero_point_domain is Noner1   )r   r   float32float16bfloat16r2   rN   r;   rS   shaperT   r   rZ   rG   r[   r_   r^   
reciprocalr`   )rI   r5   rd   rh   r+   r,   rD   r7   r8   original_shapeshape_after_reductionr:   quantri   r<   s                  r"   rr   rr     s*   $ ;;  1 
#5;;-0	1 
 z?eiik) 
^J<@) +@JJL+' [[NJJ*+E/#$  JJ,-E__%:;
O//444KKu-.;Y
 
o2277	7! 	
F	
! EKKu(=>	U		"! 	
F	
! E$4$4$66	M O$9$9$>$>>>>*Q.!3	y00KKE12I
 JJ~&ELr$   rj   input_dtypec                H    [        U UUUUUUUb  UR                  US9	$ SUS9	$ )a  
Args:
  input (torch.Tensor): quantized tensor, should match the dtype `dtype` argument
  block_size: (List[int]): granularity of quantization,
    this means the size of the tensor elements that's sharing the same qparam
    e.g. when size is the same as the input tensor dimension, we are using per tensor quantization
  scale (Tensor): quantization parameter for affine quantization
  zero_point (Tensor): quantization parameter for affine quantization
  input_dtype (torch.dtype): requested dtype (e.g. torch.uint8) for output Tensor
  quant_min (Optional[int]): minimum quantized value for input Tensor
  quant_max (Optional[int]): maximum quantized value for input Tensor
  output_dtype (torch.dtype): dtype for output Tensor, default is fp32
  zero_point_domain (ZeroPointDomain): the domain that zero_point is in, should be either integer or float
    if zero_point is in integer domain, zero point is added to the quantized integer value during
    quantization
    if zero_point is in floating point domain, zero point is subtracted from the floating point (unquantized)
    value during quantization
    default is ZeroPointDomain.INT

Output:
  dequantized Tensor, with requested dtype or fp32
Nr~   )_dequantize_affinerG   	rI   r5   rd   rh   r   r+   r,   rD   rj   s	            r"   dequantize_affiner     sM    D "3"?!
 
 FJ!
 
r$   c	           
         U[         ;  a'  U R                  U:X  d   SU SU R                   35       eU[        R                  [        R                  [        R
                  4;   d
   SU 35       e[        XEU5      u  pV[        U UUUUUUU5      $ )zCop definition that has compatible signatures with custom op libraryz
Expected: z, got: zUnsupported output dtype: )rp   r   r   rv   rw   rx   r/   !_dequantize_affine_no_dtype_checkr   s	            r"   r   r     s     //{{k) 	
WU[[M:	
)   3 
$L>2	3 
 4KIVI,	 	r$   c                 8   [        U5      U R                  5       :X  d   SU R                  5        SU 35       e[        XR                  5       5      u  pU R                  n
U R                  U5      n UnU	 H  nSX'   M	     UR                  U5      nUb  UR                  U5      nU[        R                  R                  :X  aX  U R                  [        R                  SS9nUb!  XR                  [        R                  5      -
  nUR                  U5      nX-  nOU[        R                  R                  :X  a   Ub   S5       eU R                  U5      nX-  nOUcN  Ub   S5       e[        U R                  5      (       d   SU R                   35       eU R                  U5      nX-  nORU[        R                  R                  :X  d
   S	U 35       eXT-   S-   S
-  nX-
  nUR                  U5      nX-  nUb  X-  nUR                  U
5      R                  U5      $ )a  This function converts AQT tensors to their high precision floating point representation

The op does the following:
1. figure out the dimension for reduction based on block_size, also reshape the input to align with
   the shape after reduction
2. dequantize the input based on the quantization parameters scale and zero_point and args like zero_point_domain
3. reshape the quantized result to origianl shape and change dtype to the output_dtype
rK   rL   r   T)copyrt   ru   zNdequantiztion with no zero point domain is only supported with FP8 types, got zUnexpected zero point domain: r1   )r2   rN   r;   rS   ry   rT   r   rZ   rG   ra   r   int32r^   r#   r   r`   )rI   r5   rd   rh   r+   r,   rD   rj   r7   r8   r{   r|   r:   dequantri   s                  r"   r   r   )  s1   $ z?eiik) 
^J<@) +@JJL+' [[NJJ*+E/#$  JJ,-E__%:;
O//444 ((5;;T(2!ekk ::G**\*/	o2277	7! 	
F	
! ((<(/		"! 	
F	
! u{{++ 	
\]b]h]h\ij	
+ ((<(/ O$9$9$>$>> 	
,->,?@	
> *Q.!3	#**\*!!G<<'**<88r$   c                   v    \ rS rSrS\R
                  4S jrS\\R
                  \R
                  4   4S jrSr	g)AffineQuantizedMinMaxObserveris  rI   c                 4   UR                  5       S:X  a  U$ UR                  5       nUR                  U l        U R                  c   S5       e[        UR                  U R                  5      U l        [        U R                  UR                  5       5      u  p4UR                  U5      n[        R                  " X$SS9n[        R                  " X$SS9n[        U S5      (       a  [        U S5      (       d  XPl        X`l        U$ U R                  R                  UR                  :X  d+   SU R                  R                   SUR                   35       eU R                   R                  UR                  :X  d+   S	U R                   R                   S
UR                   35       e[        R"                  " U R                  U5      n[        R$                  " U R                   U5      nU R                  R'                  U5        U R                   R'                  U5        U$ Nr   zgranularity is NoneFrM   r<   r=   z=Can't update existing min_val - shape mismatch, self.min_val:z != min_val:z=Can't update existing max_val - shape mismatch, self.max_val z != max_val:)numeldetachr   original_dtypegranularityr   ry   r5   r;   rS   rT   r   rU   rV   hasattrr<   r=   r(   r)   copy_selfrI   input_detachedr7   r8   r<   r=   s          r"   forward%AffineQuantizedMinMaxObserver.forwardt  s   ;;=AL,22+B-BB+()=)=t?O?OP.COO^002/
+ (,,-@A**^O**^OtY''wtY/G/G"L"L  <<%%6 OPTP\P\PbPbOccopwp}p}o~6 <<%%6 OPTP\P\PbPbOccopwp}p}o~6 iig6Giig6GLLw'LLw'r$   r   c                 \   [        U S5      (       a  [        U S5      (       d   S5       e[        U R                  U R                  U R                  / U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  5      $ Nr<   r=   zhExpecting the observer has min_val and max_val, please run the observer before calling calculate_qparamsr   rH   r<   r=   r>   r?   r+   r,   r@   rA   rB   rC   rD   r   s    r"   calculate_qparams/AffineQuantizedMinMaxObserver.calculate_qparams  s    tY''GD),D,D 	
v	
D 2LLLLNNNNHH!!""
 	
r$   )r5   r=   r<   r   N)
__name__
__module____qualname____firstlineno__r   Tensorr   tupler   __static_attributes__ r$   r"   r   r   s  s1    U\\ @
5u||)C#D 
r$   r   c                   @  ^  \ rS rSrSSSSSSSS\R
                  4	S\S\R                  S\	S	\
\   S
\
\   S\
\   S\
\R                     S\
\R                     S\S\
\   4U 4S jjjrS\R                  4S jrS\\R                  \R                  4   4S jrSrU =r$ )*AffineQuantizedMovingAverageMinMaxObserveri  g{Gz?NFTr>   r?   r   r+   r,   r@   rA   rB   rC   rD   c                    > Xl         X@l        U(       a(  U R                  S:w  a  [        SU R                   35      e[        TU ]  UUUUUUU	U
UUS9
  g )Nr   z[MovingAverageMinMaxObserver doesn't support dynamic quantization for averaging constant of 
r>   r?   r   r+   r,   r@   rA   rB   rC   rD   )
is_dynamicaveraging_constantNotImplementedErrorsuper__init__)r   r>   r?   r   r   r+   r,   r@   r   rA   rB   rC   rD   kwargs	__class__s                 r"   r   3AffineQuantizedMovingAverageMinMaxObserver.__init__  sv    " %"4$11Q6%))-)@)@(AC 
 	%%##-'/ 	 	
r$   rI   c                 P   UR                  5       S:X  a  U$ UR                  5       nUR                  U l        U R                  c   S5       e[        UR                  U R                  5      U l        [        U R                  UR                  5       5      u  p4UR                  U5      n[        R                  " X$SS9n[        R                  " X$SS9n[        U S5      (       a  [        U S5      (       d  XPl        X`l        U$ U R                  R                  UR                  :X  d+   SU R                  R                   SUR                   35       eU R                   R                  UR                  :X  d+   S	U R                   R                   S
UR                   35       eU R                  U R"                  XPR                  -
  -  -   nU R                   U R"                  X`R                   -
  -  -   nU R                  R%                  U5        U R                   R%                  U5        U$ r   )r   r   r   r   r   r   ry   r5   r;   rS   rT   r   rU   rV   r   r<   r=   r   r   r   s          r"   r   2AffineQuantizedMovingAverageMinMaxObserver.forward  s   ;;=AL,22+B-BB+()=)=t?O?OP.COO^002/
+ (,,-@A**^O**^OtY''wtY/G/G"L"L  <<%%6 OPTP\P\PbPbOccopwp}p}o~6 <<%%6 OPTP\P\PbPbOccopwp}p}o~6 llT%<%<,,@V%WWGllT%<%<,,@V%WWGLLw'LLw' r$   r   c                 \   [        U S5      (       a  [        U S5      (       d   S5       e[        U R                  U R                  U R                  / U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  5      $ r   r   r   s    r"   r   <AffineQuantizedMovingAverageMinMaxObserver.calculate_qparams  s    tY''GD),D,D 	
v	
D 2LLLLNNNNHH!!""
 	
r$   )r   r5   r   r=   r<   r   )r   r   r   r   r   rZ   r
   r   r   r   r   r]   rX   boolr   r   r   r   r   r   __classcell__r   s   @r"   r   r     s      #'#'#-126"7F7J7J$
!$
 kk$
 !	$
 C=$
 C=$
 e_$
 ekk*$
 #5;;/$
 $
 $O4$
 $
LU\\ B
5u||)C#D 
 
r$   r   c                      ^  \ rS rSrSSSSSSS\R
                  4S\S\R                  S\	S\
\   S	\
\   S
\
\   S\
\R                     S\
\R                     S\S\
\   4U 4S jjjrS rS rSrU =r$ )"AffineQuantizedPlaceholderObserveri  NFTr>   r?   r   r+   r,   r@   rA   rB   rC   rD   c                 >   > Xpl         [        TU ]	  UUUUUUUU	U
US9
  g )Nr   )r   r   r   )r   r>   r?   r   r+   r,   r@   r   rA   rB   rC   rD   r   r   s                r"   r   +AffineQuantizedPlaceholderObserver.__init__  s:      %%%##-'/ 	 	
r$   c                 r    [        UR                  U R                  5      U l        UR                  U l        U$ r   )r   ry   r   r5   r   r   )r   rI   s     r"   r   *AffineQuantizedPlaceholderObserver.forward%  s+    (d6F6FG#kkr$   c                     [        S5      e)Nz>calculate_qparams should not be called for PlaceholderObserver)	Exceptionr   s    r"   r   4AffineQuantizedPlaceholderObserver.calculate_qparams*  s    L
 	
r$   )r5   r   r   )r   r   r   r   r   rZ   r
   r   r   r   r   r]   rX   r   r   r   r   r   r   r   s   @r"   r   r     s     $(#'#-126"7F7J7J
!
 kk
 !	

 C=
 C=
 e_
 ekk*
 #5;;/
 
 $O4
 
>

 
r$   r   )	NNNNNTrZ   NN)Floggingabcr   typingr   r   r   r   r   torchao.quantizationr   "torchao.quantization.pt2e.observerr	   r
   r   r   torchao.quantization.utilsr   objectr   __annotations__	getLoggerr   loggerr   r   r   r    r&   uint1uint2uint3uint4uint5uint6uint7rp   rq   int8int16r   r   dictr   r   r]   updater   r#   r/   r;   rZ   r   rX   rH   strrF   no_gradrn   rG   listrl   rr   rv   r   r   r   r   r   r   r   r$   r"   <module>r      s     - -  ,  656)R(S (			8	$ 
					 
KK	KK	KK	KK	KK	KK	KK 
 
KK	JJ	KK&	KK&	T eEKK$=>c3hOP    4 55;; 4  >'/`  $#)-.23B3F3F&\\&\\& & c3h	&
 ++& }& }& 
%& %++&& u{{+& &  0& 5<<%&&\ 4837)-.2',&*&*@3ELL!@3@3 S	@3 ++	@3
 c5$./0@3 c5$./0@3 
%@3 %++&@3 u{{+@3 @3  }@3 ell#@3 ell#@3 5<<%&@3F  .2-13B3F3F5<<5c3h5 <<5 &	5
 ++5 c5j)*5 c5j)*5  05 \\5 5| 4837'6':':'?'? << S	  <<  &	 
 ++  c5$./0  c5$./0   }  \\ T (7':':'?'?><<>S	> <<> &	>
 S%Z > S%Z >  }> \\>N .2-1)8)<)<, !&,<<,c3h, <<, &	,
 , c5j)*, c5j)*, ', ++, \\,j 4837'6':':'?'? % << S	  <<  &	 
   c5$./0  c5$./0   }  ++  \\ T (7':':'?'? %G9<<G9S	G9 <<G9 &	G9
 S%Z G9 S%Z G9  }G9 ++G9 \\G9T2
$? 2
jZ
1L Z
z(
)D (
r$   