[JIT] make is_scripting a condvalue#32871
Conversation
driazati
left a comment
There was a problem hiding this comment.
Accepting since this doesn’t really add any more behavior and looks like it makes more sense than is_scripting and an @ignore
zdevito
left a comment
There was a problem hiding this comment.
I think this is an improvement on what was there before. Please don't expand its use just because it better though, it is still a code smell whenever it appears since it breaks the script/python is the same contract.
| } | ||
| return CondValue( | ||
| emitToBool(emitExpr(expr)), RefinementSet({}), c10::nullopt); | ||
| auto expr_out = emitToBool(emitExpr(expr)); |
There was a problem hiding this comment.
For robustness, I'd prefer this looked at the node before emitExpr to determine whether it is an is_scripting call. Doing it afterward is subject to arbitrary peephole optimizations that code emission might do and doesn't match the pattern in the rest of this function.
There was a problem hiding this comment.
The AST looks like:
(apply
(.
(.
(variable (ident torch))
(ident jit))
(ident is_scripting))
(list)
(list)))
How should I pattern match then? Are we taking the stance that only torch.jit.is_scripting works, and not jit.is_scripting, or is_scripting, or
import torch.jit.is_scripting as COMPILE_BLOCK
if not COMPILE_BLOCK()
...
i'm fine with whatever. up to this point we have only used condvalues with builtin reserved keywords, so this is a different case.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
Is this is_scrpting stuff working when tracing a module? I tried will some simle demo but not working. Only false is returned. My env is: |
|
Hi, this doesn't work with tracing. it should just return false when tracing. you can use is_tracing for that. |
Summary: Add `torch.jit.is_scripting` to the list of CondValues, or values that if they are an input to a if statement we only compile one side of the if. I'm not sure if we actually want this PR. Pros: - Makes it easier to add features that are not yet supported in TorchScript (like has_torch_function) - The current idiom of writing `torch.jit.is_scripting` and factoring out the block to a function annotated with `torch.jit.ignore` is functionally equivalent and much more cumbersome Cons: - Makes it easier to add features that are not yet supported in TorchScript - Perhaps is confusing as a reader what is being compiled. Potentially could give all caps name or otherwise change name to make it more visually stand out. Pull Request resolved: pytorch#32871 Differential Revision: D19670383 Pulled By: eellison fbshipit-source-id: 5257b0bd23c66f199d59a7f2c911e948301e5588
Add
torch.jit.is_scriptingto the list of CondValues, or values that if they are an input to a if statement we only compile one side of the if. I'm not sure if we actually want this PR.Pros:
torch.jit.is_scriptingand factoring out the block to a function annotated withtorch.jit.ignoreis functionally equivalent and much more cumbersomeCons: