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 perturb() to allow capturing intermediate gradients #2476

Merged
merged 1 commit into from
Sep 23, 2022

Conversation

IvyZX
Copy link
Collaborator

@IvyZX IvyZX commented Sep 22, 2022

Add a perturb() function in nn.Module, which could be used to capture the intermediate gradients inside a module's call.

See example in the docstring. There will be a future Colab/notebook with better examples.

@IvyZX IvyZX requested a review from levskaya September 22, 2022 21:23
@cgarciae
Copy link
Collaborator

Looks good! Should we add a simple test?

@IvyZX
Copy link
Collaborator Author

IvyZX commented Sep 23, 2022

Looks good! Should we add a simple test?

Test added!

Copy link
Collaborator

@levskaya levskaya left a comment

Choose a reason for hiding this comment

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

Looks good as a start. I still think we should think about whether there are ways to simplify using "perturb" in practice w.o. incurring too much extra memory burden. We may wish to reserve the right to modify this API as we understand how people will use it - perhaps it's worth marking as "experimental" in docstrings to be clear that we may need to tweak it in the future.

flax/linen/module.py Outdated Show resolved Hide resolved
@cgarciae
Copy link
Collaborator

@IvyZX @levskaya we forgot to add this new method to the sphinx page in docs/api_reference/flax.linen.rst, its currently not being rendered.

@IvyZX IvyZX deleted the perturb branch November 7, 2022 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants