Featured image of post Stable Diffusion in the Cloud Set up

Stable Diffusion in the Cloud Set up

Objective

Just to document my set up so I can come back and refer to it. And for this to be newbie friendly.

To set up an online cloud environment to run Stable Diffusion to create AI video (with ComfyUI and AnimateDiff).

It would save me money via:

  • Electricity Cost
  • Graphic Card (which will depreciate overtime with new technology)

Real life reason:

I ran out of memory and it crash my queue when I was doing AnimateDiff. 6GB VRAM on my laptop wasn’t enough and it took over 16 hours to run a partial portion of it.

Cloud Provider

https://www.runpod.io/

I use Runpod because that’s the first option I’ve found.

I also found a tutorial on setup via youtube: ComfyUI AnimateDiff Prompt Travel: Runpod.io Cloud GPUs Tutorial by c0nsumption

Setting up a Pod (a GPU cloud instance)

To start spinning up a new instance first click on the ‘New Pod’ option over at the console.

Spinning up a new pod.

Pod Console

New pod console.

Pod Template

Make sure Pod Template is set to: ‘RunPod SD Comfy UI’

Pod Template.

Pod Cloud Type

Select cloud type using the Cloud Type drop down filter menu. I chose the ‘Community Cloud’ option because it’s cheaper.

Pod Cloud Type.

Pod Cloud Type Options.

Select GPU

I chose this option for my first run.

Click the option, ‘Customize Deployment’.

Customize Deployment button.

And change Container Disk to 25GB. Some installation package will eat up more than 5GB (default).

Customize Deployment button.

Click the option, ‘Deploy’.

You will end up with the next menu, check all the option is correct. Make sure the ‘Start Jupyter Notebook’ checkbox is checked. Once confirming that the GPU instance configurations is correct click on the button, ‘Continue’.

Pod Cloud confirmation. Yes the graphic on the console is messed up. That’s how it’s render in Chrome browser.

Deploy GPU Instance

Look over the pricing summary for the extra/hidden cost on top of the GPU pricing rate. Once you’re okay with the total cost, click on the button ‘Deploy’.

Pod Cloud Instance Pricing Summary. Yes the graphic on the console is messed up. That’s how it’s render in Chrome browser.

It’ll redirect you to the Pod Console where your new instance is now created but not started.

Pod Console with your new pod instance.

More info on the pod by clicking the purple arrow button.

Pod Info

Pod Customization

Set up ComfyUI port 8188

IMPORTANT

Click on the hamburger button (the three horizontal line button) aka More Actions.

Hamburger

Select ‘Edit Pod’.

Hamburger Options

You should get this menu.

Edit Pod menu.

  1. From the menu above, locate ‘Expose TCP Ports’.
  2. Add 8188 to that field. Note you should now have ‘22,8188’ (see picture below).
  3. Port 8188 is the default ComfyUI port.

Expose TCP Ports. Add in port 8188.

Click Save.

Pod ComfyUI Setup

Connect to Juypter

Click on the ‘Connect’.

Connect

You’ll get this menu:

Connect menu.

Select the option Connect to Jupyter Lab [Port 8888]. This will open a new tab in your browser with Jupyter Lab.

Connect to Jupyter Lab Port 8888.

Jupyter Lab Terminal

From the Other menu, select the Terminal option.

Jupyter Lab Other menu options.

From here you should get this terminal:

Jupyter Lab Terminal.

NOTE/WARNING: Anything in the /workspace directory will persist and exist after you stop your instance. Anything outside of this folder will not persist.

Jupyter Lab Leftside Panel File Explorer.

Setup Python Virtual Environment

Type below into Jupyter’s terminal:

1
python -m venv venv

Setup Python Virtual Environment.

Setup Python Virtual Environment.

Activate virtual environment:

1
source venv/bin/activate

Activate Python Virtual Environment.

Latest ComfyUI version

Get the latest ComfyUI version.

1
2
cd /workspace/ComfyUI
git pull

ComfyUI setup Nvidia

Following the Linux Nvidia installation instruction.

Type the commands below in Jupyter Terminal:

1
2
cd ComfyUI
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121

Then do this:

1
pip install -r requirements.txt

ComfyUI Manager Installation

Go to the custom_nodes folder:

1
cd /workspace/ComfyUI/custom_nodes/

Once in the custom_nodes folder, we going to do git clone.

1
git clone https://github.com/ltdrdata/ComfyUI-Manager.git

Start ComfyUI

1
2
cd /workspace/ComfyUI/
python main.py --listen

Connect to ComfyUI

Go back to Pod Console, click on the Connect button.

Pod Console.

Notice the Public IP and External port across from Internal port 8188 (ComfyUI default port).

That’s how you get you to comfyui in your browser:

Public IP:External

Public IP:40007

Pod TCP port mappings.

Download Models from Civic AI

Make sure you close ComfyUI if it’s running.

At the Jupyter Terminal shortcut, Ctrl + c.

Go to the ComfyUI models folder:

1
cd /workspace/ComfyUI/models

ComfyUI’s models folder.

Checkpoint Models

Go to checkpoint model directory:

1
cd /workspace/ComfyUI/models/checkpoints

You can list all that’s inside the folder with ls.

Go to Civic AI and find a checkpoint model you like

Make a Civic AI account (it’s free).

Civic AI search options.

For the search option click on the Filters option.

These are all the options in the Filters option menu (make sure you scroll down for more options):

Civic AI Filters options.

Civic AI Filters options continue.

My chosen checkpoint, GhostMix, for this tutorial:

Civic AI chosen checkpoint

Click on it to head to the main page of chosen checkpoint.

Civic AI chosen checkpoint page

right click on the Download button and select Copy Link.

The link address should be copied and it should be this:

1
https://civitai.com/api/download/models/76907

Find out the file name of the check point by downloading it to local computer and cancel the download:

Civic AI chosen checkpoint file name.

File name:

ghostmix_v20Bakedvae.safetensors

Download Chosen Checkpoint into your pod

Head over to your pod Jupyter Notebook’s terminal.

Make sure you are in the checkpoint folder.

1
cd /workspace/ComfyUI/models/checkpoints

Now download the chosen model:

1
wget -O ghostmix_v20Bakedvae.safetensors https://civitai.com/api/download/models/76907 

So the format is:

1
wget -O filename_with_extension model_url 

Type ls to make sure the model is downloaded.

Starting Workflow

Start up Python’s virtual environment

1
source venv/bin/activate

Start up ComfyUI

1
2
cd /workspace/ComfyUI/
python main.py --listen

`

Conclusion

So that’s basically it for the set up.

Now you need a workflow and download models that the workflow require. I’ll make another post on AnimateDiff workflow using this base setup.

Credits

comments powered by Disqus

Desiderata by Max Ehrmann

Go placidly amid the noise and the haste, and remember what peace there may be in silence. As far as possible without surrender be on good terms with all persons. Speak your truth quietly and clearly; and listen to others, even to the dull and the ignorant, they too have their story. Avoid loud and aggressive persons, they are vexations to the spirit.

If you compare yourself with others, you may become vain or bitter; for always there will be greater and lesser persons than yourself. Enjoy your achievements as well as your plans. Keep interested in your own career, however humble; it is a real possession in the changing fortunes of time.

Exercise caution in your business affairs, for the world is full of trickery. But let not this blind you to what virtue there is; many persons strive for high ideals, and everywhere life is full of heroism. Be yourself. Especially do not feign affection. Neither be cynical about love; for in the face of all aridity and disenchantment it is as perennial as the grass. Take kindly the counsel of the years, gracefully surrendering the things of youth.

Nurture strength of spirit to shield you in sudden misfortune. But do not distress yourself with dark imaginings. Many fears are born of fatigue and loneliness. Beyond a wholesome discipline, be gentle with yourself. You are a child of the universe, no less than the trees and the stars; you have a right to be here. And whether or not it is clear to you, no doubt the universe is unfolding as it should.

Therefore, be at peace with God, whatever you conceive Him to be. And whatever your labors and aspirations in the noisy confusion of life, keep peace in your soul. With all its sham, drudgery and broken dreams; it is still a beautiful world. Be cheerful.

Strive to be happy.

Built with Hugo
Theme Stack designed by Jimmy