Running trainNetwork() starts parallel pool in Matlab 2023b even when options.Ex​ecutionEnv​ironment = 'cpu'

5 views (last 30 days)
It seems the behaviour of trainNetwork has changed. I have a for loop that performs a grid search of models' hyper-parameters. After updating to version 2023b, parallel pool is being started whenever trainNetwork is invoked. Is this a bug or trainNetwork behaviour changed?
  6 Comments
Artem Lensky
Artem Lensky on 22 Sep 2023
In function
function executionSettings = setupExecutionEnvironment(options)
there is this if statement
% Validate PCT if needed. It is not needed only when the execution
% environment is set as CPU and dispatch in background is false
if isPoolNeeded || options.ExecutionEnvironment == "gpu"
nnet.internal.cnn.util.validatePCTIsInstalled(options.ExecutionEnvironment);
end
for some reason even when options.ExecutionEnvironment set to "cpu", isPoolNeeded is set to true, which leads to executing the pool even when there is no need for it.
Artem Lensky
Artem Lensky on 22 Sep 2023
I think I identified the problem, option DispatchInBackground was set to True expcplicitly. Surprisingly, it didn't execute the pool in previous Matlab version.

Sign in to comment.

Accepted Answer

Artem Lensky
Artem Lensky on 22 Sep 2023
Edited: Artem Lensky on 22 Sep 2023
Whenever option DispatchInBackground set true, trainNetwork executes parallel pool.
If I am not mistaken this behaviour was different in 2023a, I already deleted it so can't verify, but it would be nice if someone at Mathworks would check wherther
function executionSettings = setupExecutionEnvironment( opts, X, precision, networkInfo )
contains these lines
% In DLT if the training datastore is set up for background prefetch,
% enable background prefetch
backgroundPrefetch = iUseBackgroundPrefetch(X) || opts.DispatchInBackground;
  4 Comments
Joss Knight
Joss Knight on 25 Sep 2023
Experiment Manager can do an parameter sweep in whatever way you like, and the parameters can be anything you like, so rng seeds for instance.
Implementing a specific grid search algorithm (sweeping one parameter at a time) may require more manual intervention I'll admit. But you might still find it saves you time.
Artem Lensky
Artem Lensky on 26 Sep 2023
Thanks for the reply. I might give it another go. I am surprised the grid search hasn't been implemented as an out of the box feature given that it is one of the basic parameter search approaches. Perhaps in 2024 version :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!