From a6b7fe2e010a9f39883a2275a852b768d8c00d0d Mon Sep 17 00:00:00 2001 From: Tom Aarsen Date: Tue, 6 Jun 2023 16:59:21 +0200 Subject: [PATCH] Prevent ZeroDivisionError if evaluation is too quick --- src/transformers/trainer_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/transformers/trainer_utils.py b/src/transformers/trainer_utils.py index bb44c4c1ab0728..d6008b53e752d0 100644 --- a/src/transformers/trainer_utils.py +++ b/src/transformers/trainer_utils.py @@ -350,6 +350,8 @@ def speed_metrics(split, start_time, num_samples=None, num_steps=None): """ runtime = time.time() - start_time result = {f"{split}_runtime": round(runtime, 4)} + if runtime == 0: + return result if num_samples is not None: samples_per_second = num_samples / runtime result[f"{split}_samples_per_second"] = round(samples_per_second, 3)