Skip to content

[Contributor Experience] Test Collection fails on MPS #6807

@UmerHA

Description

@UmerHA

Describe the bug

On MPS, the test collection fails. Therefore not all tests are shown e.g. in VS Code, which makes the contributor experience more tedious.

Currently, 4515-4486 = 29 tests are missed.


The error is caused because in utls/testing_utils.py the variable torch_device is defined as a string ("cpu", "cuda" or "mps"), but used as a device (i.e., torch_device.type is called).

I'll submit a small fix PR.

Reproduction

pytest --collect-only tests

Logs

============================================================================ ERRORS ============================================================================
______________________________________________________ ERROR collecting tests/models/test_layers_utils.py ______________________________________________________
src/diffusers/utils/testing_utils.py:862: in _is_torch_fp64_available
    x = torch.zeros((2, 2), dtype=torch.float64).to(device)
E   TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead.

During handling of the above exception, another exception occurred:
tests/models/test_layers_utils.py:319: in <module>
    class Transformer2DModelTests(unittest.TestCase):
tests/models/test_layers_utils.py:430: in Transformer2DModelTests
    @require_torch_accelerator_with_fp64
src/diffusers/utils/testing_utils.py:241: in require_torch_accelerator_with_fp64
    return unittest.skipUnless(_is_torch_fp64_available(torch_device), "test requires accelerator with fp64 support")(
src/diffusers/utils/testing_utils.py:867: in _is_torch_fp64_available
    if device.type == "cuda":
E   AttributeError: 'str' object has no attribute 'type'

System Info

  • diffusers version: 0.26.0.dev0
  • Platform: macOS-14.2.1-arm64-arm-64bit
  • Python version: 3.11.7
  • PyTorch version (GPU?): 2.1.2 (False)
  • Huggingface_hub version: 0.20.2
  • Transformers version: 4.36.2
  • Accelerate version: 0.26.1
  • xFormers version: not installed
  • Using GPU in script?: no
  • Using distributed or parallel set-up in script?: no

Who can help?

Questions on Tests: @DN6 @sayakpaul

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions