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

Disable EMA if the user inputs 0 for alpha #330

Merged
merged 1 commit into from
Jun 20, 2024

Conversation

RaulPPelaez
Copy link
Collaborator

EMA for the losses during training should be disabled if the user sends a 0 for it. Currently LNNP will happily take this number and make it so that the losses are detached:

        alpha = getattr(self.hparams, f"ema_alpha_{type}")
        if stage in ["train", "val"] and alpha < 1:
            ema = (
                self.ema[stage][type][loss_name]
                if loss_name in self.ema[stage][type]
                else loss.detach()
            )
            loss = alpha * loss + (1 - alpha) * ema
            self.ema[stage][type][loss_name] = loss.detach()
        return loss

Becomes just

 loss = loss.detach()

when alpha is set to 0.

I added a conditional to skip EMA if alpha is not between 0 and 1.

@RaulPPelaez RaulPPelaez merged commit e908988 into torchmd:main Jun 20, 2024
2 checks passed
@RaulPPelaez RaulPPelaez deleted the ema_fix branch June 20, 2024 09:43
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.

1 participant