# Call custom functions by jit in C++

**URL:** <https://discuss.pytorch.org/t/call-custom-functions-by-jit-in-c/62929>\
**Category:** jit\
**Created:** [December 3, 2019, 10:46pm UTC](https://discuss.pytorch.org/t/call-custom-functions-by-jit-in-c/62929 "2019-12-03T22:46:01Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![driazati](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/driazati/32/15393_2.png) [@driazati](https://discuss.pytorch.org/u/driazati)\
**Post date:** [December 3, 2019, 11:36pm UTC](https://discuss.pytorch.org/t/call-custom-functions-by-jit-in-c/62929/2 "2019-12-03T23:36:26Z")

</div>

Does this answer help?

> [@Jit for tolist()](https://discuss.pytorch.org/t/jit-for-tolist/60926/4):
>
> 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 thi…

---

_[View the full topic](https://discuss.pytorch.org/t/call-custom-functions-by-jit-in-c/62929)._
