Skip to content

Commit 4c24347

Browse files
brkirchAUTOMATIC1111
authored andcommitted
Remove BSRGAN from --use-cpu, add SwinIR
1 parent f53ca51 commit 4c24347

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

modules/devices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def enable_tf32():
4545

4646
errors.run(enable_tf32, "Enabling TF32")
4747

48-
device = device_interrogate = device_gfpgan = device_bsrgan = device_esrgan = device_scunet = device_codeformer = None
48+
device = device_interrogate = device_gfpgan = device_swinir = device_esrgan = device_scunet = device_codeformer = None
4949
dtype = torch.float16
5050
dtype_vae = torch.float16
5151

modules/shared.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
parser.add_argument("--opt-split-attention-invokeai", action='store_true', help="force-enables InvokeAI's cross-attention layer optimization. By default, it's on when cuda is unavailable.")
5959
parser.add_argument("--opt-split-attention-v1", action='store_true', help="enable older version of split attention optimization that does not consume all the VRAM it can find")
6060
parser.add_argument("--disable-opt-split-attention", action='store_true', help="force-disables cross-attention layer optimization")
61-
parser.add_argument("--use-cpu", nargs='+',choices=['all', 'sd', 'interrogate', 'gfpgan', 'bsrgan', 'esrgan', 'scunet', 'codeformer'], help="use CPU as torch device for specified modules", default=[], type=str.lower)
61+
parser.add_argument("--use-cpu", nargs='+',choices=['all', 'sd', 'interrogate', 'gfpgan', 'swinir', 'esrgan', 'scunet', 'codeformer'], help="use CPU as torch device for specified modules", default=[], type=str.lower)
6262
parser.add_argument("--listen", action='store_true', help="launch gradio with 0.0.0.0 as server name, allowing to respond to network requests")
6363
parser.add_argument("--port", type=int, help="launch gradio with given server port, you need root/admin rights for ports < 1024, defaults to 7860 if available", default=None)
6464
parser.add_argument("--show-negative-prompt", action='store_true', help="does not do anything", default=False)
@@ -96,8 +96,8 @@
9696
"outdir_save",
9797
]
9898

99-
devices.device, devices.device_interrogate, devices.device_gfpgan, devices.device_bsrgan, devices.device_esrgan, devices.device_scunet, devices.device_codeformer = \
100-
(devices.cpu if any(y in cmd_opts.use_cpu for y in [x, 'all']) else devices.get_optimal_device() for x in ['sd', 'interrogate', 'gfpgan', 'bsrgan', 'esrgan', 'scunet', 'codeformer'])
99+
devices.device, devices.device_interrogate, devices.device_gfpgan, devices.device_swinir, devices.device_esrgan, devices.device_scunet, devices.device_codeformer = \
100+
(devices.cpu if any(y in cmd_opts.use_cpu for y in [x, 'all']) else devices.get_optimal_device() for x in ['sd', 'interrogate', 'gfpgan', 'swinir', 'esrgan', 'scunet', 'codeformer'])
101101

102102
device = devices.device
103103
weight_load_location = None if cmd_opts.lowram else "cpu"

modules/swinir_model.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from basicsr.utils.download_util import load_file_from_url
88
from tqdm import tqdm
99

10-
from modules import modelloader
11-
from modules.shared import cmd_opts, opts, device
10+
from modules import modelloader, devices
11+
from modules.shared import cmd_opts, opts
1212
from modules.swinir_model_arch import SwinIR as net
1313
from modules.swinir_model_arch_v2 import Swin2SR as net2
1414
from modules.upscaler import Upscaler, UpscalerData
@@ -42,7 +42,7 @@ def do_upscale(self, img, model_file):
4242
model = self.load_model(model_file)
4343
if model is None:
4444
return img
45-
model = model.to(device)
45+
model = model.to(devices.device_swinir)
4646
img = upscale(img, model)
4747
try:
4848
torch.cuda.empty_cache()
@@ -111,7 +111,7 @@ def upscale(
111111
img = img[:, :, ::-1]
112112
img = np.moveaxis(img, 2, 0) / 255
113113
img = torch.from_numpy(img).float()
114-
img = img.unsqueeze(0).to(device)
114+
img = img.unsqueeze(0).to(devices.device_swinir)
115115
with torch.no_grad(), precision_scope("cuda"):
116116
_, _, h_old, w_old = img.size()
117117
h_pad = (h_old // window_size + 1) * window_size - h_old
@@ -139,8 +139,8 @@ def inference(img, model, tile, tile_overlap, window_size, scale):
139139
stride = tile - tile_overlap
140140
h_idx_list = list(range(0, h - tile, stride)) + [h - tile]
141141
w_idx_list = list(range(0, w - tile, stride)) + [w - tile]
142-
E = torch.zeros(b, c, h * sf, w * sf, dtype=torch.half, device=device).type_as(img)
143-
W = torch.zeros_like(E, dtype=torch.half, device=device)
142+
E = torch.zeros(b, c, h * sf, w * sf, dtype=torch.half, device=devices.device_swinir).type_as(img)
143+
W = torch.zeros_like(E, dtype=torch.half, device=devices.device_swinir)
144144

145145
with tqdm(total=len(h_idx_list) * len(w_idx_list), desc="SwinIR tiles") as pbar:
146146
for h_idx in h_idx_list:

0 commit comments

Comments
 (0)