facebookresearch / hydra

Hydra is a framework for elegantly configuring complex applications
https://hydra.cc
MIT License
8.84k stars 638 forks source link

Optuna GirdSampler error #2003

Closed yfeng24816 closed 2 years ago

yfeng24816 commented 2 years ago

🐛 Bug

Description

Got this error when using Optuna random sampler

image

This is my config

image

This is weird because consider_prior is not in the config of RandomSampler of Hydra

image

Update(Debugging)

This seems to be hydra defaults to load the TPE config.

image

In this file, it first loads the defaulted TPE config, then my randomSampler config. But when doing the merge, the randomSampler's config did not override the redundant parts like consider_prior, making them passed to Optuna's RandomSampler, and caused error.

image image image

Is there a way to manipulated the defaulted TPE config and avoid the error?

Checklist

Jasha10 commented 2 years ago

Hi @yfeng24816, Yes, Hydra selects the TPE sampler by default (see here). You need to override the hydra/sweeper/sampler group using the defaults list. Please try adding the following to your config:

defaults:
  - /hydra/sweeper/sampler: random  # using RandomSamplerConfig
Jasha10 commented 2 years ago

@yfeng24816 did this solve your problem?

yfeng24816 commented 2 years ago

@yfeng24816 did this solve your problem?

Yes Jasha, thank you. Closing this issue.

yfeng24816 commented 2 years ago

Is there a way to use Optuna's GridSampler? I tried this in config but failed

image image

It is possible to use hydra's -m option with command line interface for grid search, and in fact I used it pretty often. But I just hope if there is something more consistent. And Optuna's hyper parameter search outputs a optimization_results.yaml which I found very handy for loading search result.

Editing this file (https://github.com/facebookresearch/hydra/blob/8d45045e1408ca9d67a504c2372fb732bb9e6920/plugins/hydra_optuna_sweeper/hydra_plugins/hydra_optuna_sweeper/config.py#L129) might work but problem is that GridSampler does not accept the seed argument (which is used by all supported Optuna samplers for now) for instantiation.

image

This might require some restructuring at a higher level.

nzw0301 commented 2 years ago

I suppose no. https://github.com/facebookresearch/hydra/issues/1815 says the grid-search sampler is not supported.

jieru-hu commented 2 years ago

closing. pls follow #1815 instead.