From 277a4ff1b178f2e266497807dd027e0644f589b0 Mon Sep 17 00:00:00 2001 From: Neel Kovelamudi <60985914+nkovela1@users.noreply.github.com> Date: Mon, 25 Sep 2023 10:12:55 -0700 Subject: [PATCH] Fix legacy optimizer handling in `compile_from_config()`. --- keras/engine/training.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/keras/engine/training.py b/keras/engine/training.py index f8b2dbcfa2a..e6b0627ff63 100644 --- a/keras/engine/training.py +++ b/keras/engine/training.py @@ -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)