The adamupdate function in MATLAB R2024b incorrectly uses uint32 with sqrt and exhibits state corruption, causing errors even in minimal test cases."
Show older comments
% Test adamupdate function
clc;
clear;
% Define test parameters
learnable = dlarray(randn(5, 1)); % Example learnable parameter
gradient = dlarray(randn(5, 1)); % Example gradient
state = []; % Initial state (empty)
optimizer = trainingOptions('adam', 'InitialLearnRate', 0.01); % Example optimizer
timeStep = uint32(1); % Initial time step
try
% Perform a single adamupdate
updatedLearnable = adamupdate(learnable, gradient, state, optimizer, timeStep);
% Display results
disp('adamupdate test successful!');
disp('Updated Learnable:');
disp(updatedLearnable);
catch ME
% Display error message
disp('adamupdate test failed!');
disp(['Error: ', ME.message]);
%Display the stack trace to help Mathworks track the problem.
disp('Stack Trace:');
disp(ME.stack);
end
% Perform a second adam update to test state persistence.
timeStep = uint32(2);
try
% Perform a single adamupdate
updatedLearnable = adamupdate(learnable, gradient, state, optimizer, double(timeStep));
% Display results
disp('adamupdate second test successful!');
disp('Updated Learnable:');
disp(updatedLearnable2);
catch ME
% Display error message
disp('adamupdate second test failed!');
disp(['Error: ', ME.message]);
%Display the stack trace to help Mathworks track the problem.
disp('Stack Trace:');
disp(ME.stack);
end
Accepted Answer
More Answers (1)
Categories
Find more on Visualization and Interpretability in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!