Skip to content

Add ComfyUI + Flux tutorial #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
{
"group": "Pods",
"pages": [
"tutorials/pods/comfyui-flux",
"tutorials/pods/run-your-first",
"tutorials/pods/run-fooocus",
"tutorials/pods/run-ollama",
Expand Down
197 changes: 197 additions & 0 deletions tutorials/pods/comfyui-flux.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
---
title: "Generate images with ComfyUI and Flux"
sidebarTitle: "Generate images with ComfyUI"
description: "Deploy ComfyUI on Runpod to create AI-generated images."
tag: "NEW"
---

This tutorial walks through how to configure ComfyUI on a [GPU Pod](/pods/overview), and use it to generate images using text-to-image models.

[ComfyUI](https://www.comfy.org/) is a node-based graphical interface for creating AI image generation workflows. Instead of writing code, you connect different components visually to build custom image generation pipelines. This approach provides flexibility to experiment with various models and techniques while maintaining an intuitive interface.

[Flux](https://huggingface.co/black-forest-labs/FLUX.1-dev) is a state-of-the-art text-to-image AI model developed by Black Forest Labs. It generates high-quality images from text descriptions and comes in three versions:

- **Flux Schnell**: An open-source model optimized for speed and cost.
- **Flux Dev**: An open-source model optimized for visual fidelity and prompt adherence.
- **Flux Pro**: A premium version available through API access.

The template used in this tutorial uses the Flux Dev model, but you can learn how to install other models (including non-Flux models) in the [Workflow customization](#install-missing-models) section.

## What you'll learn

In this tutorial you'll learn how to:

- Deploy a Pod with ComfyUI pre-installed.
- Connect to the ComfyUI web interface.
- Generate your first AI image.
- Browse pre-configured workflow templates.
- Download new models and workflow nodes to your Pod.

## Requirements

Before you begin, you'll need:

- A [Runpod account](/get-started/manage-accounts).
- At least $10 in credits.
- Basic understanding of AI image generation.

## Step 1: Deploy a ComfyUI Pod

First we'll deploy a Pod using a template that pre-installs ComfyUI and and the ComfyUI Manager plugin:

<Steps>
<Step title="Deploy a Pod from the ComfyUI template">
Navigate to the [Better Comfy Slim](https://console.runpod.io/explore/cndsag8ob0) template in the Runpod console and click **Deploy**.
</Step>

<Step title="Configure your Pod">
Configure your Pod with these settings:

- **GPU selection:** Choose an L40 or RTX 4090 for optimal performance with Flux models. Lower VRAM GPUs may work for smaller models.
- **Storage:** The default container and disk volume sizes set by the template should be sufficient for Flux Dev. You can also add a [network volume](/pods/storage/create-network-volumes) to your Pod if you want persistent storage.
- **Deployment type:** Select **On-Demand** for flexibility.
</Step>

<Step title="Deploy and wait">
Click **Deploy On-Demand** to create your Pod.

The Pod will take up to 30 minutes to initialize the container, download the Flux Dev model, and start the ComfyUI service.
</Step>
</Steps>

## Step 2: Open the ComfyUI interface

Once your Pod is finished initializing you can open the ComfyUI interface:

<Steps>
<Step title="Open your Pod in the console">
Navigate to the [Pods section](https://www.runpod.io/console/pods) in the Runpod console, then find your deployed ComfyUI Pod and expand it.

<Warning>
The Pod will take up to 30 minutes to initialize when first deployed, but if you stop and restart the Pod it generally takes much less time to reinitialize.
</Warning>
</Step>

<Step title="Start the ComfyUI service">
Click **Connect** on your Pod, then select **Connect to HTTP Service [Port 7860]**.

This will open the ComfyUI interface in a new browser tab. The URL follows the format: `https://[POD_ID]-7860.proxy.runpod.net`.

<Note>
If you see an error when first connecting, wait 2-3 minutes for the HTTP service to fully start, then refresh the page.
</Note>

</Step>

</Steps>



## Step 3: Import an example Flux workflow

The Pod template we deployed comes with the Flux Dev model pre-installed, but you'll need a valid workflow to use it. Follow these steps to import a pre-configured Flux workflow:

<Steps>
<Step title="Download the workflow file">
Visit the [flux-runpod repository](https://github.com/camenduru/flux-runpod/tree/main), locate the `Flux.1-Dev-ComfyUI.json` file, and click the download button in the top right corner of the code block.
</Step>

<Step title="Import into ComfyUI">
In the ComfyUI interface:
1. Click **Workflow** in the top right corner.
2. Select **Open**.
3. Select the `Flux.1-Dev-ComfyUI.json` file using the file browser to upload it.
</Step>
</Steps>

## Step 4: Generate your first image

Now the workflow is loaded, follow these steps to generate an image:

<Steps>
<Step title="Customize your prompt">
Locate the text input node labeled "CLIP Text Encode (Prompt)" in the workflow.

Click on the text field containing the default prompt and replace it with your desired image description.

Example prompts:
- "A serene mountain landscape at sunset with a crystal clear lake"
- "A futuristic cityscape with neon lights and flying vehicles"
- "A detailed portrait of a robot reading a book in a library"
</Step>

<Step title="Start generation">
Click **Run** at the bottom of the workflow (or press <kbd>Ctrl</kbd>+<kbd>Enter</kbd>) to begin the image generation process.

Watch as the workflow progresses through each node:
- Text encoding.
- Model loading.
- Image generation steps.
- Final output processing.
</Step>

<Step title="View your result">
The generated image appears in the output node when complete.

Right-click the image to save it to your local machine, view it at full resolution, or copy it to your clipboard.
</Step>
</Steps>

Congratulations! You've just generated your first image with ComfyUI on Runpod.

## Workflow customization

Once you're comfortable with basic image generation, explore the [ComfyUI documentation](https://docs.comfy.org/) to learn how to build more advanced workflows.

Here are ideas for where to start:

### Browse workflow templates

In the top-right corner of the ComfyUI interface, click **Workflow** and select **Browse Templates**. This will open a modal with a list of pre-configured workflows.

You can also browse the web for a preconfigured workflow and import it using the procedure from [Step 3](#step-3-import-a-flux-workflow).

### Install missing models

When you open a workflow, you may see a pop-up labeled **Missing Models**, indicating that the workflow requires additional models not present in your Pod. Clicking the **Download** button in the pop-up will download the model to your local machine rather than your running Pod. You can then use the [Runpod CLI](/runpodctl/overview) to [transfer the model files](/runpodctl/transfer-files) to your Pod.

You can also download the model directly to your Pod using the ComfyUI Manager plugin (which comes pre-installed in the ComfyUI Pod template we used). To install a model using the plugin:

1. Click **Manager** in the top right of the ComfyUI interface.
2. Select **Model Manager**.
3. Search for the model(s) you need.
4. Click **Install**.

### Create custom workflows

Build your own workflows by:

1. Right-clicking the canvas to add new nodes.
2. Connecting node outputs to inputs by dragging between connection points.
3. Saving your custom workflow clicking **Workflow** and selecting **Save**.

## Manage your Pod

While working with ComfyUI, monitor your usage by checking GPU utilization and generation times in the [Pods page](https://console.runpod.io/pods) of the Runpod console.

Stop your Pod when you're finished to avoid unnecessary charges.

It's also a good practice to download any custom workflows to your local machine before stopping the Pod. For persistent storage of models and outputs across sessions, consider using a [network volume](/pods/storage/create-network-volumes).

## Troubleshooting

Here are some common issues and solutions:

- **Connection errors**: Wait for the Pod to fully initialize (up to 30 minutes for initial deployment).
- **HTTP service not ready**: Wait at least 2-3 minutes after Pod deployment for the HTTP service to fully start.
- **Out of memory errors**: Reduce image resolution or batch size in your workflow.
- **Slow generation**: Ensure you're using an appropriate GPU for your selected model.

## Next steps

Now that you've mastered the basics of running ComfyUI on Runpod:

- Explore [other AI templates](/pods/templates/overview) available on Runpod.
- Learn about [persistent storage options](/pods/storage/types) for saving your work.
- Connect to your Pod [via SSH](/pods/configuration/use-ssh) for advanced customization.
- Join the [Runpod Discord](https://discord.gg/runpod) to share your creations and get support.