已合并
fix(nn): fix test for nn api: torch.nn.ParameterDict, torch.nn.ParameterList, torch.nn.Sequential #32058
dinglaiping创建于 3月19日
fix(nn): fix test for nn api: torch.nn.ParameterDict, torch.nn.ParameterList, torch.nn.Sequential #32058
已合并
dinglaiping创建于 3月19日
已删除 :fixtest-nn-api-2.9.0合入到Ascend/pytorchv2.9.0
2 个文件变更+12-9
@@ -35,14 +35,14 @@ import torch_npu.testing
35from torch.testing._internal.common_dtype import integral_types, get_all_math_dtypes, floating_types35from torch.testing._internal.common_dtype import integral_types, get_all_math_dtypes, floating_types
36from torch.testing._internal.common_utils import freeze_rng_state, run_tests, TestCase, skipIfNoLapack, skipIfRocm, \36from 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, \37 TEST_NUMPY, TEST_SCIPY, TEST_WITH_CROSSREF, TEST_WITH_ROCM, \
38- download_file, get_function_arglist, load_tests, skipIfMps, \38+ download_file, get_function_arglist, load_tests, skipIfMPS, \
39 IS_PPC, TEST_PRIVATEUSE1, custom_device_mod, \39 IS_PPC, TEST_PRIVATEUSE1, custom_device_mod, \
40 parametrize as parametrize_test, subtest, instantiate_parametrized_tests, \40 parametrize as parametrize_test, subtest, instantiate_parametrized_tests, \
41 skipIfTorchDynamo, IS_WINDOWS, gcIfJetson, set_default_dtype41 skipIfTorchDynamo, IS_WINDOWS, gcIfJetson, set_default_dtype
42from torch.testing._internal.common_cuda import TEST_CUDNN, TEST_CUDNN_VERSION, PLATFORM_SUPPORTS_FLASH_ATTENTION42from torch.testing._internal.common_cuda import TEST_CUDNN, TEST_CUDNN_VERSION, PLATFORM_SUPPORTS_FLASH_ATTENTION
43from torch.testing._internal.common_nn import NNTestCase, NewModuleTest, CriterionTest, \43from torch.testing._internal.common_nn import NNTestCase, NewModuleTest, CriterionTest, \
44 module_tests, criterion_tests, loss_reference_fns, _create_basic_net, \44 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_input45+ ctcloss_reference, get_new_module_tests, single_batch_reference_fn, _test_bfloat16_ops, _test_module_empty_input
46from torch.testing._internal.common_device_type import instantiate_device_type_tests, dtypes, \46from torch.testing._internal.common_device_type import instantiate_device_type_tests, dtypes, \
47 precisionOverride, skipCUDAIfCudnnVersionLessThan, onlyCPU, \47 precisionOverride, skipCUDAIfCudnnVersionLessThan, onlyCPU, \
48 skipCUDAIfRocm, skipCUDAIf, skipCUDAIfNotRocm, \48 skipCUDAIfRocm, skipCUDAIf, skipCUDAIfNotRocm, \
@@ -54,10 +54,10 @@ import torch.testing._internal.hypothesis_utils as hu
54from torch.testing._internal.common_utils import _assertGradAndGradgradChecks, gradcheck, gradgradcheck, \54from torch.testing._internal.common_utils import _assertGradAndGradgradChecks, gradcheck, gradgradcheck, \
55 GRADCHECK_NONDET_TOL55 GRADCHECK_NONDET_TOL
56from torch.testing._internal.common_utils import dtype2prec_DONTUSE56from 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_on57+from torch.testing._internal.common_cuda import tf32_on_and_off, tf32_off, tf32_on
58 58 
59 59 
60-AMPERE_OR_ROCM = TEST_WITH_ROCM or tf32_is_not_fp32()60+AMPERE_OR_ROCM = TEST_WITH_ROCM or torch.cuda.is_tf32_supported()
61 61 
62# load_tests from common_utils is used to automatically filter tests for62# load_tests from common_utils is used to automatically filter tests for
63# sharding on sandcastle. This line silences flake warnings63# sharding on sandcastle. This line silences flake warnings
@@ -7439,7 +7439,7 @@ def add_test(test_tmp, decorator=None):
7439 kwargs['extra_args'] = test_tmp.extra_args7439 kwargs['extra_args'] = test_tmp.extra_args
7440 7440 
7441 if 'dtype' in get_function_arglist(test_tmp.test_cuda):7441 if 'dtype' in get_function_arglist(test_tmp.test_cuda):
7442- if tf32_is_not_fp32() and test_tmp.with_tf32:7442+ if torch.cuda.is_tf32_supported() and test_tmp.with_tf32:
7443 7443 
7444 def with_tf32_off(self, test_tmp=test_tmp, kwargs=kwargs):7444 def with_tf32_off(self, test_tmp=test_tmp, kwargs=kwargs):
7445 with tf32_off():7445 with tf32_off():
@@ -7482,7 +7482,7 @@ def add_test(test_tmp, decorator=None):
7482 with tf32_off():7482 with tf32_off():
7483 test_tmp.test_cuda(self, **kwargs)7483 test_tmp.test_cuda(self, **kwargs)
7484 7484 
7485- if tf32_is_not_fp32() and test_tmp.with_tf32:7485+ if torch.cuda.is_tf32_supported() and test_tmp.with_tf32:
7486 add(cuda_test_name + '_fp32', with_tf32_off)7486 add(cuda_test_name + '_fp32', with_tf32_off)
7487 7487 
7488 def with_tf32_on(self, test_tmp=test_tmp, kwargs=kwargs):7488 def with_tf32_on(self, test_tmp=test_tmp, kwargs=kwargs):
@@ -7494,7 +7494,7 @@ def add_test(test_tmp, decorator=None):
7494 add(cuda_test_name, with_tf32_off)7494 add(cuda_test_name, with_tf32_off)
7495 7495 
7496 7496 
7497-for test_params in module_tests + new_module_tests:7497+for test_params in module_tests + get_new_module_tests():
7498 if 'constructor' not in test_params:7498 if 'constructor' not in test_params:
7499 name = test_params.pop('module_name')7499 name = test_params.pop('module_name')
7500 test_params['constructor'] = getattr(nn, name)7500 test_params['constructor'] = getattr(nn, name)
@@ -10606,7 +10606,7 @@ class TestNNDeviceType(NNTestCase):
10606 self.assertEqual(logits_soft.grad, logits_hard.grad, atol=tol, rtol=0)10606 self.assertEqual(logits_soft.grad, logits_hard.grad, atol=tol, rtol=0)
10607 10607 
10608 @dtypesIfPRIVATEUSE1(torch.half, torch.float, torch.double)10608 @dtypesIfPRIVATEUSE1(torch.half, torch.float, torch.double)
10609- @skipIfMps10609+ @skipIfMPS
10610 @dtypes(torch.float, torch.double)10610 @dtypes(torch.float, torch.double)
10611 def test_gumbel_softmax(self, device, dtype):10611 def test_gumbel_softmax(self, device, dtype):
10612 self._test_gumbel_softmax_st_shapes(device, dtype, shape=[5], dim=0, count_expected=1)10612 self._test_gumbel_softmax_st_shapes(device, dtype, shape=[5], dim=0, count_expected=1)
@@ -31599,5 +31599,8 @@
31599 "test_replicate (__main__.TestDataParallel)": ["", [""]],31599 "test_replicate (__main__.TestDataParallel)": ["", [""]],
31600 "test_replicate_buffers (__main__.TestDataParallel)": ["", [""]],31600 "test_replicate_buffers (__main__.TestDataParallel)": ["", [""]],
31601 "test_index_put_accumulate_large_tensor_npu (__main__.TestIndexingPRIVATEUSE1)": ["", ["910A"]],31601 "test_index_put_accumulate_large_tensor_npu (__main__.TestIndexingPRIVATEUSE1)": ["", ["910A"]],
31602- "test_serialization_array_with_empty (__main__.TestNpu)": ["", [""]]31602+ "test_serialization_array_with_empty (__main__.TestNpu)": ["", [""]],
31603+ "test_module_backcompat (__main__.TestNN)": ["", [""]],
31604+ "test_register_state_dict_pre_hook_backward_compat (__main__.TestNN)": ["", [""]],
31605+ "test_softmax_forward_64bit_indexing_npu (__main__.TestNNDeviceTypePRIVATEUSE1)": ["", [""]]
31603}31606}