Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Migrate to Hydra 1.0
Browse files Browse the repository at this point in the history
Summary:
- Migrated to Hydra 1.0
- We need to figure out what the best hierarchy is for Classy given Hydra's new capabilities since the original decision might not be the best now
  - I tried out package directives as well and they work well
  - Leaving this for the future though

Documenting the API changes here -
```
pip install .
pip install hydra-core==1.0.0rc1 # to be replaced with final version
classy_project my_hydra_project

# some example runs with the new API
# note that since task, optimizer and param_scheduler are used in args.yaml, they will not need a + prefix in the command

./my_hydra_project/classy_train.py +model=resnet_50
./my_hydra_project/classy_train.py +loss=cross_entropy +model=resnet50
```

Differential Revision: D21916837

fbshipit-source-id: 536d158fc919128998d126d614f57fbe61ef49b9
  • Loading branch information
mannatsingh authored and facebook-github-bot committed Jun 6, 2020
1 parent a8c5652 commit 02e1226
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 5 deletions.
5 changes: 3 additions & 2 deletions classy_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

try:
import hydra
import omegaconf

hydra_available = True
except ImportError:
Expand Down Expand Up @@ -154,11 +155,11 @@ def configure_hooks(args, config):

if hydra_available:

@hydra.main(config_path="hydra_configs/args.yaml")
@hydra.main(config_name="hydra_configs/args")
def hydra_main(cfg):
args = cfg
check_generic_args(cfg)
config = cfg.config.to_container()
config = omegaconf.OmegaConf.to_container(cfg.config)
main(args, config)


Expand Down
1 change: 1 addition & 0 deletions classy_vision/hydra/conf/config/resnet50_synthetic.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# @package _global_
config:
name: classification_task
num_epochs: 2
Expand Down
1 change: 1 addition & 0 deletions classy_vision/hydra/conf/dataset/synthetic_image.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# @package _global_
config:
dataset:
train:
Expand Down
1 change: 1 addition & 0 deletions classy_vision/hydra/conf/loss/cross_entropy.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# @package _global_
config:
loss:
name: CrossEntropyLoss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# @package _global_
config:
loss:
name: label_smoothing_cross_entropy
Expand Down
1 change: 1 addition & 0 deletions classy_vision/hydra/conf/meters/accuracy.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# @package _global_
config:
meters:
accuracy:
Expand Down
1 change: 1 addition & 0 deletions classy_vision/hydra/conf/model/resnet_50.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# @package _global_
config:
model:
name: resnet
Expand Down
1 change: 1 addition & 0 deletions classy_vision/hydra/conf/optimizer/sgd.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# @package _global_
config:
optimizer:
name: sgd
Expand Down
1 change: 1 addition & 0 deletions classy_vision/hydra/conf/param_scheduler/step.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# @package _global_
config:
optimizer:
param_schedulers:
Expand Down
1 change: 1 addition & 0 deletions classy_vision/hydra/conf/task/classification_task.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# @package _global_
config:
name: classification_task
num_epochs: 2
1 change: 1 addition & 0 deletions classy_vision/templates/synthetic/hydra_configs/args.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# @package _global_
debug: False
device: null
checkpoint_folder: ""
Expand Down
9 changes: 6 additions & 3 deletions hydra_plugins/classy_vision_path/classy_vision_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

from hydra.plugins import SearchPathPlugin
from hydra.core.config_search_path import ConfigSearchPath
from hydra.plugins.search_path_plugin import SearchPathPlugin


class ClassyVisionPathPlugin(SearchPathPlugin):
def manipulate_search_path(self, search_path):
search_path.append("classy_vision", "pkg://classy_vision.hydra.conf")
def manipulate_search_path(self, search_path: ConfigSearchPath) -> None:
search_path.append(
provider="classy_vision", path="pkg://classy_vision.hydra.conf"
)

0 comments on commit 02e1226

Please sign in to comment.