Repository: huggingface/diffusers
File: tests/testing_utils.py (Python)

Code before:

def require_torch_gpu(test_case):
    """Decorator marking a test that requires CUDA and PyTorch."""
    return pytest.mark.skipif(
        not (is_torch_available() and torch_device == "cuda"), reason="test requires PyTorch+CUDA"
    )(test_case)


def require_torch_cuda_compatibility(expected_compute_capability):
    def decorator(test_case):
        if torch.cuda.is_available():
            current_compute_capability = get_torch_cuda_device_capability()
            return pytest.mark.skipif(
                float(current_compute_capability) != float(expected_compute_capability),
                reason="Test not supported for this compute capability.",
            )(test_case)
        return test_case

    return decorator


# These decorators are for accelerator-specific behaviours that are not GPU-specific
def require_torch_accelerator(test_case):
    """Decorator marking a test that requires an accelerator backend and PyTorch."""
    return pytest.mark.skipif(
        not (is_torch_available() and torch_device != "cpu"), reason="test requires accelerator+PyTorch"
    )(test_case)


def require_torch_multi_gpu(test_case):
    """
    Decorator marking a test that requires a multi-GPU setup (in PyTorch). These tests are skipped on a machine without
    multiple GPUs. To run *only* the multi_gpu tests, assuming all test names contain multi_gpu: $ pytest -sv ./tests
    -k "multi_gpu"
    """
    if not is_torch_available():
        return pytest.mark.skip(reason="test requires PyTorch")(test_case)

    import torch

    return pytest.mark.skipif(torch.cuda.device_count() <= 1, reason="test requires multiple GPUs")(test_case)


def require_torch_multi_accelerator(test_case):
    """
    Decorator marking a test that requires a multi-accelerator setup (in PyTorch). These tests are skipped on a machine
    without multiple hardware accelerators.
    """
    if not is_torch_available():
        return pytest.mark.skip(reason="test requires PyTorch")(test_case)


Review comment (bug):
* Simpler (as `torch_device` will fail anyway so we won't need the first check)
* Easier to ready

```suggestion
        torch_device == "cpu", reason="test requires accelerator+PyTorch"
```

Code after:

def require_torch_gpu(test_case):
    """Decorator marking a test that requires CUDA and PyTorch."""
    return pytest.mark.skipif(torch_device != "cuda", reason="test requires PyTorch+CUDA")(test_case)


def require_torch_cuda_compatibility(expected_compute_capability):
    def decorator(test_case):
        if torch.cuda.is_available():
            current_compute_capability = get_torch_cuda_device_capability()
            return pytest.mark.skipif(
                float(current_compute_capability) != float(expected_compute_capability),
                reason="Test not supported for this compute capability.",
            )(test_case)
        return test_case

    return decorator


# These decorators are for accelerator-specific behaviours that are not GPU-specific
def require_torch_accelerator(test_case):
    """Decorator marking a test that requires an accelerator backend and PyTorch."""
    return pytest.mark.skipif(torch_device == "cpu", reason="test requires accelerator+PyTorch")(test_case)


def require_torch_multi_gpu(test_case):
    """
    Decorator marking a test that requires a multi-GPU setup (in PyTorch). These tests are skipped on a machine without
    multiple GPUs. To run *only* the multi_gpu tests, assuming all test names contain multi_gpu: $ pytest -sv ./tests
    -k "multi_gpu"
    """
    if not is_torch_available():
        return pytest.mark.skip(reason="test requires PyTorch")(test_case)

    import torch

    return pytest.mark.skipif(torch.cuda.device_count() <= 1, reason="test requires multiple GPUs")(test_case)


def require_torch_multi_accelerator(test_case):
    """
    Decorator marking a test that requires a multi-accelerator setup (in PyTorch). These tests are skipped on a machine
    without multiple hardware accelerators.
    """
    if not is_torch_available():
        return pytest.mark.skip(reason="test requires PyTorch")(test_case)

    import torch

    return pytest.mark.skipif(
        not (torch.cuda.device_count() > 1 or torch.xpu.device_count() > 1),