Volatile GPU-Util is 0% during Neural network training

9 vues (au cours des 30 derniers jours)
기태 김
기태 김 le 8 Sep 2023
Commenté : 기태 김 le 26 Sep 2023
Hello.
I would like to train my neural network with 4 GPUs (on a remote server)
To utilize my GPUs I set ExecutionEnvironment in the training option to 'multi-gpu'
However, the Volatile GPU-util remains at 0% during training.
It seems that the data load on the GPU memory.
I would appreciate your help.
  8 commentaires
Joss Knight
Joss Knight le 12 Sep 2023
Modifié(e) : Joss Knight le 12 Sep 2023
Right, so the parfor is opening a pool with a lot of workers (presumably you have a large number of CPU cores); but unfortunately these are then not used for your preprocessing during training. You need to enable DispatchInBackground as well. Try that. You should have received a warning on the first run, telling you that most of your workers were not going to be used for training.
It does look as though the general problem is that your data preprocessing is dominating the training time meaning only a small proportion of each second is being spent computing gradients, and this is what the Utilization is measuring. If DispatchInBackground doesn't help we can explore further how to vectorize your transform functions; you might also consider using augmentedImageDatastore, which provides most of what you need. Or you could preprocess data on the GPU.
기태 김
기태 김 le 14 Sep 2023
Thank you for your response, Joss. Using the augmentedImageDatastore with DispatchInBackground improved the situation with a single GPU, but the results were not entirely satisfactory. Consequently, I attempted to use multiple GPUs with DispatchInBackground, but it was unsuccessful. I am aware that I used the combine function, which cannot be partitioned. Additionally, I found this link: Cannot utilize fully all GPUs during network training - MATLAB Answers - MATLAB Central (mathworks.com). It seems that I could resolve the problem by creating my own custom datastore. However, after building my custom datastore, I still encountered an error message: "Input datastore does not support DispatchInBackground with parallel or multi-gpu ExecutionEnvironment."
Here's my Custom Datstore.
I am not sure what is the problem on it.
Thank you very much for your help.
classdef CustomImageDatastore < matlab.io.Datastore & ...
matlab.io.datastore.Shuffleable & matlab.io.datastore.Partitionable
properties
Datastore % Image Datastore
NumObservations
CurrentFileIndex
ReadSize = 1; % Default value is 1
end
methods
function ds = CustomImageDatastore(folder)
% ds = CustomImageDatastore(folder) creates a datastore
% from the images in folder using the specified read function.
% Create image datastore
imds = imageDatastore(folder, ...
'IncludeSubfolders', true, ...
'LabelSource', 'none', ...
'ReadFcn', @customReadFcn);
ds.Datastore = imds;
ds.NumObservations = numel(imds.Files);
ds.CurrentFileIndex = 1;
end
function tf = hasdata(ds)
tf = ds.CurrentFileIndex <= ds.NumObservations;
end
function [data,info] = read(ds)
% [data,info] = read(ds) read one mini-batch of data.
miniBatchSize = ds.ReadSize;
info = struct;
for i = 1:miniBatchSize
img = read(ds.Datastore);
predictors{i,1} = img;
responses{i,1} = img;
ds.CurrentFileIndex = ds.CurrentFileIndex + 1;
end
data = table(predictors, responses);
end
function reset(ds)
reset(ds.Datastore);
ds.CurrentFileIndex = 1;
end
function subds = partition(ds, numPartitions, index)
% Create a copy of datastore
subds = copy(ds);
subds.Datastore = partition(ds.Datastore, numPartitions, index);
subds.NumObservations = numel(subds.Datastore.Files);
subds.reset();
end
function dsNew = shuffle(ds)
% dsNew = shuffle(ds) shuffles the files in the datastore.
% Create a copy of datastore
dsNew = copy(ds);
dsNew.Datastore = copy(ds.Datastore);
imds = dsNew.Datastore;
% Shuffle files
numObservations = dsNew.NumObservations;
idx = randperm(numObservations);
imds.Files = imds.Files(idx);
end
end
methods(Access = protected)
function n = maxpartitions(ds)
n = ds.NumObservations;
end
end
end
function img = customReadFcn(filename)
% customReadFcn Read and process an image.
%
% img = customReadFcn(filename) reads the image from the specified
% filename, resizes it to 224x224x3, and normalizes it.
% Read image
img = imread(filename);
% Resize image to 224x224x3
img = imresize(img, [224, 224]);
% If the image is grayscale, replicate it to create a 3-channel image
if size(img, 3) == 1
img = repmat(img, [1, 1, 3]);
end
% Normalize image to [0, 1]
img = double(img) / 255;
end

Connectez-vous pour commenter.

Réponse acceptée

aditi bagora
aditi bagora le 25 Sep 2023
The error message indicates that there is an issue while distributing the data parallelly in the background. To fix the issue, the class "CustomImageDatastore" needs to implement an additional class "matlab.io.datastore.Subsettable." which will support parallel and multi-GPU environment.
For further details, refer the below documentation link.
Hope this helps you in solving the error.
  1 commentaire
기태 김
기태 김 le 26 Sep 2023
Hello Aditi, It works! Thank you very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by