mirror of
https://github.com/pytorch/pytorch.git
synced 2026-10-28 18:56:51 +08:00
This PR is to make TestNN cases generated by add_test() device agnostic, for this purpose we updated common code in common_nn.py, including ModuleTest and NewModuleTest, and renamed test_cuda() to test_acclerator(). As a result the test code test/test_expanded_weights.py and test/cpp_api_parity/* and test/test_cpp_api_parity.py that also referenced the common_nn and test_cuda had to be updated in the same PR. 1. rename ModuleTest method test_cuda to test_accelerator and make the function device agnostic 2. rename CriterionTest method test_cuda to test_accelerator and make the function device agnostic 3. make common_utils.to_gpu device agnostic. 4. enable xpu in test_nn.py add_test() 5. Updated test/test_expanded_weights.py and test/cpp_api_parity/* and test/test_cpp_api_parity.py to align with common_nn updates. 6. in original test_nn add_test() the _cuda* variants unconditionally skipped at runtime on CPU, so on CPU-only machines (including every dynamo_wrapped shard) those tests disappear from collection entirely rather than being reported as skipped. -> This PR used `if torch.accelerator.is_available():` to constrains only accelerator will run. Pull Request resolved: https://github.com/pytorch/pytorch/pull/189653 Approved by: https://github.com/etaf, https://github.com/jansel