Ë
    g^(hà  ã                   óª  — d dl mZmZ d dlmZmZ d dlmZmZm	Z	 d dl
Z
d dl
mZ d dlmZ d dlmZ d dlmZ g d	¢Z G d
„ de«      Z edd¬«       G d„ de«      «       Z edd¬«       G d„ de«      «       Z	 e	eeef   ef   Zde_         edd¬«       G d„ de«      «       Z edd¬«       G d„ de«      «       Ze G d„ d«      «       Z G d„ de«      Zy)é    )ÚABCÚabstractmethod)Ú	dataclassÚfield)ÚCallableÚOptionalÚUnionN)ÚTensor)ÚObserverOrFakeQuantize)Ú"_ObserverOrFakeQuantizeConstructor)ÚNode)Ú	QuantizerÚQuantizationSpecBaseÚQuantizationSpecÚFixedQParamsQuantizationSpecÚ
EdgeOrNodeÚSharedQuantizationSpecÚDerivedQuantizationSpecÚQuantizationAnnotationc                   ó   — e Zd ZdZy)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__Ú__doc__© ó    úg/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/ao/quantization/quantizer/quantizer.pyr   r      s   „ òr   r   T)ÚeqÚfrozenc                   ó²   — e Zd ZU dZej
                  ed<   eed<   dZe	e
   ed<   dZe	e
   ed<   dZe	ej                     ed<   dZe	e
   ed<   d	Zeed
<   d„ Zy)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.
    ÚdtypeÚobserver_or_fake_quant_ctrNÚ	quant_minÚ	quant_maxÚqschemeÚch_axisFÚ
is_dynamicc                 ó   — | j                   �K| j                  �?| j                   | j                  kD  r&t        d| j                   › d| j                  › d�«      ‚| j                  �| j                  dk  rt        d«      ‚y y )Nz
quant_min z must be <= quant_max ú.r   zCh_axis is < 0.)r#   r$   Ú
ValueErrorr&   )Úselfs    r   Ú__post_init__zQuantizationSpec.__post_init__1   s~   € ð �N‰NÐ&Ø—‘Ð*Ø—‘ §¡Ò/äØ˜TŸ^™^Ð,Ð,BÀ4Ç>Á>ÐBRÐRSÐTóð ð �<‰<Ð#¨¯©°qÒ(8ÜÐ.Ó/Ð/ð )9Ð#r   )r   r   r   r   Útorchr!   Ú__annotations__r   r#   r   Úintr$   r%   r&   r'   Úboolr,   r   r   r   r   r      sh   … ñð �;‰;Óð
 !CÓBØ#€Iˆx˜‰}Ó#Ø#€Iˆx˜‰}Ó#Ø'+€GˆX�e—m‘mÑ$Ó+Ø!€GˆX�c‰]Ó!Ø€J�Óó0r   r   c                   óž   — e Zd ZU ej                  ed<   eed<   eed<   dZe	e   ed<   dZ
e	e   ed<   dZe	ej                     ed<   dZeed	<   y)
r   r!   ÚscaleÚ
zero_pointNr#   r$   r%   Fr'   )r   r   r   r-   r!   r.   Úfloatr/   r#   r   r$   r%   r'   r0   r   r   r   r   r   C   sO   … à�;‰;ÓØƒLØƒOØ#€Iˆx˜‰}Ó#Ø#€Iˆx˜‰}Ó#Ø'+€GˆX�e—m‘mÑ$Ó+Ø€J�Ôr   r   z)torch.ao.quantization.quantizer.quantizerc                   ó   — e Zd ZU dZeed<   y)r   zg
    Quantization spec for the Tensors whose quantization parameters are shared with other Tensors
    Úedge_or_nodeN)r   r   r   r   r   r.   r   r   r   r   r   X   s   … ñð
 Ôr   r   c                   óØ   — e Zd ZU dZee   ed<   eee   ge	e
e
f   f   ed<   ej                  ed<   dZee   ed<   dZee   ed<   dZeej"                     ed<   dZee   ed	<   d
Zeed<   y)r   z^Quantization spec for the Tensors whose quantization parameters are derived from other TensorsÚderived_fromÚderive_qparams_fnr!   Nr#   r$   r%   r&   Fr'   )r   r   r   r   Úlistr   r.   r   r   Útupler
   r-   r!   r#   r   r/   r$   r%   r&   r'   r0   r   r   r   r   r   b   sƒ   … áhà�zÑ"Ó"Ø Ð&<Ñ!=Ð >ÀÀfÈfÀnÑ@UÐ UÑVÓVØ�;‰;ÓØ#€Iˆx˜‰}Ó#Ø#€Iˆx˜‰}Ó#Ø'+€GˆX�e—m‘mÑ$Ó+Ø!€GˆX�c‰]Ó!Ø€J�Ôr   r   c                   ón   — e Zd ZU dZ ee¬«      Zeeee	   f   e
d<   dZee	   e
d<   dZee
d<   dZee
d	<   y)
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_factoryÚinput_qspec_mapNÚoutput_qspecTÚallow_implicit_sharingFÚ
_annotated)r   r   r   r   r   Údictr>   r   r   r   r.   r?   r@   r0   rA   r   r   r   r   r   p   s[   … ññ CHØôC€O�T˜$ Ð)=Ñ >Ð>Ñ?ó ð 48€L�(Ð/Ñ0Ó7ð
 $(Ð˜DÓ'ð €J�Ôr   r   c                   ó^  — e Zd Zdej                  j
                  dej                  j
                  fd„Zedej                  j
                  dej                  j
                  fd„«       Zedej                  j
                  ddfd„«       Z	dej                  j
                  de
eef   ddfd„Zy)	r   ÚmodelÚreturnc                 ó   — |S )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+   rD   s     r   Útransform_for_annotationz"Quantizer.transform_for_annotationŠ   s	   € ð ˆr   c                  ó   — y ©Nr   rG   s     r   ÚannotatezQuantizer.annotateš   ó   € àr   Nc                  ó   — y rJ   r   rG   s     r   ÚvalidatezQuantizer.validateŸ   rL   r   Úedge_or_node_to_obs_or_fqc                  ó   — y)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+   rD   rO   s      r   Úprepare_obs_or_fq_callbackz$Quantizer.prepare_obs_or_fq_callback£   s   € ð$ 	r   )r   r   r   r-   ÚfxÚGraphModulerH   r   rK   rN   rB   r   r   rQ   r   r   r   r   r   ‰   sÃ   „ ðØ—X‘X×)Ñ)ðà	�‰×	Ñ	óð  ð˜eŸh™h×2Ñ2ð °u·x±x×7KÑ7Kò ó ðð ð˜eŸh™h×2Ñ2ð °tò ó ððà�x‰x×#Ñ#ðð $(¨
Ð4JÐ(JÑ#Kðð 
ô	r   r   )Úabcr   r   Údataclassesr   r   Útypingr   r   r	   r-   r
   Útorch.ao.quantizationr   Útorch.ao.quantization.qconfigr   Útorch.fxr   Ú__all__r   r   r   r;   r   r   r   r   r   r   r   r   r   ú<module>r[      s  ðç #ß (ß ,Ñ ,ã Ý Ý 8Ý LÝ ò	€ô˜3ô ñ ˆd˜4Ô ô 0Ð+ó  0ó !ð 0ñF ˆd˜4Ô ôÐ#7ó ó !ððð �5˜˜t˜Ñ$ dÐ*Ñ+€
ØC€
Ô ñ ˆd˜4Ô ôÐ1ó ó !ðñ ˆd˜4Ô ô
Ð2ó 
ó !ð
ð ÷ð ó ðô0,�õ ,r   