added VICReg losses#12
Open
drscotthawley wants to merge 2 commits into
Open
Conversation
zqevans
reviewed
May 16, 2023
| # These two losses offer a sort of "repulsion" regularization, across the batch dimension, to keep the | ||
| # space from collapse. Intended to be connected to the latents in the middle of the autoencoder.. | ||
|
|
||
| def vicreg_var_loss(z, gamma=1, eps=1e-4): |
Collaborator
There was a problem hiding this comment.
These need to made into instantiable "loss modules" like the ones above. Also please add a test for them.
Collaborator
Author
|
@zqevans take a look at the new version; not sure I wrote the module class correctly. |
zqevans
reviewed
May 17, 2023
| def forward(self, inputs: TensorDict) -> TensorDict: | ||
| z = inputs['latent'] | ||
| # writing with self.... "hooks" to enable extraction of individual losses for logging | ||
| self.var_loss = vicreg_var_loss(inputs, gamma=self.gamma, eps=self.eps) |
Collaborator
There was a problem hiding this comment.
Shouldn't store values in instance variables like this, doesn't make sense semantically.
If you want to return the individual losses, you can do so in the inputs.update() call on line 217.
zqevans
reviewed
May 17, 2023
| inputs = accumulate_value( | ||
| inputs, | ||
| { | ||
| "vicreg_loss": self.weight * loss |
Collaborator
There was a problem hiding this comment.
Should be "generator_loss". This line adds the vic_reg loss to the overall accumulated loss while the inputs.update() line below is used to return the individual named losses.
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.
This adds a few very simple functions that implement VICReg.
If the style of writing these are not to your liking, let me know how I can be more compliant with the style
-- e.g. I didn't find it necessary to create nn.Module Classes for these since they are so simple, but I could so.