Skip to content

Recommended way to specialize #428

@darsnack

Description

@darsnack

I'm migrating to tyro from Hydra, and after spending a lot of time reading through issues + docs, I still can't figure out the recommended way to specialize.

Specifically, in Hydra's docs, they go over specializing on dataset + model which is a fairly common pattern. Currently I have the following:

@dataclass
class Config:
    """Main configuration for train-bp script."""
    data: ALL_DATA_CFGS = field(default_factory=MNISTConfig)
    optimizer: ALL_OPT_CFGS = field(default_factory=lambda: SGDConfig(learning_rate=0.01))
    logger: ALL_LOGGER_CFGS = field(default_factory=lambda: WandbLoggerConfig())
    model: ALL_MODEL_CFGS = field(default_factory=ConditionedMLPConfig)

If isinstance(cfg.model, CNNConfig) and isinstance(cfg.data, MNISTConfig), then I want to do things like set cfg.optimizer.learning_rate to specific value, etc. Currently, I tried to do this in __post_init__, but this clearly seems like the wrong place. Namely, I might have something like cfg.model.features that is unknown until the dataset is specified, but overwriting this in __post_init__ does not help since tyro flags it as a missing argument that's required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions