-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[WIP] Accelerator registry follow-up #12461
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
Conversation
@@ -829,3 +831,9 @@ def is_distributed(self) -> bool: | |||
if isinstance(self.accelerator, TPUAccelerator): | |||
is_distributed |= self.strategy.is_distributed | |||
return is_distributed | |||
|
|||
|
|||
def _populate_registries() -> None: |
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.
Why have it in accelerator_connector
, not during import time __init__
?
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.
Because we don't need to do it on import time, so better to delay it if possible.
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.
Why not? What's the benefit of delaying it?
If I do this
from pytorch_lightning.accelerators.registry import ACCELERATOR_REGISTRY
print(ACCELERATOR_REGISTRY.names)
I would be expecting a list of accelerator names, rather than calling one more function _populate_registeries
before it. Also registeries
is plural, and we are populating only one Registry
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.
Doing things at import time is usually problematic. In addition to slowing time to start running, it means users are very limited when they want to override or customize behaviour.
Also registeries is plural, and we are populating only one Registry
Yes, but we would eventually do the same changes for strategies.
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.
For strategies, we really can't get rid of register_strategies
, as we have multiple configurations for certain strategies.
That's the major con of this approach, we can't have multiple subclasses with different defaults in our code.
We can't have an inconsistent api for registering strategies and accelerators.
pass | ||
@staticmethod | ||
@abstractmethod | ||
def name() -> str: |
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.
The discussion for removing the name
method. #12180 (comment)
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 think having name
is useful and clearly separates the accelerator from the registry. Otherwise the registry logic (a protected class) leaks inside the Accelerator
(a stable class).
It also allows registering the accelerators automatically as shown in this PR.
One drawback I see is that one class couldn't register multiple instances of itself. But we could create subclasses with those defaults.
class MyAccel(Accelerator):
def __init__(self, a=None):
...
@staticmethod
@abstractmethod
def name():
return "my_accel"
class MyAccelA2(MyAccel):
def __init__(self, a=2):
super().__init__(a=a)
@staticmethod
@abstractmethod
def name():
return "my_accel_a_2"
cc @justusschock @ananthsub as participants from prev discussion
What does this PR do?
My review of #12180
Does your PR introduce any breaking changes? If yes, please list them.
None as this is unreleased.
Before submitting
PR review
Anyone in the community is welcome to review the PR.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:
Did you have fun?
Make sure you had fun coding 🙃