Template Function torch::python::bind_module(py::module, const char *)

Function Documentation

template<typename ModuleType, bool force_enable = false>
torch::disable_if_t<torch::detail::has_forward<ModuleType>::value && !force_enable, detail::PyModuleClass<ModuleType>> torch::python::bind_module(py::module module, const char *name)

Creates a pybind11 class object for an nn::Module subclass type and adds default bindings.

After adding the default bindings, the class object is returned, such that you can add more bindings.

Example usage:

 struct Net : torch::nn::Module {
   Net(int in, int out) { }
   torch::Tensor forward(torch::Tensor x) { return x; }

 PYBIND11_MODULE(my_module, m) {
   torch::python::bind_module<Net>(m, "Net")
     .def(py::init<int, int>())
     .def("forward", &Net::forward);


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources