Skip to content

[ONNX] Expose the testing module#162495

Closed
justinchuby wants to merge 3 commits intopytorch:mainfrom
justinchuby:justinchu/onnx-testing
Closed

[ONNX] Expose the testing module#162495
justinchuby wants to merge 3 commits intopytorch:mainfrom
justinchuby:justinchu/onnx-testing

Conversation

@justinchuby
Copy link
Collaborator

@justinchuby justinchuby commented Sep 9, 2025

  • Created a new module torch/onnx/testing.py that exposes the assert_onnx_program function for testing exported ONNX models.
  • Updated the ONNX documentation (docs/source/onnx.md) to include onnx_testing in the list of relevant modules.

cc @titaiwangms

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@pytorch-bot pytorch-bot bot added the release notes: onnx torch.onnx related changes that should show up in the release notes label Sep 9, 2025
@pytorch-bot
Copy link

pytorch-bot bot commented Sep 9, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/162495

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 280a075 with merge base c0142f5 (image):

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.

@justinchuby justinchuby added module: onnx Related to torch.onnx topic: new features topic category labels Sep 9, 2025
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@titaiwangms
Copy link
Collaborator

What is the motivation?

@justinchuby
Copy link
Collaborator Author

I think it is becoming increasingly useful for users to validate their models when we are making dynamo=True as the default. As an example, we are using it in prototypes: https://github.com/jambayk/torch-onnx-models/blob/main/test/rms_norm_test.py

@titaiwangms
Copy link
Collaborator

I think it is becoming increasingly useful for users to validate their models when we are making dynamo=True as the default. As an example, we are using it in prototypes: https://github.com/jambayk/torch-onnx-models/blob/main/test/rms_norm_test.py

Is it like a checker? If so, we can just embed it into the exporter? What do we expect our users do when they find their onnx_program failing to assertion?

@justinchuby
Copy link
Collaborator Author

In the example above, we can use this to compare the exported model with a reference ep: jambayk/torch-onnx-models#1

embed it into the exporter

I would prefer separating it, because this way it is more flexible (we can control and manipulate the onnx_program, for example by updating the onnx ir model first before asserting).

@titaiwangms
Copy link
Collaborator

titaiwangms commented Sep 9, 2025

In the example above, we can use this to compare the exported model with a reference ep: jambayk/torch-onnx-models#1

embed it into the exporter

I would prefer separating it, because this way it is more flexible (we can control and manipulate the onnx_program, for example by updating the onnx ir model first before asserting).

But this sounds like we don't guarantee the validity of the exported model from our API.

onnx_export
onnx_ops
onnx_verification
onnx_testing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a place that we can notify the users where they might want to use this to validate their current onnx_program? right now, I am thinking probably it's for advanced users who do customized model surgery (although I feel like they won't do it in onnx program, they probably directly use onnx ir or model proto instead.)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not entirely sure what the alternative would be?

@justinchuby
Copy link
Collaborator Author

In the example above, we can use this to compare the exported model with a reference ep: jambayk/torch-onnx-models#1

embed it into the exporter

I would prefer separating it, because this way it is more flexible (we can control and manipulate the onnx_program, for example by updating the onnx ir model first before asserting).

But this sounds like we don't guarantee the validity of the exported model from our API.

Maybe we can frame it as "if you want to use custom ops etc. you can use this to verify it"?

@justinchuby
Copy link
Collaborator Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 9, 2025
@pytorchmergebot
Copy link
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

@justinchuby justinchuby linked an issue Sep 10, 2025 that may be closed by this pull request
markc-614 pushed a commit to markc-614/pytorch that referenced this pull request Sep 17, 2025
* Created a new module `torch/onnx/testing.py` that exposes the `assert_onnx_program` function for testing exported ONNX models.
* Updated the ONNX documentation (`docs/source/onnx.md`) to include `onnx_testing` in the list of relevant modules.

Pull Request resolved: pytorch#162495
Approved by: https://github.com/titaiwangms, https://github.com/xadupre
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
* Created a new module `torch/onnx/testing.py` that exposes the `assert_onnx_program` function for testing exported ONNX models.
* Updated the ONNX documentation (`docs/source/onnx.md`) to include `onnx_testing` in the list of relevant modules.

Pull Request resolved: pytorch#162495
Approved by: https://github.com/titaiwangms, https://github.com/xadupre
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
* Created a new module `torch/onnx/testing.py` that exposes the `assert_onnx_program` function for testing exported ONNX models.
* Updated the ONNX documentation (`docs/source/onnx.md`) to include `onnx_testing` in the list of relevant modules.

Pull Request resolved: pytorch#162495
Approved by: https://github.com/titaiwangms, https://github.com/xadupre
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
* Created a new module `torch/onnx/testing.py` that exposes the `assert_onnx_program` function for testing exported ONNX models.
* Updated the ONNX documentation (`docs/source/onnx.md`) to include `onnx_testing` in the list of relevant modules.

Pull Request resolved: pytorch#162495
Approved by: https://github.com/titaiwangms, https://github.com/xadupre
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged module: onnx Related to torch.onnx open source release notes: onnx torch.onnx related changes that should show up in the release notes topic: new features topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ONNX] Expose torch.onnx.testing

5 participants