keras-team / keras-tuner

A Hyperparameter Tuning Library for Keras
https://keras.io/keras_tuner/
Apache License 2.0
2.85k stars 395 forks source link

Bayesian Crashes on 3rd Epoch each time. #658

Open STRATZ-Ken opened 2 years ago

STRATZ-Ken commented 2 years ago
Traceback (most recent call last):
  File "/home/stratz/work/training/stratz-keras/win_rate.py", line 733, in <module>
    main()
  File "/home/stratz/work/training/stratz-keras/win_rate.py", line 730, in main
    model.train()
  File "/home/stratz/work/training/stratz-keras/neural_net.py", line 182, in train
    self.run_generator()
  File "/home/stratz/work/training/stratz-keras/neural_net.py", line 98, in run_generator
    tuner.search(training_generator,
  File "/home/stratz/anaconda3/envs/stratz/lib/python3.9/site-packages/keras_tuner/engine/base_tuner.py", line 169, in search
    trial = self.oracle.create_trial(self.tuner_id)
  File "/home/stratz/anaconda3/envs/stratz/lib/python3.9/site-packages/keras_tuner/engine/oracle.py", line 189, in create_trial
    response = self.populate_space(trial_id)
  File "/home/stratz/anaconda3/envs/stratz/lib/python3.9/site-packages/keras_tuner/tuners/bayesian.py", line 209, in populate_space
    self.gpr.fit(x, y)
  File "/home/stratz/anaconda3/envs/stratz/lib/python3.9/site-packages/keras_tuner/tuners/bayesian.py", line 83, in fit
    self._alpha_vector = cho_solve(self._l_matrix, self._y_train)
  File "/home/stratz/anaconda3/envs/stratz/lib/python3.9/site-packages/keras_tuner/tuners/bayesian.py", line 31, in cho_solve
    y = solve_triangular(l_matrix, b.reshape(-1, 1), lower=True)
  File "/home/stratz/anaconda3/envs/stratz/lib/python3.9/site-packages/keras_tuner/tuners/bayesian.py", line 24, in solve_triangular
    return tf.linalg.triangular_solve(a, b, lower=lower).numpy()
  File "/home/stratz/anaconda3/envs/stratz/lib/python3.9/site-packages/tensorflow/python/framework/ops.py", line 442, in __getattr__
    self.__getattribute__(name)
AttributeError: 'Tensor' object has no attribute 'numpy'

I do use a custom loss function. Not sure if that matters, saw a few posts on it.

STRATZ-Ken commented 2 years ago

This was solved by enabling eager on the model, and not using accuracy but binary_accuracy.

jessegmeyerlab commented 2 years ago

I'm having the same problem training a regression model - fails on the third round. Using tf 2.9.1 so eager is enabled by default, and I tried using both 'mse' and 'val_mse' and both fail.

jessegmeyerlab commented 2 years ago

seems to be related to the num_initial_points parameter because after I change to 4 from the default of 2 it fails after 4 instead of 2

haifeng-jin commented 2 years ago

@jessegmeyerlab Are you getting the same error message of AttributeError: 'Tensor' object has no attribute 'numpy'?

jessegmeyerlab commented 2 years ago

@jessegmeyerlab Are you getting the same error message of AttributeError: 'Tensor' object has no attribute 'numpy'?

Yes

haifeng-jin commented 2 years ago

@jessegmeyerlab It seems an important bug. Would you share a code snippet for us to reproduce the error? Thanks!