|
24 | 24 | from executorch.exir.passes import ScalarToTensorPass |
25 | 25 | from executorch.exir.passes.pass_registry import PassRegistry |
26 | 26 | from executorch.exir.program import to_edge |
| 27 | +from torch._subclasses.fake_tensor import FakeTensor |
27 | 28 | from torch.export import Dim, export, ExportedProgram |
28 | 29 | from torch.export.graph_signature import InputKind, InputSpec, TensorArgument |
29 | 30 | from torch.fx.passes.infra.pass_base import PassBase, PassResult |
@@ -513,6 +514,27 @@ def placeholder( |
513 | 514 | any(dim is not None for dim in self._symbolic_input_shape(new_input)) |
514 | 515 | ) |
515 | 516 |
|
| 517 | + def test_export_pass_ignores_symbolic_metadata_for_constant_input(self) -> None: |
| 518 | + graph_module = self._export_dynamic_graph_module() |
| 519 | + original_input = self._find_input_node(graph_module) |
| 520 | + original_value = original_input.meta["val"] |
| 521 | + self.assertIsInstance(original_value, FakeTensor) |
| 522 | + assert isinstance(original_value, FakeTensor) |
| 523 | + constant = torch.randn(2, 3) |
| 524 | + original_value.constant = constant |
| 525 | + |
| 526 | + new_graph_module = ExportPass()(graph_module).graph_module |
| 527 | + new_input = self._find_input_node(new_graph_module) |
| 528 | + new_value = new_input.meta["val"] |
| 529 | + |
| 530 | + self.assertIsInstance(new_value, FakeTensor) |
| 531 | + assert isinstance(new_value, FakeTensor) |
| 532 | + self.assertIs(new_value.constant, constant) |
| 533 | + self.assertEqual( |
| 534 | + self._symbolic_input_shape(new_input), |
| 535 | + self._symbolic_input_shape(original_input), |
| 536 | + ) |
| 537 | + |
516 | 538 | def test_export_pass_rejects_collapsed_symbolic_input_metadata(self) -> None: |
517 | 539 | class CollapseSymbolicInputPass(ExportPass): |
518 | 540 | def placeholder( |
|
0 commit comments