Skip to content

Commit 6c23854

Browse files
Fix OSX latent2rgb previews.
1 parent 7718ada commit 6c23854

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

comfy/model_management.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,14 @@ def supports_dtype(device, dtype): #TODO
630630
def device_supports_non_blocking(device):
631631
if is_device_mps(device):
632632
return False #pytorch bug? mps doesn't support non blocking
633+
return True
634+
635+
def device_should_use_non_blocking(device):
636+
if not device_supports_non_blocking(device):
637+
return False
633638
return False
634-
# return True #TODO: figure out why this causes issues
639+
# return True #TODO: figure out why this causes memory issues on Nvidia and possibly others
640+
635641

636642
def cast_to_device(tensor, device, dtype, copy=False):
637643
device_supports_cast = False
@@ -643,7 +649,7 @@ def cast_to_device(tensor, device, dtype, copy=False):
643649
elif is_intel_xpu():
644650
device_supports_cast = True
645651

646-
non_blocking = device_supports_non_blocking(device)
652+
non_blocking = device_should_use_non_blocking(device)
647653

648654
if device_supports_cast:
649655
if copy:

comfy/ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
def cast_bias_weight(s, input):
2323
bias = None
24-
non_blocking = comfy.model_management.device_supports_non_blocking(input.device)
24+
non_blocking = comfy.model_management.device_should_use_non_blocking(input.device)
2525
if s.bias is not None:
2626
bias = s.bias.to(device=input.device, dtype=input.dtype, non_blocking=non_blocking)
2727
if s.bias_function is not None:

latent_preview.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55
from comfy.cli_args import args, LatentPreviewMethod
66
from comfy.taesd.taesd import TAESD
7+
import comfy.model_management
78
import folder_paths
89
import comfy.utils
910
import logging
@@ -43,7 +44,7 @@ def decode_latent_to_preview(self, x0):
4344
latents_ubyte = (((latent_image + 1) / 2)
4445
.clamp(0, 1) # change scale from -1..1 to 0..1
4546
.mul(0xFF) # to 0..255
46-
).to(device="cpu", dtype=torch.uint8, non_blocking=True)
47+
).to(device="cpu", dtype=torch.uint8, non_blocking=comfy.model_management.device_supports_non_blocking(latent_image.device))
4748

4849
return Image.fromarray(latents_ubyte.numpy())
4950

0 commit comments

Comments
 (0)