Skip to content

Change torch.jit.trace to no longer be a decorator#11069

Closed
zdevito wants to merge 3 commits intopytorch:masterfrom
zdevito:pr/trace_api
Closed

Change torch.jit.trace to no longer be a decorator#11069
zdevito wants to merge 3 commits intopytorch:masterfrom
zdevito:pr/trace_api

Conversation

@zdevito
Copy link
Contributor

@zdevito zdevito commented Aug 30, 2018

This was done because it surprising for a decorator to run a function
rather than wrap it, and not simplify the syntax for tracing modules.

This was done because it surprising for a decorator to run a function
rather than wrap it, and not simplify the syntax for tracing modules.
@zdevito zdevito added the oncall: jit Add this issue/PR to JIT oncall triage queue label Aug 30, 2018
Copy link
Contributor

@apaszke apaszke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks ok. Some minor comments

as inputs while tracing. The resulting trace can be run with
inputs of different types and shapes assuming the traced operations
support those types and shapes.
example_inputs - a tuple of example inputs that will be passed to the function

This comment was marked as off-topic.

This comment was marked as off-topic.

if not _enabled:
return func
executor_options = {'optimize': bool(optimize)}
# Special case for common case of passing a single Variable

This comment was marked as off-topic.

example_inputs = (example_inputs,)
# done primarily so that weird iterables fail here and not pybind11 code
if not isinstance(example_inputs, tuple):
example_inputs = tuple(e for e in example_inputs)

This comment was marked as off-topic.

if isinstance(example_inputs, torch.Tensor):
example_inputs = (example_inputs,)
# done primarily so that weird iterables fail here and not pybind11 code
if not isinstance(example_inputs, tuple):

This comment was marked as off-topic.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zdevito has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

if len(kwargs) != 0:
raise TypeError("got unexpected keyword arguments: {}".format(", ".join(kwargs.keys())))
Returns:
A torch.jit.ScriptModule object with a single forward() method containing the traced code.

This comment was marked as off-topic.

raise TypeError("got unexpected keyword arguments: {}".format(", ".join(kwargs.keys())))
Returns:
A torch.jit.ScriptModule object with a single forward() method containing the traced code.
When func in s a torch.nn.Module, the returned ScriptModule will have the same set of

This comment was marked as off-topic.

Example:
>>> def f(x):
... return x * 2
>>> traced_f = torch.jit.trace(f, torch.rand(1))

This comment was marked as off-topic.

as inputs while tracing. The resulting trace can be run with
inputs of different types and shapes assuming the traced operations
support those types and shapes.
func - a python function or torch.nn.Module that will be run with example_inputs.

This comment was marked as off-topic.

facebook-github-bot pushed a commit to pytorch/translate that referenced this pull request Aug 30, 2018
Summary:
This was done because it surprising for a decorator to run a function
rather than wrap it, and not simplify the syntax for tracing modules.
Pull Request resolved: pytorch/pytorch#11069

Reviewed By: jamesr66a

Differential Revision: D9583192

Pulled By: zdevito

fbshipit-source-id: b914b7ab4c73c255086465a6576eef3a22de1e13
PenghuiCheng pushed a commit to PenghuiCheng/pytorch that referenced this pull request Sep 11, 2018
Summary:
This was done because it surprising for a decorator to run a function
rather than wrap it, and not simplify the syntax for tracing modules.
Pull Request resolved: pytorch#11069

Reviewed By: jamesr66a

Differential Revision: D9583192

Pulled By: zdevito

fbshipit-source-id: b914b7ab4c73c255086465a6576eef3a22de1e13
@ezyang ezyang added the merged label Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants