Lightning-AI / Lightning-AI/pytorch-lightning

An explicit `trainer`'s method to trigger `callback`'s hook.

Open
#14,003 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

🚀 Feature

Consider to add one pair of methods: Trainer.trigger(message), and Callback.on_trigger(message).

Motivation

When I finish my experiment, I want the trainer to trigger a callback to do something (for example, rename output dir).
For example:

# main.py
if args.do_train:
    trainer.fit(...)
    trainer.test(...)
    trainer.trigger("train success")
if args.do_test_only:
    trainer.test(...)
    trainer.trigger("test success")
if args.do_predict_only:
    trainer.predict(...)
    trainer.trigger("predict success")

# xxx_callback.py
class OutputDirManager(Callback)
...
def on_exception(trainer, pl_module, exception)
      ...  # rename output dir to mark this is a fail experiment

def on_trigger(trainer, pl_module, message)
    # rename output dir to mark this is a success experiment
    if message=="train success"
        ...
    if message=="test success"
        ...
    if message=="predict success"
        ...

I think this pair of methods are flexible for wider usages.

cc @awaelchli @ananthsub @rohitgr7

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 by locating the Trainer and Callback definitions and reviewing how existing hooks are dispatched. Define the intended trigger message flow for the fit, test, and predict examples, then verify that callbacks receive the message and that the new API is covered by project tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Feature
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.