Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions optimum/habana/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1861,12 +1861,8 @@ def evaluation_loop(
if loss is not None:
# Handle NaN loss
if args.logging_nan_inf_filter and (torch.isnan(loss) or torch.isinf(loss)):
# If loss is NaN or Inf, use the average of previous losses or a small constant
if losses_host is not None and len(losses_host) > 0:
avg_loss = torch.mean(losses_host)
loss = avg_loss
else:
loss = torch.tensor(1e-8, device=loss.device)
# If loss is NaN or Inf, use a small constant
loss = torch.tensor(1e-8, device=loss.device)

losses = self.gather_function((loss.repeat(batch_size)))
all_losses.add(losses)
Expand Down