pytorch/torch/csrc/deploy/example/trace_simple.py
Will Constable dc2a44c4fc Back out "Revert D25850783: Add torch::deploy, an embedded torch-python interpreter" (#51124)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51124

Original commit changeset: 1c7133627da2

Test Plan: Test locally with interpreter_test and on CI

Reviewed By: suo

Differential Revision: D26077905

fbshipit-source-id: fae83bf9822d79e9a9b5641bc5191a7f3fdea78d
2021-01-27 16:49:42 -08:00

21 lines
549 B
Python

import argparse
import torch
class MyModule(torch.nn.Module):
def __init__(self, N, M):
super(MyModule, self).__init__()
self.weight = torch.nn.Parameter(torch.rand(N, M))
def forward(self, input):
output = self.weight + input
return output
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("save_file", help="Where to save the model")
args = parser.parse_args()
my_module = MyModule(10, 20)
sm = torch.jit.script(my_module)
sm.save(args.save_file)