Skip to content

Reimplement dpnp.random.RandomState on the device RNG - #3162

Open
ndgrigorian wants to merge 1 commit into
feature/device-rng-bit-generatorsfrom
feature/device-rng-random-state
Open

ndgrigorian wants to merge 1 commit into
feature/device-rng-bit-generatorsfrom
feature/device-rng-random-state

Conversation

@ndgrigorian

@ndgrigorian ndgrigorian commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

This PR moves dpnp.random.RandomState and the dpnp.random module functions onto the device RNG, as part of the series splitting #3147. It is stacked on #3161

RandomState now delegates to the Generator samplers, with NumPy's legacy checks and error messages. Unlike Generator, it also checks parameters on the device, as CuPy does, which waits for the device. The module functions keep one RandomState per queue: the queue given by device/sycl_queue, or else that of the first dpnp.ndarray parameter, or else the default queue

Adds

  • get_state, set_state, get_bit_generator and set_bit_generator (per queue; seed reseeds in place)
  • A bit generator as the seed of RandomState

RandomState also receives changes

  • Values now match across devices, and differ from the legacy implementation's
  • device, usm_type and sycl_queue are keyword-only
  • randn no longer takes d0=
  • uniform no longer takes an integer dtype
  • randint(dtype=int) returns int64
  • shuffle requires a dpnp.ndarray

Also enables the CuPy random_tests the device RNG supports, with per-test skips for CuPy internals and the bit generators we don't provide, and drops the random entries of the skip lists. The ones in skipped_tests_cuda.tbl are dropped too, but haven't been run on CUDA

The legacy Cython module is still built but no longer used; #3163 removes it

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

RandomState and the module functions now delegate to the Generator
samplers, keeping NumPy's legacy checks and messages, also for
parameters on the device. The module keeps one RandomState per queue,
and adds get_state, set_state, get_bit_generator and set_bit_generator.

Enable the CuPy random tests the device RNG supports.
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-bit-generators branch from 3565820 to e06fd8c Compare November 4, 2026 19:50
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-random-state branch from 142a3d8 to 160719a Compare November 4, 2026 19:50
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.22.0dev0=np2py314h8d9cdd5_32 ran successfully.
Passed: 1491
Failed: 0
Skipped: 6

@coveralls

coveralls commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

Coverage is 78.153% — feature/device-rng-random-state into feature/device-rng-bit-generators. No base build found for feature/device-rng-bit-generators.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants