Main Content

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 by a VNC connection.

The MATLAB Deep Learning Container image 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® GPU enabled instance. For other cloud service vendors, the required steps are different. The MATLAB Deep Learning Container image, a Docker® container image hosted on NVIDIA GPU Cloud, simplifies the process. The container image is available at the NVIDIA GPU Cloud Container Catalog.

Requirements

To use the MATLAB Deep Learning Container image, you need:

  • An Amazon® Web Services account.

  • A MATLAB license that meets the following conditions:

Additionally, if you have a Concurrent license type, you must supply the port number and DNS address of the network license manager when you run the container. Add an option of the following form to the docker run command when you start the container.

-e MLM_LICENSE_FILE=27000@MyLicenseServer

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. For more information, see Amazon EC2 Key Pairs.

Note

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

Launch Docker Host Instance

Log in to your Amazon Web Services Console. Click Services > Compute > EC2 and launch an instance.

On the Launch instance page, name your instance and search for the NVIDIA GPU-Optimized AMI under Application and OS Images, select it and confirm. This Amazon Machine Image (AMI) is designed for use with NVIDIA GPU Cloud to take advantage of the Volta GPUs available in P3 instances.

Configure your instance type, network settings, and storage as needed. Note that not all Availability Zones offer P3 instances. Your Availability Zone is defined during setup of your virtual private cloud (VPC).

If necessary, choose or create appropriate Security Groups for your instance.

Select the appropriate key pair option and launch your instance. Make sure that you have access to your private key so you can log in to your instance.

After your instance launches successfully, open the Instances page from the navigation bar on the left. Locate the instance corresponding to your instance name. When the Status check field shows that all the checks pass, you can connect to your instance.

Connect to Instance

Click the Instance ID of your instance to go to the Instance summary page, which shows the public IPv4 DNS address of your instance. Connect to your instance by using SSH from your client machine with your private key, using PuTTY or another SSH client. If you use PuTTY, add the private key under Connection > SSH > Auth. If you use a command-line interface, add the private key using the tag -i "path/to/key.pem". The default username to connect to your EC2 instance is ubuntu. The address to connect to the instance has this form:

ubuntu@ec2-public-ipv4-address.amazonaws.com
Replace ec2-public-ipv4-address.amazonaws.com with the public IPv4 DNS address of your instance.

Pull Container Image

After connecting to the instance, pull the container image to download the container image onto the Docker host instance, the machine on which the container is to run. You need to do this only once per EC2 instance.

You can copy the pull command for the container image release from the NVIDIA GPU Cloud Container Catalog. 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 has the form:

docker pull nvcr.io/partners/matlab:r20XYz
Replace the tag r20XYz with the specific MATLAB release name, for example, r2020a. Ensure the last part of the pull command matches the MATLAB release you want to use.

Paste the docker pull command into your SSH client, and run the command on your EC2 instance. You do not need to log in to the NVIDIA Container Catalog to pull the container image.

Running the docker pull command downloads the MATLAB container image onto the host EC2 machine. Downloading and extracting the large container image can take some time.

Run Container

Run the MATLAB Deep Learning Container using a command in this form:

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

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

The option -p hostport:containerport maps ports from the Docker host instance to ports inside the container so that you can connect to the container desktop. The container uses the ports 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.

Run MATLAB in Container

Access MATLAB in the container in one of three ways:

  • Use a web browser to connect from your local machine to the container desktop and run MATLAB desktop.

  • Use VNC to connect from your local machine to the container desktop and run MATLAB desktop.

  • Run MATLAB using the command-line interface.

Connect Using Web Browser

To connect using a web browser, first set up a tunnel to the container port 6080 (default noVNC port) from your local machine. Do so by setting up an SSH tunnel from the local client machine to the port on the remote host instance that you connected to the container port 6080 when you executed the docker run command. For more information on how to set up an SSH tunnel, see Create Encrypted Connection to Remote Applications and Containers. Then, use a URL like the one in the browser on your local machine to connect to the appropriate port:

http://localhost:6080

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

On the login screen for noVNC that appears, 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. To check, visit License Center.

Connect Using VNC

To connect by VNC, first set up a tunnel to the container port 5901 (default VNC port) from your local machine. Do so by setting up an SSH tunnel from the local client machine to the port on the remote host instance that you connected to the container port 5901 when you executed the docker run command. For more information on how to set up an SSH tunnel, see Create Encrypted Connection to Remote Applications and Containers. Then, use a VNC client on your local machine to connect to the appropriate display port on the client:

localhost:1 

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

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. To check, visit License Center.

Run MATLAB Using Command-Line Interface

You can also run MATLAB from the local terminal using the command-line interface. First, set up an SSH connection to the remote host instance from your local machine. Then, run MATLAB from the command-line interface using this 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. To check, visit License Center.

Test Container Using Deep Learning Example

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, 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 Neural 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'.

Close Container Session

To close the container session, type exit from the container terminal. Doing so stops the container and removes it. 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 Share Data with Containers.

Terminate Instance

When you no longer need your instance, terminate it. Terminating the instance deletes all the data associated with it. To terminate your EC2 instance, go to the Instance summary page and click Terminate instance in the Instance drop-down list.

Additional Information

How Do I Configure the MATLAB Deep Learning Container?

You can configure and customize the behavior of a MathWorks container by setting specific environment variables. For more information, see Configure Containers.

What Is NVIDIA GPU Cloud?

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

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 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™

To perform deep learning using GPUs in the MATLAB Deep Learning Container, you must have a license for MATLAB, Deep Learning Toolbox, and Parallel Computing Toolbox. A license valid for the other products in the container is required to access the full functionality of the container.

  • If you do not have a 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 license for other products in the MATLAB Deep Learning Container, MATLAB displays a message on startup indicating that you cannot use these products.

You can obtain a trial license for products in the MATLAB Deep Learning Container at MATLAB Trial for Deep Learning on the Cloud. In addition, the container contains several Pretrained Deep 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 setup 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.

Related Topics

External Websites