-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove unnecessary on save checkpoint hook injection * Test the run path is stored in the checkpoint * Implement resume logic * Test resume behaviour * Refactor resume with semantic options
- Loading branch information
Showing
5 changed files
with
134 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import torch | ||
from omegaconf import DictConfig, OmegaConf | ||
from pytest import TempPathFactory | ||
|
||
from tests.conftest import TRAIN_MAX_NSTEPS, get_checkpoint_path, load_checkpoint | ||
|
||
from nn_template.run import run | ||
|
||
|
||
def test_resume(run_trainings_not_dry: str, cfg_all_not_dry: DictConfig, tmp_path_factory: TempPathFactory) -> None: | ||
old_checkpoint_path = get_checkpoint_path(run_trainings_not_dry) | ||
|
||
new_cfg = OmegaConf.create(cfg_all_not_dry) | ||
new_storage_dir = tmp_path_factory.mktemp("resumed_training") | ||
|
||
new_cfg.core.storage_dir = str(new_storage_dir) | ||
new_cfg.train.trainer.max_steps = 2 * TRAIN_MAX_NSTEPS | ||
|
||
new_cfg.train.restore.ckpt_or_run_path = str(old_checkpoint_path) | ||
new_cfg.train.restore.mode = "hotstart" | ||
|
||
new_training_dir = run(new_cfg) | ||
|
||
old_checkpoint = torch.load(old_checkpoint_path) | ||
new_checkpoint = load_checkpoint(new_training_dir) | ||
|
||
assert old_checkpoint["run_path"] != new_checkpoint["run_path"] | ||
assert old_checkpoint["global_step"] * 2 == new_checkpoint["global_step"] | ||
assert new_checkpoint["epoch"] == 2 |