如何正确生成多层次构图?
目前,我的 Hydra 配置组织如下:
configs/
├── config.yaml
├── data
│ ├── IMDB.yaml
│ └── REUT.yaml
└── model
├── BERT.yaml
├── GPT.yaml
└── loss
├── CrossEntropyLoss.yaml
└── TripletMarginLoss.yaml
config.yaml:
defaults:
- model: BERT
- data: IMDB
tasks: [ "fit", "eval" ]
数据集(IMDB.yaml
和 REUT.yaml
)设置的格式为:
name: IMDB
dir: resource/dataset/imdb_reviews/
folds: [0,1,2,3,4]
max_length: 256
num_classes: 10
模型(>BERT.yaml
和 GPT.yaml
)设置的格式为:
defaults:
- loss: TripletMarginLoss
name: BERT
architecture: bert-base-uncased
lr: 5e-5
tokenizer:
architecture: ${model.architecture}
最后,损失函数设置(CrossEntropyLoss.yaml
和TripletMarginLoss.yam
) 采用以下结构:
_target_: source.loss.TripletMarginLoss.TripletMarginLoss
params:
name: TripletMarginLoss
margin: 1.0
eps: 1e-6
reduction: mean
运行以下入口点:
@hydra.main(config_path="configs/", config_name="config.yaml")
def my_app(params):
OmegaConf.resolve(params)
print(
f"Params:\n"
f"{OmegaConf.to_yaml(params)}\n")
if __name__ == '__main__':
my_app()
# python main.py
生成正确的配置组合:
tasks:
- fit
- eval
model:
loss:
_target_: source.loss.TripletMarginLoss.TripletMarginLoss
params:
name: TripletMarginLoss
margin: 1.0
eps: 1.0e-06
reduction: mean
name: BERT
architecture: bert-base-uncased
lr: 5.0e-05
tokenizer:
architecture: bert-base-uncased
data:
name: IMDB
dir: resource/dataset/imdb_reviews/
folds:
- 0
- 1
- 2
- 3
- 4
max_length: 256
num_classes: 10
但是,覆盖损失函数会生成错误的配置:
python main.py model.loss=CrossEntropyLoss
tasks:
- fit
- eval
model:
loss: CrossEntropyLoss
name: BERT
architecture: bert-base-uncased
lr: 5.0e-05
tokenizer:
architecture: bert-base-uncased
data:
name: IMDB
dir: resource/dataset/imdb_reviews/
folds:
- 0
- 1
- 2
- 3
- 4
max_length: 256
num_classes: 10
因此,如何正确生成多级组合?
Currently, my hydra config is organized as follows:
configs/
├── config.yaml
├── data
│ ├── IMDB.yaml
│ └── REUT.yaml
└── model
├── BERT.yaml
├── GPT.yaml
└── loss
├── CrossEntropyLoss.yaml
└── TripletMarginLoss.yaml
config.yaml:
defaults:
- model: BERT
- data: IMDB
tasks: [ "fit", "eval" ]
The dataset (IMDB.yaml
and REUT.yaml
) settings are in the format:
name: IMDB
dir: resource/dataset/imdb_reviews/
folds: [0,1,2,3,4]
max_length: 256
num_classes: 10
The model (BERT.yaml
and GPT.yaml
) settings are in the format:
defaults:
- loss: TripletMarginLoss
name: BERT
architecture: bert-base-uncased
lr: 5e-5
tokenizer:
architecture: ${model.architecture}
And finally, the loss function settings (CrossEntropyLoss.yaml
and TripletMarginLoss.yam
) adopt the following structure:
_target_: source.loss.TripletMarginLoss.TripletMarginLoss
params:
name: TripletMarginLoss
margin: 1.0
eps: 1e-6
reduction: mean
Running the following entry point:
@hydra.main(config_path="configs/", config_name="config.yaml")
def my_app(params):
OmegaConf.resolve(params)
print(
f"Params:\n"
f"{OmegaConf.to_yaml(params)}\n")
if __name__ == '__main__':
my_app()
# python main.py
generates the correct config composition:
tasks:
- fit
- eval
model:
loss:
_target_: source.loss.TripletMarginLoss.TripletMarginLoss
params:
name: TripletMarginLoss
margin: 1.0
eps: 1.0e-06
reduction: mean
name: BERT
architecture: bert-base-uncased
lr: 5.0e-05
tokenizer:
architecture: bert-base-uncased
data:
name: IMDB
dir: resource/dataset/imdb_reviews/
folds:
- 0
- 1
- 2
- 3
- 4
max_length: 256
num_classes: 10
However, overriding the loss function generates the wrong config:
python main.py model.loss=CrossEntropyLoss
tasks:
- fit
- eval
model:
loss: CrossEntropyLoss
name: BERT
architecture: bert-base-uncased
lr: 5.0e-05
tokenizer:
architecture: bert-base-uncased
data:
name: IMDB
dir: resource/dataset/imdb_reviews/
folds:
- 0
- 1
- 2
- 3
- 4
max_length: 256
num_classes: 10
Therefore, how to correctly generate a multi-level composition?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
覆盖嵌套配置组是使用 / 作为分隔符来完成的,如配置组描述此处中所述。
尝试:
Overriding nested config groups is done with / as separator as documented in the config group description here.
Try: