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
Add support for models with mutated buffer on torch.onnx.dynamo_export #112272
Add support for models with mutated buffer on torch.onnx.dynamo_export #112272
Conversation
`run_test_with_fx_to_onnx_exporter_and_onnx_runtime` had to be extended to allow extra outputs on the ONNX graph due to extra outputs due to mutated inputs and buffers [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/112272
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit ce48b3d with merge base 88a8a0d (): FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
`run_test_with_fx_to_onnx_exporter_and_onnx_runtime` had to be extended to allow extra outputs on the ONNX graph due to extra outputs due to mutated inputs and buffers ghstack-source-id: 4ef89ce32fecf1ecb3bd996b76ce65e1880c864b Pull Request resolved: #112272
…tated buffer" `run_test_with_fx_to_onnx_exporter_and_onnx_runtime` had to be extended to allow extra outputs on the ONNX graph due to extra outputs due to mutated inputs and buffers [ghstack-poisoned]
`run_test_with_fx_to_onnx_exporter_and_onnx_runtime` had to be extended to allow extra outputs on the ONNX graph due to extra outputs due to mutated inputs and buffers ghstack-source-id: 979da739bfeeb9fcadc498e53d2afba1374de9c4 Pull Request resolved: #112272
…tated buffer" `run_test_with_fx_to_onnx_exporter_and_onnx_runtime` had to be extended to allow extra outputs on the ONNX graph due to extra outputs due to mutated inputs and buffers [ghstack-poisoned]
…tated buffer" `run_test_with_fx_to_onnx_exporter_and_onnx_runtime` had to be extended to allow extra outputs on the ONNX graph due to extra outputs due to mutated inputs and buffers [ghstack-poisoned]
…tated buffer" `run_test_with_fx_to_onnx_exporter_and_onnx_runtime` had to be extended to allow extra outputs on the ONNX graph due to extra outputs due to mutated inputs and buffers [ghstack-poisoned]
…tated buffer" `run_test_with_fx_to_onnx_exporter_and_onnx_runtime` had to be extended to allow extra outputs on the ONNX graph due to extra outputs due to mutated inputs and buffers [ghstack-poisoned]
…tated buffer" `run_test_with_fx_to_onnx_exporter_and_onnx_runtime` had to be extended to allow extra outputs on the ONNX graph due to extra outputs due to mutated inputs and buffers [ghstack-poisoned]
…tated buffer" `run_test_with_fx_to_onnx_exporter_and_onnx_runtime` had to be extended to allow extra outputs on the ONNX graph due to extra outputs due to mutated inputs and buffers [ghstack-poisoned]
…tated buffer" `run_test_with_fx_to_onnx_exporter_and_onnx_runtime` had to be extended to allow extra outputs on the ONNX graph due to extra outputs due to mutated inputs and buffers [ghstack-poisoned]
…tated buffer" `run_test_with_fx_to_onnx_exporter_and_onnx_runtime` had to be extended to allow extra outputs on the ONNX graph due to extra outputs due to mutated inputs and buffers [ghstack-poisoned]
…ynamo_export" This PR adds a unit test that leverages `torch.export.ExportedProgram` models that mutates registered buffers. Although the exporter already works out of the box in such scenario, the GraphModule and the exported ONNX model have extra outputs containing the mutated buffers. On future runs of the ONNX model, the mutated buffers are used as input to the model. The aforementioned extra inputs and outputs are by design and the `ONNXProgram.model_signature` can be used to fetch detailed input/output schema for the exported model. However, when we want to compare pytorch output to ONNX's, there is a mismatch between the schema because pytorch output does not include the mutated buffers present on the ONNX output. This PR extends `onnx_program.adapt_torch_outputs_to_onnx(torch_outputs)` so that the mutated buffers are prepended to the Pytorch output, matching the ONNX schema. [ghstack-poisoned]
…ynamo_export" This PR adds a unit test that leverages `torch.export.ExportedProgram` models that mutates registered buffers. Although the exporter already works out of the box in such scenario, the GraphModule and the exported ONNX model have extra outputs containing the mutated buffers. On future runs of the ONNX model, the mutated buffers are used as input to the model. The aforementioned extra inputs and outputs are by design and the `ONNXProgram.model_signature` can be used to fetch detailed input/output schema for the exported model. However, when we want to compare pytorch output to ONNX's, there is a mismatch between the schema because pytorch output does not include the mutated buffers present on the ONNX output. This PR extends `onnx_program.adapt_torch_outputs_to_onnx(torch_outputs)` so that the mutated buffers are prepended to the Pytorch output, matching the ONNX schema. [ghstack-poisoned]
@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 |
|
||
# ONNXProgram holds a reference (not copy) to the original ref_model, including its state_dict. | ||
# Thus, ONNXProgram() must run before ref_model() to prevent ref_model.forward() from changing the state_dict. | ||
# Otherwise, the ref_model can change buffers on state_dict which would be used by ONNXProgram.__call__() |
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.
I recall there was a PR that will make ONNXProgram.call() update original pytorch model lol. This problem will arise again if that's added.
Btw there is a flag has_mutation
up there that triggers model cloning. Might be helpful.
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.
that pr was merged with this one.
@pytorchbot revert -m 'Sorry for reverting you change but it is failing dynamo test in trunk https://hud.pytorch.org/pytorch/pytorch/commit/c4a22d6918b7ca218f2712d7e7e147aca7127fa3' -c weird |
@pytorchbot successfully started a revert job. Check the current status here. |
@thiagocrepaldi your PR has been successfully reverted. |
…mo_export (#112272)" This reverts commit c4a22d6. Reverted #112272 on behalf of https://github.com/huydhn due to Sorry for reverting you change but it is failing dynamo test in trunk https://hud.pytorch.org/pytorch/pytorch/commit/c4a22d6918b7ca218f2712d7e7e147aca7127fa3 ([comment](#112272 (comment)))
It looks like the revert doesn't help, I will reland the change. Sorry for the churn. |
@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 |
pytorch#112272) This PR adds a unit test that leverages `torch.export.ExportedProgram` models that mutates registered buffers. Although the exporter already works out of the box in such scenario, the GraphModule and the exported ONNX model have extra outputs containing the mutated buffers. On future runs of the ONNX model, the mutated buffers are used as input to the model. The aforementioned extra inputs and outputs are by design and the `ONNXProgram.model_signature` can be used to fetch detailed input/output schema for the exported model. However, when we want to compare pytorch output to ONNX's, there is a mismatch between the schema because pytorch output does not include the mutated buffers present on the ONNX output. This PR extends `onnx_program.adapt_torch_outputs_to_onnx(torch_outputs)` so that the mutated buffers are prepended to the Pytorch output, matching the ONNX schema. Pull Request resolved: pytorch#112272 Approved by: https://github.com/titaiwangms, https://github.com/BowenBao
…mo_export (pytorch#112272)" This reverts commit c4a22d6. Reverted pytorch#112272 on behalf of https://github.com/huydhn due to Sorry for reverting you change but it is failing dynamo test in trunk https://hud.pytorch.org/pytorch/pytorch/commit/c4a22d6918b7ca218f2712d7e7e147aca7127fa3 ([comment](pytorch#112272 (comment)))
pytorch#112272) This PR adds a unit test that leverages `torch.export.ExportedProgram` models that mutates registered buffers. Although the exporter already works out of the box in such scenario, the GraphModule and the exported ONNX model have extra outputs containing the mutated buffers. On future runs of the ONNX model, the mutated buffers are used as input to the model. The aforementioned extra inputs and outputs are by design and the `ONNXProgram.model_signature` can be used to fetch detailed input/output schema for the exported model. However, when we want to compare pytorch output to ONNX's, there is a mismatch between the schema because pytorch output does not include the mutated buffers present on the ONNX output. This PR extends `onnx_program.adapt_torch_outputs_to_onnx(torch_outputs)` so that the mutated buffers are prepended to the Pytorch output, matching the ONNX schema. Pull Request resolved: pytorch#112272 Approved by: https://github.com/titaiwangms, https://github.com/BowenBao
Stack from ghstack (oldest at bottom):
This PR adds a unit test that leverages
torch.export.ExportedProgram
models that mutates registered buffers. Although the exporter already works out of the box in such scenario, the GraphModule and the exported ONNX model have extra outputs containing the mutated buffers. On future runs of the ONNX model, the mutated buffers are used as input to the model.The aforementioned extra inputs and outputs are by design and the
ONNXProgram.model_signature
can be used to fetch detailed input/output schema for the exported model.However, when we want to compare pytorch output to ONNX's, there is a mismatch between the schema because pytorch output does not include the mutated buffers present on the ONNX output.
This PR extends
onnx_program.adapt_torch_outputs_to_onnx(torch_outputs)
so that the mutated buffers are prepended to the Pytorch output, matching the ONNX schema.