README.md

lltm

The goal of lltm is to be a minimal implementation of an extension for torch that interfaces with the underlying C++ interface, called LibTorch.

In this pakage we provide an implementation of a new recurrent unit that is similar to a LSTM but it lacks a forget gate and uses an Exponential Linear Unit (ELU) as its internal activation function. Because this unit never forgets, we’ll call it LLTM, or Long-Long-Term-Memory unit.

The example implemented here is a port of the official PyTorch tutorial on custom C++ and CUDA extensions.

High-Level overview

Writing C++ extensions for torch requires us to coordinate the communication between multiple agents in the torch ecossytem. The following diagram is a high-level overview on how they communicate in this package.

On the torch package side the agents that appear are:

In the extension side the actors are:

Project structure

csrc: Implementing the operators and their C wrappers.

The library implemented in csrc can be compiled with CMake. We use the following commands to compile and install it locally:

cd csrc && mkdir build
cmake .. && cmake --build . --target install --config Release

src: Wrapping the library with Rcpp

Now that we implemented the operators that we wanted to call from R, we can now implement the Rcpp wrappers that will allow us to call those operators from R.

R API

Now the Rcpp wrappers are implemented and exported you have now access to lltm_forward in the R side.

Packaging

It’s not trivial to package torch extensions because they can’t be entirely built on CRAN machines. We would need to include pre-built binaries in the package tarball but for security reasons that’s not accepted on CRAN.

In this package we implement a suggested way of packaging torch extensions that makes it really easy for users to install your package without having to use custom installation steps or building libraries from source. The diagram below shows an overview of the packaging process.

Installation

~~You can install the released version of lltm from CRAN with:~~

install.packages("lltm")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("mlverse/lltm")


mlverse/lltm documentation built on Jan. 28, 2022, 8:41 p.m.