How to Use Stable Diffusion Without a Graphics Card (CPU Guide)
Stable Diffusion without a graphics card

AI-powered image generation has taken the Web and social media by storm. Online solutions are growing more robust and advanced, but running models locally has two major advantages: it's free, and it removes the limits imposed by online platforms. The best offline option remains Stable Diffusion, but its standard setup recommends Nvidia graphics cards. Fortunately, a recommendation is not a requirement, and today we're going to explore how to redirect Stable Diffusion to use the CPU…

For those who want to dip their toes into the waters of image generation, the easiest way is to create an account at DreamStudio or use Midjourney through Discord, but none of these options are free, and you'll need to buy credits once you've exhausted their trial offers. Alternatively, the public demo of Stable Diffusion is still up, and if you're patient (and I mean the waiting queue, spontaneous errors, and "work" your prompts), you can create very interesting images.

However, there is also offline generation, and if you have a compatible Nvidia graphics card, it is by far the best way to get images. Why? You can explore different models shared by the community, escape the (logical) limits of online editions, and most importantly, create images without paying a single cent. But what if a graphics card isn't an option? In that case, the solution is to convince Stable Diffusion to use the CPU.

Before you start

You must moderate your expectations. The process trades time for compatibility. Exact performance depends on each processor and how strong its cores are (and yes, you definitely need a multi-core chip and 16 GB of RAM for this), but on average you should expect about five minutes per image at 20 steps. Some sampling methods require 30 to 40 steps for optimal results, so you need to be patient.

How to configure Stable Diffusion without a graphics card

How to Use Stable Diffusion Without a Graphics Card (CPU Guide)
Stable Diffusion without a graphics card
  1. In essence, this guide follows the same steps as the installation tutorial for the WebUI version of Stable Diffusion developed by Automatic1111 on GitHub. It's one of the most popular and up-to-date on the Web, but it won't work on processors without a couple of tweaks at the end. That's our job.
  2. First, you must install Python 3.10.6 or higher, selecting the "Add Python to PATH" option when the installer presents it.
  3. Then comes Git for Windows. At the time of writing, its latest build is 2.38.0, compatible with 64-bit systems.
  4. Two options here: you can use the command git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git to download the full repository, or do that same download manually by clicking the green Code button and then choosing Download Zip. The first path lets you use git pull to update it later, while the second requires downloading the zip each time. In any case, installing git is mandatory.
  5. The most complicated step: getting Stable Diffusion model 1.4. This is a four-gigabyte brick, so I recommend using a magnet link for its download via BitTorrent. Another alternative is direct download, but cross your fingers that your connection doesn't get interrupted.
  6. Once downloaded, change its name to model.ckpt, and place it inside stable-diffusion-webui-master\models\Stable-diffusion\. The rest of the models download automatically with the first run.
  7. We haven't left the jungle yet. The key to making this work is forcing CPU usage and at the same time indicating that there are no CUDA devices.
  8. To do this, edit the file webui.bat and add two lines as shown in the image below: set CUDA_VISIBLE_DEVICES=-1 and set COMMANDLINE_ARGS=--precision full --no-half --use-cpu all --skip-torch-cuda-test --autolaunch. Save the changes.
How to Use Stable Diffusion Without a Graphics Card (CPU Guide)
Stable Diffusion without a graphics card
  1. Open a command prompt with elevated privileges and run webui.bat. This elevation is not strictly necessary, but it avoids any potential conflicts with Windows.
  2. If WebUI needs something else, it will likely try to download it automatically. This is the expected behavior. If all goes well, the Stable Diffusion WebUI will open in your default browser tab at address 127.0.0.1:7860.
  3. Enter a prompt, and limit the number of steps to 20 to begin. Not all samplers work in CPU mode (for example, DDIM), and my suggestion is to stick to Euler A or LMS. Click Generate and wait.
How to Use Stable Diffusion Without a Graphics Card (CPU Guide)
Stable Diffusion without a graphics card
How to Use Stable Diffusion Without a Graphics Card (CPU Guide)

That's it! With these steps, image generation using Stable Diffusion and a processor becomes a reality. The rest is... patience. Personally, I can create 16 images on GPU for each one on CPU, so there's a huge performance difference, but calibrating the number of steps and resolution will help reduce processing time. Good luck!