已合并
test: adapt debug_set_autodiff_subgraph_inlining for NPU #41607
test: adapt debug_set_autodiff_subgraph_inlining for NPU #41607
已合并
yulin520创建于 7月14日
1 个文件变更+66-0
Atest_upstream/test/jit/test_autodiff_subgraph_slicing.py.patch+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+@@ -25,6 +25,7 @@ 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+@@ -41,7 +42,7 @@ 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+@@ -65,7 +66,7 @@ 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+@@ -331,7 +332,7 @@ 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+@@ -391,7 +392,7 @@ 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+@@ -404,7 +405,7 @@ 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+@@ -419,7 +420,7 @@ 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+