I'm pretty new to hydra and was wondering if the following thing is was possible: I have the parameter num_atom_feats in the model section which I would like to make dependent on the feat_type parameter in the data section. In particular, if I have feat_type: type1 then I would like to have num_atom_feats:22. If instead, I initialize data with feat_type : type2 then I would like to have num_atom_feats:200
model:
_target_: model.EmbNet_Lightning
model_name: 'EmbNet'
num_atom_feats: 22
dim_target: 128
loss: 'log_ratio'
lr: 1e-3
wd: 5e-6
data:
_target_: data.DataModule
feat_type: 'type1'
batch_size: 64
data_path: '.'
wandb:
_target_: pytorch_lightning.loggers.WandbLogger
name: embnet_logger
project: ''
trainer:
max_epochs: 1000
You can achieve this using OmeagConf's
custom resolverfeature.Here's an example showing how to register a custom resolver that computes
model.num_atom_featbased on the value ofdata.feat_type:I'd recommend reading through the docs of OmegaConf, which is the backend used by Hydra.
The
compute_num_atom_featsfunction is invoked lazily when you accesscfg.data.num_atom_featsin your python code.When using custom resolvers with Hydra, you can call
OmegaConf.register_new_resolvereither before you invoke your@hydra.main-decorated function, or from within the@hydra.main-decorated function itself. The important thing is that you callOmegaConf.register_new_resolverbefore you accesscfg.data.num_atom_feats.