Summary
Convert test/optim/test_swa_utils.py from manual torch.cuda.is_available() guards to instantiate_device_type_tests so SWA utility tests run on all registered device backends (CPU, CUDA, MPS, OpenReg, XPU).
- Split
test_averaged_model_all_devicesintotest_averaged_model_same_device(device-generic) andtest_averaged_model_cross_device(@onlyAccelerator) - Gate
test_averaged_model_mixed_devicewith@onlyAccelerator, replace.cuda()with.to(device) - Refactor
_test_update_bnhelper: replacecudaboolean withdeviceparameter - Make
test_update_bn_dnn/test_update_bn_cnnacceptdevice, use.to(device)for model placement - Add
@onlyCPUto 4 tests that don't need multi-device coverage (state_dict, picklable, exponential, eval_momentum) - Add
instantiate_device_type_tests(TestSWAUtils, globals(), allow_mps=True)intest_optim.py
Test plan
- Full SWA test suite passed on CUDA: 25 passed, 11 skipped, 0 failed
test_averaged_model_same_deviceruns and passes on both CPU and CUDAtest_averaged_model_cross_deviceruns on CUDA, correctly skips on CPUtest_averaged_model_mixed_deviceruns on CUDA, correctly skips on CPUtest_update_bn_dnn/test_update_bn_cnnrun on both CPU and CUDA- CPU-only tests (
@onlyCPU) correctly skip on CUDA
Pull Request resolved: #183874
Approved by: https://github.com/fffrog, https://github.com/jbschlosser
SOCIAL SHARE CARD GENERATOR