
    Pi1                         d dl Z d dlmZ d dlmZ dgZde j        j        dee j	        df         de j        j        fd	Z
dS )
    N)constant_fold)freezing_passeslower_pt2e_quantized_to_x86modelexample_inputs.returnc                    d }d }t           j                            | |d                               |                                                      } ||           t	          ||           t          |           |S )a  Lower a PT2E-qantized model to x86 backend.

    Args:
    * `model` (torch.fx.GraphModule): a model quantized by PT2E quantization flow.
    * `example_inputs` (tuple[torch.Tensor, ...]): example inputs for the model.

    Return:
    A module lowered to x86 backend.
    c                      t           j                                        } t          |                                           D ])}t           j        j                            |          s| |= *| S )N)torchexportdefault_decompositionslistkeys_exportutils
_is_cia_op)decomp_tableks     v/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchao/quantization/pt2e/lowering.py_post_autograd_decomp_tablez@lower_pt2e_quantized_to_x86.<locals>._post_autograd_decomp_table   sc    |::<< l''))** 	$ 	$A=&11!44 $ O    c                    t           j        j        }| j        }|j        D ]}|j        |j        j        k    r|                    |          5  |j	        d         }ddg}|
                    |j        j        ||f          }|                    |           |                    |           d d d            n# 1 swxY w Y   |                                 |                                  d S )Nr      )args)r   opsatengraphnodestargettdefaultinserting_beforer   call_functionpermutereplace_all_uses_with
erase_nodelint	recompile)mr   gnodexdims	perm_nodes          r   _node_replacez2lower_pt2e_quantized_to_x86.<locals>._node_replace)   s   y~GG 	' 	'D{dfn,,''-- ' '	!Aq6D !0DAt9 U UI..y999LL&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 	
	s   AB77B;	>B;	T)strict)r   r   run_decompositionsmoduler   r   )r   r   r   r/   lowered_models        r   r   r      s    	 	 	  " 	E>$??		7799	:	:	 
 M-   M>222-   r   )r    torch._inductor.constant_foldingr   +torch._inductor.fx_passes.freezing_patternsr   __all__fxGraphModuletupleTensorr    r   r   <module>r<      s     : : : : : : G G G G G G "
181%,+,1 X1 1 1 1 1 1r   