keras-team / keras-core

A multi-backend implementation of the Keras API, with support for TensorFlow, JAX, and PyTorch.
Apache License 2.0
1.27k stars 116 forks source link

v0.1.6 bug: AttributeError: 'GPT2CausalLM' object has no attribute 'compiled' #916

Closed sirfz closed 1 year ago

sirfz commented 1 year ago

Not sure if this affects other models but in v0.1.6 the .summary() method is broken on GPT2CausalLM. Downgrading to keras_core v0.1.5 resolves the issue.

Versions:

To reproduce:

import keras_nlp

gpt2_lm = keras_nlp.models.GPT2CausalLM.from_preset("gpt2_base_en")
gpt2_lm.summary()

Error output:

In [3]: gpt2_lm.summary()
Preprocessor: "gpt2_causal_lm_preprocessor"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Tokenizer (type)                                   ┃                                             Vocab # ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ gpt2_tokenizer (GPT2Tokenizer)                     │                                              50,257 │
└────────────────────────────────────────────────────┴─────────────────────────────────────────────────────┘
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[3], line 1
----> 1 gpt2_lm.summary()

File /opt/tensorflow/lib/python3.10/site-packages/keras_nlp/src/models/task.py:311, in Task.summary(self, line_length, positions, print_fn, **kwargs)
    308         print_fn(console.end_capture(), line_break=False)
    310 # Hardcode summary from keras_core for now.
--> 311 keras_core.Model.summary(
    312     self,
    313     line_length=line_length,
    314     positions=positions,
    315     print_fn=print_fn,
    316     **kwargs,
    317 )

File /opt/tensorflow/lib/python3.10/site-packages/keras_core/src/utils/traceback_utils.py:123, in filter_traceback.<locals>.error_handler(*args, **kwargs)
    120     filtered_tb = _process_traceback_frames(e.__traceback__)
    121     # To get the full stack trace, call:
    122     # `keras_core.config.disable_traceback_filtering()`
--> 123     raise e.with_traceback(filtered_tb) from None
    124 finally:
    125     del filtered_tb

File /opt/tensorflow/lib/python3.10/site-packages/keras_core/src/utils/summary_utils.py:311, in print_summary(model, line_length, positions, print_fn, expand_nested, show_trainable, layer_range)
    308 non_trainable_count = count_params(model.non_trainable_weights)
    309 non_trainable_memory_size = weight_memory_size(model.non_trainable_weights)
--> 311 if model.compiled and model.optimizer and model.optimizer.built:
    312     optimizer_weight_count = count_params(model.optimizer.variables)
    313     optimizer_memory_size = weight_memory_size(model.optimizer.variables)
mattdangerw commented 1 year ago

Thanks for the bug, we landed a fix for this on the keras-nlp side last week, we just need to cut a new keras-nlp release with this fix. Should do shortly!

https://github.com/keras-team/keras-nlp/pull/1244

mattdangerw commented 1 year ago

Release is out!