|
11 | 11 | auto_functionalized, |
12 | 12 | auto_functionalized_v2, |
13 | 13 | ) |
14 | | -from torch._inductor.fx_passes.reinplace import ( |
15 | | - _generalized_scatter, |
16 | | - canonicalize_view_scatter_ops, |
17 | | - decompose_generalized_scatter, |
18 | | - reinplace_inplaceable_ops_core, |
19 | | -) |
| 14 | +from torch._inductor.fx_passes.reinplace import reinplace_inplaceable_ops_core |
20 | 15 | from torch._inductor.test_case import run_tests, TestCase as InductorTestCase |
21 | 16 | from torch.testing._internal.common_utils import ( |
22 | 17 | instantiate_parametrized_tests, |
23 | 18 | IS_LINUX, |
24 | 19 | parametrize, |
25 | 20 | subtest, |
26 | | - TEST_Z3, |
27 | 21 | ) |
28 | 22 | from torch.testing._internal.inductor_utils import GPU_TYPE, HAS_GPU |
29 | 23 | from torch.testing._internal.logging_utils import logs_to_string |
@@ -530,164 +524,6 @@ def fn(x_1): |
530 | 524 | result = torch.compile(fn, fullgraph=True, backend="inductor")(x) |
531 | 525 | self.assertEqual(result, expected) |
532 | 526 |
|
533 | | - def test_generalized_scatter_target_is_operator(self): |
534 | | - from torch._guards import detect_fake_mode |
535 | | - from torch._inductor.virtualized import V |
536 | | - from torch.func import functionalize |
537 | | - |
538 | | - def fn(x, y): |
539 | | - z = x.sin() |
540 | | - z[:, 0].copy_(y) |
541 | | - return z.cos() |
542 | | - |
543 | | - x = torch.randn(2, 3) |
544 | | - y = torch.randn(2) |
545 | | - gm = make_fx(functionalize(fn), tracing_mode="fake")(x, y) |
546 | | - fake_mode = detect_fake_mode( |
547 | | - [node.meta["val"] for node in gm.graph.nodes if "val" in node.meta] |
548 | | - ) |
549 | | - |
550 | | - with V.set_fake_mode(fake_mode): |
551 | | - canonicalize_view_scatter_ops(gm.graph) |
552 | | - |
553 | | - generalized_scatter_nodes = [ |
554 | | - node |
555 | | - for node in gm.graph.nodes |
556 | | - if node.op == "call_function" and node.target is _generalized_scatter |
557 | | - ] |
558 | | - self.assertEqual(len(generalized_scatter_nodes), 1) |
559 | | - |
560 | | - unexpected_targets = [ |
561 | | - node.target |
562 | | - for node in gm.graph.nodes |
563 | | - if node.op == "call_function" |
564 | | - and not isinstance(node.target, torch._ops.OpOverload) |
565 | | - and node.target is not operator.getitem |
566 | | - ] |
567 | | - self.assertFalse( |
568 | | - unexpected_targets, f"unexpected targets: {unexpected_targets}" |
569 | | - ) |
570 | | - |
571 | | - with V.set_fake_mode(fake_mode): |
572 | | - decompose_generalized_scatter(gm.graph) |
573 | | - |
574 | | - remaining_generalized_scatter_nodes = [ |
575 | | - node |
576 | | - for node in gm.graph.nodes |
577 | | - if node.op == "call_function" and node.target is _generalized_scatter |
578 | | - ] |
579 | | - self.assertFalse(remaining_generalized_scatter_nodes) |
580 | | - |
581 | | - def test_generalized_scatter_symbolic_view_args(self): |
582 | | - from torch._guards import detect_fake_mode |
583 | | - from torch._inductor.virtualized import V |
584 | | - from torch.func import functionalize |
585 | | - from torch.utils import _pytree as pytree |
586 | | - |
587 | | - def fn(x, y): |
588 | | - z = x.sin() |
589 | | - z[: y.shape[0], 0].copy_(y) |
590 | | - return z.cos() |
591 | | - |
592 | | - x = torch.randn(4, 3) |
593 | | - y = torch.randn(2) |
594 | | - torch._dynamo.mark_dynamic(y, 0) |
595 | | - gm = make_fx(functionalize(fn), tracing_mode="symbolic")(x, y) |
596 | | - fake_mode = detect_fake_mode( |
597 | | - [node.meta["val"] for node in gm.graph.nodes if "val" in node.meta] |
598 | | - ) |
599 | | - |
600 | | - with V.set_fake_mode(fake_mode): |
601 | | - canonicalize_view_scatter_ops(gm.graph) |
602 | | - |
603 | | - generalized_scatter_nodes = [ |
604 | | - node |
605 | | - for node in gm.graph.nodes |
606 | | - if node.op == "call_function" and node.target is _generalized_scatter |
607 | | - ] |
608 | | - self.assertEqual(len(generalized_scatter_nodes), 1) |
609 | | - |
610 | | - node = generalized_scatter_nodes[0] |
611 | | - fake_args, fake_kwargs = pytree.tree_map( |
612 | | - lambda arg: arg.meta["val"] if isinstance(arg, torch.fx.Node) else arg, |
613 | | - (node.args, node.kwargs), |
614 | | - ) |
615 | | - fake_result = node.target(*fake_args, **fake_kwargs) |
616 | | - self.assertEqual(fake_result.shape, fake_args[0].shape) |
617 | | - |
618 | | - def test_generalized_scatter_dynamic_clamped_slice(self): |
619 | | - def fn(x, y): |
620 | | - z = x.sin() |
621 | | - z[:9223372036854775807].copy_(y) |
622 | | - return z.cos() |
623 | | - |
624 | | - x = torch.randn(4, 3) |
625 | | - y = torch.randn(4, 3) |
626 | | - torch._dynamo.mark_dynamic(x, 0) |
627 | | - torch._dynamo.mark_dynamic(y, 0) |
628 | | - |
629 | | - expected = fn(x, y) |
630 | | - result = torch.compile(fn, fullgraph=True, backend="inductor")(x, y) |
631 | | - self.assertEqual(result, expected) |
632 | | - |
633 | | - def test_generalized_scatter_dynamic_clamped_slice_translation_validation(self): |
634 | | - if not TEST_Z3: |
635 | | - self.skipTest("requires z3-solver") |
636 | | - |
637 | | - import torch.fx.experimental._config as fx_config |
638 | | - |
639 | | - def fn(x, y): |
640 | | - z = x.sin() |
641 | | - z[:9223372036854775807].copy_(y) |
642 | | - return z.cos() |
643 | | - |
644 | | - x = torch.randn(4, 3) |
645 | | - y = torch.randn(4, 3) |
646 | | - torch._dynamo.mark_dynamic(x, 0) |
647 | | - torch._dynamo.mark_dynamic(y, 0) |
648 | | - |
649 | | - expected = fn(x, y) |
650 | | - with fx_config.patch(translation_validation=True): |
651 | | - result = torch.compile(fn, fullgraph=True, backend="inductor")(x, y) |
652 | | - self.assertEqual(result, expected) |
653 | | - |
654 | | - def test_generalized_scatter_dynamic_negative_slice(self): |
655 | | - def fn(x, y): |
656 | | - z = x.sin() |
657 | | - z[-y.shape[0] :].copy_(y) |
658 | | - return z.cos() |
659 | | - |
660 | | - x = torch.randn(4, 3) |
661 | | - y = torch.randn(2, 3) |
662 | | - torch._dynamo.mark_dynamic(x, 0) |
663 | | - torch._dynamo.mark_dynamic(y, 0) |
664 | | - |
665 | | - expected = fn(x, y) |
666 | | - result = torch.compile(fn, fullgraph=True, backend="inductor")(x, y) |
667 | | - self.assertEqual(result, expected) |
668 | | - |
669 | | - def test_generalized_scatter_ignores_unrelated_view_ops(self): |
670 | | - from torch._guards import detect_fake_mode |
671 | | - from torch._inductor.virtualized import V |
672 | | - from torch.func import functionalize |
673 | | - |
674 | | - def fn(x, y): |
675 | | - z = x.sin() |
676 | | - t = x.t() |
677 | | - z[:, 0].copy_(y) |
678 | | - return z.cos(), t |
679 | | - |
680 | | - x = torch.randn(2, 3) |
681 | | - y = torch.randn(2) |
682 | | - gm = make_fx(functionalize(fn), tracing_mode="fake")(x, y) |
683 | | - fake_mode = detect_fake_mode( |
684 | | - [node.meta["val"] for node in gm.graph.nodes if "val" in node.meta] |
685 | | - ) |
686 | | - |
687 | | - with V.set_fake_mode(fake_mode): |
688 | | - canonicalize_view_scatter_ops(gm.graph) |
689 | | - decompose_generalized_scatter(gm.graph) |
690 | | - |
691 | 527 | @parametrize( |
692 | 528 | "factory_op", |
693 | 529 | [ |
|
0 commit comments