-
Notifications
You must be signed in to change notification settings - Fork 197
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
Replaced seed with key in add_noise and noisy_sgd #1138
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
These changes look good! Can you sign the google CLA to be able to run unit tests? I like the change of placing the key first in the argument list. Can you take a look at these files as well:
It'd be good to rename the argument to |
I signed the CLA yesterday and went to bed. |
Awesome
Not at all, thanks for the contribution! Exactly, any additional commits in your branch will be added to the PR here, in the end, you can also squish your commits into one before merging with something like: $ git rebase -i main
$ # change all but one commit to "squish" leaving one of them (probably the first one) as "pick"
$ # if everything went well
$ git push -f (to overwrite history, which is necessary when squishing commits) |
Ok, and one more question - there are a lot of things that will change. Maybe we'll add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small comment about the signature of the optimizer. Otherwise I fully agree with Robert that a full pass would be great. Could be in a separate PR if needed.
optax/_src/alias.py
Outdated
@@ -1253,10 +1253,10 @@ def lamb( | |||
|
|||
|
|||
def noisy_sgd( | |||
key: chex.PRNGKey, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would still keep learning_rate first as in other optimizers for this function, and I would give a default value for the key for convenience, like key=jax.random.PNRGKey(0)
.
Sometimes one wants to benchmark quickly optimizers and it seems easier if they all have a similar signature, at least for the first argument.
On the other hand, for the transform, (add_noise
) and other functions Robert pointed out, I agree that it would make sense to have the key first.
Hi, haven't had time to make changes.
|
A default key value might be confusing giving determinism where people don't expect it, but Something like: def noisy_sgd(
learning_rate: base.ScalarOrSchedule,
eta: float = 0.01,
gamma: float = 0.55,
key: chex.PRNGKey | None = None,
) -> base.GradientTransformation:
if key is None:
raise ValueError("noisy_sgd optimizer requires specifying random key: noisy_sgd(..., key=random.key(0))") |
I like this idea. It may also smooth out backward compatibility issues with clear raised errors. |
@Tomas542 could you add this change? |
Yeap, I can do this. Also I will try to change tests. To summarize, we decided to replace all UPD: Also I would create another PR after we finish this discussion. And annotation would be |
Yes, good point for the annotation. And yes for the summary! |
Now we can move to #1145 |
Replaced
seed
inadd_noise
withkey
in favor ofjax.random
-like style.Added (duplicated) example with
add_noise
fromnoisy_sgd
.Changed
seed
tokey
innoisy_sgd
. Importedchex
for annotation purpose in_alias.py