Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions keras/src/callbacks/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ def set_model(self, model):

@property
def model(self):
if backend.backend() == "torch":
from torch.nn.parallel import DistributedDataParallel

if isinstance(self._model, DistributedDataParallel):
# Keras Callbacks expect to work with Keras models. e.g
# ModelCheckpoint and EarlyStopping both attempt to call
# keras-specific APIs on the value returned from this
# property. If this callback was created against a DDP
# wrapper instead of the underlying keras.Model, it is
# likely to fail. Return self._model.module for DDP
# instances instead.
return self._model.module

if backend.backend() == "jax" and hasattr(
self._model, "jax_state_sync"
):
Expand Down