From ba1e0dd89aef431dad029da924e72a5604a3263d Mon Sep 17 00:00:00 2001 From: Sing_chan <51314274+betterpig@users.noreply.github.com> Date: Wed, 17 Nov 2021 18:58:21 +0800 Subject: [PATCH] avoid zero division problem (#37284) --- .../fluid/tests/unittests/dygraph_to_static/test_sentiment.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_sentiment.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_sentiment.py index f866841935a..74d415cc3ee 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_sentiment.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_sentiment.py @@ -324,6 +324,9 @@ def train(args, to_static): if batch_id % args.log_step == 0: time_end = time.time() used_time = time_end - time_begin + # used_time may be 0.0, cause zero division error + if used_time < 1e-5: + used_time = 1e-5 print("step: %d, ave loss: %f, speed: %f steps/s" % (batch_id, avg_cost.numpy()[0], args.log_step / used_time)) -- GitLab