pytorch - ✅(Solved) Fix Add custom precision or tolerance support for out of tree backends [1 pull requests, 6 comments, 3 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#177968Fetched 2026-04-08 01:07:50
View on GitHub
Comments
6
Participants
3
Timeline
27
Reactions
0
Author
Timeline (top)
commented ×6labeled ×5mentioned ×5subscribed ×5

Fix Action

Fixed

PR fix notes

PR #178311: [OpenReg] Add bypass_only_on flag to DeviceTypeTestBase

Description (problem / solution / changelog)

Walkthrough Out-Of-Tree Backend Support: bypass_only_on

This PR implements the bypass_only_on flag for DeviceTypeTestBase, allowing out-of-tree backends to bypass restrictive device specific test decorators such as @onlyCUDA and @onlyNativeDeviceTypes. This aligns with the recent PyTorch Test Refactoring RFC to improve testing infrastructure for external custom hardware backends.

Changes:

  • torch/testing/_internal/common_device_type.py:

    • Added bypass_only_on: bool = False to DeviceTypeTestBase.
    • Updated onlyOn, onlyNativeDeviceTypes, onlyNativeDeviceTypesAnd, and onlyCUDAAndPRIVATEUSE1 to check for the bypass_only_on flag on the test instance.
    • When enabled, these decorators short-circuit and allow the test to run regardless of the current device type.
  • test/test_testing.py:

    • Added TestBypassOnlyOnDisabled and TestBypassOnlyOnEnabled to verify the bypass functionality.
    • TestBypassOnlyOnEnabled serves as the bypass control, while TestBypassOnlyOnDisabled demonstrates the default skipping behavior.

Verification Results:

  • Integrated new tests into the main test suite: TestBypassOnlyOnDisabled and TestBypassOnlyOnEnabled.
  • Total tests run: 4 (2 methods × 2 classes: bypass disabled and bypass enabled).
  • Verified that @onlyCUDA tests run on CPU when bypass_only_on = True is set on the test class.

Resolves #177968 cc @fffrog @mikaylagawarecki

Changed files

  • test/test_testing.py (modified, +20/-2)
  • torch/testing/_internal/common_device_type.py (modified, +9/-0)
RAW_BUFFERClick to expand / collapse

For out of tree backends, due to the diverse chip designs, it's difficult to require all vendors' chips to have the same operator precision or tolerance.

While on-tree backends can directly add the @precisionOverride decorator in certain specific test cases, out of tree backends require additional mechanisms similar to those mentioned in this PR to allow them to customize precision or tolerance.

cc @mruberry @bdhirsh @mikaylagawarecki

extent analysis

Fix Plan

To address the issue of out-of-tree backends requiring customization of precision or tolerance, we can implement a mechanism similar to the @precisionOverride decorator used in on-tree backends.

Steps to Implement the Fix

  • Create a new decorator, e.g., @outOfTreePrecisionOverride, that allows out-of-tree backends to specify custom precision or tolerance.
  • Modify the test framework to recognize and apply the new decorator.
  • Provide documentation and examples for out-of-tree backend vendors to use the new decorator.

Example Code

import functools

def outOfTreePrecisionOverride(precision):
    def decorator(test_func):
        @functools.wraps(test_func)
        def wrapper(*args, **kwargs):
            # Apply custom precision or tolerance
            original_precision = get_current_precision()
            set_precision(precision)
            try:
                return test_func(*args, **kwargs)
            finally:
                set_precision(original_precision)
        return wrapper
    return decorator

# Example usage:
@outOfTreePrecisionOverride(0.01)
def test_custom_precision():
    # Test code here
    pass

Verification

To verify the fix, out-of-tree backend vendors can apply the new decorator to their test cases and verify that the custom precision or tolerance is correctly applied.

Extra Tips

  • Ensure that the new decorator is properly documented and communicated to out-of-tree backend vendors.
  • Consider adding additional logging or debugging mechanisms to help vendors troubleshoot issues related to precision or tolerance.

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