Skip to content

Commit

Permalink
remove disent.util.config
Browse files Browse the repository at this point in the history
  • Loading branch information
nmichlo committed Jul 28, 2021
1 parent 8c0005b commit 7f7d757
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 75 deletions.
73 changes: 0 additions & 73 deletions disent/util/config.py

This file was deleted.

2 changes: 1 addition & 1 deletion experiment/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import pytorch_lightning as pl
import torch
import torch.utils.data
from disent.util.config import instantiate_recursive
from omegaconf import DictConfig
from omegaconf import OmegaConf
from pytorch_lightning.loggers import CometLogger
Expand All @@ -49,6 +48,7 @@
from experiment.util.hydra_data import HydraDataModule
from experiment.util.hydra_utils import make_non_strict
from experiment.util.hydra_utils import merge_specializations
from experiment.util.hydra_utils import instantiate_recursive
from experiment.util.run_utils import log_error_and_exit
from experiment.util.run_utils import set_debug_logger
from experiment.util.run_utils import set_debug_trainer
Expand Down
2 changes: 1 addition & 1 deletion experiment/util/hydra_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from disent.dataset import DisentDataset
from disent.nn.transform import DisentDatasetTransform
from disent.util.config import instantiate_recursive
from experiment.util.hydra_utils import instantiate_recursive


# ========================================================================= #
Expand Down
29 changes: 29 additions & 0 deletions experiment/util/hydra_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,43 @@

import logging

import hydra
from deprecated import deprecated
from omegaconf import DictConfig
from omegaconf import ListConfig
from omegaconf import OmegaConf


log = logging.getLogger(__name__)


# ========================================================================= #
# Recursive Hydra Instantiation #
# TODO: use https://github.com/facebookresearch/hydra/pull/989 #
# I think this is quicker? Just doesn't perform checks... #
# ========================================================================= #


@deprecated('replace with hydra 1.1')
def call_recursive(config):
# recurse
def _call_recursive(config):
if isinstance(config, (dict, DictConfig)):
c = {k: _call_recursive(v) for k, v in config.items() if k != '_target_'}
if '_target_' in config:
config = hydra.utils.instantiate({'_target_': config['_target_']}, **c)
elif isinstance(config, (tuple, list, ListConfig)):
config = [_call_recursive(v) for v in config]
return config
return _call_recursive(config)


# alias
@deprecated('replace with hydra 1.1')
def instantiate_recursive(config):
return call_recursive(config)


# ========================================================================= #
# Better Specializations #
# TODO: this might be replaced by recursive instantiation #
Expand Down

0 comments on commit 7f7d757

Please sign in to comment.