Jit for tolist()

For methods other than forward you have to explicitly get the method and run it. For this Module

class M(nn.Module):
    @torch.jit.export
    def infer(self, x):
        return x + 10

torch.jit.script(M()).save("m.pt")

You can run it in C++ with script::Module::get_method

int main() {
  auto module = torch::jit::load("m.pt");
  auto result = module.get_method("infer")({torch::ones({2, 2})});
  std::cout << result << "\n";
}

We have an open issue to improve our C++ documentation to make things like this more clear in the future.

6 Likes