Ë
    g^(hï  ã                   ót  — U d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlZd dlmZ d dlmZ d dlmZmZmZ g d¢Zej*                  j,                  ej*                  j.                  j0                  hej*                  j2                  ej*                  j.                  j4                  hej*                  j6                  ej*                  j.                  j8                  hej*                  j:                  ej*                  j.                  j<                  ej*                  j.                  j>                  hej*                  j@                  ej*                  j.                  jB                  hej*                  jD                  ej*                  j.                  jF                  ej*                  j.                  jH                  hejJ                  ejJ                  ejL                  d	d
hejN                  ejN                  ejP                  ddhga)e*e+   e,d<   d„ Z- e-«       a.de*e+   fd„Z/d"d„Z0dee   fd„Z1d„ Z2de*e   fd„Z3	 	 d#dejh                  jj                  de*e   de	eege6f      fd„Z7dejh                  jj                  dejh                  j                  de8de9e:ej*                  jv                  ejh                  j                  f   fd„Z<dejh                  jj                  de*e9e:ej*                  jv                  ejh                  j                  f      fd„Z=de
eejh                  jj                  f   d eddfd!„Z>y)$é    N)ÚOrderedDict)ÚSequence)ÚAnyÚCallableÚOptionalÚUnion)ÚExportedProgram)ÚNode)Úcheck_subgraphs_connectedÚget_source_partitionsÚSourcePartition)Úfind_sequential_partitionsÚget_equivalent_typesÚupdate_equivalent_types_dictÚbfs_trace_with_node_processÚaddÚadd_ÚmulÚmul_Ú_EQUIVALENT_TYPESc                  óJ   — i } t         D ]  }|D ]  }t        |«      | |<   Œ Œ | S ©N)r   Úlist)Ú_DICTÚvaluesÚvs      úd/var/www/skyplay_api_hub/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   0   s   € ÜÐr   c                 ó6   — | €t        d«      ‚| at        «       ay)zÒHelp 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   4   s'   € ð
 #Ð*ÜÐIÓJÐJð 4ÐÜ:Ó<Ñr   Ú
partitionsc                 ó:   — d }| D ]  }|�t        ||«      s y|}Œ y)NFT)r   )r'   Úprev_partitionÚ	partitions      r   Ú_partitions_sequentialr+   A   s8   € Ø€NØò #ˆ	ØÐ%Ô.GØ˜Iô/
ñ Ø"‰ð#ð r   c                 óL   — | g}| t         v r|j                  t         |    «       |S r   )r%   Úextend)Úpartition_typeÚmatching_typess     r   Ú_get_matching_typesr0   L   s-   € Ø$Ð%€NØÔ/Ñ/Ø×ÑÔ4°^ÑDÔEØÐr   Úpartition_typesc                 ó‚   — t        «       }| D ]0  }t        |«      }t        |«      }t        ||z  «      dkD  r y||z  }Œ2 y)Nr   FT)Úsetr0   Úlen)r1   Úpartition_types_setr.   r/   Úmatching_types_sets        r   Ú_valid_type_sequencer7   S   sV   € Ü›%ÐØ)ò 2ˆÜ,¨^Ó<ˆÜ  Ó0ÐÜÐ"Ð%7Ñ7Ó8¸1Ò<ÙØÐ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                  |Ž }	|	D �
cg c]  }
t        |
«      r|
‘Œ }}
|S c c}
w )NzInvalid partition types: z*. Each type in the sequence must be unique)r7   r$   r   r0   r   Úgraphr   Ú	itertoolsÚchainÚfrom_iterabler   Úproductr+   )r8   r1   Úinclude_functional_equivalentr9   Útyped_partitionsr.   Útypes_to_matchr'   Útyped_partitions_listÚfusion_candidatesÚ	candidateÚfused_partitionss               r   r   r   ^   sç   € ô   Ô0ÜØ'¨Ð'8Ð8bÐcó
ð 	
ô ALÃÐØ)ò 
ˆÜ,¨^Ó<ˆÜ*¨2¯8©8°^ÀYÓOˆ
Ü+/Ü�O‰O×)Ñ)¨*×*;Ñ*;Ó*=Ó>ó,
Ð˜Ò(ð
ô !Ð!1×!8Ñ!8Ó!:Ó;ÐÜ!×)Ñ)Ð+@ÐAÐð +öàÜ! )Ô,ò 	ðÐð ð
 Ðùòs   Â6CÚgraph_moduleÚnodeÚ	arg_indexc                 ó  — |j                   |   }t        |t        j                  j                  «      sJ ‚|j
                  dk(  sJ ‚t        |j                  t        «      sJ ‚| j                  |j                  «      }|j                  ||fS )NÚget_attr)	ÚargsÚ
isinstanceÚtorchÚfxr
   ÚopÚtargetÚstrÚget_submodule)rG   rH   rI   Úsubmod_nodeÚ	submodules        r   Ú_get_submodulerV   {   s{   € ð —)‘)˜IÑ&€KÜ�k¤5§8¡8§=¡=Ô1Ð1Ð1Ø�>‰>˜ZÒ'Ð'Ð'Ü�k×(Ñ(¬#Ô.Ð.Ð.Ø×*Ñ*¨;×+=Ñ+=Ó>€Ià×Ñ˜y¨$Ð.Ð.r   c                 óÊ  — g }| j                   j                  D ]Ç  }|j                  dk7  rŒ|j                  t        j
                  j                  j                  u r8|j                  t        | |d«      «       |j                  t        | |d«      «       |j                  t        j
                  j                  j                  u sŒ¬|j                  t        | |d«      «       ŒÉ |S )a{  
    Returns a list of submodules used for control flow operations
    (torch.ops.higher_order.cond/map) that are in the given toplevel graph (does not look
    into submodules). Specifically, the returned value is a list containing a
    tuple of (name of the submodule that's stored in the graph module, the
    submodule itself, and the fx node that uses this submodule).
    Úcall_functioné   é   r   )r;   ÚnodesrP   rQ   rN   ÚopsÚhigher_orderÚcondÚappendrV   Úmap_impl)rG   Úcontrol_flow_submodulesrH   s      r   Ú_get_control_flow_submodulesrb   ‡   s»   € ð !ÐØ×"Ñ"×(Ñ(ò RˆØ�7‰7�oÒ%Øà�;‰;œ%Ÿ)™)×0Ñ0×5Ñ5Ñ5Ø#×*Ñ*¬>¸,ÈÈaÓ+PÔQØ#×*Ñ*¬>¸,ÈÈaÓ+PÔQØ�;‰;œ%Ÿ)™)×0Ñ0×9Ñ9Ò9Ø#×*Ñ*¬>¸,ÈÈaÓ+PÕQðRð #Ð"r   ÚmodelÚnode_opc                 ó¼  — t        | t        t        j                  j                  f«      sJ dt        | «      › �«       ‚t        | t        «      r| j                  n| }|g}|rv|j                  d«      }|j                  j                  D ]  }|j                  dv rŒ ||«       Œ t        |«      D ��cg c]  \  }}}|‘Œ
 }}}|j                  |«       |rŒuyyc c}}w )z9Traverse the graph module and apply node_op to each node.z-Expected GraphModule or ExportedProgram, got r   )ÚoutputÚplaceholderN)rM   r	   rN   rO   ÚGraphModuleÚtyperG   Úpopr;   r[   rP   rb   r-   )	rc   rd   r8   ÚqueueÚcurrent_graph_modulerH   Ú_rU   ra   s	            r   r   r   Ÿ   sç   € ô
 Ø”¤§¡×!5Ñ!5Ð6ôð Eà	6´t¸E³{°mÐDóEð ô  *¨%´ÔAˆ×	Ò	Àu€BØˆD€EÙ
Ø$Ÿy™y¨›|ÐØ(×.Ñ.×4Ñ4ò 	ˆDØ�w‰wÐ3Ñ3Øá�D�Mð		ô $@Ð@TÓ#U÷#
á��9˜aò ð#
Ðñ #
ð 	�‰Ð,Ô-ô ùó#
s   Â2Cr   )TN)?r<   ÚoperatorÚcollectionsr   Úcollections.abcr   Útypingr   r   r   r   rN   Útorch.exportr	   Ú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   r   r3   Ú__annotations__r   r%   r   r   r+   r0   r7   rO   rh   Úboolr   ÚintÚtuplerR   ÚModulerV   rb   r   r"   r   r   ú<module>r�      s¸  ðä Û Ý #Ý $ß 1Ó 1ã Ý (Ý ÷ñ ò€ð ‡X�X‡_�_�e—h‘h×)Ñ)×0Ñ0Ð1Ø
‡X�X‡_�_�e—h‘h×)Ñ)×0Ñ0Ð1Ø
‡X�X×Ñ §¡×!4Ñ!4×!HÑ!HÐIØ
‡X�X‡]�]�E—H‘H×'Ñ'×,Ñ,¨e¯h©h×.AÑ.A×.GÑ.GÐHØ
‡X�X×Ñ˜5Ÿ8™8×.Ñ.×9Ñ9Ð:Ø
‡X�X×Ñ˜Ÿ™×+Ñ+×4Ñ4°e·h±h×6IÑ6I×6SÑ6SÐTØ
‡Y�Y�—‘˜hŸm™m¨U°FÐ;Ø
‡Y�Y�—‘˜hŸm™m¨U°FÐ;ð	 Ð �4˜‘9ó 	òñ 7Ó8Ð ð˜d 3™ió ó
=ð x°Ñ'@ó òð¨$¨s©)ó ð #'Ø26ñ	Ø�‰×Ñðà˜#‘Yðð ˜ $ ¨ Ñ.Ñ/ó	ð:	/Ø—(‘(×&Ñ&ð	/Ø.3¯h©h¯m©mð	/ØHKð	/à
ˆ3�—‘—‘ §¡§¡Ð.Ñ/ó	/ð#Ø—(‘(×&Ñ&ð#à	ˆ%��U—X‘X—_‘_ e§h¡h§m¡mÐ3Ñ
4Ñ5ó#ð0.Ø� %§(¡(×"6Ñ"6Ð6Ñ7ð.ØBJð.à	ô.r   