Skip to content

[RFC] Introduce Plugin Registry #6923

@SeanNaren

Description

@SeanNaren

🚀 Feature

Introduce a registry, where plugins and users can register their own plugins to alias when creating the trainer (cc @tchaton who came up with the idea).

from pytorch_lightning.plugins import plugins_registry

print(plugins_registry.available_plugins(with_descriptions=True, with_recommendations=True))

# prints
# ddp_sharded: description ..., recommended when: ...
# deepspeed: description ..., recommended when: ...
# deepspeed_zero_3: description ..., recommended when: ...
# deepspeed_zero_3_offload: description ..., recommended when: ...
# ...

pl.Trainer(plugins='deepspeed_zero_3_offload')

Motivation

When using https://github.com/SeanNaren/minGPT I was testing across a bunch of different configurations across DeepSpeed and Sharded training. I was doing it manually, by specifying the plugin and the options available:

    trainer = Trainer.from_argparse_args(
        args,
        log_every_n_steps=1,
        max_epochs=1,
        # plugins=DDPPlugin(find_unused_parameters=True), # keep these for later to run
        # plugins=DDPShardedPlugin(ddp_comm_hook=...), # keep these for later to run
        plugins=DeepSpeedPlugin(stage=2, cpu_offload=False, logging_level=logging.INFO),
        gradient_clip_val=1.0,
        checkpoint_callback=False,
        callbacks=[lr_decay, CUDACallback()],
    )

This is extremely cumbersome and we're seeing a similar trend appear for other libraries as well, case or case. Having aliases allows users to use the trainer without having to modify the code. This is also important for cloud train agent solutions that rely on this flexibility from repos.

To support this in code right now, I either A) have to integrate a config tool to allow me to instantiate the plugins (Hydra) or B) add a bunch of branching statements and argparse.

Given the goal of Lightning is to reduce boilerplate, my proposal moves this boilerplate into Lightning rather than user code via a registry.

Alternatives

Force users to use an instantiating package such as Hydra in their own repo or implement their own branching logic to select a plugin.

Points from @carmocca discussion. I don't have answers to all these and most are not important now, but are important once this registry idea has been approved from the high level API.

How many plugins would we provide?

Leave it up to the plugin to decide. It would be nice to have an interface for the plugin (maybe an inherited classmethod) that defines the alias to add the plugin, and combinations to a registry.

Where would the registry be?

I think this question boils down to if we want a general registry across PL or separate registries. The registry should live in PL, and for a first iteration should be preferably tied to plugins for now. I can see further iterations if the idea proves more value to move to other arguments.

Should we do this for other trainer arguments?

Based on the above, I'd start with plugins first before moving onto all other arguments primarily to ensure the idea proves value. I can imagine a world where the registry provides easier access to certain objects that can be instantiated easily.

How would users register their own plugins?

Using the same registry. Preferably with a function or context manager.

Where would we register our plugins?

Like done in many other repos, we can add our pre-built plugins by a simple search across the plugins directory.

Will this introduce too much clutter?

To me this is a non-issue as I prioritise reducing user code clutter over lightning code clutter, and if aliases are handled by plugins, this means the responsibility is distributed. Currently to use custom plugins and the various configurations, it's impractical. If we'd like to continue reducing boilerplate we'll need some form of registry to make it easier to enable plugins with slightly different arguments.

Metadata

Metadata

Labels

discussionIn a discussion stagefeatureIs an improvement or enhancementhelp wantedOpen to be worked on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions