-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot handle this data type: (1, 1, 3), <f4 #3539
Cannot handle this data type: (1, 1, 3), <f4 #3539
Comments
After investigating a little the file latent_preview.py, function decode_latent_to_preview, which was modified a few days ago, the values are transformed into [0.0, 255.0], but the dtype stays torch.float32 instead of becoming torch.uint8. For some reason the "to" method doesn't do the type change unless you do it alone like this: latents_ubyte = (((latent_image + 1) / 2)
.clamp(0, 1) # change scale from -1..1 to 0..1
.mul(0xFF) # to 0..255
)
latents_ubyte = latents_ubyte.to(dtype=torch.uint8)
latents_ubyte = latents_ubyte.to(device="cpu", dtype=torch.uint8, non_blocking=True) Not sure if it doesn't beat the purpose though. Hope it helps. |
The OS fix doesn't work for my windows 11 + AMD CPU + AMD GPU. |
@Maveyyl Thanks for the latents_ubyte = (((latent_image + 1) / 2)
.clamp(0, 1) # change scale from -1..1 to 0..1
.mul(0xFF) # to 0..255
)
latents_ubyte = latents_ubyte.to(dtype=torch.uint8)
latents_ubyte = latents_ubyte.to(device="cpu", dtype=torch.uint8, non_blocking=comfy.model_management.device_supports_non_blocking(latent_image.device)) and it's working perfectly. I'm not sure why though maybe this issue is AMD specific, but I hope this helps for others.
|
I could almost guarantee that AMD devices don't support non-blocking anything on Windows (especially not with DirectML). |
If that's the case the right fix is adding a:
Here: https://github.com/comfyanonymous/ComfyUI/blob/master/comfy/model_management.py#L630 |
Can confirm this is working on my Radeon 6600XT |
After trying all of the suggested solutions, the only thing that worked was redownload and replace the |
Having same Issue, I'm using Stability Matrix with ComfyUI. It used to work but I removed a few weeks ago and decide to try again. CPU: AMD Ryzen 5 5600 and GPU: AMD Radeon RX 6700XT. ERRORS: G:\SD\StabilityMatrix\Data\Packages\ComfyUI\venv\lib\site-packages\torch_dynamo\external_utils.py:17: UserWarning: Set seed for The above exception was the direct cause of the following exception: Traceback (most recent call last): |
Try changing your def preview_to_image(latent_image):
latents_ubyte = (((latent_image + 1) / 2)
.clamp(0, 1) # change scale from -1..1 to 0..1
.mul(0xFF) # to 0..255
)
latents_ubyte = latents_ubyte.to(dtype=torch.uint8)
latents_ubyte = latents_ubyte.to(device="cpu", dtype=torch.uint8, non_blocking=comfy.model_management.device_supports_non_blocking(latent_image.device))
return Image.fromarray(latents_ubyte.numpy()) |
I initially got the cannot handle data type error, and the fix above, updating the preview_to_image method in latent_preview.py got me passed that, but now I'm getting blank output. Ryzne 7950x3d/Radeon 7900xtx |
Sounds like a NaN issue or something else is going on. Can you share a screenshot? I get blank images from time to time which is almost always a driver issue. You can try to reset your GPU with this python script. You must run Python in an administrator window. import subprocess
def restart_gpu_driver():
# Define the command to get the Instance ID of the GPU device
command = 'powershell "Get-PnpDevice | Where-Object { ($_.Class -eq \'Display\' ) -and ($_.Status -eq \'OK\')} | Select-Object -ExpandProperty InstanceId"'
try:
# Get Instance ID and strip any extra whitespace or newline characters
instanceID = subprocess.check_output(command, shell=True, text=True).strip()
print("Running on the selected GPU: " + instanceID)
# Define the commands to disable and enable the GPU device
disable_command = f'powershell "Disable-PnpDevice -InstanceId \'{instanceID}\' -Confirm:$false"'
enable_command = f'powershell "Enable-PnpDevice -InstanceId \'{instanceID}\' -Confirm:$false"'
# Disable the GPU device
subprocess.run(disable_command, shell=True, check=True)
print("GPU disabled successfully.")
# Enable the GPU device
subprocess.run(enable_command, shell=True, check=True)
print("GPU enabled successfully.")
except subprocess.CalledProcessError as e:
print(f"An error occurred: {e}")
# Call the function to restart the GPU driver
restart_gpu_driver() your screen will flash. This script usually fixes any NaN issues I have with my 6600xt. |
this ones helped in addition with fix in latent_preview.py (probalby even not needed) |
Forcing uint8 was for AMD devices, specifically |
It goes away if preview disabled via manager, suggestions above didn't work for me (RX570 8gb VRAM, 32gb RAM --directml) |
@dnswd Thanks! I tried your and it working, my GPU is AMD rx580
|
@dnswd |
Hello I am also having a quite similar issue, but
I'm having a quite similar issue, but somehow it did not work for me! My system:
=============================================================== ComfyUI Error ReportError Details
Stack Trace
System Information
Devices
Logs
Attached WorkflowPlease make sure that workflow does not contain any sensitive information such as API keys or passwords.
Additional Context(Please add any additional context or steps to reproduce the error here) ================================================================================== Any ideas of what I can do to fix this? |
it's the same issue as before. Line 14 in cc9cf6d
Change the def preview_to_image(latent_image):
latents_ubyte = (((latent_image + 1) / 2)
.clamp(0, 1) # change scale from -1..1 to 0..1
.mul(0xFF) # to 0..255
)
latents_ubyte = latents_ubyte.to(dtype=torch.uint8)
latents_ubyte = latents_ubyte.to(device="cpu", dtype=torch.uint8, non_blocking=comfy.model_management.device_supports_non_blocking(latent_image.device))
return Image.fromarray(latents_ubyte.numpy()) For some reason our AMD gpus don't like the way it's coded. Converting it to an 8-bit unsigned int before dumping it on the CPU (if necessary) fixes it. Make sure you have the latest version of ComfyUI before editing the code. |
This one finally worked for me too! |
Had perfectly working old install of Comfy UI. But naively pressed - Update ALL. |
Totally agree... |
Hi,
After 2 days without using, I updated comfyUI and now I get this error when I try to sample anything, seemingly happens when it tries to show a preview:
!!! Exception during processing!!! Cannot handle this data type: (1, 1, 3), <f4
Traceback (most recent call last):
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\venv\lib\site-packages\PIL\Image.py", line 3130, in fromarray
mode, rawmode = _fromarray_typemap[typekey]
KeyError: ((1, 1, 3), '<f4')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\execution.py", line 151, in recursive_execute
output_data, output_ui = get_output_data(obj, input_data_all)
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\execution.py", line 81, in get_output_data
return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\execution.py", line 74, in map_node_over_list
results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\nodes.py", line 1344, in sample
return common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise)
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\nodes.py", line 1314, in common_ksampler
samples = comfy.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\custom_nodes\ComfyUI-Impact-Pack\modules\impact\sample_error_enhancer.py", line 9, in informative_sample
return original_sample(*args, **kwargs) # This code helps interpret error messages that occur within exceptions but does not have any impact on other operations.
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\custom_nodes\ComfyUI-AnimateDiff-Evolved\animatediff\sampling.py", line 313, in motion_sample
return orig_comfy_sample(model, noise, *args, **kwargs)
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\comfy\sample.py", line 37, in sample
samples = sampler.sample(noise, positive, negative, cfg=cfg, latent_image=latent_image, start_step=start_step, last_step=last_step, force_full_denoise=force_full_denoise, denoise_mask=noise_mask, sigmas=sigmas, callback=callback, disable_pbar=disable_pbar, seed=seed)
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\comfy\samplers.py", line 761, in sample
return sample(self.model, noise, positive, negative, cfg, self.device, sampler, sigmas, self.model_options, latent_image=latent_image, denoise_mask=denoise_mask, callback=callback, disable_pbar=disable_pbar, seed=seed)
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\comfy\samplers.py", line 663, in sample
return cfg_guider.sample(noise, latent_image, sampler, sigmas, denoise_mask, callback, disable_pbar, seed)
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\comfy\samplers.py", line 650, in sample
output = self.inner_sample(noise, latent_image, device, sampler, sigmas, denoise_mask, callback, disable_pbar, seed)
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\comfy\samplers.py", line 629, in inner_sample
samples = sampler.sample(self, sigmas, extra_args, callback, noise, latent_image, denoise_mask, disable_pbar)
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\comfy\samplers.py", line 534, in sample
samples = self.sampler_function(model_k, noise, sigmas, extra_args=extra_args, callback=k_callback, disable=disable_pbar, **self.extra_options)
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\venv\lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\comfy\k_diffusion\sampling.py", line 585, in sample_dpmpp_2m
callback({'x': x, 'i': i, 'sigma': sigmas[i], 'sigma_hat': sigmas[i], 'denoised': denoised})
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\comfy\samplers.py", line 532, in
k_callback = lambda x: callback(x["i"], x["denoised"], x["x"], total_steps)
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\latent_preview.py", line 94, in callback
preview_bytes = previewer.decode_latent_to_preview_image(preview_format, x0)
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\latent_preview.py", line 18, in decode_latent_to_preview_image
preview_image = self.decode_latent_to_preview(x0)
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\latent_preview.py", line 48, in decode_latent_to_preview
return Image.fromarray(latents_ubyte.numpy())
File "C:\Users\maveyyl\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\venv\lib\site-packages\PIL\Image.py", line 3134, in fromarray
raise TypeError(msg) from e
TypeError: Cannot handle this data type: (1, 1, 3), <f4
The text was updated successfully, but these errors were encountered: