Stable diffusion running on the Framework Laptop using opencl

Something fun, but stable diffusion runs on the framework laptop. It can generate an image in about 90 seconds. Since Xe graphics can run from system memory, it can load the model without any issues.

Quick guide using Fedora.
Install intel-opencl
dnf install intel-opencl
Download and setup an environment for tinygrad
git clone git@github.com:geohot/tinygrad.git
cd tinygrad
python3 -m venv venv-tinygrad
source venv-tinygrad/bin/activate
python3 setup.py develop
pip install tqdm pyopencl

Grab the model for stable-diffusion:
Go to CompVis/stable-diffusion-v-1-4-original · Hugging Face and make an account, then agree to the terms so you can download the model. Then download the model from https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/blob/main/sd-v1-4.ckpt and copy it to weights/ directory

Generate something interesting
OPT=2 OPENCL=1 time python3 examples/stable_diffusion.py --phrase "trees in the sunset with mountians and elephants" --out art.png

If you install intel_gpu_top you can see that the processing is done on the GPU! And is much faster than the CPU.

10 Likes

That’s cool to see. I need to give it a shot.

I’ve been playing with SD, but running it on the CPU. My i7-1260p averages 6.70s/it or 5.5ish minutes for a 50 iteration image. Using an ONNX version of SD through Diffusers is a little faster at 6.00s/it or 5 minutes for 50 iterations.

That’s way better than running Stable Diffusion on the CPU. Thanks for sharing!