Skip to content
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