Building a Stable Diffusion WebUI environment with RunPod
Tags: ai, stablediffusion, googlecolab, runpod
Published: 2023-05-07 09:01:42

As Google Colab has restricted the execution of Stable Diffusion in the free tier, we introduce [RunPod](https://www.runpod.io/) as an alternative cloud resource.

What you need:

- $10
- RunPod account
- Backblaze account

First, visit [RunPod](https://www.runpod.io/) and [Backblaze](https://www.backblaze.com/) to create accounts.

## Paying the fee

RunPod requires a prepayment, so you will need to pay a minimum of $10 upfront.

![SetCreditAmount](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tppg7rcvb0xknjvetae0.png)

You will be redirected to the Stripe page, where you can enter your credit card information.


![SetCreditCardInfo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ez6iar8oz2ate7s4z3yq.png)

If your payment is successful, the following screen will be displayed.

![SuccessPayment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z0kepgz39s6vifw2bxg4.png)

## Building a Stable Diffusion environment

We will build a Stable Diffusion environment with RunPod.

Go to the Secure Cloud and select the resources you want to use. In this case, we will choose the cheapest option, the **RTX A4000**.

![SelectResource](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ncn4oq212hr81se1q14m.png)

From the existing templates, select **RunPod Fast Stable Diffusion**.

![SelectFastStableDiffusion](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u1n103yio177p2ind5w2.png)

Once the confirmation screen is displayed, click **Deploy**.

![ConfirmDeploy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j3dml94t6kixm5depol9.png)

Click **My Pods** and check the deployed Pod.

![GoToMyPods](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t1fd6ihpxug8r4huajvi.png)

After confirming that the CPU usage has decreased, click **Connect** and then **Connect to Jupyter Lab**.

![ConnectToJupyterLab](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dhslxj7g4ap970qnexvz.png)

Open the **RNPD-A1111.ipynb** file.

![OpenRNPD-A1111.ipynb](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vu34wyainecypw8k6bgz.png)

Once the notebook is open, execute the cells in order from **Dependencies**, **Install/Update AUTOMATIC1111 repo**, **Model Download/Load**, **ControlNet**, to **Start Stable-Diffusion**.

When you run Start Stable-Diffusion, a URL like `Running on local URL: https://foobar-3000.proxy.runpod.net` will be displayed, so access it.

![StableDiffusionOnRunPod](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ray47q2cjrpoi91tdy09.png)

Enjoy generating images within the limits of your credit with the familiar interface.

To stop, click **Stop** in My Pods.

![StopPod](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nd2sci1zqsd2m9cohnti.png)

A confirmation screen will appear, so click **Stop Pod**.

![ConfirmStopPod](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r7b0xccvwdkamtdyg1t5.png)

As mentioned on the confirmation screen, RunPod will continue to charge you until the storage you are using is released, even after stopping the Pod. In the example above, $0.014 will be deducted per hour.

The only way to stop this is to click **Terminate** to completely delete the Pod.

![TerminatePod](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aj8p3a5kx3r2smwrd8ew.png)

## Saving RunPod data with Backblaze

As it stands, the generated images will be lost, so we will save them to Backblaze.

Go to Backblaze and click **Create a Bucket** from Buckets.

![CreateBucket](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nhmap6xvw5oboik8zys9.png)

Enter the Bucket Unique Name and click **Create a Bucket**.

![SetBucketProperties](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mvyj38lp5rhrbgvbgltz.png)

Next, go to Application Keys.

![GoToApplicationKeys](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lv0jxqq5ltlsbjpm82dj.png)

Click **Add a New Application Key** to issue a new key.

![AddNewApplicationKey](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/71w3oyfqz37w6dkfm9ke.png)

Enter the key name and specify the bucket you set earlier.

![SetApplicationKeyProperties](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o7gvm7irj5r1h2oba76j.png)

Take note of the **keyID** and **keyName** displayed here.

Return to RunPod and click **CloudSync**.

![ClickCloudSync](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/91dotm0atylwj0d2vd0u.png)

When the cloud storage selection screen appears, click **Backblaze B2**.

![SelectBackblazeB2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i41zn4znacw7xnfkng0y.png)

Click **Copy to Backblaze B2**.

![CopyToBackblazeB2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0yo9674wnujqdksx606m.png)

Enter the **keyID** and **keyName** you noted earlier as follows:

```
Account ID: keyID displayed when generating the key in Backblaze
Application Key: keyName displayed when generating the key in Backblaze
Bucket Path: {bucket} is the bucketName, {folder} is an appropriate name. ex: RunPodCloudSyncSDWebUI/fast-stable-diffusion
Pod Path: /workspace
```

![SetCloudSyncPropertiesTo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rp5b0qr97p8jo85q8l5d.png)

This will save the output results and properties of Stable Diffusion to Backblaze B2.

Once the upload is complete, you can check the specified folder in Backblaze's Browse Files to see that the files have been saved.

![BrowseFiles](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d8vzr4t2gyqsvv6h0vf4.png)

Now, even if you terminate the Pod, the generated images will not be lost. When launching the next Pod, click **Copy from Backblaze B2** to copy files from Backblaze B2, allowing you to continue generating images from where you left off.

## Conclusion

- If you frequently generate images with Stable Diffusion, Google Colab Pro is more cost-effective.
- If you only generate images occasionally with Stable Diffusion, RunPod's pay-as-you-go flexibility may be better.
- If you temporarily need more specs than those provided by Google Colab, such as for model training, RunPod is more suitable.