forked from Uminosachi/sd-webui-inpaint-anything
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ia_check_versions.py
76 lines (59 loc) · 2.24 KB
/
ia_check_versions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
from importlib.util import find_spec
import torch
from modules import paths, sd_samplers_common
from packaging.version import parse
try:
from functools import cached_property
from importlib.metadata import version
except Exception:
from pkg_resources import get_distribution
def version(module_name): return get_distribution(module_name).version
cached_property = property
def get_module_version(module_name):
try:
module_version = version(module_name)
except Exception:
module_version = None
return module_version
def compare_version(version1, version2):
if not isinstance(version1, str) or not isinstance(version2, str):
return None
if parse(version1) > parse(version2):
return 1
elif parse(version1) < parse(version2):
return -1
else:
return 0
def compare_module_version(module_name, version_string):
module_version = get_module_version(module_name)
result = compare_version(module_version, version_string)
return result if result is not None else -2
class IACheckVersions:
@cached_property
def diffusers_enable_cpu_offload(self):
if (find_spec("diffusers") is not None and compare_module_version("diffusers", "0.15.0") >= 0 and
find_spec("accelerate") is not None and compare_module_version("accelerate", "0.17.0") >= 0):
return True
else:
return False
@cached_property
def torch_mps_is_available(self):
if compare_module_version("torch", "2.0.1") < 0:
if not getattr(torch, "has_mps", False):
return False
try:
torch.zeros(1).to(torch.device("mps"))
return True
except Exception:
return False
else:
return torch.backends.mps.is_available() and torch.backends.mps.is_built()
@cached_property
def webui_refiner_is_available(self):
basedir = os.path.join(paths.script_path, "modules", "processing_scripts")
refiner_script = os.path.join(basedir, "refiner.py")
if os.path.isfile(refiner_script) and hasattr(sd_samplers_common, "apply_refiner"):
return True
return False
ia_check_versions = IACheckVersions()