Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

HPO GP Tuner: Float object is not subscriptable #4978

Closed
brycecoldcocacola opened this issue Jun 30, 2022 · 1 comment
Closed

HPO GP Tuner: Float object is not subscriptable #4978

brycecoldcocacola opened this issue Jun 30, 2022 · 1 comment
Assignees

Comments

@brycecoldcocacola
Copy link

Describe the issue:

Using GP tuner results in TypeError: 'float' object is not subscriptable exception.

Environment:

  • NNI version: 2.8
  • Training service (local|remote|pai|aml|etc): local
  • Client OS: Mac
  • Server OS (for remote mode only):
  • Python version: 3.9.9
  • PyTorch/TensorFlow version: Torch version 1.12.0
  • Is conda/virtualenv/venv used?: venv
  • Is running in Docker?: no

Configuration:

  • Experiment config (remember to remove secrets!):
experiment = Experiment('local')
experiment.config.search_space = params

experiment.config.tuner.name = "GP"
experiment.config.tuner.class_args = {
    'optimize_mode': 'maximize',
    'utility': 'poi',
    'kappa': 5.0,
    'xi': 0.0,
    'nu': 2.5,
    'alpha': 1e-6,
    'cold_start_num': 10,
    'selection_num_warm_up': 100000,
    'selection_num_starting_points': 250
}

experiment.config.trial_concurrency = 1
experiment.config.trial_command = 'python3 model.py'
  • Search space:
params = {
    "a": {"_type": "quniform", "_value": [0, 10, 1]},
    "b": {"_type": "quniform", "_value": [0, 10, 1]},
    "c": {"_type": "quniform", "_value": [0, 10, 1]},
    "d": {"_type": "quniform", "_value": [0, 10, 1]},
    "e": {"_type": "quniform", "_value": [0, 10, 1]},
    "f": {"_type": "quniform", "_value": [0, 10, 1]},
}

Log message:

  • nnimanager.log:
  • dispatcher.log:
[2022-06-30 13:38:57] INFO (nni.runtime.msg_dispatcher_base/MainThread) Dispatcher started
[2022-06-30 13:38:57] INFO (GP_Tuner_AutoML/Thread-1) Generate paramageters:
 {'a': 8.0, 'b': 0.0, 'c': 2.0, 'd': 1.0, 'e': 9.0, 'f': 6.0}
[2022-06-30 13:39:08] INFO (GP_Tuner_AutoML/Thread-1) Received trial result.
[2022-06-30 13:39:08] INFO (GP_Tuner_AutoML/Thread-1) value :26.0
[2022-06-30 13:39:08] INFO (GP_Tuner_AutoML/Thread-1) parameter : {'a': 8.0, 'b': 0.0, 'c': 2.0, 'd': 1.0, 'e': 9.0, 'f': 6.0}
[2022-06-30 13:39:12] INFO (GP_Tuner_AutoML/Thread-1) Generate paramageters:
 {'a': 2.0, 'b': 3.0, 'c': 3.0, 'd': 3.0, 'e': 7.0, 'f': 8.0}
[2022-06-30 13:39:18] INFO (GP_Tuner_AutoML/Thread-1) Received trial result.
[2022-06-30 13:39:18] INFO (GP_Tuner_AutoML/Thread-1) value :26.0
[2022-06-30 13:39:18] INFO (GP_Tuner_AutoML/Thread-1) parameter : {'a': 2.0, 'b': 3.0, 'c': 3.0, 'd': 3.0, 'e': 7.0, 'f': 8.0}
[2022-06-30 13:39:22] INFO (GP_Tuner_AutoML/Thread-1) Generate paramageters:
 {'a': 8.0, 'b': 9.0, 'c': 3.0, 'd': 7.0, 'e': 5.0, 'f': 10.0}
[2022-06-30 13:39:28] INFO (GP_Tuner_AutoML/Thread-1) Received trial result.
[2022-06-30 13:39:28] INFO (GP_Tuner_AutoML/Thread-1) value :42.0
[2022-06-30 13:39:28] INFO (GP_Tuner_AutoML/Thread-1) parameter : {'a': 8.0, 'b': 9.0, 'c': 3.0, 'd': 7.0, 'e': 5.0, 'f': 10.0}
[2022-06-30 13:39:32] INFO (GP_Tuner_AutoML/Thread-1) Generate paramageters:
 {'a': 3.0, 'b': 9.0, 'c': 5.0, 'd': 8.0, 'e': 8.0, 'f': 5.0}
[2022-06-30 13:39:38] INFO (GP_Tuner_AutoML/Thread-1) Received trial result.
[2022-06-30 13:39:38] INFO (GP_Tuner_AutoML/Thread-1) value :38.0
[2022-06-30 13:39:38] INFO (GP_Tuner_AutoML/Thread-1) parameter : {'a': 3.0, 'b': 9.0, 'c': 5.0, 'd': 8.0, 'e': 8.0, 'f': 5.0}
[2022-06-30 13:39:42] INFO (GP_Tuner_AutoML/Thread-1) Generate paramageters:
 {'a': 3.0, 'b': 10.0, 'c': 3.0, 'd': 1.0, 'e': 2.0, 'f': 8.0}
[2022-06-30 13:39:48] INFO (GP_Tuner_AutoML/Thread-1) Received trial result.
[2022-06-30 13:39:48] INFO (GP_Tuner_AutoML/Thread-1) value :27.0
[2022-06-30 13:39:48] INFO (GP_Tuner_AutoML/Thread-1) parameter : {'a': 3.0, 'b': 10.0, 'c': 3.0, 'd': 1.0, 'e': 2.0, 'f': 8.0}
[2022-06-30 13:39:52] INFO (GP_Tuner_AutoML/Thread-1) Generate paramageters:
 {'a': 6.0, 'b': 1.0, 'c': 10.0, 'd': 9.0, 'e': 6.0, 'f': 10.0}
[2022-06-30 13:39:58] INFO (GP_Tuner_AutoML/Thread-1) Received trial result.
[2022-06-30 13:39:58] INFO (GP_Tuner_AutoML/Thread-1) value :42.0
[2022-06-30 13:39:58] INFO (GP_Tuner_AutoML/Thread-1) parameter : {'a': 6.0, 'b': 1.0, 'c': 10.0, 'd': 9.0, 'e': 6.0, 'f': 10.0}
[2022-06-30 13:40:02] INFO (GP_Tuner_AutoML/Thread-1) Generate paramageters:
 {'a': 9.0, 'b': 2.0, 'c': 9.0, 'd': 8.0, 'e': 1.0, 'f': 8.0}
[2022-06-30 13:40:08] INFO (GP_Tuner_AutoML/Thread-1) Received trial result.
[2022-06-30 13:40:08] INFO (GP_Tuner_AutoML/Thread-1) value :37.0
[2022-06-30 13:40:08] INFO (GP_Tuner_AutoML/Thread-1) parameter : {'a': 9.0, 'b': 2.0, 'c': 9.0, 'd': 8.0, 'e': 1.0, 'f': 8.0}
[2022-06-30 13:40:13] INFO (GP_Tuner_AutoML/Thread-1) Generate paramageters:
 {'a': 1.0, 'b': 5.0, 'c': 4.0, 'd': 9.0, 'e': 3.0, 'f': 10.0}
[2022-06-30 13:40:19] INFO (GP_Tuner_AutoML/Thread-1) Received trial result.
[2022-06-30 13:40:19] INFO (GP_Tuner_AutoML/Thread-1) value :32.0
[2022-06-30 13:40:19] INFO (GP_Tuner_AutoML/Thread-1) parameter : {'a': 1.0, 'b': 5.0, 'c': 4.0, 'd': 9.0, 'e': 3.0, 'f': 10.0}
[2022-06-30 13:40:23] INFO (GP_Tuner_AutoML/Thread-1) Generate paramageters:
 {'a': 6.0, 'b': 10.0, 'c': 9.0, 'd': 9.0, 'e': 4.0, 'f': 5.0}
[2022-06-30 13:40:28] INFO (GP_Tuner_AutoML/Thread-1) Received trial result.
[2022-06-30 13:40:28] INFO (GP_Tuner_AutoML/Thread-1) value :43.0
[2022-06-30 13:40:28] INFO (GP_Tuner_AutoML/Thread-1) parameter : {'a': 6.0, 'b': 10.0, 'c': 9.0, 'd': 9.0, 'e': 4.0, 'f': 5.0}
[2022-06-30 13:40:33] INFO (GP_Tuner_AutoML/Thread-1) Generate paramageters:
 {'a': 7.0, 'b': 5.0, 'c': 9.0, 'd': 3.0, 'e': 6.0, 'f': 3.0}
[2022-06-30 13:40:39] INFO (GP_Tuner_AutoML/Thread-1) Received trial result.
[2022-06-30 13:40:39] INFO (GP_Tuner_AutoML/Thread-1) value :33.0
[2022-06-30 13:40:39] INFO (GP_Tuner_AutoML/Thread-1) parameter : {'a': 7.0, 'b': 5.0, 'c': 9.0, 'd': 3.0, 'e': 6.0, 'f': 3.0}
[2022-06-30 13:40:56] ERROR (nni.runtime.msg_dispatcher_base/Thread-1) 'float' object is not subscriptable
Traceback (most recent call last):
  File "/Users/bryceanglin/Projects/nni-test/.venv/lib/python3.9/site-packages/nni/runtime/msg_dispatcher_base.py", line 97, in command_queue_worker
    self.process_command(command, data)
  File "/Users/bryceanglin/Projects/nni-test/.venv/lib/python3.9/site-packages/nni/runtime/msg_dispatcher_base.py", line 143, in process_command
    command_handlers[command](data)
  File "/Users/bryceanglin/Projects/nni-test/.venv/lib/python3.9/site-packages/nni/runtime/msg_dispatcher.py", line 102, in handle_request_trial_jobs
    params_list = self.tuner.generate_multiple_parameters(ids, st_callback=self.send_trial_callback)
  File "/Users/bryceanglin/Projects/nni-test/.venv/lib/python3.9/site-packages/nni/tuner.py", line 135, in generate_multiple_parameters
    res = self.generate_parameters(parameter_id, **kwargs)
  File "/Users/bryceanglin/Projects/nni-test/.venv/lib/python3.9/site-packages/nni/algorithms/hpo/gp_tuner/gp_tuner.py", line 178, in generate_parameters
    results = acq_max(
  File "/Users/bryceanglin/Projects/nni-test/.venv/lib/python3.9/site-packages/nni/algorithms/hpo/gp_tuner/util.py", line 106, in acq_max
    if max_acq is None or -res.fun[0] >= max_acq:
TypeError: 'float' object is not subscriptable
  • nnictl stdout and stderr:

How to reproduce it?:

script.py

import nni
from nni.experiment import Experiment

params = {
    "a": {"_type": "quniform", "_value": [0, 10, 1]},
    "b": {"_type": "quniform", "_value": [0, 10, 1]},
    "c": {"_type": "quniform", "_value": [0, 10, 1]},
    "d": {"_type": "quniform", "_value": [0, 10, 1]},
    "e": {"_type": "quniform", "_value": [0, 10, 1]},
    "f": {"_type": "quniform", "_value": [0, 10, 1]},
}

experiment = Experiment('local')
experiment.config.search_space = params

experiment.config.tuner.name = "GP"
experiment.config.tuner.class_args = {
    'optimize_mode': 'maximize',
    'utility': 'poi',
    'kappa': 5.0,
    'xi': 0.0,
    'nu': 2.5,
    'alpha': 1e-6,
    'cold_start_num': 10,
    'selection_num_warm_up': 100000,
    'selection_num_starting_points': 250
}

experiment.config.trial_concurrency = 1
experiment.config.trial_command = 'python3 model.py'

if __name__ == "__main__":
    experiment.run(8082)

model.py

import nni

params = nni.get_next_parameter()

def optimize(a, b, c, d, e, f):
    return a + b + c + d + e + f

nni.report_final_result(optimize(**params))

run python script.py

after the 10 cold trials, GP will kick in and crash after n trials. In my case, it usually crashes on the first trial.

Related

@ultmaster
Copy link
Contributor

Closing as it seems to have been fixed.

zihaooo added a commit to zihaooo/auction-based-realtime-control that referenced this issue Dec 5, 2022
@TimSchim TimSchim mentioned this issue May 8, 2024
6 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants