Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,7 @@ def _maybe_log_save_evaluate(
# reset tr_loss to zero
tr_loss -= tr_loss

logs["loss"] = round(tr_loss_scalar / (self.state.global_step - self._globalstep_last_logged), 4)
logs["loss"] = tr_loss_scalar / (self.state.global_step - self._globalstep_last_logged)
if grad_norm is not None:
logs["grad_norm"] = grad_norm.item() if isinstance(grad_norm, torch.Tensor) else grad_norm
if learning_rate is not None:
Expand Down
8 changes: 5 additions & 3 deletions src/transformers/trainer_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,12 +665,12 @@ def on_log(self, args, state, control, logs=None, **kwargs):
f"[String too long to display, length: {len(v)} > {self.max_str_len}. "
"Consider increasing `max_str_len` if needed.]"
)
if isinstance(v, float):
# Format floats for better readability
shallow_logs[k] = f"{v:.4g}"
else:
shallow_logs[k] = v
_ = shallow_logs.pop("total_flos", None)
# round numbers so that it looks better in console
if "epoch" in shallow_logs:
shallow_logs["epoch"] = round(shallow_logs["epoch"], 2)
self.training_bar.write(str(shallow_logs))

def on_train_end(self, args, state, control, **kwargs):
Expand All @@ -687,6 +687,8 @@ class PrinterCallback(TrainerCallback):
def on_log(self, args, state, control, logs=None, **kwargs):
_ = logs.pop("total_flos", None)
if state.is_local_process_zero:
if logs is not None:
logs = {k: (f"{v:.4g}" if isinstance(v, float) else v) for k, v in logs.items()}
print(logs)


Expand Down