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