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

Updated Fabric trainer example to not call self.trainer.model during validation #19993

Merged
merged 6 commits into from
Jun 21, 2024

Conversation

liambsmith
Copy link
Contributor

@liambsmith liambsmith commented Jun 18, 2024

Before, using the trainer would result in:

AttributeError: Your LightningModule code tried to access self.trainer.model but this attribute is not available when using Fabric with a LightningModule.

Which would occur during validation when 'on_validation_model_eval' and 'on_validation_model_train' were called, as they do not work with fabric. This change allows the model to be switched between train and eval mode (which the original behavior intends) without relying on calling 'self.trainer.model'. A check is added for overridden methods to not change a user's code.

Fixes #19992


📚 Documentation preview 📚: https://pytorch-lightning--19993.org.readthedocs.build/en/19993/

Before, using the trainer would result in:

AttributeError: Your LightningModule code tried to access `self.trainer.model` but this attribute is not available when using Fabric with a LightningModule.

Which would occur during validation when 'on_validation_model_eval' and 'on_validation_model_train' were called, as they do not work with fabric. This change allows the model to be switched between train and eval mode (which the original behavior intends) without relying on calling 'self.trainer.model'. A check is added for overridden methods to not change a user's code.
@github-actions github-actions bot added the fabric lightning.fabric.Fabric label Jun 18, 2024
@liambsmith
Copy link
Contributor Author

Added a second commit to fix a minor typo.

liambsmith and others added 3 commits June 20, 2024 13:42
…al()

Change to not overcomplicate the fix for fabric not working with the default "on_validation_model_eval" and "on_validation_model_train".
@awaelchli awaelchli added this to the 2.4 milestone Jun 21, 2024
@awaelchli awaelchli changed the title Updated trainer to not call self.trainer.model during validation. Updated Fabric trainer example to not call self.trainer.model during validation Jun 21, 2024
@awaelchli awaelchli merged commit 709a2a9 into Lightning-AI:master Jun 21, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
example fabric lightning.fabric.Fabric
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fabric example trainer fails with validation
2 participants