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

Add Training Type Plugins Registry #6982

Merged
merged 27 commits into from
Apr 16, 2021

Conversation

kaushikb11
Copy link
Contributor

@kaushikb11 kaushikb11 commented Apr 13, 2021

What does this PR do?

Add Training Type Plugins Registry #6923

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 update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is free to review the PR once the tests have passed.
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 🙃

@codecov
Copy link

codecov bot commented Apr 13, 2021

Codecov Report

Merging #6982 (a6001b9) into master (fe0d088) will decrease coverage by 11%.
The diff coverage is 78%.

@@           Coverage Diff            @@
##           master   #6982     +/-   ##
========================================
- Coverage      92%     81%    -11%     
========================================
  Files         194     196      +2     
  Lines       12346   14134   +1788     
========================================
+ Hits        11331   11407     +76     
- Misses       1015    2727   +1712     

Comment on lines 20 to 41
class _TrainingTypePluginsRegistry(UserDict):
"""
This class is a Registry that stores information about the Training Type Plugins.

The Plugins are mapped to strings. These strings are names that idenitify
a plugin, eg., "deepspeed". It also returns Optional description and
parameters to initialize the Plugin, which were defined durng the
registeration.

The motivation for having a TrainingTypePluginRegistry is to make it convenient
for the Users to try different Plugins by passing just strings
to the plugins flag to the Trainer.

Example::

@TrainingTypePluginsRegistry.register("lightning", description="Super fast", a=1, b=True)
class LightningPlugin:
def __init__(self, a, b):
...

"""

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this opens up a new surface area for backwards compatibility, so we should have clear ways to mark registry entries as deprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we should have clear ways to mark registry entries as deprecated

@ananthsub What do you mean by this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaushikb11 we'll need some annotation as to whether a specific plugin configuration is deprecated. For example, if we want to remove a plugin or a specific configuration, we should give users enough heads up and apply our normal rules for deprecating artifacts.

That means we'll need more metadata associated with the registry entry, such as the description, but also the status of the entry. e.g. if its active or deprecated. this way, when we're reading the entries or instantiating items from the registry, we can warn users if they're using a deprecated plugin

Copy link
Member

@justusschock justusschock Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ananthsub Not sure about this. I think we can only list the active ones here and still handle the deprecation within the Trainer/AcceleratorConnector as we do now. If a plugin is deprecated, IMO it should no longer be listed here, but still supported by the Trainer for the deprecation phase

Copy link
Contributor

@SeanNaren SeanNaren Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for deprecating configurations why not:

@TrainingTypePluginsRegistry.register("myplugin", param=1, param_two=True, deprecate_version=1.5)

@kaushikb11 kaushikb11 changed the title WIP: Add Plugins Registry Add Training Type Plugins Registry Apr 14, 2021
@kaushikb11 kaushikb11 self-assigned this Apr 14, 2021
@kaushikb11 kaushikb11 added the feature Is an improvement or enhancement label Apr 14, 2021
@kaushikb11 kaushikb11 marked this pull request as ready for review April 14, 2021 20:11
@kaushikb11 kaushikb11 marked this pull request as draft April 14, 2021 20:38
@kaushikb11 kaushikb11 marked this pull request as ready for review April 15, 2021 19:48
Copy link
Contributor

@SeanNaren SeanNaren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @kaushikb11!

Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it ! Great work !

pytorch_lightning/plugins/plugins_registry.py Outdated Show resolved Hide resolved
pytorch_lightning/plugins/plugins_registry.py Outdated Show resolved Hide resolved
pytorch_lightning/plugins/plugins_registry.py Outdated Show resolved Hide resolved
tests/plugins/test_plugins_registry.py Show resolved Hide resolved
pytorch_lightning/plugins/plugins_registry.py Outdated Show resolved Hide resolved
pytorch_lightning/plugins/plugins_registry.py Outdated Show resolved Hide resolved
Copy link
Member

@justusschock justusschock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it!

from pytorch_lightning.utilities.exceptions import MisconfigurationException


class _TrainingTypePluginsRegistry(UserDict):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we maybe make this a general registry and reuse this with flash? We also have a registry in flash and duplicating this does not make sense...

I think you only have to change the naming of the fields...

cc @tchaton

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did think of a generic LightningRegistry that could be used for different types. But for now, there has only been a need for TrainingTypePlugins, we could change it down the road as well, as _TrainingTypePluginsRegistry is internal.

@kaushikb11 kaushikb11 merged commit 832a03a into Lightning-AI:master Apr 16, 2021
@kaushikb11 kaushikb11 deleted the feat/plugins_registry branch April 16, 2021 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants