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

Fix exception handling in torch._dynamo.utils.same and add corresponding test #125132

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

KevinHeeHee
Copy link

@KevinHeeHee KevinHeeHee commented Apr 29, 2024

Description:
This PR addresses an issue where the torch._dynamo.utils.same function swallows exceptions raised by torch.allclose without preserving the original exception information. It also adds a new test file to cover the scenario where an exception occurs during the torch.allclose check.

Changes:

  1. Updated exception handling in torch._dynamo.utils.same:
  • Wrapped the torch.allclose check inside a try-except block.
  • In the except block, log the custom error message along with the original exception using logging.exception.
  • Re-raise the original exception to preserve the exception information.
  1. Added a new test file test/dynamo/test_same_allclose.py:
  • Created a new test class TestSameAllclose that inherits from torch._dynamo.test_case.TestCase.
  • Defined two test methods:
    • test_same_allclose_exception: Tests the scenario where torch.allclose raises a RuntimeError due to a size mismatch between input tensors. Asserts that the custom error message and original exception information are present in the raised exception.
    • test_same_allclose_no_exception: Tests the case where no exception is expected, and torch.allclose should return True.
  • Imported the necessary modules: unittest, torch, and same from torch._dynamo.testing.

Benefits:

  • By improving the exception handling when an unexpected error occurs, this helps in debugging and understanding the root cause of the error
  • Adds test coverage and ensures the function behaves as expected
  • Ran testing to verify behavior

Fixes #111075
Please review this pull request and provide any feedback or suggestions for improvement.

Thank you!

cc @ezyang @msaroufim @bdhirsh @anijain2305 @chauhang @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng

…oesn't swallow exceptions and maintains original error context
…rror messages are both not obscured in the case that an exception happens. Also added a test for when an exception is not raised for completeness
Copy link

pytorch-bot bot commented Apr 29, 2024

🔗 Helpful Links

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

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

❌ 13 New Failures, 5 Unrelated Failures

As of commit 427d9f2 with merge base e3b9b71 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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

Copy link

linux-foundation-easycla bot commented Apr 29, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@ezyang ezyang added the topic: not user facing topic category label Apr 29, 2024
Copy link
Contributor

@ezyang ezyang left a comment

Choose a reason for hiding this comment

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

okey dokey

@ezyang
Copy link
Contributor

ezyang commented Apr 29, 2024

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Apr 29, 2024
@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

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@ezyang
Copy link
Contributor

ezyang commented Apr 30, 2024

@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

@pytorchmergebot
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export swallows exception
4 participants