Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/diffusers/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@

import torch

from packaging import version


global_rng = random.Random()
torch_device = "cuda" if torch.cuda.is_available() else "cpu"
torch_device = "mps" if torch.backends.mps.is_available() else torch_device
is_torch_higher_equal_than_1_12 = version.parse(version.parse(torch.__version__).base_version) >= version.parse("1.12")

if is_torch_higher_equal_than_1_12:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @pcuenca

We need to be careful when using features that are quite new in PyTorch. This would have broken PyTorch 1.11 here.
In the future we should run backwards compatible version tests starting from our oldest supported version. For now we need to be a bit careful when adding very new features to not break PyTorch 1.11

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I thought about asking when I first added the line but then forgot. Thanks for fixing it.

torch_device = "mps" if torch.backends.mps.is_available() else torch_device


def parse_flag_from_env(key, default=False):
Expand Down