-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Make trainer.state a read-only property #3109
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3109 +/- ##
=======================================
- Coverage 90% 89% -1%
=======================================
Files 81 82 +1
Lines 7780 8320 +540
=======================================
+ Hits 6995 7410 +415
- Misses 785 910 +125 |
good work, but I would rather add also setter which main checks that the values in TrainerState type :] |
@Borda I would prefer to keep it read-only as well. everything that is exposed will most likely be used by users in some way. And checking for valid arguments is quite hard. We can check for types, but even arguments with correct types may be wrong w.r.t. to trainer's flow. |
pytorch_lightning/trainer/states.py
Outdated
if exiting is not None: | ||
self.state = exiting | ||
self._state = exiting | ||
else: | ||
self.state = state_before | ||
self._state = state_before |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._state = exiting if exiting is not None else state_before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me this looks completely fine :D
Making things, the user isn't expected to change directly read-only is always a good idea I think :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like to see this ❤️
What does this PR do?
Follow-up on #2541 to make trainer state read-only.
Before submitting
PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.
Did you have fun?
Make sure you had fun coding 🙃