diff --git a/paddle/fluid/operators/class_center_sample_op.cu b/paddle/fluid/operators/class_center_sample_op.cu index cfcfd04e6fc7c2421ebe05ea2b29f8d7e0f3a915..c3f6460e018a9117b848b1fd1574938c35b65594 100644 --- a/paddle/fluid/operators/class_center_sample_op.cu +++ b/paddle/fluid/operators/class_center_sample_op.cu @@ -390,18 +390,26 @@ class ClassCenterSampleCUDAKernel : public framework::OpKernel { ctx.cuda_device_context().stream()))); // step 5: random sample negative class center + uint64_t seed_data; + uint64_t increment; int vec_size = VectorizedSize(cub_sort_keys_ptr); - int increment = ((num_classes - 1) / - (NumBlocks(num_classes) * kNumCUDAThreads * vec_size) + - 1) * - vec_size; - if (!fix_seed) { + auto offset = ((num_classes - 1) / + (NumBlocks(num_classes) * kNumCUDAThreads * vec_size) + + 1) * + vec_size; + auto gen_cuda = framework::GetDefaultCUDAGenerator(rank); + if (gen_cuda->GetIsInitPy() && (!fix_seed)) { + auto seed_offset = gen_cuda->IncrementOffset(offset); + seed_data = seed_offset.first; + increment = seed_offset.second; + } else { std::random_device rnd; - seed = rnd(); + seed_data = fix_seed ? seed + rank : rnd(); + increment = offset; } RandomSampleClassCenter<<>>( - num_classes, seed + rank, increment, num_classes, cub_sort_keys_ptr); + num_classes, seed_data, increment, num_classes, cub_sort_keys_ptr); // step 6: mark positive class center as negative value // fill the sort values to index 0, 1, ..., batch_size-1