|
1 | 1 | # (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
2 | 2 |
|
3 | 3 |
|
| 4 | +from typing import Sequence |
| 5 | + |
4 | 6 | import executorch.backends.cadence.aot.ops_registrations # noqa
|
5 | 7 | import torch
|
6 | 8 | from executorch.backends.cadence.aot.graph_builder import (
|
|
9 | 11 | )
|
10 | 12 | from executorch.backends.cadence.aot.pass_utils import count_node
|
11 | 13 | from executorch.exir.dialects._ops import ops as exir_ops
|
12 |
| -from executorch.exir.pass_base import ExportPass |
| 14 | +from executorch.exir.pass_base import ExportPass, NodeMetadata |
13 | 15 | from later.unittest import TestCase
|
14 | 16 |
|
15 | 17 |
|
@@ -68,3 +70,27 @@ def test_graph_with_single_im2row(self) -> None:
|
68 | 70 | # Check graph has a single im2row node.
|
69 | 71 | self.assertEqual(len([gm.graph.nodes]), 1)
|
70 | 72 | self.assertEqual(count_node(gm, exir_ops.edge.cadence.im2row.default), 1)
|
| 73 | + |
| 74 | +class TestHigherOrderOps(TestCase): |
| 75 | + def _get_inner_graph(self, x_shape: Sequence[int]): |
| 76 | + builder = GraphBuilder() |
| 77 | + x = builder.placeholder("x", torch.randn(*x_shape)) |
| 78 | + add = builder.call_operator( |
| 79 | + exir_ops.edge.aten.add.Tensor, |
| 80 | + (x, x), # pyre-ignore |
| 81 | + ) |
| 82 | + builder.output([x, add]) |
| 83 | + gm = builder.get_graph_module() |
| 84 | + # Check if graph module is valid by running exportpass on it. |
| 85 | + gm = ExportPass().call(gm).graph_module |
| 86 | + return gm |
| 87 | + |
| 88 | + def test_call_map(self): |
| 89 | + builder = GraphBuilder() |
| 90 | + x_shape = (4, 8, 8) |
| 91 | + x = builder.placeholder("x", torch.randn(*x_shape)) |
| 92 | + map_node = builder.call_map(self._get_inner_graph(x_shape[1:]), [x], [], NodeMetadata({})) |
| 93 | + builder.output([map_node]) |
| 94 | + gm = builder.get_graph_module() |
| 95 | + # Check if graph module is valid by running exportpass on it. |
| 96 | + ExportPass().call(gm).graph_module |
0 commit comments