Skip to content

Commit

Permalink
[cherry-pick]Support fixed seed in Python for test (#36065) (#36094)
Browse files Browse the repository at this point in the history
When users use gumbel_softmax, they can use paddle.seed() in python for fixed seed.
  • Loading branch information
YuanRisheng authored Sep 27, 2021
1 parent bc13ab9 commit c3a0eaa
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion paddle/fluid/operators/gumbel_softmax_op.cu
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ struct GumbleNoiseGenerator<platform::CUDADeviceContext, T> {
T* random_data =
random_tensor.mutable_data<T>({size}, platform::CUDAPlace());
thrust::counting_iterator<unsigned int> index_sequence_begin(0);
const unsigned int seed = std::random_device()();

// generate gumbel noise
int device_id =
Expand All @@ -144,6 +143,7 @@ struct GumbleNoiseGenerator<platform::CUDADeviceContext, T> {
thrust::device_ptr<T>(random_data),
UniformCUDAGenerator<T>(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<T>(random_data),
UniformCUDAGenerator<T>(0.00001, 1, seed));
Expand Down
3 changes: 1 addition & 2 deletions paddle/fluid/operators/gumbel_softmax_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ struct GumbleNoiseGenerator<platform::CPUDeviceContext, T> {
// generate uniform random number
const int size = size_to_axis * size_from_axis;
std::uniform_real_distribution<T> 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<T>({size}, platform::CPUPlace());
Expand Down

0 comments on commit c3a0eaa

Please sign in to comment.