+
    "Ý³jl}  ã                   ó   a € R$ t=0 t ^ RIt^ RIHt ^ RIHtHtHtHt ^ RI	t	^ RI
Ht ^ RIHtHtHtHt ^ RIHt ]! R]3/ 4      t] ^ k ]P*                  ! ]4      t]	P0                  ]	P2                  ]	P4                  ]	P6                  0t]	P:                  R%]	P<                  R&]	P>                  R']	P@                  R(]	PB                  R)]	PD                  R*]	PF                  R+/t$ ]	PJ                  R,]	PL                  R-]	PN                  R.]	PP                  R//t)] ^k ])PU                  ]$4       R R	 lt+R
 t,R t-RRRRRR]P\                  3R R llt/R0R R llt0]	Pb                  ! 4       RR]P\                  3R R ll4       t2RR]P\                  Pf                  3R R llt4]P\                  Pf                  3R R llt5RR]P\                  3R]	Pl                  /R R lllt7RR]P\                  Pf                  ]	Pl                  3R R llt8]P\                  Pf                  ]	Pl                  3R R llt9 ! R R]4      t: ! R  R!]4      t; ! R" R#]4      t<R# )1é    N)ÚABCMeta)ÚAnyÚListÚOptionalÚUnion)ÚGranularity)ÚAffineQuantizedObserverBaseÚMappingTypeÚTorchAODTypeÚZeroPointDomain)Úget_block_sizeÚABCc                óD   € V ^8„  d   QhR\         P                  R\        /# )é   ÚdtypeÚreturn)Útorchr   Úbool)Úformats   "Úo/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torchao/quantization/pt2e/_affine_quantization.pyÚ__annotate__r   :   s   € ÷ ñ œ5Ÿ;™;ð ¬4ñ ó    c                 ó†   € \         P                  \         P                  \         P                  \         P                  0pW9   # ©N)r   Úfloat8_e4m3fnÚfloat8_e4m3fnuzÚfloat8_e5m2Úfloat8_e5m2fnuz)r   Ú	fp8_typess   & r   Ú_is_float8_typer    :   s8   € ä×ÑÜ×ÑÜ×ÑÜ×Ñð	€Ið ÑÐr   c                óR  € V \         9   dA   \        P                  ! V 4      P                  \        P                  ! V 4      P                  rCM(V \
        9  d   \        RV  24      h\
        V ,          w  r4Vf   TpVf   TpW8¼  g   Q RV RV 24       hW$8:  g   Q RV RV 24       hW3# )z‰Get 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ÚmaxÚ_DTYPE_TO_QVALUE_BOUNDSÚ
ValueError)r   Ú	quant_minÚ	quant_maxÚquant_min_lower_boundÚquant_max_upper_bounds   &&&  r   Ú_get_and_check_qmin_qmaxr,   E   sØ   € ð
 ”	Ôä�KŠK˜Ó×"Ñ"Ü�KŠK˜Ó×"Ñ"ñ  5ð 
Ô-Ô	-ÜÐ.¨u¨gÐ6Ó7Ð7ä7NÈuÕ7UÑ4ÐØÒØ)ˆ	ØÒØ)ˆ	àÔ-ð ð	"Ø"7Ð!8¸ÀYÀKð	QóÐ-ð
 Ô-ð ð	"Ø"7Ð!8¸ÀYÀKð	QóÐ-ð ÐÐr   c                ój  € \        V 4      \        V4      8X  g   Q h. p. p^ p\        \        V 4      4       Fø  pW,          W,          8w  d¥   W,          ^8”  d˜   W,          W,          ,          ^ 8X  g    Q RV RW,           RV RW,           24       hVP                  W,          W,          ,          4       VP                  W,          4       VP                  V^,           4       V^,          pKº  VP                  W,          4       W,          ^8w  d   VP                  V4       V^,          pKú  	  W#3# )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]
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_paramsr7   d   s  € ô  ˆz‹?œc *›oÔ-Ð-Ð-ØÐØ€NØ€GÜ”3�z“?Ö#ˆØ�=˜J�MÔ)¨j­m¸aÔ.?Ø•= :¥=Õ0°AÔ5ð Ø*¨1¨#¨\Ø•=�/Ð!CÀAÀ3ÀlÐS]ÕS`ÐRaðcóÐ5ð  ×&Ñ& z¥}¸
½Õ'EÔFØ×&Ñ& z¥}Ô5à×!Ñ! '¨A¥+Ô.Ø�q�LŠGð  ×&Ñ& z¥}Ô5ð �} Ô!Ø×%Ñ% gÔ.Ø�q�LŠGñ% $ð& Ð.Ð.r   Tc                ó   € V ^8„  d   QhR\         P                  R\         P                  R\        R\        \        R3,          R\         P
                  R\        \        ,          R\        \        ,          R	\        \        ,          R
\        \         P
                  ,          R\        \         P
                  ,          R\        R\        \        ,          R\        \         P                  \         P                  3,          /# )r   Úmin_valÚmax_valÚmapping_typer1   .Útarget_dtyper(   r)   ÚepsÚscale_dtypeÚzero_point_dtypeÚpreserve_zeroÚzero_point_domainr   )
r   ÚTensorr
   ÚtupleÚintr   r   Úfloatr   r   )r   s   "r   r   r   Ž   sÓ   € ÷ &ñ &Ü�\‰\ð&ä�\‰\ð&ô ð&ô ”c˜3�h•ð	&ô
 —+‘+ð&ô œ�}ð&ô œ�}ð&ô 
”%�ð&ô œ%Ÿ+™+Õ&ð&ô œuŸ{™{Õ+ð&ô ð&ô  ¤Õ0ð&ô Œ5�<‰<œŸ™Ð%Õ&ñ&r   c                óp   € \        RVP                  TTTTTTT	T
Ve   VP                  V V4      # RV V4      # )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)r9   r:   r;   r1   r<   r(   r)   r=   r>   r?   r@   rA   s   &&&&&&&&&&&&r   Ú"choose_qparams_affine_with_min_maxrI   Ž   sa   € ô0 "ØØ×ÑØØØØØØØØØ"3Ò"?Ð×ÑØØóð ð FJØØóð r   c                ó¶  € V ^8„  d   QhR\         \        P                  ,          R\        R\        \
        ,          R\        P                  R\         \        \
        \        \        3,          ,          R\         \        \
        \        \        3,          ,          R\         \        ,          R\         \        P                  ,          R	\         \        P                  ,          R
\        R\         \        ,          R\         \        P                  ,          R\         \        P                  ,          R\        \        P                  \        P                  3,          /# )r   Úinputr;   r1   r<   r(   r)   r=   r>   r?   r@   rA   r9   r:   r   )r   r   rB   Ústrr   rD   r   r   rE   r   rC   )r   s   "r   r   r   ·   s  € ÷ @3ñ @3Ü”E—L‘LÕ!ð@3äð@3ô ”S•	ð@3ô —+‘+ð	@3ô
 œœc¤5¬$Ð.Õ/Õ0ð@3ô œœc¤5¬$Ð.Õ/Õ0ð@3ô 
”%�ð@3ô œ%Ÿ+™+Õ&ð@3ô œuŸ{™{Õ+ð@3ô ð@3ô  ¤•}ð@3ô ”e—l‘lÕ#ð@3ô ”e—l‘lÕ#ð@3ô Œ5�<‰<œŸ™Ð%Õ&ñ@3r   c                óH
  € \        W4V4      w  rEV\        P                  P                  \        P                  P                  \        P
                  P                  39   g   Q RV 24       hV\        9   d*   V\        P                  P                  8X  g   Q RV 24       hV eå   Vf   V P                  pVf   V P                  pVf+   \        P                  ! V P                  4      P                  p\        V4      V P                  4       8X  g   Q RV P                  4        RV 24       h\        W P                  4       4      w  rÞV P                  V4      p \        P                   ! WRR7      p\        P"                  ! WRR7      pMVe   Vf   Q R4       hVP                  VP                  8X  g   Q R	4       hVf   VP                  pVf   VP                  pVf+   \        P                  ! VP                  4      P                  pV	'       dX   \        P$                  ! V\        P&                  ! V4      4      p\        P(                  ! V\        P&                  ! V4      4      pMTpTpV\        P                  P                  8X  g!   V\        P                  P                  8X  EdI   V\        P                  P                  8X  d9   \        P(                  ! V) V4      pV\+        WT,
          4      ^,          ,          pMbV\        P                  P                  8X  g   Q hV\+        V4      ,          pV\+        V4      ,          pVV8„  p\        P,                  ! VVV4      pV	'       g   \/        R
4      hV
e+   V
\0        P2                  P                  8w  d   \/        R4      h\        P4                  ! VVR7      p\        P6                  ! V\9        WT,           ^,           ^,          4      4      pEM
V\        P
                  P                  8X  g   Q hVV,
          \+        WT,
          4      ,          p\        P4                  ! VVR7      pV
\0        P:                  P                  8X  d   RpM�V	'       d=   V\        P<                  ! VV,          4      ,
          p\        P4                  ! VWE4      pMLV
\0        P>                  P                  8X  g   Q R4       hWT,           ^,           ^,          pVVV,          ,           pVe   VPA                  VR7      pVPA                  VR7      V3# )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}zBpreserve_zero == False is not supported for symmetric quantizationzTzero_point_domain != ZeroPointDomain.INT is not supported for symmetric quantization)r$   z8if not preserve_zero, zero_point must be in FLOAT domain)r   )!r,   r
   Ú	SYMMETRICrH   ÚSYMMETRIC_NO_CLIPPING_ERRÚ
ASYMMETRICr"   r   r   r#   r=   r.   rQ   r7   ÚsizeÚviewÚaminÚamaxr$   Ú
zeros_liker%   rE   Úwherer'   r   ÚINTÚclampÚ	full_likerD   ÚNONEÚroundÚFLOATÚto)rK   r;   r1   r<   r(   r)   r=   r>   r?   r@   rA   r9   r:   r3   r4   Úmin_val_negÚmax_val_posÚscaleÚsminÚsmaxÚmaskÚ
zero_pointÚ	mid_points   &&&&&&&&&&&&&          r   rG   rG   ·   sI  € ô. 4°LÈYÓWÑ€IØÜ×Ñ×"Ñ"Ü×-Ñ-×2Ñ2Ü×Ñ×#Ñ#ðô ð 3ð 
$ L >Ð2ó	3ð ð
 ”yÔ Øœ{×4Ñ4×9Ñ9Ô9ð 	
ØJÈ<È.ÐYó	
Ð9ð ÒØÒØŸ+™+ˆKØÒ#Ø$Ÿ{™{ÐØŠ;Ü—+’+˜eŸk™kÓ*×.Ñ.ˆCä�:‹ %§)¡)£+Ô-ð 	
Ø˜UŸY™Y›[˜M¨¸
°|ÐDó	
Ð-ô /DØŸ
™
›ó/
Ñ+Ðð —
‘
Ð.Ó/ˆä—*’*˜UÀÔFˆÜ—*’*˜UÀÔF‰àÒ" wÒ':ð 	
Øcó	
Ð:ð �}‰} §¡Ô-ð 	
Økó	
Ð-ð ÒØ!Ÿ-™-ˆKØÒ#Ø&Ÿ}™}ÐØŠ;Ü—+’+˜gŸm™mÓ,×0Ñ0ˆCçÜ—i’i ¬×)9Ò)9¸'Ó)BÓCˆÜ—i’i ¬×)9Ò)9¸'Ó)BÓC‰àˆØˆð 	œ×-Ñ-×2Ñ2Ô2Øœ;×@Ñ@×EÑEÕEð œ;×0Ñ0×5Ñ5Ô5ÜŸ)š) [ L°+Ó>ˆKØ¤5¨Õ)>Ó#?À!Õ#CÕD‰Eà¤;×#HÑ#H×#MÑ#MÔMÐMÐMð ¤ yÓ!1Õ1ˆDØ¤ yÓ!1Õ1ˆDØ˜$‘;ˆDÜ—K’K  d¨DÓ1ˆEçÜØTóð ð Ò)Ø!¤_×%8Ñ%8×%=Ñ%=Ô=äØfóð ô —’˜E sÔ+ˆÜ—_’_ U¬C°Õ1FÈÕ1JÈaÕ0OÓ,PÓQŠ
àœ{×5Ñ5×:Ñ:Ô:Ð:Ð:Ø˜{Õ*¬e°IÕ4IÓ.JÕJˆÜ—’˜E sÔ+ˆØ¤× 4Ñ 4× 9Ñ 9Ô9Ø‰JçØ&¬¯ª°[À5Õ5HÓ)IÕI�
Ü"Ÿ[š[¨°YÓJ‘
à(¬O×,AÑ,A×,FÑ,FÔFð ØNóÐFð 'Õ2°QÕ6¸!Õ;�	Ø(¨5°9Õ+<Õ<�
àÒØ—]‘]Ð)9�]Ó:ˆ
Ø�8‰8˜+ˆ8Ó&¨
Ð2Ð2r   c                óž  € V ^8„  d   QhR\         P                  R\        \        R3,          R\         P                  R\        \         P                  ,          R\         P
                  R\        \        \        \        3,          ,          R\        \        \        \        3,          ,          R	\        \        ,          R
\         P                  /	# )r   rK   r1   .re   ri   Úoutput_dtyper(   r)   rA   r   ©	r   rB   rC   rD   r   r   r   rE   r   )r   s   "r   r   r   ;  s¤   € ÷ 5ñ 5Ü�<‰<ð5ä”c˜3�h•ð5ô �<‰<ð5ô œŸ™Õ&ð	5ô
 —+‘+ð5ô œœc¤5˜jÕ)Õ*ð5ô œœc¤5˜jÕ)Õ*ð5ô  ¤Õ0ð5ô ‡\�\ñ5r   c           
     óN   € \        T TTTTTTVe   VP                  4      # R4      # )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_affinerH   ©rK   r1   re   ri   rl   r(   r)   rA   s   &&&&&&&&r   Úquantize_affinerq   :  sG   € ôZ ØØØØØØØØ"3Ò"?Ð×Ñó	ð 	ð FJó	ð 	r   c                ó®  € V ^8„  d   QhR\         P                  R\        \        ,          R\         P                  R\        \         P                  ,          R\         P
                  R\        \        \        \        \        3,          ,          R\        \        \        \        \        3,          ,          R\        \        ,          R	\         P                  /	# )
r   rK   r1   re   ri   rl   r(   r)   rA   r   ©
r   rB   ÚlistrD   r   r   r   rE   r   rL   )r   s   "r   r   r   s  s¥   € ÷  ñ  Ü�<‰<ð ä”S•	ð ô �<‰<ð ô œŸ™Õ&ð	 ô
 —+‘+ð ô œœc¤5¬$Ð.Õ/Õ0ð ô œœc¤5¬$Ð.Õ/Õ0ð ô  ¤•}ð ô ‡\�\ñ r   c           	     ó”   € \        WEV4      w  rVV\        9   d   \        P                  p\	        V VVVVVV4      P                  V4      # )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_castrb   rp   s   &&&&&&&&r   ro   ro   s  sU   € ô& 4°LÈYÓWÑ€Ið Ô,Ô,Ü—{‘{ˆÜ)ØØØØØØØó÷ 	�bˆÓðr   c                óN  € V ^8„  d   QhR\         P                  R\        \        ,          R\         P                  R\        \         P                  ,          R\
        \        \        3,          R\
        \        \        3,          R\        \        ,          R\         P                  /# )	r   rK   r1   re   ri   r(   r)   rA   r   )r   rB   rt   rD   r   r   rE   rL   )r   s   "r   r   r   –  s‡   € ÷ >ñ >Ü�<‰<ð>ä”S•	ð>ô �<‰<ð>ô œŸ™Õ&ð	>ô
 ”Sœ%�ZÕ ð>ô ”Sœ%�ZÕ ð>ô  ¤•}ð>ô ‡\�\ñ>r   c                ó  € V P                   \        P                  \        P                  \        P                  39   g   Q RV P                    24       h\        V4      V P                  4       8X  g   Q RV P                  4        RV 24       h\        WP                  4       4      w  rxV P                  p	V P                  V4      p Tp
V F  p^W«&   K	  	  VP                  V
4      pVe   VP                  V
4      pV\        P                  P                  8X  dC   \        P                  ! \        P                  ! V RV,          ,          4      V,           WE4      pEMV\        P                   P                  8X  dF   Ve   Q R4       h\        P                  ! \        P                  ! V RV,          ,          4      WE4      pM¹Vf8   Ve   Q R4       h\        P                  ! WP#                  4       ,          WE4      pM~V\        P$                  P                  8X  g   Q hWT,           ^,           ^,          pW2V,          ,
          p\        P                  ! \        P                  ! W,
          V,          4      WE4      pVP                  V	4      pV# )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: rN   rO   g      ð?ú8zero_point should be None when zero_point_domain is NONEú8zero_point should be None when zero_point_domain is None)r   r   Úfloat32Úfloat16Úbfloat16r.   rQ   r7   rV   ÚshaperW   r   r\   rH   r]   r`   r_   Ú
reciprocalra   )rK   r1   re   ri   r(   r)   rA   r3   r4   Úoriginal_shapeÚshape_after_reductionr6   Úquantrj   r9   s   &&&&&&&        r   rx   rx   –  s*  € ð$ �;‰;Ü�‰Ü�‰Ü�‰ðô ð 1ð 
# 5§;¡; -Ð0ó	1ð ô
 ˆz‹?˜eŸi™i›kÔ)ð Ø
˜Ÿ™›˜ ^°J°<Ð@óÐ)ô +@Ø—J‘J“Ló+Ñ'Ðð —[‘[€NØ�J‰JÐ*Ó+€EØ/ÐÛˆØ#$ÐÓ ñ à�J‰JÐ,Ó-€EØÒØ—_‘_Ð%:Ó;ˆ
àœO×/Ñ/×4Ñ4Ô4Ü—’Ü�KŠK˜  u¥Õ-Ó.°Õ;¸Yó
Šð 
œo×2Ñ2×7Ñ7Ô	7ØÒ!ð 	
ØFó	
Ð!ô —’œEŸKšK¨°°uµÕ(=Ó>À	ÓU‰Ø	Ò	"àÒ!ð 	
ØFó	
Ð!ô —’˜E×$4Ñ$4Ó$6Õ6¸	ÓM‰à ¤O×$9Ñ$9×$>Ñ$>Ô>Ð>Ð>ØÕ*¨QÕ.°!Õ3ˆ	Ø yÕ0Õ0ˆÜ—’Ü�KŠK˜�¨EÕ1Ó2°Ió
ˆð �J‰J�~Ó&€Eà€Lr   rl   c                ó¨  € V ^8„  d   QhR\         P                  R\        \        R3,          R\         P                  R\        \         P                  ,          R\         P
                  R\        \        \        \        3,          ,          R\        \        \        \        3,          ,          R	\        R
\         P
                  R\         P                  /
# )r   rK   r1   .re   ri   Úinput_dtyper(   r)   rA   rl   r   rm   )r   s   "r   r   r   ×  s­   € ÷ ,ñ ,Ü�<‰<ð,ä”c˜3�h•ð,ô �<‰<ð,ô œŸ™Õ&ð	,ô
 —‘ð,ô œœc¤5˜jÕ)Õ*ð,ô œœc¤5˜jÕ)Õ*ð,ô 'ð,ô —+‘+ð,ô ‡\�\ñ,r   c               óV   € \        T TTTTTTVe   VP                  VR7	      # RVR7	      # )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
N)rl   )Ú_dequantize_affinerH   ©	rK   r1   re   ri   r†   r(   r)   rA   rl   s	   &&&&&&&&$r   Údequantize_affinerŠ   ×  sM   € ôD ØØØØØØØØ"3Ò"?Ð×ÑØ!ô
ð 
ð FJØ!ô
ð 
r   c                óÎ  € V ^8„  d   QhR\         P                  R\        \        ,          R\         P                  R\        \         P                  ,          R\         P
                  R\        \        \        \        \        3,          ,          R\        \        \        \        \        3,          ,          R\        \        ,          R	\         P
                  R
\         P                  /
# )r   rK   r1   re   ri   r†   r(   r)   rA   rl   r   rs   )r   s   "r   r   r     s³   € ÷  ñ  Ü�<‰<ð ä”S•	ð ô �<‰<ð ô œŸ™Õ&ð	 ô
 —‘ð ô œœc¤5¬$Ð.Õ/Õ0ð ô œœc¤5¬$Ð.Õ/Õ0ð ô  ¤•}ð ô —+‘+ð ô ‡\�\ñ r   c	           
     ó$  € V\         9  d)   V P                  V8X  g   Q RV RV P                   24       hV\        P                  \        P                  \        P
                  39   g   Q RV 24       h\        WEV4      w  rV\        V VVVVVVV4      # )zCop definition that has compatible signatures with custom op libraryz
Expected: z, got: zUnsupported output dtype: )rv   r   r   r}   r~   r   r,   Ú!_dequantize_affine_no_dtype_checkr‰   s	   &&&&&&&&&r   rˆ   rˆ     s¯   € ð Ô/Ô/Ø�{‰{˜kÔ)ð 	
Ø˜˜ W¨U¯[©[¨MÐ:ó	
Ð)ð Ü�‰Ü�‰Ü�‰ðô ð 3ð 
$ L >Ð2ó	3ð ô
 4°KÈIÓVÑ€IÜ,ØØØØØØØØó	ð 	r   c                ón  € V ^8„  d   QhR\         P                  R\        \        ,          R\         P                  R\        \         P                  ,          R\
        \        \        3,          R\
        \        \        3,          R\        \        ,          R\         P                  R	\         P                  /	# )
r   rK   r1   re   ri   r(   r)   rA   rl   r   )	r   rB   rt   rD   r   r   rE   rL   r   )r   s   "r   r   r   )  s    € ÷ G9ñ G9Ü�<‰<ðG9ä”S•	ðG9ô �<‰<ðG9ô œŸ™Õ&ð	G9ô
 ”Sœ%�ZÕ ðG9ô ”Sœ%�ZÕ ðG9ô  ¤•}ðG9ô —+‘+ðG9ô ‡\�\ñG9r   c                ó¦  € \        V4      V P                  4       8X  g   Q RV P                  4        RV 24       h\        WP                  4       4      w  r‰V P                  p
V P                  V4      p TpV	 F  p^W¼&   K	  	  VP                  V4      pVe   VP                  V4      pV\        P                  P                  8X  df   V P                  \        P                  RR7      pVe&   WÓP                  \        P                  4      ,
          pVP                  V4      pWÒ,          pEMV\        P                  P                  8X  d&   Ve   Q R4       hV P                  V4      pWÒ,          pMÄVfU   Ve   Q R4       h\        V P                  4      '       g   Q RV P                   24       hV P                  V4      pWÒ,          pMlV\        P                  P                  8X  g   Q RV 24       hWT,           ^,           ^,          pW,
          pVP                  V4      pWÒ,          pVe	   WÓ,          pVP                  V
4      P                  V4      # )	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
rN   rO   T)Úcopyr{   r|   zNdequantiztion with no zero point domain is only supported with FP8 types, got zUnexpected zero point domain: )r.   rQ   r7   rV   r€   rW   r   r\   rH   rb   r   Úint32r_   r    r   ra   )rK   r1   re   ri   r(   r)   rA   rl   r3   r4   r‚   rƒ   r6   Údequantrj   s   &&&&&&&&       r   r�   r�   )  s1  € ô$ ˆz‹?˜eŸi™i›kÔ)ð Ø
˜Ÿ™›˜ ^°J°<Ð@óÐ)ô +@Ø—J‘J“Ló+Ñ'Ðð —[‘[€NØ�J‰JÐ*Ó+€EØ/ÐÛˆØ#$ÐÓ ñ à�J‰JÐ,Ó-€EàÒØ—_‘_Ð%:Ó;ˆ
àœO×/Ñ/×4Ñ4Ô4ð —(‘(œ5Ÿ;™;¨T�(Ó2ˆØÒ!Ø§¡¬e¯k©kÓ :Õ:ˆGØ—*‘*˜\Ó*ˆØ•/ŠØ	œo×2Ñ2×7Ñ7Ô	7ØÒ!ð 	
ØFó	
Ð!ð —(‘(˜<Ó(ˆØ•/‰Ø	Ò	"àÒ!ð 	
ØFó	
Ð!ô ˜uŸ{™{×+Ò+ð 	
Ø\Ð]b×]hÑ]hÐ\iÐjó	
Ð+ð —(‘(˜<Ó(ˆØ•/‰à ¤O×$9Ñ$9×$>Ñ$>Ô>ð 	
Ø,Ð->Ð,?Ð@ó	
Ð>ð Õ*¨QÕ.°!Õ3ˆ	àÕ#ˆØ—*‘*˜\Ó*ˆØÕˆØÒ!ØÕ!ˆGà�<‰<˜Ó'×*Ñ*¨<Ó8Ð8r   c                   óD   a € ] tR tRt o V 3R lR ltV 3R lR ltRtV tR# )ÚAffineQuantizedMinMaxObserveris  c                ó4   <€ V ^8„  d   QhRS[ P                  /# ©r   rK   ©r   rB   )r   Ú__classdict__s   "€r   r   Ú*AffineQuantizedMinMaxObserver.__annotate__t  s   ø€ ÷ ñ ™UŸ\™\ñ r   c                óL  € VP                  4       ^ 8X  d   V# VP                  4       pVP                  V n        V P                  f   Q R4       h\        VP                  V P                  4      V n        \        V P                  VP                  4       4      w  r4VP                  V4      p\        P                  ! W$RR7      p\        P                  ! W$RR7      p\        V R4      '       d   \        V R4      '       g   WPn        W`n        V# V P                  P                  VP                  8X  g,   Q RV P                  P                   RVP                   24       hV P                   P                  VP                  8X  g,   Q RV P                   P                   R	VP                   24       h\        P"                  ! V P                  V4      p\        P$                  ! V P                   V4      pV P                  P'                  V4       V P                   P'                  V4       V# ©
r   zgranularity is NoneFrP   r9   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   r€   r1   r7   rV   rW   r   rX   rY   Úhasattrr9   r:   r$   r%   Úcopy_©ÚselfrK   Úinput_detachedr3   r4   r9   r:   s   &&     r   ÚforwardÚ%AffineQuantizedMinMaxObserver.forwardt  sÈ  € Ø�;‰;‹=˜AÔØˆLàŸ™›ˆØ,×2Ñ2ˆÔØ×ÑÒ+ÐBÐ-BÓBÐ+Ü(¨×)=Ñ)=¸t×?OÑ?OÓPˆŒä.CØ�O‰O˜^×0Ñ0Ó2ó/
Ñ+Ðð (×,Ñ,Ð-@ÓAˆÜ—*’*˜^ÈÔOˆÜ—*’*˜^ÈÔOˆÜ�t˜Y×'Ò'¬w°t¸Y×/GÒ/GØ"ŒLØ"ŒLð ˆð —<‘<×%Ñ%¨¯©Ô6ð ØOÐPT×P\ÑP\×PbÑPbÐOcÐcoÐpw×p}Ñp}Ðo~ÐóÐ6ð —<‘<×%Ñ%¨¯©Ô6ð ØOÐPT×P\ÑP\×PbÑPbÐOcÐcoÐpw×p}Ñp}Ðo~ÐóÐ6ô —i’i §¡¨gÓ6ˆGÜ—i’i §¡¨gÓ6ˆGØ�L‰L×Ñ˜wÔ'Ø�L‰L×Ñ˜wÔ'àˆr   c                ó^   <€ V ^8„  d   QhRS[ S[P                  S[P                  3,          /# ©r   r   ©rC   r   rB   )r   r˜   s   "€r   r   r™   ”  s&   ø€ ÷ 
ñ 
¡5©¯©±u·|±|Ð)CÕ#Dñ 
r   c                ó`  € \        V R 4      '       d   \        V R4      '       g   Q R4       h\        V P                  V P                  V P                  . V P
                  V P                  V P                  V P                  V P                  V P                  V P                  V P                  4      # ©r9   r:   zhExpecting the observer has min_val and max_val, please run the observer before calling calculate_qparams©r    rI   r9   r:   r;   r<   r(   r)   r=   r>   r?   r@   rA   ©r£   s   &r   Úcalculate_qparamsÚ/AffineQuantizedMinMaxObserver.calculate_qparams”  s–   € Ü�t˜Y×'Ò'¬G°D¸)×,DÒ,Dð 	
Øvó	
ÐDô 2Ø�L‰LØ�L‰LØ×ÑØØ×ÑØ�N‰NØ�N‰NØ�H‰HØ×ÑØ×!Ñ!Ø×ÑØ×"Ñ"ó
ð 	
r   )r1   r:   r9   rž   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r¥   r®   Ú__static_attributes__Ú__classdictcell__)r˜   s   @r   r”   r”   s  s   ø‡ € ÷ð ÷@
ö 
r   r”   c            	       óŒ   a a€ ] tR tRt oRRRRRRRR]P
                  3	V3R lV 3R llltV3R lR	 ltV3R
 lR ltRt	Vt
V ;t# )Ú*AffineQuantizedMovingAverageMinMaxObserveri¨  g{®Gáz„?NFTc                óò   <€ V ^8„  d   QhRS[ RS[P                  RS[RS[S[,          RS[S[,          RS[S[,          RS[S[P                  ,          RS[S[P                  ,          R	S[R
S[S[,          /
# ©r   r;   r<   rŸ   r(   r)   r=   r>   r?   r@   rA   ©	r
   r   r   r   r   rD   rE   r   r   )r   r˜   s   "€r   r   Ú7AffineQuantizedMovingAverageMinMaxObserver.__annotate__©  s–   ø€ ÷ $
ñ $
á!ð$
ñ —k‘kð$
ñ !ð	$
ñ ™C•=ð$
ñ ™C•=ð$
ñ ‘e�_ð$
ñ ™eŸk™kÕ*ð$
ñ #¡5§;¡;Õ/ð$
ñ ð$
ñ $¡OÕ4ñ$
r   c                ó´   <€ W€n         W@n        V'       d*   V P                  ^8w  d   \        RV P                   24      h\        SV `  VVVVVVV	V
VVR7
       R# )é   z[MovingAverageMinMaxObserver doesn't support dynamic quantization for averaging constant of ©
r;   r<   rŸ   r(   r)   r=   r>   r?   r@   rA   N)Ú
is_dynamicÚaveraging_constantÚNotImplementedErrorÚsuperÚ__init__)r£   r;   r<   rŸ   rÀ   r(   r)   r=   r¿   r>   r?   r@   rA   ÚkwargsÚ	__class__s   &&&&&&&&&&&&&,€r   rÃ   Ú3AffineQuantizedMovingAverageMinMaxObserver.__init__©  sv   ø€ ð" %ŒØ"4Ôß˜$×1Ñ1°QÔ6Ü%ð)Ø)-×)@Ñ)@Ð(AðCóð ô
 	‰ÑØ%Ø%Ø#ØØØØ#Ø-Ø'Ø/ð 	ö 	
r   c                ó4   <€ V ^8„  d   QhRS[ P                  /# r–   r—   )r   r˜   s   "€r   r   r»   Ï  s   ø€ ÷ ñ ™UŸ\™\ñ r   c                ó˜  € VP                  4       ^ 8X  d   V# VP                  4       pVP                  V n        V P                  f   Q R4       h\        VP                  V P                  4      V n        \        V P                  VP                  4       4      w  r4VP                  V4      p\        P                  ! W$RR7      p\        P                  ! W$RR7      p\        V R4      '       d   \        V R4      '       g   WPn        W`n        V# V P                  P                  VP                  8X  g,   Q RV P                  P                   RVP                   24       hV P                   P                  VP                  8X  g,   Q RV P                   P                   R	VP                   24       hV P                  V P"                  WPP                  ,
          ,          ,           pV P                   V P"                  W`P                   ,
          ,          ,           pV P                  P%                  V4       V P                   P%                  V4       V# r›   )rœ   r�   r   rž   rŸ   r   r€   r1   r7   rV   rW   r   rX   rY   r    r9   r:   rÀ   r¡   r¢   s   &&     r   r¥   Ú2AffineQuantizedMovingAverageMinMaxObserver.forwardÏ  sâ  € Ø�;‰;‹=˜AÔØˆLàŸ™›ˆØ,×2Ñ2ˆÔØ×ÑÒ+ÐBÐ-BÓBÐ+Ü(¨×)=Ñ)=¸t×?OÑ?OÓPˆŒä.CØ�O‰O˜^×0Ñ0Ó2ó/
Ñ+Ðð (×,Ñ,Ð-@ÓAˆÜ—*’*˜^ÈÔOˆÜ—*’*˜^ÈÔOˆÜ�t˜Y×'Ò'¬w°t¸Y×/GÒ/GØ"ŒLØ"ŒLð ˆð —<‘<×%Ñ%¨¯©Ô6ð ØOÐPT×P\ÑP\×PbÑPbÐOcÐcoÐpw×p}Ñp}Ðo~ÐóÐ6ð —<‘<×%Ñ%¨¯©Ô6ð ØOÐPT×P\ÑP\×PbÑPbÐOcÐcoÐpw×p}Ñp}Ðo~ÐóÐ6ð —l‘l T×%<Ñ%<ÀÏ,É,Õ@VÕ%WÕWˆGØ—l‘l T×%<Ñ%<ÀÏ,É,Õ@VÕ%WÕWˆGØ�L‰L×Ñ˜wÔ'Ø�L‰L×Ñ˜wÔ'ð ˆr   c                ó^   <€ V ^8„  d   QhRS[ S[P                  S[P                  3,          /# r¨   r©   )r   r˜   s   "€r   r   r»   ð  s&   ø€ ÷ 
ñ 
¡5©¯©±u·|±|Ð)CÕ#Dñ 
r   c                ó`  € \        V R 4      '       d   \        V R4      '       g   Q R4       h\        V P                  V P                  V P                  . V P
                  V P                  V P                  V P                  V P                  V P                  V P                  V P                  4      # r«   r¬   r­   s   &r   r®   Ú<AffineQuantizedMovingAverageMinMaxObserver.calculate_qparamsð  s–   € Ü�t˜Y×'Ò'¬G°D¸)×,DÒ,Dð 	
Øvó	
ÐDô 2Ø�L‰LØ�L‰LØ×ÑØØ×ÑØ�N‰NØ�N‰NØ�H‰HØ×ÑØ×!Ñ!Ø×ÑØ×"Ñ"ó
ð 	
r   )rÀ   r1   r¿   r:   r9   rž   ©r°   r±   r²   r³   r   r\   rÃ   r¥   r®   r´   rµ   Ú__classcell__©rÅ   r˜   s   @@r   r·   r·   ¨  sM   ù‡ € ð  Ø#'Ø#'Ø#ØØ-1Ø26Ø"Ø7F×7JÑ7J÷$
õ $
÷Lð ÷B
÷ 
ð 
r   r·   c                   ór   a a€ ] tR tRt oRRRRRRR]P
                  3V3R lV 3R llltR tR tR	t	Vt
V ;t# )
Ú"AffineQuantizedPlaceholderObserveri  NFTc                óò   <€ V ^8„  d   QhRS[ RS[P                  RS[RS[S[,          RS[S[,          RS[S[,          RS[S[P                  ,          RS[S[P                  ,          R	S[R
S[S[,          /
# r¹   rº   )r   r˜   s   "€r   r   Ú/AffineQuantizedPlaceholderObserver.__annotate__  s–   ø€ ÷ 
ñ 
á!ð
ñ —k‘kð
ñ !ð	
ñ
 ™C•=ð
ñ ™C•=ð
ñ ‘e�_ð
ñ ™eŸk™kÕ*ð
ñ #¡5§;¡;Õ/ð
ñ ð
ñ $¡OÕ4ñ
r   c                óF   <€ Wpn         \        SV `	  VVVVVVVV	V
VR 7
       R# )r¾   N)r¿   rÂ   rÃ   )r£   r;   r<   rŸ   r(   r)   r=   r¿   r>   r?   r@   rA   rÄ   rÅ   s   &&&&&&&&&&&&,€r   rÃ   Ú+AffineQuantizedPlaceholderObserver.__init__  s:   ø€ ð  %Œä‰ÑØ%Ø%Ø#ØØØØ#Ø-Ø'Ø/ð 	ö 	
r   c                ór   € \        VP                  V P                  4      V n        VP                  V n        V# r   )r   r€   rŸ   r1   r   rž   )r£   rK   s   &&r   r¥   Ú*AffineQuantizedPlaceholderObserver.forward%  s+   € Ü(¨¯©°d×6FÑ6FÓGˆŒØ#Ÿk™kˆÔØˆr   c                ó   € \        R 4      h)z>calculate_qparams should not be called for PlaceholderObserver)Ú	Exceptionr­   s   &r   r®   Ú4AffineQuantizedPlaceholderObserver.calculate_qparams*  s   € ÜØLó
ð 	
r   )r1   r¿   rž   rÍ   rÏ   s   @@r   rÑ   rÑ     s>   ù‡ € ð $(Ø#'Ø#ØØ-1Ø26Ø"Ø7F×7JÑ7J÷
õ 
ò>÷

ò 
r   rÑ   c                óâ   € V ^8„  d   Qh/ ^ \         9   d
   \        ;R&   ^\         9   dG   \        \        \        P
                  \        3,          \        \        \        3,          3,          ;R&   # )r   r   r&   )	Ú__conditional_annotations__r   Údictr   r   r   r   rC   rD   )r   s   "r   r   r   
   sP   € ‡�÷ )Ò („SÑ (ñ ÷Nò œœe¤E§K¡K´Ð$=Õ>ÄÄcÌ3ÀhÅÐOÕPñ òO r   )r   r½   )r   é   )r   é   )r   é   )r   é   )r   é?   )r   é   )r   éÿ   )i€ÿÿÿrã   )i €ÿÿiÿ  )i   €iÿÿÿ)	NNNNNTr\   NN)>rÜ   ÚloggingÚabcr   Útypingr   r   r   r   r   Útorchao.quantizationr   Ú"torchao.quantization.pt2e.observerr	   r
   r   r   Útorchao.quantization.utilsr   Úobjectr   Ú	getLoggerr°   Úloggerr   r   r   r   r"   Úuint1Úuint2Úuint3Úuint4Úuint5Úuint6Úuint7rv   rw   Úint8Úint16r‘   r&   Úupdater    r,   r7   r\   rI   rG   Úno_gradrq   rH   ro   rx   r}   rŠ   rˆ   r�   r”   r·   rÑ   r   )rÜ   s   @r   Ú<module>rù      sB  øð÷ €Ý ß -Ó -ã å ,÷ó õ 6á�5˜6˜) RÓ(€Ó (à	×	Ò	˜8Ó	$€ð 
×ÑØ	×ÑØ	×ÑØ	×Ñð	€	ð 
‡K�K�Ø	‡K�K�Ø	‡K�K�Ø	‡K�K�Ø	‡K�K�Ø	‡K�K�Ø	‡K�K�ðÐ ðð
 
‡K�K�Ø	‡J�J�Ø	‡K�KÐ&Ø	‡K�KÐ&ð	TÐ ó ð × Ñ Ð4Ô 5õò ò>'/ð`  $Ø#ØØ)-Ø.2ØØ3B×3FÑ3F÷&÷R@3ðF ‡‚ƒð .2Ø-1Ø3B×3FÑ3Fö5ó ð5ð| 48Ø37Ø'6×':Ñ':×'?Ñ'?÷ ðT (7×':Ñ':×'?Ñ'?÷>ðN .2Ø-1Ø)8×)<Ñ)<ñ,ð !&§¡÷,ð ,ðj 48Ø37Ø'6×':Ñ':×'?Ñ'?Ø %§¡÷ ðT (7×':Ñ':×'?Ñ'?Ø %§¡÷G9ôT2
Ð$?ô 2
ôjZ
Ð1Lô Z
ôz(
Ð)Dö (
r   