onnxscript 0.1.0.dev20231121__tar.gz → 0.1.0.dev20231123__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {onnxscript-0.1.0.dev20231121/onnxscript.egg-info → onnxscript-0.1.0.dev20231123}/PKG-INFO +2 -2
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/backend/onnx_export.py +130 -185
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/graph_building.py +153 -17
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/ops/core.py +2 -2
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/ops/nn.py +16 -3
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/function_libs/torch_lib/ops_test_data.py +6 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123/onnxscript.egg-info}/PKG-INFO +2 -2
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/pyproject.toml +0 -1
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/setup.py +13 -1
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/LICENSE +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/MANIFEST.in +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/README.md +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/VERSION +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/__init__.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/_internal/__init__.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/_internal/analysis.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/_internal/analysis_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/_internal/ast_utils.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/_internal/autocast.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/_internal/deprecation.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/_internal/param_manipulation.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/_internal/param_manipulation_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/_internal/runtime_typing.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/_internal/utils.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/_internal/version_utils.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/backend/__init__.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/backend/onnx_backend.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/backend/onnx_backend_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/backend/onnx_export_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/converter.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/converter_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/__init__.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/_infra.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/context.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/decorator.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/formatter.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/__init__.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_address.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_artifact.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_artifact_change.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_artifact_content.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_artifact_location.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_attachment.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_code_flow.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_configuration_override.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_conversion.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_edge.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_edge_traversal.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_exception.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_external_properties.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_external_property_file_reference.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_external_property_file_references.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_fix.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_graph.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_graph_traversal.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_invocation.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_location.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_location_relationship.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_logical_location.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_message.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_multiformat_message_string.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_node.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_notification.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_physical_location.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_property_bag.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_rectangle.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_region.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_replacement.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_reporting_configuration.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_reporting_descriptor.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_reporting_descriptor_reference.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_reporting_descriptor_relationship.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_result.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_result_provenance.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_run.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_run_automation_details.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_sarif_log.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_special_locations.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_stack.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_stack_frame.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_suppression.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_thread_flow.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_thread_flow_location.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_tool.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_tool_component.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_tool_component_reference.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_translation_metadata.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_version_control_details.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_web_request.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/_web_response.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/sarif/version.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/diagnostics/infra/utils.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/evaluator.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/evaluator_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/tools/torch_lib/deduce_type_constraints.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/tools/torch_lib/deduce_type_constraints_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/tools/torch_lib/generate_aten_signatures.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/tools/torch_lib/generate_prims_signatures.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/__init__.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/_constants.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/_flags.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/graph_building_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/ops/__init__.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/ops/common.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/ops/fft.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/ops/linalg.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/ops/nested.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/ops/prims.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/ops/sparse.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/ops/special.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/registration.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/function_libs/torch_lib/tensor_typing.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/irbuilder.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/main.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/__init__.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset1.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset10.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset11.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset12.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset13.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset14.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset15.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset16.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset17.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset18.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset19.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset2.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset3.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset4.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset5.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset6.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset7.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset8.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset9.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset_ai_onnx_ml1.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset_ai_onnx_ml2.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset_ai_onnx_ml3.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_opset/_impl/opset_ai_onnx_preview_training1.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/onnx_types.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/py.typed +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/sourceinfo.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tensor.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tensor_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/testing.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/__init__.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/common/__init__.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/common/onnx_script_test_case.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/common/testutils.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/eager_mode_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/eager_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/external_tensor_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/function_libs/torch_lib/error_reproduction.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/function_libs/torch_lib/extra_opinfo.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/function_libs/torch_lib/ops_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/function_libs/torch_lib/ops_test_common.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/functions/attr_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/functions/gemmgelu.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/functions/gemmgelu_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/functions/if_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/functions/onnxfns1A_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/functions/onnxfns2_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/functions/onnxfns_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/functions/ort_custom_ops.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/if_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/loop_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/__init__.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/attrref.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/cast_like.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/different_opset.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/dropout.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/eager_op.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/eg1.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/getitem.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/graph_attr.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/identity.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/if_statement.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/loops_break.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/loops_while.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/m1.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/multi.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/onnxfns1.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/onnxfns1A.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/onnxfns2.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/opt_input.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/opt_output.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/renaming.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/sequences.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/signal_dft.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/subfunction.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/models/type_double.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/onnx_types_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/tests/operator_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/type_annotation.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/type_annotation_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/values.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/values_test.py +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript.egg-info/SOURCES.txt +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript.egg-info/dependency_links.txt +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript.egg-info/requires.txt +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript.egg-info/top_level.txt +0 -0
- {onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/setup.cfg +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: onnxscript
|
|
3
|
-
Version: 0.1.0.
|
|
3
|
+
Version: 0.1.0.dev20231123
|
|
4
4
|
Summary: Naturally author ONNX functions and models using a subset of Python
|
|
5
|
+
Home-page: https://onnxscript.ai/
|
|
5
6
|
Author-email: Microsoft Corporation <onnx@microsoft.com>
|
|
6
7
|
License: MIT License
|
|
7
8
|
|
|
@@ -25,7 +26,6 @@ License: MIT License
|
|
|
25
26
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
27
|
SOFTWARE.
|
|
27
28
|
|
|
28
|
-
Project-URL: Repository, https://github.com/microsoft/onnxscript
|
|
29
29
|
Classifier: Development Status :: 4 - Beta
|
|
30
30
|
Classifier: Environment :: Console
|
|
31
31
|
Classifier: Intended Audience :: Developers
|
{onnxscript-0.1.0.dev20231121 → onnxscript-0.1.0.dev20231123}/onnxscript/backend/onnx_export.py
RENAMED
|
@@ -14,32 +14,6 @@ from onnx.helper import make_node
|
|
|
14
14
|
import onnxscript.onnx_types
|
|
15
15
|
import onnxscript.type_annotation
|
|
16
16
|
|
|
17
|
-
_template_python = '''
|
|
18
|
-
import numpy
|
|
19
|
-
from onnx import TensorProto
|
|
20
|
-
from onnx.helper import make_tensor
|
|
21
|
-
from onnxscript import script, external_tensor
|
|
22
|
-
from onnxscript.values import Opset
|
|
23
|
-
{% if unique_types %}
|
|
24
|
-
from onnxscript.onnx_types import {{ ", ".join(unique_types) }}
|
|
25
|
-
{%- endif %}
|
|
26
|
-
{{translate_opset_imports_of(main_model)}}
|
|
27
|
-
{% for domain, name, fct in functions: %}
|
|
28
|
-
{{translate_function(fct["proto"])}}
|
|
29
|
-
{% endfor %}
|
|
30
|
-
{% if graph %}
|
|
31
|
-
@script()
|
|
32
|
-
def {{ function_name }}{{translate_sig(graph.input, graph.output)}}
|
|
33
|
-
{% if doc_string %}"""
|
|
34
|
-
{{ doc_string }}
|
|
35
|
-
"""{%- endif %}
|
|
36
|
-
{{ python_make_node_graph(graph, opsets, indent=1) }}
|
|
37
|
-
return {{ rename(graph.output[0]) }}{%
|
|
38
|
-
for o in graph.output[1:]: %}, {{ rename(o) }}{% endfor %}
|
|
39
|
-
{%- endif %}
|
|
40
|
-
'''
|
|
41
|
-
|
|
42
|
-
|
|
43
17
|
kwlist = {
|
|
44
18
|
"False",
|
|
45
19
|
"None",
|
|
@@ -101,7 +75,7 @@ def _get_const_repr(const_node):
|
|
|
101
75
|
return None
|
|
102
76
|
|
|
103
77
|
|
|
104
|
-
def
|
|
78
|
+
def _cleanup_variable_name(name: ValueInfoProto | str) -> Optional[str]:
|
|
105
79
|
"""Converts given name into a valid python variable names.
|
|
106
80
|
Handles names that clash with python keywords and common issues seen in ONNX models:
|
|
107
81
|
* Identifiers like "5" (that do not start with an alpha character)
|
|
@@ -128,6 +102,23 @@ def _rename_variable(name: ValueInfoProto | str) -> Optional[str]:
|
|
|
128
102
|
return "".join([rename_char(c) for c in name])
|
|
129
103
|
|
|
130
104
|
|
|
105
|
+
def _make_short_name_mapper():
|
|
106
|
+
"""Returns a renamer used to create short new names (like v0, v1, ...) for variables."""
|
|
107
|
+
variable_names: dict[str, str] = {}
|
|
108
|
+
|
|
109
|
+
def renamer(name):
|
|
110
|
+
# TODO: simplify this. No need to use _cleanup_variable_name?
|
|
111
|
+
var_name = _cleanup_variable_name(name)
|
|
112
|
+
if var_name in variable_names:
|
|
113
|
+
return variable_names[var_name]
|
|
114
|
+
new_name = f"v{len(variable_names) + 1}"
|
|
115
|
+
assert var_name is not None # TODO(rama): This looks suspect.
|
|
116
|
+
variable_names[var_name] = new_name
|
|
117
|
+
return new_name
|
|
118
|
+
|
|
119
|
+
return renamer
|
|
120
|
+
|
|
121
|
+
|
|
131
122
|
def _translate_type(onnx_type):
|
|
132
123
|
"""Converts a onnx type into a type defined by *onnxscript*."""
|
|
133
124
|
return onnxscript.onnx_types.onnx_type_to_onnxscript_repr(onnx_type)
|
|
@@ -139,10 +130,10 @@ def _translate_signature(inputs, outputs):
|
|
|
139
130
|
def input_sig(inp: ValueInfoProto | str):
|
|
140
131
|
if isinstance(inp, ValueInfoProto):
|
|
141
132
|
# GraphProto inputs/outputs are ValueInfoProto
|
|
142
|
-
return f"{
|
|
133
|
+
return f"{_cleanup_variable_name(inp.name)}: {_translate_type(inp.type)}"
|
|
143
134
|
|
|
144
135
|
# FunctionProto inputs/outputs are just strings
|
|
145
|
-
return
|
|
136
|
+
return _cleanup_variable_name(inp)
|
|
146
137
|
|
|
147
138
|
result = f"({', '.join([input_sig(x) for x in inputs])})"
|
|
148
139
|
if outputs and isinstance(outputs[0], ValueInfoProto):
|
|
@@ -192,7 +183,7 @@ def _attribute_value(attr: onnx.AttributeProto):
|
|
|
192
183
|
|
|
193
184
|
|
|
194
185
|
def _update_names_used_in_graph(names: set[str], graph: GraphProto) -> None:
|
|
195
|
-
"""
|
|
186
|
+
"""Adds the names used in a graph to given set."""
|
|
196
187
|
names.update(x.name for x in graph.input)
|
|
197
188
|
names.update(x.name for x in graph.output)
|
|
198
189
|
names.update(x.name for x in graph.initializer)
|
|
@@ -226,14 +217,19 @@ def _names_used_in_function(fun: FunctionProto) -> set[str]:
|
|
|
226
217
|
class Exporter:
|
|
227
218
|
"""Class used for recursive traversal of Proto structures."""
|
|
228
219
|
|
|
229
|
-
def __init__(
|
|
220
|
+
def __init__(
|
|
221
|
+
self, rename: bool, use_operators: bool = False, inline_const: bool = False
|
|
222
|
+
) -> None:
|
|
230
223
|
self.use_operators = use_operators
|
|
224
|
+
if rename:
|
|
225
|
+
rename_function = _make_short_name_mapper()
|
|
226
|
+
else:
|
|
227
|
+
rename_function = _cleanup_variable_name
|
|
231
228
|
self._rename_variable = self._handle_attrname_conflict(rename_function)
|
|
232
229
|
self.inline_const = inline_const
|
|
233
230
|
self.constants: dict[str, str] = {}
|
|
234
231
|
self._attr_renaming: dict[str, str | None] = {} # For current function.
|
|
235
232
|
self._names_used: set[str] = set() # For current function.
|
|
236
|
-
self.opsets: dict[str, int] = {}
|
|
237
233
|
|
|
238
234
|
def _handle_attrname_conflict(self, renamer):
|
|
239
235
|
"""Add ref-attr-name-conflict handling logic to renaming function."""
|
|
@@ -266,11 +262,11 @@ class Exporter:
|
|
|
266
262
|
return "opset"
|
|
267
263
|
return domain.replace(".", "_")
|
|
268
264
|
|
|
269
|
-
def
|
|
265
|
+
def _make_opset_name(self, domain, version):
|
|
270
266
|
return f"{self._rename_domain(domain)}{version}"
|
|
271
267
|
|
|
272
268
|
def _python_make_node_name(self, domain, version, name, node=False):
|
|
273
|
-
name =
|
|
269
|
+
name = _cleanup_variable_name(
|
|
274
270
|
name
|
|
275
271
|
) # TODO: Is this a typo? Is it supposed to be self._rename_variable(name)?
|
|
276
272
|
if node:
|
|
@@ -281,7 +277,7 @@ class Exporter:
|
|
|
281
277
|
f"version must be an integer not {version!r} for domain={domain!r} "
|
|
282
278
|
f"and name={name!r}."
|
|
283
279
|
)
|
|
284
|
-
opset = self.
|
|
280
|
+
opset = self._make_opset_name(domain, version)
|
|
285
281
|
return f"{opset}.{name}"
|
|
286
282
|
return name
|
|
287
283
|
|
|
@@ -410,7 +406,7 @@ class Exporter:
|
|
|
410
406
|
"""Translates a node Scan into python."""
|
|
411
407
|
raise NotImplementedError()
|
|
412
408
|
|
|
413
|
-
def
|
|
409
|
+
def _lookup(self, var):
|
|
414
410
|
if var in self.constants:
|
|
415
411
|
return self.constants[var]
|
|
416
412
|
|
|
@@ -456,7 +452,7 @@ class Exporter:
|
|
|
456
452
|
if self.use_operators and node.op_type in ops:
|
|
457
453
|
return (
|
|
458
454
|
f"{sindent}{self._rename_variable(node.output[0])} = "
|
|
459
|
-
f"{(f' {ops[node.op_type]} ').join(map(self.
|
|
455
|
+
f"{(f' {ops[node.op_type]} ').join(map(self._lookup, node.input))}"
|
|
460
456
|
)
|
|
461
457
|
name = self._python_make_node_name(
|
|
462
458
|
node.domain, opsets[node.domain], node.op_type, node=True
|
|
@@ -477,36 +473,38 @@ class Exporter:
|
|
|
477
473
|
" = ",
|
|
478
474
|
name,
|
|
479
475
|
"(",
|
|
480
|
-
", ".join(map(self.
|
|
476
|
+
", ".join(map(self._lookup, node.input)),
|
|
481
477
|
attributes_str,
|
|
482
478
|
")",
|
|
483
479
|
]
|
|
484
480
|
return "".join(text)
|
|
485
481
|
|
|
486
|
-
def
|
|
482
|
+
def _translate_opset_import(self, domain: str, version: int) -> str:
|
|
487
483
|
if domain in {"", "ai.onnx"}:
|
|
488
484
|
return f"from onnxscript.onnx_opset import opset{version}\n"
|
|
489
485
|
else:
|
|
490
|
-
varname = self.
|
|
486
|
+
varname = self._make_opset_name(domain, version)
|
|
491
487
|
return f"{varname} = Opset('{domain}', {version})\n"
|
|
492
488
|
|
|
493
|
-
def
|
|
489
|
+
def _translate_opset_imports(
|
|
490
|
+
self, opset_imports: Sequence[onnx.OperatorSetIdProto]
|
|
491
|
+
) -> str:
|
|
494
492
|
return "".join(
|
|
495
|
-
[self.
|
|
493
|
+
[self._translate_opset_import(x.domain, x.version) for x in opset_imports]
|
|
496
494
|
)
|
|
497
495
|
|
|
498
|
-
def
|
|
496
|
+
def _translate_opset_imports_of(
|
|
499
497
|
self, proto: ModelProto | FunctionProto | GraphProto
|
|
500
498
|
) -> str:
|
|
501
499
|
if hasattr(proto, "opset_import"):
|
|
502
|
-
text = self.
|
|
500
|
+
text = self._translate_opset_imports(proto.opset_import)
|
|
503
501
|
if isinstance(proto, FunctionProto):
|
|
504
502
|
if not any(x.domain == proto.domain for x in proto.opset_import):
|
|
505
|
-
text += self.
|
|
503
|
+
text += self._translate_opset_import(proto.domain, 1)
|
|
506
504
|
return text
|
|
507
505
|
return ""
|
|
508
506
|
|
|
509
|
-
def
|
|
507
|
+
def _translate_function_signature(self, funproto: onnx.FunctionProto) -> str:
|
|
510
508
|
"""Generate signature for FunctionProto."""
|
|
511
509
|
type_map = _attribute_param_types(funproto)
|
|
512
510
|
|
|
@@ -527,8 +525,11 @@ class Exporter:
|
|
|
527
525
|
message = ""
|
|
528
526
|
return f"({input_and_attrs}):{message}"
|
|
529
527
|
|
|
530
|
-
def
|
|
528
|
+
def _translate_function(self, funproto: onnx.FunctionProto) -> str:
|
|
531
529
|
"""Generate python code for FunctionProto."""
|
|
530
|
+
opsets = {}
|
|
531
|
+
for imported in funproto.opset_import:
|
|
532
|
+
opsets[imported.domain] = imported.version
|
|
532
533
|
self._attr_renaming = {}
|
|
533
534
|
used_proto_names = _names_used_in_function(funproto)
|
|
534
535
|
renamed_names_used = [self._rename_variable(x) for x in used_proto_names]
|
|
@@ -538,19 +539,94 @@ class Exporter:
|
|
|
538
539
|
def add_line(line: str) -> None:
|
|
539
540
|
result.append(line)
|
|
540
541
|
|
|
541
|
-
opset_name = self.
|
|
542
|
+
opset_name = self._make_opset_name(funproto.domain, 1)
|
|
542
543
|
add_line(f"@script({opset_name})")
|
|
543
544
|
fun_name = self._python_make_node_name(funproto.domain, 1, funproto.name)
|
|
544
|
-
fun_sig = self.
|
|
545
|
+
fun_sig = self._translate_function_signature(funproto)
|
|
545
546
|
add_line(f"def {fun_name}{fun_sig}")
|
|
546
547
|
if funproto.doc_string:
|
|
547
548
|
add_line(f' """{funproto.doc_string}"""')
|
|
548
549
|
for node in funproto.node:
|
|
549
|
-
add_line(self._python_make_node(node,
|
|
550
|
+
add_line(self._python_make_node(node, opsets, indent=1))
|
|
550
551
|
return_values = ", ".join(self._rename_variable(x) for x in funproto.output)
|
|
551
552
|
add_line(f" return {return_values}")
|
|
552
553
|
return "\n".join(result)
|
|
553
554
|
|
|
555
|
+
def _translate_graph(self, model: onnx.ModelProto, function_name: str) -> str:
|
|
556
|
+
graph = model.graph
|
|
557
|
+
opsets = {}
|
|
558
|
+
for imported in model.opset_import:
|
|
559
|
+
opsets[imported.domain] = imported.version
|
|
560
|
+
|
|
561
|
+
result: list[str] = []
|
|
562
|
+
|
|
563
|
+
def add(line: str) -> None:
|
|
564
|
+
result.append(line)
|
|
565
|
+
|
|
566
|
+
add("@script()")
|
|
567
|
+
add(f"def {function_name}{_translate_signature(graph.input, graph.output)}")
|
|
568
|
+
doc = graph.doc_string
|
|
569
|
+
if doc:
|
|
570
|
+
add(f' """{doc}"""')
|
|
571
|
+
add(self._python_make_node_graph(graph, opsets, indent=1))
|
|
572
|
+
return_values = ", ".join(self._rename_variable(x) for x in graph.output)
|
|
573
|
+
add(f" return {return_values}")
|
|
574
|
+
return "\n".join(result)
|
|
575
|
+
|
|
576
|
+
def _import_onnx_types(
|
|
577
|
+
self, proto: onnx.ModelProto | onnx.GraphProto | onnx.FunctionProto
|
|
578
|
+
) -> str:
|
|
579
|
+
"""Generate import statements for types used in the graph."""
|
|
580
|
+
if isinstance(proto, ModelProto):
|
|
581
|
+
graph_or_function = proto.graph
|
|
582
|
+
else:
|
|
583
|
+
graph_or_function = proto
|
|
584
|
+
used_types: set[str] = set()
|
|
585
|
+
for t in list(graph_or_function.input) + list(graph_or_function.output):
|
|
586
|
+
if hasattr(t, "type"):
|
|
587
|
+
ts = _translate_type(t.type)
|
|
588
|
+
its = ts.split("[", maxsplit=1)[0]
|
|
589
|
+
used_types.add(its)
|
|
590
|
+
# TODO: handle types in nested graphs.
|
|
591
|
+
sorted_types = sorted(used_types)
|
|
592
|
+
if sorted_types:
|
|
593
|
+
return "from onnxscript.onnx_types import " + ", ".join(sorted_types)
|
|
594
|
+
return ""
|
|
595
|
+
|
|
596
|
+
def export(self, proto: onnx.ModelProto | onnx.FunctionProto, function_name: str) -> str:
|
|
597
|
+
result: list[str] = []
|
|
598
|
+
|
|
599
|
+
def add(line: str) -> None:
|
|
600
|
+
result.append(line)
|
|
601
|
+
|
|
602
|
+
# Generic imports.
|
|
603
|
+
add("import numpy")
|
|
604
|
+
add("from onnx import TensorProto")
|
|
605
|
+
add("from onnx.helper import make_tensor")
|
|
606
|
+
add("from onnxscript import script, external_tensor")
|
|
607
|
+
add("from onnxscript.values import Opset")
|
|
608
|
+
add(self._import_onnx_types(proto))
|
|
609
|
+
|
|
610
|
+
if isinstance(proto, ModelProto):
|
|
611
|
+
translated_functions = [self._translate_function(f) for f in proto.functions]
|
|
612
|
+
translated_functions.append(self._translate_graph(proto, function_name))
|
|
613
|
+
else:
|
|
614
|
+
assert isinstance(proto, FunctionProto)
|
|
615
|
+
# TODO: use function_name?
|
|
616
|
+
translated_functions = [self._translate_function(proto)]
|
|
617
|
+
|
|
618
|
+
# TODO: unique_function_domain_version.add((f.domain, 1))
|
|
619
|
+
add(self._translate_opset_imports_of(proto))
|
|
620
|
+
result.extend(translated_functions)
|
|
621
|
+
|
|
622
|
+
add("")
|
|
623
|
+
final = "\n".join(result)
|
|
624
|
+
|
|
625
|
+
if "\nreturn" in final:
|
|
626
|
+
raise SyntaxError(f"The produced code is wrong.\n{final}")
|
|
627
|
+
|
|
628
|
+
return final
|
|
629
|
+
|
|
554
630
|
|
|
555
631
|
def _attribute_param_types(
|
|
556
632
|
funproto: onnx.FunctionProto,
|
|
@@ -577,131 +653,6 @@ def _attribute_param_types(
|
|
|
577
653
|
return type_map
|
|
578
654
|
|
|
579
655
|
|
|
580
|
-
def export_template(
|
|
581
|
-
model_onnx,
|
|
582
|
-
template,
|
|
583
|
-
name=None,
|
|
584
|
-
function_name="main_function",
|
|
585
|
-
use_operators=False,
|
|
586
|
-
rename=False,
|
|
587
|
-
inline_const: bool = False,
|
|
588
|
-
):
|
|
589
|
-
"""Exports an ONNX model into a code based on a template.
|
|
590
|
-
|
|
591
|
-
Args:
|
|
592
|
-
model_onnx: string or ONNX graph
|
|
593
|
-
template: exporting template
|
|
594
|
-
name: to overwrite onnx name
|
|
595
|
-
function_name: main function name in the code
|
|
596
|
-
use_operators: use Python operators.
|
|
597
|
-
rename: rename variable name to get shorter names
|
|
598
|
-
inline_const: replace ONNX constants inline if compact
|
|
599
|
-
|
|
600
|
-
Returns:
|
|
601
|
-
python code
|
|
602
|
-
"""
|
|
603
|
-
|
|
604
|
-
if rename:
|
|
605
|
-
variable_names: dict[str, str] = {}
|
|
606
|
-
|
|
607
|
-
def rename_variable(name):
|
|
608
|
-
var_name = _rename_variable(name)
|
|
609
|
-
if var_name in variable_names:
|
|
610
|
-
return variable_names[var_name]
|
|
611
|
-
new_name = f"v{len(variable_names) + 1}"
|
|
612
|
-
assert var_name is not None # TODO(rama): This looks suspect.
|
|
613
|
-
variable_names[var_name] = new_name
|
|
614
|
-
return new_name
|
|
615
|
-
|
|
616
|
-
else:
|
|
617
|
-
|
|
618
|
-
def rename_variable(name):
|
|
619
|
-
return _rename_variable(name)
|
|
620
|
-
|
|
621
|
-
exporter = Exporter(rename_variable, use_operators, inline_const)
|
|
622
|
-
|
|
623
|
-
# containers
|
|
624
|
-
context = {
|
|
625
|
-
"main_model": model_onnx,
|
|
626
|
-
"python_make_node": exporter._python_make_node, # pylint: disable=protected-access
|
|
627
|
-
"python_make_node_graph": exporter._python_make_node_graph, # pylint: disable=protected-access
|
|
628
|
-
"python_make_node_name": exporter._python_make_node_name, # pylint: disable=protected-access
|
|
629
|
-
"rename": rename_variable,
|
|
630
|
-
"translate_sig": _translate_signature,
|
|
631
|
-
"translate_function_signature": exporter.translate_function_signature,
|
|
632
|
-
"translate_function": exporter.translate_function,
|
|
633
|
-
"translate_opset_imports_of": exporter.translate_opset_imports_of,
|
|
634
|
-
"hasattr": hasattr,
|
|
635
|
-
"make_opset_name": exporter.make_opset_name,
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
# opset
|
|
639
|
-
if hasattr(model_onnx, "opset_import"):
|
|
640
|
-
opsets = {}
|
|
641
|
-
for oimp in model_onnx.opset_import:
|
|
642
|
-
opsets[oimp.domain] = oimp.version
|
|
643
|
-
context["opsets"] = opsets
|
|
644
|
-
exporter.opsets = opsets
|
|
645
|
-
|
|
646
|
-
graph = model_onnx.graph if hasattr(model_onnx, "graph") else model_onnx
|
|
647
|
-
|
|
648
|
-
# types
|
|
649
|
-
unique_types = set()
|
|
650
|
-
for t in list(graph.input) + list(graph.output):
|
|
651
|
-
if hasattr(t, "type"):
|
|
652
|
-
ts = _translate_type(t.type)
|
|
653
|
-
its = ts.split("[", maxsplit=1)[0]
|
|
654
|
-
unique_types.add(its)
|
|
655
|
-
context["unique_types"] = sorted(unique_types)
|
|
656
|
-
|
|
657
|
-
# functions
|
|
658
|
-
functions = []
|
|
659
|
-
unique_function_domain_version = set()
|
|
660
|
-
|
|
661
|
-
def add_function(f: FunctionProto) -> None:
|
|
662
|
-
opsets = {}
|
|
663
|
-
for oimp in f.opset_import:
|
|
664
|
-
opsets[oimp.domain] = oimp.version
|
|
665
|
-
functions.append((f.domain, f.name, {"proto": f, "opsets": opsets}))
|
|
666
|
-
unique_function_domain_version.add((f.domain, 1))
|
|
667
|
-
|
|
668
|
-
if hasattr(model_onnx, "functions"):
|
|
669
|
-
for f in model_onnx.functions:
|
|
670
|
-
add_function(f)
|
|
671
|
-
else:
|
|
672
|
-
assert isinstance(model_onnx, FunctionProto)
|
|
673
|
-
add_function(model_onnx)
|
|
674
|
-
|
|
675
|
-
context["functions"] = functions
|
|
676
|
-
context["unique_function_domain_version"] = sorted(unique_function_domain_version)
|
|
677
|
-
context["graph"] = graph if isinstance(graph, onnx.GraphProto) else None
|
|
678
|
-
|
|
679
|
-
# graph
|
|
680
|
-
context["name"] = name or graph.name
|
|
681
|
-
context["function_name"] = function_name
|
|
682
|
-
if hasattr(model_onnx, "graph"):
|
|
683
|
-
context["doc_string"] = model_onnx.doc_string
|
|
684
|
-
else:
|
|
685
|
-
context["doc_string"] = ""
|
|
686
|
-
|
|
687
|
-
# First rendering to detect any unused or replaced initializer.
|
|
688
|
-
# pylint: disable=import-outside-toplevel
|
|
689
|
-
from jinja2 import Template # delayed import
|
|
690
|
-
|
|
691
|
-
# pylint: enable=import-outside-toplevel
|
|
692
|
-
|
|
693
|
-
template = Template(template)
|
|
694
|
-
final = template.render(
|
|
695
|
-
enumerate=enumerate, sorted=sorted, len=len, repr=repr, map=map, list=list, **context
|
|
696
|
-
)
|
|
697
|
-
|
|
698
|
-
final += "\n"
|
|
699
|
-
if "\nreturn" in final:
|
|
700
|
-
raise SyntaxError(f"The produced code is wrong.\n{final}")
|
|
701
|
-
|
|
702
|
-
return final
|
|
703
|
-
|
|
704
|
-
|
|
705
656
|
def export2python(
|
|
706
657
|
model_onnx,
|
|
707
658
|
opset=None,
|
|
@@ -745,18 +696,12 @@ def export2python(
|
|
|
745
696
|
"""
|
|
746
697
|
del opset # unused
|
|
747
698
|
del verbose # unused
|
|
699
|
+
del name # unused
|
|
748
700
|
if isinstance(model_onnx, str):
|
|
749
701
|
model_onnx = onnx.load(model_onnx)
|
|
750
702
|
|
|
751
703
|
if not isinstance(model_onnx, (ModelProto, FunctionProto)):
|
|
752
704
|
raise TypeError(f"The function expects a ModelProto not {type(model_onnx)!r}.")
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
name=name,
|
|
757
|
-
function_name=function_name,
|
|
758
|
-
use_operators=use_operators,
|
|
759
|
-
rename=rename,
|
|
760
|
-
inline_const=inline_const,
|
|
761
|
-
)
|
|
762
|
-
return code
|
|
705
|
+
|
|
706
|
+
exporter = Exporter(rename, use_operators, inline_const)
|
|
707
|
+
return exporter.export(model_onnx, function_name)
|