
    sgc                        U d dl Z 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mZmZmZ g dZe	j"                  j$                  e	j"                  j&                  j(                  he	j"                  j*                  e	j"                  j&                  j,                  he	j"                  j.                  e	j"                  j&                  j0                  he	j"                  j2                  e	j"                  j&                  j4                  e	j"                  j&                  j6                  he	j"                  j8                  e	j"                  j&                  j:                  he	j"                  j<                  e	j"                  j&                  j>                  e	j"                  j&                  j@                  he	jB                  ejB                  ejD                  ddhe	jF                  ejF                  ejH                  dd	hga%ee   e&d
<   d Z' e'       a(dee   fdZ)ddZ*dee   fdZ+d Z,dee   fdZ-	 	 dde	j\                  j^                  dee   deeege0f      fdZ1y)    N)AnyCallableListOptionalOrderedDictSet)Node)check_subgraphs_connectedget_source_partitionsSourcePartition)find_sequential_partitionsget_equivalent_typesupdate_equivalent_types_dictaddadd_mulmul__EQUIVALENT_TYPESc                  J    i } t         D ]  }|D ]  }t        |      | |<     | S N)r   list)_DICTvaluesvs      Y/var/www/html/venv/lib/python3.12/site-packages/torch/ao/quantization/pt2e/graph_utils.py_create_equivalent_types_dictr   !   s9    E# $ 	$AF|E!H	$$ L    returnc                      t         S r   )r    r   r   r   r   ,   s    r   c                 6    | t        d      | at               ay)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)customized_equivalent_typess    r   r   r   0   s'    
 #*IJJ 4:<r   
partitionsc                 :    d }| D ]  }|t        ||      s y|} y)NFT)r
   )r%   prev_partition	partitions      r   _partitions_sequentialr)   =   s8    N #	%.GI/
 "# r   c                 L    | g}| t         v r|j                  t         |           |S r   )r#   extend)partition_typematching_typess     r   _get_matching_typesr.   H   s-    $%N//4^DEr   partition_typesc                     t               }| D ]0  }t        |      }t        |      }t        ||z        dkD  r y||z  }2 y)Nr   FT)setr.   len)r/   partition_types_setr,   r-   matching_types_sets        r   _valid_type_sequencer5   O   sV    %) 2,^< 0"%7781<112 r   gm	filter_fnc                    t        |      st        d| d      t               }|D ]]  }t        |      }t	        | j
                  ||      }t        t        j                  j                  |j                                     ||<   _ t        |j                               }t        j                  | }	g }
|	D ]  }t        |      s|
j                  |       ! |
S )NzInvalid partition types: z*. Each type in the sequence must be unique)r5   r"   r   r.   r   graphr   	itertoolschainfrom_iterabler   productr)   append)r6   r/   include_functional_equivalentr7   typed_partitionsr,   types_to_matchr%   typed_partitions_listfusion_candidatesfused_partitions	candidates               r   r   r   Z   s      0''88bc
 	
 AL) 
,^<*288^YO
+/OO))**;*;*=>,
(
 !!1!8!8!:;!))+@A& /	!),##I./ r   r   )TN)2r:   operatortypingr   r   r   r   r   r   torchtorch.fxr	   *torch.fx.passes.utils.source_matcher_utilsr
   r   r   __all__nnConv1d
functionalconv1dConv2dconv2dAdaptiveAvgPool2dadaptive_avg_pool2dReLUrelurelu_BatchNorm2d
batch_normHardtanhhardtanh	hardtanh_r   iaddr   imulr   __annotations__r   r#   r   r   r)   r.   r5   fxGraphModuleboolr   r    r   r   <module>rb      s     B B    XX__ehh))001
XX__ehh))001
XX!4!4!H!HI
XX]]EHH'',,ehh.A.A.G.GH
XX588..99:
XX++44ehh6I6I6S6ST
YYhmmUF;
YYhmmUF;	  49 	 78 d3i 
=tO'< $s)  #'26	#Y $./	r   