Release/1.0 (#156)
* update to Hydra 1.1 * add bash folder with scripts for conda setup and run scheduling * add saving seed in `log_hyperparameters()` method * redesign Dockerfile to make it weight less * add `test_after_training` parameter to config * add inheritance to trainer configs * remove forcing ddp-friendly configuration * refactor tests * remove conda_env_gpu.yaml * remove default langage version from pre-commit config * add mnist datamodule unit test * rename test folder from 'smoke' to 'shell' * remove wandb import from utils.py * change 'use_artifact' to 'log_artifact' in wandb callbacks * add rank zero decorator to wandb callbacks * add dumping rich tree config to file * get rid of `=` character in ckpt names * update requirements.txt * update LICENSE * update README.md
This commit is contained in:
1 parent
362a4beebb
commit
d45f604bc8
35 files changed
+398
-424
No files matched your search
@@ -18,9 +18,6 @@ def _module_available(module_path: str) -> bool:
|
||||
"""
|
||||
try:
|
||||
return find_spec(module_path) is not None
|
||||
except AttributeError:
|
||||
# Python 3.6
|
||||
return False
|
||||
except ModuleNotFoundError:
|
||||
# Python 3.7+
|
||||
return False
|
||||
|
||||
File renamed without changes.
@@ -0,0 +1,58 @@
|
||||
import pytest
|
||||
|
||||
from tests.helpers.run_command import run_command
|
||||
from tests.helpers.runif import RunIf
|
||||
|
||||
|
||||
def test_fast_dev_run():
|
||||
"""Run 1 train, val, test batch."""
|
||||
command = ["run.py", "++trainer.fast_dev_run=true"]
|
||||
run_command(command)
|
||||
|
||||
|
||||
def test_default_cpu():
|
||||
"""Test default config on CPU."""
|
||||
command = ["run.py", "++trainer.max_epochs=1", "++trainer.gpus=0"]
|
||||
run_command(command)
|
||||
|
||||
|
||||
# use RunIf to skip execution of some tests, e.g. when no gpus are available
|
||||
@RunIf(min_gpus=1)
|
||||
def test_default_gpu():
|
||||
"""Test default config on GPU."""
|
||||
command = [
|
||||
"run.py",
|
||||
"++trainer.max_epochs=1",
|
||||
"++trainer.gpus=1",
|
||||
"++datamodule.pin_memory=True",
|
||||
]
|
||||
run_command(command)
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_experiments():
|
||||
"""Train 1 epoch with all experiment configs."""
|
||||
command = ["run.py", "-m", "experiment=glob(*)", "++trainer.max_epochs=1"]
|
||||
run_command(command)
|
||||
|
||||
|
||||
def test_limit_batches():
|
||||
"""Train 1 epoch on 25% of data."""
|
||||
command = [
|
||||
"run.py",
|
||||
"++trainer.max_epochs=1",
|
||||
"++trainer.limit_train_batches=0.25",
|
||||
"++trainer.limit_val_batches=0.25",
|
||||
"++trainer.limit_test_batches=0.25",
|
||||
]
|
||||
run_command(command)
|
||||
|
||||
|
||||
def test_double_validation_loop():
|
||||
"""Train 1 epoch with validation loop twice per epoch."""
|
||||
command = [
|
||||
"run.py",
|
||||
"++trainer.max_epochs=1",
|
||||
"++trainer.val_check_interval=0.5",
|
||||
]
|
||||
run_command(command)
|
||||
@@ -0,0 +1,47 @@
|
||||
from tests.helpers.run_command import run_command
|
||||
from tests.helpers.runif import RunIf
|
||||
|
||||
|
||||
@RunIf(amp_apex=True)
|
||||
def test_apex_O1():
|
||||
"""Test mixed-precision level O1."""
|
||||
command = [
|
||||
"run.py",
|
||||
"trainer=default",
|
||||
"++trainer.max_epochs=1",
|
||||
"++trainer.gpus=1",
|
||||
"++trainer.amp_backend=apex",
|
||||
"++trainer.amp_level=O1",
|
||||
"++trainer.precision=16",
|
||||
]
|
||||
run_command(command)
|
||||
|
||||
|
||||
@RunIf(amp_apex=True)
|
||||
def test_apex_O2():
|
||||
"""Test mixed-precision level O2."""
|
||||
command = [
|
||||
"run.py",
|
||||
"trainer=default",
|
||||
"++trainer.max_epochs=1",
|
||||
"++trainer.gpus=1",
|
||||
"++trainer.amp_backend=apex",
|
||||
"++trainer.amp_level=O2",
|
||||
"++trainer.precision=16",
|
||||
]
|
||||
run_command(command)
|
||||
|
||||
|
||||
@RunIf(amp_apex=True)
|
||||
def test_apex_O3():
|
||||
"""Test mixed-precision level O3."""
|
||||
command = [
|
||||
"run.py",
|
||||
"trainer=default",
|
||||
"++trainer.max_epochs=1",
|
||||
"++trainer.gpus=1",
|
||||
"++trainer.amp_backend=apex",
|
||||
"++trainer.amp_level=O3",
|
||||
"++trainer.precision=16",
|
||||
]
|
||||
run_command(command)
|
||||
@@ -17,7 +17,7 @@ def test_default_sweep():
|
||||
"datamodule.batch_size=64,128",
|
||||
"model.lr=0.01,0.02",
|
||||
"trainer=default",
|
||||
"trainer.fast_dev_run=true",
|
||||
"++trainer.fast_dev_run=true",
|
||||
]
|
||||
run_command(command)
|
||||
|
||||
@@ -30,14 +30,6 @@ def test_optuna_sweep():
|
||||
"-m",
|
||||
"hparams_search=mnist_optuna",
|
||||
"trainer=default",
|
||||
"trainer.fast_dev_run=true",
|
||||
"++trainer.fast_dev_run=true",
|
||||
]
|
||||
run_command(command)
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="TODO: Add Ax sweep config.")
|
||||
@pytest.mark.slow
|
||||
def test_ax_sweep():
|
||||
"""Test Ax sweeper."""
|
||||
command = ["run.py", "-m", "hparams_search=mnist_ax", "trainer.fast_dev_run=true"]
|
||||
run_command(command)
|
||||
@@ -1,106 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from tests.helpers.run_command import run_command
|
||||
from tests.helpers.runif import RunIf
|
||||
|
||||
|
||||
def test_fast_dev_run():
|
||||
"""Run 1 train, val, test batch."""
|
||||
command = ["run.py", "trainer=default", "trainer.fast_dev_run=true"]
|
||||
run_command(command)
|
||||
|
||||
|
||||
def test_default_cpu():
|
||||
"""Test default configuration on CPU."""
|
||||
command = ["run.py", "trainer.max_epochs=1", "trainer.gpus=0"]
|
||||
run_command(command)
|
||||
|
||||
|
||||
@RunIf(min_gpus=1)
|
||||
def test_default_gpu():
|
||||
"""Test default configuration on GPU."""
|
||||
command = [
|
||||
"run.py",
|
||||
"trainer.max_epochs=1",
|
||||
"trainer.gpus=1",
|
||||
"datamodule.pin_memory=True",
|
||||
]
|
||||
run_command(command)
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_experiments():
|
||||
"""Train 1 epoch with all experiment configs."""
|
||||
command = ["run.py", "-m", "experiment=glob(*)", "trainer.max_epochs=1"]
|
||||
run_command(command)
|
||||
|
||||
|
||||
def test_limit_batches():
|
||||
"""Train 1 epoch on 25% of data."""
|
||||
command = [
|
||||
"run.py",
|
||||
"trainer=default",
|
||||
"trainer.max_epochs=1",
|
||||
"trainer.limit_train_batches=0.25",
|
||||
"trainer.limit_val_batches=0.25",
|
||||
"trainer.limit_test_batches=0.25",
|
||||
]
|
||||
run_command(command)
|
||||
|
||||
|
||||
def test_gradient_accumulation():
|
||||
"""Train 1 epoch with gradient accumulation."""
|
||||
command = [
|
||||
"run.py",
|
||||
"trainer=default",
|
||||
"trainer.max_epochs=1",
|
||||
"trainer.accumulate_grad_batches=10",
|
||||
]
|
||||
run_command(command)
|
||||
|
||||
|
||||
def test_double_validation_loop():
|
||||
"""Train 1 epoch with validation loop twice per epoch."""
|
||||
command = [
|
||||
"run.py",
|
||||
"trainer=default",
|
||||
"trainer.max_epochs=1",
|
||||
"trainer.val_check_interval=0.5",
|
||||
]
|
||||
run_command(command)
|
||||
|
||||
|
||||
def test_csv_logger():
|
||||
"""Train 5 epochs with 5 batches with CSVLogger."""
|
||||
command = [
|
||||
"run.py",
|
||||
"trainer=default",
|
||||
"trainer.max_epochs=5",
|
||||
"trainer.limit_train_batches=5",
|
||||
"logger=csv",
|
||||
]
|
||||
run_command(command)
|
||||
|
||||
|
||||
def test_tensorboard_logger():
|
||||
"""Train 5 epochs with 5 batches with TensorboardLogger."""
|
||||
command = [
|
||||
"run.py",
|
||||
"trainer=default",
|
||||
"trainer.max_epochs=5",
|
||||
"trainer.limit_train_batches=5",
|
||||
"logger=tensorboard",
|
||||
]
|
||||
run_command(command)
|
||||
|
||||
|
||||
def test_overfit_batches():
|
||||
"""Overfit to 10 batches over 10 epochs."""
|
||||
command = [
|
||||
"run.py",
|
||||
"trainer=default",
|
||||
"trainer.min_epochs=10",
|
||||
"trainer.max_epochs=10",
|
||||
"trainer.overfit_batches=10",
|
||||
]
|
||||
run_command(command)
|
||||
@@ -1,47 +0,0 @@
|
||||
from tests.helpers.run_command import run_command
|
||||
from tests.helpers.runif import RunIf
|
||||
|
||||
|
||||
@RunIf(amp_apex=True)
|
||||
def test_apex_01():
|
||||
"""Test mixed-precision level 01."""
|
||||
command = [
|
||||
"run.py",
|
||||
"trainer=default",
|
||||
"trainer.max_epochs=1",
|
||||
"trainer.gpus=1",
|
||||
"trainer.amp_backend=apex",
|
||||
"trainer.amp_level=O1",
|
||||
"trainer.precision=16",
|
||||
]
|
||||
run_command(command)
|
||||
|
||||
|
||||
@RunIf(amp_apex=True)
|
||||
def test_apex_02():
|
||||
"""Test mixed-precision level 02."""
|
||||
command = [
|
||||
"run.py",
|
||||
"trainer=default",
|
||||
"trainer.max_epochs=1",
|
||||
"trainer.gpus=1",
|
||||
"trainer.amp_backend=apex",
|
||||
"trainer.amp_level=O2",
|
||||
"trainer.precision=16",
|
||||
]
|
||||
run_command(command)
|
||||
|
||||
|
||||
@RunIf(amp_apex=True)
|
||||
def test_apex_03():
|
||||
"""Test mixed-precision level 03."""
|
||||
command = [
|
||||
"run.py",
|
||||
"trainer=default",
|
||||
"trainer.max_epochs=1",
|
||||
"trainer.gpus=1",
|
||||
"trainer.amp_backend=apex",
|
||||
"trainer.amp_level=O3",
|
||||
"trainer.precision=16",
|
||||
]
|
||||
run_command(command)
|
||||
@@ -1,40 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from tests.helpers.run_command import run_command
|
||||
|
||||
"""
|
||||
Use the following command to skip slow tests:
|
||||
pytest -k "not slow"
|
||||
"""
|
||||
|
||||
|
||||
# @pytest.mark.slow
|
||||
# def test_wandb_optuna_sweep():
|
||||
# """Test wandb logging with Optuna sweep."""
|
||||
# command = [
|
||||
# "run.py",
|
||||
# "-m",
|
||||
# "hparams_search=mnist_optuna",
|
||||
# "trainer=default",
|
||||
# "trainer.max_epochs=10",
|
||||
# "trainer.limit_train_batches=20",
|
||||
# "logger=wandb",
|
||||
# "logger.wandb.project=template-tests",
|
||||
# "logger.wandb.group=Optuna_SimpleDenseNet_MNIST",
|
||||
# "hydra.sweeper.n_trials=5",
|
||||
# ]
|
||||
# run_command(command)
|
||||
|
||||
|
||||
# @pytest.mark.slow
|
||||
# def test_wandb_callbacks():
|
||||
# """Test wandb callbacks."""
|
||||
# command = [
|
||||
# "run.py",
|
||||
# "trainer=default",
|
||||
# "trainer.max_epochs=3",
|
||||
# "logger=wandb",
|
||||
# "logger.wandb.project=template-tests",
|
||||
# "callbacks=wandb",
|
||||
# ]
|
||||
# run_command(command)
|
||||
@@ -0,0 +1,36 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from src.datamodules.mnist_datamodule import MNISTDataModule
|
||||
|
||||
|
||||
@pytest.mark.parametrize("batch_size", [32, 128])
|
||||
def test_mnist_datamodule(batch_size):
|
||||
datamodule = MNISTDataModule(batch_size=batch_size)
|
||||
datamodule.prepare_data()
|
||||
|
||||
assert not datamodule.data_train and not datamodule.data_val and not datamodule.data_test
|
||||
|
||||
assert os.path.exists(os.path.join("data", "MNIST"))
|
||||
assert os.path.exists(os.path.join("data", "MNIST", "raw"))
|
||||
|
||||
datamodule.setup()
|
||||
|
||||
assert datamodule.data_train and datamodule.data_val and datamodule.data_test
|
||||
assert (
|
||||
len(datamodule.data_train) + len(datamodule.data_val) + len(datamodule.data_test) == 70_000
|
||||
)
|
||||
|
||||
assert datamodule.train_dataloader()
|
||||
assert datamodule.val_dataloader()
|
||||
assert datamodule.test_dataloader()
|
||||
|
||||
batch = next(iter(datamodule.train_dataloader()))
|
||||
x, y = batch
|
||||
|
||||
assert len(x) == batch_size
|
||||
assert len(y) == batch_size
|
||||
assert x.dtype == torch.float32
|
||||
assert y.dtype == torch.int64
|
||||
@@ -1,26 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from tests.helpers.runif import RunIf
|
||||
|
||||
|
||||
def test_something1():
|
||||
"""Some test description."""
|
||||
assert True is True
|
||||
|
||||
|
||||
def test_something2():
|
||||
"""Some test description."""
|
||||
assert 1 + 1 == 2
|
||||
|
||||
|
||||
@pytest.mark.parametrize("arg1", [0.5, 1.0, 2.0])
|
||||
def test_something3(arg1: float):
|
||||
"""Some test description."""
|
||||
assert arg1 > 0
|
||||
|
||||
|
||||
# use RunIf to skip execution of some tests, e.g. when not on windows or when no gpus are available
|
||||
@RunIf(skip_windows=True, min_gpus=1)
|
||||
def test_something4():
|
||||
"""Some test description."""
|
||||
assert True is True
|
||||
Reference in new issue
Block a user