ml-explore / ml-explore/mlx-examples

Stable diffusion txt2image.py with dtype=float16 generates PNGs with all zero values.

Open
#404 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
9k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

I'm trying to run Stable diffusion txt2image.py with float16 dtype on M1 8GB iMac, since float32 dtype requires more than 8 GB memory. I modified this line of code https://github.com/ml-explore/mlx-examples/blob/e9b32747b424468eabb5a7f0609f275637e1a0c3/stable_diffusion/txt2image.py#L26 into the following:

sd = StableDiffusion(float16=True)

I run it with the following command line:

python3 txt2image.py "A photo of an astronaut riding a horse on Mars." --n_images=1

The execution finishes and produces a 512x512 PNG file 'out.png'.

However, the generated PNG has no content and is fully black. Inspecting the file shows that it contains only zeros. Does the Stable diffusion model work with float16 dtype? Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with stable_diffusion/txt2image.py at the float16=True change near line 26, then run the provided command on the reported setup. Trace the generated image values through the PNG-writing path and determine whether float16 execution is supported; done means the cause is documented and the command produces a non-empty 512x512 PNG or the limitation is clearly reported.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.