/usr/local/lib64/python3.6/site-packages/torch/quantization/fx/__pycache__
NameSizeModeActions
convert.cpython-36.pyc130810644editdlrm
fuse.cpython-36.pyc25980644editdlrm
fusion_patterns.cpython-36.pyc49420644editdlrm
graph_module.cpython-36.pyc55130644editdlrm
lower_to_fbgemm.cpython-36.pyc5060644editdlrm
lower_to_qnnpack.cpython-36.pyc5090644editdlrm
match_utils.cpython-36.pyc43240644editdlrm
pattern_utils.cpython-36.pyc17540644editdlrm
prepare.cpython-36.pyc259380644editdlrm
qconfig_utils.cpython-36.pyc73400644editdlrm
quantization_patterns.cpython-36.pyc453210644editdlrm
quantization_types.cpython-36.pyc3150644editdlrm
quantized_fusion_patterns_and_replacements.cpython-36.pyc12480644editdlrm
utils.cpython-36.pyc146600644editdlrm
_equalize.cpython-36.pyc249460644editdlrm
_lower_to_native_backend.cpython-36.pyc9260644editdlrm
__init__.cpython-36.pyc3800644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/quantization/fx/__pycache__/utils.cpython-36.pyc (14660B)
3 EgP@sddlZddlZddljZddlmZmZddlmZddl m Z m Z ddl m Z mZddlmZmZmZmZmZmZmZmZmZddlZejjjdgejjjdgejjjdgejjjdgejjjdgejjj dgejjj!d giZ"ejjjejjj ejjj!hZ#ejjjejjjejjj ejjj!hZ$d d Z%d@e&d ddZ'ddZ(eee&eee&fee&effdddZ)eejj*eee&ejj*fe ee&ee&e+ffe,edddZ-eed ddZ.ddZ/eedddZ0ee,edd d!Z1e&ed"d#d$Z2eeeed%d&d'Z3e eee d(d)d*Z4ejj*ed+d,d-Z5ejj*e e&eed.d/d0Z6e&eeee&ejj*fe ee&ee&e+ffeeefd1d2d3Z7eee&ejj*feee,fe,d4d5d6Z8ee,d%d7d8Z9eee:d%d9d:Z;ee,d%d;d<Zd?Z=dS)BN) is_per_tensoris_per_channel)is_activation_post_process) GraphModulemap_arg)GraphNode) CallableOptionalListDictAnySetTupleUnionTypecCs8|jdd}t|dkr$d|dfS|d|dfSdS)N.rr)rsplitlen)targetrrG/usr/local/lib64/python3.6/site-packages/torch/quantization/fx/utils.py _parent_name&s   rT)returncCstjd}tjd}dddddd}i}d}x|D]}t|||<q2Wg}x|jD] } t| j} |rt| jdd} t| j} |r| |kr|| } t| j} |r|j | } | rd| j dd} |j | }|rd|j dd} | jdd} t| j }|r|jdd}t| j }x8t || | | ||fD] \}}t||t|||<q(W|j| | | ||gqTWd}d}||j||7}x|D]}||j||7}qW|r|d7}|S)zyReturns a printable representation of the ops in the graph of g. If shorten is True, tries to abbreviate fields. zz ZplchdrZgt_prmZcl_funZcl_modZcl_meth) placeholderget_attr call_function call_module call_methodnameoprargskwargsactivation_post_processZobszz t|jstd|j\}}t|}t|}|j}|||fS)Nz)Only per tensor quantization is supported)rqschemeAssertionErrorcalculate_qparamsfloatintdtype)r(scale zero_pointrErrrget_per_tensor_qparamsos  rH)r(rcCs|j}d}|tjtjgkrxd}|j\}}t|jrTt|j}||||d}tj }qt |}t|}|||d}tj }n,|tj krd}d}d|i}nt dt||dk st|||fS) z Given an activation_post_process module, return node_type(e.g. call_function), quantize op(e.g. quantize_per_tensor) and a dictionary of extracted qparams from the module Nr!)_scale_ _zero_point_Z_axis__dtype_)rIrJrKr#ZtorKz,Unsupported dtype in get_quantize_node_info:)rEtorchZquint8qint8rBrr@rDch_axisZquantize_per_channelrCZquantize_per_tensorfloat16 Exceptionr-rA)r(rE quantize_op node_typerFrGrNqparamsrrrget_quantize_node_infows(       rT)in_node obs_moduleobs_nodemodulesquantized_graphnode_name_to_scopeis_inputrcCs|r^t|j}|r|dnd}d} x,|D]$} | jdkr(| jtjjjkr(| } Pq(W| rX| }d} n|}d} |r|j|kr||j\} } nd} |d}|}t |\}}}|g}xH|j D]<\}}|d krt ||| | ||}|j |q|j |qW|j ||t|iS) a  Add quantization nodes (eg. quantize_per_tensor/per_channel) for given node to graph with the qparams calculated from activation_post_process (obs_module). The observer node (obs_node) is used to find the FQN of the user of act_post_process. e.g. Given input `node` in `node = self.conv(x)`, insert node: `quantized_node = torch.quantize_per_tensor(x, self._scale_0, self._zer_point_0, self._dtype_0)` where self._scale_0, self._zero_point_0 and self._dtype_0 are calculated from `obs_module` rNr!_input_outputrrIrJ)rIrJ)listusersr%rrLnn functionallinearr$rTitemscreate_getattr_from_valuer3 create_nodetuple)rUrVrWrXrYrZr[r_Zfirst_linear_use_or_first_useZ linear_noder9prefix module_path_ root_modulegraphrRrQrSinputskeyvalueZ qparam_noderrr quantize_nodes4   rocCsHt}|j|i}x,dD]$}|j|i}t|j}||O}qWt|S)a_ Get all the unique custom module keys in the custom config dict e.g. Input: custom_config_dict = { "float_to_observed_custom_module_class": { "static": { CustomModule1: ObservedCustomModule }, "dynamic": { CustomModule2: DynamicObservedCustomModule }, "weight_only": { CustomModule3: WeightOnlyObservedCustomModule }, }, } Output: # extract all the keys in "static", "dynamic" and "weight_only" dict [CustomModule1, CustomModule2, CustomModule3] staticdynamic weight_only)rprqrr)setgetkeysr^)Zcustom_config_dictZcustom_config_dict_keyZfloat_custom_module_classesZcustom_module_mappingZ quant_modeZquant_mode_custom_module_configZ quant_mode_custom_module_classesrrrget_custom_module_class_keyss     rvcCs6|tjkrtjjjS|tjkr(tjjjStd|dS)Nz&can't get linear prepack op for dtype:)rLrOops quantizedZlinear_prepack_fp16rMZlinear_prepackrP)rErrrget_linear_prepack_op_for_dtypes     ry)conv_oprcCsVtjjjtjjjtjjjtjjjtjjj tjjj i}|j |d}|sRt dj ||S)NzDidn't find prepack op for {})rLr`raconv1drwrxZconv1d_prepackconv2dZconv2d_prepackconv3dZconv3d_prepackrtrAr4)rzZ prepack_opsZ prepack_oprrrget_qconv_prepack_ops  r~)rzhas_relurcCstjjjtjjjtjjjtjjjtjjj tjjj itjjjtjjjtjjjtjjjtjjj tjjj id}||j |}|st dj |||S)N)TFz4Can't find corresponding quantized conv op for {} {})rLr`rar{rwrxZ conv1d_relur|Z conv2d_relur}Z conv3d_relurtrAr4)rzrZqconv_opZqconvrrr get_qconv_opsr)rgrcs&jddtjjdfdd }|S)Nrri)modulecsBtdfdd }d}||}xt||r<|d7}||}q W|S)N)ics t|S)N)r-)r)rgrr get_attr_nameszOget_new_attr_name_with_prefix..get_new_attr_name..get_attr_namerr)rDhasattr)rrr attr_name)rgrrget_new_attr_names  z8get_new_attr_name_with_prefix..get_new_attr_name)r.rLr`Module)rgrr)rgrget_new_attr_name_with_prefixs  r)nodercCs|g}|g}xx|r|j}t|jt|jj}xN|D]F}t|tsHq8|jdkrVdS|j||jdkor|j t ks8|j|q8WqW|S)a Starting from a target node, trace back until we hit inpu or getattr node. This is used to extract the chain of operators starting from getattr to the target node, for example def forward(self, x): observed = self.observer(self.weight) return F.linear(x, observed) collect_producer_nodes(observed) will either return a list of nodes that produces the observed node or None if we can't extract a self contained graph without free variables(inputs of the forward function). rNr!) popr^r&r'values isinstancer r%r3rgetattr)rr,ZfrontierZall_argsargrrrcollect_producer_nodes#s     r)rootproducer_nodesrcspt|dkstd|jt}ifdd}x|D]}|j|||<q8W|j||dt||}|S)a- Construct a graph module from extracted producer nodes from `collect_producer_nodes` function Args: root: the root module for the original graph producer_nodes: a list of nodes we use to construct the graph Return: A graph module constructed from the producer nodes rz'list of producer nodes can not be emptycst|fddS)Ncs|S)Nr)r)envrrOszDgraph_module_from_producer_nodes..load_arg..)r)a)rrrload_argNsz2graph_module_from_producer_nodes..load_argr)rrAreverserZ node_copyoutputr)rrrkrZ producer_nodeZ graph_moduler)rr graph_module_from_producer_nodes>s    r)rrcCs^dd|jDdd|jDB}t|dks>tdj|t|dkrVtt|nd}|S)z Returns the unique device for a module, or None if no device is found. Throws an error if multiple devices are detected. cSsh|] }|jqSr)device).0prrr [sz/assert_and_get_unique_device..cSsh|] }|jqSr)r)rrrrrr\srzMprepare only works with cpu or single-device CUDA modules, but got devices {}rN) parametersbuffersrrAr4nextiter)rZdevicesrrrrassert_and_get_unique_deviceVsr)rrkrgrnrcCs>t|}||}t|}|j|tj||d|jd|}|S)z Given a value of any type, creates a getattr node corresponding to the value and registers the value as a buffer to the module. )rr )rrZregister_bufferrLZtensorre)rrkrgrnrrrZ attr_noderrrrdds  rd) node_namerFrGrXrYrZrc Cs@|d}||\}}t|||d|} t|||d|} | | fS)z Create getattr nodes in the quantized graph for scale and zero point values. The nodes are registered with the root_module of the model. rrIrJ)rd) rrFrGrXrYrZrjrhriZ scale_nodeZzero_point_noderrrcreate_qparam_nodesqs  r)rrXcacherc Cs|r||kr||Sd}t|ts*d}n|jdkrZfound_one_tensorrZlist_elZ!this_list_el_args_have_no_tensorsZthis_arg_args_have_no_tensorsrrrrsd                rcCs|jdko|jdkS)zd Returns true if this node results in an integer, even if some of the args are Tensors. r#r)r%r)rrrrnode_return_type_is_intsrcCs|jdkr|jdkrdgSgS)z0 Returns indexes of boolean Tensor args r#Z masked_fillr)r%r)rrrrnode_bool_tensor_arg_indexessrcCs&|jdko |jtko |jddk}|S)z Returns True if this node is a node that takes a Tensor as input and output some meta information about the Tensor, e.g. shape, size etc. r!rr)r%rrr&)rr>rrris_get_tensor_info_nodes"r)rrXtarget_module_typetarget_functional_typercCsfx`|jjD]R\}}|jdkr>|dk r>t|t|j|r>|S|jdkr |dk r |j|kr |Sq WdS)a% Gets the next module that matches what is needed in is_target_module_type if it exists Args: node: The node whose users we want to look at target_module_type: Module type that we want to check target_functional_type: Functional type that we want to check r"Nr!)r_rcr%rr-r)rrXrruserrirrrmaybe_get_next_modules r)T)NN)>r*rLZtorch.nnr`utilsrrZtorch.ao.quantization.quantizerZtorch.fxrrZtorch.fx.graphrr typingr r r r rrrrrrrar{r|r}rbZ layer_normZ group_normZ instance_normZWEIGHT_INDEX_DICTZNON_QUANTIZABLE_WEIGHT_OPSZFUNCTIONAL_OPS_WITH_BIASrr-r?rHrTrtypeboolrorvryr~rrrrrrdrrrrDrrrrrrrsl  ,       B*3  (L