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

ValueError from trying to turn trial_id into an int #680

Closed kotoroshinoto closed 2 years ago

kotoroshinoto commented 2 years ago

Describe the bug Traceback (most recent call last): File "TrainModels.py", line 112, in hyper_tuner.search(tf_train, validation_data=tf_valid) File "/opt/conda/lib/python3.7/site-packages/keras_tuner/engine/base_tuner.py", line 178, in search self.on_trial_begin(trial) File "/opt/conda/lib/python3.7/site-packages/keras_tuner/engine/base_tuner.py", line 240, in on_trial_begin self._display.on_trial_begin(self.oracle.get_trial(trial.trial_id)) File "/opt/conda/lib/python3.7/site-packages/keras_tuner/engine/tuner_utils.py", line 109, in on_trial_begin self.trial_number = int(trial.trial_id) + 1 ValueError: invalid literal for int() with base 10: '1923f869d8f82ba5c8e64e383ddfe153'

Expected behavior running a search using hypermodel

Would you like to help us fix it? If I can I will help. It looks like the trial ID might be generated in hex, and the int() transformer doesn't know that.

kotoroshinoto commented 2 years ago

the changelog for version 1.1.1 says that the trial ids were supposed to change from hex to ints starting at 0, so why would I be getting a trial ID that is still a hex string when my system tells me it has version 1.1.2?

looking at your trial class

class Trial(stateful.Stateful): def init(self, hyperparameters, trial_id=None, status=TrialStatus.RUNNING): self.hyperparameters = hyperparameters self.trial_id = generate_trial_id() if trial_id is None else trial_id

that function: def generate_trial_id(): s = str(time.time()) + str(random.randint(1, int(1e7))) return hashlib.sha256(s.encode("utf-8")).hexdigest()[:32]

doesn't return an appropriate int string when provided trial_id is None.

I gather that this isn't supposed to happen, given the code from oracle.py:

Make the trial_id the current number of trial, pre-padded with 0s

    trial_id = "{{:0{}d}}".format(len(str(self.max_trials)))
    trial_id = trial_id.format(len(self.trials))

I'm really confused as to why i'm ending up with a hex value, and why when I manually bypass that changing the int cast to use int(val,16), I then end up with a completely different, but equally confusing bug: https://github.com/keras-team/keras-tuner/issues/681

Edit: that occurred because when I subclassed your tuner class I forgot to return the result of the call to the super-class's run_trial function. oops XD. The ID issue does still remain though.

kotoroshinoto commented 2 years ago

I might have figured it out, I might have had the wrong version installed when the project directory was created and it may have cached some information that was being reloaded rather than generated fresh.

I deleted the generated project folder and it is now using base 10 integers starting at 0 for trial_ids. I'll leave the issue open until it finishes a test run.

kotoroshinoto commented 2 years ago

Its not likely that the code generating the hex values will be used, but that should probably still be either removed or altered so that it either will function as expected, or simply not confuse people looking through the codebase.