From ee25c7384b80c951955d4de15fbb547d4707b5cd Mon Sep 17 00:00:00 2001 From: Matt Watson Date: Wed, 13 Sep 2023 15:50:32 -0700 Subject: [PATCH] Add compat shims for the upcoming keras-core release --- keras_nlp/models/task.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/keras_nlp/models/task.py b/keras_nlp/models/task.py index 6f65a78f33..5d9a605449 100644 --- a/keras_nlp/models/task.py +++ b/keras_nlp/models/task.py @@ -246,6 +246,17 @@ def summary( **kwargs, ): """Override `model.summary()` to show a preprocessor if set.""" + + # Compat fixes for tf.keras. + if not hasattr(self, "compiled"): + self.compiled = getattr(self.optimizer, "_is_compiled", False) + if ( + self.compiled + and self.optimizer + and not hasattr(self.optimizer, "built") + ): + self.optimizer.built = getattr(self.optimizer, "_built", False) + # Below is copied from keras-core for now. # We should consider an API contract. line_length = line_length or 108