Skip to content
Open
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
8 changes: 5 additions & 3 deletions demo_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ def __init__(self, model_id_or_path):
self.model.eval()

# Set device and precision
self.device = "cuda" if torch.cuda.is_available() else "cpu"
# Cuda -> MPS -> CPU
self.device = "cuda" if torch.cuda.is_available() else ("mps" if getattr(torch.backends, "mps", None) and torch.backends.mps.is_available() else "cpu")

self.model.to(self.device)
# Use float16 on CUDA, float32 on CPU
if self.device == "cuda":
# Use float16 on CUDA and MPS, float32 on CPU
if self.device == "cuda" or self.device == "mps":
self.model = self.model.half()
else:
self.model = self.model.float()
Expand Down