Text-to-Image
Diffusers
Safetensors
StableDiffusionPipeline
stable-diffusion
Inference Endpoints

[Solution] How do I get stable diffusion 2.1 to work on a Mac?

#52
by SaruStudios - opened

How do I get stable diffusion 2.1 to work on a Mac?

I'm not a developer so I don't understand most of this stuff but I've been using YouChat at you.com which is an AI that uses GPT 3 or 4 and the internet to help me.

I'm trying to run this on a M1 MacBook Pro with 32 Memory. I know there's issues with GPU and Graphics cards though I know its possible to get Stable Diffusion to work.

I watched these tutorials:
Mac: Easy Stable Diffusion WebUI Installation | Full Guide & Tutorial
How to Install Stable Diffusion on M1 Macs

My first error I came across was "Error completing request." This was related to home brew installing. I was also getting "zsh: command not found: brew"

I saw in the comments of the first YouTube video from a guy called FUGASA that said

"add 'export PATH=/opt/homebrew/bin:$PATH'"

I entered that in terminal and that did the trick and I got past the home brew issues. Remember I followed all the steps of the first tutorial.

After the install was finished I did text to image. I typed pool or girl and then click generate and this is the last part of the next error I would get:

"A tensor with all NaNs was produced in Unet. This could be either because there's not enough precision to represent the picture, or because your video card does not support half type. Try setting the "Upcast cross attention layer to float32" option in Settings > Stable Diffusion or using the --no-half commandline argument to fix this. Use --disable-nan-check commandline argument to disable this check."

Screenshot 2023-04-29 at 8.30.36 AM.png

I also watched this tutorial for mac errors:
How to Fix Common Warnings When Installing Stable Diffusion on Your Mac

I gave it the error to "YouChat" and this is what it says:

"Based on the error message you mentioned, it seems that Stable Diffusion is encountering a problem with generating an image due to an issue with the precision of the data or video card type. The error message suggests two potential solutions:

Set the "Upcast cross attention layer to float32" option in Settings > Stable Diffusion, which may help to resolve the precision issue.

Use the --no-half command line argument to disable the use of half data type and instead use float32 type, which may also help to resolve the issue.

If those solutions do not work, the error message suggests using --disable-nan-check command line argument to disable the NaN check. This could suppress the error message but it's unclear if the resulting images would be valid.

If you are still encountering the issue after trying these suggestions, you may need to seek further assistance from the Stable Diffusion development team or community."

I asked for help to execute the solutions:

"Yes, I can explain how to implement the solutions mentioned in the error message you encountered with Stable Diffusion.

Set the "Upcast cross attention layer to float32" option in Settings > Stable Diffusion: To set the "Upcast cross attention layer to float32" option, you need to open the Stable Diffusion settings window and navigate to the "Advanced" tab. There you will find an option to "Upcast cross attention layer to float32". Enable this option, save your changes, and then try generating an image again.

Use the --no-half command line argument: If you are using the command line to run Stable Diffusion, you can add the --no-half flag to disable the use of half data type and instead use float32 type. Simply add this flag to your command when running Stable Diffusion. For example:

python run_generator.py --no-half
Use the --disable-nan-check command line argument: If you want to disable the NaN check, you can do so by adding the --disable-nan-check flag to your command. For example:

python run_generator.py --disable-nan-check
Note that disabling the NaN check could suppress the error message but the resulting images may be invalid.

I hope these solutions help to resolve the issue you are encountering with Stable Diffusion. If you need further assistance, feel free to ask!"

It was a simple fix but not having experience working with terminal I ended up making it more complicated. Thankfully I saw this:

Settings > Stable Diffusion: To set the "Upcast cross attention layer to float32"

I went to the settings and found "Upcast cross attention layer to float32" and checked the box.

I typed Pool and got my first generation.

I am apart of a Stable Diffusion discord which also helped. I just googled it and joined the first one I found.

I will post updates here and I'll make a YouTube video also about my experience since there isn't enough mac tutorials out there.

Sign up or log in to comment