§
    ŠŠtjV ã                   óÚ  — d dl Z d dlZd dlmZ d dlZd dlmZ d dlmZm	Z	m
Z
 d dlmZmZmZ d dlmZmZmZ d dlmZ d dlmZmZ d d	lmZ d d
lmZmZ d dlmZmZm Z m!Z!m"Z" d dl#m$Z$ d dl%m&Z&m'Z' d dl(m)Z) ddl*m+Z+m,Z, ddl-m.Z.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z= ddl>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZK g d¢ZLeMeNejO        dgZPejQ        ejR        ejS        ejT        ejU        ejV        ejW        ejX        ejY        ejZ        g
Z[ e
j\        ejN        ¬¦  «        Z]ej^        j_        j`        ja        jb        ej^        j_        j`        ja        jb        dœZcej^        j_        j`        jd        jb        ej^        j_        j`        jd        jb        dœZe	 djdedeOdedeOdeOd eOd!eOfd"„Zfd#e'd$egeheji        jj        f         d!eOfd%„Zkd&e	dz  d!elejm        dz  eOf         fd'„Znd(e)d#e'd)ed*ed+ed!eOfd,„Zod#e'd)ed*ed!eOfd-„Zpd d.lmqZq d d/l#m'Z' eqele'e'f         e'z  df         Zrd#e'd$egeheji        jj        f         d0egere	f         fd1„Zsd2e"dz  d3ete'         dz  d)ed+ed!eOf
d4„Zud#e'd$egeheji        jj        f         d5e.d6ed7edz  d!eleeled8f         e.edz  f         fd9„Zvd:eji        jj        d;ege"eweji        jj                 f         d!dfd<„Zxd3e!d=eyeh         fd>„Zz	 dkd#e'd&e	d?eji        jj        d$egeheji        jj        f         d@e&dAej{        dz  d!e'fdB„Z|d3e!dCe'd)edDe=dz  d+ed$egeheji        jj        f         dEege'eOf         dFeye'         d!dfdG„Z}d#e'd)edDe=dz  d$egeheji        jj        f         d+edEege'eOf         d!egehef         fdH„Z~d(e'd$egeheji        jj        f         d0egere	f         dIeOd!e	dz  f
dJ„Zd(e'd$egeheji        jj        f         d0egere	f         dIeOd!ejm        dz  f
dK„Z€d(e'd#e'd$egeheji        jj        f         d0egere	f         dIeOd!e	dz  fdL„Z�	 	 dld#e'ez  d(e)d)ed?eji        jj        d$egeheji        jj        f         d@e&dDe=dz  d5e.d0egere	f         dIeOd+edz  dAej{        dz  d!e)fdM„Z‚	 	 dld#e'd)ed?eji        jj        d$egeheji        jj        f         d@e&dDe=dz  d5e.d0egere	f         dIeOd+edz  dAej{        dz  d!dfdN„Zƒd#e'dOed?eji        jj        d$egeheji        jj        f         d@e&dPeOd!dfdQ„Z„d#e'd?eji        jj        d$egeheji        jj        f         d@e&d0egere	f         dIeOd!e'dz  fdR„Z…dSe'd?eji        jj        d$egeheji        jj        f         d@e&d0egere	f         dIeOd!dfdT„Z†d#e'dUejm        ewz  dVegehe2f         d!dfdW„Z‡d@e&dVegehe2f         d!dfdX„Zˆd#e'd?eji        jj        d$egeheji        jj        f         d!eOfdY„Z‰d#e'd?eji        jj        d$egeheji        jj        f         fdZ„ZŠd#e'd)ed$egeheji        jj        f         d5e.fd[„Z‹d?e$dVegehe2f         d\egehef         d5e.d]egehef         d+ed^eyeh         dIeOd!e'dz  fd_„ZŒd?eji        jj        dIeOd$egeheji        jj        f         dVed5e.d+ed!dfd`„Z�dae$d\egehef         dbegehelehewf         f         d5e.dcegehef         ddedIeOd^eyeh         d!dfde„ZŽ	 	 	 	 dmd?e$ddeegehef         z  dIeOdbegehelehewf         f         dfeled8f         d5e.egehef         z  dz  dgeegehef         z  dz  d+eegehef         z  dz  dheOd!e$fdi„Z�dS )né    N)ÚAny)Ú
FakeTensor)ÚObserverBaseÚObserverOrFakeQuantizeÚPlaceholderObserver)ÚBackendConfigÚDTypeConfigÚget_native_backend_config)Ú&get_fusion_pattern_to_root_node_getterÚget_module_to_qat_moduleÚget_pattern_to_dtype_configs)Ú_is_activation_post_process)Ú_is_reuse_input_qconfigÚ
QConfigAny)ÚQConfigMapping)ÚconvertÚpropagate_qconfig_)Ú_parent_nameÚget_qconfig_dtypesÚget_swapped_custom_module_classÚNodePatternÚPattern)ÚGraphModule)ÚGraphÚNode)ÚArgumenté   )Úis_equalization_observerÚnode_supports_equalization)ÚPrepareCustomConfigÚStandaloneModuleConfigEntry)Ú_find_matchesÚ_MatchResultWithQConfig)Ú_sorted_patterns_dict)Ú_generate_node_name_to_qconfigÚ_get_flattened_qconfig_dictÚ_update_qconfig_for_fusionÚ_update_qconfig_for_qat)Ú_default_root_node_getterÚ!_get_pattern_to_quantize_handlersÚQuantizeHandler)Ú3_insert_dequant_stubs_for_custom_module_lstm_outputÚ_is_custom_module_lstmÚ+_maybe_get_custom_module_lstm_from_node_argÚ+_qconfig_satisfies_dtype_config_constraintsÚall_node_args_have_no_tensorsÚassert_and_get_unique_deviceÚget_custom_module_class_keysÚget_new_attr_name_with_prefixÚ(get_non_observable_arg_indexes_and_typesÚnode_arg_is_biasÚnode_arg_is_weightÚNON_QUANTIZABLE_WEIGHT_OPSÚObservedGraphModuleAttrs)Úinsert_observers_for_modelÚprepareÚ propagate_dtypes_for_known_nodes©Údtype©Úinput_act_obs_or_fq_ctrÚoutput_act_obs_or_fq_ctrFÚprev_output_dtypeÚprev_output_is_dynamicÚcur_target_dtypeÚcur_target_is_dynamicÚreuse_input_obs_or_fqÚis_zeroth_argÚreturnc                 óÈ   — |r5|t           vrt          d|› �¦  «        ‚| t          v rt          d¦  «        ‚|S |rdS |t           v r| t           t          j        gz   v o|| k    S dS )a×  
    note: we will treat "not specified" as torch.float for now
    utility function that checks if we should insert an observer or fake quant node
    base on the requested dtype for the nodes from user

    is_zeroth_arg: we only dynamically quantize the first arg of the node right now
      this should be removed when we enable configuring dynamic quantization
      for a specific argument, this can be removed if we deprecate fx graph mode
      quantization

    z6Expected cur_target_dtype to be torch.float, but got: z7prev_output_dtype must not be in _DO_NOT_OBS_DTYPE_LISTF)Ú_OBS_DTYPE_LISTÚAssertionErrorÚ_DO_NOT_OBS_DTYPE_LISTÚtorchÚfloat)rA   rB   rC   rD   rE   rF   s         ú^/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/ao/quantization/fx/prepare.pyÚ_needs_obs_or_fqrO   k   s£   € ð, ð 	Ø¥?Ð2Ð2Ý Ø[ÐIYÐ[Ð[ñô ð ð Õ 6Ð6Ð6Ý ØIñô ð ð ÐØð Øˆuà�?Ð*Ð*à¥µE´K°=Ñ!@Ð@ð 6Ø Ð$5Ò5ð	
ð ˆ5ó    ÚnodeÚnamed_modulesc                 ó¤   — t          | t          j        j        ¦  «        o1| j        dk    o&t          |t          | j        ¦  «                 ¦  «        S )NÚcall_module)Ú
isinstancerL   Úfxr   Úopr   ÚstrÚtarget)rQ   rR   s     rN   Ú _is_activation_post_process_noderZ   ˜   sJ   € õ 	�4�œœÑ'Ô'ð 	IØŒG�}Ò$ð	Iå'¨µc¸$¼+Ñ6FÔ6FÔ(GÑHÔHðrP   Ú	obs_or_fqc                 ó:   — | €dS | j         t          | dd¦  «        fS )zgGiven a constructor for observer or fake quant module, returns
    a Tuple of dtype and is_dynamic
    N)NFÚ
is_dynamicF)r=   Úgetattr)r[   s    rN   Ú_get_dtype_and_is_dynamicr_   ¢   s(   € ð ÐØˆ{àŒ¥¨	°<ÀÑ GÔ GÐGÐGrP   ÚargÚqconfigÚdtype_configÚbackend_configc                 óš  ‡‡‡‡— t          | t          t          f¦  «        rt          ˆˆˆˆfd„| D ¦   «         ¦  «        S t          | t          ¦  «        sdS t          ‰| ¦  «        }t          ‰| ¦  «        }| o| }|rŽ‰j        d                              d¦  «        }|r
 |¦   «         nd}	t          |	¦  «        \  }
}‰j
        du pD‰j
        |
k    o9t          ‰j        ¦  «        t          |¦  «        k    ot          ‰‰j        ¦  «        S |rm‰j        d                              dd¦  «        }|r
 |¦   «         nd}t          |¦  «        \  }}‰j        }||k    }t          ‰‰j        d¬¦  «        }|du p|o|S ‰j        d                              d	d¦  «        }|r
 |¦   «         nd}t          |¦  «        \  }}‰j        }|du p||k    S )
z\Check if the configured qconfig for the argument
    is supported by the backend or not
    c              3   ó>   •K  — | ]}t          |‰‰‰‰¦  «        V — Œd S ©N)Ú(_is_input_arg_dtype_supported_by_backend)Ú.0Úarc   rb   rQ   ra   s     €€€€rN   ú	<genexpr>z;_is_input_arg_dtype_supported_by_backend.<locals>.<genexpr>º   sR   øè è € ð 	
ð 	
ð õ 5ØØØØØñô ð	
ð 	
ð 	
ð 	
ð 	
ð 	
rP   TÚtarget_dtype_infor?   NÚweight_obs_or_fq_ctrF)Úis_activationÚbias_obs_or_fq_ctr)rU   ÚlistÚtupleÚallr   r6   r5   ÚmetaÚgetr_   Úinput_dtypeÚboolr]   r/   Úinput_dtype_with_constraintsÚweight_dtypeÚweight_dtype_with_constraintsÚ
bias_dtype)r`   rQ   ra   rb   rc   Ú	is_weightÚis_biasrm   r?   Úinput_act_obs_or_fqÚqconfig_dtypeÚqconfig_is_dynamicrl   Úweight_obs_or_fqÚqconfig_weight_dtypeÚ_Úbackend_config_weight_dtypeÚdtype_matchesÚqconfig_satisfies_constraintsrn   Úbias_obs_or_fqÚqconfig_bias_dtypeÚbackend_config_bias_dtypes    ````                  rN   rg   rg   ¯   s’  øøøø€ õ �#��e�}Ñ%Ô%ð 

Ýð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð ð	
ñ 	
ô 	
ñ 	
ô 	
ð 		
õ �c�4Ñ Ô ð Øˆtå" 4¨Ñ-Ô-€IÝ˜t SÑ)Ô)€GØ!�MÐ1¨' k€MØð -
Ø"&¤)Ð,?Ô"@×"DÒ"DØ%ñ#
ô #
Ðð *AÐJÐ#Ð#Ñ%Ô%Ð%Àdð 	õ -FØñ-
ô -
Ñ)ˆÐ)ð
 Ô(¨DÐ0ð 
ØÔ$¨Ò5ð Ý�\Ô,Ñ-Ô-µÐ6HÑ1IÔ1IÒIðå;Ø˜ÔBñô ð	
ð 
ð 
à#œyÐ)<Ô=×AÒAØ" Dñ 
ô  
Ðð 6JÐSÐ/Ð/Ñ1Ô1Ð1ÈtÐÝ";Ð<LÑ"MÔ"MÑÐ˜aØ&2Ô&?Ð#Ø,Ð0KÒKˆÝ(SØ�\Ô?Èuð)
ñ )
ô )
Ð%ð +¨dÐ2ð 
ØÐ;Ð;ð	
ð
 "œYÐ':Ô;×?Ò?Ø  $ñ
ô 
Ðð 2DÐMÐ+Ð+Ñ-Ô-Ð-ÈˆÝ 9¸.Ñ IÔ IÑÐ˜AØ$0Ô$;Ð!à%¨Ð-ð ?Ø!Ð%>Ò>ð	
rP   c                 ó  — |j         }d}| j        d                              dt          ¦  «        }|r
 |¦   «         nd}t	          |¦  «        \  }}|rt
          j        }||k    }t          ||j        ¦  «        }	|du p|o|	S )zZCheck if the configured qconfig for the output
    is supported by the backend or not
    Nrk   r@   )	Úoutput_dtyperr   rs   Ú_DEFAULT_FP32_OBS_OR_FQ_CTRr_   rL   Úfloat32r/   Úoutput_dtype_with_constraints)
rQ   ra   rb   Úbackend_config_output_dtypeÚqconfig_output_dtyper@   Úoutput_act_obs_or_fqÚqconfig_output_is_dynamicrƒ   r„   s
             rN   Ú%_is_output_dtype_supported_by_backendr‘   ú   sÅ   € ð #/Ô";Ðð  ÐØ#œyÐ)<Ô=×AÒAØ"Õ$?ñ ô  Ðð '?ÐHÐ Ð Ñ"Ô"Ð"ÀDð õ 7PØñ7ô 7Ñ3ÐÐ3ð !ð -Ý$œ}ÐØ(Ð,GÒG€MÝ$OØ�Ô;ñ%ô %Ð!ð '¨$Ð.ð ØÐ7Ð7ðrP   )Ú	Annotated)r   Úobs_or_fq_mapc                 óþ   — t          | |||¦  «        }t          | j        ¦  «        dk    rRt          | j        d         t          ¦  «        r2|t
          j        t
          j        fv r| j        d         j        dk    rdS dS )zÓCheck if observer in same graph
    when the node output is not fp32 and input is 'placeholder'
    the input is assumed to be quantized, so it is observed
    in a different place rather than not observed.
    r   ÚplaceholderFT)	Ú_get_arg_target_dtype_as_outputÚlenÚargsrU   r   rL   Úquint8Úuint8rW   )rQ   rR   r“   Úis_qatÚnode_output_dtypes        rN   Ú_is_observer_in_same_graphr�   '  sx   € õ 8Øˆm˜]¨Fñô Ðõ ˆ4Œ9�~„~˜ÒÐ�j¨¬°1¬µtÑ<Ô<Ðà¥%¤,µ´Ð!<Ð<Ð<Ø”	˜!”” =Ò0Ð0à�5Øˆ4rP   ÚpatternÚmatched_node_patternc           	      ó  — |�| €dS |�t          |¦  «        dk     rt          d¦  «        ‚t          |¦  «        }|                     | g ¦  «        }t	          |¦  «        }|                     | t
          ¦  «        } ||¦  «        }|}	|d         }
|D ]o}d}t          |	j        ¦  «        t          |	j         	                    ¦   «         ¦  «        z   D ]}|ot          ||	|||¦  «        }Œ|ot          |
||¦  «        }|r dS ŒpdS )z¹Check if the dtype configuration of a pattern is supported by
    the backend or not, and whether the qconfig satisfies constraints
    specified in the corresponding dtype config.
    NTr   z&matched_node_pattern must be non-emptyr   F)r—   rJ   r   rs   r   r)   ro   r˜   ÚkwargsÚvaluesrg   r‘   )rž   rŸ   ra   rc   Úpattern_to_dtype_configsÚdtype_configsÚpattern_to_root_node_getterÚroot_node_getterÚ	root_nodeÚ
input_nodeÚoutput_noderb   Ú	supportedr`   s                 rN   Ú9_is_pattern_dtype_config_and_qconfig_supported_by_backendr«   >  sR  € ð Ð  ØˆtØÐ#¥sÐ+?Ñ'@Ô'@À1Ò'DÐ'DÝÐEÑFÔFÐFÝ;¸NÑKÔKÐØ'?×'CÒ'CÀGÈRÑ'PÔ'P€MÝ"HÈÑ"XÔ"XÐà2×6Ò6ØÕ*ñô Ðð !Ð Ð!5Ñ6Ô6€IØ€JØ& qÔ)€KØ%ð ð ˆàˆ	Ý˜
œÑ(Ô(­4°
Ô0A×0HÒ0HÑ0JÔ0JÑ+KÔ+KÑKð 	ð 	ˆCØ!ð Õ&NØ�Z ¨,¸ñ'ô 'ˆIˆIð ð 
Õ"GØ˜ ,ñ#
ô #
ˆ	ð ð 	Ø�4�4ð	àˆ5rP   Úprepare_custom_configÚparent_qconfigÚparent_backend_config.c                 óŠ  — t          | j        ¦  «        }t          ||         ¦  «        }t          dddd¦  «        }|j                             ||¦  «        }|j                             ||¦  «        }|j        p t          ¦   «          	                    |¦  «        }|j
        }	|j        pt          ¦   «         }|j        p|}
||	||
fS )z©
    Returns the standalone module QConfigMapping and PrepareCustomConfig
    for `node`, assuming that the module pointed to by `node` is
    a standalone modules.
    N© )rX   rY   Útyper!   Ústandalone_module_classesrs   Ústandalone_module_namesÚqconfig_mappingr   Ú
set_globalÚexample_inputsr¬   r    rc   )rQ   rR   r¬   r­   r®   Úmodule_nameÚmodule_typeÚconfig_entryr´   r¶   rc   s              rN   Ú_get_standalone_module_configsrº   f  sÛ   € õ �d”kÑ"Ô"€KÝ�} [Ô1Ñ2Ô2€Kå.¨t°R¸¸tÑDÔD€LØ(ÔB×FÒFØ�\ñô €Lð )Ô@×DÒDØ�\ñô €Lð #Ô2ð µnÑ6FÔ6F×6QÒ6QØñ7ô 7€Oð "Ô0€NØ(Ô>ÐWÕBUÑBWÔBWÐØ!Ô0ÐIÐ4I€NØ˜^Ð-BÀNÐSÐSrP   ÚrootÚmodule_to_qat_modulec                 ó,   — t          | |dd¬¦  «         d S )NTF)ÚmappingÚinplaceÚremove_qconfig)r   )r»   r¼   s     rN   Ú_qat_swap_modulesrÁ   †  s"   € õ ˆDÐ.¸ÈUÐSÑSÔSÐSÐSÐSrP   Úsc                 óÎ   — t          | t          ¦  «        r|                     | j        ¦  «         d S t          | t          t
          f¦  «        r| D ]}t          ||¦  «         Œd S d S rf   )rU   r   ÚaddÚnamero   rp   Ú_add_matched_node_name_to_set)rŸ   rÂ   Ú
maybe_nodes      rN   rÆ   rÆ   Œ  s~   € ÝÐ&­Ñ-Ô-ð 9Ø	�ŠÐ"Ô'Ñ(Ô(Ð(Ð(Ð(Ý	Ð(­4µ¨-Ñ	8Ô	8ð 9Ø.ð 	9ð 	9ˆJÝ)¨*°aÑ8Ô8Ð8Ð8ð9ð 9ð	9ð 	9rP   ÚmodelÚgraphÚmodel_devicec                 óz  — |€t          |¦  «        }|r|                     |¦  «         t          |¦  «        r| j        dz   }nd}t	          |¦  «        } ||¦  «        }t          |||¦  «         |||<   |                     | ¦  «        5  |                     d|| fi ¦  «        }	ddd¦  «         n# 1 swxY w Y   |	S )z±
    Attaches `obs_or_fq` to `model`, and creates a node which calls
    `obs_or_fq` on the output of `node`.

    obs_or_fq: an instance of Observer or FakeQuantize module
    NÚ_equalization_process_Úactivation_post_process_rT   )r1   Útor   rÅ   r3   ÚsetattrÚinserting_afterÚcreate_node)
rQ   r[   rÈ   rR   rÉ   rÊ   ÚprefixÚget_new_obs_or_fq_nameÚobs_or_fq_nameÚnew_obss
             rN   Ú_insert_obs_or_fqrÖ   ”  s)  € ð ÐÝ3°EÑ:Ô:ˆØð #Ø�Š�\Ñ"Ô"Ð"å 	Ñ*Ô*ð ,Ø”Ð5Ñ5ˆˆà+ˆÝ:¸6ÑBÔBÐØ+Ð+¨EÑ2Ô2€NÝˆE�> 9Ñ-Ô-Ð-Ø$-€M�.Ñ!Ø	×	Ò	˜tÑ	$Ô	$ð Pð PØ×#Ò# M°>ÀDÀ7ÈBÑOÔOˆðPð Pð Pñ Pô Pð Pð Pð Pð Pð Pð Pøøøð Pð Pð Pð Pà€Ns   Â
B0Â0B4Â7B4Ú	last_nodeÚqhandlerÚcache_for_no_tensor_checkÚprocessed_nodesc                 ól  — t          | t          t          f¦  «        r| D ]}t          ||||||||¦  «         ŒdS t          | t          ¦  «        ret          | t          ¦  «        st          d¦  «        ‚| }	|	|v rdS |                     |	¦  «         |€dS t          |	|||||¦  «        }
|
|	j        d<   dS dS )z�Sets the target_dtype_info for each node in matched_node_pattern
    Note: processed_nodes is used to ensure we only process each node once
    z#matched_node_pattern must be a NodeNrk   )	rU   ro   rp   Ú/_set_target_dtype_info_for_matched_node_patternr   rJ   rÄ   Ú%_get_target_activation_dtype_for_noderr   )rŸ   r×   ra   rØ   rc   rR   rÙ   rÚ   Únode_patternrQ   rk   s              rN   rÜ   rÜ   ´  s  € õ Ð&­­u¨Ñ6Ô6ð (;Ø0ð 
	ð 
	ˆLÝ;ØØØØØØØ)Øñ	ô 	ð 	ð 	ð
	ð 
	õ 
Ð(­$Ñ	/Ô	/ð ;åÐ.µÑ5Ô5ð 	HÝ Ð!FÑGÔGÐGØ#ˆØ�?Ð"Ð"ØˆFØ×Ò˜DÑ!Ô!Ð!àˆ?ØˆFõ -RØØØØØØ%ñ-
ô -
Ðð *;ˆŒ	Ð%Ñ&Ð&Ð&ð3;ð ;rP   c           
      óB  — t          | ||¦  «        }|rdddœS |��lt          |¦  «        \  }}}	|t          j        k    r|t          j        k    r|	st          j        nt          j        }
|duo|                     ¦   «         }|duo|                     ¦   «         }d}t          | t          ¦  «        rC| j	        dk    r8| j
        |j        v r*|j        | j
                 j                             d¦  «        }d}t          | t          ¦  «        rC| j	        dk    r8| j
        |j        v r*|j        | j
                 j                             d¦  «        }|j        |j        t!          j        |
¬¦  «        |||j        t%          |¦  «        ||dœ	S t'          j        t(          ¦  «        S )a<  
    For each op attribute in the op's input activation, output activation,
    weight, bias - returns the settings of dtype and is_dynamic we expect
    for the `quantize` call in the reference model representation, or None
    if there is no `quantize` call needed.

    For example, if we have a node corresponding to `op0` in

      x0 -> op0 -> x1

    And we want a reference quantized representation to be

      x0 -> quant_static -> dequant -> op0 -> quant_dynamic -> dequant -> x1

    Then this function will return

      {
        "input_act_obs_or_fq_ctr": MinMaxObserver.with_args(dtype=torch.quint8, is_dynamic=False),
        "output_act_obs_or_fq_ctr": MinMaxObserver.with_args(dtype=torch.quint8, is_dynamic=False),
      }

    TODO(future PR, if needed): explicitly spell out the non-Tensor
    dtypes.
    Nr>   Úcall_functionÚweightÚbiasr<   )	r?   rl   rn   Úweight_indexÚ
bias_indexr@   rE   Úinput_output_share_observersÚ_is_standalone_module)r0   r   rL   Úfloat16rM   Úis_general_tensor_value_opÚis_standalone_modulerU   r   rW   rY   Ú!_pattern_complex_format_to_configÚ_input_type_to_indexrs   Ú
activationrá   r   Ú	with_argsr   ÚcopyÚ+_DEFAULT_FP32_QCONFIG_FOR_TARGET_DTYPE_INFO)rQ   ra   rØ   rR   rc   rÙ   Úargs_have_no_tensorsÚ	act_dtyperw   Úinput_act_is_dynamicry   rè   ræ   rã   rä   s                  rN   rÝ   rÝ   ì  sÛ  € õ@ 9ØˆmÐ6ñô Ðð ð 
à'+Ø(,ð
ð 
ð 	
ð
 ÑÝ8JÈ7Ñ8SÔ8SÑ5ˆ	�<Ð!5ð �Uœ]Ò*Ð*Ø ¥E¤MÒ1Ð1Ø-ð 2õ ŒMˆMõ ”ð 	ð ˜DÐ ÐJ X×%HÒ%HÑ%JÔ%Jð 	#ð !)°Ð 4Ð X¸×9VÒ9VÑ9XÔ9XÐàˆå�t�TÑ"Ô"ð	1à”˜?Ò*Ð*Ø”˜~ÔOÐOÐOà)ÔKØ”ôä"§3¢3 x¡=¤=ð ð ˆ
å�t�TÑ"Ô"ð	/à”˜?Ò*Ð*Ø”˜~ÔOÐOÐOà'ÔIØ”ôä"§3¢3 v¡;¤;ð ð
 (/Ô'9Ø$+¤NÝ"5Ô"?ÀjÐ"QÑ"QÔ"QØ(Ø$Ø(/Ô(:Ý%<¸WÑ%EÔ%EØ,FØ%:ð

ð 

ð 
	
õ Œ9Õ@ÑAÔAÐArP   r›   c                 óš  — t          | t          ¦  «        st          d¦  «        ‚d| j        v rt	          d¦  «        ‚t          | |¦  «        }d}|�"|j        d         d         }|r
 |¦   «         nd}nØt          | |¦  «        rƒ| j        d         }t          |t          ¦  «        st          d¦  «        ‚d|j        v rt	          d¦  «        ‚d|j        vrt          d	¦  «        ‚|j        d         d         }|r
 |¦   «         nd}nEd| j        v r'| j        d                              dt          ¦  «        }nt          }|r
 |¦   «         nd}|S )
aC  Get the constructor for observer or fake quant object for
    the argument in the original graph as the output of previous node,
    skipping inserted observers

    We are assuming that the observers are inserted correctly, and the dtype for
    argument in quantized graph will match what is specified by the qconfig
    úarg must be a NodeÚquantization_annotationúMPlease use torchao (https://github.com/pytorch/ao) for pt2e quantization flowNrk   r@   r   z(Currently we only support observing Nodez1expected 'target_dtype_info' in observed_arg.meta)
rU   r   rJ   rr   ÚNotImplementedErrorr.   rZ   r˜   rs   rŠ   )r`   rR   r“   r›   Úcustom_module_lstm_noder@   r�   Úobserved_args           rN   Ú_get_output_act_obs_or_fqrú   Q  sÅ  € õ �c�4Ñ Ô ð 3ÝÐ1Ñ2Ô2Ð2à  C¤HÐ,Ð,Ý!Ø[ñ
ô 
ð 	
õ JØˆ]ñô Ðð  $ÐØÐ*Ø#:Ô#?Ð@SÔ#TØ&ô$
Ð ð +CÐLÐ$Ð$Ñ&Ô&Ð&Èð 	Ðõ 
*¨#¨}Ñ	=Ô	=ð 
Ø”x ”{ˆÝ˜,­Ñ-Ô-ð 	MÝ Ð!KÑLÔLÐLà$¨Ô(9Ð9Ð9Ý%Ø_ñô ð ð  lÔ&7Ð7Ð7Ý Ð!TÑUÔUÐUØ#/Ô#4Ð5HÔ#IØ&ô$
Ð ð +CÐLÐ$Ð$Ñ&Ô&Ð&Èð 	Ðð  #¤(Ð*Ð*Ø'*¤xÐ0CÔ'D×'HÒ'HØ*Õ,Gñ(ô (Ð$Ð$õ (CÐ$à*BÐLÐ$Ð$Ñ&Ô&Ð&Èð 	ð  ÐrP   c                 óN   — t          | |||¦  «        }t          |¦  «        \  }}|S rf   )rú   r_   )r`   rR   r“   r›   Úarg_as_output_act_obs_or_fqÚarg_as_output_target_dtyper�   s          rN   r–   r–   –  s?   € õ #<Øˆ]˜M¨6ñ#ô #Ðõ %>Ø#ñ%ô %Ñ!Ð ð &Ð%rP   c                 óò  — t          | t          ¦  «        st          d¦  «        ‚d|j        v rt	          d¦  «        ‚t          || ¦  «        }t          || ¦  «        }| o| }d}|r'|j        d                              dt          ¦  «        }n]|r5|j	        t          vr&|j        d                              dt          ¦  «        }n&|j        d                              dt          ¦  «        }|r
 |¦   «         ndS )	zcGet the observer or fake quant constructor for the Argument `arg`, as input
    to Node `node`
    rô   rõ   rö   Nrk   r?   rl   rn   )rU   r   rJ   rr   r÷   r6   r5   rs   rŠ   rY   r7   )	r`   rQ   rR   r“   r›   rz   r{   rm   Úobs_or_fq_ctrs	            rN   Ú_get_arg_as_input_act_obs_or_fqr   ¥  s  € õ �c�4Ñ Ô ð 3ÝÐ1Ñ2Ô2Ð2à  D¤IÐ-Ð-Ý!Ø[ñ
ô 
ð 	
õ # 4¨Ñ-Ô-€IÝ˜t SÑ)Ô)€GØ!�MÐ1¨' k€MØ€MØð 
Øœ	Ð"5Ô6×:Ò:Ø%Õ'Bñ
ô 
ˆˆð 
ð 
ØŒ;Õ8Ð8Ð8Ø œIÐ&9Ô:×>Ò>Ø&Õ(Cñô ˆMøð œ	Ð"5Ô6×:Ò:Ø Õ"=ñ
ô 
ˆð ,Ð5ˆ=ˆ=‰?Œ?ˆ?°Ð5rP   c                 óª  — t          |t          t          f¦  «        rNg }|D ]1}t          | |||||||||	|
|¦  «        }|                     |¦  «         Œ2 t          |¦  «        |¦  «        S t          |t          ¦  «        s|S t          |t          ¦  «        st          d¦  «        ‚|}|duo|                     ¦   «         }|s×d| j	        v rt          d¦  «        ‚d| j	        vrt          d¦  «        ‚| j	        d         }|                     dd¦  «        }t          || |||	¦  «        }t          |¦  «        \  }}t          ||||	¦  «        }t          |¦  «        \  }}t          |||||t!          | j        ¦  «        d	k    o|| j        d	         u ¬
¦  «        }n²|€t          d¦  «        ‚t%          | ||||
¦  «        \  }}}}|j        }d}t)          | j        ¦  «        D ]\  }}||u r|} nŒ|€d}nDt+          ||||	¦  «        }||v rt,          j        nt,          j        }||k    o|t,          j        k    }|j        } | r
 | ¦   «         nd}|r†d}!|j        D ]I}"|"j        dk    r<||"j                 }#t          |#¦  «        t          |¦  «        u r|#j        |k    r|#}|"}! nŒJ|€t          d¦  «        ‚|||| f<   |!€t=          ||||||¦  «        }$|$}n|!}|S )zk
    Given a `node` and an `arg`, inserts an input observer between
    `node` and `arg` if necessary.
    rô   Nrõ   rö   rk   ú)expected 'target_dtype_info' in node.metarE   Fr   )rF   zqconfig must not be NonerT   z+arg_as_input_act_obs_or_fq must not be None)rU   ro   rp   Ú-_maybe_insert_input_observer_for_arg_or_kwargÚappendr±   r   rJ   ré   rr   r÷   rs   r   r_   rú   rO   r—   r˜   rº   Úinput_quantized_indexesÚ	enumerater–   rL   r™   rM   rì   ÚusersrW   rY   r=   rÖ   )%rQ   r`   ra   rÈ   rR   rÉ   rØ   r¬   r“   r›   rc   rÊ   Únew_arg_to_returnÚ	inner_argÚnew_inner_argÚnew_argré   rk   rE   Úarg_as_input_act_obs_or_fqÚarg_as_input_target_dtypeÚarg_as_input_target_is_dynamicrü   rý   Úarg_as_output_target_is_dynamicÚneeds_obs_or_fqr�   Úsm_prepare_custom_configÚsm_input_quantized_idxsÚcur_input_idxÚarg_idxÚarg_to_checkÚact_post_process_ctrÚexisting_obs_nodeÚmaybe_obs_nodeÚmaybe_obs_modÚnew_obs_nodes%                                        rN   r  r  Í  sû  € õ( �#��e�}Ñ%Ô%ð ,ØÐØð 	4ð 	4ˆIÝIØØØØØØØØ%ØØØØñô ˆMð ×$Ò$ ]Ñ3Ô3Ð3Ð3Ø�t�C‰yŒyÐ*Ñ+Ô+Ð+å�c�4Ñ Ô ð Øˆ
Ý�c�4Ñ Ô ð 3ÝÐ1Ñ2Ô2Ð2à€Gà#¨4Ð/ÐS°H×4QÒ4QÑ4SÔ4SÐàð N
ð
 %¨¬	Ð1Ð1Ý%Ø_ñô ð ð  d¤iÐ/Ð/Ý Ð!LÑMÔMÐMð !œIÐ&9Ô:Ðð !2× 5Ò 5Ð6MÈuÑ UÔ UÐÝ%DØ��} m°Vñ&
ô &
Ð"õ &Ð&@ÑAÔAñ	
Ø%Ø*õ '@Ø� ¨vñ'
ô '
Ð#õ &Ð&AÑBÔBñ	
Ø&Ø+õ +Ø&Ø+Ø%Ø*Ø!Ý˜dœi™.œ.¨1Ò,ÐD°¸¼	À!¼Ð1Dð
ñ 
ô 
ˆˆð ˆ?Ý Ð!;Ñ<Ô<Ð<å,JØ�-Ð!6¸Àñ-
ô -
Ñ)ˆˆ1Ð&¨ð #;Ô"RÐð ˆÝ%.¨t¬yÑ%9Ô%9ð 	ð 	Ñ!ˆG�\Ø˜sÐ"Ð"Ø '�Ø�ð #ð Ð Ø#ˆOˆOå)HØ�] M°6ñ*ô *Ð&ð
 !Ð$;Ð;Ð;õ ”�å”[ð &ð +Ð.GÒGð=à,µ´Ò;ð ð  'Ô1Ðà&:ÐDÐ Ð Ñ"Ô"Ð"Àð 	#ð ð %(Ø Ðð "œið 		ð 		ˆNØÔ  MÒ1Ð1Ø -¨nÔ.CÔ D�å˜Ñ'Ô'­4Ð0JÑ+KÔ+KÐKÐKØ%Ô+Ð/HÒHÐHà1>Ð.Ø(6Ð%Ø�Eøà%Ð-Ý Ð!NÑOÔOÐOØ%?ˆ�s˜D�kÑ"ØÐ$Ý,ØØ*ØØØØñô ˆLð #ˆGˆGà'ˆGà€NrP   c                 ó2  — g }| j         D ]1}t          | ||||||||||	|
¦  «        }|                     |¦  «         Œ2i }| j                             ¦   «         D ]$\  }}t          | ||||||||||	|
¦  «        }|||<   Œ%t          |¦  «        | _         || _        dS )aK  
    If needed, inserts observers to the input args and kwargs of `node`.
    Note: modifies `node` inplace.

    For example, if cur_node needs an observer after prev_node, we change from

      prev_node -> cur_node

    To

      prev_node -> obs -> cur_node

    Note: backend_config only needed for standalone_module node
    N)r˜   r  r  r¡   Úitemsrp   )rQ   ra   rÈ   rR   rÉ   rØ   r¬   r“   r›   rc   rÊ   Únew_argsr`   r  Ú
new_kwargsÚkÚkwargÚ	new_kwargs                     rN   Ú&_maybe_insert_input_observers_for_noder"  x  sä   € ð: €HØŒyð !ð !ˆÝ?ØØØØØØØØ!ØØØØñ
ô 
ˆð 	�Š˜Ñ Ô Ð Ð à€JØ”K×%Ò%Ñ'Ô'ð "ð "‰ˆˆ5ÝAØØØØØØØØ!ØØØØñ
ô 
ˆ	ð "ˆ
�1‰ˆõ �h‘”€D„IØ€D„K€K€KrP   Úequalization_qconfigÚ	is_branchc                 óÄ  — |�t          | |¦  «        sdS |rt          j        d| › d�d¬¦  «         dS g }| j        D ]�}t	          |t
          ¦  «        rt          | |¦  «        r|                     |¦  «         Œ=t          | |¦  «        }|r|j	        n|j
        }	 |	¦   «         }
t          ||
|||¦  «        }|                     |¦  «         Œ�t          |¦  «        | _        dS )zâ
    If `node` needs to be equalized, find the input/weight observers it needs in
    `equalization_qconfig`, creates them, and inserts it into `graph`.

    If `node` does not need an equalization observer, returns None.
    NzCannot equalize z  because it is part of a branch.é   ©Ú
stacklevel)r   ÚwarningsÚwarnr˜   rU   r   r5   r  r6   rá   Úinput_activationrÖ   rp   )rQ   r#  rÈ   rR   rÉ   r$  r  r`   rz   Úact_eq_process_ctrÚnew_eq_obs_modÚnew_eq_obs_nodes               rN   Ú3_maybe_insert_input_equalization_observers_for_noder/  ¾  s/  € ð Ð#Õ+EØˆmñ,ô ,Ð#ð 	ˆàð ÝŒØE˜tÐEÐEÐEÐRSð	
ñ 	
ô 	
ð 	
ð 	ˆà€HØŒyð )ð )ˆÝ˜#�tÑ$Ô$ð 	Õ(8¸¸sÑ(CÔ(Cð 	Ø�OŠO˜CÑ Ô Ð Øå& t¨SÑ1Ô1ˆ	ð ð7Ð Ô'Ð'à%Ô6ð 	ð ,Ð+Ñ-Ô-ˆÝ+Ø� ¨°uñ
ô 
ˆð 	�Š˜Ñ(Ô(Ð(Ð(õ �h‘”€D„I€I€IrP   c                 óä  — | j         dk    rt          d¦  «        ‚d}d| j        v rt          d¦  «        ‚d| j        vrt          d¦  «        ‚| j        d                              dd¦  «        }| j        d                              d	¦  «        }|r
 |¦   «         nd
}t          |¦  «        \  }	}
d}t          t          j        d|	|
|¦  «        }|
rd}|o| }|r||| <   t          | ||||¦  «        S d
S )a$  
    If `node` needs an output observer, creates it, inserts it into `graph`
    and returns it.

    If `node` does not need an output observer, returns None.

    Note: inserting dynamic quantization ops for output is not supported in fx graph mode
    quantization code path right now
    Úoutputz3observer insertion for outputs is handled elsewhereFrõ   rö   rk   r  ræ   r@   N)
rW   rJ   rr   r÷   rs   r_   rO   rL   rM   rÖ   )rQ   rÈ   rR   rÉ   r“   r›   ré   r@   r�   Útarget_dtypeÚtarget_is_dynamicrE   r  s                rN   Ú&_maybe_insert_output_observer_for_noder4  ð  s_  € ð" „w�(ÒÐÝÐRÑSÔSÐSà ÐØ  D¤IÐ-Ð-Ý!Ø[ñ
ô 
ð 	
ð  $¤)Ð+Ð+ÝÐHÑIÔIÐIØœ9Ð%8Ô9×=Ò=Ø ñô Ðð  $œyÐ)<Ô=×AÒAØ"ñ ô  Ðð '?ÐHÐ Ð Ñ"Ô"Ð"ÀDð õ '@Ð@TÑ&UÔ&UÑ#€LÐ#ð "Ðõ 'ÝŒ�U˜LÐ*;Ð=Rñô €Oð ð  Øˆð &ÐDÐ/CÐ+C€Oàð Ø2ˆ�dÑÝ ØÐ&¨¨}¸eñ
ô 
ð 	
ð ˆtrP   Úgraph_output_nodec           
      ó  ‡‡‡‡‡‡— dt           dt          j        j        dt          t
          t          j        j        f         dt          dt           f
ˆˆˆfd„Šˆˆˆˆfd„| j        D ¦   «         }t          |¦  «        | _        dS )	zž
    If the output needs to be quantized and there are any nodes
    in the output which are not already observed, inserts observers
    for those nodes.
    rÇ   rÈ   rR   rÉ   rG   c                 óÄ  •‡‡‡— t          | t          ¦  «        r�t          | ‰‰‰¦  «        }d}t          j        }d| j        v r4| j        d                              dd¦  «        }|� |¦   «         }|j        }||k    o|t          j        k    }|r&|€t          d¦  «        ‚t          | |‰‰‰¦  «        }	|	S | S t          | t          t          f¦  «        r7ˆˆˆˆfd„| D ¦   «         }
t          | t          ¦  «        r|
S t          |
¦  «        S t          | t          ¦  «        r/i }|                      ¦   «         D ]\  }} ‰|‰‰‰¦  «        ||<   Œ|S | €dS t          d| ¦  «        ‚)a`  
        Navigate an arbitrary data structure of lists, tuples, dicts.
        For each container type, recurse on all inputs. Once any Node
        is found, insert an observer if needed and do not recurse further.

        For example, given a structure of

          {'foo1': [[bar1]], 'foo2': {'foo3': [[[bar3]]]}}

        we recurse down to bar1 and bar3, observe them if necessary,
        and if we inserted an observer then replace the original node
        with its observer.

        Returns the data structure with all nodes needing observation being
        replaced by their observers.
        Nrk   r?   z3observer_mod must not be None when need_obs is Truec                 ó,   •— g | ]} ‰|‰‰‰¦  «        ‘ŒS r°   r°   )rh   Ú
inner_nodeÚ&_recursive_maybe_replace_node_with_obsrÉ   rÈ   rR   s     €€€€rN   ú
<listcomp>zo_maybe_insert_observers_before_graph_output.<locals>._recursive_maybe_replace_node_with_obs.<locals>.<listcomp>‡  sD   ø€ ð ð ð ð ð 7Ð6ØØØ!Øñ	ô ðð ð rP   z!Unhandled type for returned node:)rU   r   r–   rL   rM   rr   rs   r=   rJ   rÖ   ro   rp   Údictr  Ú	Exception)rÇ   rÈ   rR   rÉ   rý   Úobserver_modr  Úobserver_clsÚneed_obsÚobserver_nodeÚresultsÚresults_dictr  Úinner_vr:  r›   r“   s    ```          €€€rN   r:  z[_maybe_insert_observers_before_graph_output.<locals>._recursive_maybe_replace_node_with_obsQ  sð  øøøø€ õ, �j¥$Ñ'Ô'ð 9	å)HØ˜M¨=¸&ñ*ô *Ð&ð  ˆLÝ(-¬Ð%Ø" j¤oÐ5Ð5Ø)œÐ/BÔC×GÒGØ-¨tñ ô  �ð  Ð+Ø#/ <¡>¤>�LØ0<Ô0BÐ-ð +Ð.GÒGð =Ø-µ´Ò<ð ð ð "ØÐ'Ý(ØMñô ð õ !2Ø ¨e°]ÀEñ!ô !�ð %Ð$à!Ð!Ý˜
¥T­5 MÑ2Ô2ð 	ðð ð ð ð ð ð ð #-ðñ ô ˆGõ ˜*¥dÑ+Ô+ð &Ø�å˜W‘~”~Ð%Ý˜
¥DÑ)Ô)ð 	ØˆLØ(×.Ò.Ñ0Ô0ð ð ‘
��7Ø"HÐ"HØ˜U M°5ñ#ô #�˜Q‘�ð  ÐØÐØ�4åØ3°Zñô ð rP   c                 ó,   •— g | ]} ‰|‰‰‰¦  «        ‘ŒS r°   r°   )rh   Úold_argr:  rÉ   rÈ   rR   s     €€€€rN   r;  z?_maybe_insert_observers_before_graph_output.<locals>.<listcomp>¢  s:   ø€ ð ð ð àð 	/Ð.¨w¸¸}ÈeÑTÔTðð ð rP   N)	r   rL   ÚnnÚModuler<  rX   r   r˜   rp   )r5  rÈ   rR   rÉ   r“   r›   r  r:  s    ````` @rN   Ú+_maybe_insert_observers_before_graph_outputrI  C  sÏ   øøøøøø€ ðOÝðOåŒxŒðOõ �C¥¤¤Ð0Ô1ðOõ ð	Oõ
 
ðOð Oð Oð Oð Oð Oð Oð Oðbð ð ð ð ð ð à(Ô-ðñ ô €Hõ
 # 8™_œ_ÐÔÐÐrP   r2  Ú&node_name_to_match_result_with_qconfigc                 ó&  — d| j         d         d<   d| j         d         d<   |                     | j        d¦  «        \  }}}}}|�I|                     ¦   «         r7| j        d         }t          |t          ¦  «        rt          |||¦  «         dS dS dS dS )zÛ
    Assigns `target_dtype` to `node`, setting `is_dynamic` to False. If `node`
    is a general tensor shape op, also call this function recursively on
    the first argument, to propagate the dtype to the caller.
    Nrk   r?   r@   ©NNNNNr   )rr   rs   rÅ   rè   r˜   rU   r   Ú_maybe_propagate_dtype_for_node)	rQ   r2  rJ  Ú
_root_noder�   Ú_patternrØ   Ú_qconfigÚ	prev_nodes	            rN   rM  rM  ª  sÏ   € ð AE€D„IÐ!Ô"Ð#<Ñ=ØAE€D„IÐ!Ô"Ð#=Ñ>ð 	/×2Ò2ØŒ	Ð1ñ	ô 	ñØØ	ØØØð
 Ð × CÒ CÑ EÔ EÐØ”I˜a”Lˆ	Ý�i¥Ñ&Ô&ð 	Ý+Ø˜<Ð)Oñô ð ð ð ð ÐÐÐð	ð 	rP   c           	      óZ  — | j         D ]¢}t          |¦  «        }|D ]Ž} ||         |¦  «        }|D ]x}|j        |         }t          |t          t
          f¦  «        rt          |¦  «        }n|g}|D ]7}	t          |	t          j        j        j	        ¦  «        rt          |	||¦  «         Œ8ŒyŒ�Œ£dS )a  
    Currently we assume that inputs to the graph are either `torch.float` or
    `torch.quint8`, which is not always correct. For ops such as
    `x.masked_fill(mask, value)`, we know that the dtype of  `mask` is a
    `BoolTensor`. Propagate this information throughout the graph.

    Note: not all dtypes in the graph will be correct after this pass, but a
    higher percentage of them will be correct. Hopefully in the future we can
    replace this with a better way to reason about dtypes of tensors.
    N)Únodesr4   r˜   rU   rp   ro   rL   rV   rQ   r   rM  )
rÉ   rJ  rQ   Únon_observable_arg_dictÚarg_typeÚnon_observable_indicesÚindexr`   Úarg_listÚcur_args
             rN   r;   r;   É  së   € ð ”ð ð ˆÝ"JÈ4Ñ"PÔ"PÐà/ð 	ð 	ˆHØ%FÐ%<¸XÔ%FÀtÑ%LÔ%LÐ"à/ð ð �Ø”i Ô&�õ ˜c¥E­4 =Ñ1Ô1ð %Ý# C™yœy�H�Hà #˜u�Hà'ð ð �Gå! '­5¬8¬=Ô+=Ñ>Ô>ð Ý7Ø# XÐ/Uñô ð øððð	ðð rP   c                 ó   — d}t          t          | j        ¦  «        ¦  «        D ]>}t          | j        |         t          t
          t          f¦  «        r| j        |         } nŒ?|€dS t          |t
          t          f¦  «        r	|d         }nt          |t          ¦  «        r|}ndS d}t          ||¦  «        sžt          |t          ¦  «        sdS |j        dk    rdS d}t          t          |j        ¦  «        ¦  «        D ]&}|j        |         }t          |t          ¦  «        r nŒ'|€dS |}|dz  }|dk    rt          d¦  «        ‚t          ||¦  «        ¯žt          |t          ¦  «        st          d¦  «        ‚|j
        }t          |t          ¦  «        st          d	¦  «        ‚||         }	t          |t
          t          f¦  «        r®t          |¦  «        D ]ž\  }
}|
dk    rŒd}t          ||¦  «        sRt          |j        ¦  «        dk     r dS |j        d         }|dz  }|dk    rt          d¦  «        ‚t          ||¦  «        ¯Rt          |j
        ¦  «        \  }}t          ||         ||	¦  «         ŒŸ| j        D ]O}t          ||¦  «        st          d
¦  «        ‚t          |j
        ¦  «        \  }}t          ||         ||	¦  «         ŒPdS )aª  
    Ensures that we share an observer
    for all input arguments as well as the output argument. In detail, given
    a graph of

      x0 -> obs0 -> op -> x2
                  /
      x1 -> obs1 /

    where node obs0 points to observer instance observer0,
    obs1 points to observer1 and obs2 points to observer2, we make nodes obs1
    and ob2 point to observer0.
    Returns: whether the operation succeeded or not
    NFr   r•   r   i'  z(Unable to find observer of previous nodezfirst_arg_arg must be a Nodeztarget_to_use must be a stringú7output_obs_node must be an activation post process nodeT)Úranger—   r˜   rU   r   ro   rp   rZ   rW   rJ   rY   rX   r  r   rÏ   r  )rQ   rÈ   rR   Ú	first_argÚiÚfirst_arg_argÚiteration_guardÚtrace_back_nodeÚtarget_to_useÚobs_mod_to_useÚ	input_idxÚ	input_argÚparent_namerÅ   Úoutput_obs_nodes                  rN   Ú(_maybe_make_input_output_share_observersrh  ï  s<  € ð& €Iå•3�t”y‘>”>Ñ"Ô"ð ð ˆÝ�d”i ”l¥T­4µÐ$7Ñ8Ô8ð 	Øœ	 !œˆIØˆEð	ð
 ÐØˆuå�)�d¥E˜]Ñ+Ô+ð Ø! !œˆˆÝ	�I�tÑ	$Ô	$ð Ø!ˆˆàˆuð
 €Oå.¨}¸mÑLÔLð MÝ˜-­Ñ.Ô.ð 	Ø�5àÔ˜}Ò,Ð,Ø�5àˆÝ•s˜=Ô-Ñ.Ô.Ñ/Ô/ð 	ð 	ˆAØ+Ô0°Ô3ˆOÝ˜/­4Ñ0Ô0ð Ø�ðàÐ"Ø�5Ø'ˆà˜1ÑˆØ˜UÒ"Ð"Ý Ð!KÑLÔLÐLõ% /¨}¸mÑLÔLð Mõ( �m¥TÑ*Ô*ð =ÝÐ;Ñ<Ô<Ð<Ø!Ô(€MÝ�m¥SÑ)Ô)ð ?ÝÐ=Ñ>Ô>Ð>Ø" =Ô1€Nå�)�d¥E˜]Ñ+Ô+ð Få$-¨iÑ$8Ô$8ð 	Fð 	FÑ ˆI�yØ˜AŠ~ˆ~ØØˆOå6°yÀ-ÑPÔPð 	Uõ �y”~Ñ&Ô&¨Ò*Ð*Ø ˜5˜5à%œN¨1Ô-�	Ø 1Ñ$�Ø" UÒ*Ð*Ý(Ð)SÑTÔTÐTõ 7°yÀ-ÑPÔPð 	Uõ !-¨YÔ-=Ñ >Ô >ÑˆK˜Ý�M +Ô.°°nÑEÔEÐEÐEð  œ:ð Bð BˆÝ/°ÀÑOÔOð 	Ý ØIñô ð õ )¨Ô)?Ñ@Ô@Ñˆ�TÝ�˜kÔ*¨D°.ÑAÔAÐAÐAð ˆ4rP   c                 óþ   — t          | j                             ¦   «         ¦  «        }|D ]S\  }}t          ||¦  «        st	          d¦  «        ‚|                     | ¦  «         |j                             |¦  «         ŒTd S )Nr[  )ro   r  r  rZ   rJ   Úreplace_all_uses_withrÉ   Ú
erase_node)rQ   rÈ   rR   r  rg  r�   s         rN   Ú_remove_output_observerrl  W  s“   € õ �”×!Ò!Ñ#Ô#Ñ$Ô$€EØ#ð 0ð 0Ñˆ˜Ý/°ÀÑOÔOð 	Ý ØIñô ð ð 	×-Ò-¨dÑ3Ô3Ð3ØŒ×Ò˜Ñ/Ô/Ð/Ð/ð0ð 0rP   c                 óÖ   — || j                  }|j        }t          |||¦  «        }|                     |¦  «        }t	          | j         ¦  «        \  }}	t          ||         |	|¦  «         d S rf   )rY   Úfloat_to_observed_mappingr   Ú
from_floatr   rÏ   )
rQ   ra   rR   r¬   Úcustom_moduleÚcustom_module_class_mappingÚobserved_custom_module_classÚobserved_custom_modulerf  rÅ   s
             rN   Ú_swap_custom_module_to_observedrt  d  sy   € ð " $¤+Ô.€MØ"7Ô"QÐÝ#BØÐ2°Gñ$ô $Ð ð :×DÒDÀ]ÑSÔSÐÝ$ T¤[Ñ1Ô1Ñ€K�ÝˆM˜+Ô&¨Ð.DÑEÔEÐEÐEÐErP   Únode_name_to_qconfigÚequalization_config_mapÚobserved_node_namesc                 óÊ  — i }t          |                      d¬¦  «        ¦  «        }	|j        }
|j        }t	          ¦   «         }| j        j        D ]#}t          j        t          ¦  «        |j	        d<   Œ$d}d}i }i }| j        j        D ],}|j
        dk    r
|||<   |dz  }|j
        dk    r
|||<   |dz  }Œ-|                     ¦   «         D ]1}|\  }}}}}|€t          d	¦  «        ‚t          ||||||	||¦  «         Œ2| j        j        D ]™}|j
        dk    r,||         |
v r"t          j        t          ¦  «        |j	        d<   Œ9|j
        d
v r!t          ||	|¦  «        }|rdddœ|j	        d<   Œc|j
        dk    r+||         |v r!t          j        t          ¦  «        |j	        d<   Œšt!          | j        |¦  «         t	          ¦   «         }|                     ¦   «         D ]­}|\  }}}}}t#          ||||¦  «        }|€t          d	¦  «        ‚|j	        d         d         }|r
 |¦   «         nd}t%          |¦  «        \  }}|sK|dt&          t(          t*          j        fvr/t          ||t*          j        j        j        j        d||	||¦  «         Œ®t7          | j        j        ¦  «        }t	          ¦   «         }d}d}d} i }!t9          | ¦  «        }"|D �]}|j
        dk    r�né|j
        dv �rß|                     |j        d¦  «        \  }}}}}|                     |j        ¦  «        }#|j	        d         }$d|j	        v r%|$duot?          |j	        d         t@          ¦  «        }%n|$du}%|du p|% o
|j
        dk    }&t#          ||||¦  «        }|&�s>|�r;t          |                      d¬¦  «        ¦  «        }	|j
        dk    �ró|€t          d¦  «        ‚tC          ||¦  «         d}'tE          |j#        ¦  «        dk    r¶t?          |j#        d         tH          ¦  «        r–tE          |j#        d         j%        ¦  «        dk    rs|j#        d         j%        D ]`}(|                     |(j        ¦  «        dup7|(j
        dk    o,t?          |	tM          |(j'        ¦  «                 tP          ¦  «        })|(|k    r|)rd}'ŒatS          |¦  «        }*|*                     |tT          ¦  «        }+ |+|¦  «        },||,u }-|-r7tW          ||| |	| j        |||!|||"¦  «         tY          ||#| |	| j        |'¦  «         ||u }.|j	        d                              dd¦  «        }/|j	        d                              dd¦  «        }0|.�rFt[          ||	||¦  «        rNt]          || |	| j        ¦  «         |j'        |vr,| /                    |j'        ¦  «         ta          |||	|¦  «         �n tc          || |	| j        |!|¦  «        }1|1�Ët7          |j%         2                    ¦   «         ¦  «        }2|2D ]}3|3|1u rŒ|3 3                    ||1¦  «         Œti          ||	|!|¦  «        }4|/r|4s|0r"tk          || |	¦  «        stm          || |	¦  «         |�I| 7                    ¦   «         r5|j'        |vr,| /                    |j'        ¦  «         ta          |||	|¦  «         ntq          || |	| j        |!|¦  «         |j
        dk    r|dz  }�Œ|j
        dk    r|dz  }|} �Œ| S )a$  
    Inserts observers, using the following high level algorithm:

    For each node in the graph:
      1. determine the target dtype of this node in the quantized graph, and save
           it for future steps
      2. determine the target dtype or all args and kwargs of this node
      3. if any arg or kwarg's target dtype does not match the current node's
           dtype, insert an observer
      4. if the current node needs an output observer, insert it

    For example:

    - starting graph:
        x0 -> linear -> x1

    - observed graph after processing x0:
        x0(fp32)

    - observed graph after processing linear:
        x0(fp32) -> x0_obs0(int8) -> linear(int8) -> linear_obs0(int8)

    - observed graph after processing x1:
        x0(fp32) -> x0_obs0(int8) -> linear(int8) -> linear_obs0(int8) -> x1

    After a node is processed, the naive observer placement is guaranteed to be
    complete for that node and all of its predecessors. There can be future
    passes which optimize the graph by deduplicating observers, etc.
    F©Úremove_duplicaterk   r   r•   r   r1  Nzqhandler must not be None)rT   Úcall_methodrà   r>   r@   )rT   r{  rà   r1  rL  Úvalz%matched_node_pattern must not be NonerT   Trå   rE   )9r<  rR   r  Úoutput_quantized_indexesÚsetrÉ   rS  rî   rï   rr   rW   r¢   rJ   rÜ   Ú-_DEFAULT_QUINT8_QCONFIG_FOR_TARGET_DTYPE_INFOr0   r;   r«   r_   ÚintrM   rL   ru   ÚaoÚquantizationra   Ú!_default_fp32_placeholder_qconfigro   r1   rs   rÅ   rU   r   rÆ   r—   r˜   r   r  rX   rY   r   r   r)   r"  r/  r-   r,   rÄ   rt  r4  ÚkeysÚreplace_input_withr�   rh  rl  Úis_custom_modulerI  )5rÈ   rJ  ru  r¬   rv  rc   rw  r›   rÙ   rR   Úinput_quantized_idxsÚoutput_quantized_idxsrÚ   rQ   Úinputs_seen_counterÚoutputs_seen_counterÚplaceholder_node_to_input_indexÚoutput_node_to_output_indexÚmatch_res_with_qconfigr×   rŸ   rž   rØ   ra   rð   Úis_supported_by_backendÚoutput_act_or_fq_ctrÚoutput_act_or_fqÚoutput_act_dtyper�   Únodes_before_observationÚ#custom_module_names_already_swappedÚresults_noder“   rÊ   r#  Úthis_node_dtype_infoÚoutput_is_a_tensorÚskip_inserting_observersÚis_quantized_branchÚuserÚis_user_quantizedr¥   r¦   r§   Úis_input_node_of_the_patternÚis_last_node_of_patternrå   rE   Úmaybe_output_obs_nodeÚ
orig_usersÚ	user_nodeÚ_is_observer_in_same_graph_s5                                                        rN   r9   r9   t  s¤	  € ðx 35Ðõ ˜×,Ò,¸eÐ,ÑDÔDÑEÔE€Mà&;Ô&SÐØ'<Ô'UÐÝ!$¡¤€Oà”Ô!ð 
ð 
ˆÝ)-¬Ý7ñ*
ô *
ˆŒ	Ð%Ñ&Ð&ð ÐØÐØ79Ð#ð 46ÐØ”Ô!ð &ð &ˆØŒ7�mÒ#Ð#Ø4GÐ+¨DÑ1Ø 1Ñ$ÐØŒ7�hÒÐØ0DÐ'¨Ñ-Ø  AÑ%Ð øð
 #I×"OÒ"OÑ"QÔ"Qð 
ð 
Ðð #ñ	
ØØ ØØØàÐÝ Ð!<Ñ=Ô=Ð=Ý7Ø ØØØØØØ%Øñ		
ô 		
ð 		
ð 		
ð  ”Ô!ð !ð !ˆàŒG�}Ò$Ð$Ø/°Ô5Ð9MÐMÐMõ .2¬YÝ=ñ.ô .ˆDŒIÐ)Ñ*Ð*ð ŒWÐGÐGÐGÝ#@Ø�mÐ%>ñ$ô $Ð ð $ð à/3Ø04ð2ð 2�”	Ð-Ñ.øð
 ŒG�xÒÐØ+¨DÔ1Ð5JÐJÐJõ .2¬YÝ=ñ.ô .ˆDŒIÐ)Ñ*øõ %ØŒÐ;ñô ð õ "%¡¤€OØ"H×"OÒ"OÑ"QÔ"Qð (ð (Ðð #ñ	
ØØ ØØØõ FØÐ-¨w¸ñô ð 	 ð
 ÐÝ Ð!<Ñ=Ô=Ð=ð
  $œyÐ)<Ô=Ø&ô 
Ðð 6JÐSÐ/Ð/Ñ1Ô1Ð1ÈtÐÝ7Ð8HÑIÔIÑÐ˜!Ø&ð 	Ð+;ØÝÝÝŒJð	D
ð ,
ð ,
õ <Ø$ØÝ”Ô%Ô-ÔOØØØØ)Øñ	ô 	ð 	øõ$  $ E¤KÔ$5Ñ6Ô6Ðõ 58±E´EÐ'ð ÐØÐØ€LØ>@€MÝ/°Ñ6Ô6€Lð )ð G ñ G ˆØŒ7�mÒ#Ð#ñ àŒWÐQÐQÑQð 7×:Ò:Ø”	Ð9ñô ñØØ$ØØØð $;×#>Ò#>¸t¼yÑ#IÔ#IÐ à#'¤9Ð-@Ô#AÐ Ø˜œ	Ð!Ð!Ø%9ÀÐ%Eð &Í*Ø”I˜eÔ$¥jñKô KÐ"Ð"ð &:ÀÐ%EÐ"ð ˜D�Ð;Ð);Ð%;ð((à”7˜hÒ&ð %õ JØÐ1°7¸Nñô ð $ð ,ñ PÐ0Gñ PÝ $ U×%8Ò%8È%Ð%8Ñ%PÔ%PÑ QÔ Q�Ø”7˜hÒ&Ñ&Ø+Ð3Ý,Ð-TÑUÔUÐUå1Ø,Ð.Añô ð ð +0Ð'å˜DœI™œ¨Ò*Ð*Ý& t¤y°¤|µTÑ:Ô:ð +å ¤	¨!¤Ô 2Ñ3Ô3°aÒ7Ð7à$(¤I¨a¤LÔ$6ð ;ð ;˜Dà0D×0HÒ0HØ $¤	ñ1ô 1à%)ð1*ð 1ð !%¤¨=Ò 8ð !"Ý$.Ø$1µ#°d´kÑ2BÔ2BÔ$CÅ\ñ%"ô %"ð	 .ð  $ tš|˜|Ð0A˜|Ø6:Ð 3øõ ?¸~ÑNÔNð 0ð (C×'FÒ'FØÕ!:ñ(ô (Ð$ð !1Ð 0Ð1EÑ FÔ F�IØ37¸9Ð3DÐ0Ø3ð å>Ø Ø#Ø!Ø)Ø!œKØ$Ø1Ø)Ø"Ø*Ø(ñô ð õ LØ Ø0Ø!Ø)Ø!œKØ/ñô ð ð /3°iÐ.?Ð+Ø37´9Ð=PÔ3Q×3UÒ3UØ6¸ñ4ô 4Ð0ð -1¬IÐ6IÔ,J×,NÒ,NØ/°ñ-ô -Ð)ð /ñ z*Ý1à Ø)Ø#Ø$ñô ð y*õ$ Pà $Ø %Ø -Ø %¤ñô ð ð  $œ{Ð2UÐUÐUà C× GÒ GÈÌÑ TÔ TÐ TÝ ?à$(Ø$+Ø$1Ø$9ñ!"ô !"ð !"ùõ !Gà$(Ø$)Ø$1Ø$)¤KØ$1Ø$*ñ!"ô !"ð 2ð  5Ð@õ" .2°$´*·/²/Ñ2CÔ2CÑ-DÔ-D 
Ø1;ð !&ð !& IØ'0Ð4IÐ'IÐ'IØ(0Ø$-×$@Ò$@Ø(,Ð.Cñ%&ô %&ð %&ð %&õ
 %?à(,Ø(5Ø(5Ø(.ñ%&ô %&ð !<ð %Að!*à(Cð!*ð &;ð!*õ ,Tà(,Ø(-Ø(5ñ	,&ô ,&ð %*õ )@à,0Ø,1Ø,9ñ	)*ô )*ð )*ð $,Ð#7¸H×<UÒ<UÑ<WÔ<WÐ#7ð )-¬Ø/Rð)Sð )Sð )L×(OÒ(Oà,0¬Kñ)*ô )*ð )*õ )Hà,0Ø,3Ø,9Ø,Añ)*ô )*ð )*øõ @Ø˜e ]°E´KÀÐPVñô ð ð Œ7�mÒ#Ð#Ø 1Ñ$ÐÑØŒW˜Ò Ð Ø  AÑ%Ð ØˆLùàÐrP   c           	      ó‚  — |                      ¦   «         D ]©\  }}}}	}
|	€Œ|	                     ¦   «         sŒ t          ||||
|¦  «        \  }}}}||j                 }t          j        j        j        j        } |||||||¬¦  «        }t          |j        ¦  «        \  }}t          ||         ||¦  «         |||j        <   ŒªdS )z¨
    Runs prepare_fx on each standalone module. Note: this does
    not modify the graph, it just replaces the unobserved modules with
    their observed versions.
    N)r¶   r¬   rc   )r¢   ré   rº   rY   rL   r�  r‚  Úquantize_fxÚ_prepare_standalone_module_fxr   rÏ   )rÈ   r›   rR   rJ  r¬   rc   r§   r�   rO  rØ   ra   Úsm_qconfig_mappingÚsm_example_inputsr  Úsm_backend_configÚstandalone_moduler:   Úobserved_standalone_modulerf  rÅ   s                       rN   Ú%_run_prepare_fx_on_standalone_modulesr©  g  s  € ð& 
0×	6Ò	6Ñ	8Ô	8ð!Eð !Eñ 	ØØ	ØØØàÐØØ×.Ò.Ñ0Ô0ð 	Øõ +Ø�}Ð&;¸WÀnñ
ô 
ñ	
ØØØ$Øð
 *¨)Ô*:Ô;ÐÝ”(Ô'Ô3ÔQˆØ%, WØØØØ,Ø":Ø,ð&
ñ &
ô &
Ð"õ )¨Ô)9Ñ:Ô:Ñˆ�TÝ�˜kÔ*¨DÐ2LÑMÔMÐMØ*Dˆ�iÔ&Ñ'Ð'ðC!Eð !ErP   ÚobservedÚnode_name_to_scopeÚ!equalization_node_name_to_qconfigr´   c           	      óB   — t          |||||||¬¦  «        | j        d<   d S )N)ru  r«  r¬   r¬  r´   r›   rw  Ú_observed_graph_module_attrs)r8   rr   )rª  ru  r«  r¬   r¬  r´   r›   rw  s           rN   Ú_save_stater¯  ˜  s<   € õ 5MØ1Ø-Ø3Ø*KØ'ØØ/ð5ñ 5ô 5€H„MÐ0Ñ1Ð1Ð1rP   r¶   Ú_equalization_configré   c	           
      ór  — |€t          ¦   «         }|€t          ¦   «         }t          |t          ¦  «        r0t	          j        dt          d¬¦  «         t          j        |¦  «        }t          |t          ¦  «        r0t	          j        dt          d¬¦  «         t          j        |¦  «        }t          |t          ¦  «        r0t	          j        dt          d¬¦  «         t          j        |¦  «        }t          |t          ¦  «        r0t	          j        dt          d¬¦  «         t          j        |¦  «        }t          |t          ¦  «        st          d¦  «        ‚t          |t          ¦  «        st          d	¦  «        ‚t          j        |¦  «        }t          j        |¦  «        }i }	|€t          ¦   «         }t          |¦  «        }	t          |	¦  «        }	t          |¦  «        }
t!          | |¦  «         t!          | |¦  «         t#          |¦  «        }t%          | ||                     ¦   «         ¦  «         |r/t)          |¦  «        }t+          | |¦  «         t-          ||¦  «         t          |                      d
¬¦  «        ¦  «        }t1          | || j        ||¦  «        }t1          | || j        ||¦  «        }t5          |j                             ¦   «         ¦  «        }t5          |j                             ¦   «         ¦  «        }t=          |j        ¦  «        }tA          | j        ||	|
|||¦  «        }i }| !                    ¦   «         D ]\  }}g |¢||         ‘R }|||<   ŒtE          | |||||¦  «         tG          ¦   «         }tI          | |||||||¦  «        }tK          | | j        ¦  «        } tM          | |||||||¦  «         |rp|€t          d¦  «        ‚t          |j'        d         tP          ¦  «        st          d¦  «        ‚|j)        }|j*        }| j+        d         }d|_,        ||_-        ||_.        | S )a:  standalone_module means it a submodule that is not inlined in
    parent module, and will be quantized separately as one unit.

    How the standalone module is observed is specified by `input_quantized_idxs` and
    `output_quantized_idxs` in the prepare_custom_config for the standalone module
    Args:
        node_name_to_scope: mapping from node name to the scope of the module which contains the node.
        The scope is a tuple of fully qualified path of the module and the type of the module
    Returns:
        model(GraphModule): prepared standalone module
        attributes related to standalone module
        in model.meta["_observed_graph_module_attrs"]:
            is_observed_standalone_module (bool): boolean value that shows whether the
            current model is a observed standalone module or not
            standalone_module_input_quantized_idxs(List[Int]): a list of
                indexes for the graph input that is expected to be quantized,
                same as input_quantized_idxs configuration provided
                for the standalone module
            standalone_module_output_quantized_idxs(List[Int]): a list of
                indices for the graph output that is quantized
                same as input_quantized_idxs configuration provided
                for the standalone module
    Nz�Passing a QConfig dictionary to prepare is deprecated and will not be supported in a future version. Please pass in a QConfigMapping instead.r&  r'  zžPassing a QConfig dictionary to prepare for equalization is deprecated and will not be supported in a future version. Please pass in a QConfigMapping instead.zšPassing a prepare_custom_config_dict to prepare is deprecated and will not be supported in a future version. Please pass in a PrepareCustomConfig instead.z�Passing a backend_config_dict to prepare is deprecated and will not be supported in a future version. Please pass in a BackendConfig instead.z(qconfig_mapping must be a QConfigMappingz-_equalization_config must be a QConfigMappingFry  z3result_node must not be None for standalone modulesr   zWstandalone module only supports returning simple value currently (not tuple, dict etc.)r®  T)/r    r   rU   r<  r)  r*  ÚFutureWarningÚ	from_dictr   rJ   rî   Údeepcopyr
   r*   r$   r   r'   r&   r   Úto_dictr   rÁ   r(   rR   r%   rÉ   ro   r³   r„  r²   r2   rn  r"   r  r©  r~  r9   r   r¯  r˜   r   r  r}  rr   Úis_observed_standalone_moduleÚ&standalone_module_input_quantized_idxsÚ'standalone_module_output_quantized_idxs)rÈ   r´   r›   r«  r¶   r¬   r°  rc   ré   Úpattern_to_quantize_handlerÚroot_node_getter_mappingÚflattened_qconfig_dictr¼   rR   r¬  ru  r³   r²   Úcustom_module_classesÚmatches_without_qconfigrJ  Ú	node_nameÚmatch_without_qconfigÚmatch_with_qconfigrw  Úresult_noder‡  rˆ  Úobserved_graph_module_attrss                                rN   r:   r:   ­  sù  € ðD Ð$Ý 3Ñ 5Ô 5ÐØÐ#Ý-Ñ/Ô/Ðå�/¥4Ñ(Ô(ð DÝŒðLåØð		
ñ 	
ô 	
ð 	
õ )Ô2°?ÑCÔCˆåÐ&­Ñ-Ô-ð NÝŒðYåØð		
ñ 	
ô 	
ð 	
õ  .Ô7Ð8LÑMÔMÐåÐ'­Ñ.Ô.ð UÝŒðQåØð		
ñ 	
ô 	
ð 	
õ !4Ô =Ð>SÑ TÔ TÐå�.¥$Ñ'Ô'ð AÝŒðKåØð		
ñ 	
ô 	
ð 	
õ 'Ô0°Ñ@Ô@ˆå�o¥~Ñ6Ô6ð IÝÐGÑHÔHÐHÝÐ*­NÑ;Ô;ð NÝÐLÑMÔMÐMÝ”m OÑ4Ô4€OÝœ=Ð)=Ñ>Ô>Ðð CEÐØÐÝ2Ñ4Ô4ˆÝ"CÀNÑ"SÔ"SÐÝ"7Ð8SÑ"TÔ"TÐåEÀnÑUÔUÐõ ˜u oÑ6Ô6Ð6å˜uÐ&:Ñ;Ô;Ð;å8¸ÑIÔIÐå�uÐ4Ð6K×6SÒ6SÑ6UÔ6UÑVÔVÐVàð AÝ7¸ÑGÔGÐÝ˜%Ð!5Ñ6Ô6Ð6å °Ñ@Ô@Ð@õ ˜×,Ò,¸eÐ,ÑDÔDÑEÔE€Mõ )GØØØŒàØñ)ô )Ð%õ :ØØØŒàØñô Ðõ #Ð#8Ô#P×#UÒ#UÑ#WÔ#WÑXÔXÐÝ $ØÔ7×<Ò<Ñ>Ô>ñ!ô !Ðõ 9ØÔ7ñô Ðõ ,ØŒØØ#Ø ØØ!Øñô Ðð .0Ð*Ø,C×,IÒ,IÑ,KÔ,Kð Oð OÑ(ˆ	Ð(ØVÐ4ÐVÐ6JÈ9Ô6UÐVÐVÐØ<NÐ.¨yÑ9Ð9å)ØØØØ.ØØñô ð õ %(¡E¤EÐå,ØØ.ØØØ)ØØØñ	ô 	€Kõ ˜˜uœ{Ñ+Ô+€EåØØØØØ)àØØñ
ô 
ð 
ð ð 
ØÐÝ Ð!VÑWÔWÐWÝ˜+Ô*¨1Ô-­tÑ4Ô4ð 	Ý Øiñô ð ð +@Ô*WÐà!Ô:ð 	ð ',¤jÐ1OÔ&PÐ#àDHÐ#ÔAà ð 	$ÔJð "ð 	$ÔKð €LrP   )Frf   )NN)NNNF)�rî   r)  Útypingr   rL   Útorch._subclassesr   Útorch.ao.quantizationr   r   r   Ú$torch.ao.quantization.backend_configr   r	   r
   Ú*torch.ao.quantization.backend_config.utilsr   r   r   Útorch.ao.quantization.observerr   Útorch.ao.quantization.qconfigr   r   Ú%torch.ao.quantization.qconfig_mappingr   Útorch.ao.quantization.quantizer   r   Útorch.ao.quantization.utilsr   r   r   r   r   Útorch.fxr   Útorch.fx.graphr   r   Útorch.fx.noder   Ú	_equalizer   r   Úcustom_configr    r!   Úmatch_utilsr"   r#   Úpattern_utilsr$   Úqconfig_mapping_utilsr%   r&   r'   r(   Úquantize_handlerr)   r*   r+   Úutilsr,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   Ú__all__r€  rM   ru   rK   r™   Úqint8Úqint32rç   rš   Úint8Úint16Úint32Úfloat8_e5m2Úfloat8_e4m3fnrI   rí   rŠ   r�  r‚  ra   rƒ  rì   rï   Ú#_default_quint8_placeholder_qconfigr  rO   r<  rX   rG  rH  rZ   rp   r=   r_   rg   r‘   r’   Ú
EdgeOrNoder�   ro   r«   rº   r±   rÁ   r~  rÆ   ÚdevicerÖ   rÜ   rÝ   rú   r–   r   r  r"  r/  r4  rI  rM  r;   rh  rl  rt  r9   r©  r¯  r:   r°   rP   rN   ú<module>râ     s%  ðà €€€Ø €€€Ø Ð Ð Ð Ð Ð à €€€Ø (Ð (Ð (Ð (Ð (Ð (ðð ð ð ð ð ð ð ð ð ð
ð ð ð ð ð ð ð ð ð ð
ð ð ð ð ð ð ð ð ð ð
 GÐ FÐ FÐ FÐ FÐ FØ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MØ @Ð @Ð @Ð @Ð @Ð @Ø FÐ FÐ FÐ FÐ FÐ FÐ FÐ Fðð ð ð ð ð ð ð ð ð ð ð ð ð ð !Ð  Ð  Ð  Ð  Ð  Ø &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ø "Ð "Ð "Ð "Ð "Ð "à KÐ KÐ KÐ KÐ KÐ KÐ KÐ KØ KÐ KÐ KÐ KÐ KÐ KÐ KÐ KØ ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0ðð ð ð ð ð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð ð ð
ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð"ð ð €ð ˜u e¤j°$Ð7Ð à	„LØ	„KØ	„LØ	„MØ	„KØ	„JØ	„KØ	„KØ	ÔØ	Ôð€ð <Ð1Ô;À%Ä+ÐNÑNÔNÐ ð
  %œxÔ4Ô<Ô^ÔiØ %¤Ô 5Ô =Ô _Ô jð/ð /Ð +ð  %œxÔ4Ô<Ô`ÔkØ %¤Ô 5Ô =Ô aÔ lð1ð 1Ð -ð  ð*ð *Øð*à ð*ð ð*ð  ð	*ð
  ð*ð ð*ð 
ð*ð *ð *ð *ðZØ
ðØ# C¨¬¬Ð$8Ô9ðà	ðð ð ð ð
HØ%¨Ñ,ð
Hà
ˆ5Œ;˜Ñ˜tÐ#Ô$ð
Hð 
Hð 
Hð 
HðH
Ø	ðH
à
ðH
ð ðH
ð ð	H
ð
 "ðH
ð 
ðH
ð H
ð H
ð H
ðV"Ø
ð"àð"ð ð"ð 
ð	"ð "ð "ð "ðJ Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð ð �u˜T 4˜ZÔ(¨4Ñ/°Ð5Ô6€
ðØ
ðà˜˜UœXœ_Ð,Ô-ðð ˜
Ð$:Ð:Ô;ðð ð ð ð.%Ø�t‰^ð%à˜tœ* tÑ+ð%ð ð%ð "ð	%ð
 
ð%ð %ð %ð %ðPTØ
ðTà˜˜UœXœ_Ð,Ô-ðTð /ðTð ð	Tð
 )¨4Ñ/ðTð ˆ>˜5  c œ?Ð,?ÀÐQUÑAUÐUÔVðTð Tð Tð Tð@TØ
Œ(Œ/ðTØ15°g¸tÀEÄHÄOÔ?TÐ6TÔ1UðTà	ðTð Tð Tð Tð9¸ð 9ÈÈCÌð 9ð 9ð 9ð 9ð )-ðð Ø
ðà%ðð Œ8Œ?ðð ˜˜UœXœ_Ð,Ô-ð	ð
 ðð ”, Ñ%ðð 
ðð ð ð ð@5;Ø%ð5;àð5;ð ð5;ð  Ñ$ð	5;ð
 "ð5;ð ˜˜UœXœ_Ð,Ô-ð5;ð  $ D¨$ JÔ/ð5;ð ˜”Yð5;ð 
ð5;ð 5;ð 5;ð 5;ðpbBØ
ðbBàðbBð  Ñ$ðbBð ˜˜UœXœ_Ð,Ô-ð	bBð
 "ðbBð  $ D¨$ JÔ/ðbBð 
ˆ#ˆsˆ(„^ðbBð bBð bBð bBðJB Ø	ðB à˜˜UœXœ_Ð,Ô-ðB ð ˜
Ð$:Ð:Ô;ðB ð ð	B ð
 ˜dÑ"ðB ð B ð B ð B ðJ&Ø	ð&à˜˜UœXœ_Ð,Ô-ð&ð ˜
Ð$:Ð:Ô;ð&ð ð	&ð
 „[�4Ñð&ð &ð &ð &ð%6Ø	ð%6à
ð%6ð ˜˜UœXœ_Ð,Ô-ð%6ð ˜
Ð$:Ð:Ô;ð	%6ð
 ð%6ð ˜dÑ"ð%6ð %6ð %6ð %6ðf ,0Ø(,ðhð hØ
�‰*ðhà	ðhð ðhð Œ8Œ?ð	hð
 ˜˜UœXœ_Ð,Ô-ðhð ðhð  Ñ$ðhð /ðhð ˜
Ð$:Ð:Ô;ðhð ðhð " DÑ(ðhð ”, Ñ%ðhð ðhð hð hð hðj ,0Ø(,ðCð CØ
ðCàðCð Œ8Œ?ðCð ˜˜UœXœ_Ð,Ô-ð	Cð
 ðCð  Ñ$ðCð /ðCð ˜
Ð$:Ð:Ô;ðCð ðCð " DÑ(ðCð ”, Ñ%ðCð 
ðCð Cð Cð CðL/ Ø
ð/ àð/ ð Œ8Œ?ð/ ð ˜˜UœXœ_Ð,Ô-ð	/ ð
 ð/ ð ð/ ð 
ð/ ð / ð / ð / ðdPØ
ðPàŒ8Œ?ðPð ˜˜UœXœ_Ð,Ô-ðPð ð	Pð
 ˜
Ð$:Ð:Ô;ðPð ðPð 
ˆD�[ðPð Pð Pð Pðfd-Øðd-àŒ8Œ?ðd-ð ˜˜UœXœ_Ð,Ô-ðd-ð ð	d-ð
 ˜
Ð$:Ð:Ô;ðd-ð ðd-ð 
ðd-ð d-ð d-ð d-ðNØ
ðà”+ Ñ$ðð -1°Ð6MÐ1MÔ,Nðð 
ð	ð ð ð ð>#Øð#à,0°Ð6MÐ1MÔ,Nð#ð 
ð#ð #ð #ð #ðLeØ
ðeàŒ8Œ?ðeð ˜˜UœXœ_Ð,Ô-ðeð 
ð	eð eð eð eðP
0Ø
ð
0Ø”x”ð
0Ø7;¸CÀÄÄÐ<PÔ7Qð
0ð 
0ð 
0ð 
0ðFØ
ðFàðFð ˜˜UœXœ_Ð,Ô-ðFð /ð	Fð Fð Fð Fð pØðpà,0°Ð6MÐ1MÔ,Nðpð ˜s J˜Ô/ðpð /ð	pð
 " # s (œ^ðpð "ðpð ˜Sœðpð ðpð 
ˆD�[ðpð pð pð pðf.EØŒ8Œ?ð.Eàð.Eð ˜˜UœXœ_Ð,Ô-ð.Eð -0ð	.Eð
 /ð.Eð "ð.Eð 
ð.Eð .Eð .Eð .EðbØðà˜s J˜Ô/ðð ˜S %¨¨T¨	Ô"2Ð2Ô3ðð /ð	ð
 (,¨C°¨H¤~ðð $ðð ðð ˜Sœðð 
ðð ð ð ð6 JNØCGØ<@Ø!&ðeð eØðeà# d¨3°¨8¤nÑ4ðeð ðeð ˜S %¨¨T¨	Ô"2Ð2Ô3ð	eð
 ˜#˜s˜(”Oðeð /°°c¸3°h´Ñ?À$ÑFðeð )¨4°°S°¬>Ñ9¸DÑ@ðeð " D¨¨c¨¤NÑ2°TÑ9ðeð ðeð ðeð eð eð eð eð erP   