Skip to content

Commit

Permalink
round epoch only in console (#30237)
Browse files Browse the repository at this point in the history
  • Loading branch information
xdedss authored Apr 15, 2024
1 parent fe2d20d commit 7668101
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3048,7 +3048,7 @@ def log(self, logs: Dict[str, float]) -> None:
The values to log.
"""
if self.state.epoch is not None:
logs["epoch"] = round(self.state.epoch, 2)
logs["epoch"] = self.state.epoch
if self.args.include_num_input_tokens_seen:
logs["num_input_tokens_seen"] = self.state.num_input_tokens_seen

Expand Down
6 changes: 6 additions & 0 deletions src/transformers/trainer_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
Callbacks to use with the Trainer class and customize the training loop.
"""
import copy
import dataclasses
import json
from dataclasses import dataclass
Expand Down Expand Up @@ -520,7 +521,12 @@ def on_predict(self, args, state, control, **kwargs):

def on_log(self, args, state, control, logs=None, **kwargs):
if state.is_world_process_zero and self.training_bar is not None:
# avoid modifying the logs object as it is shared between callbacks
logs = copy.deepcopy(logs)
_ = logs.pop("total_flos", None)
# round numbers so that it looks better in console
if "epoch" in logs:
logs["epoch"] = round(logs["epoch"], 2)
self.training_bar.write(str(logs))

def on_train_end(self, args, state, control, **kwargs):
Expand Down

0 comments on commit 7668101

Please sign in to comment.