forked from ashleve/lightning-hydra-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sweeps.py
107 lines (88 loc) · 2.64 KB
/
test_sweeps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from pathlib import Path
import pytest
from tests.helpers.run_if import RunIf
from tests.helpers.run_sh_command import run_sh_command
startfile = "src/train.py"
overrides = ["logger=[]"]
@RunIf(sh=True)
@pytest.mark.slow
def test_experiments(tmp_path: Path) -> None:
"""Test running all available experiment configs with `fast_dev_run=True.`
:param tmp_path: The temporary logging path.
"""
command = [
startfile,
"-m",
"experiment=glob(*)",
"hydra.sweep.dir=" + str(tmp_path),
"++trainer.fast_dev_run=true",
] + overrides
run_sh_command(command)
@RunIf(sh=True)
@pytest.mark.slow
def test_hydra_sweep(tmp_path: Path) -> None:
"""Test default hydra sweep.
:param tmp_path: The temporary logging path.
"""
command = [
startfile,
"-m",
"hydra.sweep.dir=" + str(tmp_path),
"model.optimizer.lr=0.005,0.01",
"++trainer.fast_dev_run=true",
] + overrides
run_sh_command(command)
@RunIf(sh=True)
@pytest.mark.slow
def test_hydra_sweep_ddp_sim(tmp_path: Path) -> None:
"""Test default hydra sweep with ddp sim.
:param tmp_path: The temporary logging path.
"""
command = [
startfile,
"-m",
"hydra.sweep.dir=" + str(tmp_path),
"trainer=ddp_sim",
"trainer.max_epochs=3",
"+trainer.limit_train_batches=0.01",
"+trainer.limit_val_batches=0.1",
"+trainer.limit_test_batches=0.1",
"model.optimizer.lr=0.005,0.01,0.02",
] + overrides
run_sh_command(command)
@RunIf(sh=True)
@pytest.mark.slow
def test_optuna_sweep(tmp_path: Path) -> None:
"""Test Optuna hyperparam sweeping.
:param tmp_path: The temporary logging path.
"""
command = [
startfile,
"-m",
"hparams_search=mnist_optuna",
"hydra.sweep.dir=" + str(tmp_path),
"hydra.sweeper.n_trials=10",
"hydra.sweeper.sampler.n_startup_trials=5",
"++trainer.fast_dev_run=true",
] + overrides
run_sh_command(command)
@RunIf(wandb=True, sh=True)
@pytest.mark.slow
def test_optuna_sweep_ddp_sim_wandb(tmp_path: Path) -> None:
"""Test Optuna sweep with wandb logging and ddp sim.
:param tmp_path: The temporary logging path.
"""
command = [
startfile,
"-m",
"hparams_search=mnist_optuna",
"hydra.sweep.dir=" + str(tmp_path),
"hydra.sweeper.n_trials=5",
"trainer=ddp_sim",
"trainer.max_epochs=3",
"+trainer.limit_train_batches=0.01",
"+trainer.limit_val_batches=0.1",
"+trainer.limit_test_batches=0.1",
"logger=wandb",
]
run_sh_command(command)