diff --git a/paddle/fluid/framework/new_executor/interpretercore_util.cc b/paddle/fluid/framework/new_executor/interpretercore_util.cc index 07fb60bd2186c218bf544da6158562c9d04bb185..08f2dd3dc2487cc6827c19f9a3f148d511f684af 100644 --- a/paddle/fluid/framework/new_executor/interpretercore_util.cc +++ b/paddle/fluid/framework/new_executor/interpretercore_util.cc @@ -685,6 +685,22 @@ std::map> build_op_downstream_map( } } } + + // add dependences for random op, make sure that the random op is scheduled + // sequentially + const std::set random_op_set = { + "bernoulli", "poisson", "multinomial", "gaussian_random", + "uniform_random", "randint", "randperm", "exponential"}; + int dependence_op_idx = -1; + for (size_t op_idx = 0; op_idx < vec_instruction.size(); ++op_idx) { + if (random_op_set.count(vec_instruction[op_idx].OpBase()->Type())) { + if (dependence_op_idx != -1) { + op2dependences[op_idx].insert(dependence_op_idx); + } + dependence_op_idx = op_idx; + } + } + return std::move(get_downstream_map(op2dependences)); }