已合并
Skip old torch(<=2.2) test case in test/dynamo/test_activate_checkpoint.py #37352
HandsoemLemon创建于 6月1日
Skip old torch(<=2.2) test case in test/dynamo/test_activate_checkpoint.py #37352
已合并
HandsoemLemon创建于 6月1日
1 个文件变更+27-1
@@ -1,6 +1,7 @@
1# Owner(s): ["module: dynamo"]1# Owner(s): ["module: dynamo"]
2import functools2import functools
3import unittest3import unittest
4+from packaging import version
4from importlib import import_module5from importlib import import_module
5 6 
6import torch7import torch
@@ -15,7 +16,11 @@ from torch._dynamo.backends.common import aot_autograd
15from torch._dynamo.testing import CompileCounterWithBackend16from torch._dynamo.testing import CompileCounterWithBackend
16from torch._higher_order_ops.wrap import tag_activation_checkpoint17from torch._higher_order_ops.wrap import tag_activation_checkpoint
17from torch.testing._internal.common_utils import IS_WINDOWS18from torch.testing._internal.common_utils import IS_WINDOWS
18-from torch.utils.checkpoint import _pt2_selective_checkpoint_context_fn_gen, checkpoint19+ 
20+version_skip_test = True
21+if version.parse(torch.__version__) <= version.parse("2.2.0"):
22+ from torch.utils.checkpoint import _pt2_selective_checkpoint_context_fn_gen, checkpoint
23+ version_skip_test = False
19 24 
20requires_npu = functools.partial(unittest.skipIf, not torch.npu.is_available(), "requires npu")25requires_npu = functools.partial(unittest.skipIf, not torch.npu.is_available(), "requires npu")
21 26 
@@ -110,6 +115,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
110 msg="Gradient mismatch between torch.compile and eager versions",115 msg="Gradient mismatch between torch.compile and eager versions",
111 )116 )
112 117 
118+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
113 @requires_npu()119 @requires_npu()
114 def test_tags_function(self):120 def test_tags_function(self):
115 def gn(x, y):121 def gn(x, y):
@@ -128,6 +134,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
128 backend = aot_autograd(fw_compiler=fw_compiler, bw_compiler=bw_compiler)134 backend = aot_autograd(fw_compiler=fw_compiler, bw_compiler=bw_compiler)
129 self._validate(fn, backend, x, y)135 self._validate(fn, backend, x, y)
130 136 
137+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
131 @requires_npu()138 @requires_npu()
132 def test_tags_function_via_global_checkpoint(self):139 def test_tags_function_via_global_checkpoint(self):
133 def gn(x, y):140 def gn(x, y):
@@ -147,6 +154,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
147 backend = aot_autograd(fw_compiler=fw_compiler, bw_compiler=bw_compiler)154 backend = aot_autograd(fw_compiler=fw_compiler, bw_compiler=bw_compiler)
148 self._validate(fn, backend, x, y)155 self._validate(fn, backend, x, y)
149 156 
157+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
150 @requires_npu()158 @requires_npu()
151 def test_tags_function_with_kwargs(self):159 def test_tags_function_with_kwargs(self):
152 def gn(x, y):160 def gn(x, y):
@@ -167,6 +175,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
167 backend = aot_autograd(fw_compiler=fw_compiler, bw_compiler=bw_compiler)175 backend = aot_autograd(fw_compiler=fw_compiler, bw_compiler=bw_compiler)
168 self._validate(fn, backend, x, y)176 self._validate(fn, backend, x, y)
169 177 
178+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
170 @requires_npu()179 @requires_npu()
171 def test_tags_multiple_checkpoints(self):180 def test_tags_multiple_checkpoints(self):
172 def gn(x, y):181 def gn(x, y):
@@ -189,6 +198,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
189 backend = aot_autograd(fw_compiler=fw_compiler, bw_compiler=bw_compiler)198 backend = aot_autograd(fw_compiler=fw_compiler, bw_compiler=bw_compiler)
190 self._validate(fn, backend, x, y)199 self._validate(fn, backend, x, y)
191 200 
201+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
192 @requires_npu()202 @requires_npu()
193 def test_tags_module(self):203 def test_tags_module(self):
194 class MockModule(torch.nn.Module):204 class MockModule(torch.nn.Module):
@@ -215,6 +225,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
215 backend = aot_autograd(fw_compiler=fw_compiler, bw_compiler=bw_compiler)225 backend = aot_autograd(fw_compiler=fw_compiler, bw_compiler=bw_compiler)
216 self._validate(fn, backend, x)226 self._validate(fn, backend, x)
217 227 
228+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
218 @requires_npu()229 @requires_npu()
219 def test_tags_decomps(self):230 def test_tags_decomps(self):
220 # Ensures that tags are passed on through decompositions as well231 # Ensures that tags are passed on through decompositions as well
@@ -248,6 +259,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
248 )259 )
249 self._validate(fn, backend, x)260 self._validate(fn, backend, x)
250 261 
262+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
251 @requires_npu()263 @requires_npu()
252 @torch._inductor.config.patch(fallback_random=True)264 @torch._inductor.config.patch(fallback_random=True)
253 def test_tags_recomputed_rand(self):265 def test_tags_recomputed_rand(self):
@@ -272,6 +284,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
272 backend = "inductor"284 backend = "inductor"
273 self._validate(fn, backend, x, y)285 self._validate(fn, backend, x, y)
274 286 
287+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
275 @requires_npu()288 @requires_npu()
276 @torch._inductor.config.patch(fallback_random=True)289 @torch._inductor.config.patch(fallback_random=True)
277 def test_tags_rand(self):290 def test_tags_rand(self):
@@ -299,6 +312,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
299 backend = "inductor"312 backend = "inductor"
300 self._validate(fn, backend, x, y)313 self._validate(fn, backend, x, y)
301 314 
315+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
302 @requires_npu()316 @requires_npu()
303 @torch._inductor.config.patch(fallback_random=True)317 @torch._inductor.config.patch(fallback_random=True)
304 def test_tags_dropout(self):318 def test_tags_dropout(self):
@@ -322,6 +336,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
322 # rand decomps do not have have numerical results as eager336 # rand decomps do not have have numerical results as eager
323 self._validate(fn, backend, x, skip_check=True)337 self._validate(fn, backend, x, skip_check=True)
324 338 
339+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
325 @requires_npu()340 @requires_npu()
326 def test_fallback(self):341 def test_fallback(self):
327 def gn(x, y):342 def gn(x, y):
@@ -350,6 +365,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
350 self.assertEqual(cnt.op_count, 2)365 self.assertEqual(cnt.op_count, 2)
351 self.assertEqual(len(cnt.graphs), 2)366 self.assertEqual(len(cnt.graphs), 2)
352 367 
368+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
353 @requires_npu()369 @requires_npu()
354 def test_kwargs(self):370 def test_kwargs(self):
355 def gn(x, y, z=None):371 def gn(x, y, z=None):
@@ -384,6 +400,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
384 body_function = getattr(cnt.graphs[0], wrap_node.args[0].name)400 body_function = getattr(cnt.graphs[0], wrap_node.args[0].name)
385 self.assertEqual(op_count(body_function), 2)401 self.assertEqual(op_count(body_function), 2)
386 402 
403+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
387 @requires_npu()404 @requires_npu()
388 def test_symints_location(self):405 def test_symints_location(self):
389 def gn(x, y):406 def gn(x, y):
@@ -414,6 +431,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
414 wrap_node = find_first_node(cnt.graphs[0], tag_activation_checkpoint)431 wrap_node = find_first_node(cnt.graphs[0], tag_activation_checkpoint)
415 self.assertEqual(len(wrap_node.args), 3)432 self.assertEqual(len(wrap_node.args), 3)
416 433 
434+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
417 @unittest.skipIf(IS_WINDOWS, "torch.compile doesn't work with windows")435 @unittest.skipIf(IS_WINDOWS, "torch.compile doesn't work with windows")
418 @torch._dynamo.config.patch(436 @torch._dynamo.config.patch(
419 "_experimental_support_context_fn_in_torch_utils_checkpoint", True437 "_experimental_support_context_fn_in_torch_utils_checkpoint", True
@@ -462,6 +480,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
462 )480 )
463 self._validate(fn, backend, x, y)481 self._validate(fn, backend, x, y)
464 482 
483+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
465 @unittest.skipIf(IS_WINDOWS, "torch.compile doesn't work with windows")484 @unittest.skipIf(IS_WINDOWS, "torch.compile doesn't work with windows")
466 @torch._dynamo.config.patch(485 @torch._dynamo.config.patch(
467 "_experimental_support_context_fn_in_torch_utils_checkpoint", True486 "_experimental_support_context_fn_in_torch_utils_checkpoint", True
@@ -528,6 +547,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
528 )547 )
529 self._validate(fn, backend, x, y)548 self._validate(fn, backend, x, y)
530 549 
550+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
531 @unittest.skipIf(IS_WINDOWS, "torch.compile doesn't work with windows")551 @unittest.skipIf(IS_WINDOWS, "torch.compile doesn't work with windows")
532 @torch._dynamo.config.patch(552 @torch._dynamo.config.patch(
533 "_experimental_support_context_fn_in_torch_utils_checkpoint", True553 "_experimental_support_context_fn_in_torch_utils_checkpoint", True
@@ -574,6 +594,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
574 )594 )
575 self._validate(fn, backend, x, y)595 self._validate(fn, backend, x, y)
576 596 
597+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
577 @unittest.skipIf(IS_WINDOWS, "torch.compile doesn't work with windows")598 @unittest.skipIf(IS_WINDOWS, "torch.compile doesn't work with windows")
578 @unittest.skip(599 @unittest.skip(
579 "In-place op support in selective checkpointing + torch.compile "600 "In-place op support in selective checkpointing + torch.compile "
@@ -626,6 +647,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
626 )647 )
627 self._validate(fn, backend, x, y)648 self._validate(fn, backend, x, y)
628 649 
650+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
629 @unittest.skipIf(IS_WINDOWS, "torch.compile doesn't work with windows")651 @unittest.skipIf(IS_WINDOWS, "torch.compile doesn't work with windows")
630 @torch._dynamo.config.patch(652 @torch._dynamo.config.patch(
631 "_experimental_support_context_fn_in_torch_utils_checkpoint", True653 "_experimental_support_context_fn_in_torch_utils_checkpoint", True
@@ -674,6 +696,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
674 )696 )
675 self._validate(fn, backend, x, y)697 self._validate(fn, backend, x, y)
676 698 
699+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
677 @unittest.skipIf(IS_WINDOWS, "torch.compile doesn't work with windows")700 @unittest.skipIf(IS_WINDOWS, "torch.compile doesn't work with windows")
678 @torch._dynamo.config.patch(701 @torch._dynamo.config.patch(
679 "_experimental_support_context_fn_in_torch_utils_checkpoint", True702 "_experimental_support_context_fn_in_torch_utils_checkpoint", True
@@ -714,6 +737,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
714 ):737 ):
715 self._validate(fn, backend, x, y)738 self._validate(fn, backend, x, y)
716 739 
740+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
717 @requires_npu()741 @requires_npu()
718 def test_autocast_flash_attention(self):742 def test_autocast_flash_attention(self):
719 def fn(primals_1, primals_2, primals_3):743 def fn(primals_1, primals_2, primals_3):
@@ -738,6 +762,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
738 res = opt_gn(*args)762 res = opt_gn(*args)
739 self.assertEqual(ref, res)763 self.assertEqual(ref, res)
740 764 
765+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
741 @requires_npu()766 @requires_npu()
742 def test_error_msg(self):767 def test_error_msg(self):
743 class MockModule(torch.nn.Module):768 class MockModule(torch.nn.Module):
@@ -763,6 +788,7 @@ class ActivationCheckpointingViaTagsTests(torch._dynamo.test_case.TestCase):
763 ):788 ):
764 opt_fn(x)789 opt_fn(x)
765 790 
791+ @unittest.skipIf(version_skip_test, "current torch is too old, skip the test")
766 @requires_npu()792 @requires_npu()
767 def test_list_inputs(self):793 def test_list_inputs(self):
768 class MockModule(torch.nn.Module):794 class MockModule(torch.nn.Module):