New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce torch.onnx.dynamo_export API #97920
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/97920
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit f8ed7cc: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
3a01a1a
to
518ab7f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work
518ab7f
to
acc95db
Compare
882c198
to
b2b4d83
Compare
11fdb46
to
4962704
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
eba5d6c
to
388b918
Compare
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 jobs have failed, first few of them are: trunk / linux-bionic-py3.8-clang9-slow / filter Details for Dev Infra teamRaised by workflow job |
521f11c
to
4e87a6a
Compare
This is the first phase of the new ONNX exporter API for exporting from TorchDynamo and FX, and represents the beginning of a new era for exporting ONNX from PyTorch. The API here is a starting point upon which we will layer more capability and expressiveness in subsequent phases. This first phase introduces the following into `torch.onnx`: dynamo_export( model: torch.nn.Module, /, *model_args, export_options: Optional[ExportOptions] = None, **model_kwargs, ) -> ExportOutput class ExportOptions: opset_version: Optional[int] = None dynamic_shapes: Optional[bool] = None logger: Optional[logging.Logger] = None class ExportOutputSerializer(Protocol): def serialize( self, export_output: ExportOutput, destination: io.BufferedIOBase ) -> None: ... class ExportOutput: export_options: ExportOptions model_proto: onnx.ModelProto def save( self, destination: Union[str, io.BufferedIOBase], *, serializer: Optional[ExportOutputSerializer] = None ) -> None: ... Co-authored-by: Bowen Bao <bowbao@microsoft.com> Co-authored-by: Aaron Bockover <abock@microsoft.com>
We have a few experiments for exporting Dynamo and FX to ONNX that this PR rationalizes through the new Exporter API and adjusts tests to use the new API. - A base FXGraphModuleExporter exporter from which all derive: - DynamoExportExporter: uses dynamo.export to acquire FX graph - DynamoOptimizeExporter: uses dynamo.optimize to acquire FX graph - FXSymbolicTraceExporter: uses FX symbolic tracing The dynamo_export API currently uses DynamoOptimizeExporter.
4e87a6a
to
f8ed7cc
Compare
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
This is the first phase of the new ONNX exporter API for exporting from TorchDynamo and FX, and represents the beginning of a new era for exporting ONNX from PyTorch. The API here is a starting point upon which we will layer more capability and expressiveness in subsequent phases. This first phase introduces the following into `torch.onnx`: ```python dynamo_export( model: torch.nn.Module, /, *model_args, export_options: Optional[ExportOptions] = None, **model_kwargs, ) -> ExportOutput: ... class ExportOptions: opset_version: Optional[int] = None dynamic_shapes: Optional[bool] = None logger: Optional[logging.Logger] = None class ExportOutputSerializer(Protocol): def serialize( self, export_output: ExportOutput, destination: io.BufferedIOBase, ) -> None: ... class ExportOutput: model_proto: onnx.ModelProto def save( self, destination: Union[str, io.BufferedIOBase], *, serializer: Optional[ExportOutputSerializer] = None, ) -> None: ... ``` In addition to the API in the first commit on this PR, we have a few experiments for exporting Dynamo and FX to ONNX that this PR rationalizes through the new Exporter API and adjusts tests to use the new API. - A base `FXGraphModuleExporter` exporter from which all derive: - `DynamoExportExporter`: uses dynamo.export to acquire FX graph - `DynamoOptimizeExporter`: uses dynamo.optimize to acquire FX graph - `FXSymbolicTraceExporter`: uses FX symbolic tracing The `dynamo_export` API currently uses `DynamoOptimizeExporter`. ### Next Steps (subsequent PRs): * Combine `DynamoExportExporter` and `DynamoOptimizeExporter` into a single `DynamoExporter`. * Make it easy to test `FXSymbolicTraceExporter` through the same API; eventually `FXSymbolicTraceExporter` goes away entirely when the Dynamo approach works for large models. We want to keep `FXSymbolicTraceExporter` around for now for experimenting and internal use. * Parameterize (on `ExportOptions`) and consolidate Dynamo exporter tests. - This PR intentionally leaves the existing tests unchanged as much as possible except for the necessary plumbing. * Subsequent API phases: - Diagnostics - Registry, dispatcher, and Custom Ops - Passes - Dynamic shapes Fixes #94774 Pull Request resolved: #97920 Approved by: https://github.com/justinchuby, https://github.com/titaiwangms, https://github.com/thiagocrepaldi, https://github.com/shubhambhokare1
This is the first phase of the new ONNX exporter API for exporting from TorchDynamo and FX, and represents the beginning of a new era for exporting ONNX from PyTorch.
The API here is a starting point upon which we will layer more capability and expressiveness in subsequent phases. This first phase introduces the following into
torch.onnx
:In addition to the API in the first commit on this PR, we have a few experiments for exporting Dynamo and FX to ONNX that this PR rationalizes through the new Exporter API and adjusts tests to use the new API.
FXGraphModuleExporter
exporter from which all derive:DynamoExportExporter
: uses dynamo.export to acquire FX graphDynamoOptimizeExporter
: uses dynamo.optimize to acquire FX graphFXSymbolicTraceExporter
: uses FX symbolic tracingThe
dynamo_export
API currently usesDynamoOptimizeExporter
.Next Steps (subsequent PRs):
DynamoExportExporter
andDynamoOptimizeExporter
into a singleDynamoExporter
.FXSymbolicTraceExporter
through the same API; eventuallyFXSymbolicTraceExporter
goes away entirely when the Dynamo approach works for large models. We want to keepFXSymbolicTraceExporter
around for now for experimenting and internal use.ExportOptions
) and consolidate Dynamo exporter tests.Fixes #94774