Skip to content

Code Generation for 'C++' Interfaces for 'torch'.

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

mlverse/torchexport

Repository files navigation

torchexport

The goal of torchexport is to generate code to handle errors and common caveats when writing C++ extensions for torch. In general, you won't need to use this package directly as it's called automatically in the template CMake file.

Installation

You can install the development version of torchexport from GitHub with:

# install.packages("devtools")
devtools::install_github("dfalbel/torchexport")

Example

Annotate the function you want to export with [[ torch::export ]]:

// [[ torch::export ]]
void* c_lltm_forward(void* input,
                     void* weights,
                     void* bias,
                     void* old_h,
                     void* old_cell) {
  return make_raw::TensorList(lltm_forward(
      from_raw::Tensor(input),
      from_raw::Tensor(weights),
      from_raw::Tensor(bias),
      from_raw::Tensor(old_h),
      from_raw::Tensor(old_cell)
  ));
}

Calling torchexport::export() will generate csrc/src/exports.cpp and csrc/include/<<NAME>>/exports.h with definitions that correctly handle cross-compile exceptions as well as import/export declarations.

About

Code Generation for 'C++' Interfaces for 'torch'.

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages