https://github.com/mlverse/torchexport
Code Generation for 'C++' Interfaces for 'torch'.
https://github.com/mlverse/torchexport
Last synced: 5 months ago
JSON representation
Code Generation for 'C++' Interfaces for 'torch'.
- Host: GitHub
- URL: https://github.com/mlverse/torchexport
- Owner: mlverse
- License: other
- Created: 2022-01-24T18:55:34.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-06T15:26:58.000Z (over 1 year ago)
- Last Synced: 2025-10-13T02:53:03.678Z (9 months ago)
- Language: R
- Homepage: https://mlverse.github.io/torchexport
- Size: 1.33 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("dfalbel/torchexport")
```
## Example
Annotate the function you want to export with `[[ torch::export ]]`:
``` r
// [[ 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/<>/exports.h` with definitions that correctly handle cross-compile
exceptions as well as import/export declarations.