Change torch.jit.trace to no longer be a decorator#11069
Change torch.jit.trace to no longer be a decorator#11069zdevito wants to merge 3 commits intopytorch:masterfrom
Conversation
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.
apaszke
left a comment
There was a problem hiding this comment.
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.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/jit/__init__.py
Outdated
| 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.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/jit/__init__.py
Outdated
| 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.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/jit/__init__.py
Outdated
| 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.
This comment was marked as off-topic.
Sorry, something went wrong.
facebook-github-bot
left a comment
There was a problem hiding this comment.
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.
This comment was marked as off-topic.
Sorry, something went wrong.
| 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.
This comment was marked as off-topic.
Sorry, something went wrong.
| Example: | ||
| >>> def f(x): | ||
| ... return x * 2 | ||
| >>> traced_f = torch.jit.trace(f, torch.rand(1)) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| 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.
This comment was marked as off-topic.
Sorry, something went wrong.
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
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
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.