Skip to content

Overriding values of type Type #437

Answered by DirkKuhn
DirkKuhn asked this question in Q&A
Discussion options

You must be logged in to vote

I did a bit of experimenting and the approach with config groups seems to work:

from typing import Type
from torch import nn

from hydra_zen import to_yaml, store, builds, zen, launch, just
from omegaconf import DictConfig, OmegaConf

class Model:
    def __init__(self, activation_fn: Type[nn.Module]):
        self.activation_fn = activation_fn

def app(zen_cfg: DictConfig, model: Model) -> None:
    OmegaConf.resolve(zen_cfg)
    print(to_yaml(zen_cfg))

store(Model, group='model')

activation_fn_store = store(group='model/activation_fn')
activation_fn_store(just(nn.ReLU), name='relu')
activation_fn_store(just(nn.SELU), name='selu')

Config = builds(
    app,
    hydra_defaults=[
        {

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@rsokl
Comment options

@DirkKuhn
Comment options

Answer selected by rsokl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants