未验证 提交 c3a0eaab 编写于 作者: Y YuanRisheng 提交者: GitHub

[cherry-pick]Support fixed seed in Python for test (#36065) (#36094)

When users use gumbel_softmax, they can use paddle.seed() in python for fixed seed.
上级 bc13ab9e
......@@ -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 =
......@@ -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));
......
......@@ -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());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册