【发布时间】:2023-01-21 03:55:30
【问题描述】:
我需要更改 hydra 配置框架的输出/工作目录,使其位于我的项目目录之外。根据我的理解和doc,config.yaml 需要如下所示:
exp_nr: 0.0.0.0
condition: something
hydra:
run:
dir: /absolute/path/to/folder/${exp_nr}/${condition}/
在我的代码中,我尝试访问并设置如下路径:
import os
import hydra
from omegaconf import DictConfig
@hydra.main(config_path="../../config", config_name="config", version_base="1.3")
def main(cfg: DictConfig):
print(cfg)
cwd = os.getcwd()
print(f"The current working directory is {cwd}")
owd = hydra.utils.get_original_cwd()
print(f"The Hydra original working directory is {owd}")
work_dir = cfg.hydra.run.dir
print(f"The work directory should be {work_dir}")
但我得到以下输出和错误:
{'exp_nr': '0.0.0.0', 'condition': 'something'}
The current working directory is /project/path/subdir/subsubdir
The Hydra original working directory is /project/path/subdir/subsubdir
Error executing job with overrides: ['exp_nr=1.0.0.0', 'condition=somethingelse']
Traceback (most recent call last):
File "/project/path/subdir/subsubdir/model.py", line 13, in main
work_dir = cfg.hydra.run.dir
omegaconf.errors.ConfigAttributeError: Key 'hydra' is not in struct
full_key: hydra
object_type=dict
我看到 hydra.run.dir 没有出现在首先打印的 cfg dict 中,但是如果 os.getcwd() 尚未设置,我如何通过配置访问路径?或者我做错了什么?
路径是正确的,因为我在集成 hydra 之前已经将文件保存到文件夹中,如果进程由于错误没有被终止,文件夹也会被创建,但是 hydra 不会向其中保存任何文件,甚至是带有它应该默认保存的参数。我还尝试设置相对于标准输出路径的路径或具有额外的配置参数work_dir: ${hydra.run.dir}(返回插值错误)。
【问题讨论】:
标签: python-3.x configuration fb-hydra hydra-core