Running Jupyter Lab on Spot Instances

Feb 24, 2019

Running Jupyter Lab on Spot Instances

Jupyter is considered to be the best framework for data scientists to process and develop machine learning models. One of the leading free deep learning courses, Fast AI extensively uses Jupyter Notebooks for teaching material. However, the cost of running a notebook with connected GPU is expensive on the cloud. This tutorial gives a brief overview how to run Jupyter Lab on Snark platform using spot instance to drive the cost 3x down.

Spot instances are three times cheaper, however they can be interrupted anytime. Snark manages the interruption by storing the data in a persistent storage and restarting the machine.

Everything in this tutorial can be completed using the Web UI with one-click jupyter.

Step 1. Setup

Assuming you already registered at the Lab authenticate yourself in the terminal.

> pip install snark
> snark login

Make sure your package is updated.

Step 2. Create a local yaml file jupyter.yaml

version: 1
    framework: jupyter
      gpu: k80
      spot: True
      - lab

and run snark up

> snark up -f jupyter.yaml

There are few interesting things happening here

  1. Snark automatically spins a spot instance on the cloud with k80 ($0.3/h) GPU. You could alternatively request v100 ($1/h) or add more gpus with gpu_count: 8.
  2. It Starts a Jupyter Lab inside persistent folder /snark
  3. Any data stored inside the folder will be persisted after any spot interruption
  4. In case of spot interruption the instance will be restarted.

Step 3. Open Jupyter Lab

It will take couple minutes to warm up the instance. In order to open the Jupyter Lab we need get the public IP and the access token.

> snark ps exp_id

exp_id is the id of the experiment shown after running command up. Alternatively you could run snark ps to get the exp_id and the corresponding ip.

Then, please take task_id from the above command to get the logs of running experiment.

> snark logs task_id

You can copy the link of the jupyter lab and replace localhost or (... or with the real ip of the docker and open in the browser. The link will look like ip:8888/?token=....

Once you are done with the experiment shut down the instance to save money.

> snark down exp_id

You can restart anytime and the stored data will appear in the same place.

Step 4. Fast AI

We also prepared Fast AI course for you to get started instantly. Simply use the following recipe.

version: 1
    framework: fastai
      gpu: k80
      spot: true
      - run

You will notice that fastai folder is created in your storage where your work can be saved eternally.

By default, Fast AI package downloads the training data to /home/ubuntu folder. In order to save training data, you could alter the location to store inside /snark/ folder


Instead of paying $0.9 for running K80 GPUs, using Snark platform you could save 3x on cloud costs. In case of interrupts your data will be kept safe inside a persistent storage. Enjoy running Jupyter Lab and learning deep learning using Fast AI course.