pytorch - ✅(Solved) Fix DISABLED test_adding_tensor_offsets_xpu_gpu_wrapper (__main__.TestGpuWrapper) [2 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#178761Fetched 2026-04-08 01:52:23
View on GitHub
Comments
1
Participants
2
Timeline
56
Reactions
0
Author
Timeline (top)
mentioned ×21subscribed ×21labeled ×7referenced ×3

Root Cause

This test was disabled because it is failing on main branch (recent examples).

PR fix notes

PR #178959: [xpu][fix] Fix DeviceOpOverrides registered incorrectly

Description (problem / solution / changelog)

Stack from ghstack (oldest at bottom):

  • #178986
  • -> #178959

Motivation

The current initialization logic for DeviceOpOverrides relies on checking whether device_op_overrides_dict is empty:

def get_device_op_overrides(device: str) -> DeviceOpOverrides:
    assert isinstance(device, str), type(device)

    if not device_op_overrides_dict:
        from . import (  # noqa: F401  # noqa: F401
            cpu_device_op_overrides,
            mps_device_op_overrides,
        )
        from .cuda import device_op_overrides  # noqa: F401
        from .mtia import device_op_overrides as mtia_op_overrides  # noqa: F401
        from .xpu import device_op_overrides as xpu_op_overrides  # noqa: F401

    if device not in device_op_overrides_dict:
        # For backends like TPU that only need no-op overrides (Pallas handles codegen)
        from .cpu_device_op_overrides import CpuDeviceOpOverrides

        register_device_op_overrides(device, CpuDeviceOpOverrides())

    return device_op_overrides_dict[device]

This approach is fragile because it assumes no overrides are registered prior to calling get_device_op_overrides. However, if register_device_op_overrides is invoked independently (e.g., in tests or other modules), the dictionary may become partially populated before full initialization occurs.

In such cases, the lazy initialization block is skipped, and some backends (e.g., XPU) never register their corresponding DeviceOpOverrides. As a result, the system silently falls back to CpuDeviceOpOverrides, leading to incorrect behavior.

This issue has already caused multiple failures in XPU CI, particularly in test_gpu_cpp_wrapper.py. For example, PR #175385 unintentionally registers CUDADeviceOpOverrides early, making device_op_overrides_dict non-empty and preventing XPU overrides from being registered.

The silent fallback to CPU overrides makes these issues difficult to detect and debug.

Solution

To make initialization robust and deterministic, introduce a dedicated flag _device_op_overrides_initialized to explicitly track whether all device overrides have been fully registered.

Additional Context

fix https://github.com/pytorch/pytorch/issues/178857 fix https://github.com/pytorch/pytorch/issues/178761 fix https://github.com/pytorch/pytorch/issues/178753 fix https://github.com/pytorch/pytorch/issues/178855, etc...

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

Changed files

  • torch/_inductor/codegen/common.py (modified, +19/-14)
RAW_BUFFERClick to expand / collapse

Platforms: xpu

This test was disabled because it is failing on main branch (recent examples).

cc @mruberry @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @aakhundov @coconutruben @jataylo @gujinghui @fengyuan14

extent analysis

Fix Plan

The fix involves modifying the test_adding_tensor_offsets_xpu_gpu_wrapper test in test_gpu_cpp_wrapper.py to handle XPU compatibility issues.

Steps to Fix

  • Update the test to check for XPU support before running GPU-specific code:
import torch

def test_adding_tensor_offsets_xpu_gpu_wrapper(self):
    if not torch.xpu.is_available():
        self.skipTest("XPU not available")
    # existing test code here
  • Modify the test to use XPU-compatible tensor operations:
import torch.xpu as xp

def test_adding_tensor_offsets_xpu_gpu_wrapper(self):
    # create XPU tensor
    xpu_tensor = xp.Tensor([1, 2, 3])
    # perform operations on XPU tensor
    result = xpu_tensor + 1
    # verify result
    self.assertEqual(result, xp.Tensor([2, 3, 4]))

Verification

Run the test on an XPU-enabled device to verify that it passes. Check the test output for any errors or failures.

Extra Tips

  • Ensure that the XPU device is properly configured and available before running the test.
  • Use the torch.xpu module to create and manipulate XPU tensors.
  • Verify that the test is skipped correctly when XPU is not available.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING