8 def get_custom_op_library_path():
9 if sys.platform.startswith(
"win32"):
10 library_filename =
"custom_ops.dll" 11 elif sys.platform.startswith(
"darwin"):
12 library_filename =
"libcustom_ops.dylib" 14 library_filename =
"libcustom_ops.so" 15 path = os.path.abspath(
"build/{}".format(library_filename))
16 assert os.path.exists(path), path
22 super(Model, self).__init__()
23 self.
p = torch.nn.Parameter(torch.eye(5))
25 @torch.jit.script_method
26 def forward(self, input):
27 return torch.ops.custom.op_with_defaults(input)[0] + 1
31 parser = argparse.ArgumentParser(
32 description=
"Serialize a script module with custom ops" 34 parser.add_argument(
"--export-script-module-to", required=
True)
35 options = parser.parse_args()
37 torch.ops.load_library(get_custom_op_library_path())
40 model.save(options.export_script_module_to)
43 if __name__ ==
"__main__":