U
    yhJ                     @   s  U d dl Z d dlmZmZmZmZmZmZ d dlZd dl	m
Z
 d dlZd dlmZmZmZ dddgZejjejjjhejjejjjhejjejjjhejjejjjejjjhejjejjjhejjejjjejjj hej!ej!ej"dd	hej#ej#ej$d
dhga%ee e&d< dd Z'e' a(ee dddZ)dddZ*ee dddZ+dd Z,ee dddZ-dej.j/ee eee
ge0f  dddZ1dS )    N)AnyListOrderedDictSetOptionalCallable)Node)check_subgraphs_connectedget_source_partitionsSourcePartitionfind_sequential_partitionsget_equivalent_typesupdate_equivalent_types_dictaddZadd_mulZmul__EQUIVALENT_TYPESc                  C   s(   i } t D ]}|D ]}t|| |< qq| S N)r   list)Z_DICTvaluesv r   X/var/www/html/venv/lib/python3.8/site-packages/torch/ao/quantization/pt2e/graph_utils.py_create_equivalent_types_dict!   s
    r   )returnc                   C   s   t S r   )r   r   r   r   r   r   +   s    c                 C   s   | dkrt d| at adS )zHelp function for user who wants to customize the _EQUIVALENT_TYPES and _EQUIVALENT_TYPES_DICT.
    When customized_equivalent_types passes in,
    re-generate _EQUIVALENT_TYPES and _EQUIVALENT_TYPES_DICT.
    Nz.customized_equivalent_types should not be None)
ValueErrorr   r   _EQUIVALENT_TYPES_DICT)Zcustomized_equivalent_typesr   r   r   r   .   s    )
partitionsc                 C   s.   d }| D ] }|d k	r$t ||s$ dS |}qdS )NFT)r	   )r   Zprev_partition	partitionr   r   r   _partitions_sequential:   s    
 r   c                 C   s    | g}| t kr|t |   |S r   )r   extend)partition_typematching_typesr   r   r   _get_matching_typesE   s    r"   )partition_typesc                 C   sB   t  }| D ]2}t|}t |}t||@ dkr4 dS ||O }q
dS )Nr   FT)setr"   len)r#   Zpartition_types_setr    r!   Zmatching_types_setr   r   r   _valid_type_sequenceL   s    
r&   T)gmr#   	filter_fnc                 C   s   t |std| dt }|D ]2}t|}t| j||}ttj	|
 ||< q"t|
 }tj| }	g }
|	D ]}t|rt|
| qt|
S )NzInvalid partition types: z*. Each type in the sequence must be unique)r&   r   r   r"   r
   graphr   	itertoolschainfrom_iterabler   productr   append)r'   r#   Zinclude_functional_equivalentr(   Ztyped_partitionsr    Ztypes_to_matchr   Ztyped_partitions_listZfusion_candidatesZfused_partitions	candidater   r   r   r   W   s     

)N)TN)2r*   typingr   r   r   r   r   r   operatorZtorch.fxr   ZtorchZ*torch.fx.passes.utils.source_matcher_utilsr	   r
   r   __all__nnZConv1dZ
functionalZconv1dZConv2dZconv2dZAdaptiveAvgPool2dZadaptive_avg_pool2dZReLUZreluZrelu_ZBatchNorm2dZ
batch_normZHardtanhZhardtanhZ	hardtanh_r   iaddr   imulr   __annotations__r   r   r   r   r   r"   r&   ZfxZGraphModuleboolr   r   r   r   r   <module>   sB     
  