-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Adapt test_misc.py to HPUs #147609
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
Adapt test_misc.py to HPUs #147609
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/147609
Note: Links to docs will display an error until the docs builds have been completed. ❌ 12 New FailuresAs of commit dba2f05 with merge base bd019c0 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@ankurneog , @EikanWang , @yanboliang , @guangyey : please review this PR. |
| res = opt_func(a) | ||
| self.assertIsInstance(res, torch.Tensor) | ||
|
|
||
| # @unittest.skipIf(not TEST_CUDA, "requires cuda") |
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.
| # @unittest.skipIf(not TEST_CUDA, "requires cuda") |
| self.assertEqual(res.device.index, 0) | ||
| self.assertEqual(counter.frame_count, 2) | ||
|
|
||
| def test_torch_device_python_type(self): |
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.
| def test_torch_device_python_type(self): | |
| def test_torch_device_python_type(self, device): |
| @unittest.skipIf(not torch.cuda.is_available(), "Test requires CUDA.") | ||
| def test_symint_as_device_kwarg_non_strict_export(self): |
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.
Does this case cannot work well on HPU?
| else: | ||
| return x - 1 | ||
|
|
||
| x = torch.rand(4) |
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.
The x is a CPU tensor. How does it verify the CUDA and HPU path?
| # FIXME(XuehaiPan): do not inline infinite generator if it does not raise errors in eager mode | ||
| def fn(x): | ||
| def gen(): | ||
| while True: | ||
| yield x | ||
|
|
||
| return list(zip(range(10), gen())) | ||
|
|
||
| x = torch.randn([0, 1, 2, 3, 4, 5]) | ||
| compiled_fn = torch.compile(fn, backend="eager", fullgraph=True) | ||
| with self.assertRaisesRegex( | ||
| torch._dynamo.exc.Unsupported, "infinite generator" | ||
| ): | ||
| compiled_fn(x) | ||
|
|
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.
Duplicated code block.
|
|
||
| def write_state(state): | ||
| torch.set_grad_enabled(state[0]) | ||
| torch.set_grad_enabled(state[0]), |
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.
| torch.set_grad_enabled(state[0]), | |
| torch.set_grad_enabled(state[0]) |
| torch.set_grad_enabled(state[0]), | ||
| torch.use_deterministic_algorithms(state[1]) | ||
| torch._C._set_cublas_allow_tf32(state[2]) | ||
| torch._C._set_cublas_allow_tf32(state[2]), |
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.
| torch._C._set_cublas_allow_tf32(state[2]), | |
| torch._C._set_cublas_allow_tf32(state[2]) |
| torch.cuda.set_device(1) | ||
| return a + 1 | ||
|
|
||
| with torch.cuda.device(0): |
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.
This case is device-specific. It should be decorated by requires_cuda.
| _, ne = run(torch.ones(1)) | ||
| self.assertFalse(ne) | ||
|
|
||
| def test_ne_operator_with_custom_ne(self): |
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.
ditto
|
|
||
| torch.allclose(inp1_custom.grad, inp1_usual.grad) | ||
|
|
||
| def test_retain_grad(self): |
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.
ditto
|
The review comments and merge conflicts will be addressed in a separate PR. |
This PR is related to #145476 . That PR had two files (test_functions.py and test_misc.py) . test_functions was causing CI/rebase/merge issues and hence removed for now. This PR contains only test_misc.py. This is a continuation of #144387 . ## MOTIVATION We recently integrated support for Intel Gaudi devices (identified as 'hpu') into the common_device_type framework via the pull request at #126970. This integration allows tests to be automatically instantiated for Gaudi devices upon loading the relevant library. Building on this development, the current pull request extends the utility of these hooks by adapting selected CUDA tests to operate on Gaudi devices. Additionally, we have confirmed that these modifications do not interfere with the existing tests on CUDA devices. Other accelerators can also extend the functionality by adding the device in the devices list. ( For eg: xpu ) ## CHANGES Create a separate class for test functions running on CUDA devices Extend the functionality of these tests to include HPUs Use instantiate_device_type_tests with targeted attributes to generate device-specific test instances within the new classes Apply skipIfHPU decorator to bypass tests that are not yet compatible with HPU devices PS: Most of these changes were initially part of #147609 , but closed that PR due to merge conflicts. The review comments were handled in this PR. Pull Request resolved: #149499 Approved by: https://github.com/EikanWang, https://github.com/desertfire, https://github.com/cyyever
This PR is related to pytorch#145476 . That PR had two files (test_functions.py and test_misc.py) . test_functions was causing CI/rebase/merge issues and hence removed for now. This PR contains only test_misc.py. This is a continuation of pytorch#144387 . ## MOTIVATION We recently integrated support for Intel Gaudi devices (identified as 'hpu') into the common_device_type framework via the pull request at pytorch#126970. This integration allows tests to be automatically instantiated for Gaudi devices upon loading the relevant library. Building on this development, the current pull request extends the utility of these hooks by adapting selected CUDA tests to operate on Gaudi devices. Additionally, we have confirmed that these modifications do not interfere with the existing tests on CUDA devices. Other accelerators can also extend the functionality by adding the device in the devices list. ( For eg: xpu ) ## CHANGES Create a separate class for test functions running on CUDA devices Extend the functionality of these tests to include HPUs Use instantiate_device_type_tests with targeted attributes to generate device-specific test instances within the new classes Apply skipIfHPU decorator to bypass tests that are not yet compatible with HPU devices PS: Most of these changes were initially part of pytorch#147609 , but closed that PR due to merge conflicts. The review comments were handled in this PR. Pull Request resolved: pytorch#149499 Approved by: https://github.com/EikanWang, https://github.com/desertfire, https://github.com/cyyever
This PR is related to pytorch#145476 . That PR had two files (test_functions.py and test_misc.py) . test_functions was causing CI/rebase/merge issues and hence removed for now. This PR contains only test_misc.py. This is a continuation of pytorch#144387 . ## MOTIVATION We recently integrated support for Intel Gaudi devices (identified as 'hpu') into the common_device_type framework via the pull request at pytorch#126970. This integration allows tests to be automatically instantiated for Gaudi devices upon loading the relevant library. Building on this development, the current pull request extends the utility of these hooks by adapting selected CUDA tests to operate on Gaudi devices. Additionally, we have confirmed that these modifications do not interfere with the existing tests on CUDA devices. Other accelerators can also extend the functionality by adding the device in the devices list. ( For eg: xpu ) ## CHANGES Create a separate class for test functions running on CUDA devices Extend the functionality of these tests to include HPUs Use instantiate_device_type_tests with targeted attributes to generate device-specific test instances within the new classes Apply skipIfHPU decorator to bypass tests that are not yet compatible with HPU devices PS: Most of these changes were initially part of pytorch#147609 , but closed that PR due to merge conflicts. The review comments were handled in this PR. Pull Request resolved: pytorch#149499 Approved by: https://github.com/EikanWang, https://github.com/desertfire, https://github.com/cyyever
This PR is related to #145476 . That PR had two files (test_functions.py and test_misc.py) . test_functions was causing CI/rebase/merge issues and hence removed for now. This PR contains only test_misc.py.
This is a continuation of #144387 .
MOTIVATION
We recently integrated support for Intel Gaudi devices (identified as 'hpu') into the common_device_type framework via the pull request at #126970. This integration allows tests to be automatically instantiated for Gaudi devices upon loading the relevant library. Building on this development, the current pull request extends the utility of these hooks by adapting selected CUDA tests to operate on Gaudi devices. Additionally, we have confirmed that these modifications do not interfere with the existing tests on CUDA devices.
Other accelerators can also extend the functionality by adding the device in the devices list. ( For eg: xpu )
CHANGES
Create a separate class for test functions running on CUDA devices
Extend the functionality of these tests to include HPUs
Use instantiate_device_type_tests with targeted attributes to generate device-specific test instances within the new classes
Apply skipIfHPU decorator to bypass tests that are not yet compatible with HPU devices
cc: @ankurneog , @EikanWang , @yanboliang , @guangyey
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames