已合并
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
已合并
共 1 个文件变更+27-1
| @@ -1,6 +1,7 @@ | |||
| 1 | # Owner(s): ["module: dynamo"] | 1 | # Owner(s): ["module: dynamo"] |
| 2 | import functools | 2 | import functools |
| 3 | import unittest | 3 | import unittest |
| 4 | +from packaging import version | ||
| 4 | from importlib import import_module | 5 | from importlib import import_module |
| 5 | 6 | ||
| 6 | import torch | 7 | import torch |
| @@ -15,7 +16,11 @@ from torch._dynamo.backends.common import aot_autograd | |||
| 15 | from torch._dynamo.testing import CompileCounterWithBackend | 16 | from torch._dynamo.testing import CompileCounterWithBackend |
| 16 | from torch._higher_order_ops.wrap import tag_activation_checkpoint | 17 | from torch._higher_order_ops.wrap import tag_activation_checkpoint |
| 17 | from torch.testing._internal.common_utils import IS_WINDOWS | 18 | from torch.testing._internal.common_utils import IS_WINDOWS |
| 18 | -from torch.utils.checkpoint import _pt2_selective_checkpoint_context_fn_gen, checkpoint | 19 | + |
| 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 | ||
| 20 | requires_npu = functools.partial(unittest.skipIf, not torch.npu.is_available(), "requires npu") | 25 | requires_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 | + | ||
| 113 | 119 | ||
| 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 | + | ||
| 131 | 138 | ||
| 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 | + | ||
| 150 | 158 | ||
| 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 | + | ||
| 170 | 179 | ||
| 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 | + | ||
| 192 | 202 | ||
| 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 | + | ||
| 218 | 229 | ||
| 219 | def test_tags_decomps(self): | 230 | def test_tags_decomps(self): |
| 220 | # Ensures that tags are passed on through decompositions as well | 231 | # 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 | + | ||
| 251 | 263 | ||
| 252 | 264 | ||
| 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 | + | ||
| 275 | 288 | ||
| 276 | 289 | ||
| 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 | + | ||
| 302 | 316 | ||
| 303 | 317 | ||
| 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 eager | 336 | # 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 | + | ||
| 325 | 340 | ||
| 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 | + | ||
| 353 | 369 | ||
| 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 | + | ||
| 387 | 404 | ||
| 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 | + | ||
| 417 | 435 | ||
| 418 | 436 | ||
| 419 | "_experimental_support_context_fn_in_torch_utils_checkpoint", True | 437 | "_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 | + | ||
| 465 | 484 | ||
| 466 | 485 | ||
| 467 | "_experimental_support_context_fn_in_torch_utils_checkpoint", True | 486 | "_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 | + | ||
| 531 | 551 | ||
| 532 | 552 | ||
| 533 | "_experimental_support_context_fn_in_torch_utils_checkpoint", True | 553 | "_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 | + | ||
| 577 | 598 | ||
| 578 | 599 | ||
| 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 | + | ||
| 629 | 651 | ||
| 630 | 652 | ||
| 631 | "_experimental_support_context_fn_in_torch_utils_checkpoint", True | 653 | "_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 | + | ||
| 677 | 700 | ||
| 678 | 701 | ||
| 679 | "_experimental_support_context_fn_in_torch_utils_checkpoint", True | 702 | "_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 | + | ||
| 717 | 741 | ||
| 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 | + | ||
| 741 | 766 | ||
| 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 | + | ||
| 766 | 792 | ||
| 767 | def test_list_inputs(self): | 793 | def test_list_inputs(self): |
| 768 | class MockModule(torch.nn.Module): | 794 | class MockModule(torch.nn.Module): |