Developer Tools

PyTorch introduces hardware classification for test filtering

New flag lets developers selectively run tests for CPU, CUDA, XPU, or MPS

Deep Dive

PyTorch has merged a new feature that brings hardware-aware test filtering to its testing framework. The `HardwareClassification` enum defines three tiers: GENERIC for platform-independent tests, DEVICE_GENERIC for accelerator-agnostic device tests, and specific types (CPU, CUDA, XPU, MPS). Tests annotate their class with a `hw_classification` attribute, and users pass `--hw-classification` to limit execution.

The system is fully integrated across all major execution paths: direct unittest, pytest, `run_test.py` forwarding, parallel execution, repeat mode, and XML output. The PR includes validation on `test/profiler/test_memory_profiler.py`, where 34 test methods are classified as 20 GENERIC + 14 DEVICE_GENERIC, and filters correctly select only matching tests. This allows developers to avoid running GPU-specific tests on CPU-only CI nodes or vice versa, streamlining continuous integration pipelines.

Key Points
  • HardwareClassification categories: GENERIC, DEVICE_GENERIC, and specific device types (CUDA, XPU, MPS)
  • Supports --hw-classification across unittest, pytest, parallel, repeat, XML, and run_test.py
  • Validated with 34 tests: combining GENERIC+DEVICE_GENERIC runs all, unmatched filters run 0

Why It Matters

Makes PyTorch CI faster by running only hardware-relevant tests, saving compute and developer time.

📬 Get the top 10 AI stories daily