diff --git a/tests/test_models.py b/tests/test_models.py index 86e14578..c1c0ceab 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -36,6 +36,13 @@ def get_exp(): return exp +def clear_tt_dir(): + root_dir = os.path.dirname(os.path.realpath(__file__)) + tt_dir = os.path.join(root_dir, 'tests_tt_dir') + if os.path.exists(tt_dir): + os.remove(tt_dir) + + def assert_ok_acc(trainer): # this model should get 0.80+ acc assert trainer.tng_tqdm_dic['val_acc'] > 0.80, "model failed to get expected 0.80 validation accuracy" @@ -54,12 +61,14 @@ def test_cpu_model(): train_percent_check=0.4, val_percent_check=0.4 ) - result = trainer.fit(model) - assert result == 1, 'cpu model failed to complete' + # correct result and ok accuracy + assert result == 1, 'cpu model failed to complete' assert_ok_acc(trainer) + clear_tt_dir() + def test_single_gpu_model(): """ @@ -82,9 +91,12 @@ def test_single_gpu_model(): result = trainer.fit(model) + # correct result and ok accuracy assert result == 1, 'single gpu model failed to complete' assert_ok_acc(trainer) + clear_tt_dir() + def test_multi_gpu_model_dp(): """ @@ -110,9 +122,12 @@ def test_multi_gpu_model_dp(): result = trainer.fit(model) + # correct result and ok accuracy assert result == 1, 'multi-gpu dp model failed to complete' assert_ok_acc(trainer) + clear_tt_dir() + def test_multi_gpu_model_ddp(): """ @@ -139,9 +154,12 @@ def test_multi_gpu_model_ddp(): result = trainer.fit(model) + # correct result and ok accuracy assert result == 1, 'multi-gpu ddp model failed to complete' assert_ok_acc(trainer) + clear_tt_dir() + def test_amp_gpu_ddp(): """ @@ -169,9 +187,12 @@ def test_amp_gpu_ddp(): result = trainer.fit(model) + # correct result and ok accuracy assert result == 1, 'amp + ddp model failed to complete' assert_ok_acc(trainer) + clear_tt_dir() + def test_amp_gpu_dp(): """ @@ -199,9 +220,11 @@ def test_amp_gpu_dp(): result = trainer.fit(model) + # correct result and ok accuracy assert result == 1, 'amp + gpu model failed to complete' assert_ok_acc(trainer) + clear_tt_dir() if __name__ == '__main__': pytest.main([__file__])