You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Greetings! I'm a big fan of this library and I'm trying to learn the best ways to perform config validation using structured configs and OmegaConf.merge. (I'll try to articulate my question coherently, but I'm at such a basic level where even that is difficult!)
My question is about runtime type validation for a config that can have variable nodes. Here's a toy example of what I'm getting at. In the context of an ML project, I specify a model from a config as follows, where the encoder and prediction_head nodes can be variable but all share a high-level structure:
encoder:
module_name: MyTransformerEncoder # this is the name of a custom pytorch modulemodule_cfg: # specify the init params to instantiate the model, must be consistent with the above-specified moduled_model: 768num_layers: 4prediction_head:
module_name: MyFFNPredictor # another custom pytorch modulemodule_cfg: # same as above, specify the init paramsnum_target_classes: 50hidden_dim: 1024
But since I want to support different types of encoders and prediction heads, another equally valid config might be (don't worry about the fact that a transformer encoder is typically not easily swappable with a feedforward network...):
encoder:
module_name: MyFFNEncoder # use a different encoder this timemodule_cfg:
embed_dim: 768n_layers: 6prediction_head: # same as in first examplemodule_name: MyFFNPredictor module_cfg:
num_target_classes: 50hidden_dim: 1024
I want to use a structured config to validate such configs at runtime. A first attempt at this could be:
The two example configs should validate just fine against this ModelConfig schema, but I'd like to further validate that the fields and types given in the module_cfg nodes are consistent with the corresponding value of module_name, and this is where I'm getting stuck. I don't want to write a separate structure config for every possible combination of specific encoders and decoders, but I want to be able to validate all such possible configs. While I found a (probably hackish) halfway solution, I'm very curious about how you all might approach this. Maybe I should just expect the user to provide correct values for these nodes (if they don't the code will almost surely error out as it tries to instantiate the specified module with the given init parameters) and be satisfied with my first attempt above?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Greetings! I'm a big fan of this library and I'm trying to learn the best ways to perform config validation using structured configs and
OmegaConf.merge
. (I'll try to articulate my question coherently, but I'm at such a basic level where even that is difficult!)My question is about runtime type validation for a config that can have variable nodes. Here's a toy example of what I'm getting at. In the context of an ML project, I specify a model from a config as follows, where the
encoder
andprediction_head
nodes can be variable but all share a high-level structure:But since I want to support different types of encoders and prediction heads, another equally valid config might be (don't worry about the fact that a transformer encoder is typically not easily swappable with a feedforward network...):
I want to use a structured config to validate such configs at runtime. A first attempt at this could be:
The two example configs should validate just fine against this
ModelConfig
schema, but I'd like to further validate that the fields and types given in themodule_cfg
nodes are consistent with the corresponding value ofmodule_name
, and this is where I'm getting stuck. I don't want to write a separate structure config for every possible combination of specific encoders and decoders, but I want to be able to validate all such possible configs. While I found a (probably hackish) halfway solution, I'm very curious about how you all might approach this. Maybe I should just expect the user to provide correct values for these nodes (if they don't the code will almost surely error out as it tries to instantiate the specified module with the given init parameters) and be satisfied with my first attempt above?Thanks all!
Beta Was this translation helpful? Give feedback.
All reactions