Skip to content

Commit 82db5bb

Browse files
mcr229YIWENX14
authored andcommitted
update dynamic shape detection
Differential Revision: D68036835 Pull Request resolved: #7605
1 parent c5c6088 commit 82db5bb

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

backends/xnnpack/operators/op_squeeze.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
XNNStaticReshape,
1717
XNode,
1818
)
19+
1920
from executorch.backends.xnnpack.utils.utils import check_or_raise, get_input_node
21+
from torch.fx.experimental.symbolic_shapes import free_symbols
2022

2123

2224
@register_node_visitor
@@ -57,7 +59,7 @@ def define_node(
5759

5860
num_dynamic_dims = 0
5961
for dim in dynamic_shape:
60-
if isinstance(dim, torch.SymInt):
62+
if free_symbols(dim):
6163
num_dynamic_dims += 1
6264
new_shape.append(0)
6365
else:
@@ -119,7 +121,7 @@ def define_node(
119121

120122
num_dynamic_dims = 0
121123
for dim in dynamic_shape:
122-
if isinstance(dim, torch.SymInt):
124+
if free_symbols(dim):
123125
num_dynamic_dims += 1
124126
new_shape.append(0)
125127
else:

exir/backend/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
from executorch.exir.lowered_backend_module import create_submodule_from_nodes
2525
from torch._export.utils import is_buffer, is_lifted_tensor_constant, is_param
26+
from torch.fx.experimental.symbolic_shapes import has_free_symbols
2627
from torch.fx.node import Node
2728
from torch.fx.passes.utils.source_matcher_utils import SourcePartition
2829

@@ -424,10 +425,7 @@ def is_shape_dynamic(node: torch.fx.Node) -> bool:
424425
Check if the node shape is dynamic.
425426
"""
426427

427-
# Shape is dynamic if any of the dimensions don't evaluate to a static value
428-
return "val" in node.meta and any(
429-
isinstance(d, torch.SymInt) for d in node.meta["val"].shape
430-
)
428+
return has_free_symbols(node.meta["val"].shape)
431429

432430

433431
# TODO - style: use templated types

0 commit comments

Comments
 (0)