Skip to content

[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

Closed
wants to merge 3 commits into from
Closed

Conversation

carmocca
Copy link
Contributor

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

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

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:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 🙃

@carmocca carmocca added feature Is an improvement or enhancement accelerator labels Mar 25, 2022
@carmocca carmocca added this to the 1.6 milestone Mar 25, 2022
@carmocca carmocca self-assigned this Mar 25, 2022
@@ -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:
Copy link
Contributor

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__?

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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:
Copy link
Contributor

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)

Copy link
Contributor Author

@carmocca carmocca Mar 28, 2022

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

@carmocca carmocca modified the milestones: 1.6, 1.7 Mar 29, 2022
@carmocca carmocca removed this from the pl:1.7 milestone Jul 19, 2022
@carmocca carmocca closed this Sep 2, 2023
@carmocca carmocca deleted the feat/accel-registry branch September 2, 2023 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accelerator feature Is an improvement or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants