Lightning-AI / Lightning-AI/pytorch-lightning

Use the Callback state_key to disambiguate callbacks provided to trainer and from LightningModule

Open
#11,138 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

callback refactor
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

We still use the types of the callbacks here: https://github.com/PyTorchLightning/pytorch-lightning/blob/92d9fc2280091c300fe8848284b9f6dfcbd209eb/pytorch_lightning/trainer/connectors/callback_connector.py#L272-L283

This can lead to collisions, when perhaps we have multiple callback instances of the same type with different settings that we want to use together.

For checkpointing callback states, we have shifted to using the newly introduced callback state key here: https://github.com/PyTorchLightning/pytorch-lightning/blob/92d9fc2280091c300fe8848284b9f6dfcbd209eb/pytorch_lightning/trainer/callback_hook.py#L58

We can do the same thing in this callback connector

_Originally posted by @ananthsub in https://github.com/PyTorchLightning/pytorch-lightning/pull/11060#discussion_r768986581_

cc @justusschock @awaelchli @akihironitta @rohitgr7 @ananthsub @daniellepintz

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pytorch_lightning/trainer/connectors/callback_connector.py at the callback handling around lines 272-283, then read the state-key usage in pytorch_lightning/trainer/callback_hook.py around line 58. Trace how callbacks supplied to the Trainer and LightningModule are distinguished. Done means multiple instances of the same callback type with different settings can be used together without collisions.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.