Installation

After the usual R package installation, torch requires installing other 2 libraries: LibTorch and LibLantern. They are automatically installed by detecting information about you OS if you are using torch in interactive mode. If you are running torch in non-interactive environments you need to set the TORCH_INSTALL env var to 1, so it’s automatically installed or manually call torch::install_torch().

We have provide pre-compiled binaries for all major platforms and you can find specific installation instructions below.

Windows

CPU

If you don’t have a GPU or want to install the CPU version of torch, you can install with:

install.packages("torch")

Some Windows distributions don’t have the Visual Studio runtime pre-installed and you will observe an error like:

Error in cpp_lantern_init(normalizePath(install_path())): C:\Users\User\Documents\R\R-4.0.2\library\torch\deps\lantern.dll - The specified module could not be found.

See here for instructions on how to install it.

GPU

Since version 0.1.1 torch supports GPU installation on Windows. In order to use GPU’s with torch you need to:

Once you have installed all pre-requisites you can install torch with:

install.packages("torch")

If you have followed default installation locations we will detect that you have CUDA software installed and automatically download the GPU enabled Lantern binaries. You can also specify the CUDA env var with something like Sys.setenv(CUDA="10.1") if you want to force an specific version of the CUDA toolkit.

MacOS

CPU

We only support CPU builds of torch on MacOS. On MacOS you can install torch with:

install.packages("torch")

Linux

CPU

To install the cpu version of torch you can run:

install.packages("torch")

GPU

To install the GPU version of torch on linux you must verify that:

Once you have installed all pre-requisites you can install torch with:

install.packages("torch")

If you have followed default installation locations we will detect that you have CUDA software installed and automatically download the GPU enabled Lantern binaries. You can also specify the CUDA env var with something like Sys.setenv(CUDA="10.1") if you want to force an specific version of the CUDA toolkit.