Skip to content

fix is_inplace_node check #12071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions exir/passes/insert_write_back_for_buffers_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,15 @@ def _is_inplace_node(node: torch.fx.Node) -> bool:
"""Check if a node is an inplace node."""
return (
node.op == "call_function"
and isinstance(node.target, torch._ops.OpOverload)
and hasattr(node.target, "_schema")
and is_inplace_variant(
node.target._schema.name, node.target._schema.overload_name
node.target._schema.name, node.target._schema.overload_name #pyre-ignore
)
)


def _inplace_lineage(
output_arg: torch.fx.Node,
gm: torch.fx.GraphModule,
gs: ExportGraphSignature,
kind: SchemaKind,
) -> bool:
Expand Down Expand Up @@ -160,7 +159,6 @@ def insert_write_back_for_buffers_pass(
# if the arg and target are not the same, we add a copy_ node.
not _inplace_lineage(
output_node.args[0][i],
gm,
ep.graph_signature,
ep.graph_signature.output_specs[i].kind,
)
Expand Down
9 changes: 9 additions & 0 deletions exir/tests/test_reinplace_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ def forward(

self.assertIsNotNone(index_put_node, "Should find an index_put_ node")

# Find the copy_ node
copy_node = None
for node in et.exported_program().graph.nodes:
if node.op == "call_function" and "copy_" in str(node.target):
copy_node = node
break

self.assertIsNone(copy_node, "Shouldn't find an copy_ node")

e = _load_for_executorch_from_buffer(et.buffer)
self.assertTrue(
torch.allclose(
Expand Down
Loading