Repository navigation
Remember the first PID gradient for the next derivative - #560
Open
shaneraphel wants to merge 1 commit into
Open
shaneraphel wants to merge 1 commit into
shaneraphel wants to merge 1 commit into
Conversation
The first step assigned the local name g_buf to the current gradient after storing a zero buffer. The stored gradient stayed 0, and the next step took its derivative against that zero instead of the gradient from the previous step. Copy the gradient into the buffer. The first derivative is still 0, because there is no earlier gradient. The second step then uses (1 - momentum) times the change in gradient.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The first step of
PIDdid this:The second assignment rebinds the local name. The buffer stored in the state stays zero, and the derivative on that step is
d_p - d_p = 0. The following step still reads the zero buffer, so its derivative is taken against 0 rather than against the gradient from the previous step. The same two lines are in the cited reference,tensorboy/PIDOptimizer. Copying them preserved the missed store.The gradient is now copied into the buffer. The first derivative stays 0, because there is no earlier gradient. With momentum 0.5, integral 0, derivative 10 and learning rate 1, gradients 1 then 3 move a parameter that starts at 0 to -1 and then to -14. Against a zero previous gradient the second step would have been -19.
Test plan
pytest tests/test_pid_grad_buffer.py— after the first step the buffer equals 1 and the parameter is -1; after the second step the parameter is -14.