Skip to content

Re-enable learning_hybrid_frontend_through_example_tutorial.py #377

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
Dec 7, 2018
Merged
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions .jenkins/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ pushd audio
python setup.py install
popd

# We will fix the hybrid frontend tutorials when the API is stable
rm beginner_source/hybrid_frontend/learning_hybrid_frontend_through_example_tutorial.py || true

aws configure set default.s3.multipart_threshold 5120MB

# Decide whether to parallelize tutorial builds, based on $JOB_BASE_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,21 @@ class definitions.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We can implement part one as a pure python function as below. Notice, to
trace this function we add the ``@torch.jit.trace`` decorator. Since the
trace requires a dummy input of the expected runtime type and shape, we
also include the ``torch.rand`` to generate a single valued torch
tensor.
trace this function we call ``torch.jit.trace`` and pass in the function
to be traced. Since the trace requires a dummy input of the expected
runtime type and shape, we also include the ``torch.rand`` to generate a
single valued torch tensor.

"""

import torch

# This is how you define a traced function
# Pass in an example input to this decorator and then apply it to the function
@torch.jit.trace(torch.rand(()))
def traced_fn(x):
def fn(x):
return torch.abs(2*x)

# This is how you define a traced function
# Pass in both the function to be traced and an example input to ``torch.jit.trace``
traced_fn = torch.jit.trace(fn, torch.rand(()))

######################################################################
# Part 2 - Scripting a pure python function
Expand All @@ -124,7 +124,7 @@ def traced_fn(x):
@torch.jit.script
def script_fn(x):
z = torch.ones([1], dtype=torch.int64)
for i in range(x):
for i in range(int(x)):
z = z * (i + 1)
return z

Expand Down Expand Up @@ -163,7 +163,7 @@ class ScriptModule(torch.jit.ScriptModule):
@torch.jit.script_method
def forward(self, x):
r = -x
if torch.fmod(x, 2.0) == 0.0:
if int(torch.fmod(x, 2.0)) == 0.0:
r = x / 2.0
return r

Expand Down Expand Up @@ -201,7 +201,7 @@ def __init__(self):
# Modules must be attributes on the Module because if you want to trace
# or script this Module, we must be able to inherit the submodules'
# params.
self.traced_module = torch.jit.trace(torch.rand(()))(TracedModule())
self.traced_module = torch.jit.trace(TracedModule(), torch.rand(()))
self.script_module = ScriptModule()

print('traced_fn graph', traced_fn.graph)
Expand Down Expand Up @@ -244,8 +244,6 @@ def forward(self, x):
# Tracing the Top-Level Model
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# **NOTE:** Open issue https://github.com/pytorch/pytorch/issues/8755
#
# The last part of the example is to trace the top-level module, ``Net``.
# As mentioned previously, since the traced/scripted modules are
# attributes of Net, we are able to trace ``Net`` as it inherits the
Expand All @@ -254,11 +252,9 @@ def forward(self, x):
# Also, check out the graph that is created.
#

# TODO: this fails with some weird bug https://github.com/pytorch/pytorch/issues/8755
#n_traced = torch.jit.trace(torch.tensor([5]))(n)
#print(n_traced(torch.tensor([5])))

# TODO: print the graph of the traced module
n_traced = torch.jit.trace(n, torch.tensor([5]))
print(n_traced(torch.tensor([5])))
print('n_traced graph', n_traced.graph)


######################################################################
Expand Down