[release/2.13] [Bug Skip] test_philox_rand on XPU: CUDARngStateHelper has no XPU equivalent
@BBBela is already working on this.
Since May 5, 2026.
- 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:
- The XPU port re-routes
test_philox_randto the XPU device despite the upstream@onlyCUDAdecorator — likely becauseXPUPatchForImportneutralises@onlyCUDAso the test body is dispatched on XPU. - The test body is CUDA-specific by construction: it uses
CUDARngStateHelper, which gates ontorch.cuda.is_available(). There is no XPU equivalent ofCUDARngStateHelperexposed bytorch._prims_common.
This is therefore a coverage gap, not a numeric bug:
- Either the XPU port should keep the
@onlyCUDAdecorator 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
philoxon XPU as of 2026-04-25)
Versions
- pytorch: source build (HEAD)
- torch-xpu-ops: HEAD
- env: pytorch_opencode_env on PVC
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.