/usr/local/lib64/python3.6/site-packages/torch/onnx/__pycache__
NameSizeModeActions
operators.cpython-36.pyc8840644editdlrm
symbolic_caffe2.cpython-36.pyc74140644editdlrm
symbolic_helper.cpython-36.pyc269960644editdlrm
symbolic_opset7.cpython-36.pyc20300644editdlrm
symbolic_opset8.cpython-36.pyc83740644editdlrm
symbolic_opset9.cpython-36.pyc984760644editdlrm
symbolic_opset10.cpython-36.pyc96580644editdlrm
symbolic_opset11.cpython-36.pyc252700644editdlrm
symbolic_opset12.cpython-36.pyc87090644editdlrm
symbolic_opset13.cpython-36.pyc92190644editdlrm
symbolic_opset14.cpython-36.pyc16330644editdlrm
symbolic_registry.cpython-36.pyc34940644editdlrm
utils.cpython-36.pyc358880644editdlrm
__init__.cpython-36.pyc181970644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/onnx/__pycache__/utils.cpython-36.pyc (35888B)
3 Eg&@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddlm Z ddlmZmZmZmZddlmZmZmZmZddlmZmZmZdaGd d d eZd d ZiZ ej!d dZ"deddZ#ddZ$ddZ%dfddZ&ddZ'ddZ(ddZ)ddZ*d d!Z+d"d#Z,d$d%Z-dgd&d'Z.d(d)Z/d*d+Z0d,d-Z1d.d/Z2d0d1Z3dddej4ddddddf d2d3Z5dddddej4ej6dddddddddfd4d5Z7dddddej4ej6ddddddddddfd6d7Z8dej9ddddfd8d9Z:ddddddej6ddddddddddfd:d;Z;dZ>d?d@Z?dAdBZ@dCdDZAdEdFZBdGdHZCdIdJZDdKdLZEdMdNZFdOdPZGdQdRZHdSdTZIej4fdUdVZJdWdXZKdYdZZLd[d\ZMd]d^ZNd_d`ZOdadbZPdcddZQeDejRjS_TeKejRjS_UeEejRjV_TeLejRjS_WeMejRjX_YdS)hz The torch.onnx module contains functions to export models into the ONNX IR format. These models can be loaded with the ONNX library and then converted to models which run on other deep learning frameworks. N)string_classes)_unique_state_dict)ONNX_ARCHIVE_MODEL_PROTO_NAME ExportTypesOperatorExportTypes TrainingMode)ListType OptionalType"_propagate_and_assign_input_shapes_check_onnx_proto)ListTupleUnionFc@s eZdZdS)ONNXCheckerErrorN)__name__ __module__ __qualname__rrrr_flattenrHru) method_graph args_paramsparam_count_listZinput_Z arg_params_in_vars_rrr_get_param_count_listsrcCsd}t|tjjry|jj}tjj|tjj|j dd}tjj |\}}|j dj}t |t |}t ||} tjj|\} } t|t | | dd}Wn,tk r} ztd| WYdd} ~ XnX||||fSt|tjjr4f}tjjt |\} } |j}tjj|t ||} t|t | | dd}|||dfSt||\}}t|}t|j}t|j}t|t|}t|j}x2t|D]&\}}||kr|j|||qWtjj||||dfSdS)NT)ZpreserveParametersrsFz('forward' method must be a script method)rrr ScriptModulersrWrSZ$_jit_pass_onnx_function_substitutionZ_freeze_moduleZ_cZ_jit_onnx_list_model_parametersZ _get_methodrxrrr ryrrrrr`valuesrNrura enumerate setDebugName)r$r4rrWZ freezed_mr[paramsrrrrrrZin_descZ state_dictZ graph_inputsZuser_input_num param_namesiinprrr_create_jit_graphsH            rcCs<dd|jD}|t|t|d}tt||}|S)NcSsg|] }|jqSr) debugName).0rOrrr sz)_get_named_param_dict..)rNrur_r^)rWrZinput_and_param_namesr _params_dictrrr_get_named_param_dictsrcCsltj|}i}|r4t|dtr4|d}|dd}|||}t|tjtttfrX|f}t|t rh|g}|S)Nr]rprprp) copydeepcopyrr_rrintfloatboolr`)r$r4Z input_argsZ input_kwargsr*rrr_get_example_outputss    rc  Csddlm} t|tjtttfr&|f}t||\} }}}t | |}t | ||| || ||d} ddlm }t|tj j st|tj jr|dkrt||}n*t|tjtttfr|f}t|tr|g}tj jt|\}}tjj| |||nsz"_model_to_graph..css|] }dVqdS)r]Nr)rrrrrrsrg)(r"rrrrrrrrrr\rRrrrrr`rrxrSZ"_jit_pass_onnx_assign_output_shapeZ _jit_flattenrusumrNAssertionError_set_input_and_output_namesrrZ_jit_pass_onnx_eval_peepholer/Zconstant_folding_opset_versionsZ_jit_pass_onnx_constant_foldrUrVZ%_jit_pass_onnx_eliminate_unused_itemsZ,_jit_pass_onnx_cast_all_constant_to_floatingprintZ%_jit_pass_filter_non_tensor_argumentsZ#_jit_decay_packed_param_input_types)r$r4r7r8r9r'r*r)rXrYrr+rrWrrr[rZrRZout_varsdescZ flatten_argsrZoutput_wrappedZoutput_tensorsZout_descrrr_model_to_graphs`     ,  ,       rcCsP|dk rtjd| dk r$tjdt|||||||||| | | | |||||dS)NzN'f' is deprecated and ignored. It will be removed in the next PyTorch release.z_'_retain_param_name' is deprecated and ignored. It will be removed in the next PyTorch release.)r)rjr,r-r+)r r!_export_to_pretty_string)r$r4r5r6r7rr8r9r' export_typer*google_printerr(r:r,r-rjr)r+rrrexport_to_pretty_string7s  rcCsddlm}m}ddlm}| dkr(|} |dkr4i}|| ||ddlm}||t||jt||| }t||}t| ||}t ||}t ||||||| ||||d \}}}|j || d|| |||SQRXdS)Nr)_default_onnx_opset_version_set_opset_version)_set_operator_export_type)_set_onnx_shape_inference)rYrr+F) r"rrrrr&rirkrlrrZ_pretty_print_onnx)r$r4r5r6r7rr8r9r'rr*rr(r)r,rYr-rjonnx_shape_inferencer+rrrrrhval_add_node_namesval_do_constant_foldingrWrZrrrrrKs2        rc Csddlm} m} |dkr| }| |tj} t||(t||}t|||||| \} } }WdQRXt}x4| j D](}|j j dddkrr|j |j qrW| |fS)a3 This diagnostic tool runs your model with operator_export_type set to OperatorExportTypes.ONNX_FALLTHROUGH once in order to get a list of all the ops that are not supported/implemented by the current exporter operator_export_type is set to OperatorExportTypes.ONNX_FALLTHROUGH by default OperatorExportTypes.ONNX_FALLTHROUGH: If an op is not supported in ONNX, fall through and export the operator as is, as a custom ONNX op. Using this mode, the op can be exported and implemented by the user for their runtime backend. Example graph:: graph(%0 : Float(2, 3, 4, strides=[12, 4, 1], requires_grad=0, device=cpu)): %6 : Long(requires_grad=0, device=cpu) = prim::Constant[value={0}]() %4 : None = prim::Constant() %5 : Float(2, 3, 4, strides=[12, 4, 1], requires_grad=0, device=cpu) = aten::cumsum(%0, %6, %4) # main.py:6:0 return (%5) is exported as:: graph(%0 : Float(2, 3, 4, strides=[12, 4, 1], requires_grad=0, device=cpu)): %6 : Long(requires_grad=0, device=cpu) = prim::Constant[value={0}]() %4 : None = prim::Constant() %5 : Float(2, 3, 4, strides=[12, 4, 1], requires_grad=0, device=cpu) = aten::cumsum(%0, %6, %4) # main.py:6:0 return (%5) In the above example, aten::cumsum in not implemented in opset 9, hence exporter falls through and provides a list of unsupported ops, the result being: Unsupported ops : [aten:cumsum] r)rrN:r/prim)r/r) r"rrrONNX_FALLTHROUGHr&rrr`rDr<splitrH)r$r4r5r7rr8r9r(r+rrr'rWrZrZunsupported_opsrArrr_find_missing_ops_onnx_exportms    rc-$Cst|tjjrtdtdks"tdazBddlm}||ddlm }m }ddlm }| dkrf|} |stj j rztj}ntj}|| ||t||t||| }t||}t| ||}t|||\}}t||}| dkri} t| |||t||||||| |||| d \}}}| tjk } |dkr0i}|r^|j|| | | || ||||| \}!}"}n&|ji| | d|| ||||| \}!}"}| tjkrt|"dksttjj|d }#|#j|!WdQRXnF| tj tj!gkrJddl"}$| tj!kr|$j#n|$j$}%|$j%|d |%d 6}&|&j&t'|!x"|"j(D]\}'}(|&j&|'|(q$WWdQRXn| tj)krddl*})|)j+j,|r|)j+j-|stn |)j.||)j+j/|t'}*tjj|*d }#|#j|!WdQRXxR|"j(D]<\}'}(|)j+j/||'}+tjj|+d }#|#j|(WdQRXqWnt0d |tjkr^| r^y t1|!Wn,t0k r\},zt2|,WYdd},~,XnXWdQRXWdtsvtdaX|S) Nztorch.nn.DataParallel is not supported by ONNX exporter, please use 'attribute' module to unwrap model from torch.nn.DataParallel. Try torch.onnx.export(model.module, ...)FTr)r)rr)r)rYrr+wbw) compressionzUnknown export type)3rrnnZ DataParallelrzrrr"rrrrr/r0rr1r2r&rirkrlror_validate_dynamic_axesrr PROTOBUF_FILEZ _export_onnxruZ serializationZ_open_file_likewriteZ ZIP_ARCHIVEZCOMPRESSED_ZIP_ARCHIVEzipfile ZIP_DEFLATED ZIP_STOREDZipFilewritestrritemsZ DIRECTORYospathexistsisdirmakedirsjoinrr r)-r$r4r5r6r7rr8r9r'rr*r(r)r+r,rYr-rjr.rrrrrrhrrrmrnrWrZrZdefer_weight_exportprotoZ export_mapZ opened_filerrzkvrZmodel_proto_fileZweight_proto_filerrrrr3s                  ( r3cCs4dd}|t|j|d|t|j|ddS)NcSsj|dkr dSt|t|kr8td|t||t|fx,t||D]\}}|j|krD|j|qDWdS)Nz.set_namesrPr=)r`rNoutputs)rWr8r9rrrrrs rz^(.+)_([ifstgz])$cCsNy||f|Stk rH}zdj|jd|f|_WYdd}~XnXdS)z\ This trampoline function gets invoked for every symbolic method call from C++. z!{} (occurred when translating {})rN) TypeErrorr#r4)rLop_name symbolic_fnr4rrrr_run_symbolic_method+s rcCs0t|t r,t|tj r,t|tjjr,dSdS)NTF)rrrr collectionsabcIterable)valuerrr _is_onnx_list:s  rcCstj|}|dkr td j||jd|jd}}t|rF|d7}|rt|tjr|j dkrjt dt |}t|t rd}nd }t ||d ||S) z8 initializes the right attribute based on type of value Nz'Invalid attribute specifier '{}' names z5 must be suffixed with type, e.g. 'dim_i' or 'dims_i'r]sz Should not pass tensor attributer5rrz\Invalid attribute specifier '{}' names must be suffixed with type, e.g. 'dim_i' or 'dims_i') attr_patternmatchr{r#grouprrrrnumelrz_scalarrgetattr)rAkeyratenmrr<rrr_add_attributeBs"     rcCs|jdkst|dS)z,Convert a scalar tensor into a Python value.r]r)rr)xrrrrYsrc Os|d|krd}|}n$|jdd}|r&dnd}|d|}|j|||}x2t|jD]"\} } | dkrdqRt|| | |dqRW|S)Nz::Frr/inplace)r)poprIsortedrr) rLopnamerr4kwargsr ns_opnamensnrrrrr_newNode_s   rc s|jdd}tdd|jD}fddtfdd|D}jt||f||}dd lm}|rdd lm}t j j |t ||dkr|j Std d|jDS) a Create an ONNX operator "opname", taking "args" as inputs and attributes "kwargs"; returning the node representing the single output of this operator (see the `outputs` keyword argument for multi-return nodes). The set of operators and the inputs/attributes they take is documented at https://github.com/onnx/onnx/blob/master/docs/Operators.md This function is monkey-patched onto Graph. Args: opname (string): The ONNX operator name, e.g., `Abs` or `Add`. args (Node...): The inputs to the operator; usually provided as arguments to the `symbolic` definition. kwargs: The attributes of the ONNX operator, with keys named according to the following convention: `alpha_f` indicates the `alpha` attribute with type `f`. The valid type specifiers are `f` (float), `i` (int), `s` (string) or `t` (Tensor). An attribute specified with type float accepts either a single float, or a list of floats (e.g., you would say `dims_i` for a `dims` attribute that takes a list of integers). outputs (int, optional): The number of outputs this operator returns; by default an operator is assumed to return a single output. If `outputs` is greater than one, this functions returns a tuple of output `Node`, representing each output of the ONNX operator in positional. rr]css"|]\}}|dk r||fVqdS)Nr)rrrrrrrsz_graph_op..cs0|dkr |St|tjjr|Sjd|dSdS)NConstant)value_z)rrrSValueop)arg)rLrrconst_if_tensors z"_graph_op..const_if_tensorc3s|]}|VqdS)Nr)rr)rrrrsr)rR)rcss|] }|VqdS)Nr)rorrrrs)rr_rr`Z insertNoderr"rRrrrS(_jit_pass_onnx_node_shape_type_inferencerr=rxr) rLrZraw_argsrrr4rrRr(r)rrLr _graph_opps    rc Osd|krd}|}n$|jdd}|r&dnd}|d|}|j|t|}x2t|jD]"\}} |dkrfqTt||| |dqTWtt|jdkr|jSt dd |jDS) Nz::Frr/r)rr]css|] }|VqdS)Nr)rrrrrrsz_block_op..) rZaddNoder`rrrrurr=rx) brr4rrrrrrrrrr _block_ops   rcCs|jS)N)addBlock)rArrr _add_blocksrcCs|jS)N)ZaddInputToBlock)rMrrr_add_input_to_blocksrcCs|j|}|S)N)ZregisterOutput)rMrZ new_outputrrr_add_output_to_blocks rcCs6ddljj}|j|||s(|tjkr(dS|j|||S)Nr)torch.onnx.symbolic_registryr/symbolic_registryis_registered_oprrZget_registered_op)domainrr(r' sym_registryrrr_find_symbolic_in_registrys   r c(sy\ddlddlm}ddljj}|jd||tjkrZ|dkrZddl jj j d|j j drzj dd0}nj }|jd\} } | d kr| d krjj||Sfd d jD} |j| f|| d jiSnt| dkr|j| d|} |tjk} |tjk}| s(| rh|rhfdd jD} j}|| d <t|| f|ddi| Sd}t|| ||}|dkrdSfdd jD} ||f|| Sn| dkr| dkrj rjddkr|jdddSjddkr|jdddSjjjtjsFjjjtjrjj }t!|rtj"fdd|Dng}|jd|dSjjj dkrdSt#dj$jdq\js| dks| dks| dkrdS| d krjjj dkrdS| d!ks| d"kr4| d"ko8|dj%j d#k}d$}|r|dj%dj&}t'|t(rlt)|nt*|}|r~dnd}t(j+|}d}jj,|||||}t(j-}t(|j-}g}xNt.t!|D]>}|||krt#d%||d&|||}|j/|qW|S|j| f|d ji}jdkrN|dj%n|j%} xj+D]}!| j0}"xvt1|!j2D]f\}#}$|#dkr|#t!|kr|$j3||#j|#dkrz|#dt!|krz|$j3||#djqzWjj,|!|"|||q`Wjj4| |}dd'lm5}%|%r.jj6| t7||Snbd(| }&d}t||&||}|dkr\dSfd)d jD} | d*krf|}||f|| Sn| d+krd}|tjkrd}t|| ||}|dkrdSfd,d jD} ||f|| S|j8| |rL| }t|| ||}|dkr&dSfd-d jD} ||f|| St#d.j$| | Wnbt#k r|tj9krdSYn<t:k r}'zd/j$|'j;d| f|'_;WYdd}'~'XnXdS)1Nr)rrgZcaffe2rr]z::r/Z Placeholdercs(i|] }||dj|dqS)rr)kindOf)rr)rrr sz*_run_symbolic_function..rrcs(i|] }||dj|dqS)rr)r)rr)rrrrsTcsi|]}||qSrr)rr)rrrrsrrrt)value_tr)Zvalue_scsg|]}j|qSr)tensor)rr)rrrrsz*_run_symbolic_function..Z DeviceObjTypez9Unsupported prim::Constant kind: `{}`. Send a bug report.Z ListConstructZ ListUnpackZ UninitializedZdeviceZLoopIfzonnx::ConstantFzThe sub block ATen output z is not in env.)rRZprim_csi|]}||qSrr)rr)rrrrusZPythonOpZ quantizedcsi|]}||qSrr)rr)rrrrscsi|]}||qSrr)rr)rrrrszONNX export failed on an operator with unrecognized namespace {}::{}. If you are trying to export a custom operator, make sure you registered it with the right domain and version.z#{} (Occurred when translating {}).rp)r?rZofIntsZofFloatsrGrustackrr#rAtolistrr`allrrEZ_jit_pass_onnx_blockrrangerHrrrNrKZ%_jit_pass_fixup_onnx_controlflow_noderRrrZis_registered_versionrrr4)(rLrMrrNenvr'r(r Z ns_op_namerrattrsZis_exportable_aten_opZis_onnx_aten_exportZis_aten_fallback_exportrr rvalsrZ static_ifZ is_sub_blockZ input_flagZ const_valueZ block_idxZ current_bZif_output_listZcurrent_b_listZ final_b_listidxZonnx_bZnew_op_outputsnew_noderZ new_blockrZb_inrR symbolic_namerr)rrr_run_symbolic_functions   "     0 &(    "          r!cOs|jd|d|i|S)NATenZ operator_s)r")r)rLrr4rrrrrsrcOs(t|tjst|dk std}|dksB|dksBt|tdgkrLdg}d}|j}|dkrhtj|}n|dkr|tj|}nl|dkrtj |}nX|dkrtj |}nD|d krtj |}n0|d krtj |}n|d krtj |}ntd |j||r|jd|d|i|S|jd|d|i|S)NFrr]TcharshortrlongZhalfrdoublezfUnknown type, type should be one of the following strings: char, short, int, long, half, float, doublerrr)r)r)rnumbersNumberrsetlowerrZ CharTensorZ ShortTensorZ IntTensorZ LongTensorZ HalfTensorZ FloatTensorZ DoubleTensorrzZfill_r)rLrZdimsr>r4rZisscalarrrrr_graph_constants4 "        r+cCs|j|}t|||S)z Accessor for attributes of a node which is polymorphic over return type. NB: This is monkey-patched onto Node. )rr)selfrselrrr _node_getitems r.cCsVttjd|stdj||jd\}}dddg}||krNtdj||||fS)Nz+^[a-zA-Z0-9-_]*::[a-zA-Z-_]+[a-zA-Z0-9-_]*$zFailed to register operator {}. The symbolic name must match the format Domain::Name, and should start with a letter and contain only alphanumerical charactersz::r/rrzGFailed to register operator {}. The domain {} is already a used domain.)rrerrr#r)r rrZunaccepted_domain_namesrrrget_ns_op_name_from_custom_ops  r0c CsXt|\}}ddljj}ddlm}m}x*||gD]}||kr4|j||||q4WdS)Nr)_onnx_stable_opsets_onnx_main_opset)r0rr/r r"r1r2Z register_op) r rr(rrr r1r2versionrrrregister_custom_op_symbolics   r4cCsVt|\}}ddljj}ddlm}m}x(||gD]}||kr4|j|||q4WdS)Nr)r1r2)r0rr/r r"r1r2Z unregister_op)r r(rrr r1r2r3rrrunregister_custom_op_symbolics   r5c Cs8t|dkrdSt|drj|dks.t|dkrBdd|jjD}|dksVt|dkrjdd|jjD}t|prg|pxg}x|jD]\}}||krtjdj |t |t rtjdj |i}x`t |D]T\}} t | t std| |krtjd j | |qt|d t|d || <qW|||<qWdS) NrrWcSsg|] }|jqSr)r)rrrrrrsz*_validate_dynamic_axes..cSsg|] }|jqSr)r)ryrrrrszAProvided key {} for dynamic axes is not a valid input/output namezNo names were found for specified dynamic axes of provided input.Automatically generated names will be applied to each dynamic axes of input {}z3The type of axis index is expected to be an integerz:Duplicate dynamic axis index {} was provided for input {}.Z_dynamic_axes_r])ruhasattrrWrNrr)rr r!r#rr`rrrzrb) r+r$r8r9Z valid_namesrrZ value_dictrrrrrrs.       r)TFNNNNNNTNNNNNNN)FFNNNN)F)Z__doc__rZ torch.jitZtorch.autogradZtorch.serializationr/r contextlibrr'r Z torch._sixrrZ torch.onnxrrrrZtorch._Crr r r typingr r rrr|rrrcontextmanagerr&r;rCrFr\rdrfrirkrlrorrrrrrrr2rrrrrrr3rcompilerrrrrrrrrrrr r!rr+r.r0r4r5rrSZGraphrZatZBlockZconstantNode __getitem__rrrrs  &   d  !  )[1u 7 D #   $