ComfyUI icon indicating copy to clipboard operation
ComfyUI copied to clipboard

Trying to convert Float8_e4m3fn to the MPS backend but it does not have support for that dtype.

Open rainchen26 opened this issue 1 year ago • 4 comments

Custom Node Testing

Expected Behavior

:(

Actual Behavior

:(

Steps to Reproduce

:(

Debug Logs

:(

Other

No response

rainchen26 avatar Jul 12 '25 08:07 rainchen26

Instead of getting the generated image, this error is thrown. Why arent the corresponding logs attached when opening the issue automatically?

maria-antignolo avatar Jul 19 '25 22:07 maria-antignolo

use this piece of code to convert the float8_e4m3fm to float16, as macos doesn't support float8

from safetensors.torch import save_file, safe_open
import torch

# Load model weights from safetensors on CPU
state_dict = {}
with safe_open("models/diffusion_models/flux1-dev-kontext_fp8_scaled.safetensors", framework="pt", device="cpu") as f:
    for k in f.keys():
        v = f.get_tensor(k)
        # Cast FP8 weights to float16 on CPU
        if v.dtype not in [torch.float16, torch.float32, torch.bfloat16]:
            v = v.to(torch.float16)
        state_dict[k] = v

# Save as safetensors
save_file(state_dict, "models/diffusion_models/flux1-dev-kontext_fp16_scaled.safetensors")

convert both the text_encoder and flux1-dev file

jainamnahar14surat avatar Jul 21 '25 08:07 jainamnahar14surat

then try to run the code again

jainamnahar14surat avatar Jul 21 '25 08:07 jainamnahar14surat

I am brand new to ComfyUI and am attempting to run it on a M4 Mac Mini Pro. I am getting this same error and I appreciate your feedback @jainamnahar14surat however I have no idea as to where to place that code :-) -- finding good info for beginners (especially for the mac environment) can be challenging as the tech changes so quickly -- before finding this thread I assumed I had installed all of my prerequisite software wrong, is that still a possibility? Either way, any guidance on how to fix this would be appreciated.

sConvey avatar Aug 03 '25 05:08 sConvey