From 08c5b1d15ceb58d99ef8cc45732de7544e812ccd Mon Sep 17 00:00:00 2001 From: shangliang Xu Date: Fri, 23 Jul 2021 15:54:24 +0800 Subject: [PATCH] fix bug for num_iters in fit/evaluate (#34059) --- python/paddle/hapi/model.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/python/paddle/hapi/model.py b/python/paddle/hapi/model.py index a1fe1f58643..1ac873ce9ca 100644 --- a/python/paddle/hapi/model.py +++ b/python/paddle/hapi/model.py @@ -1707,7 +1707,8 @@ class Model(object): steps = self._len_data_loader(train_loader) self.num_iters = num_iters - if num_iters is not None and isinstance(num_iters, int): + if num_iters is not None and isinstance(num_iters, int) and isinstance( + steps, int): assert num_iters > 0, "num_iters must be greater than 0!" epochs = (num_iters // steps) + 1 steps = min(num_iters, steps) @@ -1742,8 +1743,8 @@ class Model(object): eval_logs = self._run_one_epoch(eval_loader, cbks, 'eval') cbks.on_end('eval', eval_logs) - if self.stop_training: - break + if self.stop_training: + break cbks.on_end('train', logs) self._test_dataloader = None @@ -1830,7 +1831,8 @@ class Model(object): eval_steps = self._len_data_loader(eval_loader) self.num_iters = num_iters - if num_iters is not None and isinstance(num_iters, int): + if num_iters is not None and isinstance(num_iters, int) and isinstance( + eval_steps, int): assert num_iters > 0, "num_iters must be greater than 0!" eval_steps = min(num_iters, eval_steps) self.num_iters = eval_steps @@ -2092,7 +2094,9 @@ class Model(object): callbacks.on_batch_end(mode, step, logs) if hasattr(self, 'num_iters') and self.num_iters is not None: self.num_iters -= 1 - if self.num_iters == 0: + if self.num_iters <= 0: + self.stop_training = True + del self.num_iters break self._reset_metrics() -- GitLab