dlarray and parfor gives error

조회 수: 4 (최근 30일)
Roman Foell
Roman Foell 2023년 8월 7일
답변: Roman Foell 2023년 8월 9일
Hello together,
I want to accelerate my compuations with parfor while using dlarray.
My compuation looks like this:
parfor i = 1:num_features
feature = ... some calculations ...
loss_temp(i) = mse(feature,feature_ground_truth,'DataFormat','CB')
end
loss = sum(loss_temp);
gradients = dlgradient(loss,dlnet.Learnables);
It gives me the error:
Error using dlarray/dlgradient
Value to differentiate is not traced. It must be a traced real dlarray scalar. Use dlgradient inside a function called by dlfeval to trace the variables.
Error in modelGradients (line 67)
gradients = dlgradient(loss,dlnet.Learnables);
Does this mean, dlarray information is lost during parfor calculation and it is not compatible with it?
Thanks for your help.
Edit:
There is a website Link. Do I have to use dlaccelerate somehow? Thanks.

답변 (1개)

Roman Foell
Roman Foell 2023년 8월 9일
Thanks all,
I already got the answer:
Calculate the gradients inside the parfor loop and combine it outside.
Possible, because the gradient of a sum is the sum of the gradient summands.
Thanks.

카테고리

Help CenterFile Exchange에서 Operations에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by