Skip to content

Commit c786135

Browse files
committed
Update on "Add preserve_ops to EdgeCompileConfig"
1. Add `preserve_ops` to `EdgeCompileConfig` 2. Remove preserved ops from the decomposition table in `to_edge`. 3. Add checks to the verifier ensuring that preserved ops do not have mutations or views. 4. Update 'core_aten_exception_list' to be 'preserved_ops' in `to_edge_transform_and_lower`. Context/Usage **core_aten_ops_exception_list** - Contains operators that are missing a decomposition to core aten. - Exclude these so that verification can still be run on the rest of the graph. - Ideally, this list should be empty. **preserve_ops** - Contains operators that the user specifically does not want decomposed. - Must be aten; custom ops are ignored by verifier. Edge case: - If an aten operator does not have a decomp, and the user specifically wants it to be preserved, put it in preserve_ops rather than core_aten_ops_exception_list. Differential Revision: [D78298749](https://our.internmc.facebook.com/intern/diff/D78298749/) [ghstack-poisoned]
1 parent 391119f commit c786135

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

exir/verification/verifier.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# LICENSE file in the root directory of this source tree.
66

77
import itertools
8+
import logging
89
import operator
910
import types
1011
from contextlib import nullcontext
@@ -134,16 +135,21 @@ def check_valid_op(self, op):
134135
):
135136
return
136137
if op in self._preserve_ops:
138+
if op.namespace != "aten":
139+
raise RuntimeError(
140+
f"Only preserve aten ops. Received op {op} with namespace {op.namespace}."
141+
)
137142
# Preserved ops should not include mutation or view,
138143
# which may affect memory planning.
139-
if op._schema.is_mutable or op.is_view:
144+
if op.is_view:
140145
raise RuntimeError(
141146
f"Cannot preserve operator {op} because it is a view or mutation."
142147
)
143-
if op.namespace != "aten":
144-
raise RuntimeError(
145-
f"Only preserve aten ops. Received op {op} with namespace {op.namespace}."
148+
if op.is_mutable:
149+
logging.warning(
150+
f"Preserving mutation ops like {op} is a no-op because run_decomposition functionalizes it and prevents it from showing up."
146151
)
152+
147153
return
148154
if torch.Tag.core not in op.tags and torch.Tag.view_copy not in op.tags:
149155
# NOTE(qihan): whether view_copy operators are marked as canonical is still under

0 commit comments

Comments
 (0)