YUFENG GUO: Don't you just love setting up your computer,
installing libraries, configuring them, and making
sure they're all compatible?
It's just so much fun.
No?
Yeah.
Me neither.
That's why we're going to skip around all that nonsense today
using Deep Learning VM Images on Google Compute Engine.
Welcome to AI Adventures where we explore the art, science,
and tools of machine learning.
My name is Yufeng Guo, and on this episode,
we're going to check out how to take advantage of Deep Learning
VM Images to make setting up a new environment a piece
of cake.
The Google Cloud Deep Learning VM Image
makes it easy and fast to instantiate
a VM image containing the most popular deep learning
and machine learning frameworks, all on a Google Compute Engine
instance.
It lets you launch Compute Engine instances preinstalled
with your choice of ML frameworks
like TensorFlow or even PyTorch.
And you can easily add Cloud TPU and, of course, GPU support.
You can either instantiate the image
using the Google Cloud Platform Cloud Launcher UI
or from the command line.
So now you get to use your favorite open source
tools even sooner without having to keep them up to date or deal
with installation troubles.
The Deep Learning VM Images are prepackaged
as a click-to-deploy virtual machine that
can be accessed in the marketplace,
formerly known as Cloud Launcher.
Search for Deep Learning VM and select
Launch on Compute Engine.
There, you can select from a number of different Deep
Learning VM Images with configurations
of CPU, memory, storage, GPU, and your choice
of installed libraries.
There are just a ton of combinations available,
and you can fine tune them for your specific workload.
The best part is that unlike a typical computer
under your desk, the hardware for a VM
can be edited at a moment's notice.
Need more memory, double the disk space,
or say another GPU or four?
Just edit away.
Let's take a look at how you can create these VMs using
the gcloud command line tool.
We will start with the simpler case of a virtual machine
with only CPU, no GPU.
In this case, we just need to decide
what zone to put our VM in and what machine learning
library we want to use with it.
Here's the list of all the available images
to choose from.
Let's say we do tf-latest-cpu.
The full command to run this word look something like this.
And once you run this, it will take a moment
to provision the machine and install all the software
packages.
Once the VM is up and running, you can SSH into the machine.
Instead of a standard SSH command,
I would recommend using this slightly modified SSH
command, which does a bit of port forwarding
for you to enable you to connect to JupyterLab
via your local Chrome browser, just like you were running it
locally.
Now, when you run this command, it
will drop you into an SSH session.
You can poke around there in the command line if you'd like,
but the real good stuff awaits in your browser.
Head over to localhost-8080, and it'll magically
load up JupyterLab.
It'll just be there.
Now we can do a whole separate video on just JupyterLab alone
but, in brief, it's like Jupyter Notebooks but way cooler.
You can manage your entire data science workflow from here,
running multiple notebooks in different tabs
and with different versions of Python even
and take some notes, say, in a text file.
OK.
So that's the end-to-end workflow
for a CPU-powered virtual machine.
Now let's say we want GPUs, because it seems like everyone
wants GPUs these days.
There are a few additional considerations
here that you'll need to keep in mind as you
work through this process.
The tricky part of doing all of this
is that you need to coordinate just a couple of things
to get these GPUs working right.
First, let's take a look at what GPUs are available.
As of this recording, there are options
that include the K80, the P100, and the V100.
So you'll need to perhaps do a little bit of research
to choose which one you want to use.
Once you've decided on your GPU of choice,
check out what regions a given GPU is available.
You can see that shown here.
And finally, head over to your Quotas page in Cloud Console
to ensure that you have enough quota
to provision a machine with that combination of GPU
in that zone.
This final step is crucial to getting your VM provisioned
successfully.
If you don't have the necessary quota,
go ahead and click on Edit Quotas
and submit a quota request.
On the surface, it seems to be all about having
the necessary quota.
But it's a bit more nuanced than that since the quota specifies
not only what model of GPU but also
what region that GPU sits in.
OK.
So say you've figured out what GPU you want,
what zone it should be in, and confirmed
that you have the necessary quota to provision it.
Now let's look at how to actually get a GPU-powered Deep
Learning VM going.
The step that differs from all the previous CPU workflow
that we just saw is how we actually start up the VM.
We can take the command that we used before and add to it
a few extra bargains.
First, we'll need to set the maintenance
policy to terminate.
This is due to the fact that we can't live migrate
a GPU-powered virtual machine.
So for maintenance, it'll actually shut down the VM,
but you can have it auto restart.
So always be sure to save your work.
Next, choose your GPU type and count, informed by that quota
deep dive we just did.
And finally add a piece of metadata,
which will ensure that the drivers to power your GPU
are installed on your behalf.
It's a couple of additional steps
to get these GPU-powered VMs working,
but I promise it's worth the effort.
Once you run this command, the rest of the workflow
is exactly the same.
And when you SSH into your machine,
JupyterLab is there waiting for you.
And if you do a PIP freeze, you can
see that the version of TensorFlow that is installed
is tensorflow-gpu.
So the next time you're thinking about installing
a bunch of libraries by hand, remember
to save yourself some time and energy
by using the Deep Learning VM Images on Google Cloud
Platform.
Thanks for watching this episode of Cloud AI Adventures.
And if you enjoyed it, please like it
and subscribe to get all the latest episodes right
when they come out.
Now, head on over to your console
and make yourself a deep learning environment
in the cloud.