forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite assert statement with torch._assert under config (pytorch#88246)
This diff rewrites assert statement in python with torch._assert under config. The resulting graph looks something like: ``` SOURCE CODE: def f(x): assert x[0] == 3 return x.cos() CAPTURED GRAPH: graph(): %arg0 : [#users=2] = placeholder[target=arg0] %getitem : [#users=1] = call_function[target=operator.getitem](args = (%arg0, 0), kwargs = {}) %eq : [#users=1] = call_function[target=operator.eq](args = (%getitem, 3), kwargs = {}) %_assert : [#users=0] = call_function[target=torch._assert](args = (%eq, "assertion_error"), kwargs = {}) %cos : [#users=1] = call_method[target=cos](args = (%arg0,), kwargs = {}) return cos ``` Note that this introduces side-effect as it could error out while executing graph, but the assertion can eliminated via DCE if we choose to ignore it. Pull Request resolved: pytorch#88246 Approved by: https://github.com/jansel
- Loading branch information
1 parent
af448e8
commit 04169c5
Showing
3 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters