|
| 1 | +# Parse local options first, and rewrite the sys.argv[]. |
| 2 | +# We need to do that before import "common", as otherwise we get an error for |
| 3 | +# unrecognized arguments. |
| 4 | +import argparse |
| 5 | +import sys |
| 6 | + |
| 7 | +parser = argparse.ArgumentParser(add_help=False) |
| 8 | +parser.add_argument('--replicated', action='store_true') |
| 9 | +parser.add_argument('--long_test', action='store_true') |
| 10 | +parser.add_argument('--max_diff_count', type=int, default=25) |
| 11 | +parser.add_argument('--verbosity', type=int, default=0) |
| 12 | +FLAGS, leftovers = parser.parse_known_args() |
| 13 | +sys.argv = [sys.argv[0]] + leftovers |
| 14 | + |
| 15 | +# Normal imports section starts here. |
| 16 | +import torch |
| 17 | +import torch_xla |
| 18 | +import torch_xla.utils.utils as xu |
| 19 | +import torch_xla.core.xla_model as xm |
| 20 | +import torch_xla.debug.metrics as met |
| 21 | +import unittest |
| 22 | + |
| 23 | + |
| 24 | +class TestOperationsHlo(unittest.TestCase): |
| 25 | + |
| 26 | + def setUp(self): |
| 27 | + super(TestOperationsHlo, self).setUp() |
| 28 | + |
| 29 | + def tearDown(self): |
| 30 | + super(TestOperationsHlo, self).tearDown() |
| 31 | + |
| 32 | + def test_expand(self): |
| 33 | + a = torch.rand(1, 5, device=xm.xla_device()) |
| 34 | + b = a.expand(5, 5) |
| 35 | + hlo_text = torch_xla._XLAC._get_xla_tensors_text([b]) |
| 36 | + assert 'aten::expand' in hlo_text |
| 37 | + |
| 38 | + |
| 39 | +if __name__ == '__main__': |
| 40 | + torch.set_default_tensor_type('torch.FloatTensor') |
| 41 | + torch.manual_seed(42) |
| 42 | + torch_xla._XLAC._xla_set_use_full_mat_mul_precision( |
| 43 | + use_full_mat_mul_precision=True) |
| 44 | + test = unittest.main(verbosity=FLAGS.verbosity, exit=False) |
| 45 | + if xu.getenv_as('METRICS_DEBUG', bool, defval=False): |
| 46 | + print(met.metrics_report()) |
| 47 | + sys.exit(0 if test.result.wasSuccessful() else 1) |
0 commit comments