mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
Dev gzf exp (#1684)
* resume from step * batch * batch * batch * batch * batch * batch * batch * batch * batch * batch * batch * batch * batch * batch * batch * train_loss_avg train_acc_avg * train_loss_avg train_acc_avg
This commit is contained in:
parent
a09aba419f
commit
48a8c95334
@ -198,7 +198,7 @@ def main(**kwargs):
|
||||
writer = None
|
||||
|
||||
dataloader_tr, dataloader_val = None, None
|
||||
for epoch in range(trainer.start_epoch, trainer.max_epoch + 1):
|
||||
for epoch in range(trainer.start_epoch, trainer.max_epoch):
|
||||
time1 = time.perf_counter()
|
||||
|
||||
for data_split_i in range(trainer.start_data_split_i, dataloader.data_split_num):
|
||||
|
||||
@ -169,6 +169,8 @@ class Trainer:
|
||||
"data_split_i": kwargs.get("data_split_i", 0),
|
||||
"data_split_num": kwargs.get("data_split_num", 1),
|
||||
"batch_total": self.batch_total,
|
||||
"train_loss_avg": kwargs.get("train_loss_avg", 0),
|
||||
"train_acc_avg": kwargs.get("train_acc_avg", 0),
|
||||
}
|
||||
step = step_in_epoch
|
||||
if hasattr(model, "module"):
|
||||
@ -306,7 +308,12 @@ class Trainer:
|
||||
checkpoint["step_in_epoch"] if "step_in_epoch" in checkpoint else 0
|
||||
)
|
||||
self.step_in_epoch = 0 if self.step_in_epoch is None else self.step_in_epoch
|
||||
|
||||
self.train_acc_avg = (
|
||||
checkpoint["train_acc_avg"] if "train_acc_avg" in checkpoint else 0
|
||||
)
|
||||
self.train_loss_avg = (
|
||||
checkpoint["train_loss_avg"] if "train_loss_avg" in checkpoint else 0
|
||||
)
|
||||
model.to(self.device)
|
||||
print(f"Checkpoint loaded successfully from '{ckpt}'")
|
||||
else:
|
||||
@ -400,12 +407,13 @@ class Trainer:
|
||||
speed_stats["backward_time"] = f"{time4 - time3:0.3f}"
|
||||
|
||||
self.train_loss_avg = (
|
||||
self.train_loss_avg * batch_idx + loss.detach().cpu().item()
|
||||
) / (batch_idx + 1)
|
||||
self.train_loss_avg * (self.step_in_epoch - 1) + loss.detach().cpu().item()
|
||||
) / self.step_in_epoch
|
||||
if "acc" in stats:
|
||||
self.train_acc_avg = (
|
||||
self.train_acc_avg * batch_idx + stats["acc"].detach().cpu().item()
|
||||
) / (batch_idx + 1)
|
||||
self.train_acc_avg * (self.step_in_epoch - 1)
|
||||
+ stats["acc"].detach().cpu().item()
|
||||
) / self.step_in_epoch
|
||||
if self.use_ddp or self.use_fsdp:
|
||||
train_loss_avg = torch.tensor(self.train_loss_avg, dtype=torch.float32).to(
|
||||
self.device
|
||||
@ -490,6 +498,8 @@ class Trainer:
|
||||
step_in_epoch=self.step_in_epoch,
|
||||
data_split_i=kwargs.get("data_split_i", 0),
|
||||
data_split_num=kwargs.get("data_split_num", 1),
|
||||
train_loss_avg=self.train_loss_avg,
|
||||
train_acc_avg=self.train_acc_avg,
|
||||
)
|
||||
|
||||
time_beg = time.perf_counter()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user