Update custom-hires-fix-mod-for-automatic1111-2.9/scripts/custom_hires_fix.py
Browse files
custom-hires-fix-mod-for-automatic1111-2.9/scripts/custom_hires_fix.py
CHANGED
|
@@ -135,6 +135,17 @@ config_path = (Path(__file__).parent.resolve() / "../config.yaml").resolve()
|
|
| 135 |
|
| 136 |
|
| 137 |
class CustomHiresFix(scripts.Script):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
def _interp(self, *args, _default_mode: str = "bicubic", **kwargs):
|
| 139 |
"""Config-driven interpolate with runtime fallbacks."""
|
| 140 |
import torch.nn.functional as F
|
|
@@ -142,8 +153,16 @@ class CustomHiresFix(scripts.Script):
|
|
| 142 |
label = str(self.config.get("latent_resample_mode", _default_mode))
|
| 143 |
mode, antialias = self._parse_interpolate_mode(label)
|
| 144 |
kwargs["mode"] = mode
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
try:
|
| 148 |
return F.interpolate(*args, **kwargs)
|
| 149 |
except Exception as e:
|
|
|
|
| 135 |
|
| 136 |
|
| 137 |
class CustomHiresFix(scripts.Script):
|
| 138 |
+
def _get_free_vram_bytes(self):
|
| 139 |
+
"""Return free VRAM bytes if available; else None."""
|
| 140 |
+
try:
|
| 141 |
+
import torch
|
| 142 |
+
if torch.cuda.is_available():
|
| 143 |
+
free, total = torch.cuda.mem_get_info()
|
| 144 |
+
return int(free)
|
| 145 |
+
except Exception:
|
| 146 |
+
pass
|
| 147 |
+
return None
|
| 148 |
+
|
| 149 |
def _interp(self, *args, _default_mode: str = "bicubic", **kwargs):
|
| 150 |
"""Config-driven interpolate with runtime fallbacks."""
|
| 151 |
import torch.nn.functional as F
|
|
|
|
| 153 |
label = str(self.config.get("latent_resample_mode", _default_mode))
|
| 154 |
mode, antialias = self._parse_interpolate_mode(label)
|
| 155 |
kwargs["mode"] = mode
|
| 156 |
+
# Set align_corners only for linear/bilinear/bicubic/trilinear families
|
| 157 |
+
if mode in {"linear", "bilinear", "bicubic", "trilinear"}:
|
| 158 |
+
kwargs.setdefault("align_corners", False)
|
| 159 |
+
else:
|
| 160 |
+
kwargs.pop("align_corners", None)
|
| 161 |
+
# antialias valid only for linear/bilinear/bicubic/trilinear
|
| 162 |
+
if mode in {"linear", "bilinear", "bicubic", "trilinear"}:
|
| 163 |
+
kwargs["antialias"] = antialias
|
| 164 |
+
else:
|
| 165 |
+
kwargs.pop("antialias", None)
|
| 166 |
try:
|
| 167 |
return F.interpolate(*args, **kwargs)
|
| 168 |
except Exception as e:
|