-
Notifications
You must be signed in to change notification settings - Fork 4.2k
[TorchScript] Fix Intro to TorchScript tutorial #866
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
Conversation
cc: Tutorial authors @jamesr66a @suo For some reason GitHub won't let me add reviewers |
Deploy preview for pytorch-tutorials-preview ready! Built with commit 7a71c8a https://deploy-preview-866--pytorch-tutorials-preview.netlify.app |
b282774
to
386308c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, one comment inline. Thanks for fixing this!
@@ -274,6 +274,8 @@ def forward(self, x, h): | |||
|
|||
my_cell = MyCell(MyDecisionGate()) | |||
traced_cell = torch.jit.trace(my_cell, (x, h)) | |||
|
|||
print(traced_cell.dg.code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Add some text here and similarly below, to say which forward
is for the decision gate and which is for the cell
Summary: There is a section of the Intro to TorchScript tutorial that is supposed to illustrate that tracing cannot capture control flow but scripting can. However, the generated IR for both cases is the same because the tutorial only prints out the IR for the outer module, not the inner module that contains the control flow. This commit fixes this issue by printing the IR for both the inner and outer module to clearly show that tracing does not capture control flow, but scripting does. Testing: Ran the tutorial file.
386308c
to
7a71c8a
Compare
Summary: There is a section of the Intro to TorchScript tutorial that is supposed to illustrate that tracing cannot capture control flow but scripting can. However, the generated IR for both cases is the same because the tutorial only prints out the IR for the outer module, not the inner module that contains the control flow. This commit fixes this issue by printing the IR for both the inner and outer module to clearly show that tracing does not capture control flow, but scripting does. Testing: Ran the tutorial file.
Summary
There is a section of the Intro to TorchScript tutorial that is supposed
to illustrate that tracing cannot capture control flow but scripting can.
However, the generated IR for both cases is the same because the tutorial
only prints out the IR for the outer module, not the inner module that
contains the control flow. This commit fixes this issue by printing the IR
for both the inner and outer module to clearly show that tracing does not
capture control flow, but scripting does.
Testing
Ran the tutorial file.
Tracing Output:
Scripting Output: