Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save flrs/e80e7cd819cbaef74f0457abb687fbfa to your computer and use it in GitHub Desktop.
Save flrs/e80e7cd819cbaef74f0457abb687fbfa to your computer and use it in GitHub Desktop.
GPU-powered Deep Learning for Time Series with modeltime.gluonts on Saturn Cloud
# Saturn Cloud Startup Script for Running GPU-enabled modeltime.gluonts
#
# How to use:
# 1. Create an account on saturncloud.io
# 2. Create a new project in Saturn Cloud
# 3. Select image "saturncloud/saturn-gpu:2020.12.23" as image for your project
# 4. Copy and paste code below into "Advanced Settings (optional)" > "Start Script (Bash)".
# (This code will install R, a Jupyter R kernel, modeltime.gluonts, and prepare a Python environment
# for executing GluonTS.)
# 5. The startup script takes about 40 min to run. After that, you can start Jupyter Lab in your Saturn Cloud
# project and run GPU-enabled modeltime.gluonts in a new Jupyter Notebook that uses the "R" kernel.
#
# More info about GPUs in modeltime.gluonts: https://business-science.github.io/modeltime.gluonts/articles/using-gpus.html
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo su -c "echo 'deb https://cran.rstudio.com/bin/linux/ubuntu bionic-cran40/' >>/etc/apt/sources.list"
sudo apt update
sudo apt -y install r-base libv8-dev libcurl4-openssl-dev libssl-dev
mkdir -p ~/.local/lib/R
export R_LIBS_USER=~/.local/lib/R
R -e "install.packages(c('IRkernel','tidymodels','tidyverse','devtools'))"
R -e "IRkernel::installspec()"
R -e "devtools::install_github('business-science/modeltime.gluonts')"
conda run -n saturn pip install gluonts pandas numpy pathlib mxnet-cu101
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Example: GPU-powered Deep Learning for Time Series with modeltime.gluonts on Saturn Cloud "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Set GLUONTS_PYTHON environment variable to point modeltime.gluonts to Python environment with mxnet installed\n",
"Sys.setenv(GLUONTS_PYTHON = '/srv/conda/envs/saturn/bin/python')\n",
"\n",
"# Import modeltime.gluonts\n",
"library(modeltime.gluonts)\n",
"\n",
"# Check if modeltime.gluonts can find the the Python environment (should be true)\n",
"is_gluonts_activated()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model_fit_deepar <- deep_ar(\n",
" id = \"id\",\n",
" freq = \"M\",\n",
" prediction_length = 24,\n",
" lookback_length = 36,\n",
" epochs = 10, \n",
" num_batches_per_epoch = 500,\n",
" learn_rate = 0.001,\n",
" num_layers = 3,\n",
" num_cells = 80,\n",
" dropout = 0.10\n",
") %>%\n",
" set_engine(\"gluonts_deepar\") %>%\n",
" fit(value ~ date + id, m750)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "R",
"language": "R",
"name": "ir"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "4.0.4"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
@mdancho84
Copy link

It turns out SaturnCloud has turned this into an image so we don't need to wait the 40 minutes for an image to build.
514354729342.dkr.ecr.us-east-2.amazonaws.com/saturn-r-modeltime-gpu:2021.03.01.02.45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment