Skip to content

Commit

Permalink
Disable non_blocking when --deterministic or directml.
Browse files Browse the repository at this point in the history
  • Loading branch information
comfyanonymous committed May 30, 2024
1 parent 71ec5b1 commit bf3e334
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions comfy/model_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,10 @@ def supports_dtype(device, dtype): #TODO
def device_supports_non_blocking(device):
if is_device_mps(device):
return False #pytorch bug? mps doesn't support non blocking
if args.deterministic: #TODO: figure out why deterministic breaks non blocking from gpu to cpu (previews)
return False
if directml_enabled:
return False
return True

def device_should_use_non_blocking(device):
Expand Down

3 comments on commit bf3e334

@KillyTheNetTerminal
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not working on RX580 Win11 the preview is still broken:
Error occurred when executing KSampler (Efficient):

Cannot handle this data type: (1, 1, 3),
k_callback = lambda x: callback(x["i"], x["denoised"], x["x"], total_steps)
File "C:\Users\WarMa\OneDrive\Escritorio\ComfyUI\ComfyUI\latent_preview.py", line 94, in callback
preview_bytes = previewer.decode_latent_to_preview_image(preview_format, x0)
File "C:\Users\WarMa\OneDrive\Escritorio\ComfyUI\ComfyUI\latent_preview.py", line 19, in decode_latent_to_preview_image
preview_image = self.decode_latent_to_preview(x0)
File "C:\Users\WarMa\OneDrive\Escritorio\ComfyUI\ComfyUI\latent_preview.py", line 48, in decode_latent_to_preview
return Image.fromarray(latents_ubyte.numpy())
File "C:\Users\WarMa\AppData\Local\Programs\Python\Python310\lib\site-packages\PIL\Image.py", line 3092, in fromarray
raise TypeError(msg) from e

@rabidcopy
Copy link

@rabidcopy rabidcopy commented on bf3e334 Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also confirm previews just don't work on DirectML. Though being more specific it starts from this change. 4ae1515 Can confirm previews still worked on DirectML with 0bdc2b1 and earlier.

@rabidcopy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to add that reverting these lines in latent_preview.py make previews functional again on DirectML. Just for anyone that wants to be on the latest commit while not sacrificing previews for the time being. (I know this probably helps not even a double digit number of people but just putting it out there.)

@@ -14,7 +14,7 @@ MAX_PREVIEW_RESOLUTION = 512
 def preview_to_image(latent_image):
         latents_ubyte = (((latent_image + 1.0) / 2.0).clamp(0, 1)  # change scale from -1..1 to 0..1
                             .mul(0xFF)  # to 0..255
-                            ).to(device="cpu", dtype=torch.uint8, non_blocking=comfy.model_management.device_supports_non_blocking(latent_image.device))
+                            .byte()).cpu()

         return Image.fromarray(latents_ubyte.numpy())

@@ -40,8 +40,7 @@ class Latent2RGBPreviewer(LatentPreviewer):
         self.latent_rgb_factors = torch.tensor(latent_rgb_factors, device="cpu")

     def decode_latent_to_preview(self, x0):
-        self.latent_rgb_factors = self.latent_rgb_factors.to(dtype=x0.dtype, device=x0.device)
-        latent_image = x0[0].permute(1, 2, 0) @ self.latent_rgb_factors
+        latent_image = x0[0].permute(1, 2, 0).cpu() @ self.latent_rgb_factors
         return preview_to_image(latent_image)

Please sign in to comment.