已合并
fix(nn): fix test for nn api: torch.nn.ParameterDict, torch.nn.ParameterList, torch.nn.Sequential #32056
dinglaiping创建于 3月19日
fix(nn): fix test for nn api: torch.nn.ParameterDict, torch.nn.ParameterList, torch.nn.Sequential #32056
已合并
从已删除 :fixtest-nn-api-2.7.1合入到Ascend/pytorchv2.7.1
共 2 个文件变更+17-9
| @@ -32,17 +32,18 @@ from torch.types import _TensorOrTensors | |||
| 32 | from url import get_url | 32 | from url import get_url |
| 33 | import torch_npu | 33 | import torch_npu |
| 34 | import torch_npu.testing | 34 | import torch_npu.testing |
| 35 | +from torch_npu.testing.common_utils import SupportedDevices | ||
| 35 | from torch.testing._internal.common_dtype import integral_types, get_all_math_dtypes, floating_types | 36 | from torch.testing._internal.common_dtype import integral_types, get_all_math_dtypes, floating_types |
| 36 | from torch.testing._internal.common_utils import freeze_rng_state, run_tests, TestCase, skipIfNoLapack, skipIfRocm, \ | 37 | from torch.testing._internal.common_utils import freeze_rng_state, run_tests, TestCase, skipIfNoLapack, skipIfRocm, \ |
| 37 | TEST_NUMPY, TEST_SCIPY, TEST_WITH_CROSSREF, TEST_WITH_ROCM, \ | 38 | TEST_NUMPY, TEST_SCIPY, TEST_WITH_CROSSREF, TEST_WITH_ROCM, \ |
| 38 | - download_file, get_function_arglist, load_tests, skipIfMps, \ | 39 | + download_file, get_function_arglist, load_tests, skipIfMPS, \ |
| 39 | IS_PPC, TEST_PRIVATEUSE1, custom_device_mod, \ | 40 | IS_PPC, TEST_PRIVATEUSE1, custom_device_mod, \ |
| 40 | parametrize as parametrize_test, subtest, instantiate_parametrized_tests, \ | 41 | parametrize as parametrize_test, subtest, instantiate_parametrized_tests, \ |
| 41 | skipIfTorchDynamo, IS_WINDOWS, gcIfJetson, set_default_dtype | 42 | skipIfTorchDynamo, IS_WINDOWS, gcIfJetson, set_default_dtype |
| 42 | from torch.testing._internal.common_cuda import TEST_CUDNN, TEST_CUDNN_VERSION, PLATFORM_SUPPORTS_FLASH_ATTENTION | 43 | from torch.testing._internal.common_cuda import TEST_CUDNN, TEST_CUDNN_VERSION, PLATFORM_SUPPORTS_FLASH_ATTENTION |
| 43 | from torch.testing._internal.common_nn import NNTestCase, NewModuleTest, CriterionTest, \ | 44 | from torch.testing._internal.common_nn import NNTestCase, NewModuleTest, CriterionTest, \ |
| 44 | module_tests, criterion_tests, loss_reference_fns, _create_basic_net, \ | 45 | module_tests, criterion_tests, loss_reference_fns, _create_basic_net, \ |
| 45 | - ctcloss_reference, new_module_tests, single_batch_reference_fn, _test_bfloat16_ops, _test_module_empty_input | 46 | + ctcloss_reference, get_new_module_tests, single_batch_reference_fn, _test_bfloat16_ops, _test_module_empty_input |
| 46 | from torch.testing._internal.common_device_type import instantiate_device_type_tests, dtypes, \ | 47 | from torch.testing._internal.common_device_type import instantiate_device_type_tests, dtypes, \ |
| 47 | precisionOverride, skipCUDAIfCudnnVersionLessThan, onlyCPU, \ | 48 | precisionOverride, skipCUDAIfCudnnVersionLessThan, onlyCPU, \ |
| 48 | skipCUDAIfRocm, skipCUDAIf, skipCUDAIfNotRocm, \ | 49 | skipCUDAIfRocm, skipCUDAIf, skipCUDAIfNotRocm, \ |
| @@ -54,10 +55,10 @@ import torch.testing._internal.hypothesis_utils as hu | |||
| 54 | from torch.testing._internal.common_utils import _assertGradAndGradgradChecks, gradcheck, gradgradcheck, \ | 55 | from torch.testing._internal.common_utils import _assertGradAndGradgradChecks, gradcheck, gradgradcheck, \ |
| 55 | GRADCHECK_NONDET_TOL | 56 | GRADCHECK_NONDET_TOL |
| 56 | from torch.testing._internal.common_utils import dtype2prec_DONTUSE | 57 | from torch.testing._internal.common_utils import dtype2prec_DONTUSE |
| 57 | -from torch.testing._internal.common_cuda import tf32_on_and_off, tf32_is_not_fp32, tf32_off, tf32_on | 58 | +from torch.testing._internal.common_cuda import tf32_on_and_off, tf32_off, tf32_on |
| 58 | 59 | ||
| 59 | 60 | ||
| 60 | -AMPERE_OR_ROCM = TEST_WITH_ROCM or tf32_is_not_fp32() | 61 | +AMPERE_OR_ROCM = TEST_WITH_ROCM or torch.cuda.is_tf32_supported() |
| 61 | 62 | ||
| 62 | # load_tests from common_utils is used to automatically filter tests for | 63 | # load_tests from common_utils is used to automatically filter tests for |
| 63 | # sharding on sandcastle. This line silences flake warnings | 64 | # sharding on sandcastle. This line silences flake warnings |
| @@ -7439,7 +7440,7 @@ def add_test(test_tmp, decorator=None): | |||
| 7439 | kwargs['extra_args'] = test_tmp.extra_args | 7440 | kwargs['extra_args'] = test_tmp.extra_args |
| 7440 | 7441 | ||
| 7441 | if 'dtype' in get_function_arglist(test_tmp.test_cuda): | 7442 | if 'dtype' in get_function_arglist(test_tmp.test_cuda): |
| 7442 | - if tf32_is_not_fp32() and test_tmp.with_tf32: | 7443 | + if torch.cuda.is_tf32_supported() and test_tmp.with_tf32: |
| 7443 | 7444 | ||
| 7444 | def with_tf32_off(self, test_tmp=test_tmp, kwargs=kwargs): | 7445 | def with_tf32_off(self, test_tmp=test_tmp, kwargs=kwargs): |
| 7445 | with tf32_off(): | 7446 | with tf32_off(): |
| @@ -7482,7 +7483,7 @@ def add_test(test_tmp, decorator=None): | |||
| 7482 | with tf32_off(): | 7483 | with tf32_off(): |
| 7483 | test_tmp.test_cuda(self, **kwargs) | 7484 | test_tmp.test_cuda(self, **kwargs) |
| 7484 | 7485 | ||
| 7485 | - if tf32_is_not_fp32() and test_tmp.with_tf32: | 7486 | + if torch.cuda.is_tf32_supported() and test_tmp.with_tf32: |
| 7486 | add(cuda_test_name + '_fp32', with_tf32_off) | 7487 | add(cuda_test_name + '_fp32', with_tf32_off) |
| 7487 | 7488 | ||
| 7488 | def with_tf32_on(self, test_tmp=test_tmp, kwargs=kwargs): | 7489 | def with_tf32_on(self, test_tmp=test_tmp, kwargs=kwargs): |
| @@ -7494,7 +7495,7 @@ def add_test(test_tmp, decorator=None): | |||
| 7494 | add(cuda_test_name, with_tf32_off) | 7495 | add(cuda_test_name, with_tf32_off) |
| 7495 | 7496 | ||
| 7496 | 7497 | ||
| 7497 | -for test_params in module_tests + new_module_tests: | 7498 | +for test_params in module_tests + get_new_module_tests(): |
| 7498 | if 'constructor' not in test_params: | 7499 | if 'constructor' not in test_params: |
| 7499 | name = test_params.pop('module_name') | 7500 | name = test_params.pop('module_name') |
| 7500 | test_params['constructor'] = getattr(nn, name) | 7501 | test_params['constructor'] = getattr(nn, name) |
| @@ -9598,6 +9599,7 @@ class TestNNDeviceType(NNTestCase): | |||
| 9598 | 9599 | ||
| 9599 | 9600 | ||
| 9600 | 9601 | ||
| 9602 | + | ||
| 9601 | def test_upsamplingNearestExact2d_correctness(self, device, memory_format, isize, osize): | 9603 | def test_upsamplingNearestExact2d_correctness(self, device, memory_format, isize, osize): |
| 9602 | in_t = torch.arange(isize * isize, dtype=torch.float, device=device).reshape(1, 1, isize, isize) | 9604 | in_t = torch.arange(isize * isize, dtype=torch.float, device=device).reshape(1, 1, isize, isize) |
| 9603 | in_t = in_t.contiguous(memory_format=memory_format) | 9605 | in_t = in_t.contiguous(memory_format=memory_format) |
| @@ -9691,6 +9693,7 @@ class TestNNDeviceType(NNTestCase): | |||
| 9691 | 9693 | ||
| 9692 | 9694 | ||
| 9693 | 9695 | ||
| 9696 | + | ||
| 9694 | def test_upsamplingNearestExact3d_correctness(self, device, memory_format, isize, osize): | 9697 | def test_upsamplingNearestExact3d_correctness(self, device, memory_format, isize, osize): |
| 9695 | in_t = torch.arange(isize * isize * isize, dtype=torch.float, device=device) | 9698 | in_t = torch.arange(isize * isize * isize, dtype=torch.float, device=device) |
| 9696 | in_t = in_t.reshape(1, 1, isize, isize, isize) | 9699 | in_t = in_t.reshape(1, 1, isize, isize, isize) |
| @@ -9788,6 +9791,7 @@ class TestNNDeviceType(NNTestCase): | |||
| 9788 | 9791 | ||
| 9789 | 9792 | ||
| 9790 | 9793 | ||
| 9794 | + | ||
| 9791 | def test_upsamplingBiMode2d_nonsupported_dtypes(self, device, antialias, num_channels, mode, dtype): | 9795 | def test_upsamplingBiMode2d_nonsupported_dtypes(self, device, antialias, num_channels, mode, dtype): |
| 9792 | x = torch.ones(1, num_channels, 32, 32, dtype=dtype, device=device) | 9796 | x = torch.ones(1, num_channels, 32, 32, dtype=dtype, device=device) |
| 9793 | 9797 | ||
| @@ -10606,7 +10610,7 @@ class TestNNDeviceType(NNTestCase): | |||
| 10606 | self.assertEqual(logits_soft.grad, logits_hard.grad, atol=tol, rtol=0) | 10610 | self.assertEqual(logits_soft.grad, logits_hard.grad, atol=tol, rtol=0) |
| 10607 | 10611 | ||
| 10608 | 10612 | ||
| 10609 | - @skipIfMps | 10613 | + @skipIfMPS |
| 10610 | 10614 | ||
| 10611 | def test_gumbel_softmax(self, device, dtype): | 10615 | def test_gumbel_softmax(self, device, dtype): |
| 10612 | self._test_gumbel_softmax_st_shapes(device, dtype, shape=[5], dim=0, count_expected=1) | 10616 | self._test_gumbel_softmax_st_shapes(device, dtype, shape=[5], dim=0, count_expected=1) |
| @@ -31650,5 +31650,9 @@ | |||
| 31650 | "test_fake_autocast_fft_fftshift_npu_float32 (__main__.TestFakeTensorPRIVATEUSE1)": ["", [""]], | 31650 | "test_fake_autocast_fft_fftshift_npu_float32 (__main__.TestFakeTensorPRIVATEUSE1)": ["", [""]], |
| 31651 | "test_fake_autocast_fft_ifftshift_npu_float32 (__main__.TestFakeTensorPRIVATEUSE1)": ["", [""]], | 31651 | "test_fake_autocast_fft_ifftshift_npu_float32 (__main__.TestFakeTensorPRIVATEUSE1)": ["", [""]], |
| 31652 | "test_index_put_accumulate_large_tensor_npu (__main__.TestIndexingPRIVATEUSE1)": ["", ["910A"]], | 31652 | "test_index_put_accumulate_large_tensor_npu (__main__.TestIndexingPRIVATEUSE1)": ["", ["910A"]], |
| 31653 | - "test_serialization_array_with_empty (__main__.TestNpu)": ["", [""]] | 31653 | + "test_serialization_array_with_empty (__main__.TestNpu)": ["", [""]], |
| 31654 | + "test_module_backcompat (__main__.TestNN)": ["", [""]], | ||
| 31655 | + "test_register_state_dict_pre_hook_backward_compat (__main__.TestNN)": ["", [""]], | ||
| 31656 | + "test_CTCLoss_empty_target_npu (__main__.TestNNDeviceTypePRIVATEUSE1)": ["", [""]], | ||
| 31657 | + "test_to_complex_npu (__main__.TestNNDeviceTypePRIVATEUSE1)": ["", [""]] | ||
| 31654 | } | 31658 | } |