How to run ComfyUI on Google Colab

Updated Categorized as Tutorial Tagged , , 27 Comments on How to run ComfyUI on Google Colab

ComfyUI is a popular way to run local Stable Diffusion and Flux AI image models. It is a great complement to AUTOMATIC1111 and Forge. Some workflows may require a good GPU to run.

In this article, you will find instructions on how to run ComfyUI on Google Colab using the notebook I maintain.

What is ComfyUI?

This is a detailed guide for ComfyUI on Google Colab. You can access the notebook by getting the Quick Start Guide.

If you are a site member, log in and access the notebook below.

Become a member of this site to see this content

Already a member? Log in here.

This notebook shares models with the following notebooks in Google Drive.

Using ComfyUI on Google Colab

Google Colab (Google Colaboratory) is an interactive computing service offered by Google. It is a Jupyter Notebook environment that allows you to execute code.

Due to the computing resources required (High RAM), you need a Google Pro and Pro+ to run ComfyUI on Colab.

I recommend using the Colab Pro plan. It gives you 100 compute units per month on T4, which are about 50 hours on a standard GPU. (It’s a steal)

Alternatives

Think Diffusion provides fully managedComfyUI/AUTOMATIC1111/Forge online service. They cost a bit more than Colab but provide a better user experience by installing models and extensions. They offer 20% extra credit to our readers. (Affiliate link)

Running ComfyUI on Colab

Step 0: Sign up

Sign up a Google Colab Pro or Pro+ plans. (I use Pro.)

Step 1: Open the ComfyUI Colab notebook

Open the ComfyUI Colab notebook in the Quick Start Guide. You should see the notebook with the second cell below.

Note: For quick start, you can skip the following steps and run the notebook with the default settings.

Step 2: Select models

Review which models you want to use.

The more you select, the longer it takes to download. They will be downloaded to the Colab drive, not your Google Drive.

Step 3: Run the notebook

Click the Play button on the left of the cell to start.

The notebook will ask for permission to access your Google Drive. Grant permission as it is necessary to save the images and access the models in your Google Drive.

The start-up should be completed within a few minutes. The time depends on how many models you include. When it is done, you should see the message below.

Step 4: Start ComfyUI

Visit the URL to access ComfyUI. You will need the Tunnel Password listed above the link.

Step 5: Generate an image

Select the DreamShaper_8 model.

Click Queue Prompt on the right sidebar.

Faster connection with ngrok (Optional)

If you run into connection issues with ComfyUI, you can try using ngrok instead of local tunnel to establish the public connection. It is a more stable alternative.

You will need to set up a free account and get an authoken.

  1. Go to https://ngrok.com/
  2. Create an account
  3. Verify email
  4. Copy the authoken from https://dashboard.ngrok.com/get-started/your-authtoken and paste it into the NGROK field in the notebook.

Input and Output folders

The default input folder is AI_PICS > inputs in your Google Drive.

The default output folder is AI_PICS > outputs in your Google Drive.

Speeding up image generation

You can pick a faster runtime type to speed up the generation, which costs more per hour.

Click downward caret on the top right and then select Change runtime type.

When you are done

When you finish using the notebook, don’t forget to click “Disconnect and delete runtime” in the top right drop-down menu. Otherwise, you will continue to consume compute credits.

Computing resources and compute units

Computing units and usage rate.

To view computing resources and credits, click the downward caret next to the runtime type (E.g. T4, High RAM) on the top right. You will see the remaining compute units and usage rate.

Models available

For your convenience, the notebook has options to load some popular models. You will find a brief description of them in this section.

Flux models

Flux AI is a state-of-the-art AI model that produces stunning images.

v1.5 models

Stable Diffusion 1.5

The Stable Diffusion 1.5 model is the officially released model which is trained with diverse styles.

Realistic Vision

Realistic Vision v2 is suitable for generating anything realistic, whether they are people, objects, or scenes.

Dreamshaper

Dreamshaper

Model Page

Dreamshaper is easy to use and good at generating a popular photorealistic illustration style. It is an easy way to “cheat” and get good images without a good prompt!

Anything v3

Anything v3 model.

Model Page

Anything V3 is a special-purpose model trained to produce high-quality anime-style images. You can use danbooru tags (like 1girl, white hair) in the text prompt.

It’s useful for casting celebrities to amine style, which can then be blended seamlessly with illustrative elements.

SDXL 1.0 model

SDXL

This Coalb notebook supports the SDXL 1.0 base model.

Select SDXL_1 to load the SDXL 1.0 model.

Check out some SDXL prompts to get started.

JuggernautXL

The Juggernaut XL model is all-rounded for diverse styles. It is especially good at realistic images.

Pony Diffusion XL

The Pony Diffusion XL model excels in creative artistic images. See also the prompt tags for Pony XL.

ControlNet models

You need the ControlNet models to use the ControlNet custom node.

Alternatively, you can put the ControlNet models in the Google Drive folder AI_PICS > models > ControlNet.

Installing models

There are two ways to install models not on the model selection list.

  1. Use ComfyUI Manager.
  2. Put model files in your Google Drive.

Install models using ComfyUI Manager

Click the Manager button > Model Manager.

Use the filter to narrow down the model type.

Installing models in Google Drive

After running the notebook for the first time, you should see the folder AI_PICS > models created in your Google Drive. The folder structure inside this folder mirrors AUTOMATIC1111‘s and is designed to share models with:

Put your model files in the corresponding folder. For example,

  • Put checkpoint model files in AI_PICS > models > Stable-diffusion.
  • Put LoRA model files in AI_PICS > models > Lora.

You will need to restart the notebook to see the new models.

Notebook secrets

This notebook supports storing API keys in addition to Secrets. If the keys were defined in secrets, the notebook would always use them. The notebook currently supports these two API keys (All upper cases):

  • NGROK: Ngrok API key.

You will need to enable Notebook access for each key like above.

Custom nodes

Installing a custom node

You can use ComfyUI Manager to install custom nodes. Click Manager > Install custom nodes.

Search and select a custom node to install.

Click the Restart button AND refresh the ComfyUI page after installation.

The custom nodes are stored in your Google Drive: AI_PICS > ComfyUI > custom_nodes.

Removing a custom node

Delete the custom node’s folder in AI_PICS > ComfyUI > custom_nodes to remove a custom node.

Extra arguments to ComfyUI

You can add any extra command line arguments to the Extra_arguments field.

Frequently asked questions

Do I need a paid account to use the notebook?

Yes, you need a paid Google Colab account to use this notebook. Google has blocked the free usage of Stable Diffusion.

Is there any alternative to Google Colab?

Think Diffusion provides fully-managed Forge/AUTOMATIC1111/ComfyUI WebUI web service. They offer 20% extra credit to our readers. (Affiliate link)

How do you resolve an out-of-memory error?

The T4 runtime type has 15 GB of VRAM. You can select a runtime type of higher memory, such as L4 or A100. (They cost more.)

Can I use the checkpoint and LoRA models I trained?

Yes, put the model file in the corresponding folder in Google Drive.

  • Checkpoint models: AI_PICS > models > Stable-diffusion.
  • LoRA models: AI_PICS > models > Lora.

How do I use the Flux.1 Dev model?

How long does it take to generate a Flux image?

It depends on the runtime type. Using the Flux1 Dev FP8 model:

  • T4: 2 mins.
  • L4: 50 secs.

Select Runtime > Change runtime type to change.

Next Step

Avatar

By Andrew

Andrew is an experienced engineer with a specialization in Machine Learning and Artificial Intelligence. He is passionate about programming, art, photography, and education. He has a Ph.D. in engineering.

27 comments

  1. ok i see u dont need to enter a username or password. just leave it as it is and enter it as “a” and “a” when prompted.

    why do i need to give full access to my google drive. i dont like that and seems scammy. i would suggest anyone using this to create a new google account so this site doesnt have access to your entire google drive to add create delete view whatever they want.

  2. Thank you for this guide. Can you tell me how to save the output images? If it’s automatic, I don’t see it in my Output folder on my google drive. Do I need to click on anything to save the image? Please advise. Also the queue box I have

    1. It is in your google drive AI_PICS > outputs.
      Whether images would be saved automatically depends on the workflow itself. You can always right click the image and save to your PC.

  3. Hey Andrew! Really loving the notebook and thank you so much for putting it together for us! I’ve run into a situation where my NGROK “account has exceeded its http requests limit” and need to upgrade to their paid plan which is very much not ideal for me.. and the local tunnel gives me such an insane amount of problems to use that it stops becoming worth it.

    Are there any other alternatives other than NGROK or the local tunnel??

  4. hi Andrew,
    Why is it’s not possible to download models to a folder in google drive, so that they don’t have to be downloaded each time?

      1. They actually won’t be saved in google drive by design. Some models are large and saving them in google drive may cause out of space error.

        You can put them in google drive manually if you want to so that you don’t need to redownload.

  5. hi Andrew,

    cannot use upscalers on comfyui colab

    i understand that there should be a folder
    AI_PICS>models>upscale_models
    so i created one manually
    but i get for example:
    “Value not in list: model_name: ‘RealESRGAN_x2.pth’ not in []”
    comfyui does not seem to read the content of that folder….. and the upscalers i put there….
    thank you
    🙂

    nami

  6. The local tunnel is giving me an OBSCENE amount of issues…. I know you mentioned copy/pasting the authoken from ngrok in the “NGROK field in the notebook”, but the Colab Notebook I picked up from your GumRoad doesn’t have an ngrok field in it

  7. Hi Andrew, thank you for improving this workbook. with every update, it’s getting better and better. there are 2 things I would like to ask:
    1) Loras – is there any limitation (size) on the Loras? I can select almost all Loras I uploaded to google drive, but some are not visible… for example Flux turbo lora (which has 600mb+) is not visible for selection in comfyui environment
    2) xlab controlnets – is there any way to use these? normally they are stored in xlab directory in Comfyui models folder in my local installation.

    thanks for great works
    regards
    Pavel

  8. Hello Andrew, getting this error when I try to use FLUX. CheckpointLoaderSimple
    Error while deserializing header: HeaderTooLarge

    any idea how to fix it, please?

      1. thank you Andrew. it works now. BTW is there a way to instal custom nodes? or this is just for basic workflow with built-in nodes?

          1. Hi Andrew, I was trying to instal impact-pack through manager, but it didn’t work due to security level. can the security level can be somehow changed when starting comfyui or could you add comyui impact pack installation into the workbook, please?

          2. OK, I found the issue. This custom node doesn’t like to be in google drive. Please use the updated notebook (11/2) and don’t select “SAVE_CUSTOM_NODES_IN_GOOGLE_DRIVE” (default).

  9. I earlier used your stable diffusion colab link and I could add loras by copy them to my lora folder. Now bo lora is shown, tried even to copy loras link for flux loras into the colab notebook before I run it but no luck… should I try to delete the whole folder AI_pics and try again?

    1. I just tested the comfyui notebook. The loras in google drive is loading correctly.

      Note that there’s a change in the lora folder location. The model folder structure now mirrors A1111’s. So AI_PICS > models > Lora.

      You can rename the AI_PICS folder in google drive to AI_PICS_OLD. A new folder with model folder structure will be regenerated.

  10. I’m having trouble getting this to work! 🙂 It did run fine for me the first time I tried, but now, not so much.
    The code in the notebook runs fine, no errors that I can find. When I click on the link for the local tunnel I get the login page, then I get either a blank white screen, or I get the ComfyUI page but the potion where the graph goes just spins and spins. Also, the ComfyUI manager does not get loaded (though it did the first time I ran everything). If I try to reload the page I get “Error loading workflows: Error getting user data list ‘workflows’: 502”

    I’m running it on Google Collab with this notebook: and using all the defaults set in the notebook.

    1. it is working but the connection is unstable. I will add another connection option when I got a chance. In the meantime, it can be resolved by refreshing the page.

Leave a comment

Your email address will not be published. Required fields are marked *