Skip to content

Commit

Permalink
Successfully Resolved The ZeroDivisionError Exception. (#27524)
Browse files Browse the repository at this point in the history
* Successfully resolved the ZeroDivisionError exception in the utils.notebook.y file.

* Now I update little code mentioned by Peter

* Using Black package to reformat my file

* Now I using ruff libary to reformated my file
  • Loading branch information
hi-sushanta authored Nov 24, 2023
1 parent c13a43a commit 29c9480
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/transformers/utils/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def update(self, value: int, force_update: bool = False, comment: str = None):
self.update_bar(value)
self.last_value = value
self.last_time = current_time
if self.average_time_per_item is None:
if (self.average_time_per_item is None) or (self.average_time_per_item == 0):
self.wait_for = 1
else:
self.wait_for = max(int(self.update_every / self.average_time_per_item), 1)
Expand All @@ -177,7 +177,11 @@ def update_bar(self, value, comment=None):
f"[{spaced_value}/{self.total} {format_time(self.elapsed_time)} <"
f" {format_time(self.predicted_remaining)}"
)
self.label += f", {1/self.average_time_per_item:.2f} it/s"
if self.average_time_per_item == 0:
self.label += ", +inf it/s"
else:
self.label += f", {1/self.average_time_per_item:.2f} it/s"

self.label += "]" if self.comment is None or len(self.comment) == 0 else f", {self.comment}]"
self.display()

Expand Down Expand Up @@ -367,6 +371,8 @@ def on_evaluate(self, args, state, control, metrics=None, **kwargs):

def on_train_end(self, args, state, control, **kwargs):
self.training_tracker.update(
state.global_step, comment=f"Epoch {int(state.epoch)}/{state.num_train_epochs}", force_update=True
state.global_step,
comment=f"Epoch {int(state.epoch)}/{state.num_train_epochs}",
force_update=True,
)
self.training_tracker = None

0 comments on commit 29c9480

Please sign in to comment.