| import pyrootutils
|
| import pytest
|
| from hydra import compose, initialize
|
| from hydra.core.global_hydra import GlobalHydra
|
| from omegaconf import DictConfig, open_dict
|
|
|
|
|
| @pytest.fixture(scope="package")
|
| def cfg_train_global() -> DictConfig:
|
| with initialize(version_base="1.2", config_path="../configs"):
|
| cfg = compose(config_name="train.yaml", return_hydra_config=True, overrides=[])
|
|
|
|
|
| with open_dict(cfg):
|
| cfg.paths.root_dir = str(pyrootutils.find_root())
|
| cfg.trainer.max_epochs = 1
|
| cfg.trainer.limit_train_batches = 0.02
|
| cfg.trainer.limit_val_batches = 0.2
|
| cfg.trainer.limit_test_batches = 0.2
|
| cfg.trainer.accelerator = "cpu"
|
| cfg.trainer.devices = 1
|
| cfg.datamodule.num_workers = 0
|
| cfg.datamodule.pin_memory = False
|
| cfg.extras.print_config = False
|
| cfg.extras.enforce_tags = False
|
| cfg.logger = None
|
| cfg.launcher = None
|
|
|
| return cfg
|
|
|
|
|
| @pytest.fixture(scope="package")
|
| def cfg_eval_global() -> DictConfig:
|
| with initialize(version_base="1.2", config_path="../configs"):
|
| cfg = compose(config_name="eval.yaml", return_hydra_config=True, overrides=["ckpt_path=."])
|
|
|
|
|
| with open_dict(cfg):
|
| cfg.paths.root_dir = str(pyrootutils.find_root())
|
| cfg.trainer.max_epochs = 1
|
| cfg.trainer.limit_test_batches = 0.2
|
| cfg.trainer.accelerator = "cpu"
|
| cfg.trainer.devices = 1
|
| cfg.datamodule.num_workers = 0
|
| cfg.datamodule.pin_memory = False
|
| cfg.extras.print_config = False
|
| cfg.extras.enforce_tags = False
|
| cfg.logger = None
|
|
|
| return cfg
|
|
|
|
|
|
|
|
|
| @pytest.fixture(scope="function")
|
| def cfg_train(cfg_train_global, tmp_path) -> DictConfig:
|
| cfg = cfg_train_global.copy()
|
|
|
| with open_dict(cfg):
|
| cfg.paths.data_dir = str(tmp_path)
|
| cfg.paths.output_dir = str(tmp_path)
|
| cfg.paths.log_dir = str(tmp_path)
|
|
|
| yield cfg
|
|
|
| GlobalHydra.instance().clear()
|
|
|
|
|
|
|
|
|
| @pytest.fixture(scope="function")
|
| def cfg_eval(cfg_eval_global, tmp_path) -> DictConfig:
|
| cfg = cfg_eval_global.copy()
|
|
|
| with open_dict(cfg):
|
| cfg.paths.data_dir = str(tmp_path)
|
| cfg.paths.output_dir = str(tmp_path)
|
| cfg.paths.log_dir = str(tmp_path)
|
|
|
| yield cfg
|
|
|
| GlobalHydra.instance().clear()
|
|
|