Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dev] Config Registration Functions in __init__.py #72

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions hydra-configs-torch/hydra_configs/torch/optim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# flake8: noqa
# Mirrors torch/optim __init__ to allow for symmetric import structure
from .adadelta import AdadeltaConf
Expand All @@ -14,6 +15,25 @@
from .lbfgs import LBFGSConf
from . import lr_scheduler

from hydra.core.config_store import ConfigStore


def register_configs():
cs = ConfigStore.instance()
cs.store(provider="torch", group="torch/optim", name="adadelta", node=AdadeltaConf)
cs.store(provider="torch", group="torch/optim", name="adagrad", node=AdagradConf)
cs.store(provider="torch", group="torch/optim", name="adam", node=AdamConf)
cs.store(provider="torch", group="torch/optim", name="adamw", node=AdamWConf)
cs.store(
provider="torch", group="torch/optim", name="sparseadam", node=SparseAdamConf
)
cs.store(provider="torch", group="torch/optim", name="adamax", node=AdamaxConf)
cs.store(provider="torch", group="torch/optim", name="asgd", node=ASGDConf)
cs.store(provider="torch", group="torch/optim", name="sgd", node=SGDConf)
cs.store(provider="torch", group="torch/optim", name="lbfgs", node=LBFGSConf)
cs.store(provider="torch", group="torch/optim", name="rprop", node=RpropConf)
cs.store(provider="torch", group="torch/optim", name="rmsprop", node=RMSpropConf)
romesco marked this conversation as resolved.
Show resolved Hide resolved


del adadelta
del adagrad
Expand Down
29 changes: 29 additions & 0 deletions hydra-configs-torch/tests/test_register_optimizers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from hydra.core.config_store import ConfigStore
import hydra_configs.torch.optim

cs = ConfigStore()

# registers all 'base' optimizer configs with configstore instance
hydra_configs.torch.optim.register()
romesco marked this conversation as resolved.
Show resolved Hide resolved

expected = set(
[
"adadelta",
"adagrad",
"adam",
"adamw",
"sparseadam",
"adamax",
"asgd",
"sgd",
"lbfgs",
"rprop",
"rmsprop",
]
)


def test_instantiate_classes() -> None:
actual = set([conf.split(".yaml")[0] for conf in cs.list("torch/optim")])
assert not actual ^ expected