Skip to content

Fix randint uniformity for large ranges on XPU#3495

Open
Silv3S wants to merge 5 commits intointel:mainfrom
Silv3S:random_distrib
Open

Fix randint uniformity for large ranges on XPU#3495
Silv3S wants to merge 5 commits intointel:mainfrom
Silv3S:random_distrib

Conversation

@Silv3S
Copy link
Copy Markdown
Contributor

@Silv3S Silv3S commented Apr 27, 2026

Fixes #3473

XPU random_from_to_kernel was using threshold condition from fbcode path (switch to 64-bit RNG only when range >= 2³² for specific dtypes), instead of range >= 2²⁸. This patch changes it, to use the default threshold that matches upstream CUDA non-fbcode path.

Upstream covers both paths, but fbcode is skipped from ut: pytorch/pytorch#144819

Copilot AI review requested due to automatic review settings April 27, 2026 17:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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^32 condition to an unconditional range >= 2^28.
  • Route large-range generation through the uint64_t distribution path to reduce bias.

Comment thread src/ATen/native/xpu/sycl/DistributionTemplates.h
Comment thread src/ATen/native/xpu/sycl/DistributionTemplates.h
Copy link
Copy Markdown
Contributor

@guangyey guangyey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copilot AI review requested due to automatic review settings April 29, 2026 05:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_max near 0.75 * 2**32 and 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 {

Comment thread src/ATen/native/xpu/sycl/DistributionTemplates.h
@Silv3S Silv3S added the disable_e2e Disable all e2e test jobs for the PR label Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disable_e2e Disable all e2e test jobs for the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug Skip] test_randint_distribution on XPU: non-uniform distribution for large n_max

5 participants