Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dynamo torch.Tensor.new test. #6661

Merged
merged 4 commits into from
Apr 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions test/dynamo/test_dynamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,31 @@ def test_all_cpu_tensor(self):
self.assertIn('MarkStep', met.counter_names())


class DynamoOperationsTests(test_utils.XlaTestCase):

def test_new_with_sizes(self):

# The addition operation is needed here, since the error only occurs when FakeTensorMode
# checks the device of the arguments of some operation. If there's no operation using the
# result of Tensor.new, this comparison never occurs.
def foo(x):
return x.new(*x.size()) + x

optfoo = torch.compile(backend="openxla")(foo)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol is it a new way of calling compile? it used to be torch.compile(foo, backend="openxla")


t = torch.arange(9)
Xt = t.to(xm.xla_device())

expected = foo(t)
actual = optfoo(Xt).cpu()

# Here, we don't expect the actual data to be the same. Reason being that Tensor.new
# returns uninitialized data.
self.assertEqual(expected.shape, actual.shape)
self.assertEqual(expected.dtype, actual.dtype)
self.assertEqual(expected.device, actual.device)


if __name__ == '__main__':
test = unittest.main()
sys.exit(0 if test.result.wasSuccessful() else 1)
Loading