
    Pi                    t    d dl mZ 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dS )
    )annotations)TYPE_CHECKING)Q_ANNOTATION_KEY   )QuantizationAnnotation	QuantizerN)NodeComposableQuantizerc                  D     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)
    ```
    
quantizerslist[Quantizer]c                d    t                                                       || _        i | _        d S N)super__init__r   _graph_annotations)selfr   	__class__s     /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchao/quantization/pt2e/quantizer/composable_quantizer.pyr   zComposableQuantizer.__init__,   s.    $FH    gmtorch.fx.GraphModule	quantizerr   returnNonec                   |j         j        D ]}t          |j        v r~|| j        v rZt          | j        |                   t          |j        t                             k    rt          d|j        j         d|           |j        t                   | j        |<   || j        v rt          d|j        j         d|           d S )Nz
Quantizer z! has changed annotations on node z! has removed annotations on node )	graphnodesr   metar   idRuntimeErrorr   __name__)r   r   r   ns       r    _record_and_validate_annotationsz4ComposableQuantizer._record_and_validate_annotations1   s      	 	A16)) ///t.q122b@P9Q6R6RRR&gY%8%Aggdegg   238H1ID+A..///&gY%8%Aggdegg   0	 	r   modelc                p    | j         D ]-}|                    |           |                     ||           .|S )z!just handling global spec for now)r   annotater$   r   r%   r   s      r   r'   zComposableQuantizer.annotateF   sG     	D 	DIu%%%11%CCCCr   c                D    | j         D ]}|                    |          }|S r   )r   transform_for_annotationr(   s      r   r*   z,ComposableQuantizer.transform_for_annotationM   s/      	> 	>I66u==EEr   c                    d S r    )r   r%   s     r   validatezComposableQuantizer.validateT   s    r   )r   r   )r   r   r   r   r   r   )r%   r   r   r   )r%   r   r   r   )
r"   
__module____qualname____doc__r   r$   r'   r*   r-   __classcell__)r   s   @r   r
   r
      s         &I I I I I I
   *             r   )
__future__r   typingr   -torchao.quantization.pt2e.quantizer.quantizerr   r   r   r   torchtorch.fxr	   __all__r
   r,   r   r   <module>r8      s    # " " " " "             J J J J J J 8 8 8 8 8 8 8 8 LLL 
= = = = =) = = = = =r   