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 NVIDIA DGX platforms. 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.
Host DGX system with Docker and NVIDIA Docker installed. For more information on how to configure your DGX system, see https://docs.nvidia.com/deeplearning/dgx/preparing-containers/index.html#prepare_dgx_system.
A MATLAB license valid for the products in the MATLAB Deep Learning Container. For more information about licensing for MathWorks Containers, see Configure License for MathWorks Containers (Licensing on Cloud Platforms).
You can obtain a trial license for products in the MATLAB Deep Learning Container at MATLAB Trial for Deep Learning on the Cloud.
Pulling the container downloads the container image onto the Docker host, the machine that runs the container. You have to pull the container only once.
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:r20XYz
r20XYz
must be replaced 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. Connect to the Docker host via SSH from your client machine using PuTTY or another
SSH client. Paste the docker pull
command into your SSH client,
and run the command on the Docker host. You do not need to log in to the NVIDIA Container Registry to pull the container image.
Running the docker pull
command downloads the MATLAB container image onto the host machine. It might take some time to
download and extract the large container image.
Run the MATLAB Deep Learning Container using this command:
nvidia-docker run -it --rm -p 5901:5901 -p 6080:6080 --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 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 machine, 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 DGX machine.
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
If your host machine is protected by a firewall or you cannot access the container desktop via a web browser or VNC, you can set up SSH tunnels to the container (see Connect Securely).
Connecting with a web browser uses port 6080
in the
container. To connect, use the URL:
http://hostname:6080
hostname
is the name of the Docker host machine running the
container, for example MyCompanyDGX1
. If you incremented the
host port in Run the Container, 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. To check, visit License Center.
Connecting with VNC uses port 5901
in the container. VNC
connects to the host display for the host port mapped to container port
5901
; for example, display 1
for host
port 5901
.
To connect, use your VNC client to connect to:
hostname:1
hostname
is the name of the Docker host machine running the
container, for example MyCompanyDGX1
. If you incremented the
host port in Run the Container, use the
appropriate host display port number, for example 2
for host
port 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. To check, visit License Center.
You can 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. To check, visit License Center.
You can use SSH tunneling to set up an encrypted channel between your client machine and the container session. Doing so provides a secure connection between the client and the container. If the host or client machine is protected by a firewall, you must use SSH tunelling.
These instructions forward a client port to a container port via the Docker host. After you set up an SSH tunnel, all communication between the client port and the container port is secure.
If you are using PuTTY to connect to your Docker host, 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
.
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@MyCompanyDGX1
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 the following command:
ssh -L 5901:localhost:5901 ubuntu@MyCompanyDGX1
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
.
You can now connect to the container desktop using the forwarded client port.
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 when making the tunnel, use the appropriate
client port number, for example 6081
.
To connect with 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 when making the tunnel, use the appropriate
client display port number, for example, 2
for port
5902
.
To run the MATLAB desktop, follow the instructions in Run MATLAB from 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'
.
You can access data for deep learning and save trained networks on the Docker
host. You can mount folders in the host system to the container using the
-v
Docker option.
For example, suppose you have a folder on the client machine named
MyDeepLearningData
. This folder contains the subfolder named
MyTrainingData
, which contains the set of images for training
the network. The folder also contains the subfolder
MyTrainedNetworks
, where you want to save your trained
network data.
The following option mounts the source folder
MyDeepLearningData
and its subfolders to a target folder in
the container, ContainerDeepLearningData
:
-v /MyCompanyDGX1/MyDeepLearningData:/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 available in the
host in the folder MyDeepLearningData
. These files persist once
the container is stopped. Note that modifying files from within the container
overwrites the files on the host.
You can mount as many folders to the container as you need using additional
-v
options.
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.
If your DGX system connects to the internet via a proxy server, you can specify your proxy settings when you run the container. If you are using MATLAB with online licensing, you need to specify your proxy settings to connect to the MathWorks online licensing servers.
Use an option of the form:
-e NGC_PROXY=<proxy-server-address>
Add this option to the docker run
command when deploying
the container.
You can specify the proxy server address using any of the following forms:
hostname:12345
shorthostname:12345
http://hostname:12345
http://username:password@hostname:12345
IPaddress:12345
where hostname
is the fully qualified domain
name, shorthostname
is the relative domain name, and
12345
is the port number.
If your license is administrated via a network license manager, you can use
this license with the MATLAB Deep Learning container. You can point to the
location of the license in the docker run
command. Add the
option:
-e MLM_LICENSE_FILE=27000@MyLicenseServer
Add this option to the docker run
command when deploying
the container.
For more information, see MATLAB Deep Learning Container on NVIDIA GPU Cloud.
For advanced users, further configuration of the container deployment is available through additional Docker options. For more information, see the Docker documentation
To close the container session, type exit
from the container
terminal. The Docker 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
host by mounting host storage, as described in Import and Export Data.
You can install the latest MATLAB updates or install additional toolboxes and add-ons. Then, you can save the container for later use to avoid having to reinstall your changes.
To install or update MATLAB, you must run MATLAB with superuser privileges. At a terminal inside the container session, start MATLAB with root privileges using the following command.
sudo matlab
You can install updates and toolboxes from within MATLAB. For information on how to install updates, see Update an Existing Installation (MATLAB). For information on how to install toolboxes and add-ons, see Get and Manage Add-Ons (MATLAB).
If you make changes within the container, such as installing updates, additional toolboxes, or add-ons, you can save the container for later use. You can then deploy the updated version of the container, without needing to install the updates or toolboxes again.
Perform these steps after you have made your changes in the container and while the container is still running.
On your client machine, open another connection to the Docker host, the machine running the container, using PuTTY or the same method you used to access the Docker host and launch the container.
Obtain the container ID of the running container using the following command.
docker ps
To save the container, use the docker commit
command.
docker commit <containerID> <repository>:<tag>
docker commit
command locally saves a new container image based on the specified container ID; in this case, based on the currently running container. You can view the images available locally using the docker images
command. As an example, suppose you are using MATLAB R2020a in the MATLAB Deep Learning Container. You have updated MATLAB in the container you are running currently and you want to save it for later use.
First, find the container ID of the running container.
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3d555451f07a nvcr.io/partners/matlab:r2020a "/bin/run.sh" 24 minutes ago Up 24 minutes 0.0.0.0:5901->5901/tcp, 0.0.0.0:6080->6080/tcp relaxed_pasteur
Next, commit the container image.
docker commit 3d555451f07a mymatlab:r2020a
docker run
command. nvidia-docker run -it --rm -p 5901:5901 -p 6080:6080 --shm-size=512M mymatlab:r2020a
NVIDIA GPU Cloud is a Docker repository of containers that are designed to run applications on high-performance NVIDIA GPUs.
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.
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 valid for MATLAB, Deep Learning Toolbox, and Parallel Computing Toolbox. A license valid for the other products in the container are required to access the full functionality of the container.
If you do not have a license valid 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 valid 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.
Import from Keras (Deep Learning Toolbox)
Import from Caffe (Deep Learning Toolbox)
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.
For technical support, comments, and queries about the MATLAB Deep Learning Container, contact
cloud-support@mathworks.com
.