+
    "Ý³jû  ã                   óâ  € ^ RI t ^ RIHtH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 . ROtRt ! R R	]4      t]! RRR7       ! R R
]4      4       t]! RRR7       ! R R]4      4       t ]
]]]3,          ]3,          t] P2                  R8  d   R]n        ]! RRR7       ! R R]4      4       t]! RRR7       ! R R]4      4       t] ! R R4      4       t ! R R]4      tR# )é    N)ÚABCÚabstractmethod)Ú	dataclassÚfield)ÚCallableÚOptionalÚUnion)ÚTensor)ÚNode)ÚObserverOrFakeQuantizeÚ!ObserverOrFakeQuantizeConstructorÚ	QuantizerÚQuantizationSpecBaseÚQuantizationSpecÚFixedQParamsQuantizationSpecÚSharedQuantizationSpecÚDerivedQuantizationSpecÚQuantizationAnnotationÚquantization_annotationc                   ó   € ] tR t^%tRtRtR# )r   z‘Base class for different types of quantization specs that allows users to
specify how to quantize a Tensor (input/output of a Node) in the model
© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__static_attributes__r   ó    Ún/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torchao/quantization/pt2e/quantizer/quantizer.pyr   r   %   s   † õr   T)ÚeqÚfrozenc                   óJ   a € ] tR t^+t o RtRtRtRtRtRt	R t
V 3R ltRtV tR# )r   zŒQuantization spec for common operators that allows user to specify how to
quantize a Tensor, this includes dtype, quant_min, quant_max etc.
NFc                ó  € V P                   eP   V P                  eB   V P                   V P                  8”  d'   \        RV P                    RV P                   R24      hV P                  e   V P                  ^ 8  d   \        R4      hR # R # )Nz
quant_min z must be <= quant_max Ú.zCh_axis is < 0.)Ú	quant_minÚ	quant_maxÚ
ValueErrorÚch_axis)Úselfs   &r   Ú__post_init__ÚQuantizationSpec.__post_init__=   s~   € ð �N‰NÒ&Ø—‘Ò*Ø—‘ §¡Ô/äØ˜TŸ^™^Ð,Ð,BÀ4Ç>Á>ÐBRÐRSÐTóð ð �<‰<Ò#¨¯©°qÔ(8ÜÐ.Ó/Ð/ñ )9Ñ#r   c                óÖ   <€ V ^8„  d   Qh/ S[ P                  ;R&   S[;R&   S[S[,          ;R&   S[S[,          ;R&   S[S[ P
                  ,          ;R&   S[S[,          ;R&   S[;R&   # )é   ÚdtypeÚobserver_or_fake_quant_ctrr%   r&   Úqschemer(   Ú
is_dynamic)Útorchr.   r   r   Úintr0   Úbool)ÚformatÚ__classdict__s   "€r   Ú__annotate__ÚQuantizationSpec.__annotate__+   sz   ø‡ ‚ ñ �;‰;Ññ ñ !BÑAñ ñ ™�}Ñ#ñ ñ ™�}Ñ#ñ ñ ‘e—m‘mÕ$Ñ+ñ ñ ‘c�]Ñ!ñ ñ  Ñò! r   r   )r   r   r   r   r   r%   r&   r0   r(   r1   r*   Ú__annotate_func__r   Ú__classdictcell__©r6   s   @r   r   r   +   s1   ø‡ € ñð  $€IØ#€IØ'+€GØ!€GØ€Jò0÷% ƒ r   c                   ó<   a € ] tR t^Ot o RtRtRtRtV 3R ltRt	V t
R# )r   NFc                óÆ   <€ V ^8„  d   Qh/ S[ P                  ;R&   S[;R&   S[;R&   S[S[,          ;R&   S[S[,          ;R&   S[S[ P
                  ,          ;R&   S[;R&   # )r-   r.   ÚscaleÚ
zero_pointr%   r&   r0   r1   )r2   r.   Úfloatr3   r   r0   r4   )r5   r6   s   "€r   r7   Ú)FixedQParamsQuantizationSpec.__annotate__O   sq   ø‡ ‚ á�;‰;Ññ ñ �Lñ ñ �Oñ	 ñ
 ™�}Ñ#ñ ñ ™�}Ñ#ñ ñ ‘e—m‘mÕ$Ñ+ñ ñ Ñò r   r   )r   r   r   r   r%   r&   r0   r1   r9   r   r:   r;   s   @r   r   r   O   s"   ø‡ € ð
  $€IØ#€IØ'+€GØ€J÷ ƒ r   z-torchao.quantization.pt2e.quantizer.quantizerc                   ó0   a € ] tR t^et o RtV 3R ltRtV tR# )r   z_
Quantization spec for the Tensors whose quantization parameters are shared with other Tensors
c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # )r-   Úedge_or_node)Ú
EdgeOrNode)r5   r6   s   "€r   r7   Ú#SharedQuantizationSpec.__annotate__e   s   ø‡ ‚ ñ Ñò r   r   N)r   r   r   r   r   r9   r   r:   r;   s   @r   r   r   e   s   ø‡ € ñ÷ ƒ r   c                   óD   a € ] tR t^ot o RtRtRtRtRtRt	V 3R lt
RtV tR# )r   z^Quantization spec for the Tensors whose quantization parameters are derived from other TensorsNFc                ó0  <€ V ^8„  d   Qh/ S[ S[,          ;R&   S[S[ S[,          .S[S[S[3,          3,          ;R&   S[P                  ;R&   S[S[	,          ;R&   S[S[	,          ;R&   S[S[P                  ,          ;R&   S[S[	,          ;R&   S[;R&   # )	r-   Úderived_fromÚderive_qparams_fnr.   r%   r&   r0   r(   r1   )ÚlistrE   r   r   Útupler
   r2   r.   r   r3   r0   r4   )r5   r6   s   "€r   r7   Ú$DerivedQuantizationSpec.__annotate__o   s§   ø‡ ‚ ñ ‘zÕ"Ñ"ñ	 ñ
  ¡Ñ&<Õ!=Ð >ÁÁfÉfÀnÕ@UÐ UÕVÑVñ ñ �;‰;Ññ ñ ™�}Ñ#ñ ñ ™�}Ñ#ñ ñ ‘e—m‘mÕ$Ñ+ñ ñ ‘c�]Ñ!ñ ñ Ñò r   r   )r   r   r   r   r   r%   r&   r0   r(   r1   r9   r   r:   r;   s   @r   r   r   o   s*   ø‡ € áhð
  $€IØ#€IØ'+€GØ!€GØ€J÷ ƒ r   c                   óN   a € ] tR t^}t o Rt]! ]R7      tRtRt	Rt
V 3R ltRtV tR# )r   z¶How are input arguemnt or output should be quantized,
expressed as QuantizationSpec, this corresponds to how a Tensor in the
operator Graph is observed (PTQ) or fake quantized (QAT)
)Údefault_factoryNTFc                ó€   <€ V ^8„  d   Qh/ S[ S[S[S[,          3,          ;R&   S[S[,          ;R&   S[;R&   S[;R&   # )r-   Úinput_qspec_mapÚoutput_qspecÚallow_implicit_sharingÚ
_annotated)Údictr   r   r   r4   )r5   r6   s   "€r   r7   Ú#QuantizationAnnotation.__annotate__}   sQ   ø‡ ‚ ñ ™$¡Ñ)=Õ >Ð>Õ?ñ ñ ñ Ñ/Õ0Ñ7ñ ñ& !Ñ'ñ' ñ, Ñò- r   r   )r   r   r   r   r   r   rU   rQ   rR   rS   rT   r9   r   r:   r;   s   @r   r   r   }   s9   ø‡ € ññ CHØôC€Oð 48€Lð
 $(Ðð €J÷- ƒ r   c                   ó|   a € ] tR t^–t o V 3R lR lt]V 3R lR l4       t]V 3R lR l4       tV 3R lR ltR	t	V t
R
# )r   c                óv   <€ V ^8„  d   QhRS[ P                  P                  RS[ P                  P                  /# ©r-   ÚmodelÚreturn©r2   ÚfxÚGraphModule)r5   r6   s   "€r   r7   ÚQuantizer.__annotate__—   s1   ø€ ÷ ñ Ù—X‘X×)Ñ)ðá	�‰×	Ñ	ñr   c                ó   € V# )a¸  Allows for user defined transforms to run before annotating the graph.
This allows quantizer to allow quantizing part of the model that are otherwise not quantizable.
For example quantizer can
a) decompose a compound operator like scaled dot product attention,
into bmm and softmax if quantizer knows how to quantize bmm/softmax but not sdpa
or b) transform scalars to tensor to allow quantizing scalares.

Note: this is an optional method
r   ©r)   rZ   s   &&r   Útransform_for_annotationÚ"Quantizer.transform_for_annotation—   s	   € ð ˆr   c                óv   <€ V ^8„  d   QhRS[ P                  P                  RS[ P                  P                  /# rY   r\   )r5   r6   s   "€r   r7   r_   ¨   s/   ø€ ÷ ñ ™eŸh™h×2Ñ2ð ±u·x±x×7KÑ7Kñ r   c                ó   € R # ©Nr   ra   s   &&r   ÚannotateÚQuantizer.annotate§   ó   € ár   c                óL   <€ V ^8„  d   QhRS[ P                  P                  RR/# )r-   rZ   r[   Nr\   )r5   r6   s   "€r   r7   r_   ­   s%   ø€ ÷ ñ ™eŸh™h×2Ñ2ð °tñ r   c                ó   € R # rf   r   ra   s   &&r   ÚvalidateÚQuantizer.validate¬   ri   r   c                óh   <€ V ^8„  d   QhRS[ P                  P                  RS[S[S[3,          RR/# )r-   rZ   Úedge_or_node_to_obs_or_fqr[   N)r2   r]   r^   rU   rE   r   )r5   r6   s   "€r   r7   r_   °   s>   ø€ ÷ ñ á�x‰x×#Ñ#ðñ $(©
Ñ4JÐ(JÕ#Kðð 
ñ	r   c                ó   € R# )a¨  A callback that will be called after the observers or fake quants are created
for each sharing group, but before they are inserted into the graph. The
callback can be used to make final quantization adjustments, such as enforcing
specific scale and zero point on model input or output.

Args:
  * `model`: the graph module being prepared.
  * `edge_or_node_to_obs_or_fq`: a dictionary mapping each annotated edge and
    node to the corresponding observer or fake quant object. Note that multiple
    edges and/or nodes can map to the same observer / fake quant instance if
    they were annotated with SharedQuantizationSpec. This dictionary can be
    modified by the callback.
Nr   )r)   rZ   ro   s   &&&r   Úprepare_obs_or_fq_callbackÚ$Quantizer.prepare_obs_or_fq_callback°   s   € ñ$ 	r   r   N)r   r   r   r   rb   r   rg   rl   rq   r   r:   r;   s   @r   r   r   –   sA   ø‡ € ÷ð ð  ÷ó ðð ÷ó ð÷ö r   )r   r   r   r   rE   r   r   r   )é   é   )ÚsysÚabcr   r   Údataclassesr   r   Útypingr   r   r	   r2   r
   Útorch.fxr   Útorchao.quantization.pt2er   r   Ú__all__ÚQ_ANNOTATION_KEYr   r   r   rL   rE   Úversion_infor   r   r   r   r   r   r   r   Ú<module>r~      s&  ðó ß #ß (ß ,Ñ ,ã Ý Ý ÷ò
	€ð -Ð ô˜3ô ñ ˆd˜4Ô ô 0Ð+ó  0ó !ð 0ñF ˆd˜4Ô ôÐ#7ó ó !ððð �5˜˜t˜Õ$ dÐ*Õ+€
Ø×Ñ�gÔØK€JÔñ ˆd˜4Ô ôÐ1ó ó !ðñ ˆd˜4Ô ô
Ð2ó 
ó !ð
ð ÷ð ó ðô0,�ö ,r   