This guide will help you set up ComfyUI locally using Python, PyTorch, and Hugging Face.
- Python 3.x
- Git
- NVIDIA GPU with CUDA 12.1 or compatible
- A Hugging Face account
If you don't have access to a GPU locally, you can use a cloud provider such as AWS SageMaker Studio Labs to get a free GPU environment. Here's how:
- Go to AWS SageMaker Studio Labs.
- Sign up for an account or log in if you already have one.
- Once logged in, create a new project.
- Choose an environment that supports GPU (NVIDIA CUDA compatible).
- Start the instance and connect to the Jupyter environment.
- Use the terminal within Jupyter to follow the rest of the steps below.
For other GPU providers refer to this blog
Once you have access to a GPU environment, proceed with the setup steps.
First, create a directory for your project and clone the ComfyUI repository.
# Create and navigate to the project directory
mkdir comfyui-testing
cd comfyui-testing/
# Clone the ComfyUI repository from GitHub
git clone https://github.com/comfyanonymous/ComfyUI.gitCreate and activate a virtual environment to isolate the Python dependencies.
# Create a virtual environment
python -m venv .venv
# Activate the virtual environment
source ./.venv/bin/activateIf you have an NVIDIA GPU, you can check its status with the following command:
nvidia-smiInstall PyTorch, TorchVision, and Torchaudio with CUDA support (12.1 version) for GPU acceleration.
pip install torch torchvision torchaudioNavigate to the ComfyUI directory and install the required dependencies from the requirements.txt file.
cd ComfyUI/
pip install -r requirements.txtNow that the dependencies are installed, you can start the ComfyUI application.
# Run the application
python main.pyTo make your local server accessible externally, you can use Ngrok. Install it and set it up as follows:
pip install ngrok# import ngrok python sdk
import ngrok
import time
# Establish connectivity
listener = ngrok.forward(8188, authtoken_from_env=True)
# Output ngrok url to console
print(f"Ingress established at {listener.url()}")
# Keep the listener alive
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("Closing listener")# Run ngrok with your auth token from https://dashboard.ngrok.com/
NGROK_AUTHTOKEN=<YOUR_NGROK_TOKEN> python ngrok-python.pyInstall the Hugging Face CLI tool to download models and log in to your account using https://huggingface.co/settings/tokens
pip install -U "huggingface_hub[cli]"
# Log in to Hugging Face
huggingface-cli login
# Verify login
huggingface-cli whoami- Download a checkpoint file Place the file under ComfyUI/models/checkpoints.
huggingface-cli download Comfy-Org/stable-diffusion-v1-5-archive v1-5-pruned-emaonly.safetensors --local-dir .-
Refresh the ComfyUI.
-
Click Load Default button to use the default workflow.
-
In the Load Checkpoint node, select the checkpoint file you just downloaded.
-
Click Queue Prompt and watch your image generated. Play around with the prompts to generate different images.
- AWS SageMaker Studio Labs
- PyTorch Installation Guide
- ComfyUI Docs
- Hugging Face CLI Documentation
- ngrok Docs
You have now successfully set up ComfyUI locally. You can access the interface via your local server, or use Ngrok for external access.