已合并
[fix]add empty_with_swapped_memory ut #30887
梁松伟创建于 2月13日
[fix]add empty_with_swapped_memory ut #30887
已合并
梁松伟创建于 2月13日
1 个文件变更+9-2
@@ -19,7 +19,6 @@ import torch_npu
19from torch_npu.testing.common_utils import SupportedDevices19from torch_npu.testing.common_utils import SupportedDevices
20 20 
21 21 
22- 
23class TestNPUSwappedMemoryAllocator(unittest.TestCase):22class TestNPUSwappedMemoryAllocator(unittest.TestCase):
24 23 
25 def setUp(self):24 def setUp(self):
@@ -54,7 +53,6 @@ class TestNPUSwappedMemoryAllocator(unittest.TestCase):
54 torch.npu.empty_cache()53 torch.npu.empty_cache()
55 gc.collect()54 gc.collect()
56 55 
57- 
58 @SupportedDevices(['Ascend910B'])56 @SupportedDevices(['Ascend910B'])
59 def test_02_async_operations_and_release(self):57 def test_02_async_operations_and_release(self):
60 """Test 2: Async operations followed by release (verify stream sync works)"""58 """Test 2: Async operations followed by release (verify stream sync works)"""
@@ -72,6 +70,15 @@ class TestNPUSwappedMemoryAllocator(unittest.TestCase):
72 70
73 tensor.sqrt_()71 tensor.sqrt_()
74 72
73+ expected_tensor = torch.empty([512, 512], dtype=torch.float32, device='npu:0')
74+ expected_tensor.fill_(1.0)
75+ for i in range(10):
76+ expected_tensor = expected_tensor * 1.1
77+ expected_tensor = expected_tensor + i * 0.1
78+ expected_tensor = expected_tensor.sqrt()
79+
80+ self.assertTrue(torch.allclose(tensor, expected_tensor, rtol=1e-5, atol=1e-5))
81+
75 weak_ref = weakref.ref(tensor)82 weak_ref = weakref.ref(tensor)
76 del tensor83 del tensor
77 gc.collect()84 gc.collect()