a
    ‘º”hp  ã                   @   sN   d dl Z d dlmZ d dlmZ dgZe jjee j	df e jjdœdd„Z
dS )é    N)Úconstant_fold)Úfreezing_passesÚlower_pt2e_quantized_to_x86.)ÚmodelÚexample_inputsÚreturnc                 C   sL   dd„ }dd„ }t jj| |d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 GraphModule lowered to x86 backend.
    c                  S   s4   t j ¡ } t|  ¡ ƒD ]}t jj |¡s| |= q| S )N)ÚtorchÚexportZdefault_decompositionsÚlistÚkeysZ_exportÚutilsZ
_is_cia_op)Zdecomp_tableÚk© r   úQ/var/www/auris/lib/python3.9/site-packages/torch/ao/quantization/pt2e/lowering.pyÚ_post_autograd_decomp_table   s
    
z@lower_pt2e_quantized_to_x86.<locals>._post_autograd_decomp_tablec              	   S   s¢   t jj}| j}|jD ]x}|j|jjkr| |¡L |j	d }ddg}|j
|jj||fd}| |¡ | |¡ W d   ƒ q1 s‚0    Y  q| ¡  |  ¡  d S )Nr   é   )Úargs)r   ÚopsÚatenÚgraphÚnodesÚtargetÚtÚdefaultZinserting_beforer   Úcall_functionZpermuteZreplace_all_uses_withZ
erase_nodeZlintZ	recompile)Úmr   ÚgÚnodeÚxÚdimsZ	perm_noder   r   r   Ú_node_replace$   s    


*z2lower_pt2e_quantized_to_x86.<locals>._node_replaceT)Ústrict)r   r	   Zexport_for_trainingZrun_decompositionsÚmoduler   r   )r   r   r   r    Zlowered_modelr   r   r   r      s    ÿÿ
)r   Z torch._inductor.constant_foldingr   Z+torch._inductor.fx_passes.freezing_patternsr   Ú__all__ZfxZGraphModuleÚtupleZTensorr   r   r   r   r   Ú<module>   s   ÿý