From 1b90f96843061c6fa6d39f4cf67628377cc60be0 Mon Sep 17 00:00:00 2001 From: YuanRisheng Date: Sun, 26 Sep 2021 11:52:16 +0800 Subject: [PATCH] Support fixed seed in Python for test (#36065) * Add New Op: gumbel_softmax * Add New Op: gumbel_softmax * Add New Op: gumbel_softmax (amend) * add __main__ function in unit test * fix bugs when test in windows ci * update en docs * delete reletive error in unit test * delete relative error in unit test * set hard=True in unit test * Support fix seed in Python for test --- paddle/fluid/operators/gumbel_softmax_op.cu | 2 +- paddle/fluid/operators/gumbel_softmax_op.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/operators/gumbel_softmax_op.cu b/paddle/fluid/operators/gumbel_softmax_op.cu index bf0ac667411..6b6290d4af2 100644 --- a/paddle/fluid/operators/gumbel_softmax_op.cu +++ b/paddle/fluid/operators/gumbel_softmax_op.cu @@ -130,7 +130,6 @@ struct GumbleNoiseGenerator { T* random_data = random_tensor.mutable_data({size}, platform::CUDAPlace()); thrust::counting_iterator index_sequence_begin(0); - const unsigned int seed = std::random_device()(); // generate gumbel noise int device_id = @@ -144,6 +143,7 @@ struct GumbleNoiseGenerator { thrust::device_ptr(random_data), UniformCUDAGenerator(0.00001, 1, seed_offset.first, gen_offset)); } else { + const unsigned int seed = std::random_device()(); thrust::transform(index_sequence_begin, index_sequence_begin + size, thrust::device_ptr(random_data), UniformCUDAGenerator(0.00001, 1, seed)); diff --git a/paddle/fluid/operators/gumbel_softmax_op.h b/paddle/fluid/operators/gumbel_softmax_op.h index c224cc7ca1d..f95a4810f44 100644 --- a/paddle/fluid/operators/gumbel_softmax_op.h +++ b/paddle/fluid/operators/gumbel_softmax_op.h @@ -86,8 +86,7 @@ struct GumbleNoiseGenerator { // generate uniform random number const int size = size_to_axis * size_from_axis; std::uniform_real_distribution dist(0.00001, 1); - const int seed = std::random_device()(); - auto engine = paddle::framework::GetCPURandomEngine(seed); + auto engine = paddle::framework::GetCPURandomEngine(0); Tensor random_tensor; auto* random_data = random_tensor.mutable_data({size}, platform::CPUPlace()); -- GitLab