Ë
    g^(h¥  ã                  ó`   — d dl mZ d dlmZ ddlmZmZ er
d dlZd dlm	Z	 dgZ
 G d„ de«      Zy)	é    )Úannotations)ÚTYPE_CHECKINGé   )ÚQuantizationAnnotationÚ	QuantizerN)ÚNodeÚComposableQuantizerc                  óX   ‡ — e Zd ZdZdˆ fd„Z	 	 	 	 	 	 dd„Zd	d„Z	 	 	 	 d	d„Zd
d„Zˆ xZ	S )r	   at  
    ComposableQuantizer allows users to combine more than one quantizer into a single quantizer.
    This allows users to quantize a model with multiple quantizers. E.g., embedding quantization
    maybe supported by one quantizer while linear layers and other ops might be supported by another
    quantizer.

    ComposableQuantizer is initialized with a list of `Quantizer` instances.
    The order of the composition matters since that is the order in which the quantizers will be
    applies.
    Example:
    ```
    embedding_quantizer = EmbeddingQuantizer()
    linear_quantizer = MyLinearQuantizer()
    xnnpack_quantizer = XNNPackQuantizer() # to handle ops not quantized by previous two quantizers
    composed_quantizer = ComposableQuantizer([embedding_quantizer, linear_quantizer, xnnpack_quantizer])
    prepared_m = prepare_pt2e(model, composed_quantizer)
    ```
    c                ó>   •— t         ‰| �  «        || _        i | _        y ©N)ÚsuperÚ__init__Ú
quantizersÚ_graph_annotations)Úselfr   Ú	__class__s     €úr/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/ao/quantization/quantizer/composable_quantizer.pyr   zComposableQuantizer.__init__%   s   ø€ Ü‰ÑÔØ$ˆŒØFHˆÕó    c                ó¾  — |j                   j                  D ]Ä  }d|j                  v r�|| j                  v rVt	        | j                  |   «      t	        |j                  d   «      k7  r%t        d|j                  j                  › d|› �«      ‚|j                  d   | j                  |<   Œ’|| j                  v sŒ¡t        d|j                  j                  › d|› �«      ‚ y )NÚquantization_annotationz
Quantizer z! has changed annotations on node z! has removed annotations on node )ÚgraphÚnodesÚmetar   ÚidÚRuntimeErrorr   Ú__name__)r   ÚgmÚ	quantizerÚns       r   Ú _record_and_validate_annotationsz4ComposableQuantizer._record_and_validate_annotations*   sç   € ð —‘—‘ò 	ˆAØ(¨A¯F©FÑ2ð ˜×/Ñ/Ñ/Ü�t×.Ñ.¨qÑ1Ó2Ü˜!Ÿ&™&Ð!:Ñ;Ó<ò=ô 'Ø$ Y×%8Ñ%8×%AÑ%AÐ$BÐBcÐdeÐcfÐgóð ð 23·±Ð8QÑ1R�D×+Ñ+¨AÒ.à˜×/Ñ/Ò/Ü&Ø$ Y×%8Ñ%8×%AÑ%AÐ$BÐBcÐdeÐcfÐgóð ñ	r   c                ón   — | j                   D ]%  }|j                  |«       | j                  ||«       Œ' |S )z!just handling global spec for now)r   Úannotater    ©r   Úmodelr   s      r   r"   zComposableQuantizer.annotate@   s<   € àŸ™ò 	DˆIØ×Ñ˜uÔ%Ø×1Ñ1°%¸ÕCð	Dð ˆr   c                óJ   — | j                   D ]  }|j                  |«      }Œ |S r   )r   Útransform_for_annotationr#   s      r   r&   z,ComposableQuantizer.transform_for_annotationG   s,   € ð Ÿ™ò 	>ˆIØ×6Ñ6°uÓ=‰Eð	>àˆr   c                 ó   — y r   © )r   r$   s     r   ÚvalidatezComposableQuantizer.validateN   s   € Ør   )r   zlist[Quantizer])r   útorch.fx.GraphModuler   r   ÚreturnÚNone)r$   r*   r+   r*   )r$   r*   r+   r,   )
r   Ú
__module__Ú__qualname__Ú__doc__r   r    r"   r&   r)   Ú__classcell__)r   s   @r   r	   r	      sJ   ø„ ñõ&Ið
Ø&ðØ3<ðà	óó,ðØ)ðà	ó÷r   )Ú
__future__r   Útypingr   r   r   r   ÚtorchÚtorch.fxr   Ú__all__r	   r(   r   r   ú<module>r6      s1   ðÝ "å  ç 8ñ ÛÝð ð€ô
>˜)õ >r   