Fix new_zeros and new_empty without args.
This commit is contained in:
@@ -520,6 +520,8 @@ class TestNpu(TestCase):
|
||||
x = torch.ones(()).npu()
|
||||
x_new_empty = x.new_empty((2, 3), dtype=torch.float16, device='npu')
|
||||
res = x_new_empty + 1
|
||||
x_new_empty = x.new_empty(size=(2, 3), dtype=torch.float16, device='npu')
|
||||
res = x_new_empty + 1
|
||||
|
||||
def test_function_tensor_new_empty_strided(self):
|
||||
x = torch.ones(()).npu()
|
||||
@@ -558,9 +560,11 @@ class TestNpu(TestCase):
|
||||
npu_output1 = x.new_ones((2, 3), device=None, requires_grad=False)
|
||||
npu_output2 = x.new_ones((2, 3), device='cpu', requires_grad=False)
|
||||
npu_output3 = x.new_ones((2, 3), device='npu', requires_grad=False)
|
||||
npu_output4 = x.new_ones(size=(2, 3), device='npu', requires_grad=False)
|
||||
self.assertRtolEqual(cpu_out.numpy(), npu_output1.cpu().numpy())
|
||||
self.assertRtolEqual(cpu_out.numpy(), npu_output2.cpu().numpy())
|
||||
self.assertRtolEqual(cpu_out.numpy(), npu_output3.cpu().numpy())
|
||||
self.assertRtolEqual(cpu_out.numpy(), npu_output4.cpu().numpy())
|
||||
|
||||
def test_function_tensor_new_tensor(self):
|
||||
x_cpu = torch.tensor((), dtype=torch.float32)
|
||||
@@ -602,9 +606,11 @@ class TestNpu(TestCase):
|
||||
npu_output1 = x.new_zeros((2, 3), device=None, requires_grad=False)
|
||||
npu_output2 = x.new_zeros((2, 3), device='cpu', requires_grad=False)
|
||||
npu_output3 = x.new_zeros((2, 3), device='npu', requires_grad=False)
|
||||
npu_output4 = x.new_zeros(size=(2, 3), device='npu', requires_grad=False)
|
||||
self.assertRtolEqual(cpu_out.numpy(), npu_output1.cpu().numpy())
|
||||
self.assertRtolEqual(cpu_out.numpy(), npu_output2.cpu().numpy())
|
||||
self.assertRtolEqual(cpu_out.numpy(), npu_output3.cpu().numpy())
|
||||
self.assertRtolEqual(cpu_out.numpy(), npu_output4.cpu().numpy())
|
||||
|
||||
def test_type_conversions_npu(self):
|
||||
x = torch.randn(5, 5)
|
||||
|
||||
@@ -111,7 +111,7 @@ def _storage(self):
|
||||
|
||||
@torch_device_guard
|
||||
def _new_empty(self, *args, **kwargs):
|
||||
if isinstance(args[0], int):
|
||||
if args and isinstance(args[0], int):
|
||||
list_args = list(args)
|
||||
sizes = []
|
||||
for item in list_args:
|
||||
@@ -173,7 +173,7 @@ def _new_tensor(self, *args, **kwargs):
|
||||
|
||||
@torch_device_guard
|
||||
def _new_zeros(self, *args, **kwargs):
|
||||
if isinstance(args[0], int):
|
||||
if args and isinstance(args[0], int):
|
||||
list_args = list(args)
|
||||
sizes = []
|
||||
for item in list_args:
|
||||
|
||||
Reference in New Issue
Block a user