keras-team / keras-tuner

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

Inconsistency in hyperparameter table #1029

Open dorothyparry3 opened 6 days ago

dorothyparry3 commented 6 days ago

Describe the bug I created a hyperparameter almost identically to what is shown here, where the number of layers is also a hyperparameter. However, when looking at my output file, the hyperparameter table has two bugs.

The first is when the number of layers is increased, the hyperparameter information for those additional layers do not show up. However, it does correctly report them in subsequent trials. And, the trial objects hold the correct hyperparameters. So, it is just the first instance when it is automatically getting printed to the output file where the error occurs.

The second is that after the number of layers is increased, any trial after that will attempt to automatically fill the hyperparameter information. Thus, creating extraneous hyperparameter information. I tried to circumvent this by setting a similar name but setting the values to 0, but this threw an error. Not only does the hyperparameter table reflect the extraneous layer(s) of information, but they are also included in the trial meta-data.

To Reproduce

See above.

Expected behavior

For the first issue, I expected the hyperparameter table to include the additional layer information the first time that another layer (and subsequently another hyperparameter) is added.

For the second issue, I expect the extraneous layer(s) of information (i.e. additional hyperparameters) to either be set to a default value (such as None), or to not show up in both the Trial meta-data and hyperparameter table.

Additional context

For issue 1, see attached photo. I expected the hyperparameter table (in the output file) to include the additional layers of information. Note, I did not specifically print the hyperparameter table. It was automatically printed in the output file. Bug 1 KerasTuner HyperparamTable

Bug KerasTuner HyperparamTable

See the attached picture for help on bug issue 2. I expect all of the values after "units for layer 0" to be either 0 or None to make it easier for the user to see it and understand only the first layer is created (as well as the last one, as shown via the printed model.summary()).

Would you like to help us fix it?

ghsanti commented 5 days ago

Just a minor comment, I'm not a maintainer.

The random search first creates a space of parameters which then mutates. Then it re-builds the model.

For example, going from 1 layer to 7 layers, mutation happens on "1" subset of parameters (just unit-0 mutates), that means "7" has mostly fixed parameters. This is intertwined with the display problem that you found.

Imho the main code isn't easy to fix due to the complexity.