Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

MATLAB Deep Learning Container on NVIDIA GPU Cloud for Amazon Web Services

Speed up your deep learning applications by training neural networks in the MATLAB® Deep Learning Container, designed to take full advantage of high-performance NVIDIA® GPUs. You can access the MATLAB Deep Learning Container remotely using a web browser or via a VNC connection.

The MATLAB Deep Learning Container contains MATLAB and a range of MATLAB toolboxes that are ideal for deep learning (see Additional Information).

This guide helps you run the MATLAB desktop in the cloud on an Amazon EC2® P3 instance. For other cloud service vendors, the required steps are different. The MATLAB Deep Learning Container, a Docker container hosted on NVIDIA GPU Cloud, simplifies the process. The container is available at the NVIDIA GPU Cloud Container Registry.

Requirements

  • Amazon® Web Services account

  • NVIDIA GPU Cloud account with valid API key

  • Valid MATLAB licenses for the products in the MATLAB Deep Learning Container (see Licensing for details)

Costs

You are responsible for the cost of the Amazon Web Services used when you create a cluster using this guide. Resource settings, such as instance type, affect the cost of deployment. For cost estimates, see the pricing pages for each AWS service you are using. Prices are subject to change.

Prepare Your AWS Account

If you do not have an Amazon Web Services account, create one at https://aws.amazon.com by following the on-screen instructions. Create a key pair using the Amazon EC2 Console.

Note

Make sure that you download the private key when you create a pair as it is the only way to connect to the instance as an administrator.

Launch the Docker Host Instance

Log in to your Amazon Web Services Console. From the Services menu, select EC2. Click the Launch Instance button.

On the Choose AMI page, navigate to the AWS Marketplace and search for the NVIDIA Volta Deep Learning AMI using the search term Volta. This Amazon Machine Image (AMI) is designed for use with NVIDIA GPU Cloud to take advantage of the Volta GPUs available in P3 instances.

Note that not all Availability Zones offer P3 instances. Your Availability Zone is defined during setup of your virtual private cloud (VPC).

On the Configure Instance, Add Storage, and Add Tags pages, configure your instance as needed.

If necessary, choose or create appropriate Security Groups for your instance on the Configure Security Group page.

When correctly configured, select the appropriate key pair option and start your instance. Make sure that you have access to your private key so you can log in to your instance.

Pull the Container

Pulling the container downloads the container image onto the Docker host instance, the machine on which the container is to be run. You have to pull the container only once per EC2 instance.

You can copy the pull command for the container image release from the NVIDIA Container Registry. In the Tags section, locate the container image release that you want to run. In the Pull column, click the icon to copy the docker pull command. The command is of the form:

docker pull nvcr.io/partners/matlab:r2018b

Ensure the last part of the pull command matches the MATLAB release you want to use.

Connect to your instance via SSH from your client machine with your private key, using PuTTY or another SSH client. The default username is:

ubuntu@ec2-public-ipv4-address.region.amazonaws.com
You can find the public IPv4 DNS address of your instance in your Amazon Web Services console.

When you log in to the instance, you are prompted for your NVIDIA GPU Cloud API key. Enter your key to log in to the NVIDIA Container Registry.

If necessary, you can manually log in to the NVIDIA GPU Cloud repository using the command

docker login nvcr.io

To authenticate with your API key, enter $oauthtoken as your username.

Username: $oauthtoken
Password: [My NGC API key]

Paste the docker pull command into your SSH client, and run the command on your EC2 instance.

Running the docker pull command downloads the MATLAB container image onto the host EC2 machine. It might take some time to download and extract the large container image.

Run the Container

Run the MATLAB Deep Learning Container using a command of the form:

nvidia-docker run -it --rm -p 5901:5901 -p 6080:6080 --shm-size=512M nvcr.io/partners/matlab:r2018b

Ensure the last part of the run command matches the MATLAB release you want to use.

The options -p hostport:containerport map ports from inside the container to ports on the Docker host so that you can connect to the container desktop. Ports used in the container are 5901 (for VNC connection) and 6080 (for web browser connection). If you are deploying multiple containers on the same host instance, you must increment the host ports until you find a free port. For example:

-p 5902:5901 -p 6081:6080

The MATLAB Deep Learning Container is now running on your EC2 machine.

Connect Securely

You can use SSH tunneling to set up an encrypted channel between your client machine and the container session. You must do this to access the desktop of the container running in your EC2 instance.

These instructions forward a client port to a container port via the Docker host instance. After you set up an SSH tunnel, all communication between the client port and the container port is secure.

Using PuTTY on a Windows Client

If you are using PuTTY to connect to your Docker host instance, add a new forwarded port using the menu option Change Settings, accessible by clicking the title bar. In the PuTTY Reconfiguration dialog box, under Category, choose Connection > SSH > Tunnels.

To connect via VNC, set up a tunnel to the container port 5901.

  • In the Source port field, enter a free port on the client machine starting at 5900, for example 5901.

  • In the Destination field, enter the relevant host port that you connected to container port 5901 in Run the Container, for example, localhost:5901. Note that you must use localhost and not the name of the host instance.

To connect via a web browser, set up a tunnel to the container port 6080.

  • In the Source port field, enter a free port on the client machine, for example 6080.

  • In the Destination field, enter the relevant host port that you connected to container port 6080 in Run the Container, for example, localhost:6080. Note that you must use localhost and not the name of the host instance.

If you are using multiple containers or running a VNC server on the client machine, you must increment the source ports on the client machine until you find a free port, for example 5902 or 6081.

Using a Command-Line Interface

If you are using a command-line interface to SSH-tunnel to a container port, use a command of this form:

ssh -L clientport:hostport ubuntu@ec2-public-ipv4-address.region.amazonaws.com

clientport is a free port on the client machine, for example 5901 or 6080. hostport is the host port that you connected to the container port in Run the Container, for example localhost:5901 or localhost:6080. Note that you must use localhost and not the name of the host instance.

For example, use this command:

ssh -L 5901:localhost:5901 ubuntu@ec2-public-ipv4-address.region.amazonaws.com

If you are running a VNC server on the client machine, you must increment the client ports until you find a free port, for example 5902 or 6081.

Run MATLAB in the Container

There are three ways to access MATLAB in the container:

  • Use a web browser to connect to the container desktop and run MATLAB desktop

  • Use VNC to connect to the container desktop and run MATLAB desktop

  • Run MATLAB using the command-line interface

Connect using a Web Browser

To connect using a web browser, use the URL:

http://localhost:6080

Note that you must use localhost and not the name of the host instance.

If you incremented the client port in Connect Securely, use the appropriate host port number, for example 6081.

You will see a login screen for noVNC. Click connect. When you are prompted for a password to access the desktop, use the password:

matlab

You can run MATLAB using the desktop icon. Log in using your MathWorks®Account.

If you cannot log in using your MathWorks Account, check that your account is connected to a license that is configured for cloud use. For more information, see Licensing.

Connect using VNC

To connect via VNC, use your VNC client to connect to the appropriate display port on the client, for example:

localhost:1 

Note that you must use localhost and not the name of the host instance.

If you incremented the client port in Connect Securely, use the appropriate host display port number, for example 2 for 5902.

To log in and connect to the container desktop, use the password:

matlab

You can run MATLAB using the desktop icon. Log in using your MathWorks Account.

If you cannot log in using your MathWorks Account, check that your account is connected to a license that is configured for cloud use. For more information, see Licensing.

Run MATLAB Using the Command-Line Interface

You can also run MATLAB from the terminal using the command-line interface using the command:

matlab

Note that there is no graphical desktop in this case.

If you cannot log in using your MathWorks Account, check that your account is connected to a license that is configured for cloud use. For more information, see Licensing.

Select GPUs for Training in the Container

MATLAB supports training a single network in parallel using multiple GPUs. To enable multi-GPU training in the MATLAB Deep Learning Container, use the trainingOptions function to set ‘ExecutionEnvironment’ to ‘multi-gpu’.

Train your network using the trainNetwork function. MATLAB opens a parallel pool of workers on all available GPUs. To select only specific GPUs for training, you can use gpuDevice. For further information, see Select Particular GPUs to Use for Training (Deep Learning Toolbox).

To test your container, you can run the Create Simple Deep Learning Network for Classification (Deep Learning Toolbox) example. To try this example, double-click the file MNISTExample.mlx in the Current Folder pane in the MATLAB startup folder. To run this example on all available GPUs, in the trainingOptions function, set the ‘ExecutionEnvironment’ to ‘multi-gpu’.

Import and Export Data

Importing Data from Amazon S3

If you have data stored in Amazon S3™, you can access it directly from MATLAB. For more information, see Work with Remote Data (MATLAB).

Read and Write Cloud Data

You can access data for deep learning and save trained networks in the cloud. Read and write data in Amazon EFS and Amazon EBS by connecting your storage to your EC2 instance and mounting it to your container.

First, connect the EFS or EBS to your EC2 instance. To do this, make sure that you created your EC2 and storage with the appropriate Security Group settings and access rules. For detailed instructions, see Using the Amazon Elastic File System (EFS) for Persistent Data Storage and Using the Amazon Elastic Block Storage (EBS) for Persistent Data Storage.

For example, suppose you have mounted an EFS volume into your host EC2 instance under a folder named efs. The following option mounts the EC2 source folder efs into a target folder in the container, ContainerDeepLearningData:

-v /efs:/ContainerDeepLearningData

Add the option to the docker run command in Run the Container.

You can now access and save data within the container in the folder ContainerDeepLearningData. Saved data is also available in the EFS volume. These files persist once the container is stopped. Modifying files from within the container overwrites the files in the EFS volume.

If you have several storage volumes mounted to the host EC2 instance, you can mount as many folders to the container as you need using additional -v options.

Run Options

Configure Desktop Access Password

To change the password to access the desktop in the container via VNC or from a web browser, you can use the following option:

-e PASSWORD=MyNewPassword

Add this option to the docker run command when deploying the container.

Further Configuration Options

For advanced users, further configuration of the container deployment is available through additional Docker options. For more information, see the Docker documentation

Close the Container Session

To close the container session, type exit from the container terminal. The container is stopped and removed. No processes or data are saved by default when the container is closed, unless you have saved data in the cloud by mounting cloud storage, as described in Import and Export Data.

Licensing

You can use your Individual License with the MATLAB Deep Learning Container. Your Individual License must be configured for use on the cloud (see Configure Your Individual License for details). Alternatively, you can use a network license running on a local FlexLM server (see Network Licenses for details). For other license types, contact cloud-support@mathworks.com.

To perform deep learning using GPUs in the MATLAB Deep Learning Container, you must have valid licenses for MATLAB, Deep Learning Toolbox™, and Parallel Computing Toolbox™. Valid licenses for the other products in the container (see Additional Information) are required to access the full functionality of the container.

  • If you do not have a valid license for Deep Learning Toolbox or Parallel Computing Toolbox, MATLAB displays a warning on startup indicating that you cannot use these products.

  • If you do not have a valid license for other products in the MATLAB Deep Learning Container, MATLAB displays a message on startup indicating that you cannot use these products.

Your licenses for MATLAB and the other products in the container must be current on MathWorks Software Maintenance Service.

You can obtain a trial license for products in the MATLAB Deep Learning Container at MATLAB Trial for Deep Learning on the Cloud.

Configure Your Individual License

The MATLAB Deep Learning Container uses MathWorks Hosted License Manager by default to manage licenses for the products in the container. To use the hosted license manager, some one-time changes are required to correctly configure your license for use with MATLAB on the cloud.

To configure your Individual License, go to Configure Your Individual MATLAB License for Cloud Use and enter your license number or activation key. If you do not have either, contact your license administrator. If you get a message telling you to contact MathWorks support, contact your license administrator and ask if they have enabled or plan to enable the license for cloud use. If you are not sure who the license administrator is, sign in to your MathWorks Account, select the license you are using, and then select the Contact Administrators tab.

After you configure your license for cloud use, you must sign in to your MathWorks Account each time you start MATLAB. Doing so requires an uninterrupted Internet connection to MathWorks servers. Your MathWorks Account must be associated to your license, which occurs when you follow the procedure for configuring your license for cloud use.

Network Licenses

If you have a network license, you can use this license with the MATLAB Deep Learning Container. For instructions, see Network Licenses.

Additional Information

What is NVIDIA GPU Cloud?

NVIDIA GPU Cloud is a Docker repository of containers that are designed to run applications on high-performance NVIDIA GPUs.

What is a Container?

When you want to run an application or a piece of software in a reliable way in multiple different locations, you can use a container. A container is a lightweight package that contains everything required to run a specific application (or set of applications), including code, libraries, drivers, and settings. Because applications in a container always run in the same way, they are useful for managing well-defined test and deployment environments.

Unlike a virtual machine, containers share the operating system of the host machine and multiple instances of the same container share common resources. This makes them lightweight. However, containers are isolated from each other and the host operating system. That is, applications inside a container can only access files and processes provided within that container.

You can deploy multiple instances of the same container on the same or different hosts to test your applications simultaneously. To extend functionality, you can mount additional files, folders, and devices to containers.

What is in the MATLAB Deep Learning Container?

The MATLAB Deep Learning Container contains MATLAB and several other toolboxes that are useful in deep learning applications.

  • Computer Vision System Toolbox™

  • GPU Coder™

  • Image Processing Toolbox™

  • MATLAB Coder™

  • Deep Learning Toolbox

  • Parallel Computing Toolbox

  • Signal Processing Toolbox™

  • Statistics and Machine Learning Toolbox™

  • Text Analytics Toolbox™

In addition, the container contains several Pretrained Convolutional Neural Networks (Deep Learning Toolbox):

You can import networks and network architectures into the container from TensorFlow®-Keras and Caffe, with or without layer weights. You can also convert trained networks to the Open Neural Network Exchange (ONNX) model format.

The MATLAB Deep Learning Container also contains:

By deploying this software in a container, you can avoid the set-up time needed to install and configure these products. You can run multiple containers to train several networks at once or in different locations with reproducible results.

Technical Support

For technical support, comments, and queries about the MATLAB Deep Learning Container, contact cloud-support@mathworks.com.

Related Topics