Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3....

15
USING NGC WITH ALIBABA CLOUD DU-08909-001 _v02 | December 2018 Setup Guide

Transcript of Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3....

Page 1: Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3. (Optional) Installing Alibaba CLI To use the Alibaba CLI, follow the Alibaba CLI Install

USING NGC WITH ALIBABA CLOUD

DU-08909-001 _v02 | December 2018

Setup Guide

Page 2: Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3. (Optional) Installing Alibaba CLI To use the Alibaba CLI, follow the Alibaba CLI Install

www.nvidia.comUsing NGC with Alibaba Cloud DU-08909-001 _v02 | ii

TABLE OF CONTENTS

Chapter 1. Introduction to Using NGC with Alibaba Cloud.............................................. 1Chapter 2. Preliminary Setup................................................................................. 3

2.1. Setting Up SSH Keys......................................................................................32.2. Setting Up a Security Group............................................................................32.3. (Optional) Installing Alibaba CLI....................................................................... 5

Chapter 3. Launching an NVIDIA GPU Cloud VM with the Alibaba Console........................... 63.1. Creating the NVIDIA GPU Cloud VM Instance........................................................ 63.2. Connecting to the VM Instance with SSH............................................................. 9

Chapter 4. Launching an NVIDIA GPU Cloud Virtual Machine Image Using Alibaba CLI........... 104.1. Getting the NGC VMI Image ID........................................................................104.2. Creating Your VM Instance.............................................................................114.3. Assigning a Public IP Address......................................................................... 124.4. Starting the Instance................................................................................... 124.5. Connecting to the VM Instance with SSH............................................................124.6. Starting, Stopping, or Deleting Your VM Instance..................................................13

Page 3: Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3. (Optional) Installing Alibaba CLI To use the Alibaba CLI, follow the Alibaba CLI Install

www.nvidia.comUsing NGC with Alibaba Cloud DU-08909-001 _v02 | 1

Chapter 1.INTRODUCTION TO USING NGC WITHALIBABA CLOUD

These instructions are for using NGC with the International Alibaba Cloud. To viewinstructions for the Chinese Alibaba Cloud, see http://docs.nvidia.com/ngc.cn/ngc-alibaba-setup-guide-cn/.

NVIDIA makes available on the Alibaba Cloud platform a customized image optimizedfor the NVIDIA Pascal™ and Volta™ -based Tesla GPUs. Running NGC containers onthis virtual machine (VM) instance provides optimum performance for deep learningjobs.

For those familiar with the Alibaba platform, the process of launching the instance isas simple as logging into Alibaba, selecting the NVIDIA GPU Cloud Virtual MachineImage and one of the supported NVIDIA GPU instance types, configuring settingsas needed, then launching the VM. After launching the VM, you can SSH into it andstart running deep learning jobs using framework containers from the NGC containerregistry.

This document provides step-by-step instructions for accomplishing this.

Prerequisites

These instructions assume the following:

‣ You have an Alibaba account - https://home-intl.console.aliyun.com/ withpermissions to create resources.

‣ Browsed the NGC website and identified an available NGC container and tag to runon the VMI.

‣ If you plan to use the CLI or Terraform, then the Alibaba CLI must be be installed,with at least the ECS SDK, and you must create SSH keys to use with Alibaba; seesetup instructions below.

‣ Windows Users: The CLI code snippets are for bash on Linux or Mac OS X. If youare using Windows and want to use the snippets as-is, you can use the WindowsSubsystem for Linux and use the bash shell (you will be in Ubuntu Linux).

Page 4: Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3. (Optional) Installing Alibaba CLI To use the Alibaba CLI, follow the Alibaba CLI Install

Introduction to Using NGC with Alibaba Cloud

www.nvidia.comUsing NGC with Alibaba Cloud DU-08909-001 _v02 | 2

Additionally, if you plan to access locked NGC containers, you will need to perform thefollowing steps from the NGC website (see NGC Getting Started Guide)

‣ Signed up for an NGC account at https://ngc.nvidia.com/signup.‣ Created an NGC API key for access to locked containers within the NGC container

registry.

Page 5: Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3. (Optional) Installing Alibaba CLI To use the Alibaba CLI, follow the Alibaba CLI Install

www.nvidia.comUsing NGC with Alibaba Cloud DU-08909-001 _v02 | 3

Chapter 2.PRELIMINARY SETUP

Perform these preliminary setup tasks to simplify the process of launching the NVIDIAGPU Cloud machine image.

2.1. Setting Up SSH KeysIf you do not already have SSH keys set up specifically for Alibaba, you will need to setone up and have it on the machine you will use to SSH to the VM. In the examples, thekey is named "alibaba-key".

1. From a browser, log in to the ECS console - https://ecs.console.aliyun.com/. 2. Open the left navigation menu tab and then click Key Pairs from the Network &

Security group. 3. From the upper right of the screen, click Create Key Pair. 4. Give it a name, such as "alibaba-key" and click OK.

A .pem file will immediately download. This is the ONLY time you can download it. 5. After downloading the .pem file, move it to the .ssh directory.

mv alibaba-key.pem ~/.ssh/ chmod 400 ~/.ssh/alibaba-key.pem

On Windows, the location will depend on the SSH client you use, so modify the pathabove and in the snippets or your SSH client configuration.See the Alibaba documentation for Creating an SSH key pair.

2.2. Setting Up a Security GroupIn order to create instances, you need to put them in a Security Group.

1. Log in to the ECS console - https://ecs.console.aliyun.com/. 2. Open the left navigation menu tab and then click Security Groups from the

Network & Security group.

Page 6: Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3. (Optional) Installing Alibaba CLI To use the Alibaba CLI, follow the Alibaba CLI Install

Preliminary Setup

www.nvidia.comUsing NGC with Alibaba Cloud DU-08909-001 _v02 | 4

3. From the upper right of the screen, click Create Security Group. 4. Give it a name and description, then click OK. 5. Immediately set the rules using the section Quickly Create Rules.

a) Check SSH and HTTPS.b) At Custom Port Range, select TCP and then enter 5000/5000.c) Set Authorization Object = 0.0.0.0/0 or the IP address from which you will access.d) Click OK.

Page 7: Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3. (Optional) Installing Alibaba CLI To use the Alibaba CLI, follow the Alibaba CLI Install

Preliminary Setup

www.nvidia.comUsing NGC with Alibaba Cloud DU-08909-001 _v02 | 5

2.3. (Optional) Installing Alibaba CLITo use the Alibaba CLI, follow the Alibaba CLI Install Instructions and also install theECS SDK.

1. Install the ECS SDK.

sudo pip install aliyun-python-sdk-ecs

2. Configure the CLI with your keys.

aliyuncli configure

Page 8: Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3. (Optional) Installing Alibaba CLI To use the Alibaba CLI, follow the Alibaba CLI Install

www.nvidia.comUsing NGC with Alibaba Cloud DU-08909-001 _v02 | 6

Chapter 3.LAUNCHING AN NVIDIA GPU CLOUD VMWITH THE ALIBABA CONSOLE

3.1. Creating the NVIDIA GPU Cloud VM Instance 1. Log on the Alibaba Elastic Compute Service (ECS) console - http://

marketplace.alibabacloud.com/. 2. Search for NVIDIA GPU, then select the NVIDIA GPU Cloud Virtual Machine

Image. 3. Click Choose your plan from the NVIDIA GPU Cloud Virtual Machine Image

product page.

4. Near the bottom of the page, click ECS Advanced Purchase page.

Page 9: Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3. (Optional) Installing Alibaba CLI To use the Alibaba CLI, follow the Alibaba CLI Install

Launching an NVIDIA GPU Cloud VM with the Alibaba Console

www.nvidia.comUsing NGC with Alibaba Cloud DU-08909-001 _v02 | 7

5. Make the following selections from the Basic Configurations page..a) For Billing Method, select Pay-As-You-Go.

b) For Region, select one that contains the image (e.g. “US-West 1 Zone B“), andthen a region from the dropdown menu (for example, US.West 1 (Silicon Valley)).Note that not all regions support GPU instances.

c) For Instance Type,click Heterogeneous Compute and then locate and selecta GPU Compute Type gn5 instance according to your GPU and memoryrequirements.

d) For Image, select Marketplace Image, and then make sure the NVIDIA GPUCloud Virtual Machine Image is selected .

e) For Storage, add a disk for dataset storage by clicking Add Disk under DataDisk, and then entering the storage size.Recommended minimum dataset storage size is 1 TB (1024 GB)

f) Click Next: Networking. 6. Make the following selections from the Networking page.

a) For Security Group, click Select Security Group.b) Select your security group from the list, then click Select.

Make sure you created a Security Group as explained in the section Set UpSecurity Groups

Page 10: Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3. (Optional) Installing Alibaba CLI To use the Alibaba CLI, follow the Alibaba CLI Install

Launching an NVIDIA GPU Cloud VM with the Alibaba Console

www.nvidia.comUsing NGC with Alibaba Cloud DU-08909-001 _v02 | 8

c) Click Next: System Configurations. 7. Make the following selections from the System Configurations page.

a) Make sure Key Pair is selected for Log On Credentials.b) Click the Key Pair list arrow and then select your key pair.

8. Click Preview, then review your configuration. 9. Click the Terms of Service check box, indicating your acceptance, and then click

Create Instance.

10. At the Activated message, click Console.

Page 11: Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3. (Optional) Installing Alibaba CLI To use the Alibaba CLI, follow the Alibaba CLI Install

Launching an NVIDIA GPU Cloud VM with the Alibaba Console

www.nvidia.comUsing NGC with Alibaba Cloud DU-08909-001 _v02 | 9

Wait until your instance status is Running, then you can connect to the instanceusing SSH.

3.2. Connecting to the VM Instance with SSHOnce started, you can SSH into your instance using the SSH key for the root user. If youfollowed the setup in this tutorial, your key is in ~/.ssh/.

Command syntax:ssh -i <KEYPATH> root@<IP>

Example:ssh -i ~/.ssh/alibaba-key.pem [email protected]

Refer to Connect to a Linux Instance for more instructions on connecting to yourinstance.

Page 12: Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3. (Optional) Installing Alibaba CLI To use the Alibaba CLI, follow the Alibaba CLI Install

www.nvidia.comUsing NGC with Alibaba Cloud DU-08909-001 _v02 | 10

Chapter 4.LAUNCHING AN NVIDIA GPU CLOUDVIRTUAL MACHINE IMAGE USING ALIBABACLI

Using Example Python Scripts

A comprehensive set of example Python scripts for automating the CLI are provided athttps://github.com/nvidia/ngc-examples/tree/master/ncsp. You can download the scriptsand modify them to meet your requirements. The code examples that follow use similarenvironment variables and structure as the scripts.

Using the Instructions in this Chapter

This flow and the code snippets in this section are for Linux or Mac OS X. If you areusing Windows, you can use the Windows Subsystem for Linux and use the bash shell(where you will be in Ubuntu Linux).

Many of these CLI command can have significant delays.

For complete CLI documentation and sample scripts visit the Alibaba DocumentationCenter.

4.1. Getting the NGC VMI Image IDOnce started, you can SSH into your instance using the SSH key for the root user. If youfollowed the setup in this tutorial, your key is in ~/.ssh/.

You need to specify a source ImageID when creating an instance. Use this command tofind the latest ImageID of the NVIDIA-GPU-Cloud-Machine-Image:

aliyuncli ecs DescribeImages --RegionId us-west-1 \

--ImageName "NVIDIA-GPU-Cloud-Virtual-Machine" \

Page 13: Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3. (Optional) Installing Alibaba CLI To use the Alibaba CLI, follow the Alibaba CLI Install

Launching an NVIDIA GPU Cloud Virtual Machine Image Using Alibaba CLI

www.nvidia.comUsing NGC with Alibaba Cloud DU-08909-001 _v02 | 11

--output json --filter Images.Image[0].ImageId

It will output the Image ID such as "m-rj9iy0xjiod3ghkyhz4p"

4.2. Creating Your VM InstanceCreating an instance with the CLI is done using the `aliyuncli ecs CreateInstance`command.

Full syntax documentation - https://www.alibabacloud.com/help/doc-detail/25499.htm

Recommended Instance Options

‣ "--InternetMaxBandwidthOut 10" sets the peak outbound network bandwidth to 10Mbps. The valid range is [1, 200].

‣ "--InstanceChargeType PostPaid" sets the billing method to pay-as-you-go. Changethis to "PrePaid" to set it to a subscription billing.

Other Notable Create Instance Options

‣ The inbound network bandwidth defaults to 200 Mbps. Use "--InternetMaxBandwidthIn" to change this. The valid range is [1, 200].

‣ To change the size of the system disk (default is 40 GB), use the "--SystemDiskSize"option. Valid values are [40, 500].

‣ To add a data disk (up to 16), use the "--DataDiskNSize" and "--DataDiskNCategory"options where "N" is [1, 16]. Valid values are:

DataDiskNCategory DataDiskNSize Description

cloud [5, 2000] (default) Basic cloud disk

cloud_efficiency [20, 32768] Ultra cloud disk

cloud_ssd [20, 32768] Cloud SSD

ephemeral_ssd [5, 800] Ephemeral SSD

Launch ExampleLaunch the instance and capture the resulting JSON:aliyuncli ecs CreateInstance \ --RegionId us-west-1 \ --ImageId "m-rj9iy0xjiod3ghkyhz4p" \ --SecurityGroupId "sg-rj94krsusal2k5l6gnnz" \ --InstanceType ecs.gn5-c4g1.xlarge \ --InstanceName "my-instance" \ --InternetMaxBandwidthOut 10 \ --InstanceChargeType PostPaid \ --KeyPairName alibaba-key

Page 14: Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3. (Optional) Installing Alibaba CLI To use the Alibaba CLI, follow the Alibaba CLI Install

Launching an NVIDIA GPU Cloud Virtual Machine Image Using Alibaba CLI

www.nvidia.comUsing NGC with Alibaba Cloud DU-08909-001 _v02 | 12

The output shows the instance ID.{ "InstanceId": "i-rj9a0iw25hryafj0fm4v", "RequestId": "440ECC70-09F9-492C-AB9E-21AA9C4E0531"}

4.3. Assigning a Public IP AddressInstances created via CLI are not automatically given a public IP address.

To assign a public IP address to the instance you just created, run:

aliyuncli ecs AllocatePublicIpAddress --RegionId us-west-1 \ --InstanceId "i-rj9a0iw25hryafj0fm4v"

Successful completion of the command will return the IP address:{ "IpAddress": "47.89.248.188", "RequestId": "65EB59AE-FA75-446F-B5C7-2BA0F9A77CDC"}

4.4. Starting the InstanceInstances created via CLI are not started automatically.

To start the instance you just created, run:

aliyuncli ecs StartInstance --InstanceId "i-rj9a0iw25hryafj0fm4v"

4.5. Connecting to the VM Instance with SSHOnce started, you can SSH into your instance using the SSH key for the root user. If youfollowed the setup in this tutorial, your key is in ~/.ssh/.

Command syntax:ssh -i <KEYPATH> root@<IP>

Example:ssh -i ~/.ssh/alibaba-key.pem [email protected]

Refer to Connect to a Linux Instance for more instructions on connecting to yourinstance.

Page 15: Using NGC with Alibaba Cloud - Nvidia · Using NGC with Alibaba Cloud DU-08909-001 _v02 | 5 2.3. (Optional) Installing Alibaba CLI To use the Alibaba CLI, follow the Alibaba CLI Install

Launching an NVIDIA GPU Cloud Virtual Machine Image Using Alibaba CLI

www.nvidia.comUsing NGC with Alibaba Cloud DU-08909-001 _v02 | 13

4.6. Starting, Stopping, or Deleting Your VMInstanceOnce an instance is running, you can stop, (re)start, or delete your instance.

Stop:aliyuncli ecs StopInstance --InstanceId INSTANCE_ID

Start or Restart:aliyuncli ecs StartInstance --InstanceId INSTANCE_ID

Delete:aliyuncli ecs DeleteInstance --InstanceId INSTANCE_ID