已合并
[sync] PR-38602: 新增torch_npu.npu.are_compatible_impl_enabled和torch_npu.npu.get_amp_supported_dtype接口的测试用例。 #38702
[sync] PR-38602: 新增torch_npu.npu.are_compatible_impl_enabled和torch_npu.npu.get_amp_supported_dtype接口的测试用例。 #38702
已合并
ascend-robot创建于 6月17日
2 个文件变更+16-0
Mtest/npu/test_torch_npu.py+6-0
@@ -458,6 +458,12 @@ print(f"{{r1}}, {{r2}}")
458 except Exception as e:458 except Exception as e:
459 self.assertIn("Overflow when unpacking", str(e), f"{e}")459 self.assertIn("Overflow when unpacking", str(e), f"{e}")
460 460 
461+ def test_use_compatible_impl(self):
462+ old_enabled = torch_npu.npu.are_compatible_impl_enabled()
463+ torch_npu.npu.use_compatible_impl(True)
464+ self.assertTrue(torch_npu.npu.are_compatible_impl_enabled() is True)
465+ torch_npu.npu.use_compatible_impl(old_enabled)
466+ 
461 467 
462if __name__ == "__main__":468if __name__ == "__main__":
463 run_tests()469 run_tests()
Mtest/test_autocast.py+10-0
@@ -280,6 +280,16 @@ class TestAutocastNPU(TestCase):
280 torch_npu.npu.set_autocast_enabled(False)280 torch_npu.npu.set_autocast_enabled(False)
281 self.assertTrue(torch_npu.npu.is_autocast_enabled() is not True)281 self.assertTrue(torch_npu.npu.is_autocast_enabled() is not True)
282 282 
283+ def test_get_amp_supported_dtype(self):
284+ amp_supported_dtypes = torch_npu.npu.get_amp_supported_dtype()
285+ self.assertTrue(torch.float16 in amp_supported_dtypes)
286+ self.assertTrue(torch.float32 in amp_supported_dtypes)
287+ if torch.npu.is_bf16_supported():
288+ self.assertTrue(torch.bfloat16 in amp_supported_dtypes)
289+ self.assertTrue(len(amp_supported_dtypes) == 3)
290+ else:
291+ self.assertTrue(len(amp_supported_dtypes) == 2)
292+ 
283 293 
284@unittest.skipIf(not torch.npu.is_available(), "requires npu")294@unittest.skipIf(not torch.npu.is_available(), "requires npu")
285class TestAutocastNPUfp32(TestCase):295class TestAutocastNPUfp32(TestCase):