auto switch mps device to cpu device

This commit is contained in:
Qing
2023-02-11 13:30:09 +08:00
parent f9b5dcbfd7
commit 8f8bcfe0f4
15 changed files with 52 additions and 19 deletions

View File

@@ -8,10 +8,18 @@ import cv2
from PIL import Image, ImageOps
import numpy as np
import torch
from lama_cleaner.const import MPS_SUPPORT_MODELS
from loguru import logger
from torch.hub import download_url_to_file, get_dir
def switch_mps_device(model_name, device):
if model_name not in MPS_SUPPORT_MODELS and (device == "mps" or device == torch.device('mps')):
logger.info(f"{model_name} not support mps, switch to cpu")
return torch.device('cpu')
return device
def get_cache_path_by_url(url):
parts = urlparse(url)
hub_dir = get_dir()