Created
June 8, 2018 10:40
-
-
Save eliask/cd14372aabcb871aaaa661a87e2a2b2d to your computer and use it in GitHub Desktop.
gcloud CLI: Creating a (pre-emptible) VM instance with the NVIDIA GPU Cloud (NGC) image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This creates a pre-emptible VM on Google Cloud with a | |
# more or less NVIDIA approved configuration and drivers | |
# using the public NVIDIA GPU Cloud (NGC) image on GCP. | |
# The VM has nvidia-docker installed so anything like | |
# this will work out of the box: | |
# | |
# $ docker run --runtime=nvidia --rm paperspace/fastai:cuda9_pytorch0.3.1 | |
# | |
# None of the public scripts and info had working configuration anywhere. | |
# Even the "official" sample scripts don't have working default configuration: | |
# https://github.com/NVIDIA/ngc-examples/tree/master/ncsp | |
# | |
# But this is how you do find out the available images: | |
# $ gcloud compute images list --project nvidia-ngc-public --no-standard-images | |
image=nvidia-gpu-cloud-image-20180515 | |
# List of zones at: https://cloud.google.com/compute/docs/gpus/ | |
ZONE=europe-west1-b | |
gcloud compute instances create ngc-example-vm \ | |
--preemptible \ | |
--image-project=nvidia-ngc-public \ | |
--image=$image \ | |
--accelerator type=nvidia-tesla-k80,count=1 \ | |
--boot-disk-size=32 \ | |
--machine-type=n1-standard-4 \ | |
--local-ssd="interface=nvme" \ | |
--zone=$ZONE \ | |
--maintenance-policy=TERMINATE \ | |
--metadata startup-script='#!/bin/bash | |
# Don't prompt for the nvcr.io API key each login: | |
sed -i "s/exit [0-9]*/exit 0/" /usr/bin/ngc-get-key.sh | |
# Install the drivers without user interaction: | |
yes | /usr/bin/gcp-ngc-login.sh | |
# While at it, upgrade system packages | |
apt upgrade -y | |
# NVIDIA drivers require reboot after installation so reboot unattended: | |
if ! [ -f /root/.ngc-install-done ]; then | |
touch /root/.ngc-install-done | |
reboot | |
fi' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great stuff :) Thanks for sharing.