Skip to content

Commit

Permalink
update dynamic shape detection (#7605)
Browse files Browse the repository at this point in the history
Summary:

Updating Dynamic Shape Detection re: #5794

Reviewed By: digantdesai

Differential Revision: D68036835
  • Loading branch information
mcr229 authored and facebook-github-bot committed Jan 13, 2025
1 parent 44d223d commit b34bb95
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 4 additions & 2 deletions backends/xnnpack/operators/op_squeeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
XNNStaticReshape,
XNode,
)

from executorch.backends.xnnpack.utils.utils import check_or_raise, get_input_node
from torch.fx.experimental.symbolic_shapes import free_symbols


@register_node_visitor
Expand Down Expand Up @@ -57,7 +59,7 @@ def define_node(

num_dynamic_dims = 0
for dim in dynamic_shape:
if isinstance(dim, torch.SymInt):
if free_symbols(dim):
num_dynamic_dims += 1
new_shape.append(0)
else:
Expand Down Expand Up @@ -119,7 +121,7 @@ def define_node(

num_dynamic_dims = 0
for dim in dynamic_shape:
if isinstance(dim, torch.SymInt):
if free_symbols(dim):
num_dynamic_dims += 1
new_shape.append(0)
else:
Expand Down
6 changes: 2 additions & 4 deletions exir/backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from executorch.exir.lowered_backend_module import create_submodule_from_nodes
from torch._export.utils import is_buffer, is_lifted_tensor_constant, is_param
from torch.fx.experimental.symbolic_shapes import has_free_symbols
from torch.fx.node import Node
from torch.fx.passes.utils.source_matcher_utils import SourcePartition

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

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


# TODO - style: use templated types
Expand Down

0 comments on commit b34bb95

Please sign in to comment.