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 exact spectral norm feature #831

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

lockwo
Copy link
Contributor

@lockwo lockwo commented Sep 6, 2024

Addresses part of #810.

@lockwo
Copy link
Contributor Author

lockwo commented Sep 6, 2024

Open to discussion on best interface. The current caution around bias is ok but could be a footgun (although the original paper doing the reshaping is already kind of a footgun imo lol), but maybe I can apply the linear transpose around the whole layer pytree and update the bias too? I'm not sure that would 100% generalize to all layers though.

equinox/nn/_spectral_norm.py Outdated Show resolved Hide resolved
equinox/nn/_spectral_norm.py Outdated Show resolved Hide resolved
Comment on lines +122 to +126
!!! Caution

If `exact` is true, it computes the transpose via `jax.linear_transpose` of
the layer. This includes all operations of the layer call, which means for
layers with a bias, this can result in the incorrect spectral value.
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe we should follow JAX's lead here and transpose the tangent pass of jax.jvp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm, I tried to implemented what I thought you meant. This also means we could remove the "weight" flag for the exact case (maybe?) since we basically "determine" the weight through the jvp?

Let me know if this is what you had in mind, or if I was totally off. Does seem like a lot of jvps tho.

equinox/nn/_spectral_norm.py Outdated Show resolved Hide resolved
equinox/nn/_spectral_norm.py Outdated Show resolved Hide resolved
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.

2 participants