Ë
    ÄÓ^jÍ!  ã            
       óp  — d dl mZ d dlmZ d dlZd dlmZ d dlmc mZ	 d dl
mZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d
dlmZ ej2                  j4                  Zdeeee   f   deeeef      fd„Z eez  eeef   z  Z!ee!e!f   ee!e!e!e!f   z  Z"de#ee"e$f      fd„Z%dede"dedee   de&f
d„Z'y)é    )ÚCallable)ÚAnyN)ÚFakeQuantizeBaseÚObserverBase)Úget_native_backend_config)Ú!_get_pattern_to_quantize_handlers)Úgetattr_from_fqn)ÚGraphModule)ÚNodeé   )ÚNSNodeTargetTypeÚ base_name_to_sets_of_related_opsÚreturnc                 ó$  — t        «       }| j                  «       D ]r  }t        |«      }t        t	        |«      «      D ]N  }t        |t	        |«      «      D ]4  }|j                  ||   ||   f«       |j                  ||   ||   f«       Œ6 ŒP Œt |S )N)ÚsetÚvaluesÚlistÚrangeÚlenÚadd)r   Útype_a_related_to_bÚsÚs_listÚidx_0Úidx_1s         úg/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/torch/ao/ns/fx/pattern_utils.pyÚget_type_a_related_to_br      s¥   € ô KNË%Ðà-×4Ñ4Ó6ò HˆÜ�a“ˆäœ3˜v›;Ó'ò 	HˆEÜ˜u¤c¨&£kÓ2ò H�Ø#×'Ñ'¨°©¸¸u¹Ð(FÔGØ#×'Ñ'¨°©¸¸u¹Ð(FÕGñHñ	HðHð Ðó    c            	      óº  — g } t        t        «       «      }d}|D ]º  }t        |t        «      rFt	        |«      dk(  r8t        |d   t        «      r%t	        |d   «      dk(  r|d   |d   d   |d   d   f}t        |t        «      r| j                  ||f«       t        t        fD ]0  }t        |t        «      r|g|¢­}n||f}| j                  ||f«       Œ2 Œ¼ d}dt        j                  ft        j                  t        j                  df|ft        j                  t        j                  f|ft        j                   t        j"                  f|ft        j$                  t        j&                  f|ft        j(                  t        j                  t        j                  f|ft        j(                  t        j                   t        j"                  f|ft        j(                  t        j$                  t        j&                  f|fg}|D ]U  }| j                  |«       | j                  t        g|d   ¢­|d   f«       | j                  t        g|d   ¢­|d   f«       ŒW | S )aÙ  
    Set of potential fusions, in reverse order.  The order is reversed
    to match how fusion patterns are defined in quantization code.

    Fusion format:
    ((fusion_op_0, fusion_op_1), base_op_idx)

    Where base_op_idx is the idx of the op we should use to match other related
    ops. Note: base_op_idx is specified in non-reverse order, i.e. a base_op_idx
    of 0 represents the first op in regular (non-reverse) order, 1 represents the
    second op, etc.
    r   é   r   ÚtoÚ
dequantize)r   r   Ú
isinstanceÚtupler   Úappendr   r   ÚtorchÚfloat16ÚFÚreluÚlinearÚnnÚBatchNorm1dÚConv1dÚBatchNorm2dÚConv2dÚBatchNorm3dÚConv3dÚReLU)	ÚresultsÚall_quant_patternsÚdefault_base_op_idxÚquant_patternÚclsÚnew_patternÚfp16_em_base_op_idxÚpatterns_to_addÚps	            r   Úget_reversed_fusionsr<   4   s0  € ð /1€Gô ;Ô;TÓ;VÓWÐàÐØ+ò ?ˆô
 �}¤eÔ,Ü�MÓ" aÒ'Ü˜=¨Ñ+¬UÔ3Ü�M !Ñ$Ó%¨Ò*ð +¨1Ñ-¨}¸QÑ/?ÀÑ/BÀMÐRSÑDTÐUVÑDWÐXˆMô
 �m¤UÔ+Ø�N‰N˜MÐ+>Ð?Ô@ô !Ô"2Ð3ò 	?ˆCÜ˜-¬Ô/à"Ð3 ]Ñ3‘à" MÐ2�Ø�N‰N˜KÐ)<Ð=Õ>ñ	?ð/?ðH Ðð
 ”E—M‘MÐ"¤A§F¡F¬A¯H©H°lÐCØð	
ô �.‰.œ"Ÿ)™)Ð	$Ð&9Ð:Ü
�.‰.œ"Ÿ)™)Ð	$Ð&9Ð:Ü
�.‰.œ"Ÿ)™)Ð	$Ð&9Ð:Ü
�'‰'”2—>‘>¤2§9¡9Ð	-Ð/BÐCÜ
�'‰'”2—>‘>¤2§9¡9Ð	-Ð/BÐCÜ
�'‰'”2—>‘>¤2§9¡9Ð	-Ð/BÐCð€Oð  ò :ˆØ�‰�qÔØ�‰œÐ-¨¨!©Ñ-¨q°©tÐ4Ô5Ø�‰Ô)Ð1¨A¨a©DÑ1°1°Q±4Ð8Õ9ð:ð
 €Nr   Úend_nodeÚreversed_fusionÚgmÚ
seen_nodesc                 óB  — | }t        t        |«      «      D �]…  }||v r y||   }|j                  dk(  r€t        |t        «       xr t        |t
        «       }|rX|j                  |k7  r yt        |j                  «      dkD  r-t        |j                  d   t        «      r|j                  d   }Œš y y|j                  dk(  rÍt        |t
        «      }|r¹t        |j                  t        «      s!t        dt        |j                  «      › �«      ‚t        ||j                  «      }	t        |t
        «      s yt        |	|«      s yt        |j                  «      dkD  r.t        |j                  d   t        «      r|j                  d   }�Œv y y|j                  dk(  rýt        |t        «      xr t        |«      dk(  }
t        |t        «      }|s|
rÇ|r|j                  |k7  rn yt        |t        «      st        dt        |«      › �«      ‚|j                  |d   k7  r yt        |j                  «      dk  r y|j                  d	   |d	   k7  r yt        |j                  «      dkD  r.t        |j                  d   t        «      r|j                  d   }�Œ‚ y y y y
)zZ
    Returns true if a pattern ending with `end_node` matches
    the fusion pattern.
    FÚcall_functionr   Úcall_modulezExpected str, got Úcall_methodr    zExpected tuple, got r   T)r   r   Úopr#   ÚstrÚtypeÚtargetÚargsr   ÚAssertionErrorr	   r$   )r=   r>   r?   r@   Úcur_nodeÚ
fusion_idxÚcur_fusion_elÚfusion_el_is_funÚfusion_el_is_modÚ
target_modÚ!fusion_el_is_meth_with_second_argÚfusion_el_is_meth_without_argss               r   Ú end_node_matches_reversed_fusionrS   ˆ   sX  € ð €HÜœC Ó0Ó1ó Bˆ
à�zÑ!Ùà'¨
Ñ3ˆà�;‰;˜/Ò)Ü$.¨}¼cÓ$BÐ Bò  Ü˜}¬dÓ3Ð3ð ñ  Ø—?‘? mÒ3Ù Ü�x—}‘}Ó%¨Ò)¬j¸¿¹ÀqÑ9IÌ4Ô.PØ'Ÿ}™}¨QÑ/‘Há áà�[‰[˜MÒ)Ü)¨-¼Ó>ÐÙÜ! (§/¡/´3Ô7Ü(Ð+=¼dÀ8Ç?Á?Ó>SÐ=TÐ)UÓVÐVÜ-¨b°(·/±/ÓB�
Ü! -´Ô6Ù Ü! *¨mÔ<Ù Ü�x—}‘}Ó%¨Ò)¬j¸¿¹ÀqÑ9IÌ4Ô.PØ'Ÿ}™}¨QÑ/’Há áà�[‰[˜MÒ)ä˜=¬%Ó0ÒL´S¸Ó5GÈ1Ñ5Lð .ô .8¸ÄsÓ-KÐ*Ù-Ñ1RÙ1Ø—‘¨-Ò7Ù$ä% m´UÔ;Ü,Ø2´4¸Ó3FÐ2GÐHóð ð  —‘¨-¸Ñ*:Ò:Ù$Ü˜XŸ]™]Ó+¨aÒ/Ù$Ø!Ÿ™ qÑ)¨]¸1Ñ-=Ò=Ù$ä�x—}‘}Ó%¨Ò)¬j¸¿¹ÀqÑ9IÌ4Ô.PØ'Ÿ}™}¨QÑ/’Há ááðEBðH r   )(Úcollections.abcr   Útypingr   r&   Útorch.nnr+   Útorch.nn.functionalÚ
functionalr(   Útorch.ao.quantizationr   r   Ú$torch.ao.quantization.backend_configr   Ú)torch.ao.quantization.fx.quantize_handlerr   Útorch.ao.quantization.utilsr	   Útorch.fxr
   Útorch.fx.graphr   Úns_typesr   ÚopsÚ	quantizedÚtoqÚdictrF   r   r$   r   ÚNSFusionElTypeÚNSFusionTyper   Úintr<   ÚboolrS   © r   r   ú<module>ri      s  ðÝ $Ý ã Ý ß Ð ß @Ý JÝ WÝ 8Ý  Ý å &ð ‡i�i×Ñ€ðØ&*¨3°Ð4DÑ0EÐ+EÑ&FðàˆÐÐ!1Ð1Ñ	2Ñ3óð( Ø	ñ
àØˆSˆññð ð 
ˆ.˜.Ð
(Ñ)ØˆN˜N¨N¸NÐJÑKñLð ðQ˜d 5¨°sÐ):Ñ#;Ñ<ó QðhOØðOà!ðOð 	ðOð �D‘	ð	Oð
 
ôOr   