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

[Tune] Using sample_from breaks BayesOptSearch #45407

Open
Paippi opened this issue May 17, 2024 · 0 comments
Open

[Tune] Using sample_from breaks BayesOptSearch #45407

Paippi opened this issue May 17, 2024 · 0 comments
Labels
bug Something that is supposed to be working; but isn't P2 Important issue, but not time-critical tune Tune-related issues

Comments

@Paippi
Copy link

Paippi commented May 17, 2024

What happened + What you expected to happen

Using ray.tune.sample_from with BayesOptSearch and points_to_evaluate parameter. Causes the dictionary values to be indexed, which isn't possible for non-indexable values. Expected behavior is to be able to specify starting values for the algorithm, along with using sample_from to sample parameters, e.g., when creating samples depending on another value.

Error message I get: TypeError: 'int' object is not subscriptable

Versions / Dependencies

Ray version: 2.22.0
Python version: 3.9.2
OS: Debian GNU/Linux 11.9

Other libraries:

$ pipenv graph
bayesian-optimization==1.4.3
  - colorama [required: >=0.4.6, installed: 0.4.6]
  - numpy [required: >=1.9.0, installed: 1.26.4]
  - scikit-learn [required: >=0.18.0, installed: 1.4.2]
    - joblib [required: >=1.2.0, installed: 1.4.2]
    - numpy [required: >=1.19.5, installed: 1.26.4]
    - scipy [required: >=1.6.0, installed: 1.13.0]
      - numpy [required: >=1.22.4,<2.3, installed: 1.26.4]
    - threadpoolctl [required: >=2.0.0, installed: 3.5.0]
  - scipy [required: >=1.0.0, installed: 1.13.0]
    - numpy [required: >=1.22.4,<2.3, installed: 1.26.4]
black==24.4.2
  - click [required: >=8.0.0, installed: 8.1.7]
  - mypy-extensions [required: >=0.4.3, installed: 1.0.0]
  - packaging [required: >=22.0, installed: 24.0]
  - pathspec [required: >=0.9.0, installed: 0.12.1]
  - platformdirs [required: >=2, installed: 4.2.2]
  - tomli [required: >=1.1.0, installed: 2.0.1]
  - typing-extensions [required: >=4.0.1, installed: 4.11.0]
fsspec==2024.5.0
neovim==0.3.1
  - pynvim [required: >=0.3.1, installed: 0.5.0]
    - greenlet [required: >=3.0, installed: 3.0.3]
    - msgpack [required: >=0.5.0, installed: 1.0.8]
pandas==2.2.2
  - numpy [required: >=1.22.4, installed: 1.26.4]
  - python-dateutil [required: >=2.8.2, installed: 2.9.0.post0]
    - six [required: >=1.5, installed: 1.16.0]
  - pytz [required: >=2020.1, installed: 2024.1]
  - tzdata [required: >=2022.7, installed: 2024.1]
pyarrow==16.1.0
  - numpy [required: >=1.16.6, installed: 1.26.4]
ray==2.22.0
  - aiosignal [required: Any, installed: 1.3.1]
    - frozenlist [required: >=1.1.0, installed: 1.4.1]
  - click [required: >=7.0, installed: 8.1.7]
  - filelock [required: Any, installed: 3.14.0]
  - frozenlist [required: Any, installed: 1.4.1]
  - jsonschema [required: Any, installed: 4.22.0]
    - attrs [required: >=22.2.0, installed: 23.2.0]
    - jsonschema-specifications [required: >=2023.03.6, installed: 2023.12.1]
      - referencing [required: >=0.31.0, installed: 0.35.1]
        - attrs [required: >=22.2.0, installed: 23.2.0]
        - rpds-py [required: >=0.7.0, installed: 0.18.1]
    - referencing [required: >=0.28.4, installed: 0.35.1]
      - attrs [required: >=22.2.0, installed: 23.2.0]
      - rpds-py [required: >=0.7.0, installed: 0.18.1]
    - rpds-py [required: >=0.7.1, installed: 0.18.1]
  - msgpack [required: >=1.0.0,<2.0.0, installed: 1.0.8]
  - packaging [required: Any, installed: 24.0]
  - protobuf [required: >=3.15.3,!=3.19.5, installed: 5.26.1]
  - pyyaml [required: Any, installed: 6.0.1]
  - requests [required: Any, installed: 2.31.0]
    - certifi [required: >=2017.4.17, installed: 2024.2.2]
    - charset-normalizer [required: >=2,<4, installed: 3.3.2]
    - idna [required: >=2.5,<4, installed: 3.7]
    - urllib3 [required: >=1.21.1,<3, installed: 2.2.1]
tensorboardX==2.6.2.2
  - numpy [required: Any, installed: 1.26.4]
  - packaging [required: Any, installed: 24.0]
  - protobuf [required: >=3.20, installed: 5.26.1]

Reproduction script

from ray import tune, train as ray_train
from ray.train import Checkpoint, RunConfig, CheckpointConfig
from ray.tune.search.bayesopt import BayesOptSearch


def objective(config):
    return {"score": 1}


initial_params = [{"a": 1}]

search_space = {"a": tune.sample_from(lambda: 2)}
# Using the following search_space, would work
# search_space = {"a": 2}

bayesopt = BayesOptSearch(points_to_evaluate=initial_params)

tuner = tune.Tuner(
    objective,
    param_space=search_space,
    tune_config=tune.TuneConfig(
        metric="score", mode="max", search_alg=bayesopt
    ),
)
tuner.fit()

Issue Severity

Medium

@Paippi Paippi added bug Something that is supposed to be working; but isn't triage Needs triage (eg: priority, bug/not-bug, and owning component) labels May 17, 2024
@anyscalesam anyscalesam added the tune Tune-related issues label May 20, 2024
@hongpeng-guo hongpeng-guo added P2 Important issue, but not time-critical and removed triage Needs triage (eg: priority, bug/not-bug, and owning component) labels May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is supposed to be working; but isn't P2 Important issue, but not time-critical tune Tune-related issues
Projects
None yet
Development

No branches or pull requests

3 participants