forked from coqui-ai/Trainer
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbase_dash_logger.py
96 lines (71 loc) · 3.26 KB
/
base_dash_logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Any
from trainer._types import Audio, Figure
from trainer.config import TrainerConfig
from trainer.io import save_fsspec
from trainer.utils.distributed import rank_zero_only
if TYPE_CHECKING:
import torch
# pylint: disable=too-many-public-methods
class BaseDashboardLogger(ABC):
@abstractmethod
def model_weights(self, model: "torch.nn.Module", step: int) -> None:
pass
@abstractmethod
def add_scalar(self, title: str, value: float, step: int) -> None:
pass
@abstractmethod
def add_figure(self, title: str, figure: Figure, step: int) -> None:
pass
@abstractmethod
def add_config(self, config: TrainerConfig) -> None:
pass
@abstractmethod
def add_audio(self, title: str, audio: Audio, step: int, sample_rate: int) -> None:
pass
@abstractmethod
def add_text(self, title: str, text: str, step: int) -> None:
pass
@abstractmethod
def add_artifact(
self, file_or_dir: str | os.PathLike[Any], name: str, artifact_type: str, aliases: list[str] | None = None
) -> None:
pass
@abstractmethod
def add_scalars(self, scope_name: str, scalars: dict[str, float], step: int) -> None:
pass
@abstractmethod
def add_figures(self, scope_name: str, figures: dict[str, Figure], step: int) -> None:
pass
@abstractmethod
def add_audios(self, scope_name: str, audios: dict[str, Audio], step: int, sample_rate: int) -> None:
pass
@abstractmethod
def flush(self) -> None:
pass
@abstractmethod
def finish(self) -> None:
pass
@staticmethod
@rank_zero_only
def save_model(state: dict[str, Any], path: str) -> None:
save_fsspec(state, path)
def train_step_stats(self, step: int, stats: dict[str, float]) -> None:
self.add_scalars(scope_name="TrainIterStats", scalars=stats, step=step)
def train_epoch_stats(self, step: int, stats: dict[str, float]) -> None:
self.add_scalars(scope_name="TrainEpochStats", scalars=stats, step=step)
def train_figures(self, step: int, figures: dict[str, Figure]) -> None:
self.add_figures(scope_name="TrainFigures", figures=figures, step=step)
def train_audios(self, step: int, audios: dict[str, Audio], sample_rate: int) -> None:
self.add_audios(scope_name="TrainAudios", audios=audios, step=step, sample_rate=sample_rate)
def eval_stats(self, step: int, stats: dict[str, float]) -> None:
self.add_scalars(scope_name="EvalStats", scalars=stats, step=step)
def eval_figures(self, step: int, figures: dict[str, Figure]) -> None:
self.add_figures(scope_name="EvalFigures", figures=figures, step=step)
def eval_audios(self, step: int, audios: dict[str, Audio], sample_rate: int) -> None:
self.add_audios(scope_name="EvalAudios", audios=audios, step=step, sample_rate=sample_rate)
def test_audios(self, step: int, audios: dict[str, Audio], sample_rate: int) -> None:
self.add_audios(scope_name="TestAudios", audios=audios, step=step, sample_rate=sample_rate)
def test_figures(self, step: int, figures: dict[str, Figure]) -> None:
self.add_figures(scope_name="TestFigures", figures=figures, step=step)