intel / intel/torch-xpu-ops

[release/2.13] [Bug Skip] test_philox_rand on XPU: CUDARngStateHelper has no XPU equivalent

Open
#3,472 5 comments 0 reactions 1 assignee View on GitHub

@BBBela is already working on this.

Since May 5, 2026.

skipped test: ut
Dominant language
Python
Stars
113
Forks
129
Avg merge
5d 9h
Merged PRs (30d)
112

Description

Bug Description

test_prims.test_philox_rand is collected for the XPU device via test_prims_xpu.py but fails because the test body unconditionally calls CUDARngStateHelper.get_torch_state_as_tuple(), which raises RuntimeError: CUDA not available on XPU-only machines. The upstream test is decorated @onlyCUDA, but the XPU port file (or the XPUPatchForImport pre-import shim) re-routes it to XPU and the body itself remains CUDA-hardcoded.

Affected Tests

Cases:
op_ut,third_party.torch-xpu-ops.test.xpu.test_prims_xpu.TestPrimsXPU,test_philox_rand_xpu_float32

Error Message

RuntimeError: CUDA not available

Test Code Snippet

# pytorch/test/test_prims.py:281-310 (test_philox_rand)
@onlyCUDA
@dtypes(torch.float32)
def test_philox_rand(self, device, dtype):
    sizes = (1000, 1000000)
    repeats = 2
    for size in sizes:
        torch.cuda.manual_seed(123)
        references = []
        results = []
        rng_states = []
        for _ in range(repeats):
            rng_states.append(CUDARngStateHelper.get_torch_state_as_tuple())  # FAILS here on XPU
            ...
# pytorch/torch/_prims_common/__init__.py: CUDARngStateHelper.get_torch_state_as_tuple
@staticmethod
def get_torch_state_as_tuple(fake_mode=nullcontext()):
    if not torch.cuda.is_available():
        raise RuntimeError("CUDA not available")
    ...

Traceback

pytest_command:
cd ~/daisy_pytorch/third_party/torch-xpu-ops/test/xpu
pytest -v test_prims_xpu.py -k test_philox_rand_xpu_float32

Traceback (most recent call last):
  File ".../test/test_prims.py", line 286, in test_philox_rand
    rng_states.append(CUDARngStateHelper.get_torch_state_as_tuple())
  File ".../torch/_prims_common/__init__.py", line 2198, in get_torch_state_as_tuple
    raise RuntimeError("CUDA not available")
RuntimeError: CUDA not available

Root Cause Analysis

Two factors combine:

  1. The XPU port re-routes test_philox_rand to the XPU device despite the upstream @onlyCUDA decorator — likely because XPUPatchForImport neutralises @onlyCUDA so the test body is dispatched on XPU.
  2. The test body is CUDA-specific by construction: it uses CUDARngStateHelper, which gates on torch.cuda.is_available(). There is no XPU equivalent of CUDARngStateHelper exposed by torch._prims_common.

This is therefore a coverage gap, not a numeric bug:

  • Either the XPU port should keep the @onlyCUDA decorator effective and skip the test on XPU, or
  • An XPU equivalent of CUDARngStateHelper.get_torch_state_as_tuple() (e.g. XPURngStateHelper) should be added so the test can be ported faithfully and exercise XPU's philox RNG path.

Related Intel/torch-xpu-ops Issues

  • (none found for philox on XPU as of 2026-04-25)

Versions

  • pytorch: source build (HEAD)
  • torch-xpu-ops: HEAD
  • env: pytorch_opencode_env on PVC

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.