forked from coqui-ai/Trainer
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from idiap/tmp_outputs
Override output_path if provided in Trainer init and use temp folder for test outputs
- Loading branch information
Showing
16 changed files
with
117 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: Setup uv | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Install uv | ||
uses: astral-sh/setup-uv@v3 | ||
with: | ||
version: "0.5.1" | ||
enable-cache: true | ||
cache-dependency-glob: "**/pyproject.toml" |
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
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 |
---|---|---|
@@ -1,32 +1,27 @@ | ||
import glob | ||
import os | ||
import shutil | ||
|
||
from tests import run_cli | ||
|
||
|
||
def test_continue_train(): | ||
output_path = "output/" | ||
|
||
command_train = "python tests/utils/train_mnist.py" | ||
def test_continue_train(tmp_path): | ||
command_train = f"python tests/utils/train_mnist.py --coqpit.output_path {tmp_path}" | ||
run_cli(command_train) | ||
|
||
continue_path = max(glob.glob(os.path.join(output_path, "*/")), key=os.path.getmtime) | ||
number_of_checkpoints = len(glob.glob(os.path.join(continue_path, "*.pth"))) | ||
continue_path = max(tmp_path.iterdir(), key=lambda p: p.stat().st_mtime) | ||
number_of_checkpoints = len(list(continue_path.glob("*.pth"))) | ||
|
||
# Continue training from the best model | ||
command_continue = f"python tests/utils/train_mnist.py --continue_path {continue_path} --coqpit.run_eval_steps=1" | ||
run_cli(command_continue) | ||
|
||
assert number_of_checkpoints < len(glob.glob(os.path.join(continue_path, "*.pth"))) | ||
assert number_of_checkpoints < len(list(continue_path.glob("*.pth"))) | ||
|
||
# Continue training from the last checkpoint | ||
for best in glob.glob(os.path.join(continue_path, "best_model*")): | ||
os.remove(best) | ||
for best in continue_path.glob("best_model*"): | ||
best.unlink() | ||
run_cli(command_continue) | ||
|
||
# Continue training from a specific checkpoint | ||
restore_path = os.path.join(continue_path, "checkpoint_5.pth") | ||
command_continue = f"python tests/utils/train_mnist.py --restore_path {restore_path}" | ||
restore_path = continue_path / "checkpoint_5.pth" | ||
command_continue = ( | ||
f"python tests/utils/train_mnist.py --restore_path {restore_path} --coqpit.output_path {tmp_path}" | ||
) | ||
run_cli(command_continue) | ||
shutil.rmtree(continue_path) |
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
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
Oops, something went wrong.