Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#55 from guoshengCS/fix-program-seed
Browse files Browse the repository at this point in the history
Copy seed to the new program when using enable_dygraph.
  • Loading branch information
guoshengCS authored Apr 27, 2020
2 parents 15aef48 + 6e5a1a2 commit c88f457
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions hapi/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c88f457

Please sign in to comment.