FLUX.1-dev image generation on M1 Mac using GPU

#242
by fhashim - opened

I want to make use of GPU on my M1 Mac to generate images through prompt using black-forest-labs/FLUX.1-dev. Adding the code below.

I’ve specified mps for torch.Generator but the script fails stating with error latents = torch.randn(shape, generator=generator, device=rand_device, dtype=dtype, layout=layout).to(device) RuntimeError: Placeholder storage has not been allocated on MPS device!

How can I make use of GPU to generate image?

prompt = "A cat holding a sign that says hello world"
image = pipe(
    prompt,
    height=1024,
    width=1024,
    guidance_scale=3.5,
    num_inference_steps=1,
    max_sequence_length=512,
    generator=torch.Generator("mps").manual_seed(0)
).images[0]
image.save("flux-dev.png")

@fhashim I would recommend something like mlx instead, that is more optimized and easier for Mac’s.

https://github.com/filipstrand/mflux

Sign up or log in to comment