Skip to content

Commit

Permalink
Fix legacy optimizer handling in compile_from_config().
Browse files Browse the repository at this point in the history
  • Loading branch information
nkovela1 authored and fchollet committed Sep 25, 2023
1 parent bd465a7 commit 277a4ff
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion keras/engine/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -3680,7 +3680,12 @@ def compile_from_config(self, config):
return
config = saving_lib.deserialize_keras_object(config)
self.compile(**config)
if hasattr(self, "optimizer") and self.built:
if (
hasattr(self, "optimizer")
# Exempt legacy optimizers.
and isinstance(self.optimizer, optimizer.Optimizer)
and self.built
):
# Create optimizer variables.
self.optimizer.build(self.trainable_variables)

Expand Down

0 comments on commit 277a4ff

Please sign in to comment.