+
    "Ý³jÜy  ã            
       óÖ  € R t ^ RIt^ RIHtHt ^ RIHtHtHt ^ RI	t	^ RI
Ht ^ RIHt ^ RIHtHtHt ^ RIHt ^ RIHtHtHtHtHtHtHtHtHtHt ^ R	IH t  . R-Ot!R R lt"R R lt#R R lt$R R lt% ! R R
]]4      t& ! R R]&4      t' ! R R]'4      t( ! R R]'4      t) ! R R]'4      t*]'PW                  ]^ ^ÿ]	PX                  ]	PZ                  RR7      t. ]'PW                  ]R.^]	P^                  ]	P`                  RR7      t1 ]'PW                  ]^ ^ÿR]	PX                  ^R7      t2 ](PW                  ]R 7      t3](PW                  ]R 7      t4]3t5]4t6]'PW                  ]R.^]	P^                  ]	Pn                  R^ R!7      t8 ]'PW                  ]]	Pr                  ]	PX                  ^ ^ÿ^ ^R"7      t: ]'PW                  ]]	Pr                  ^ ]	Pv                  ^R#7      t<]'PW                  ]^ ^ÿ]	PX                  ]	PZ                  RR7      t= ])PW                  ]^ ^ÿ]	PX                  R$7      t> ])PW                  ]R.^]	P^                  ]	P`                  R%7      t? ])PW                  ]R.^]	P^                  ]	Pn                  R%7      t@ ])PW                  ]R/^]	P^                  ]	P`                  R0R&7      tA ])PW                  ]R/^]	P^                  ]	Pn                  R0R&7      tB ]*PW                  ]]P†                  ]	Pˆ                  ]! 4       R'7      tE ]*PW                  ]]PŒ                  ]	PŽ                  ]! ^€4      R'7      tH ]*PW                  ]]PŒ                  ]	PŽ                  ]! ^ 4      R'7      tI R( tJR) tKR* tLR+ tMR, tNR# )1z6Implements modules  used to perform fake quantization.N)ÚABCÚabstractmethod)ÚAnyÚOptionalÚTuple)ÚNode)ÚModule)ÚPerAxisÚPerGroupÚ	PerTensor)ÚAffineQuantizedMinMaxObserver)
ÚAffineQuantizedObserverBaseÚFixedQParamsObserverÚHistogramObserverÚMappingTypeÚMovingAverageMinMaxObserverÚ%MovingAveragePerChannelMinMaxObserverÚZeroPointDomainÚ
_with_argsÚ)default_fixed_qparams_range_0to1_observerÚ,default_fixed_qparams_range_neg1to1_observer)Ú_fake_quantize_affineÚFakeQuantizeBaseÚFakeQuantizeÚFixedQParamsFakeQuantizeÚFusedMovingAvgObsFakeQuantizeÚAffineFakeQuantizec                ó(   € V ^8„  d   QhRRR\         /# ©é   Úqschemeztorch.qschemeÚreturn©Úbool)Úformats   "Úh/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torchao/quantization/pt2e/fake_quantize.pyÚ__annotate__r&   G   s   € ÷ ñ ˜_ð ´ñ ó    c                 óf   € V \         P                  \         P                  \         P                  39   # ©N)ÚtorchÚper_channel_symmetricÚper_channel_affineÚ per_channel_affine_float_qparams©r    s   &r%   Ú_is_per_channelr/   G   s/   € ØÜ×#Ñ#Ü× Ñ Ü×.Ñ.ðñ ð r'   c                ó(   € V ^8„  d   QhRRR\         /# r   r"   )r$   s   "r%   r&   r&   O   s   € ÷ Lñ L˜Oð L´ñ Lr'   c                 óH   € V \         P                  \         P                  39   # r)   )r*   Úper_tensor_symmetricÚper_tensor_affiner.   s   &r%   Ú_is_per_tensorr4   O   s   € Ø”u×1Ñ1´5×3JÑ3JÐKÑKÐKr'   c                ó(   € V ^8„  d   QhRRR\         /# r   r"   )r$   s   "r%   r&   r&   S   s   € ÷ Pñ P ð P´Tñ Pr'   c                 óH   € V \         P                  \         P                  39   # r)   )r*   r2   r+   r.   s   &r%   Ú_is_symmetric_quantr7   S   s   € Ø”u×1Ñ1´5×3NÑ3NÐOÑOÐOr'   c                ó(   € V ^8„  d   QhRRR\         /# r   r"   )r$   s   "r%   r&   r&   W   s   € ÷ ñ ˜ð ´4ñ r'   c                 ó*   € V \         P                  39   # r)   )r*   r-   r.   s   &r%   Ú_is_float_qparamsr:   W   s   € ØÜ×.Ñ.ðñ ð r'   c                   ó~  a a€ ] tR t^]t oRtV3R lV 3R llt]R 4       t]R 4       t]	P                  P                  RV3R lR ll4       t]	P                  P                  R 4       t]	P                  P                  RV3R	 lR
 ll4       t]	P                  P                  R 4       t]R 4       tV3R ltRtVtV ;t# )r   a”  Base fake quantize module.

Base fake quantize module
Any fake quantize implementation should derive from this class.

Concrete fake quantize module should follow the same API. In forward, they will update
the statistics of the observed Tensor and fake quantize the input. They should also provide a
`calculate_qparams` function that computes the quantization parameters given
the collected statistics.

c                ó   <€ V ^8„  d   QhRR/# )r   r!   N© )r$   Ú__classdict__s   "€r%   r&   ÚFakeQuantizeBase.__annotate__m   s   ø€ ÷ Wñ W˜$ñ Wr'   c                ó   <€ \         SV `  4        V P                  R\        P                  ! ^.\        P
                  R7      4       V P                  R\        P                  ! ^.\        P
                  R7      4       R# )z,Set fake_quant_enabled and observer_enabled.Úfake_quant_enabled©ÚdtypeÚobserver_enabledN)ÚsuperÚ__init__Úregister_bufferr*   ÚtensorÚuint8)ÚselfÚ	__class__s   &€r%   rF   ÚFakeQuantizeBase.__init__m   sT   ø€ ä‰ÑÔð 	×ÑÐ1´5·<²<ÀÀÌ5Ï;É;Ô3WÔXØ×ÑÐ/´·²¸q¸cÌÏÉÔ1UÖVr'   c                ó   € R # r)   r=   )rJ   Úxs   &&r%   ÚforwardÚFakeQuantizeBase.forwardv   ó   € ár'   c                ó   € R # r)   r=   )rJ   Úkwargss   &,r%   Úcalculate_qparamsÚ"FakeQuantizeBase.calculate_qparamsz   rQ   r'   c                ó$   <€ V ^8„  d   QhRS[ RR/# ©r   Úenabledr!   Nr"   )r$   r>   s   "€r%   r&   r?      s   ø€ ÷ 9ñ 9©ð 9¸ñ 9r'   c                ó8   € V'       d   ^M^ V P                   ^ &   R# ©é   N)rA   ©rJ   rX   s   &&r%   Úenable_fake_quantÚ"FakeQuantizeBase.enable_fake_quant~   s   € ç*1¡Q°qˆ×Ñ Ó"r'   c                ó(   € V P                  R 4       R# ©FN)r]   ©rJ   s   &r%   Údisable_fake_quantÚ#FakeQuantizeBase.disable_fake_quant‚   s   € à×Ñ˜uÖ%r'   c                ó$   <€ V ^8„  d   QhRS[ RR/# rW   r"   )r$   r>   s   "€r%   r&   r?   ‡   s   ø€ ÷ 7ñ 7¡tð 7°tñ 7r'   c                ó8   € V'       d   ^M^ V P                   ^ &   R# rZ   )rD   r\   s   &&r%   Úenable_observerÚ FakeQuantizeBase.enable_observer†   s   € ç(/¡1°Qˆ×Ñ˜aÓ r'   c                ó(   € V P                  R 4       R# r`   )rf   ra   s   &r%   Údisable_observerÚ!FakeQuantizeBase.disable_observerŠ   s   € à×Ñ˜UÖ#r'   c                ó,   € \        V 3/ VB pR Vn        V# )z'torchao.quantization.pt2e.fake_quantize)r   Ú
__module__)ÚclsrS   Úfake_quant_constructors   &, r%   Ú	with_argsÚFakeQuantizeBase.with_argsŽ   s$   € ä!+¨CÑ!:°6Ñ!:Ðð -VÐÔ)Ø%Ð%r'   c                óZ   <€ V ^8„  d   Qh/ S[ P                  ;R&   S[ P                  ;R&   # )r   rA   rD   ©r*   ÚTensor)r$   r>   s   "€r%   r&   r?   ]   s'   ø‡ ‚ ñ Ÿ™Ñ$ñ ñ —l‘lÑ"ò r'   r=   )T)Ú__name__rl   Ú__qualname__Ú__firstlineno__Ú__doc__rF   r   rO   rT   r*   ÚjitÚexportr]   rb   rf   ri   Úclassmethodro   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__Ú__classcell__©rK   r>   s   @@r%   r   r   ]   sÜ   ù‡ € ñ
÷Wó Wð ñó ðð ñó ðð ‡Y�Y×Ñ÷9ñ 9ó ð9ð ‡Y�Y×Ññ&ó ð&ð ‡Y�Y×Ñ÷7ñ 7ó ð7ð ‡Y�Y×Ññ$ó ð$ð ñ&ó ð&÷e … r'   c                   óÜ   a a€ ] tR t^—t oRt]RRR3V 3R llt]P                  P                  R 4       t
R t]P                  P                  R 4       tV 3R ltV 3R	 ltV3R
 ltRtVtV ;t# )r   a÷  Simulate the quantize and dequantize operations in training time.

The output of this module is given by::

    x_out = (
      clamp(round(x/scale + zero_point), quant_min, quant_max) - zero_point
    ) * scale

* :attr:`is_dynamic` indicates whether the fake quantie is a placeholder for dynamic quantization
  operators (choose_qparams -> q -> dq) or static quantization operators (q -> dq)

* :attr:`scale` defines the scale factor used for quantization.

* :attr:`zero_point` specifies the quantized value to which 0 in floating point maps to

* :attr:`fake_quant_enabled` controls the application of fake quantization on tensors, note that
  statistics can still be updated.

* :attr:`observer_enabled` controls statistics collection on tensors

* :attr:`dtype` specifies the quantized dtype that is being emulated with fake-quantization,
    allowable values are torch.qint8 and torch.quint8.

Args:

    observer (module): Module for observing statistics on input tensors and calculating scale
      and zero-point.
    observer_kwargs (optional): Arguments for the observer module

Attributes:
    activation_post_process (Module): User provided module that collects statistics on the input tensor and
      provides a method to calculate scale and zero-point.

NFc                ó¬  <€ \         SV `  4        VeÙ   VeÕ   W#8:  g   Q R4       hVP                  R\        P                  4      p\        VR4      '       d)   \        \        VR/ 4      R/ 4      P                  RV4      p\        P                  ! V4      P                  V8:  g   Q R4       hV\        P                  ! V4      P                  8:  g   Q R4       hVP                  RVRV/4       WER	&   V! R/ VB V n        V P                  P                  V n        V P                  P                  V n        V P                  P                  V n        \        V P                  P                   4      '       d   \        P"                  pM\        P$                  pV P'                  R
\        P(                  ! R.\        P"                  R7      4       V P'                  R\        P(                  ! ^ .VR7      4       V P                  P*                  V n        V P                  P                   V n        \        V P                  R4      '       d   V P                  P,                  MRV n        \/        V P                   4      '       g=   \1        V P                   4      '       g"   Q R\3        V P                   4      ,           4       h\/        V P                   4      V n        R # )Nz1quant_min must be less than or equal to quant_maxrC   ÚpÚkeywordszquant_min out of boundzquant_max out of boundÚ	quant_minÚ	quant_maxÚ
is_dynamicÚscaleç      ð?rB   Ú
zero_pointÚch_axisr=   éÿÿÿÿzYOnly per channel and per tensor quantization are supported in fake quantize got qscheme: )rE   rF   Úgetr*   Úquint8ÚhasattrÚgetattrÚiinfoÚminÚmaxÚupdateÚactivation_post_processr„   r…   r†   r:   r    ÚfloatÚintrG   rH   rC   rŠ   r/   r4   ÚstrÚis_per_channel)	rJ   Úobserverr„   r…   r†   Úobserver_kwargsrC   Úzero_point_dtyperK   s	   &&&&&,  €r%   rF   ÚFakeQuantize.__init__¾   sF  ø€ ô 	‰ÑÔàÒ  YÒ%:ØÔ)ð ØCóÐ)ð $×'Ñ'¨´·±Ó>ˆEÜ�x ×%Ò%ô  ¤¨°#°rÓ :¸JÈÓK×OÑOØ˜Uó�ô —;’;˜uÓ%×)Ñ)¨YÔ6ÐPÐ8PÓPÐ6Ø¤§¢¨EÓ 2× 6Ñ 6Ô6ÐPÐ8PÓPÐ6Ø×"Ñ" K°¸KÈÐ#SÔTØ(2˜Ñ%Ù'/Ñ'B°/Ñ'BˆÔ$ð ×5Ñ5×?Ñ?ˆŒØ×5Ñ5×?Ñ?ˆŒØ×6Ñ6×AÑAˆŒÜ˜T×9Ñ9×AÑA×BÒBÜ$Ÿ{™{Ñä$Ÿy™yÐØ×Ñ˜W¤e§l¢l°C°5ÄÇÁÔ&LÔMØ×Ñ˜\¬5¯<ª<¸¸ÐCSÔ+TÔUØ×1Ñ1×7Ñ7ˆŒ
Ø×3Ñ3×;Ñ;ˆŒô �t×3Ñ3°Y×?Ò?ð ×(Ñ(×0Ò0àð 	Œô
 ˜tŸ|™|×,Ò,´¸t¿|¹|×0LÒ0Lð 	
ðä�$—,‘,Óõ ó	
ÐLô
 .¨d¯l©lÓ;ˆÖr'   c                ó6   € V P                   P                  4       # r)   ©r”   rT   ra   s   &r%   rT   ÚFakeQuantize.calculate_qparamsñ   ó   € à×+Ñ+×=Ñ=Ó?Ð?r'   c                ó<  € V P                   ^ ,          ^8X  Ed    V P                  VP                  4       4       V P                  4       w  r#VP	                  V P
                  P                  4      VP	                  V P                  P                  4      r2V P
                  P                  VP                  8w  dK   V P
                  P                  VP                  4       V P                  P                  VP                  4       V P
                  P                  V4       V P                  P                  V4       V P                  ^ ,          ^8X  dÌ   V P                  '       dd   \        P                  ! VV P
                  V P                  V P                  V P                  P                   V P                  P"                  4      pV# \        P$                  ! VV P
                  V P                  V P                  P                   V P                  P"                  4      pV# )é    )rD   r”   ÚdetachrT   Útor‡   Údevicer‰   ÚshapeÚresize_Úcopy_rA   r˜   r*   Ú fake_quantize_per_channel_affinerŠ   r„   r…   Úfake_quantize_per_tensor_affine©rJ   ÚXÚ_scaleÚ_zero_points   &&  r%   rO   ÚFakeQuantize.forwardõ   s‰  € Ø× Ñ  Õ# qÕ(Ø×(Ñ(¨¯©«Ô4Ø"&×"8Ñ"8Ó":ÑˆFà—	‘	˜$Ÿ*™*×+Ñ+Ó,Ø—‘˜tŸ™×5Ñ5Ó6ð  ð �z‰z×Ñ 6§<¡<Ô/Ø—
‘
×"Ñ" 6§<¡<Ô0Ø—‘×'Ñ'¨×(9Ñ(9Ô:Ø�J‰J×Ñ˜VÔ$Ø�O‰O×!Ñ! +Ô.à×"Ñ" 1Õ%¨Ô*Ø×"×"Ð"Ü×:Ò:ØØ—J‘JØ—O‘OØ—L‘LØ×0Ñ0×:Ñ:Ø×0Ñ0×:Ñ:ó�ð  ˆô ×9Ò9ØØ—J‘JØ—O‘OØ×0Ñ0×:Ñ:Ø×0Ñ0×:Ñ:ó�ð ˆr'   c                ó  € R V P                    RV P                   RV P                  P                   RV P                  P                   RV P
                   RV P                   RV P                   RV P                   RV P                   2# )	úfake_quant_enabled=ú, observer_enabled=ú, quant_min=ú, quant_max=ú, dtype=ú
, qscheme=z
, ch_axis=ú, scale=ú, zero_point=)
rA   rD   r”   r„   r…   rC   r    rŠ   r‡   r‰   ra   s   &r%   Ú
extra_reprÚFakeQuantize.extra_repr  s“   € ð " $×"9Ñ"9Ð!:Ð:MÈd×NcÑNcÐMdð eØ×5Ñ5×?Ñ?Ð@ÀÈT×MiÑMi×MsÑMsÐLtð uØ—Z‘Z�L 
¨4¯<©<¨.¸
À4Ç<Á<À.ð QØ—Z‘Z�L ¨d¯o©oÐ->ð@ð	
r'   c                ó|   <€ \         SV `  WV4       V P                  WR ,           &   V P                  WR,           &   R# ©r‡   r‰   N)rE   Ú_save_to_state_dictr‡   r‰   )rJ   ÚdestinationÚprefixÚ	keep_varsrK   s   &&&&€r%   r½   Ú FakeQuantize._save_to_state_dict   s6   ø€ ô 	‰Ñ# K¸ÔCØ(,¯
©
ˆ˜WÕ$Ñ%Ø-1¯_©_ˆ˜\Õ)Ó*r'   c           	     óH  <€ R R.pV EF   p	W),           p
W¡9   dÔ   W,          pV	R 8X  d'   V P                   P                  VP                  4       M.V	R8X  g   Q hV P                  P                  VP                  4       \        P
                  P                  4       '       dK   V	R 8X  d   V P                   P                  V4       K½  V	R8X  g   Q hV P                  P                  V4       Kã  Kå  V'       g   Kï  VP                  V
4       EK  	  \        SV `)  VVVVVVV4       R# r¼   )r‡   r§   r¦   r‰   r*   rx   Úis_scriptingr¨   ÚappendrE   Ú_load_from_state_dict)rJ   Ú
state_dictr¿   Úlocal_metadataÚstrictÚmissing_keysÚunexpected_keysÚ
error_msgsÚlocal_stateÚnameÚkeyÚvalrK   s   &&&&&&&&    €r%   rÅ   Ú"FakeQuantize._load_from_state_dict'  sü   ø€ ð  Ð-ˆÜˆDØ•-ˆCØÔ Ø •o�ð
 ˜7”?Ø—J‘J×&Ñ& s§y¡yÕ1à <Ô/Ð/Ð/Ø—O‘O×+Ñ+¨C¯I©IÔ6ô —9‘9×)Ñ)×+Ò+Ø˜w”ØŸ
™
×(Ñ(¨Ö-à# |Ô3Ð3Ð3ØŸ™×-Ñ-¨cÖ2ñ ,÷ ‘Ø×#Ñ# C×(ñ-  ô. 	‰Ñ%ØØØØØØØö	
r'   c                óZ   <€ V ^8„  d   Qh/ S[ P                  ;R&   S[ P                  ;R&   # ©r   r‡   r‰   rr   )r$   r>   s   "€r%   r&   ÚFakeQuantize.__annotate__—   s+   ø‡ ‚ ñH �<‰<ÑñI ñJ —‘ÑòK r'   )r”   rŠ   rC   r†   r˜   r    r…   r„   )rt   rl   ru   rv   rw   r   rF   r*   rx   ry   rT   rO   r¹   r½   rÅ   r{   r|   r}   r~   r   s   @@r%   r   r   —   su   ù‡ € ñ!ðP -ØØØ÷1<ðf ‡Y�Y×Ññ@ó ð@ò ðD ‡Y�Y×Ññ
ó ð
õ=õ,
÷a … r'   c                   ó¦   a a€ ] tR tRt oRtV 3R lt]P                  P                  R 4       t	]P                  P                  R 4       t
RtVtV ;t# )r   iV  zµSimulate quantize and dequantize in training time.

Simulate quantize and dequantize with fixed quantization
parameters in training time. Only per tensor quantization
is supported.
c                ó°  <€ \         SV `  VR 7       \        V P                  4      \        8X  g/   Q V P
                  P                   R\        P                   24       hWn        V P                  P                  V n        V P                  P                  V n	        \        V P                  4      '       g"   Q R\        V P                  4      ,           4       hR# )©r™   z's observer must be a NzWOnly per tensor quantization is supported FixedQParamsFakeQuantize module, got qscheme:)rE   rF   Útyper”   r   rK   rt   Ú_observer_ctrr‡   r‰   r4   r    r—   )rJ   r™   rK   s   &&€r%   rF   Ú!FixedQParamsFakeQuantize.__init___  s¶   ø€ Ü‰Ñ (ÐÔ+Ü�D×0Ñ0Ó1Ô5IÔIð 	
Ø�~‰~×&Ñ&Ð'Ð'=Ô>R×>[Ñ>[Ð=\Ð]ó	
ÐIð &ÔØ×1Ñ1×7Ñ7ˆŒ
Ø×6Ñ6×AÑAˆŒÜ˜dŸl™l×+Ò+ð 	
ð?ä�$—,‘,Óõ ó	
Ò+r'   c                ó2   € V P                   V P                  3# r)   )r‡   r‰   ra   s   &r%   rT   Ú*FixedQParamsFakeQuantize.calculate_qparamsm  s   € à�z‰z˜4Ÿ?™?Ð*Ð*r'   c                óþ   € RV P                    RV P                   RV P                   RV P                   RV P                   RV P
                  P                   RV P
                  P                   RV P                   2# )	z:Define a string representation of the object's attributes.r±   r²   r·   r¸   rµ   r³   r´   r¶   )	rA   rD   r‡   r‰   rC   r”   r„   r…   r    ra   s   &r%   r¹   Ú#FixedQParamsFakeQuantize.extra_reprq  sˆ   € ð " $×"9Ñ"9Ð!:Ð:MÈd×NcÑNcÐMdð eØ—Z‘Z�L ¨d¯o©oÐ->ð ?Ø—Z‘Z�L ¨T×-IÑ-I×-SÑ-SÐ,Tð UØ×5Ñ5×?Ñ?Ð@À
È4Ï<É<È.ðZð	
r'   )rØ   r‡   r‰   )rt   rl   ru   rv   rw   rF   r*   rx   ry   rT   r¹   r|   r}   r~   r   s   @@r%   r   r   V  sP   ù‡ € ñõ
ð ‡Y�Y×Ññ+ó ð+ð ‡Y�Y×Ññ
ó ÷
ð 
r'   c                   óæ   a a€ ] tR tRt oRt]^ ^ÿ3V3R lV 3R lllt]P                  P                  V3R lR l4       t
]P                  P                  V3R lR l4       tV3R	 lR
 ltRtVtV ;t# )r   i|  a�  Define a fused module to observe the tensor.

Fused module that is used to observe the input tensor (compute min/max), compute
scale/zero_point and fake_quantize the tensor.
This module uses calculation similar MovingAverageMinMaxObserver for the inputs,
to compute the min/max values in order to compute the scale/zero_point.
The qscheme input in the observer is used to differentiate between symmetric/affine
quantization scheme.

The output of this module is given by
x_out = (clamp(round(x/scale + zero_point), quant_min, quant_max)-zero_point)*scale

Similar to :class:`~torchao.quantization.pt2e.FakeQuantize`, and accepts the same attributes as the
base class.

c          
      ó6   <€ V ^8„  d   QhRS[ RS[RS[RS[ RR/# )r   r™   r„   r…   rš   r!   N)r   r–   )r$   r>   s   "€r%   r&   Ú*FusedMovingAvgObsFakeQuantize.__annotate__Ž  s=   ø€ ÷ 
ñ 
áð
ñ ð
ñ ð	
ñ
 ð
ð 
ñ
r'   c                óª  <€ \         SV `  ! WV3/ VB  \        V P                  \        \
        34      '       g   Q R 4       hV P                  R\        P                  ! ^.\        P                  R7      4       V P                  R\        P                  ! ^.\        P                  R7      4       \        V P                  P                  4      V n        R# )zLFused observer+fake_quant module only works with MovingAverageMinMaxObserverrA   rB   rD   N)rE   rF   Ú
isinstancer”   r   r   rG   r*   rH   Úlongr7   r    Úis_symmetric_quant)rJ   r™   r„   r…   rš   rK   s   &&&&,€r%   rF   Ú&FusedMovingAvgObsFakeQuantize.__init__Ž  s¯   ø€ ô 	‰Ò˜¨iÑK¸?ÒKÜØ×(Ñ(Ü(Ô*OÐP÷
ò 
ð 	
ð [ó		
ð 
ð 	×ÑÐ1´5·<²<ÀÀÌ5Ï:É:Ô3VÔWØ×ÑÐ/´·²¸q¸cÌÏÉÔ1TÔUÜ"5Ø×(Ñ(×0Ñ0ó#
ˆÖr'   c                ó^   <€ V ^8„  d   QhRS[ S[P                  S[P                  3,          /# ©r   r!   )Útupler*   rs   )r$   r>   s   "€r%   r&   rà   £  s)   ø€ ÷ @ñ @¡5©¯©±u·|±|Ð)CÕ#Dñ @r'   c                ó6   € V P                   P                  4       # r)   rž   ra   s   &r%   rT   Ú/FusedMovingAvgObsFakeQuantize.calculate_qparams¢  r    r'   c                ó    <€ V ^8„  d   QhRS[ /# rç   ©r—   )r$   r>   s   "€r%   r&   rà   §  s   ø€ ÷ 
ñ 
™Cñ 
r'   c                ó,  € R V P                    RV P                   RV P                   RV P                   RV P                   RV P
                  P                   RV P
                  P                   RV P                   RV P
                  P                   2# )	r±   r²   r·   r¸   rµ   r³   r´   r¶   z, reduce_range=)
rA   rD   r‡   r‰   rC   r”   r„   r…   r    Úreduce_rangera   s   &r%   r¹   Ú(FusedMovingAvgObsFakeQuantize.extra_repr¦  sœ   € ð " $×"9Ñ"9Ð!:Ð:MÈd×NcÑNcÐMdð eØ—Z‘Z�L ¨d¯o©oÐ->¸hÀtÇzÁzÀlð SØ×5Ñ5×?Ñ?Ð@ÀÈT×MiÑMi×MsÑMsÐLtð uØ—|‘|�n O°D×4PÑ4P×4]Ñ4]Ð3^ð`ð	
r'   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r   r¬   r!   rr   )r$   r>   s   "€r%   r&   rà   ¯  s#   ø€ ÷ 
ñ 
™Ÿ™ð 
©%¯,©,ñ 
r'   c                óš  € \         P                  ! VV P                  V P                  V P                  P
                  V P                  P                  V P                  V P                  V P                  P                  V P                  P                  V P                  P                  V P                  V P                  V P                  4      # r)   )r*   Úfused_moving_avg_obs_fake_quantrD   rA   r”   Úmin_valÚmax_valr‡   r‰   Úaveraging_constantr„   r…   rŠ   r˜   rä   )rJ   r¬   s   &&r%   rO   Ú%FusedMovingAvgObsFakeQuantize.forward¯  sœ   € Ü×4Ò4ØØ×!Ñ!Ø×#Ñ#Ø×(Ñ(×0Ñ0Ø×(Ñ(×0Ñ0Ø�J‰JØ�O‰OØ×(Ñ(×;Ñ;Ø×(Ñ(×2Ñ2Ø×(Ñ(×2Ñ2Ø�L‰LØ×ÑØ×#Ñ#ó
ð 	
r'   )rä   )rt   rl   ru   rv   rw   r   rF   r*   rx   ry   rT   r¹   rO   r|   r}   r~   r   s   @@r%   r   r   |  sl   ù‡ € ñð& 4ØØ÷	
õ 
ð( ‡Y�Y×Ñ÷@ó ð@ð ‡Y�Y×Ñ÷
ó ð
÷
÷ 
ð 
r'   c                   óö   a € ] tR tRt o Rt]R3V 3R lR llt]P                  P                  V 3R lR l4       t
V 3R lR	 lt]P                  P                  V 3R
 lR l4       tV 3R lR ltV 3R ltRtV tR# )r   iÁ  a2  Simulate quantize and dequantize with affine quantization in training time.

This fake quantize module supports all granularities including per-tensor,
per-axis, per-group, per-block, per-row, and per-token quantization through
the affine quantization primitives. It works with AffineQuantizedObserverBase
subclasses like AffineQuantizedMinMaxObserver and
AffineQuantizedMovingAverageMinMaxObserver.

The output of this module is given by::

    x_out = fake_quantize_affine(x, block_size, scale, zero_point, ...)

Args:
    observer (module): Module for observing statistics on input tensors and
        calculating scale and zero-point. Must be a subclass of
        AffineQuantizedObserverBase.
    is_dynamic (bool): Whether this is for dynamic quantization.
    **observer_kwargs: Arguments passed to the observer constructor.

Attributes:
    activation_post_process (AffineQuantizedObserverBase): The observer instance.
    scale (Tensor): The quantization scale.
    zero_point (Tensor): The quantization zero point.
    target_dtype (torch.dtype): The target quantized dtype.
    quant_min (Optional[int]): Minimum quantization value.
    quant_max (Optional[int]): Maximum quantization value.
    zero_point_domain (ZeroPointDomain): Domain of the zero point.
    mapping_type (MappingType): Mapping type for quantization.
    is_dynamic (bool): Whether this is dynamic quantization.
    block_size (Optional[Tuple[int, ...]]): Block size for groupwise quantization.

Example::

    >>> # Per-tensor fake quantize
    >>> fq = AffineFakeQuantize(
    ...     observer=AffineQuantizedMinMaxObserver,
    ...     mapping_type=MappingType.ASYMMETRIC,
    ...     target_dtype=torch.uint8,
    ...     granularity=PerTensor(),
    ... )
    >>> x = torch.randn(10, 20)
    >>> y = fq(x)

    >>> # Groupwise fake quantize
    >>> fq = AffineFakeQuantize(
    ...     observer=AffineQuantizedMinMaxObserver,
    ...     mapping_type=MappingType.SYMMETRIC,
    ...     target_dtype=torch.int8,
    ...     granularity=PerGroup(128),
    ... )
    >>> x = torch.randn(10, 256)
    >>> y = fq(x)
Fc                ó    <€ V ^8„  d   QhRS[ /# )r   r†   r"   )r$   r>   s   "€r%   r&   ÚAffineFakeQuantize.__annotate__û  s   ø€ ÷ ""ñ ""ñ ñ""r'   c                óü  € \         P                  V 4       W#R &   V! R/ VB V n        V P                  P                  V n        V P                  P                  V n        V P                  P
                  V n        V P                  P                  V n        V P                  P                  V n        V P                  P                  V n        W n	        V P                  \        P                  8X  d   \        P                  M\        P                  pV P                  R\        P                   ! R.\        P                  R7      4       V P                  R\        P                   ! ^ .VR7      4       RV n        RV n        R# )r†   r‡   rˆ   rB   r‰   NFr=   )r   rF   r”   Útarget_dtyper„   r…   Úzero_point_domainÚmapping_typeÚgranularityr†   r   ÚFLOATr*   r•   r–   rG   rH   Ú
block_sizeÚ_initialized)rJ   r™   r†   rš   r›   s   &&&, r%   rF   ÚAffineFakeQuantize.__init__û  s)  € ô 	×!Ñ! $Ô'à(2˜Ñ%ÙDLñ E
ØñE
ˆÔ$ð !×8Ñ8×EÑEˆÔØ×5Ñ5×?Ñ?ˆŒØ×5Ñ5×?Ñ?ˆŒØ!%×!=Ñ!=×!OÑ!OˆÔØ ×8Ñ8×EÑEˆÔØ×7Ñ7×CÑCˆÔØ$Œð ×%Ñ%¬×)>Ñ)>Ô>ô �KŠKä—‘ð 	ð 	×Ñ˜W¤e§l¢l°C°5ÄÇÁÔ&LÔMØ×Ñ˜\¬5¯<ª<¸¸ÐCSÔ+TÔUà59ˆŒØ!ˆÖr'   c                ó^   <€ V ^8„  d   QhRS[ S[P                  S[P                  3,          /# rç   )r   r*   rs   )r$   r>   s   "€r%   r&   rú      s)   ø€ ÷ @ñ @¡5©¯©±u·|±|Ð)CÕ#Dñ @r'   c                ó6   € V P                   P                  4       # )z=Calculate the quantization parameters (scale and zero_point).rž   ra   s   &r%   rT   Ú$AffineFakeQuantize.calculate_qparams  s   € ð ×+Ñ+×=Ñ=Ó?Ð?r'   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rñ   rr   )r$   r>   s   "€r%   r&   rú   $  s#   ø€ ÷ $ñ $™Ÿ™ð $©%¯,©,ñ $r'   c           
     ó^  € V P                   '       gB   V P                  VP                  4       4       V P                  P                  V n        R V n         V P                  ^ ,          ^8X  Ed<   V P                  VP                  4       4       V P                  4       w  r#VP                  V P                  P                  4      pVP                  V P                  P                  4      pV P                  P                  VP                  8w  dK   V P                  P                  VP                  4       V P                  P                  VP                  4       V P                  P                  V4       V P                  P                  V4       V P                  P                  V n        V P                  ^ ,          ^8X  dn   V P                  f   Q R4       h\        VV P                  V P                  V P                  V P                  V P                   V P"                  V P$                  4      pV# )TzŽblock_size must be set before fake quantization. Ensure the model is run at least one forward pass with both observer and fake_quant disabled.)r  r”   r£   r  rD   rT   r¤   r‡   r¥   r‰   r¦   r§   r¨   rA   r   rü   r„   r…   rý   r«   s   &&  r%   rO   ÚAffineFakeQuantize.forward$  sš  € Ø× × Ð Ø×(Ñ(¨¯©«Ô4Ø"×:Ñ:×EÑEˆDŒOØ $ˆDÔØ× Ñ  Õ# qÕ(Ø×(Ñ(¨¯©«Ô4Ø"&×"8Ñ"8Ó":ÑˆFØ—Y‘Y˜tŸz™z×0Ñ0Ó1ˆFØ%Ÿ.™.¨¯©×)?Ñ)?Ó@ˆKà�z‰z×Ñ 6§<¡<Ô/Ø—
‘
×"Ñ" 6§<¡<Ô0Ø—‘×'Ñ'¨×(9Ñ(9Ô:à�J‰J×Ñ˜VÔ$Ø�O‰O×!Ñ! +Ô.à"×:Ñ:×EÑEˆDŒOà×"Ñ" 1Õ%¨Ô*Ø—?‘?Ò.ð ð>óÐ.ô
 &ØØ—‘Ø—
‘
Ø—‘Ø×!Ñ!Ø—‘Ø—‘Ø×&Ñ&ó	ˆAð ˆr'   c                ó    <€ V ^8„  d   QhRS[ /# rç   rì   )r$   r>   s   "€r%   r&   rú   K  s   ø€ ÷ 

ñ 

™Cñ 

r'   c                ó$  € R V P                    RV P                   RV P                   RV P                   RV P                   RV P
                   RV P                   RV P                   RV P                   R	V P                   R
V P                   2# )r±   r²   r³   r´   z, target_dtype=z, granularity=z, mapping_type=z, zero_point_domain=r·   r¸   z, block_size=)rA   rD   r„   r…   rü   rÿ   rþ   rý   r‡   r‰   r  ra   s   &r%   r¹   ÚAffineFakeQuantize.extra_reprJ  s±   € ð " $×"9Ñ"9Ð!:ð ; Ø $× 5Ñ 5Ð6ð 7ØŸ™Ð(¨°T·^±^Ð4Dð EØ ×-Ñ-Ð.¨n¸T×=MÑ=MÐ<Nð OØ ×-Ñ-Ð.ð /!Ø!%×!7Ñ!7Ð 8ð 9Ø—Z‘Z�L ¨d¯o©oÐ->ð ?ØŸ/™/Ð*ð,ð		
r'   c                óN   <€ V ^8„  d   QhRS[ P                  P                  RS[/# )r   ÚmodelÚobserver_node)r*   ÚfxÚGraphModuler   )r$   r>   s   "€r%   r&   rú   W  s)   ø€ ÷ Cñ C™UŸX™X×1Ñ1ð CÁ$ñ Cr'   c                ó<   € V P                   P                  W4       R# )a�  
Converts the fake quantize node in the graph into its quantized representation.

This method delegates to the underlying activation_post_process (observer)'s
convert method, which handles the creation of quantize_affine/dequantize_affine
operations in the graph.

Args:
    model: graph module to convert the fake quantize node in
    observer_node: the fake quantize node to convert
N)r”   Úconvert)rJ   r  r  s   &&&r%   r  ÚAffineFakeQuantize.convertW  s   € ð 	×$Ñ$×,Ñ,¨UÖBr'   c                óZ   <€ V ^8„  d   Qh/ S[ P                  ;R&   S[ P                  ;R&   # rÒ   rr   )r$   r>   s   "€r%   r&   rú   Á  s+   ø‡ ‚ ñn �<‰<Ñño ñp —‘Ñòq r'   )
r  r”   r  rÿ   r†   rþ   r…   r„   rü   rý   N)rt   rl   ru   rv   rw   r   rF   r*   rx   ry   rT   rO   r¹   r  r{   r|   r}   )r>   s   @r%   r   r   Á  s{   ø‡ € ñ4ðv /Ø ÷""ò ""ðH ‡Y�Y×Ñ÷@ó ð@÷$ð $ðL ‡Y�Y×Ñ÷

ó ð

÷Cð C÷m ƒ r'   T)r™   r„   r…   rC   r    rî   F)r™   r„   r…   r†   rC   rö   rÖ   )r™   r„   r…   rC   r    rî   rŠ   )r™   r    rC   r„   r…   rŠ   rö   )r™   r    rŠ   rC   rö   )r™   r„   r…   rC   )r™   r„   r…   rC   r    )r™   r„   r…   rC   r    Úeps)r™   rþ   rü   rÿ   c                ó  € \        V \        P                  P                  4      '       dX   V P                  P
                  P                  R^4      ^,          p\        P                  ! RRV4      pVR8H  ;'       g    VR8H  # R# )zFReturn true if given mod is an instance of FakeQuantize script module.Ú.z\.___torch_mangle_\d+Ú z4torchao.quantization.pt2e.fake_quantize.FakeQuantizezEtorchao.quantization.pt2e.fake_quantize.FusedMovingAvgObsFakeQuantizeF)	râ   r*   rx   ÚRecursiveScriptModuleÚ_cÚqualified_nameÚsplitÚreÚsub)ÚmodÚsuffixrÍ   s   &  r%   Ú_is_fake_quant_script_moduler"  &  sx   € ä�#”u—y‘y×6Ñ6×7Ò7à—‘×&Ñ&×,Ñ,¨S°!Ó4°QÕ7ˆÜ�vŠvÐ.°°FÓ;ˆàÐJÑJ÷ Wð WØØVñWð	
ñ
 r'   c                óx   € \        V \        4      '       g   \        V 4      '       d   V P                  4        R# R# )zÒDisable fake quantization for the module.

Disable fake quantization for this module, if applicable. Example usage::

  # model is any PyTorch model
  model.apply(torchao.quantization.pt2e.disable_fake_quant)

N)râ   r   r"  rb   ©r   s   &r%   rb   rb   4  s/   € ô �#Ô'×(Ò(Ô,HÈ×,MÒ,MØ×ÑÖ ñ -Nr'   c                óx   € \        V \        4      '       g   \        V 4      '       d   V P                  4        R# R# )zÏEnable fake quantization for the module.

Enable fake quantization for this module, if applicable. Example usage::

  # model is any PyTorch model
  model.apply(torchao.quantization.pt2e.enable_fake_quant)

N)râ   r   r"  r]   r$  s   &r%   r]   r]   A  s/   € ô �#Ô'×(Ò(Ô,HÈ×,MÒ,MØ×ÑÖñ -Nr'   c                óx   € \        V \        4      '       g   \        V 4      '       d   V P                  4        R# R# )zÅDisable observation for this module.

Disable observation for this module, if applicable. Example usage::

  # model is any PyTorch model
  model.apply(torchao.quantization.pt2e.disable_observer)

N)râ   r   r"  ri   r$  s   &r%   ri   ri   N  s/   € ô �#Ô'×(Ò(Ô,HÈ×,MÒ,MØ×ÑÖñ -Nr'   c                óx   € \        V \        4      '       g   \        V 4      '       d   V P                  4        R# R# )zÂEnable observation for this module.

Enable observation for this module, if applicable. Example usage::

  # model is any PyTorch model
  model.apply(torchao.quantization.pt2e.enable_observer)

N)râ   r   r"  rf   r$  s   &r%   rf   rf   [  s/   € ô �#Ô'×(Ò(Ô,HÈ×,MÒ,MØ×ÑÖñ -Nr'   )r   r   r   r   r   rb   ri   r]   rf   Údefault_fake_quantÚdefault_weight_fake_quantÚdefault_dynamic_fake_quantÚ.default_fixed_qparams_range_neg1to1_fake_quantÚ+default_fixed_qparams_range_0to1_fake_quantÚ*default_symmetric_fixed_qparams_fake_quantÚ'default_affine_fixed_qparams_fake_quantÚ%default_per_channel_weight_fake_quantÚdefault_embedding_fake_quantÚ!default_embedding_fake_quant_4bitÚdefault_histogram_fake_quantÚdefault_fused_act_fake_quantÚdefault_fused_wt_fake_quantÚ'default_fused_per_channel_wt_fake_quantÚ(fused_wt_fake_quant_range_neg_127_to_127Ú4fused_per_channel_wt_fake_quant_range_neg_127_to_127Údefault_affine_fake_quantÚdefault_groupwise_fake_quantÚ"default_affine_per_axis_fake_quanti€ÿÿÿi�ÿÿÿg      0?)Orw   r  Úabcr   r   Útypingr   r   r   r*   Útorch.fxr   Útorch.nnr   Útorchao.quantizationr	   r
   r   Ú.torchao.quantization.pt2e._affine_quantizationr   Ú"torchao.quantization.pt2e.observerr   r   r   r   r   r   r   r   r   r   Ú%torchao.quantization.quant_primitivesr   Ú__all__r/   r4   r7   r:   r   r   r   r   r   ro   r�   r3   r(  Úqint8r2   r)  r*  r+  r,  r-  r.  r+   r/  r-   r0  Úquint4x2r1  r2  r3  r4  r5  r6  r7  Ú
ASYMMETRICrI   r8  Ú	SYMMETRICÚint8r9  r:  r"  rb   r]   ri   rf   r=   r'   r%   Ú<module>rI     sJ  ðñ =ã 	ß #ß 'Ñ 'ã Ý Ý ç =Ñ =õ÷÷ ÷ õò€õ@õLõPõô7&�s˜Fô 7&ôt|
Ð#ô |
ô~#
˜|ô #
ôLB
 Lô B
ôJbC˜ô bCðJ "×+Ñ+Ø(ØØØ
�,‰,Ø×#Ñ#Øð ,ó Ð ðð )×2Ñ2Ø(ØØØ
�+‰+Ø×&Ñ&Øð 3ó Ð ðð
 *×3Ñ3Ø(ØØØØ
�,‰,Øð 4ó Ð ðð 2J×1SÑ1SØ9ð 2Tó 2Ð .ð /G×.PÑ.PØ6ð /Qó /Ð +ð
 3ð +ð +VÐ 'à(4×(>Ñ(>Ø2ØØØ
�+‰+Ø×'Ñ'ØØð )?ó )Ð %ðð  ,×5Ñ5Ø2Ø×2Ñ2Ø
�,‰,ØØØØð  6ó  Ð ðð
 %1×$:Ñ$:Ø2Ø×2Ñ2ØØ
�.‰.Øð %;ó %Ð !ð  ,×5Ñ5ØØØØ
�,‰,Ø×#Ñ#Øð  6ó  Ð ðð
  =×FÑFØ(ØØØ
�,‰,ð	  Gó  Ð ðð
 <×EÑEØ(ØØØ
�+‰+Ø×&Ñ&ð Fó Ð ðð +H×*QÑ*QØ2ØØØ
�+‰+Ø×'Ñ'ð +Ró +Ð 'ðð ,I×+RÑ+RØ(ØØØ
�+‰+Ø×&Ñ&Øð ,Só ,Ð (ðð
 "×+Ñ+Ø6ØØØ�k‰kØ×+Ñ+Øð ,ó ð 5ðð /×8Ñ8Ø*Ø×'Ñ'Ø—‘Ù“ð	 9ó Ð ðð  2×;Ñ;Ø*Ø×&Ñ&Ø—‘Ù˜“ð	  <ó  Ð ðð
 &8×%AÑ%AØ*Ø×&Ñ&Ø—‘Ù˜“
ð	 &Bó &Ð "ðò
ò
!ò
 ò
ô
r'   