Skip to content
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

[ONNX] Support ONNXFakeContext with op_level_debug #105874

Closed
wants to merge 2 commits into from

Conversation

titaiwangms
Copy link
Collaborator

@titaiwangms titaiwangms commented Jul 24, 2023

Stack from ghstack (oldest at bottom):

Previous to the PR, op_level_debug doesn't support OnnxFakeConext because it relies on real tensor in args to do shape type inference propagation in fx graph to get static shapes helping simulating the op args/kwargs. However, OnnxFakeContext will fakify the args/kwargs at the very begining, so the op_level_debug can't have the static_shapes to utilize.

This PR uses SymInt API: has_hint and hint_int to fully replace the functionality of shape type inference propagation. The static shapes are obtained through SymInt. Therefore, the pass ShapeInferenceWithFakeTensor is eliminated.

Also moved the args/kwargs processing into op_validation to live under the rule op_level_debug.

@pytorch-bot
Copy link

pytorch-bot bot commented Jul 24, 2023

🔗 Helpful Links

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

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit f76d61c:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot bot added the release notes: onnx torch.onnx related changes that should show up in the release notes label Jul 24, 2023
titaiwangms added a commit that referenced this pull request Jul 24, 2023
ghstack-source-id: 0c0e27f87b8a70ae171d5642d755b1637b6c7ba9
Pull Request resolved: #105874
@titaiwangms titaiwangms marked this pull request as draft July 24, 2023 21:40
@titaiwangms titaiwangms added module: onnx Related to torch.onnx topic: bug fixes topic category labels Jul 24, 2023
@titaiwangms titaiwangms marked this pull request as ready for review July 24, 2023 21:49
Copy link
Collaborator

@thiagocrepaldi thiagocrepaldi left a comment

Choose a reason for hiding this comment

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

LGTM, just minor nits

torch/onnx/_internal/exporter.py Outdated Show resolved Hide resolved
torch/onnx/_internal/fx/op_validation.py Show resolved Hide resolved
torch/onnx/_internal/fx/op_validation.py Show resolved Hide resolved
list_int_shape.append(symbolic_shapes.hint_int(dim))
else:
raise ValueError(
f"Unexpected SymInt found in shape. SymInt: {dim}; "
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this unexpected, or is it a case we can expect but cannot handle? Just to make sure for clarity.

Copy link
Collaborator

Choose a reason for hiding this comment

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

nice catch, overlooked this one. Please reveal keyword "unbacked", will easily lead to many helpful resources such as this https://pytorch-dev-podcast.simplecast.com/episodes/unbacked-symints-oyqu0_P6

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Previous to the PR, op_level_debug doesn't support OnnxFakeConext because it relies on real tensor in args to do shape type inference propagation in fx graph to get static shapes helping simulating the op args/kwargs. However, OnnxFakeContext will fakify the args/kwargs at the very begining, so the op_level_debug can't have the static_shapes to utilize.

This PR uses SymInt API: `has_hint` and `hint_int` to fully replace the functionality of shape type inference propagation. The static shapes are obtained through SymInt. Therefore, the pass `ShapeInferenceWithFakeTensor` is eliminated.

Also moved the args/kwargs processing into op_validation to live under the rule `op_level_debug`.

[ghstack-poisoned]
titaiwangms added a commit that referenced this pull request Jul 25, 2023
ghstack-source-id: 19a82b4636e3400e93aa498108549b3be7a6c864
Pull Request resolved: #105874
@titaiwangms titaiwangms added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 25, 2023
@titaiwangms
Copy link
Collaborator Author

@pytorchbot merge

@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

@facebook-github-bot facebook-github-bot deleted the gh/titaiwangms/34/head branch July 28, 2023 14:22
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: bug fixes topic category
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants