412 comments

[ 3.2 ms ] story [ 285 ms ] thread
Is there a way to get it to run on an an Intel-based Mac? I've attempted several times, but quickly ran into dependency issues and other quirks.
I believe the branch which adds support for Apple Silicon also adds support for running on Intel chips (albeit extremely slowly). I haven't tested it myself, but I've seen several people in the GitHub issues saying this.
The standard release works fine, if you tweak the code to use the CPU pytorch device instead of CUDA. It does take about an hour to generate a set of images with the standard options on my AMD 2600 CPU though!
Comment from github: "By the way, i confirmed to work on my Intel 16-in MacBook Pro via mps. GPU (Radeon Pro 5500M 8GB) usage is 70-80% and It takes 3 min where --n_samples 1 --n_iter 1. My repo https://github.com/cruller0704/stable-diffusion-intel-mac"

For comparison, my RTX 2070 takes 10 seconds for one image (512x512)

I'd rather see someone implemented glue that allows you to run arbitrary (deep learning) code on any platform.

I mean, are we going to see X on M1 Mac, for any X now in the future?

Also, weren't torch and tensorflow supposed to be this glue?

Broadly speaking, it looks like they are. The implementation of Stable Diffusion doesn't appear to be using all of those features correctly (i.e. device selection fails if you don't have CUDA enabled even though MPS (https://pytorch.org/docs/stable/notes/mps.html) is supported by PyTorch.

Similar goes for quirks of Tensorflow that weren't taken advantage of. That's largely the work that is on-going in the OSX and M1 forks.

I got stuck on this roadblock, couldn’t get CUDA to work on my Mac, was very confusing
Didn’t apple stop supporting Nvidia cards like 5 years ago? How could it be confusing that Cuda wouldn’t run?
lol presumably the OP didn't know that... hence the confusion.
Ah, I didn't realize. It's not very obvious what GPU you have in your Macbook, I couldn't actually find out where to find that in my System settings. On Windows it's inside the "Display" settings but on MacOS... where is it? :)
That's because CUDA is only for Nvidia GPUs and Apple doesn't support Nvidia GPUs, it has its own now.

    (base)   stable-diffusion git:(main) conda env create -f environment.yaml
    Collecting package metadata (repodata.json): done
    Solving environment: failed
    
    ResolvePackageNotFound:
      - cudatoolkit=11.3
oh i was following the github fork readme, there is a special macos blog post
As mentioned in sibling comments, Torch is indeed the glue in this implementation. Other glues are TVM[0] and ONNX[1]

These just cover the neural net though, and there is lots of surrounding code and pre-/post-processing that isn't covered by these systems.

For models on Replicate, we use Docker, packaged with Cog for this stuff.[2] Unfortunately Docker doesn't run natively on Mac, so if we want to use the Mac's GPU, we can't use Docker.

I wish there was a good container system for Mac. Even better if it were something that spanned both Mac and Linux. (Not as far-fetched as it seems... I used to work at Docker and spent a bit of time looking into this...)

[0] https://tvm.apache.org/ [1] https://onnx.ai/ [2] https://github.com/replicate/cog

One beautiful thing I realized about all this progress in AI.

We will still need people to do the hard yards, and get dirt between their fingernails. I am firmly in the camp of those people.

Fancy algorithms won't dig holes, or lay out rail tracks of over hundreds of miles.. or build houses all across the world.

Are you following progress in robotics?
School us! What’s the latest in robotics that is going to knock our socks off?
They've got death robots that can fly now.

Why is nobody impressed by the future?

I mean, I'm most impressed with the gradual rise of 3d printers capable of printing entire houses.

That doesn't help with plumbing, electrical, kitchen cabinets and all the other stuff that goes into a house -- which is a majority of the cost -- but it's a gradual start.

I see very little which can't be automated, but I see a lot which would take many years of time and effort to automate and integrate.

Once they combine the progress in generative algorithms and robotics, then we are truly done for.
How fast is it on a m1?
It takes 1-2 mins for a 512x512 image. It's been a lot of fun since I did this last night.
For reference, inferencing the model on a 2070 takes 10-12 seconds for the same size at max-precision, and the 3070 can synthesize an image in almost 6 seconds.

If you extrapolate the power consumption (3070 @~300w vs M1 Pro GPU@~30-50w) the metrics make a lot of sense.

I haven't ran this fork yet, but about 1.3 sec/iter. Usually ~30-50 iters/sample (image).
The answer depends VERY MUCH on RAM.

My M1 with 8GB takes 70-90 minutes per image.

My M1 Pro with 16GB takes 3 minutes per image.

Another data point: M1 Max with 64GB takes ~40 seconds
Hopefully the library is intentionally going very slowly trying to fit in RAM and that's not just your 8GB machine totally falling over.
Sadly, in this case it's the 8GB machine falling over.
Note: I ran this and haven't yet been able to get img2img working yet. I borked it up trying to get conda working.

It's been a lot of fun to play with so far though!

Apparently, this release should include a Dockerfile for easier replicability.
Yesterday I thought I broke it too. In my case, the solution was just to make sure that the input image (from the editor or otherwise) was the same size as the output image. Hope it helps.
could someone who has already done this please share how long it takes for a 50 steps image to be generated?
1.3 sec/iter on my M1 Mac, so ~39 seconds.
That was fast. I'm only getting 5.26s/iter on an M1 Pro MBP with 16GB RAM.

EDIT: Speed increased to 2.3s/iter after a reboot

Depends what fork you're running... Some seem to be using CPU-based generation, others use the MPS device backend correctly which is MUCH faster. I have another comment floating around about lstein's fork, but it takes some massaging to get it to run happily. https://github.com/lstein/stable-diffusion/
The fork linked by OP is MPS-based, I can see GPU usage way up in Activity Monitor. Seems performance doubled after a reboot though :)
Weird, on M1 Max Mac Studio, only getting 1.42 it/s :/
I got my units backwards :sweat: My bad!
the thing eats 15GB memory on my M1 Pro with 32GB RAM... you're probably slowed down by swapping if you only have 16GB RAM...
How large an image will this handle (versus how much RAM you have)?

It seems the GPU memory requirements beyond 512x512 are obscene.

I'm on a iMac M1 16gb and I can handle up to 768x768 but since it's shared memory I close out every other application and run things overnight.

The biggest issue with apple chips is that the --seed setting doesn't work. I should be able to set a seed to, for instance, 1083958 and if I re-run a command at the same resolution with that seed, I should get the same image every time. This would allow me to test different steps so I could generate a 100 images at 16 steps (which is quite fast) and pick the ones that are most promising and re-render at 64 or 128 steps.

But currently you can't do that on apple hardware because of an open issue in PyTorch. Genuinely hoping a fix comes soon, until it is this is more of a novelty than a tool on Apple hardware.

Me at the end of last year: "Should I really go for the full 64GB on this M1 Pro? What could I possibly use this for? mmbml mumble... something about unified GPU... something Deep Learning, one day..."

Me now: "a red juicy apple floating in outer space, like a planet" --H 768 --W 768

Uses about 27GB. 1.81s/it.

Can't do 1024x1024 yet because of some hardcoded Metal issue (https://github.com/pytorch/pytorch/issues/84039.

I was so geniunely happy with my 16GB iMac M1 until stable-diffusion released.

I was amazed at how fast and powerful it was. I thought this meant I could stop buying top-of-the-line Macs every 4 years and start buying bottom-of-the-line Macs every 5 years. And that would have been 100% true... if it weren't for stable-diffusion.

Most people that want hires would just feed the resulting image into AI upscaler like gigapixel.
This model was mostly trained on 512x512 so you should stick to approximately that size.

Use external upscalers like RealESRGAN, SwinIR or BSRGAN or GFPGAN (faces).

Alternatively use hacks like txt2imghd to get it to natively create 1 MP images.

Is there a good set of benchmarks available for Stable Diffusion? I was able to run a custom Stable Diffusion build on a GCE A100 instance (~$1/hour) at around 1Mpix per 10 seconds. I.e, I could create a 512x512 image in 2.5 seconds with some batching optimizations. A consumer GPU like a 3090 runs at ~1Mpix per 20 seconds.

I'm wondering what the price floor of stock art will be when someone can use https://lexica.art/ as a starting point, generate variations of a prompt locally, and then spend a few minutes sifting through the results. It should be possible to get most stock art or concept art at a price of <$1 per image.

So you’re estimating over a thousand generated images an hour and less than a tenth of a cent per image using the A100. If that turns out to be accurate, it seems like some online image generation will included in the price of the stock art.

(DreamStudio is charging a bit over one cent per generated image at default settings, depending on exchange rates.)

Related: I wrote up instructions for running Stable Diffusion on GCE. I used a Tesla T4, which is probably the cheapest that can handle the original code. If you're spinning up an instance to play with, rather than to batch-process, then cheaper makes more sense because most of the machine's time is spent waiting for you to type stuff and look at the results.

https://sowbug.com/posts/stable-diffusion-on-google-cloud/

It can be even cheaper.

Midjourney, in case you appreciate their output, has an unlimited plan for 30$ a month. The only limitation is that if you're an extremely heavy user, they may "relax" you, which means results come in a bit slower.

Note that they've been also experimenting with a --beta parameter which basically means the algorithm uses StableDiffusion's algorithm behind the scenes, or you can use any of 4 versions of MidJourney's more stylistic algorithms.

So if you don't want to tinker or don't have a high-end GPU, it's a cheap way to play around. I have StableDiffusion running locally but still prefer MidJourney. I enjoy the stylistic output but it's also a highly social way to generate art. Everybody is doing it in the open.

Anyway, the stock art part is a hairy subject. You should assume that you AI image is not copyrighted. Which begs the question why they would pay at all.

>The only limitation is that if you're an extremely heavy user, they may "relax" you, which means results come in a bit slower.

You don't have to be an extremely heavy user. I used it for about an hour every evening and it took 11 days out of a month subscription for them to put me on relax mode.

The relax mode is based on how busy the service is. If usage is low, it's the same a fast mode. But other times its really slow.

That makes it unpredictable enough that it stopped being fun for me to use it. I've barely used midjourney since I got put on relaxed mode - it stopped feeling like I can jump on and play because I might hit a busy period and then it'll take 5 minutes to generate a prompt

That said, I could buy more hours of fast mode and I think it's still way cheaper than Dall-E or Dreamstudio

My 3170Ti will create 512x512 image in about 5-6 seconds with 50 inference steps
Between this and efforts to add 3D dimension to 2D images, I don’t see much of a future for digital multimedia creator jobs.

Even TikTok could be an endless stream of ML models.

Fears of a tech dystopia may be overblown; the masses will just shut off their gadgets and live simpler if labor markets implode within the traditional political correct economic system we have.

Open source AI is on the verge of upending the software industry and copyright. I dig it.

For those as keen as I am to try this out, I ran these steps, only to run into an error during the pip install phase:

> ERROR: Failed building wheel for onnx

I was able to resolve it by doing this:

> brew install protobuf

Then I ran pip install again, and it worked!

In the troubleshooting section it mentions running:

    brew install Cmake protobuf rust
To fix onnx build errors. I had the same issue.
What kind of speed does this run at? Eg. How long to make a 512x512 image at standard settings?
On my M1 Pro MBP with 16GB RAM, it takes ~3 minutes.
I haven't installed from this link specifically, but I used one of the branches on which this is based a few days ago, so the results should be similar.

On a first-gen M1 Mac mini with 8GB RAM, it takes 70-90 minutes for each image.

Still feels like magic, but old-school magic.

On an M1 Pro 16GB it is taking a couple minutes for each image.
Is that the difference in graphics performance between the M1 and M1 Pro or did the other person do something wrong? 70-90 minutes seems nuts
Might be the RAM difference. RAM is shared between CPU and GPU on the M1 series processors.
My 16gb M1 Air was initially taking 13 minutes for a 50 step generation. But when I closed all the open tabs and apps it went down to 3 minutes.

Looks like RAM drastically affects the speed.

I have the M1 8GB I mentioned in my first comment, and the M1 Pro 16GB I mentioned in my second component, side-by-side. However, the first one was running a Stable Diffusion branch from earlier in the week, so I replaced using the same instructions. The only difference now is the physical hardware.

The thing to understand is that the 8GB M1 has 8GB. When I run txt2img.py, my Activity Monitor shows a Python process with 9.42GB of memory, and the "Memory Pressure" graph spends time in the red zone as the machine is swapping. While the 16GB M1 Pro immediately shows PLMS Sampler progress, and consistently spends around 3 seconds per iteration (e.g. "3.29s/it" and "2.97s/it"), the 8GB M1 takes several minutes before it jumps from 0% to 2% progress, and it accurately reports "326.24s/it"

So yes, whether it's M1 vs M1 Pro, or 8GB vs 16GB, it really is that stark a difference.

Update: after the second iteration it is 208.44s/it, so it is speeding up. It should drop to less than 120s/it before it finishes, if it runs as quickly as my previous install. And yes, 186.04s/it after the third iteration, and 159.22s/it after the fourth.

Sounds entirely like a swap-constrained operation. You need ~8gb of VRAM to load the uncompressed model into memory, which obviously won't work well on a Macbook with 8gb of memory.
My first-gen M1 MacBook Air with 16GB takes just under 4 minutes per image. Running top while it's generating shows memory usage fluctuating between 10GB and 13GB, so if you're running on 8GB it's probably swapping a lot.
Installed from this link on a MacBook Pro (16-inch, 2021) with Apple M1 Pro and 16GB. First run downloads stuff, so I omit that result.

I had a YouTube video playing while I kicked off the exact command in the install docs, and got: 16.84s user 99.43s system 61% cpu 3:08.51 total

Next attempt, python aborted 78 seconds in! Weird.

Next attempt, with YouTube paused: 16.31s user 95.48s system 65% cpu 2:49.45 total

So around three minutes, I'd say.

A little over three minutes on a first-gen M1 iMac with 16GB.

It looks like memory is super-important for this (which isn't all that surprising, really...).

Looks like I'm getting around 4s per iteration on my M1 Max. At 50 iterations, that's 200 seconds.
M1 Max (32gb) is around 35 seconds per image.
Getting around 4 minutes per image on M1 MacBook Air 16GB
Hm, taking 2 hours on my M1 MacBook Air 16GB and it's clearly swapping. Are you using model v1.4? Or any other memory optimization that you applied?
For 512x512 on M1 MAX (32 core) with 64 GB RAM I'm getting 1.67it/s so 30.59s with the default ddim_steps=50.
I've gotten 1.35it/s that corresponds to 38s, but I've the M1 Max with the 24 cores GPU (the "lower end" one).
I just set up a similar thing on my own a bit differently than OP did.

Apple M1 Max with 10-core CPU, 32-core GPU, 16-core Neural Engine - Takes 38 seconds as well up to 46 when it gets hotter.

Can anyone give comparison with Nvida gpu in terms of performance?

On my M2 Air, 16G, 10 CPU cores, the default command as in the installing instructions takes like 2m20s.
MacBook Air M2 8 CPU 8GB the example apple image took 35mins. Guess I'll wait for now.
You clearly doing something wrong as I get about 3 minutes per image on m1 mac mini.

But yeah, at this stage most of guides are early hacks and require individual tweaking. It is quite expected that people get varying results. I assume in a week or a month situation will get much better and much more user-friendly.

Python dependency hell in a nutshell. Impossible to distribute ML projects that can easily be ran.
I just had to:

> brew link protobuf --overwrite

Don't blindly run this command unless you understand what you're doing.

Thanks for writing this up!! I enjoyed getting TensorFlow running with the M1, although a multi-headed model I was working on wouldn’t run.

I just made my Dad’s 101 year old birthday card using OpenAI’s image generating service (he loved it) and when I get home from travel I will use your instructions in the linked article.

Any advice for running Stable Diffusion locally vs. Colab Pro or Pro+? My M1 MacBook Pro only has 8G ram (I didn’t want to wait a month for a 16G model). Is that enough? I have a 1080 with 10G graphics memory. Is that sufficient?

101 years! Congratulations!! Does he own a suspiciously plain gold ring by any chance?
From the comments here 8GB is not enough, it will swap a lot and take way more time than a 16GB MacBook.
I've been playing with Stable Diffusion a lot the past few days on a Dell R620 CPU (24 cores, 96 GB of RAM). With a little fiddling (not knowing any python or anything about machine learning) I was able to get img2img.py working by simply comparing that script to the txt2img.py CPU patch. Was only a few lines of tweaking. img2img takes ~2 minutes to generate an image with 1 sample and 50 iterations, txt2img takes about 10 minutes for 1 sample and 50 generations.

The real bummer is that I can only get ddim and plms to run using a CPU. All of the other diffusions crash and burn. ddim and plms don't seem to do a great job of converging for hyper-realistic scenes involving humans. I've seen other algorithms "shape up" after 10 or so iterations from explorations people do online - where increasing the step count just gives you a higher fidelity and/or more realistic image. With ddim/plms on a CPU, every step seems to give me a wildly different image. You wouldn't know that steps 10 and steps 15 came from the same seed/sample they change so much.

I'm not sure if this is just because I'm running it on a CPU or if ddim and plms are just inferior to the other diffusion models - but I've mostly given up on generating anything worthwhile until I can get my hands on an nvida GPU and experiment more with faster turn arounds.

> You wouldn't know that steps 10 and steps 15 came from the same seed/sample they change so much.

I don't think this is CPU specific, this happens at these very low number of samples, even on the GPU. Most guides recommend starting with 45 steps as a useful minimum for quickly trialing prompt and setting changes, and then increasing that number once you've found values you like for your prompt and other parameters.

I've also noticed another big change sometimes happens between 70-90 steps. It's not all the time and it doesn't drastically change your image, but orientations may get rotated, colors will change, the background may change completely.

> img2img takes ~2 minutes to generate an image with 1 sample and 50 iterations

If you check the console logs you'll notice img2img doesn't actually run the real number of steps. It's number of steps multiplied by the Denoising Strength factor. So with a denoising strength of 0.5 and 50 steps, you're actually running 25 steps.

Later edit: Oh and if you do end up liking an image from step 10 or whatever, but iterating further completely changes the image, one thing you can do is save your output at 10 steps, and use that as your base image for the img2img script to do further work.

With the 1.4 checkpoint, everything under 40 steps can't be used basically and you only get good fidelity with >75 steps. I usually use 100, that's a good middleground.
How do you change these steps in the given script? Is it the --ddim_steps parameter? Or --n_iter? Or ... ?
I found I got quite decent results with 15-30 steps when generating children’s book illustrations (of course, no expectation for hyperrealism there)
Has anybody had success getting newer AMD cards working?

ROCm support seems spotty at best, I have a 5700xt and I haven't had much luck getting it working.

I've tried using this set of steps [1], but have so far not had luck, mostly because the ROCm driver setup is throwing me for a loop. Tried it with an RX 6700 XT and first was going to test on Ubuntu 22.04 but realized ROCm doesn't support that OS yet, so tried again on 20.04 and ended up breaking my GPU driver!

[1] https://gist.github.com/geerlingguy/ff3c3cbcf4416be2c0c1e0f8...

Yes. That's expected.

AMD market segmented their RDNA2 support in ROCm to the Navi21 set only (6800/6800 XT/6900 XT).

It is not officially supported in any way on other RDNA2 GPUs. (Or even on the desktop RDNA2 range at all, that only works because their top end Pro cards share the same die)

Oh... had no clue! Thanks for letting me know so I wouldn't have to spend hours banging my head against the wall.
As an aside, a totally unsupported hack to make it somewhat work on Navi2x smaller dies which you use:

HSA_OVERRIDE_GFX_VERSION=10.3.0 to force using the Navi21 binary slice.

This is totally unsupported and please don't complain if something doesn't work when using that trick.

But basic PyTorch use works using this, so you might get away with it for this scenario.

(TL;DR: AMD just doesn't care about GPGPU on the mainstream, better to switch to another GPU vendor that does next time...)

Looks like I may be out of luck with NAVI 10.
6600XT reporting in. Spent a few hours on Windows and WSL2 setup attempts, got no where. I don't run Ubuntu at home and don't want to dual boot just for this. From looking around I think I'd have a better chance on native Ubuntu.
Buy an NVIDIA card. ROCm isn't supported in any way on WSL2, but CUDA is.

AMD just doesn't invest in their developer ecosystem. Also as you use a 6600 XT, no official ROCm support for the die that you use. Only for navi21.

Or wait, if its just about stable diffusion multiple people try to create onnx and directml forks of the models/scripts, which atleast in theory can work for AMD gpus in windows and wsl2
I have it working on an RX 6800, used the scripts from this repo[0] to build a docker image that has ROCm drivers and PyTorch installed.

I'm running Ubuntu 22.04 LTS as the host OS, didn't have to touch anything beyond the basic Docker install. Next step is build a new Dockerfile that adds in the Stable Diffusion WebUI.[1]

[0] https://github.com/AshleyYakeley/stable-diffusion-rocm [1] https://github.com/hlky/stable-diffusion-webui

The RX6800 seems like a great card for this - 16GB of relatively fast VRAM for a good price.

How long does it take to do 50 iterations on a 512x512?

I tried getting pytorch vulkan inference working with radv, it gives me a missing dtype error in vkformat. Fp16 or normal precision have the same error. I think it's some bf16 thing.
Thanks for this - it's rare to see a setup guide that actually works on each step!

I did need to run the troubleshooting step too, could probably just move that up as a required step in the guide.

It isn't required for some (most?) users. Weirdly sometimes pip is picking up the wheel for `onnx`, sometimes it isn't, and we can't figure out why.

Any Python packaging experts know what's going on? all macOS 12, arm64, Python 3.10. Can't think it wouldn't resolve the wheel.

But yes, good idea to move up. I'll stick it next to the `pip install`.

Please consider also adding a small note to help those few that get stuck with this bug:

    RuntimeError: expected scalar type BFloat16 but found Float
The solution is easy:

    append the execution command with `--precision full`
Commenting for visibility, thanks for this
Commenting for more visibility, this worked for me too.

Thank you!

Different versions of pip.
Are we being pranked? I just followed the steps but the image output from my prompt is just a single frame of Rick Astley...

EDIT: It was a false-positive (honest!) on the NSFW filter. To disable it, edit txt2img.py around line 325.

Comment this line out:

    x_checked_image, has_nsfw_concept = check_safety(x_samples_ddim)
And replace it with:

    x_checked_image = x_samples_ddim
That means the NSFW filter kicked in IIRC from reading the code.

Change your prompt, or remove the filter from the code.

Haha, busted!
To be fair, the reason the filter is there is that if you ask for a picture of a woman, stable diffusion is pretty likely to generate a naked one!

If you tweak the prompt to explicitly mention clothing, you should be OK though.

Wow, is that true? I’ve never heard a more textbook ethical problem with a model.
It's an ethical problem with our society, not the model.
If you consider that the training set includes all western art from the last few centuries it’s not too surprising. There’s an awful lot of nudes in that set & most of them are female.
(comment deleted)
If you open up the script txt2img and img2img scripts, there is a content filter. If your prompt generated anything that gets detected as "inappropriate" the image is replaced with Rick Astley.

Removing the censor should be pretty straightforward, just comment out those lines.

It bothers me that this isn't just configurable. Why would they not want to expose this as a feature?
Plausible deniability
(comment deleted)
When the model detects NSFW content it replaces the output with the frame of Rick Astley.
It's kind of amazing that ML can now intelligently rick roll people.

I think it would be awesome to update the rickroll feature to the following:

Auto Re-run the img2img with some text prompt: "all of the people are now Rick Astley" with low strength so it can adjust the faces, but not change the nudity!!!1

Hah, it would be hilarious if it generated all the nudity you wanted - but with Rick Astley's face on every naked person!
To be fair, the developers added this "feature" and can easily be disabled in the code. The ML just says "this might be NSFW".
Same thing happened to me which is especially odd as I literally just pasted the example command.
It has a lot of false positives. A lot of my portraits of faces were marked as NSFW. Possibly detecting proportion of the image that's skin color?
Unrelated to stable diffusion, but I was showing DALL-E to my sister last night and a prompt with > Huge rubber tree set off the TOS violation filter.

AI alignment concerns are definitely overblown...

Any chance of this running on an M1 iPad Pro?
Probably another week or two. running on M1 iPad Pro needs to get out of PyTorch, possibly export the model either through TorchScript and then do onnx conversion. From what I found so far, not many of these conversions done (except the OpenVINO one maybe?).
Note that once you run the python script for the first time it seems to download a further ~2GB of data
Including a rick astley image for the first thing you gen -_-
That’s the NSFW filter :D
Hm, when I run the example, I get this error:

> expected scalar type BFloat16 but found Float

Has anyone seen this error? It's pretty hard to google for.

Yeah. Try running with PYTORCH_ENABLE_MPS_FALLBACK=1 <script> --full-precision
For me `--full-precision` kept erroring out, but `--precision full` worked correctly.
Are you running macOS >=12.3?
Oh, no I'm not, I'm on 12.0. Does this make a difference?
Update: I solved this error more properly by upgrading to the latest version. Thanks bfirsh.
I am having the same issue on MacOS 12.2.1 (21D62); Python 3.10.6 What did you upgrade to solve this? Thanks! (I can get it working with `--precision full`)
Does running it locally give you anything over using the web version?
You can hack on it, modify it, integrate it with other code, etc!
Also, of course, it's entirely free. The web version is actually paid, though it's hard to tell because they're not super transparent about the fact that you're steadily eating through a quota of initial tokens.
You can finetune the model with Textual Inversion. And you don't have the safety mechanism for nudity.
The online ones are usually bogged down with too much traffic. Locally seems to be much easier/faster
(comment deleted)
Magnusviri[0], the original author of the SD M1 repo credited in this article, has merged his fork into the Lstein Stable Diffusion fork.

You can now run the Lstein fork[1] with M1 as of a few hours ago.

This adds a ton of functionality - GUI, Upscaling & Facial improvements, weighted subprompts etc.

This has been a big undertaking over the last few days, and I highly recommend checking it out. See the mac m1 readme [3]

[0] https://github.com/magnusviri/stable-diffusion

[1] https://github.com/lstein/stable-diffusion

[2] https://github.com/lstein/stable-diffusion/blob/main/README-...

Brilliant, thank you! I just got OP's setup working, but this seems much more user-friendly. Giving it a try now...

EDIT: Got it working, with a couple of pre-requisite steps:

0. `rm` the existing `stable-diffusion` repo (assuming you followed OP's original setup)

1. Install `conda`, if you don't already have it:

    brew install --cask miniconda
2. Install the other build requirements referenced in OP's setup:

    brew install Cmake protobuf rust
3. Follow the main installation instructions here: https://github.com/lstein/stable-diffusion/blob/main/README-...

Then you should be good to go!

EDIT 2: After playing around with this repo, I've found:

- It offers better UX for interacting with Stable Diffusion, and seems to be a promising project.

- Running txt2img.py from lstein's repo seems to run about 30% faster than OP's. Not sure if that's a coincidence, or if they've included extra optimisations.

- I couldn't get the web UI to work. It kept throwing the "leaked semaphor objects" error someone else reported (even when rendering at 64x64).

- Sometimes it rendered images just as a black canvas, other times it worked. This is apparently a known issue and a fix is being tested.

I've reached the limits of my knowledge on this, but will following closely as new PRs are merged in over the coming days. Exciting!

Can you describe how you did (/ are doing) this? Do you now need to use conda (as opposed to OPs pip only version)?
See my edit for more info. (Just ironing out a couple of other issues I've found, so might update it again shortly)
I only get black images.
You have to disable the safety checker after creating the pipe
I was able not to have black images by using a different sampler

--sampler k_euler

full command:

"photography of a cat on the moon" -s 20 -n 3 --sampler k_euler -W 384 -H 384

(comment deleted)
Thank you with those extra steps I got it working now myself. At least I think thank you. My work productivity for the next few days might not agree.
FYI: black images are not just from the safety checker.

Yes, the safety checker will zero out images but can just turn it off with an “if False:”; Mostly black images are due to a bug, especially frustrating because it turns up on high step counts and means you’ve wasted time running it.

My experience has been roughly 2-4/32 of an image batch comes back black at the default settings, regardless of the prompt.

Just stamp out images in batches and discard the black ones.

Instructions don't work here, dead ends at

  FileNotFoundError: [Errno 2] No such file or directory: 'models/ldm/stable-diffusion-v1/model.ckpt'
Looks like there's a step missing or broken at downloading the actual weights.

Going up to the parent repo points at a bunch of dead links or hugginface pages.

You have to download the model from the huggingface[0] site first (requires a free account). The exact steps on how to link the file are then detailed here[1].

[0] https://huggingface.co/CompVis/stable-diffusion-v-1-4-origin... [1] https://github.com/lstein/stable-diffusion/blob/main/README-...

I did this but then moved the directory. When re-linking and checking with ls for the path I thought "oh, alright, it's already there". Oh well, better check with ls -l earlier next time.
I had to manually install pytorch for the preload_models.py step to work, because ReduceOp wasn't found. Why even use anaconda if all the dependencies aren't included? Every time I touch an ML project, there's always a python dependency issue. How can people use a tool that's impossible to provide a consistent environment for?
You are completely correct that there are a lot of dependency bugs here, I would just like to pedantically complain that the issue in question is PyTorch supporting MPS, which is basically entirely a C++ dependency issue rather than a Python one. (PyTorch being mostly written in C++ despite having "py" in the name.) And yeah the state of C++ dependency management is pretty bad.
To get past `pip install -r requirements` I had to muck around with CFLAGS/LDFLAGS because I guess maybe on your system /opt/homebrew/opt/openssl is a symlink to something? On mine it doesn't exist, I just have /opt/homebrew/opt/openssl@1.1 symlinked to /opt/Cellar/somewhere.

The command that finally worked for me:

  python3 -m venv venv
  . venv/bin/activate
  CFLAGS="-I /opt/homebrew/opt/openssl@1.1/include" LDFLAGS="-L /opt/homebrew/opt/openssl@1.1/lib -L/opt/homebrew/Cellar/openssl@1.1/1.1.1q/lib -lssl -lcrypto" PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig" GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1 pip install -r requirements.txt
Nice. We'll get this guide updated for this fork. Everything's moving so fast it's hard to keep track!

We struggled to get Conda working reliably for people, which it looks like lstein's fork recommends. I'll see if we can get it working with plain pip.

Check my comment alongside yours, I got Conda to work but it did require the pre-requisite Homebrew packages you originally recommended before it would cooperate :)
I really appreciate the use of pip > conda. Looking forward to the update for the repo!
Running lstein's fork with these requirements[0] but seeing this output[1]. Same steps as original guide otherwise.

Anyone got any ideas?

[0] https://github.com/bfirsh/stable-diffusion/blob/392cda328a69...

[1] https://gist.github.com/bfirsh/594c50fd9b2e6b173e31de753a842...

Same output for me also.

EDIT: https://github.com/lstein/stable-diffusion/issues/293#issuec... fixed it for me.

I couldn't get the setup process working until I switched the python distro to 3.10, as the scripts were relying on typings features that were added in 3.10 even though the yml file specified 3.9. Was strange.
Conda is recommended because it starts from a clean environment so you're not debugging 13 other experiments the user has going on.
Everything works excepts it only generates black images,

did you run

python scripts/preload_models.py

python scripts/dream.py --full_precision ?

are there benchmarks?

I was following the github issue and the CPU bound one was at 4-5 minutes, the MDS one was at 30 seconds, then 18 seconds, and people were still calling that slow.

What is it currently at now?

and I don't know what "fast" is, to compare

What are the Windows 10 with nice Nvidia chips w/ CUDA getting? Just curious whats comprehensive

> What are the Windows 10 with nice Nvidia chips w/ CUDA getting?

Are you referring to single iteration step times, or whole images? Because obviously it depends on the number of iteration steps used.

Windows 10, RTX 2070 (laptop model), lstein repo. I get about 3.2 iter/sec. A 50 step 512x512 image takes me 15 seconds.

I’m referring to there being a community effort to normalize performance metrics and results at all, with the M1 devices being in that list as well, so that we dont have to ask these questions to begin with

Are you aware of any wiki or table like that?

Huh, that’s the same speed I get on Collab. Pretty good.
I only run 1 sample at a time (batch size 1), forgot to mention that, and that affects the step time.

It looks like each additional image in a batch is cheaper than the 1st image. For example if I reduce my resolution so I can generate more in a single batch

1 image, 50 steps, 320x320: 5s

2 images, 50 steps, 320x320: 8s

3 images, 50 steps, 320x320: 11s

4 images, 50 steps, 320x320: 14s

And the trend continues, and my reported iteration/sec goes down as well. It's not accounting for the fact that with steps=50 and batch size=4 it's actually running 200 steps, just in 4 parallel parts.

Wow, that is over twice as fast as my Windows 11, RTX 3080ti
I just commented on another sibling comment (too late to edit the first one), but I forgot to mention my batch size is only 1. I think most people use batch size 4, so basically multiply my time by your batch size for a real comparison.
It was my bad, my script was still running a different fork. Seeing <10 second times with those parameters now. 13.6 seconds for an 3072 × 2048 upscaled image, which I'm particularly happy about.
I ran into:

ImportError: cannot import name 'TypeAlias' from 'typing' (/opt/homebrew/Caskroom/miniconda/base/envs/ldm/lib/python3.9/typing.py)

I ran into this. You need Python 3.10. I had to edit environment-mac.yaml and set python==3.10.6 ...
I changed the dependency to 3.10.4 (tried 3.10.6 as well), installed python 3.10.4, deactivated and activated ldm environment, but it still uses python 3.9
Can you delete your environment and try again?
Since I don't know how to use conda, I had to struggle a bit to learn how to recreate the environment. Here's the commands that worked me for future reference:

  conda deactivate
  conda env remove -n ldm
Then, again:

  CONDA_SUBDIR=osx-arm64 conda env create -f environment-mac.yaml
  conda activate ldm
I followed the conda instruction which uses Python 3.9 and ran into the same issue. The workaround is to import TypeAlias from typing_extensions:

stable-diffusion/src/k-diffusion/k_diffusion/sampling.py

(before)

  from typing import Optional, Callable, TypeAlias
(after)

  from typing import Optional, Callable
  from typing_extensions import TypeAlias
This issue is tracked in https://github.com/lstein/stable-diffusion/issues/302
you can also just change the python version in the yml file to 3.10.4 and it'll work
TypeAlias is only used once, you can open sampling.py and remove the import on line 10 and the usage on line 14:

  from typing import Optional, Callable

  from . import utils

  TensorOperator = Callable[[Tensor], Tensor]
What's the performance of these models ,how much pc spec required for sane operation?
I'm working on getting this running. Instead of "venv/bin/activate" I had to run "source venv/bin/activate". And I got an error installing the requirements, fixed by running "pip install pyyaml" as a separate command.
Wow, I'm getting as low as 1.2 seconds per "step" (about a minute for a 512x512 image with default settings) on my 32 GB M1 laptop (2021, 16-inch).
Having to use "source" means you have an older version of conda. Python package management is kind of a mess.
There's a little "." before "venv/bin/activate" that's easy to miss. I'll update it to "source" to make it more obvious.
Great. FYI, the issue with pyyaml was caused by the "--pre" flag. The reason installing it separately fixes the problem is because it installs it without the "--pre" flag, and then it is already installed when you install the requirements.

I haven't been able to make sense of n-samples and n-iters. Changing the former caused generation to freeze at 0%. Changing the latter seems to generate multiple images, even though the SD docs for n-iters are "sample this often".

I wonder if this is going to be a huge boon to m1 sales.