Main Content

Use Experiment Manager to Train Networks in Parallel

Since R2020b

By default, Experiment Manager runs one trial of your experiment at a time on a single CPU. If you have Parallel Computing Toolbox™, you can configure your experiment to run multiple trials at the same time or to run a single trial at a time on multiple GPUs, on a cluster, or in the cloud.

Training ScenarioRecommendation
Run multiple trials at the same time using one parallel worker for each trial.

Set up your parallel environment, set Mode to Simultaneous, and click Run . Experiment Manager runs as many simultaneous trials as there are workers in your parallel pool. All other trials in your experiment are queued for later evaluation.

Alternatively, to offload the experiment as a batch job, set Mode to Batch Simultaneous, specify your Cluster and Pool Size, and click Run . For more information, see Offload Experiments as Batch Jobs to Cluster.

Experiment Manager does not support Simultaneous or Batch Simultaneous execution when you set the training option ExecutionEnvironment to "multi-gpu" or "parallel" or when you enable the training option DispatchInBackground. Use these options to speed up your training only if you intend to run one trial of your experiment at a time.

Run a single trial at a time on multiple parallel workers.

Built-In Training Experiments:

In the experiment setup function, set the training option ExecutionEnvironment to "multi-gpu" or "parallel". For more information, see Scale Up Deep Learning in Parallel, on GPUs, and in the Cloud.

If you are using a partitionable datastore, enable background dispatching by setting the training option DispatchInBackground to true. For more information, see Use Datastore for Parallel Training and Background Dispatching.

Set up your parallel environment, set Mode to Sequential, and click Run .

Alternatively, to offload the experiment as a batch job, set Mode to Batch Sequential, specify your Cluster and Pool Size, and click Run . Experiment Manager does not support this execution mode when you set the training option ExecutionEnvironment to "multi-gpu". For more information, see Offload Experiments as Batch Jobs to Cluster.

Custom Training Experiments:

In the experiment training function, set up your parallel environment and use an spmd block to define a custom parallel training loop. For more information, see Custom Training with Multiple GPUs in Experiment Manager.

Set Mode to Sequential and click Run .

Alternatively, to offload the experiment as a batch job, set Mode to Batch Sequential, specify your Cluster and Pool Size, and click Run . For more information, see Offload Experiments as Batch Jobs to Cluster.

In built-in training experiments, the results table displays whether each trial runs on a single CPU, a single GPU, multiple CPUs, or multiple GPUs. To show this information, click the Show or hide columns button located above the results table and select Execution Environment.

Tip

Set Up Parallel Environment

Train on Multiple GPUs

If you have multiple GPUs, parallel execution typically increases the speed of your experiment. Using a GPU for deep learning requires Parallel Computing Toolbox and a supported GPU device. For more information, see GPU Computing Requirements (Parallel Computing Toolbox).

  • For built-in training experiments, GPU support is automatic. By default, these experiments use a GPU if one is available.

  • For custom training experiments, computations occur on a CPU by default. To train on a GPU, convert your data to gpuArray objects. To determine whether a usable GPU is available, call the canUseGPU function.

For best results, before you run your experiment, create a parallel pool with as many workers as GPUs. You can check the number of available GPUs by using the gpuDeviceCount (Parallel Computing Toolbox) function.

numGPUs = gpuDeviceCount("available");
parpool(numGPUs)

Note

If you create a parallel pool on a single GPU, all workers share that GPU, so you do not get the training speed-up and you increase the chances of the GPU running out of memory.

Train on Cluster or in Cloud

If your experiments take a long time to run on your local machine, you can accelerate training by using a computer cluster on your onsite network or by renting high-performance GPUs in the cloud. After you complete the initial setup, you can run your experiments with minimal changes to your code. Working on a cluster or in the cloud requires MATLAB Parallel Server™. For more information, see Deep Learning in the Cloud.

See Also

Apps

Functions

Objects

Related Topics