How to run Stable Diffusion locally on PC or using Google Colab

How To Run Stable Diffusion

How To Run Stable Diffusion

Do you want to turn your imagination into art, but have no idea how to run Stable Diffusion? We have got you covered. You'll find everything you need to know below.

Stable Diffusion is one of the best AI image generators that allows users to create stunning art from their text input - just like the DALL-E 2 and Imagen. On August 22, the Stable Diffusion was released publicly, which means now anyone can use them to generate images.

With Stable Diffusion, anyone can generate images with their own text. We are going to show you how to run Stable Diffusion on various hardware. Let's get down to business.

How To Run Stable Diffusion Without GPU

In order to run Stable Diffusion without using GPU, you can definitely do it through a website. There are three ways to achieve this feat:

  • Using the Hugging Face website.
  • Using Google Colab Pro
  • Using the DreamStudio Lite website.

To run Stable Diffusion using Hugging Face, just go over to this website, enter your prompt and click Generate image. We will discuss the other two methods in detail in the following sections.

How To Run Stable Diffusion Online

One of the easiest ways to run Stable Diffusion is by using the DreamStudio web app. DreamStudio Lite is a product of Stability AI - the same company that created Stable Diffusion. Using the DreamStudio interface, you can create any image you can "dream."

To run Stable Diffusion via DreamStudio:

  • Navigate to the DreamStudio website.
  • Create an account.
  • Once you are in, input your text into the textbox at the bottom, next to the Dream button.
  • Click on the Dream button once you have given your input to create the image. Your image will be generated within 5 seconds.

That's it! You can download the image you created by clicking the download icon in the middle of the generated image. There are a couple of settings on the right side that you can tweak, like the resolution of the image or the number of images to be generated.

Users get 200 credits when they sign up for DreamStudio. With that, you can generate 200 512x512 resolution free images with the DreamStudio web app. After that, you need to pay £1 ($1.18) to purchase 100 generations.

NSFW filters are applied to the images generated by this tool, so you will get a fully blurred image if you try to create images that are considered NSFW.

Run Stable Diffusion using Colab

Alternatively, you can access Stable Diffusion non-locally via Google Colab. However, the caveat is that you need a Colab Pro account since the free version of Colab has slightly too little VRAM to generate images.

It is worth noting that this tool also comes with its own NSFW filter. That said, there is a workaround to make NSFW images on Stable Diffusion via Google Colab. You can find it in the linked article.

How To Run Stable Diffusion Locally

If you have a GPU with at least 6GB of VRAM, you can run Stable Diffusion locally on your PC. If your GPU does not have enough VRAM, you might encounter the Stable Diffusion runtime error.

The steps to run the model may seem a bit complicated, but it's actually easy to follow and you can get it done with a little effort. Here is what you need to do.

Downloading and setting up Stable Diffusion

  • Create a Huggingface account. Go here, click Sign Up (top bar)and create an account. Once done, go here.
  • Go to this link and select the Files and versions tab. Download the sd-v1-4.ckpt file. The file is more than 4GB, so while you wait, go get a coffee or watch the latest TikTok trends.
  • Download the cloned repo and unzip it. To download, click on Code (green button) and select Download ZIP.
  • Open the unzipped file and navigate to stable-diffusion-main/models/ldm. Create a folder called "stable-diffusion-v1" there. Rename sd-v1-4.ckpt file to "model.ckpt", and copy it into that folder (stable-diffusion-v1) you've made.
  • Open the file environment.yaml in Notepad, and after the line saying "dependencies:", add "- git" The "-" should be lined up with the ones in the following lines.
  • Go here and download Miniconda 3 Windows.
  • Install Miniconda for all users. Uncheck "Register Miniconda as the system Python 3.9".

Now let's look at how to generate images.

Generating the images

  • Open Anaconda Prompt (Miniconda 3). Type "cd" and then drag the folder into the Anaconda prompt console.
  • Run the following command: conda env create -f environment.yaml. Make sure you are in the stable-diffusion-main folder before doing this.
  • Run the following command: conda activate ldm.
  • To generate an image run the following command: python scripts/ --prompt "Elon Musk as an alien" --H 512 --W 512 --seed 27 --n_iter 2 --ddim_steps 50.
  • For custom images, replace the Elon Musk statement with the image you wish to create.

That's how you create an image. A bit of work, right?

To create a new image you have to repeat steps 2 through 4. You can adjust the height and width of the image by changing the numbers next to H and W. However, to get higher-resolution images, you will need 10 or 12 GB of VRAM.

In case you get an out-of-memory error, run the following command in step 10: python optimizedSD/ --prompt "Elon Musk as an alien" --H 512 --W 512 --seed 27 --n_iter 1 --ddim_steps 50.

That's all you need to start to turn your wildest thoughts into art and how to run Stable Diffusion. Want to know more about artistic AI? Have a look at how to use Midjourney AI - another image generator AI like the Stable Fusion.

That's everything you need to know. If you want more guides on AI, then read our Google Bard articles.

This Article's Topics

Explore new topics and discover content that's right for you!