From 6e5a1a225e27855dd810790310109744063760c9 Mon Sep 17 00:00:00 2001 From: guosheng Date: Sun, 26 Apr 2020 20:53:14 +0800 Subject: [PATCH] Copy seed to the new program when using enable_dygraph. --- hapi/model.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hapi/model.py b/hapi/model.py index cde4ba6040be3..5a6748e9f7583 100644 --- a/hapi/model.py +++ b/hapi/model.py @@ -874,8 +874,16 @@ def prepare(self, global _parallel_context_initialized if ParallelEnv().nranks > 1 and not _parallel_context_initialized: if fluid.in_dygraph_mode(): + main_prog_seed = fluid.default_main_program().random_seed + startup_prog_seed = fluid.default_startup_program( + ).random_seed fluid.disable_dygraph() fluid.enable_dygraph(self._place) + # enable_dygraph would create and switch to a new program, + # thus also copy seed to the new program + fluid.default_main_program().random_seed = main_prog_seed + fluid.default_startup_program( + ).random_seed = startup_prog_seed fluid.dygraph.parallel.prepare_context() else: prepare_distributed_context(self._place)