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

Set model to eval mode for knn and linear classification #1440

Closed
guarin opened this issue Nov 30, 2023 · 0 comments · Fixed by #1444
Closed

Set model to eval mode for knn and linear classification #1440

guarin opened this issue Nov 30, 2023 · 0 comments · Fixed by #1444

Comments

@guarin
Copy link
Contributor

guarin commented Nov 30, 2023

Our knn and linear classifiers used for benchmarking do not set the model to evaluation mode before training. Instead we only set requires gradients to False, see:

def on_fit_start(self) -> None:
# Freeze model weights.
deactivate_requires_grad(model=self.model)
def on_fit_end(self) -> None:
# Unfreeze model weights.
activate_requires_grad(model=self.model)

The correct way to do this would be to set the model to eval mode before every training epoch:

def on_train_epoch_start(self) -> None:
    if self.freeze_model:
        self.model.eval()

Note that it has to happen in on_train_epoch_start because pytorch lightning automatically sets models to train mode at the beginning of the training epoch.

This was already implemented in #1263 but the PR is not yet merged to the main branch (and probably won't be merged for a while).

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 a pull request may close this issue.

1 participant