已合并
test: adapt debug_set_autodiff_subgraph_inlining for NPU #41607
yulin520创建于 7月14日
test: adapt debug_set_autodiff_subgraph_inlining for NPU #41607
已合并
共 1 个文件变更+66-0
| @@ -0,0 +1,66 @@ | |||
| 1 | +diff --git a/test/jit/test_autodiff_subgraph_slicing.py b/test/jit/test_autodiff_subgraph_slicing.py | ||
| 2 | +index fe8a5e0..f1f311b 100644 | ||
| 3 | +--- a/test/jit/test_autodiff_subgraph_slicing.py | ||
| 4 | ++++ b/test/jit/test_autodiff_subgraph_slicing.py | ||
| 5 | + from torch.testing._internal.jit_utils import ( | ||
| 6 | + disable_autodiff_subgraph_inlining, | ||
| 7 | + JitTestCase, | ||
| 8 | + ) | ||
| 9 | ++import torch_npu # noqa: F401 | ||
| 10 | + | ||
| 11 | + | ||
| 12 | + if GRAPH_EXECUTOR is None: | ||
| 13 | + class TestAutodiffSubgraphSlicing(JitTestCase): | ||
| 14 | + with disable_autodiff_subgraph_inlining(): | ||
| 15 | + with enable_profiling_mode_for_profiling_tests(): | ||
| 16 | + ge = torch.jit.script(fn) | ||
| 17 | +- inputs = [torch.randn(size, requires_grad=True) for size in input_sizes] | ||
| 18 | ++ inputs = [torch.randn(size).npu().requires_grad_() for size in input_sizes] | ||
| 19 | + ge(*inputs, profile_and_replay=True) | ||
| 20 | + return ge.graph_for(*inputs) | ||
| 21 | + | ||
| 22 | + class TestAutodiffSubgraphSlicing(JitTestCase): | ||
| 23 | + x1, x2 = torch.chunk(x, 2) | ||
| 24 | + return (x1, x2) | ||
| 25 | + | ||
| 26 | +- input = torch.rand(6, 10).requires_grad_() | ||
| 27 | ++ input = torch.rand(6, 10).npu().requires_grad_() | ||
| 28 | + with disable_autodiff_subgraph_inlining(): | ||
| 29 | + with enable_profiling_mode_for_profiling_tests(): | ||
| 30 | + func(input, profile_and_replay=True) | ||
| 31 | + class TestAutodiffSubgraphSlicing(JitTestCase): | ||
| 32 | + # o --> x | ||
| 33 | + def fn(x, y, z): | ||
| 34 | + a = x * y | ||
| 35 | +- b = torch.zeros([abs(int(y))]) | ||
| 36 | ++ b = torch.zeros([abs(int(y))], device=y.device) | ||
| 37 | + return a, b | ||
| 38 | + | ||
| 39 | + graph = self._perform_ad_subgraph_slicing(fn, 1, 1, 1) | ||
| 40 | + class TestAutodiffSubgraphSlicing(JitTestCase): | ||
| 41 | + # \_________/ | ||
| 42 | + def fn(w, x, y): | ||
| 43 | + a = w * x | ||
| 44 | +- b = torch.zeros(abs(int(a))) | ||
| 45 | ++ b = torch.zeros(abs(int(a)), device=a.device) | ||
| 46 | + c = a * b | ||
| 47 | + return c | ||
| 48 | + | ||
| 49 | + class TestAutodiffSubgraphSlicing(JitTestCase): | ||
| 50 | + # \_________/ | ||
| 51 | + def fn(w, x, y, z): | ||
| 52 | + a = w * x | ||
| 53 | +- b = torch.zeros(abs(int(y))) | ||
| 54 | ++ b = torch.zeros(abs(int(y)), device=y.device) | ||
| 55 | + c = a * z | ||
| 56 | + return b, c | ||
| 57 | + | ||
| 58 | + class TestAutodiffSubgraphSlicing(JitTestCase): | ||
| 59 | + # \_________/ | ||
| 60 | + def fn(v, w, x, y): | ||
| 61 | + a = v * w | ||
| 62 | +- b = torch.ones(int(y)) | ||
| 63 | ++ b = torch.ones(int(y), device=y.device) | ||
| 64 | + c = b * a | ||
| 65 | + return a, c | ||
| 66 | + | ||