Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keras Tuner crashes with Keras 3.0 #963

Open
To3No7 opened this issue Oct 22, 2023 · 2 comments
Open

Keras Tuner crashes with Keras 3.0 #963

To3No7 opened this issue Oct 22, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@To3No7
Copy link

To3No7 commented Oct 22, 2023

Describe the bug
When I was trying our Keras 3.0 it seems that Keras Tuner is crashing due to compatibility problems

First it seems to fail on check “isinstance(model, keras.models.Model)”

    165         # Stop if "build()" does not return a valid model.
    166         if not isinstance(model, keras.models.Model):
--> 167             raise errors.FatalTypeError(
    168                 "Expected the model-building function, or HyperModel.build() "
    169                 "to return a valid Keras Model instance. "

FatalTypeError: Expected the model-building function, or HyperModel.build() to return a valid Keras Model instance. Received: <Sequential name=sequential_1, built=True> of type <class 'keras.src.models.sequential.Sequential'>.

Then there is some problem what is returned from model.fit()

FatalTypeError: Expected the return value of HyperModel.fit() to be one of float, dict, keras.callbacks.History, or a list of one of these types. Recevied return value: <keras.src.callbacks.history.History object at 0x7f5974212050> of type <class 'keras.src.callbacks.history.History'>.

If one get past these two then there are problems with the new way to handle save and load models. C.f. https://groups.google.com/g/keras-users/c/jgGcX730WGE

RuntimeError: Number of consecutive failures exceeded the limit of 3.
Traceback (most recent call last):
  File "~/.local/lib/python3.10/site-packages/keras_tuner/engine/base_tuner.py", line 273, in _try_run_and_update_trial
    self._run_and_update_trial(trial, *fit_args, **fit_kwargs)
  File "~/.local/lib/python3.10/site-packages/keras_tuner/engine/base_tuner.py", line 238, in _run_and_update_trial
    results = self.run_trial(trial, *fit_args, **fit_kwargs)
  File "/tmp/ipykernel_22160/2305993176.py", line 9, in run_trial
    return super(MyTuner, self).run_trial(trial, *args, **kwargs)
  File "~/.local/lib/python3.10/site-packages/keras_tuner/engine/tuner.py", line 314, in run_trial
    obj_value = self._build_and_fit_model(trial, *args, **copied_kwargs)
  File "~/.local/lib/python3.10/site-packages/keras_tuner/engine/tuner.py", line 233, in _build_and_fit_model
    results = self.hypermodel.fit(hp, model, *args, **kwargs)
  File "~/.local/lib/python3.10/site-packages/keras_tuner/engine/hypermodel.py", line 149, in fit
    return model.fit(*args, **kwargs)
  File "~/.local/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py", line 123, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "~/.local/lib/python3.10/site-packages/keras_tuner/engine/tuner_utils.py", line 76, in on_epoch_end
    self._save_model()
  File "~/.local/lib/python3.10/site-packages/keras_tuner/engine/tuner_utils.py", line 86, in _save_model
    self.model.save_weights(write_filepath)
ValueError: The filename must end in `.weights.h5`. Received: filepath=output/FashionMNIST/trial_02/checkpoint

To Reproduce
I believe this will be true for any example running with Keras 3.0, but here is a colab notebook that shows this behaviour for the first type of crash, if that is fixed then the others will appear!
https://colab.research.google.com/drive/1v-RblPL4XiYY_AmGW47xLL6v5sbq2ggY?usp=sharing

Expected behavior
No crash!

Additional context
TensorFlow version: 2.16.0-dev20231022
Keras version: 3.0.0.dev2023102203
Keras Tuner version: 1.4.5

Would you like to help us fix it?
Would be interested, but not sure I have the knowledge to do that.

@To3No7 To3No7 added the bug Something isn't working label Oct 22, 2023
@haifeng-jin haifeng-jin self-assigned this Oct 23, 2023
@haifeng-jin
Copy link
Collaborator

Thank you so much for the issue, @To3No7 !
I am looking into this.
KerasTuner v1.4.5 is build with keras-core instead of keras-nightly.
We will support the keras-nightly soon.

@To3No7
Copy link
Author

To3No7 commented Nov 11, 2023

I was testing KerasTuner today see colab file and now it works again, good job!

Keras Tuner version: 1.4.7.dev0
TensorFlow version: 2.16.0-dev20231111
Keras version: 3.0.0.dev2023111003

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants