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 #14 from idiap/drop-py39
Drop Python 3.9 support
- Loading branch information
Showing
35 changed files
with
549 additions
and
419 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
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,6 +0,0 @@ | ||
import os | ||
|
||
|
||
def run_cli(command): | ||
exit_status = os.system(command) | ||
assert exit_status == 0, f" [!] command `{command}` failed." | ||
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,30 @@ | ||
import pytest | ||
|
||
from trainer.config import TrainerConfig | ||
|
||
|
||
def test_optimizer_params(): | ||
TrainerConfig( | ||
optimizer="optimizer", | ||
grad_clip=0.0, | ||
lr=0.1, | ||
optimizer_params={}, | ||
lr_scheduler="scheduler", | ||
) | ||
|
||
TrainerConfig( | ||
optimizer=["optimizer1", "optimizer2"], | ||
grad_clip=[0.0, 0.0], | ||
lr=[0.1, 0.01], | ||
optimizer_params=[{}, {}], | ||
lr_scheduler=["scheduler1", "scheduler2"], | ||
) | ||
|
||
with pytest.raises(TypeError, match="Either none or all of these fields must be a list:"): | ||
TrainerConfig( | ||
optimizer=["optimizer1", "optimizer2"], | ||
grad_clip=0.0, | ||
lr=[0.1, 0.01], | ||
optimizer_params=[{}, {}], | ||
lr_scheduler=["scheduler1", "scheduler2"], | ||
) |
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,27 +1,31 @@ | ||
from tests import run_cli | ||
import sys | ||
|
||
from tests.utils.train_mnist import main as train_mnist | ||
|
||
def test_continue_train(tmp_path): | ||
command_train = f"python tests/utils/train_mnist.py --coqpit.output_path {tmp_path}" | ||
run_cli(command_train) | ||
|
||
def test_continue_train(tmp_path, monkeypatch): | ||
with monkeypatch.context() as m: | ||
m.setattr(sys, "argv", [sys.argv[0], "--coqpit.output_path", str(tmp_path)]) | ||
train_mnist() | ||
|
||
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) | ||
with monkeypatch.context() as m: | ||
m.setattr(sys, "argv", [sys.argv[0], "--continue_path", str(continue_path), "--coqpit.run_eval_steps", "1"]) | ||
train_mnist() | ||
|
||
assert number_of_checkpoints < len(list(continue_path.glob("*.pth"))) | ||
|
||
# Continue training from the last checkpoint | ||
for best in continue_path.glob("best_model*"): | ||
best.unlink() | ||
run_cli(command_continue) | ||
|
||
# Continue training from a specific checkpoint | ||
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) | ||
with monkeypatch.context() as m: | ||
m.setattr( | ||
sys, "argv", [sys.argv[0], "--restore_path", str(restore_path), "--coqpit.output_path", str(tmp_path)] | ||
) | ||
train_mnist() |
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,23 @@ | ||
from collections.abc import Callable | ||
from typing import TYPE_CHECKING, Any, TypeAlias, TypedDict | ||
|
||
import torch | ||
|
||
if TYPE_CHECKING: | ||
import matplotlib | ||
import numpy.typing as npt | ||
import plotly | ||
|
||
from trainer.trainer import Trainer | ||
|
||
|
||
Audio: TypeAlias = "npt.NDArray[Any]" | ||
Figure: TypeAlias = "matplotlib.figure.Figure | plotly.graph_objects.Figure" | ||
LRScheduler: TypeAlias = torch.optim.lr_scheduler._LRScheduler | ||
|
||
Callback: TypeAlias = Callable[["Trainer"], None] | ||
|
||
|
||
class LossDict(TypedDict): | ||
train_loss: float | ||
eval_loss: float | None |
Oops, something went wrong.