Fix randint uniformity for large ranges on XPU#3495
Open
Silv3S wants to merge 5 commits intointel:mainfrom
Open
Fix randint uniformity for large ranges on XPU#3495Silv3S wants to merge 5 commits intointel:mainfrom
Silv3S wants to merge 5 commits intointel:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates XPU random_from_to_kernel to switch to a 64-bit RNG path for large ranges at range >= 2^28, aligning behavior with upstream CUDA (non-fbcode) and addressing non-uniform randint distributions for large high values.
Changes:
- Change RNG-width selection threshold from a dtype-gated
range >= 2^32condition to an unconditionalrange >= 2^28. - Route large-range generation through the
uint64_tdistribution path to reduce bias.
kdrozd-dev
approved these changes
Apr 28, 2026
PawelSwider2000
approved these changes
Apr 28, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/ATen/native/xpu/sycl/DistributionTemplates.h:485
- This change alters the RNG path selection for
torch.randint/random_over large ranges, but there is no regression test in this repo that exercises the large-range uniformity case (e.g.n_maxnear0.75 * 2**32and checking histogram spread). Please add a targeted XPU test to prevent this from regressing again.
if (range >= 1ULL << 28) {
distribution_nullary_kernel<
scalar_t,
uint64_t,
rand4_engine_calls / 2>(
iter,
gen,
Rand4ULL2DistFunctor(),
UniformIntFromToTransformFunctor<scalar_t, uint64_t>(
range, base));
} else {
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3473
XPU
random_from_to_kernelwas using threshold condition fromfbcodepath (switch to 64-bit RNG only whenrange >= 2³²for specific dtypes), instead ofrange >= 2²⁸. This patch changes it, to use the default threshold that matches upstream CUDA non-fbcode path.Upstream covers both paths, but
fbcodeis skipped from ut: pytorch/pytorch#144819