How to deploy ComfyUI on a VM
ComfyUI is a node-based graphical user interface (GUI) designed for working with Stable Diffusion, a deep learning model that generates images from text prompts. It allows users to create and manage complex workflows for image generation by connecting various functional blocks called nodes. Each node represents a specific task or operation, such as loading a model, entering a prompt, or applying filters.
Step-by-Step Process to Deploy ComfyUI on GPU VM
For the purpose of this tutorial, we will use a GPU-powered Virtual Machine offered by NodeShift; however, you can replicate the same steps with any other cloud provider of your choice. NodeShift provides the most affordable Virtual Machines at a scale that meets GDPR, SOC2, and ISO27001 requirements.
Step 1: Sign Up and Set Up a NodeShift Cloud Account
Visit the NodeShift Platform and create an account. Once you've signed up, log into your account.
Follow the account setup process and provide the necessary details and information.
Step 2: Create a GPU Node (Virtual Machine)
GPU Nodes are NodeShift's GPU Virtual Machines, on-demand resources equipped with diverse GPUs ranging from H100s to A100s. These GPU-powered VMs provide enhanced environmental control, allowing configuration adjustments for GPUs, CPUs, RAM, and Storage based on specific requirements.
Navigate to the menu on the left side. Select the GPU Nodes option, create a GPU Node in the Dashboard, click the Create GPU Node button, and create your first Virtual Machine deployment.
Step 3: Select a Model, Region, and Storage
In the "GPU Nodes" tab, select a GPU Model and Storage according to your needs and the geographical region where you want to launch your model.
We will use 1x RTX A6000 GPU for this tutorial to achieve the fastest performance. However, you can choose a more affordable GPU with less VRAM if that better suits your requirements.
Step 4: Select Authentication Method
There are two authentication methods available: Password and SSH Key. SSH keys are a more secure option. To create them, please refer to our official documentation.
Step 5: Choose an Image
Next, you will need to choose an image for your Virtual Machine. We will deploy ComfyUI on an NVIDIA Cuda Virtual Machine. This proprietary, closed-source parallel computing platform will allow you to install ComfyUI on your GPU Node.
After choosing the image, click the 'Create' button, and your Virtual Machine will be deployed.
Step 6: Virtual Machine Successfully Deployed
You will get visual confirmation that your node is up and running.
Step 7: Connect to GPUs using SSH
NodeShift GPUs can be connected to and controlled through a terminal using the SSH key provided during GPU creation.
Once your GPU Node deployment is successfully created and has reached the 'RUNNING' status, you can navigate to the page of your GPU Deployment Instance. Then, click the 'Connect' button in the top right corner.
Now open your terminal and paste the proxy SSH IP or direct SSH IP.
Step 8: Clone ComfyUI Repository
Run the following command in terminal to clone the ComfyUI repository:
cd ~
git clone https://github.com/comfyanonymous/ComfyUI.git
cd ComfyUI
Step 9: Update the System
Run the following command in terminal to update the system:
sudo apt update
Step 10: Create Virtual Environment in Python
Run the following command in terminal to create the virtual environment in python:
sudo apt install python3-venv
Step 11: Creating a Virtual Environment for ComfyUI Using Python's venv
Module
Run the following command in terminal to creating a virtual environment for ComfyUI using Python's venv
module:
python3 -m venv comfyui-env
After creating the virtual environment, run the following command to activate it:
source comfyui-env/bin/activate
Step 12: Update the System and Install Vim
What is Vim?
Vim is a text editor. The last line of the text editor is used to give commands to vi and provide you with information.
Note: If an error occurs stating that Vim is not a recognized internal or external command, install Vim using the steps below.
Step 1: Update the package list
Before installing any software, we will update the package list using the following command in your terminal:
sudo apt update
Step 2: Install Vim
To install Vim, enter the following command:
sudo apt install vim -y
This command will retrieve and install Vim and its necessary components.
Step 13: Edit Configuration File
Run the following command in the terminal to enter in the ComfyUI configuration file:
sudo vim /etc/systemd/system/comfyui.service
Entering the editing mode in Vi:
Follow the below steps to enter the editing mode in Vim
Step 1: Open a File in Vim
Step 2: Navigate to Command Mode
When you open a file in Vim, you start in the command mode. You can issue commands to navigate, save, and manipulate text in this mode. To ensure you are in command mode, press the Esc key. This step is crucial because you cannot edit the text in other modes.
Add the following configuration (adjust the WorkingDirectory
path if necessary):
[Unit]
Description=ComfyUI Daemon
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/root/ComfyUI
ExecStart=/root/ComfyUI/comfyui-env/bin/python3 /root/ComfyUI/main.py
Restart=always
Environment=DISPLAY=:0
[Install]
WantedBy=multi-user.target
Save and close the file (Ctrl+X
, Y
, Enter
).
Step 14: Run ComfyUI using nohup
Execute the following command in terminal to run ComfyUI using nohup:
nohup /root/ComfyUI/comfyui-env/bin/python3 /root/ComfyUI/main.py > comfyui.log 2>&1 &
nohup
runs processes in the background and detaches them from the terminal.
Then, run the following command in terminal to check that it is running:
ps aux | grep main.py
Step 15: Run ComfyUI Interface
Execute the following command in terminal to run the ComfyUI interface:
tail -f comfyui.log
Step 16: Access VM with port forwarding and tunneling
To forward the ComfyUI port from your GPU VM to your local machine, use this SSH port forwarding command:
ssh -L 8188:localhost:8188 -i C:/Users/Acer/.ssh/id_rsa root@85.236.58.220 -p 11297
Explanation:
-L 8188:localhost:8188
: Forwards port 8188 from your local machine to port 8188 on the remote VM.-i C:/Users/Acer/.ssh/id_rsa
: Specifies the path to your private SSH key.root@85.236.58.220 -p 11297
: Connects as theroot
user to the VM at IP85.236.58.220
using port11297
.
After running this command, you can access the ComfyUI GUI in your local browser at http://127.0.0.1:8188
.
Conclusion
By following these steps, you have successfully deployed ComfyUI on a GPU-powered virtual machine using NodeShift. This setup allows you to leverage advanced image generation capabilities efficiently while ensuring compliance with industry standards. With your environment ready, you can now explore the powerful features of ComfyUI to create stunning visuals tailored to your needs. Enjoy harnessing the full potential of AI-driven image generation!