已合并
test(fx): add CustomBuiltin test cases for v2.10.0. #35582
olpk创建于 5月13日
test(fx): add CustomBuiltin test cases for v2.10.0. #35582
已合并
共 1 个文件变更+61-0
| @@ -0,0 +1,61 @@ | |||
| 1 | +# Owner(s): ["module: test"] | ||
| 2 | + | ||
| 3 | +""" | ||
| 4 | +Add test cases for torch.fx APIs on NPU: | ||
| 5 | + | ||
| 6 | +PyTorch community lacks sufficient and direct API validations for some FX internal APIs, so this file is added. | ||
| 7 | +This file validates: | ||
| 8 | +- torch.fx.graph._custom_builtins | ||
| 9 | +- torch.fx.graph._CustomBuiltin | ||
| 10 | +- torch.fx.experimental.symbolic_shapes.SymbolicContext | ||
| 11 | + | ||
| 12 | +These APIs are internal to PyTorch FX and have no direct test coverage in community test_fx.py. | ||
| 13 | +All tests are NPU-agnostic (framework-level only). | ||
| 14 | +""" | ||
| 15 | + | ||
| 16 | +import torch | ||
| 17 | + | ||
| 18 | +from torch.fx.experimental.symbolic_shapes import SymbolicContext | ||
| 19 | +from torch.fx.graph import _custom_builtins, _CustomBuiltin | ||
| 20 | +from torch.testing._internal.common_utils import run_tests, TestCase | ||
| 21 | + | ||
| 22 | + | ||
| 23 | +class TestFxCustomBuiltins(TestCase): | ||
| 24 | + | ||
| 25 | + def test_custom_builtins_items(self): | ||
| 26 | + items = _custom_builtins.items() | ||
| 27 | + self.assertIsNotNone(items) | ||
| 28 | + items_list = list(items) | ||
| 29 | + self.assertGreater(len(items_list), 0) | ||
| 30 | + for k, v in items_list: | ||
| 31 | + self.assertIsInstance(k, str) | ||
| 32 | + self.assertIsInstance(v, _CustomBuiltin) | ||
| 33 | + | ||
| 34 | + def test_CustomBuiltin_type(self): | ||
| 35 | + self.assertIsNotNone(_CustomBuiltin) | ||
| 36 | + self.assertEqual( | ||
| 37 | + _CustomBuiltin.__module__, | ||
| 38 | + "torch.fx.graph", | ||
| 39 | + ) | ||
| 40 | + | ||
| 41 | + def test_CustomBuiltin_instance(self): | ||
| 42 | + builtin = _custom_builtins["inf"] | ||
| 43 | + self.assertIsNotNone(builtin) | ||
| 44 | + self.assertIsInstance(builtin, _CustomBuiltin) | ||
| 45 | + | ||
| 46 | + def test_SymbolicContext_import(self): | ||
| 47 | + self.assertIsNotNone(SymbolicContext) | ||
| 48 | + self.assertEqual( | ||
| 49 | + SymbolicContext.__module__, | ||
| 50 | + "torch.fx.experimental.symbolic_shapes", | ||
| 51 | + ) | ||
| 52 | + | ||
| 53 | + def test_SymbolicContext_instance(self): | ||
| 54 | + ctx = SymbolicContext() | ||
| 55 | + self.assertIsNotNone(ctx) | ||
| 56 | + self.assertIsInstance(ctx, SymbolicContext) | ||
| 57 | + | ||
| 58 | + | ||
| 59 | +if __name__ == "__main__": | ||
| 60 | + run_tests() | ||
| 61 | + | ||