From 85d1096b4cc779eeb9c52a606b3637cab060130b Mon Sep 17 00:00:00 2001 From: guru4elephant Date: Mon, 30 Sep 2019 13:55:07 +0800 Subject: [PATCH] add run by example in fl trainer --- paddle_fl/core/trainer/fl_trainer.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/paddle_fl/core/trainer/fl_trainer.py b/paddle_fl/core/trainer/fl_trainer.py index 455b1a9..2c78361 100755 --- a/paddle_fl/core/trainer/fl_trainer.py +++ b/paddle_fl/core/trainer/fl_trainer.py @@ -84,12 +84,26 @@ class FedAvgTrainer(FLTrainer): def start(self): self.exe = fluid.Executor(fluid.CPUPlace()) self.exe.run(self._startup_program) + self.step = 0 def set_trainer_job(self, job): super(FedAvgTrainer, self).set_trainer_job(job) self._send_program = job._trainer_send_program self._recv_program = job._trainer_recv_program + def reset(self): + self.cur_step = 0 + + def run(self, feed, fetch): + if self.cur_step % self._step == 0: + self.exe.run(self._recv_program) + self.exe.run(self._main_program, + feed=feed, + fetch_list=fetch) + if self.cur_step % self._step == 0: + self.exe.run(self._send_program) + self.cur_step += 1 + def train_inner_loop(self, reader): self.exe.run(self._recv_program) now_step = 0 -- GitLab