This workshop is part of the Rocky Mountain Advanced Computing Consortium’s (RMACC) High Performance Computing Symposium (5/18/2023).
This workshop presents a conceptual overview of the R interface for PyTorch. Emphasis will be on basic structures and applications for deep learning. With torch there is no need to install or use Python. Torch and its associated packages – torchaudio, torchvision, luz – will run on CPU or GPU. This workshop will demonstrate torch for R using an NVIDIA GPU environment, which significantly accelerates computations.
Materials for this workshop are based on the new book, Deep Learning and Scientific Computing with R torch by Sigrid Keydana. For slides click here.
Torch for R is an open source machine learning framework based on PyTorch. torch
provides fast array computation with strong GPU acceleration and a neural networks library built on a tape-based autograd system. The "torch for R"" ecosystem is a collection of extensions for torch. For details on getting started, see the Installation Vignette.
- Install RStudio desktop
- Install
torch
install.packages("torch")
- Clone this repos and make sure the working directory is
torch-workshop
- Download
Tiny ImageNet
data
tiny_imagenet_dataset(".", download = TRUE)
- Install the
modeldata
package from the2021-06-08
snapshot
install.packages("modeldata", repos = "https://packagemanager.rstudio.com/cran/__linux__/bionic/2021-06-08")
- Have a CUDA compatible NVIDIA GPU with compute capability 6.0 or higher
- Install the NVIDIA Container Toolkit
- Pull and run the RStudio Rocker container
docker pull rocker/rstudio
docker run --gpus=all -d -t -e PASSWORD=rstudio -p 8787:8787 --name rstudio rocker/rstudio
- Open RStudio Server from your browser by opening
http://<your.ip.address>:8787/
. Make sure port 8787 is open. Your username isrstudio
and your password isrstudio
- Configure RStudio Server to download package binaries from the Posit Package Manager
# For Red Hat 8 use:
https://packagemanager.rstudio.com/cran/__linux__/centos8/latest
# For Ubuntu 20.04 use:
https://packagemanager.rstudio.com/cran/__linux__/focal/latest
- Install
torch
from the pre-built binaries (Warning! This download is 2Gb)
options(timeout = 600)
install.packages("torch", repos = "https://storage.googleapis.com/torch-lantern-builds/packages/cu117/0.10.0/")
- Make sure your CUDA device is available (this should return
TRUE
)
library(torch)
cuda_is_available()
- Clone this repos and make sure the working directory is
torch-workshop
- Download
Tiny ImageNet
data
wget http://cs231n.stanford.edu/tiny-imagenet-200.zip
unzip tiny-imagenet-200.zip
- Install the
modeldata
package from the2021-06-08
snapshot
install.packages("modeldata", repos = "https://packagemanager.rstudio.com/cran/__linux__/bionic/2021-06-08")