Developer Tools

PyTorch refactors test_utils.py for device-agnostic GPU testing

New class enables checkpoint tests on any accelerator, not just CUDA or XPU.

Deep Dive

PyTorch has merged a critical infrastructure update in commit `ciflow/trunk/184326`, refactoring `test_utils.py` to be device-agnostic for out-of-tree backends. The primary change introduces a new `TestCheckpointDeviceType` class that uses `instantiate_device_type_tests` to run checkpoint GPU tests across all accelerator backends—not just CUDA or XPU. Five previously GPU-guarded tests from the `TestCheckpoint` class have been migrated into this new device-type class, decorated with `@onlyAccelerator` and `@deviceCountAtLeast(2)`. Only `test_checkpointing_without_reentrant_early_free` remains in `TestCheckpoint`, guarded by `torch.accelerator.is_available()` due to TLS threading issues with backward hooks.

Additionally, `TestDeviceUtils.test_get_default_device_more` was refactored to use `@onlyAccelerator` + `@deviceCountAtLeast(2)` instead of the former CUDA-specific `TEST_MULTIGPU` guard. All CUDA-specific imports (`torch.cuda`, `TEST_MULTIGPU` from `common_cuda`) and module-level `device_type`/`TEST_GPU` variables have been removed. This commit lays groundwork for seamless integration of new GPU backends (e.g., AMD ROCm, Intel XPU, custom accelerators) into PyTorch's test suite without per-backend hacks.

Key Points
  • Introduced TestCheckpointDeviceType class with instantiate_device_type_tests for accelerator-agnostic checkpoint testing
  • Moved 5 GPU-guarded tests using @onlyAccelerator and @deviceCountAtLeast(2) decorators
  • Removed all CUDA-specific imports (torch.cuda, TEST_MULTIGPU) and module-level device variables

Why It Matters

Streamlines multi-backend GPU testing in PyTorch, reducing friction for hardware vendors and enabling faster adoption.

📬 Get the top 10 AI stories daily