我使用以下结构的水龙头组合物:
├── configs
    │   ├── config.yaml
    │   ├── data
    │   │   ├── dataset_01.yaml
    │   │   └── dataset_02.yaml
    │   └── model
    │       ├── bert.yaml
    │       └── gpt.yamldefaults:
  - model: bert
  - data: dataset_01
...# @package _group_
name: "dataset_01"
train:
  path: "../resources/datasets/dataset_01/train.jsonl"
  num_samples: 1257391
test:
  path: "../resources/datasets/dataset_01/test.jsonl"
  num_samples: 71892
val:
  path: "../resources/datasets/dataset_01/val.jsonl"
  num_samples: 73805# @package _group_
name: "bert"
encoder: "source.encoder.BertEncoder.BertEncoder"
encoder_hparams:
  architecture: "bert-base-uncased"
lr: 1e-7
tokenizer:
  architecture: "bert-base-uncased"
predictions:
  path: "../resources/predictions/bert_predictions.pt"@hydra.main(config_path="configs/", config_name="config.yaml")
def perform_tasks(hparams):
    model = MyModel(hparams.model)
if __name__ == '__main__':
    perform_tasks()在hparams.model上下文中,OmegaConf无法插值键data.name,因为它不在作用域内。所以,如果有一种方法在应用程序开始时引起插值,那就太好了。
发布于 2021-01-03 23:48:38
OmegaConf内插是绝对的,并且是在最后配置上操作的。
试试这个:
九头蛇1.0 (稳定)
predictions:
  path: "../resources/predictions/bert_${data.name}_predictions.pt"九头蛇1.1 (发展)
九头蛇1.1将消除在您的信任中指定名称的需要。您可以在不使用hydra:choices.GROUP_NAME添加name字段的情况下进行内插。
predictions:
  path: "../resources/predictions/bert_${hydra:choices.data}_predictions.pt"这是记录在案的这里。请注意,这只在Hydra 1.1中可用,它尚未正式发布(您可以通过安装dev版本来试用它)。
https://stackoverflow.com/questions/65552653
复制相似问题