ComfyUI can not only be installed locally, but also run on cloud platforms. This article will introduce how to run ComfyUI on Google Colab, a convenient cloud-based method.
Google Colab (Colaboratory) is a free cloud-based Jupyter notebook environment provided by Google. It has the following features and advantages:
1. Free use: Google Colab provides free GPU and TPU resources, allowing users to run deep learning models without local hardware.
2. Preinstalled environment: Colab preinstalls many commonly used machine learning and data science libraries, such as TensorFlow, PyTorch, OpenCV, etc., which saves the hassle of environment configuration.
3. Collaboration features: It can easily share and collaborate with others to edit notebooks, which are ideal for team projects and teaching use.
4. Integration with Google Drive: You can load and save results directly from Google Drive, making it convenient for data management.
5. Run online: You only need a browser to run the code, without being restricted by the device and operating system.
6. Persistent storage: Although the running environment is temporary, the code and data can be saved to Google Drive to achieve persistent storage.
7. Community Support: There are a large number of sample notebooks and community support to learn and solve problems quickly.
For ComfyUI users, running ComfyUI with Google Colab can avoid the complexity of local installations, while leveraging the powerful computing resources in the cloud, especially for users without high-performance GPUs or newbies who want to try ComfyUI quickly.
If you are just trying to run ComfyUI, Google has provided a certain free usage limit. If you are using it for a long time, it is recommended to enable Colab Pro or Pro+. Register the activation address: https://colab.research.google.com/signup
Google Colab is a free cloud Jupyter notebook environment, which is very suitable for running ComfyUI, but it has a certain usage time limit. ComfyUI has the official corresponding scripts, you can find the corresponding files in comfyui_colab.ipynb.
The .ipynb file is in the Jupyter Notebook file format. Use this file to run on Google Colab to create a virtual environment for running various types of applications
The contents of this part are optional. If you don’t need additional models and install additional plug-ins, the instructions in this part will be relatively long. You can jump to the next part and start with the official default configuration. If you need to modify the configuration yourself, then check the contents of this part.
Under the default configuration, the official scripts provide fewer models and files to download. If you need to use some extra models, you can edit the comfyui_colab.ipynb file. It is recommended to download and install Vscode .ipynb to edit the official code. The main steps are provided by the following.
1. Environment settings Set the work environment and options, including whether to use Google Drive storage and whether to update ComfyUI. This section ensures that the required dependencies and files are configured correctly.
2. Download the model and checkpoints The required models and checkpoints are responsible for downloading the required models and checkpoints from external sources for subsequent use. Users can choose to download specific models as needed.
3. Run ComfyUI This part is divided into three sub-parts, providing different ways to access ComfyUI:
3.1 Create a tunnel through Cloudflared using Cloudflared to enable external users to access the running ComfyUI.
3.2 Using Localtunnel Use Localtunnel to generate an externally accessible link to access ComfyUI.
3.3 Use Colab IFrame to display the ComfyUI interface through an iframe in a Colab notebook, which facilitates users to operate in the same environment.
The first step is to configure the environment. We usually run it according to the default.
The second step will require the download of additional models and files, and provide downloads of commonly used models. In this step, we need to add adjustments and modifications as needed.
The third step is how to run ComfyUI after the installation is completed. We can select one of them as needed.
Use Vscode to open the code and edit it as follows
As shown in the picture below, we can notice that the official has written a prompt here
Original text: Download some models/checkpoints/vae or custom comfyui nodes (uncomment the commands for the ones you want) Chinese: Download some models/checkpoints/vae or custom comfyui nodes (uncomment the commands you want) You can see that there are notes in different parts with corresponding models, such as the Checkpoints model in the following part
# Checkpoints ### SDXL### I recommend these workflow examples: https://comfyanonymous.github.io/ComfyUI_examples/sdxl/ #!wget -c https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors -P ./models/checkpoints/#!wget -c https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors -P ./models/checkpoints/ # SDXL ReVision#!wget -c https://huggingface.co/comfyanonymous/clip_vision_g/resolve/main/clip_vision_g.safetensors -P ./models/clip_vision/ # SD1.5!wget -c https://huggingface.co/Comfy-Org/stable-diffusion-v1-5-archive/resolve/main/v1-5-pruned-emaonly-fp16.safetensors -P ./models/checkpoints/ # SD2#!wget -c https://huggingface.co/stabilityai/stable-diffusion-2-1-base/resolve/main/v2-1_512-ema-pruned.safetensors -P ./models/checkpoints/#!wget -c https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/v2-1_768-ema-pruned.safetensors -P ./models/checkpoints/
For example, in the default script, only SD1.5 model is downloaded.
# SD1.5!wget -c https://huggingface.co/Comfy-Org/stable-diffusion-v1-5-archive/resolve/main/v1-5-pruned-emaonly-fp16.safetensors -P ./models/checkpoints/
If you want to download additional models, then cancel the corresponding # in front of #!wget, and then the corresponding model will be downloaded to the corresponding path in actual operation. For example, if we want to download the SDXL model, then cancel the corresponding comment, as follows
!wget -c https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors -P ./models/checkpoints/!wget -c https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors -P ./models/checkpoints/
If you want to add a custom model, you can add the corresponding code in the source section
!wget -c File address -P . Model path
Just like downloading sd_xl_refiner_1.0.safetensors to the ./models/checkpoints/ folder below
"!wget -c https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors -P ./models/checkpoints/n",
If you are not familiar with which folder you should place in, please refer to the instructions in the comfyUI file structure section
The code examples of the installation custom plug-in provided in the official example are as follows
#!cd custom_nodes && git clone https://github.com/Fannovel16/comfy_controlnet_preprocessors; cd comfy_controlnet_preprocessors && python install.py
The code here is divided into several steps
1.!cd custom_nodes Enter the custom_nodes folder, which is the installation folder of the comfyUI plug-in
2.git clone https://github.com/Fannovel16/comfy_controlnet_preprocessors; Use git to clone the corresponding code into this folder, and it will create a comfy_controlnet_preprocessors folder under custom_nodes to store plug-in code.
3.cd comfy_controlnet_preprocessors Enter the newly cloned plugin folder
4.python install.py Use python to run scripts that install plug-in dependencies. You need to check the corresponding plug-in installation dependencies. Some plug-ins may not provide the install.py file but only require the requirements.txt file. The last command needs to be modified to pip install -r requirements.txt
For example, if you need to install the plugin ComfyUI-Manager , you need to build a command similar to the following
!cd custom_nodes && git clone https://github.com/ltdrdata/ComfyUI-Manager; cd pip install -r requirements.txt
This can achieve the purpose of installing the ComfyUI-Manager plug-in separately and installing related dependencies
After editing is completed, save the corresponding .ipynb file for subsequent processes.
First, you need a Google account. If not, please go to Google's official website Register one.
After logging into your Google Account, visit Google Colab .
Prepare (optional) the .ipynb file you modified
1. On the Colab page, click "Files/Files" > "Open Notebook" in the top menu bar.
2. In the pop-up window, select the "GitHub" tab. If it is a file you edited, select "Upload/upload"
3. Enter the following URL in the search box:
https://github.com/comfyanonymous/ComfyUI/blob/master/notebooks/comfyui_colab.ipynb
4. Click the comfyui_colab.ipynb file in the search results.
Once the notebook is opened, you will see a series of code cells.
Start at the top, click the play button to the left of each code cell, or use the shortcut key Shift+Enter to run the code.
You need to wait for the corresponding code to complete the running and display "done" before running the next code cell. First run the first two code cells to install the corresponding environment and dependencies. The subsequent code cells are used to select the running method.
In the provided configuration file, there are three ways to run. You only need to choose one of them to run.
Run ComfyUI with cloudflared (recommended)
Run ComfyUI with localtunnel
Run ComfyUI with colab iframe (when the second running mode is unavailable)
1. Run ComfyUI with cloudflared You will see
ComfyUI finished loading, trying to launch cloudflared (if it gets stuck here cloudflared is having issues)This is the URL to access ComfyUI: https://xxxxxx.trycloudflare.com
Click the last URL to access ComfyUI
2. Run ComfyUI with localtunnel After running, you will see something like
ComfyUI finished loading, trying to launch localtunnel (if it gets stuck here localtunnel is having issues)The password/enpoint ip for localtunnel is: 34.125.230.29your url is: https://xxxx.loca.lt
Click the last url and fill in the above password in the Tuneel Password of the opened page. For example, in my example, it is 34.125.230.29, so that it can run
3.Run ComfyUI with colab iframe
If you run this method, you don't need to open the URL. After the operation is completed, the operation interface will be displayed below the code block.
After use, remember to stop the corresponding running instance in time, otherwise the running time will be deducted.
The notebook files you have used will be automatically saved to your Google Drive. You can open the corresponding notebook files at any time, and then click the "Run" button in the upper right corner to run it again
After logging into your Google account https://drive.google.com/drive/my-drive
Click the Colab Notebooks folder
Find the .ipynb file you ran before and you will enter colab
Or save the URL of the corresponding interface and access it directly next time.
The free version of Google Colab has a time limit, usually several hours. If you need to use it for a long time, you can consider upgrading to a paid version.
After each use, remember to save your work and close the Colab notebook to free up resources.
Since it is running in the cloud, uploading and downloading files may be slightly slower than running locally.