当使用 Hydra 的 optuna 插件时,我可以从另一个配置文件导入搜索空间吗?
我想对同一数据进行超参数优化多个时间序列预测模型。我正在使用 Hydra 的 Optuna Sweeper 插件。不同的模型具有不同的超参数,因此具有不同的搜索空间。目前我的配置文件如下所示:
defaults:
- datasets: data
- models: Ets
- override hydra/sweeper: optuna
- override hydra/sweeper/sampler: tpe
hydra:
# launcher:
# n_jobs: 10
run:
dir: data/outputs/${now:%Y-%m-%d}/${user.user}/${now:%H-%M-%S}
sweeper:
sampler:
seed: 123
direction: minimize
study_name: main_val
storage: null
n_trials: 2
n_jobs: 4
search_space:
# Ets
models.damped_trend:
type: categorical
choices:
- 'True'
- 'False'
# Theta
# models.method:
# type: categorical
# choices:
# - 'additive'
# - 'multiplicative'
现在,当我使用 --multirun 运行 main_val.py 文件时,我获得了 Ets 的最佳超参数。伟大的。但是,当我想要对另一个模型(在此示例中为 Theta)运行优化时,我必须手动注释掉 Ets 的搜索空间并取消注释 Theta 的搜索空间。事实上,每个模型都有更多的参数需要优化,我正在使用 10 个不同的模型。这使得我的配置文件变得相当长且令人困惑,而且这种注释/取消注释的内容既烦人又容易出错。
我想从另一个 yaml 文件导入每个模型的搜索空间。这可能吗?
我尝试了以下操作:
defaults:
- datasets: data
- models: Ets
- search_spaces: Ets
- override hydra/sweeper: optuna
- override hydra/sweeper/sampler: tpe
hydra:
# launcher:
# n_jobs: 10
run:
dir: data/outputs/${now:%Y-%m-%d}/${user.user}/${now:%H-%M-%S}
sweeper:
sampler:
seed: 123
direction: minimize
study_name: main_val
storage: null
n_trials: 2
n_jobs: 4
search_space: search_spaces
文件 search_spaces/Ets.yaml 如下所示:
models.damped_trend:
type: categorical
choices:
- 'True'
- 'False'
但我收到错误:
Validation error while composing config:
Cannot assign str to Dict[str, Any]
full_key: hydra.sweeper.search_space
object_type=OptunaSweeperConf
I want to hyper-parameter optimize multiple time series forecasting models on the same data. I'm using the Optuna Sweeper plugin for Hydra. The different models have different hyper-parameters and therefore different search spaces. At the moment my config file looks like this:
defaults:
- datasets: data
- models: Ets
- override hydra/sweeper: optuna
- override hydra/sweeper/sampler: tpe
hydra:
# launcher:
# n_jobs: 10
run:
dir: data/outputs/${now:%Y-%m-%d}/${user.user}/${now:%H-%M-%S}
sweeper:
sampler:
seed: 123
direction: minimize
study_name: main_val
storage: null
n_trials: 2
n_jobs: 4
search_space:
# Ets
models.damped_trend:
type: categorical
choices:
- 'True'
- 'False'
# Theta
# models.method:
# type: categorical
# choices:
# - 'additive'
# - 'multiplicative'
Now, when I run the main_val.py file with --multirun, I get the optimal hyper-parameters for Ets. Great. But when I want to run the optimization for another model, in this example Theta, I have to manually comment out the search space for Ets and uncomment the search space for Theta. In reality, each model has much more parameters to optimize and I'm working with 10 different models. This makes my config file quite long and confusing and this commenting/uncommenting stuff is both annoying and error-prone.
I would like to import the search space for each model from another yaml file. Is that possible?
I tried the following:
defaults:
- datasets: data
- models: Ets
- search_spaces: Ets
- override hydra/sweeper: optuna
- override hydra/sweeper/sampler: tpe
hydra:
# launcher:
# n_jobs: 10
run:
dir: data/outputs/${now:%Y-%m-%d}/${user.user}/${now:%H-%M-%S}
sweeper:
sampler:
seed: 123
direction: minimize
study_name: main_val
storage: null
n_trials: 2
n_jobs: 4
search_space: search_spaces
with the file search_spaces/Ets.yaml looking like this:
models.damped_trend:
type: categorical
choices:
- 'True'
- 'False'
But I got the error:
Validation error while composing config:
Cannot assign str to Dict[str, Any]
full_key: hydra.sweeper.search_space
object_type=OptunaSweeperConf
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有两个选项:
@package
指令详细信息:
使用
@package
指令@package
指令可用于放置Ets.yaml
在 Hydra.sweeper.search_spaces 包中:使用变量插值:
字符串插值可用于创建从 Hydra.sweeper.search_spaces 到顶层的引用
search_spaces
配置。Here are two options:
@package
directiveIn detail:
Using an
@package
directiveAn
@package
directive can be used to placeEts.yaml
in thehydra.sweeper.search_space
package:Using a variable interpolation:
A string interpolation can be used to create a reference from
hydra.sweeper.search_spaces
to the top-levelsearch_spaces
config.