You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider the following code. The else branch of the condition in get_context evaluates to False when scripting. Running this code still produces an exception.
Note how the dead branch is eliminated after scripting. Instead, the dead branch should be eliminated before attempting to compile it.
There are workarounds to the current behavior (e.g. move the else clause into a separate function with a @torch.jit.unused annotation) but they aren't ergonomic and often ruin the code flow.
Versions
Any version of PyTorch
The text was updated successfully, but these errors were encountered:
@eellison This seems very useful, but also hard to do as the error gets thrown while we are still building the AST. Is there anything we can do here, like special casing torch.jit.is_scripting() and inlining if statements ahead of time?
I like the idea of special-casing torch.jit.is_scripting() until a more general solution is available.
Perhaps a more general way to handle this issue is to support constant folding and constant propagation and evaluate constant conditionals during the AST building pass.
馃悰 Describe the bug
Consider the following code. The
else
branch of the condition inget_context
evaluates toFalse
when scripting. Running this code still produces an exception.Output:
This is the output of the script after removing the
global meow
line:Note how the dead branch is eliminated after scripting. Instead, the dead branch should be eliminated before attempting to compile it.
There are workarounds to the current behavior (e.g. move the else clause into a separate function with a
@torch.jit.unused
annotation) but they aren't ergonomic and often ruin the code flow.Versions
Any version of PyTorch
The text was updated successfully, but these errors were encountered: