Testing in PrivateUse1 and out of core backend has been quickly evolving and so I wanted to write down a quick update here on where we are today and where we expect to go short term.
See the new User Guide for details on what is happening here: Accelerator Integration — PyTorch 2.9 documentation
Generally we expect 2 types of tests here:
- Ensure all ops are properly implemented. By re-using OpInfo. Accessing the opinfo db from torch.testing._internal.common_methods_invocations. These can be used to validate that cpu vs accelerator return the same result for a broad range of input. Or more generally anything that requires running PyTorch Ops.
- Ensure PyTorch modules behave as expected via “device-generic” tests. For this, you can re-use the in-core test classes and run them in your CI. Very rough steps to do that are:
Add you device test base class and register it:
from torch.testing._internal.common_device_type import device_type_test_bases
from torch.testing._internal.common_device_type import DeviceTypeTestBase
class TestBaseYours(DeviceTypeTestBase):
# Some stuff
pass
device_type_test_bases.append(YourTestBase)
Import the module containing the test class you are migrating. This module should invoke instantiate_device_type_tests on the test class, generating your specific versions.
Expose the generated test classes to the current module’s globals in order for test discovery to find them. Set the module for the test classes to be the current module. This step depends a lot on how you run your test and how much discovery is needed.
import test_tensor_creation_ops
TestTensorCreationYours = test_tensor_creation_ops.TestTensorCreationYours
TestTensorCreationYours.__module__ = __name__
You can then skip/xfail there:
# cat empty fatally crashes, so skip it
TestTensorCreationYours.test_cat_empty_yours.__unittest_skip__ = True
# kaiser_window is expected to fail on Yours device
TestTensorCreationYours.test_kaiser_window_yours_float64.__unittest_expecting_failure__ = True
The run that file like your usual tests.
This is unfortunately not done yet. But a topic we are interested in talking more about.
OpenReg has been evolving quickly to be able to test things in core.
This is continuously growing to validate all extension point from in-core directly.
We also want to enable projects to be able to run test and provide feedback. This is under heavy discussion still, but the main phases we expect to see are:
- Early: you run CI at your preferred cadence on your repo (pinned to PyTorch release, only for changes in your repo for example)
- Ramping up: Start triggering your CI for new changes happening in core. In this world, commits in core would trigger your CI through webhook. You can use this to ensure your project keeps working with PyTorch nightly/trunk.
- Stabilizing: In this phase, you would be triggering and running on all trunk commits (including just before PR merge), with signal from the run being sent back to the core monitoring infrastructure. Being visible in https://hud.pytorch.org/. The goal is to capture metrics on job stability and coverage.
- Stable: Same as stabilizing but the job is blocking viable/strict (meaning it is also blocking for PRs merge/nightly/release)
The different criterion and requirements to move between these levels are still under discussion and we’ll refine them as we onboard more users here.