SIGN IN SIGN UP

[Test] Make dynamo test_streams.py device-agnostic for out-of-tree backends (#185213)

Refactor `test/dynamo/test_streams.py` to use `instantiate_device_type_tests` with `@requires_accelerator` so stream and event tests automatically run on any registered accelerator backend.

## Changes

### Infrastructure
- Add `requires_accelerator` and `requires_xpu` to `common_utils.py` mirroring the existing `requires_cuda` named decorator
- Add `instantiate_device_type_tests` with `except_for=("cpu",)` so future accelerator backends are included automatically without editing this file
- Replace 56 per-method `@onlyAccelerator` decorators with a single `@requires_accelerator` at the `TestStreams` class level

### Test organization
- Create `TestStreamsGeneric` for 6 device-agnostic tests (side-effect registry checks, FakeTensorMode, FX graph tests) so they run on CPU-only machines
- Convert 58 tests from `@requires_cuda` to device-generic via `instantiate_device_type_tests`
- Replace `@unittest.skipUnless(TEST_XPU, "xpu only")` on `TestStreamsXPUSpecific` with `@requires_xpu`
- Remove unused `TEST_XPU` import

### Device-agnostic conversion
- Replace all hardcoded `device="cuda"` / `device="cuda:0"` with `device=device`
- Merge CUDA/XPU test pairs into single device-generic tests:
  - `test_cuda_stream_event_weakref_callback` + `test_xpu_stream_event_weakref_callback` → `test_backend_stream_event_weakref_callback`
  - `test_cuda_current_stream_with_entered_stream` + `test_xpu_current_stream_with_entered_stream` → `test_current_stream_with_entered_stream`
  - `test_cuda_event_record_on_stream` → `test_backend_event_record_on_stream`
- Use `torch.accelerator.current_stream().stream_id` instead of backend-specific `.cuda_stream` / `.sycl_queue`
- Add `skipTest` guards for backends without `torch.<backend>.Stream` / `torch.<backend>.Event`

**Test count: 82 → 83 passing** (1 new test from `TestStreamsGeneric` running on CPU; 2 additional XPU tests now properly collected and skipped when no XPU is present)

## Not Changed
- `test_stream_pointer_extraction_edge_cases` — deeply tied to `.cuda_stream` pointer values, `torch.cuda.default_stream()`, and `torch.cuda.stream()` context manager

Pull Request resolved: https://github.com/pytorch/pytorch/pull/185213
Approved by: https://github.com/mlazos
V
vishalgoyal316 committed
2b3ecd961bf3e20b7602bb137dc5a4012433a400
Parent: 6dedb93
Committed by PyTorch MergeBot <pytorchmergebot@users.noreply.github.com> on 8/25/2026, 8:05:34 AM