-
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
Trainer cleanup #934
Trainer cleanup #934
Conversation
Looks good to me!
Never mind, it appears that pass is preferred. |
@Borda i think the ... is making the code unreadable to non engs... what's the advantage? |
The adventage of |
@Borda I agree with @williamFalcon here. I think the code is less readable with ellipsis rather than with regular
In the same spirit, maybe a potential enhancement would be to use type hinting to declare the expected type of such variables (see here)? |
well we already started with type hinting, but not yet propagated everywhere lol so I would say that it fine aligned with your ref to class basic or here (maybe I missed something?) Anyway, happy to discuss it or drop my suggestion... :] |
I don't find the code less readable with ellipsis but I guess this is a subjective opinion here. I want to raise something kind of related: I use pyright to check my Python code while coding and the checker raise 431 errors on PL code. Using ellipsis fixes some of them. For example, consider the following code in class TrainerTrainLoopMixin:
def __init__(self):
self.on_epoch_end = None
def run_training_epoch(self):
# (...)
# Pyright error:
# 'self.on_epoch_end()' has type 'None' and is not callable
self.on_epoch_end() Adding typing fixes the error in class TrainerTrainLoopMixin:
def __init__(self):
# Pyright error:
# Cannot assign member 'on_epoch_end' for type 'TrainerTrainLoopMixin'
# Expression of type 'None' cannot be assigned to member 'on_epoch_end' of class 'TrainerTrainLoopMixin'
# 'None' cannot be assigned to '(*args, **kwargs) -> Any'
self.on_epoch_end: Callable = None
def run_training_epoch(self):
# (...)
# Not Pyright error.
self.on_epoch_end() Adding ellipsis fixes it: class TrainerTrainLoopMixin:
def __init__(self):
# Not Pyright error.
self.on_epoch_end: Callable = ...
def run_training_epoch(self):
# (...)
# Not Pyright error.
self.on_epoch_end() Now to be honest I don't really know whether it's a hack that appear to work or a good practice (I am not very familiar with ellipsis. |
I had the same understanding of An example from PyCharm with some types put in, I think this is mostly just useful if we decide to start specifying types in the future. For abstract methods, I can't find a particular consensus on |
Why not just:
Then you could remove the |
Totally agree with @ethanwharris. Instead if just replacing @Borda maybe we should create an epic or issue for adding type annotations to the core modules (I'm not sure there's one)? |
@Borda Pyright is written in JS and is integrated out of the box in VSCode as an extension. You can also use it in Vim or on a command line: https://github.com/microsoft/pyright#installation |
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.
This looks great! :)
@luiscape ^^ ? |
* Trainer cleanup * update abstract * remove ... * remove __init__ * update mixin types * update callbacks * fix * lower test acc
What does this PR do?
minor cleaning Training inits in its parent classes... Partially solves #887
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 🙃