Skip to content

LightningModule.configure_callbacks overrides Trainer callbacks #18784

Open
@adamjstewart

Description

@adamjstewart

Outline & Motivation

In TorchGeo, we provide LightningModules for common tasks, like classification, regression, etc. We also provide default callbacks using LightningModule.configure_callbacks as suggested in #18480. However, it seems that these default callbacks override any user-specific callbacks provided to the Trainer. According to the documentation, this actually seems to be the intended behavior:

the list or a callback returned here will be merged with the list of callbacks passed to the Trainer’s callbacks argument. If a callback returned here has the same type as one or several callbacks already present in the Trainer’s callbacks list, it will take priority and replace them.

I propose reversing this behavior such that Trainer callbacks override LightningModule.configure_callbacks when both share the same type.

Pitch

Users should be able to override callbacks hard-coded in the LightningModule with whatever they pass to the Trainer. Otherwise the only way to change something like the model checkpoint frequency is to subclass the LightningModule, which is unideal.

Alternatively, if there's another way to provide model-specific default callbacks, please let me know.

Additional context

@robmarkcole and @roybenhayun reported several issues to us that stemmed from this behavior. If we can't solve this, we may have to remove all default callbacks.

@calebrob6

cc @Borda @carmocca @justusschock @awaelchli

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionIn a discussion stagefeatureIs an improvement or enhancementlightningmodulepl.LightningModule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions