2021-01-08 15:36:49 +00:00
|
|
|
# Copyright The PyTorch Lightning team.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from pytorch_lightning import Trainer
|
2021-07-20 21:23:53 +00:00
|
|
|
from tests import _PATH_LEGACY
|
2021-01-08 15:36:49 +00:00
|
|
|
|
2021-07-20 21:23:53 +00:00
|
|
|
LEGACY_CHECKPOINTS_PATH = os.path.join(_PATH_LEGACY, 'checkpoints')
|
2021-01-08 15:36:49 +00:00
|
|
|
CHECKPOINT_EXTENSION = ".ckpt"
|
|
|
|
|
|
|
|
|
2021-01-12 01:36:12 +00:00
|
|
|
# todo: add more legacy checkpoints - for < v0.8
|
2021-02-06 11:07:26 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"pl_version",
|
|
|
|
[
|
|
|
|
# "0.8.1",
|
|
|
|
"0.8.3",
|
|
|
|
"0.8.4",
|
|
|
|
# "0.8.5", # this version has problem with loading on PT<=1.4 as it seems to be archive
|
|
|
|
# "0.9.0", # this version has problem with loading on PT<=1.4 as it seems to be archive
|
|
|
|
"0.10.0",
|
|
|
|
"1.0.0",
|
|
|
|
"1.0.1",
|
|
|
|
"1.0.2",
|
|
|
|
"1.0.3",
|
|
|
|
"1.0.4",
|
|
|
|
"1.0.5",
|
|
|
|
"1.0.6",
|
|
|
|
"1.0.7",
|
|
|
|
"1.0.8",
|
|
|
|
"1.1.0",
|
|
|
|
"1.1.1",
|
|
|
|
"1.1.2",
|
|
|
|
"1.1.3",
|
|
|
|
"1.1.4",
|
|
|
|
"1.1.5",
|
|
|
|
"1.1.6",
|
2021-02-06 06:05:53 +00:00
|
|
|
"1.1.7",
|
|
|
|
"1.1.8",
|
2021-02-19 01:13:54 +00:00
|
|
|
"1.2.0",
|
2021-03-02 16:08:29 +00:00
|
|
|
"1.2.1",
|
2021-03-05 15:57:50 +00:00
|
|
|
"1.2.2",
|
2021-03-09 23:17:36 +00:00
|
|
|
"1.2.3",
|
2021-03-18 20:13:54 +00:00
|
|
|
"1.2.4",
|
2021-03-30 10:45:07 +00:00
|
|
|
"1.2.5",
|
2021-03-31 01:25:22 +00:00
|
|
|
"1.2.6",
|
2021-04-07 22:58:41 +00:00
|
|
|
"1.2.7",
|
2021-05-11 10:44:22 +00:00
|
|
|
"1.2.8",
|
|
|
|
"1.2.10",
|
|
|
|
"1.3.0",
|
|
|
|
"1.3.1",
|
2021-05-24 17:55:02 +00:00
|
|
|
"1.3.2",
|
2021-06-13 04:12:49 +00:00
|
|
|
"1.3.3",
|
|
|
|
"1.3.4",
|
|
|
|
"1.3.5",
|
2021-06-17 15:59:40 +00:00
|
|
|
"1.3.6",
|
2021-07-01 21:49:06 +00:00
|
|
|
"1.3.7",
|
|
|
|
"1.3.8",
|
2021-02-06 11:07:26 +00:00
|
|
|
]
|
|
|
|
)
|
2021-03-09 11:27:15 +00:00
|
|
|
def test_resume_legacy_checkpoints(tmpdir, pl_version: str):
|
2021-01-08 15:36:49 +00:00
|
|
|
path_dir = os.path.join(LEGACY_CHECKPOINTS_PATH, pl_version)
|
|
|
|
|
|
|
|
# todo: make this as mock, so it is cleaner...
|
|
|
|
orig_sys_paths = list(sys.path)
|
|
|
|
sys.path.insert(0, path_dir)
|
|
|
|
from zero_training import DummyModel
|
|
|
|
|
|
|
|
path_ckpts = sorted(glob.glob(os.path.join(path_dir, f'*{CHECKPOINT_EXTENSION}')))
|
|
|
|
assert path_ckpts, 'No checkpoints found in folder "%s"' % path_dir
|
|
|
|
path_ckpt = path_ckpts[-1]
|
|
|
|
|
|
|
|
model = DummyModel.load_from_checkpoint(path_ckpt)
|
|
|
|
trainer = Trainer(default_root_dir=tmpdir, max_epochs=6)
|
2021-04-28 18:11:32 +00:00
|
|
|
trainer.fit(model)
|
2021-01-08 15:36:49 +00:00
|
|
|
|
|
|
|
# todo
|
|
|
|
# model = DummyModel()
|
|
|
|
# trainer = Trainer(default_root_dir=tmpdir, max_epochs=1, resume_from_checkpoint=path_ckpt)
|
2021-04-28 18:11:32 +00:00
|
|
|
# trainer.fit(model)
|
2021-01-08 15:36:49 +00:00
|
|
|
|
|
|
|
sys.path = orig_sys_paths
|