Tutorial

Setting Up the GPU Droplet Environment for AI/ML Coding - Jupyter Labs

Published on October 3, 2024

Technical Evangelist // AI Arcanist

Setting Up the GPU Droplet Environment for AI/ML Coding - Jupyter Labs

In this tutorial, we are going to walk through all the required steps to setup a Jupyter Lab or Jupyter Notebooks instance on a DigitalOcean GPU Droplet. Additionaly, we will cover some of the essential tips and tricks for setting up and using the Jupyter Notebook to run Deep Learning code.

Jupyter is one of the premiere tools for running Machine Learning, Deep Learning, Data Science, and Python code in general. It is increasingly common for new ML/DL/AI coders to do work within Jupyter Notebooks, especially during the data exploration phases of a workflow. Jupyters unique design with sequential code boxes makes it ideal for practicing core ML skills as well.

Readers can expect to leave this tutorial with a full understanding of how to setup their environment for running Deep Learning code on a Jupyter Notebook on DigitalOcean.

Prerequisites

  • DigitalOcean account: Followers will need to sign up for DigitalOcean to follow along
  • Visual Studio Code: We are going to leverage this application to view the Jupyter Notebooks running on our cloud machine on our local window
  • Basic shell scripting: Users will need to enter commands into their terminal to follow along

Setting up the Local Environment

On your local machine, we are going to need to do two things:

  • Set up our SSH Key if it hasn’t been done yet. Follow this tutorial to create a new one, and add it to the DigitalOcean account you plan to use
  • Download VS Code: VS Code is our favorite code editor tool, especially because of its built in capabilities around handling SSH pipelines. With VS Code, we can open our remote Jupyter Notebook window on our local browser with ease

Leave the blank window for now, and return to your browser.

Starting the GPU Droplet

Starting a new GPU Droplet is simple. Follow the instructions on the setup page to create a new one. Then follow these steps:

  • Select a datacenter region closest to you, and the default VPC network
  • Choose the “AI/ML Ready” OS template, this is essential to making the GPU work with the CPU
  • Select a single H100 GPU or 8x machine. To follow along, only a single H100 is required
  • Create or select an existing SSH key to connect with your machine. Follow this tutorial to create a new one. This must be done before starting the Droplet if we want to access the full tutorial
  • Name your machine something unique

Once these steps are complete, you can create the machine using the prompt on the right side of the window. Be sure to consider any costs this may incur to your account if you continue from this step. With that, our machine setup is complete. We can now begin setting up our local machine environment while the Droplet spins up.

Setting up the GPU Droplet Environment

Now that our GPU Droplet is setup, we can SSH in from our local terminal window. Copy the IPv4 address at the top of the Droplet home page, and paste it into the command below to access the machine this way.

ssh root@<your IPv4 address here>

Paste this command into your local browser, and type yes if prompted about the fingerprint. This will connect you to your machine.

The first thing we need to do once logged in is change out of the root user. To do this, create a username for yourself and switvch to it with the following command.

useradd -m -g users <your username>
su <your username>
bash

You will likely need to re-open the bash shell at this step.

Next, we are going to navigate to the directory we are going to do our work in from our starting position at the root directory. In the same step, we will also install both Python and Jupyter. This install is relatively fast.

cd ../home
apt install python3-pip python3.10-venv
pip3 install jupyterlab

From here, everything is ready and setup to run the Jupyter Notebook.

Launch Jupyter

Launching Jupyter is the quickest step in the entire process. Simply enter the following command into your remote terminal.

jupyter lab

image

This will return three values, 1 file path and 2 urls. Copy one of the URLs for the next step.

Use VS Code to view the Jupyter Window on your Local Browser

Open VS Code up to a blank window on your local. In the center of the page, there should be a clickable button that says “Connect to”. This will open a prompt at the top of the search bar at the top of the window. Click “Connect to Host”, and then “+ Add New SSH Host…”. This is where your will paste your ssh key to connect VS Code to your remote machine. Paste the exact same command as we did earlier, repeated below

ssh root@<your IPv4 address here>

This will allow VS Code to remotely listen and interact with our GPU Droplet from our local machine.

image

The final step to open Jupyter on our local browser is to type “Command” + “Shift” + “P” together in the now connected VS Code welcome page. Search for the “Simple Browser” and open a new window.

image

In the URL Bar that now appears, paste the URL in. Click the open button on the far right of the URL bar to now open the Jupyter Notebook in your local browser.

The Jupyter Lab Environment

image

This should open the Jupyter Labs environment in our local browser! From here, we are free to interact with Jupyter to do our AI, ML, and data science coding.

Closing Thoughts

Jupyter is the premiere learning and exploration tool for data science, data engineering, and AI research. We hope that this tutorial helps users take advantage of the powerful GPUs available on the cloud to do their work on their local machines with little to no hassle for setup.

Sign up to access the new DigitalOcean GPU Droplets today!

Thank you for reading!

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar

Technical Evangelist // AI Arcanist

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
Leave a comment


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more