
    rhp                         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
y)
    N)constant_fold)freezing_passeslower_pt2e_quantized_to_x86modelexample_inputs.returnc                     d }d }t         j                  j                  | |d      j                   |             j	                         } ||       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 GraphModule lowered to x86 backend.
    c                      t         j                  j                         } t        | j	                               D ]/  }t         j
                  j                  j                  |      r-| |= 1 | S )N)torchexportdefault_decompositionslistkeys_exportutils
_is_cia_op)decomp_tableks     v/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/torch/ao/quantization/pt2e/lowering.py_post_autograd_decomp_tablez@lower_pt2e_quantized_to_x86.<locals>._post_autograd_decomp_table   sZ    ||::< l'')* 	$A==&&11!4 O	$     c                    t         j                  j                  }| j                  }|j                  D ]  }|j
                  |j                  j                  k(  s'|j                  |      5  |j                  d   }ddg}|j                  |j                  j                  ||f      }|j                  |       |j                  |       d d d         |j                          | j                          y # 1 sw Y   xY w)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    yy~~GGGG 	'D{{dffnn,''- '		!Aq6D !0D0DAt9 UI..y9LL&' '	' 	
	' 's   +AC55C>	T)strict)r   r   export_for_trainingrun_decompositionsmoduler   r   )r   r   r   r/   lowered_models        r   r   r      sd    	" 	((t(L		79	:	 
 - M>2- r   )r    torch._inductor.constant_foldingr   +torch._inductor.fx_passes.freezing_patternsr   __all__fxGraphModuletupleTensorr    r   r   <module>r=      s[     : G "
1881%,,+,1 XX1r   