diff --git a/paddle/fluid/operators/class_center_sample_op.cu b/paddle/fluid/operators/class_center_sample_op.cu index 29286be0dd6b2082586299765310c7428365a87a..f1ccbc913d9b18c580cd9066f5ffa28d187e7507 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