Skip to content

Commit b29a04a

Browse files
Ignore symbolic metadata for lifted constants (pytorch#22056)
Differential Revision: D117081177 Pull Request resolved: pytorch#22056
1 parent 6d1cdb0 commit b29a04a

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎exir/pass_base.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ def _leaf_symbolic_snapshot(value: Argument) -> Any:
121121
return scalar_snapshot
122122

123123
if isinstance(value, FakeTensor):
124+
if value.constant is not None:
125+
return None
124126
dims = []
125127
has_symbolic_dim = False
126128
for dim in value.shape:

‎exir/tests/test_pass_infra.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from executorch.exir.passes import ScalarToTensorPass
2525
from executorch.exir.passes.pass_registry import PassRegistry
2626
from executorch.exir.program import to_edge
27+
from torch._subclasses.fake_tensor import FakeTensor
2728
from torch.export import Dim, export, ExportedProgram
2829
from torch.export.graph_signature import InputKind, InputSpec, TensorArgument
2930
from torch.fx.passes.infra.pass_base import PassBase, PassResult
@@ -513,6 +514,27 @@ def placeholder(
513514
any(dim is not None for dim in self._symbolic_input_shape(new_input))
514515
)
515516

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+
516538
def test_export_pass_rejects_collapsed_symbolic_input_metadata(self) -> None:
517539
class CollapseSymbolicInputPass(ExportPass):
518540
def placeholder(

0 commit comments

Comments
 (0)