huggingface / diffusers

🤗 Diffusers: State-of-the-art diffusion models for image and audio generation in PyTorch and FLAX.
https://huggingface.co/docs/diffusers
Apache License 2.0
26.06k stars 5.37k forks source link

hardcoded torch.float64 isn't supported on Metal (device="mps") #9224

Closed RoyLeviLangware closed 1 month ago

RoyLeviLangware commented 2 months ago

Describe the bug

Running transformer_flux on macOS device="mps" fails with error: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead

Reproduction

Run on Mac:

from diffusers import FluxPipeline

def print_hi(name):
    print(f'Hi, {name}')
    torch.set_default_device("mps")
    pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16).to(device="mps")
    # pipe.enable_model_cpu_offload()  # save some VRAM by offloading the model to CPU. Remove this if you have enough GPU power

    prompt = "A cat holding a sign that says hello world"
    image = pipe(
        prompt,
        guidance_scale=0.0,
        num_inference_steps=16,
        max_sequence_length=256,
        generator=torch.Generator("mps").manual_seed(0)
    ).images[0]
    image.save("flux-schnell.png")

if __name__ == '__main__':
    print_hi('PyCharm')

Logs

Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead

System Info

diffusers==0.30.0 torch==2.4.0

Who can help?

No response

DN6 commented 2 months ago

Should be fixed now after we merged https://github.com/huggingface/diffusers/pull/9074

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.