Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gradient ascent optimization algorithms #247

Merged
merged 2 commits into from
Jun 7, 2023
Merged

Conversation

salaast
Copy link
Collaborator

@salaast salaast commented Jun 1, 2023

This is part of the effort to port the work by Krzysztof Choromanski, Mark Rowland, Vikas Sindhwani, Richard E. Turner, Adrian Weller: "Structured Evolution with Compact Architectures for Scalable Policy Optimization", https://arxiv.org/abs/1804.02395

First step in Issue #248

@mtrofin mtrofin requested review from ebrevdo and mtrofin June 1, 2023 22:50
This is part of the effort to port the work by Krzysztof Choromanski, Mark Rowland,
Vikas Sindhwani, Richard E. Turner, Adrian Weller:  "Structured Evolution
with Compact Architectures for Scalable Policy Optimization",
https://arxiv.org/abs/1804.02395
Copy link

@ebrevdo ebrevdo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a piece of the total picture, right? Do you have a doc describing the entire GA plan?



# TODO(kchoro): Borrow JAXs optimizer library here. Integrated into Blackbox-v2.
class GAOptimizer(metaclass=abc.ABCMeta):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you follow the style guide a bit more closely?

  1. Avoid acronyms in names. GAOptimizer --> GradientAscentOptimizer or similar
  2. Can you use appropriate pytypes in all signatures and make sure this code passes pytpye checks?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rename will be addressed after porting and is kept track of with Issue #254.
The signatures will be addressed in a type annotations PR after the initial port.

###############################################################################
r"""Library of gradient ascent algorithms.

Library of stateful gradient descent algorithms taking as input the gradient and
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's worth calling the class GradientDescent and passing in the negative instead? Or change this text to gradient ascent?

Copy link
Collaborator Author

@salaast salaast Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text has been changed to gradient ascent in the related commit



class AdamOptimizer(GAOptimizer):
"""Class implementing ADAM gradient ascent optimizer."""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please describe the state vector here and in other optimizers' docstrings. Looks like here it's [mmv1] + [mmv2] + [1] where the last dim corresponds to the current step?

Copy link
Collaborator Author

@salaast salaast Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Descriptions for the states have been added in the related commit

0.1, 0.9)
optimizer.set_state(state)
recovered_state = optimizer.get_state()
np.testing.assert_array_equal(state, recovered_state)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid using equal for floats, even if you expect input and output to be identical. and certainly do not use equal when FP calculations are involved, like below.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer np.testing.assert_close/near/approx and similar.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remember to fix this in the next PR.

Copy link
Collaborator Author

@salaast salaast Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instances have been changed to assert_array_almost_equal in the related commit

@salaast
Copy link
Collaborator Author

salaast commented Jun 5, 2023

This is a piece of the total picture, right? Do you have a doc describing the entire GA plan?

The plan has been detailed in Issue #248

@ebrevdo ebrevdo self-requested a review June 7, 2023 18:04
@mtrofin mtrofin merged commit 093dae7 into google:main Jun 7, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants