Merge pull request #899 from shirayu/use_moving_average

Show moving average loss in the progress bar
This commit is contained in:
Kohya S
2023-10-29 14:37:58 +09:00
committed by GitHub
8 changed files with 53 additions and 67 deletions

View File

@@ -4697,3 +4697,21 @@ class collator_class:
dataset.set_current_epoch(self.current_epoch.value)
dataset.set_current_step(self.current_step.value)
return examples[0]
class LossRecorder:
def __init__(self):
self.loss_list: List[float] = []
self.loss_total: float = 0.0
def add(self, *, epoch:int, step: int, loss: float) -> None:
if epoch == 0:
self.loss_list.append(loss)
else:
self.loss_total -= self.loss_list[step]
self.loss_list[step] = loss
self.loss_total += loss
@property
def moving_average(self) -> float:
return self.loss_total / len(self.loss_list)