Skip to content

Make jit tutorial consistently using 4 spaces as indent. #708

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

Merged
merged 1 commit into from
Oct 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions beginner_source/Intro_to_TorchScript_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

"""

import torch # This is all you need to use both PyTorch and TorchScript!
import torch # This is all you need to use both PyTorch and TorchScript!
print(torch.__version__)


Expand Down Expand Up @@ -125,11 +125,11 @@ def forward(self, x, h):
#

class MyDecisionGate(torch.nn.Module):
def forward(self, x):
if x.sum() > 0:
return x
else:
return -x
def forward(self, x):
if x.sum() > 0:
return x
else:
return -x

class MyCell(torch.nn.Module):
def __init__(self):
Expand Down Expand Up @@ -256,11 +256,11 @@ def forward(self, x, h):
#

class MyDecisionGate(torch.nn.Module):
def forward(self, x):
if x.sum() > 0:
return x
else:
return -x
def forward(self, x):
if x.sum() > 0:
return x
else:
return -x

class MyCell(torch.nn.Module):
def __init__(self, dg):
Expand Down Expand Up @@ -342,13 +342,13 @@ def forward(self, xs):
#

class WrapRNN(torch.nn.Module):
def __init__(self):
super(WrapRNN, self).__init__()
self.loop = torch.jit.script(MyRNNLoop())
def __init__(self):
super(WrapRNN, self).__init__()
self.loop = torch.jit.script(MyRNNLoop())

def forward(self, xs):
y, h = self.loop(xs)
return torch.relu(y)
def forward(self, xs):
y, h = self.loop(xs)
return torch.relu(y)

traced = torch.jit.trace(WrapRNN(), (torch.rand(10, 3, 4)))
print(traced.code)
Expand Down