Skip to content
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

docs: Add comfyUI example doc #5148

Open
wants to merge 1 commit 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
175 changes: 169 additions & 6 deletions docs/source/examples/comfyui.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,172 @@
=======
ComfyUI
=======
=================================
ComfyUI: Deploy workflows as APIs
=================================

`ComfyUI <https://github.com/comfyanonymous/ComfyUI>`_ is a powerful tool for designing advanced diffusion pipelines. However, once the pipelines are built, deploying and serving them as API endpoints can be challenging and not very straightforward.
`ComfyUI <https://github.com/comfyanonymous/ComfyUI>`_ is a powerful tool for designing advanced diffusion workflows. It provides an extensive collection of resources, including shared workflows and custom nodes, to help creative workers and developers generate content without dealing with complex code. However, deploying and serving these workflows as scalable API endpoints can be `complex and non-intuitive <https://www.bentoml.com/blog/comfy-pack-serving-comfyui-workflows-as-apis>`_.

Recognizing the complexity of ComfyUI, BentoML provides a non-intrusive solution to serve existing ComfyUI pipelines as APIs without requiring any pipeline rewrites. It also offers the flexibility to customize the API endpoint's schema and logic.
To address the deployment challenges, the BentoML team developed `comfy-pack <https://github.com/bentoml/comfy-pack>`_, a comprehensive toolkit that transforms ComfyUI workflows into production-grade APIs. Specifically, comfy-pack enables you to:

For detailed information, see the `comfy-pack repository <https://github.com/bentoml/comfy-pack>`_ and the `release blog post <https://www.bentoml.com/blog/comfy-pack-serving-comfyui-workflows-as-apis>`_.
- Define standardized API schemas for workflow inputs and outputs
- Serve workflows as HTTP endpoints accessible via standard API clients
- Deploy workflows to BentoCloud with enterprise-grade features such as fast autoscaling and built-in observability
- Package the complete workspace as portable artifacts for consistent reproduction

Installation
------------

You can install comfy-pack using either `ComfyUI Manager <https://github.com/ltdrdata/ComfyUI-Manager>`_ or Git.

.. tab-set::

.. tab-item:: ComfyUI Manager (Recommended)

1. Open **ComfyUI Manager**.
2. Search for ``comfy-pack`` and click **Install**.

.. image:: ../../_static/img/examples/comfyui/install-comfy-pack-via-comfyui-manager.png
:alt: Install comfy-pack via ComfyUI Manager

3. Click **Restart** and refresh your ComfyUI interface to apply changes.

.. tab-item:: Git

Clone the repository into your ComfyUI custom nodes directory:

.. code-block:: bash

cd ComfyUI/custom_nodes
git clone https://github.com/bentoml/comfy-pack.git

Specify input and output nodes
------------------------------

When serving ComfyUI workflows as APIs, one key challenge is establishing a standardized schema for workflow inputs and outputs. comfy-pack addresses this by providing dedicated interface nodes that integrate seamlessly with existing workflows without affecting their core functionality.

1. Right-click a node containing the widget you want to expose.
2. Select **Convert Widget to Input**, then choose the widget name.
3. To add a comfy-pack input node:

a. Right-click anywhere on the blank space.

b. Navigate to **Add Node > ComfyPack > input**, then select the desired input node type:

- **Image Input**: Accepts image type input, similar to the official ``LoadImage`` node.
- **String Input**: Accepts string type input (e.g., prompts).
- **Int Input**: Accepts integer type input (e.g., dimensions, seeds).
- **File Input**: Accepts file type input.
- **Any Input**: Accepts combo type and other input (e.g., custom nodes).

4. Connect the comfy-pack input node to the widget you converted previously.

.. image:: ../../_static/img/examples/comfyui/add-comfy-pack-input-node.gif
:alt: Add comfy-pack input node

5. To add a comfy-pack output node:

a. Right-click anywhere on the blank space.

b. Navigate to **Add Node > ComfyPack > output**, then select the desired output node type:

- **File Output**: Outputs a file path as a string and saves the file to the specified location.
- **Image Output**: Outputs an image, similar to the official ``SaveImage`` node.

6. Connect the workflow's output to the comfy-pack output node.

.. image:: ../../_static/img/examples/comfyui/add-comfy-pack-output-node.gif
:alt: Add comfy-pack output node

7. Run the workflow to ensure it functions as expected.

Serve workflows as APIs
-----------------------

You can expose ComfyUI workflows as HTTP APIs that can be called from any client.

1. On the toolbar at the top of the screen, click **Serve**.
2. Set the desired port (default: ``3000``).
3. Click **Start** to launch the server. The API will be available at ``http://127.0.0.1:<port>``.
4. The server exposes a ``/generate`` endpoint. Use it to submit requests with parameters configured through comfy-pack nodes (e.g., ``prompt``, ``width``, ``height``, ``seed``). For example:

.. tab-set::

.. tab-item:: CURL

.. code-block:: bash

curl -X 'POST' \
'http://127.0.0.1:3000/generate' \
-H 'accept: application/octet-stream' \
-H 'Content-Type: application/json' \
--output output.png \
-d '{
"prompt": "rocks in a bottle",
"width": 512,
"height": 512,
"seed": 1
}'

.. tab-item:: Python client

comfy-pack uses BentoML as its serving framework, allowing you to use the :doc:`BentoML Python client </build-with-bentoml/clients>` for interaction:

.. code-block:: python

import bentoml

with bentoml.SyncHTTPClient("http://127.0.0.1:3000") as client:
result = client.generate(
prompt="rocks in a bottle",
width=512,
height=512,
seed=1
)

.. important::

Parameter names in API calls must match your comfy-pack node names.

Deploy to BentoCloud
--------------------

You can deploy your ComfyUI workflow to BentoCloud for better management and scalability.

1. On the toolbar at the top of the screen, click **Deploy**.
2. In the dialog that appears, set a name and select required models and system packages.
3. Enter your BentoCloud access token. If you don't have a BentoCloud account, `sign up for free <https://www.bentoml.com/>`_ and :doc:`create a token </scale-with-bentocloud/manage-api-tokens>`.
4. Click **Push to Cloud** and wait for your Bento to be built.
5. Once it's ready, click **Deploy Now** to open the Bento details page on BentoCloud.
6. Deploy the Bento from the BentoCloud console.

Package and restore a workspace
-------------------------------

You can package a ComfyUI workspace into a portable artifact, ensuring it can be easily transferred and unpacked elsewhere with consistent behavior.

Create a package
^^^^^^^^^^^^^^^^

1. On the toolbar at the top of the screen, click **Package**.
2. Set a name for the package.
3. (Optional) Choose which models to include. Note that only model hashes are stored, not the actual files. This keeps package size minimal while ensuring version accuracy.
4. Click **Pack**. Your browser will automatically download a ``.cpack.zip`` file.

Restore a workspace
^^^^^^^^^^^^^^^^^^^

1. Install comfy-pack CLI:

.. code-block:: bash

pip install comfy-pack

2. Unpack the ``.cpack.zip`` file:

.. code-block:: bash

comfy-pack unpack <workflow_name>.cpack.zip

When unpacking, comfy-pack restores the original ComfyUI workspace by performing the following steps:

1. Prepares a Python virtual environment with the exact packages used in the workflow.
2. Clones the specific ComfyUI version and custom nodes, pinned to the exact versions required by the workflow.
3. Searches for and downloads models from common registries like Hugging Face and Civitai. It uses symbolic links for efficient model sharing (i.e., models are downloaded only once and reused across workflows) and verifies model integrity via hash checking.
8 changes: 4 additions & 4 deletions docs/source/examples/controlnet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ The server is active at `http://localhost:3000 <http://localhost:3000>`_. You ca

Visit `http://localhost:3000 <http://localhost:3000/>`_, scroll down to **Service APIs**, specify the image and parameters, and click **Execute**.

.. image:: ../../_static/img/use-cases/diffusion-models/controlnet/service-ui.png
.. image:: ../../_static/img/examples/controlnet/service-ui.png

This is the example image used in the request:

.. image:: ../../_static/img/use-cases/diffusion-models/controlnet/example-image.png
.. image:: ../../_static/img/examples/controlnet/example-image.png

Expected output:

.. image:: ../../_static/img/use-cases/diffusion-models/controlnet/output-image.png
.. image:: ../../_static/img/examples/controlnet/output-image.png

Deploy to BentoCloud
--------------------
Expand Down Expand Up @@ -217,7 +217,7 @@ First, specify a configuration YAML file (``bentofile.yaml``) to define the buil

Once the Deployment is up and running on BentoCloud, you can access it via the exposed URL.

.. image:: ../../_static/img/use-cases/diffusion-models/controlnet/controlnet-bentocloud.png
.. image:: ../../_static/img/examples/controlnet/controlnet-bentocloud.png

.. note::

Expand Down
6 changes: 3 additions & 3 deletions docs/source/examples/function-calling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ The application processes this request and responds by converting USD to CAD usi

This example is ready for easy deployment and scaling on BentoCloud. With a single command, you can deploy a production-grade application with fast autoscaling, secure deployment in your cloud, and comprehensive observability.

.. image:: ../../_static/img/use-cases/large-language-models/function-calling/function-calling-playground.gif
.. image:: ../../_static/img/examples/function-calling/function-calling-playground.gif

Architecture
------------

This example includes two BentoML Services, a Currency Exchange Assistant and an LLM. The LLM Service exposes an OpenAI-compatible API, so that the Exchange Assistant can call the OpenAI client. Here is the general workflow of this example:

.. image:: ../../_static/img/use-cases/large-language-models/function-calling/function-calling-diagram.png
.. image:: ../../_static/img/examples/function-calling/function-calling-diagram.png

1. A user submits a query to the Exchange Assistant's Query API, which processes the query and forwards it to the LLM to determine the required function and extract parameters.
2. With the extracted parameters, the Query API invokes the identified Exchange Function, which is responsible for the exchange conversion using the specified parameters.
Expand Down Expand Up @@ -260,7 +260,7 @@ BentoCloud provides fast and scalable infrastructure for building and scaling AI

.. tab-item:: BentoCloud Playground

.. image:: ../../_static/img/use-cases/large-language-models/function-calling/function-calling-playground.png
.. image:: ../../_static/img/examples/function-calling/function-calling-playground.png

.. tab-item:: Python client

Expand Down
6 changes: 3 additions & 3 deletions docs/source/examples/langgraph.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ Example output:

This example is ready for easy deployment and scaling on BentoCloud. You can use either external LLM APIs or deploy an open-source LLM together with the LangGraph agent. With a single command, you get a production-grade application with fast autoscaling, secure deployment in your cloud, and comprehensive observability.

.. image:: ../../_static/img/use-cases/large-language-models/langgraph/langgraph-agent-on-bentocloud.png
.. image:: ../../_static/img/examples/langgraph/langgraph-agent-on-bentocloud.png

Architecture
------------

This project consists of two main components: a BentoML Service that serves a LangGraph agent as REST APIs and an LLM that generates text. The LLM can be an external API like Claude 3.5 Sonnet or an open-source model served via BentoML (Mistral 7B in this example).

.. image:: ../../_static/img/use-cases/large-language-models/langgraph/langgraph-bentoml-architecture.png
.. image:: ../../_static/img/examples/langgraph/langgraph-bentoml-architecture.png
Sherlock113 marked this conversation as resolved.
Show resolved Hide resolved

After a user submits a query, it is processed through the LangGraph agent, which includes:

Expand Down Expand Up @@ -250,7 +250,7 @@ BentoCloud provides fast and scalable infrastructure for building and scaling AI

.. tab-item:: BentoCloud Playground

.. image:: ../../_static/img/use-cases/large-language-models/langgraph/langgraph-agent-on-bentocloud.png
.. image:: ../../_static/img/examples/langgraph/langgraph-agent-on-bentocloud.png

.. tab-item:: Python client

Expand Down
4 changes: 2 additions & 2 deletions docs/source/examples/mlflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ The server is active at `http://localhost:3000 <http://localhost:3000/>`_. You c

Visit `http://localhost:3000 <http://localhost:3000/>`_, scroll down to **Service APIs**, specify the data, and click **Execute**.

.. image:: ../../_static/img/use-cases/custom-models/mlflow/service-ui.png
.. image:: ../../_static/img/examples/mlflow/service-ui.png

Deploy to BentoCloud
--------------------
Expand Down Expand Up @@ -189,7 +189,7 @@ Specify a configuration YAML file (``bentofile.yaml``) to define the build optio

Once the Deployment is up and running on BentoCloud, you can access it via the exposed URL.

.. image:: ../../_static/img/use-cases/custom-models/mlflow/bentocloud-ui.png
.. image:: ../../_static/img/examples/mlflow/bentocloud-ui.png

.. note::

Expand Down
6 changes: 3 additions & 3 deletions docs/source/examples/sdxl-turbo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ The server is active at `http://localhost:3000 <http://localhost:3000>`_. You ca

Visit `http://localhost:3000 <http://localhost:3000/>`_, scroll down to **Service APIs**, specify the parameters, and click **Execute**.

.. image:: ../../_static/img/use-cases/diffusion-models/sdxl-turbo/service-ui.png
.. image:: ../../_static/img/examples/sdxl-turbo/service-ui.png

Expected output:

.. image:: ../../_static/img/use-cases/diffusion-models/sdxl-turbo/output-image.png
.. image:: ../../_static/img/examples/sdxl-turbo/output-image.png

Deploy to BentoCloud
--------------------
Expand Down Expand Up @@ -168,7 +168,7 @@ First, specify a configuration YAML file (``bentofile.yaml``) to define the buil

Once the Deployment is up and running on BentoCloud, you can access it via the exposed URL.

.. image:: ../../_static/img/use-cases/diffusion-models/sdxl-turbo/sdxl-turbo-bentocloud.png
.. image:: ../../_static/img/examples/sdxl-turbo/sdxl-turbo-bentocloud.png

.. note::

Expand Down
6 changes: 3 additions & 3 deletions docs/source/examples/shieldgemma.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ It will result in the application raising an exception, indicating the prompt is

This example is ready for easy deployment and scaling on BentoCloud. With a single command, you can deploy a production-grade application with fast autoscaling, secure deployment in your cloud, and comprehensive observability.

.. image:: ../../_static/img/use-cases/large-language-models/shieldgemma/shieldgemma-bentocloud.png
.. image:: ../../_static/img/examples/shieldgemma/shieldgemma-bentocloud.png

Architecture
------------

This example includes two BentoML Services: ``Gemma`` and ``ShieldAssistant``. ``Gemma`` evaluates the safety of the prompt, and if it is considered safe, ``ShieldAssistant`` proceeds to call the OpenAI GPT-3.5 Turbo API to generate a response. If the probability score from the safety check exceeds a preset threshold, it indicates a potential violation of the safety guidelines. As a result, ``ShieldAssistant`` raises an error and rejects the query.

.. image:: ../../_static/img/use-cases/large-language-models/shieldgemma/architecture-shield.png
.. image:: ../../_static/img/examples/shieldgemma/architecture-shield.png

Code explanations
-----------------
Expand Down Expand Up @@ -211,7 +211,7 @@ BentoCloud provides fast and scalable infrastructure for building and scaling AI

.. tab-item:: BentoCloud Playground

.. image:: ../../_static/img/use-cases/large-language-models/shieldgemma/shieldgemma-bentocloud.png
.. image:: ../../_static/img/examples/shieldgemma/shieldgemma-bentocloud.png

.. tab-item:: Python client

Expand Down
4 changes: 2 additions & 2 deletions docs/source/examples/vllm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ The server is active at `http://localhost:3000 <http://localhost:3000>`_. You ca

Visit `http://localhost:3000 <http://localhost:3000/>`_, scroll down to **Service APIs**, and click **Try it out**. In the **Request body** box, enter your prompt and click **Execute**.

.. image:: ../../_static/img/use-cases/large-language-models/vllm/service-ui.png
.. image:: ../../_static/img/examples/vllm/service-ui.png

Deploy to BentoCloud
--------------------
Expand Down Expand Up @@ -279,7 +279,7 @@ After the Service is ready, you can deploy the project to BentoCloud for better

4. Once the Deployment is up and running on BentoCloud, you can access it via the exposed URL.

.. image:: ../../_static/img/use-cases/large-language-models/vllm/vllm-bentocloud.png
.. image:: ../../_static/img/examples/vllm/vllm-bentocloud.png

.. note::

Expand Down
4 changes: 2 additions & 2 deletions docs/source/examples/xgboost.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ The server is active at `http://localhost:3000 <http://localhost:3000/>`_. You c

Visit `http://localhost:3000 <http://localhost:3000/>`_, scroll down to **Service APIs**, specify the data, and click **Execute**.

.. image:: ../../_static/img/use-cases/custom-models/xgboost/service-ui.png
.. image:: ../../_static/img/examples/xgboost/service-ui.png

Deploy to BentoCloud
--------------------
Expand Down Expand Up @@ -225,7 +225,7 @@ First, specify a configuration YAML file (``bentofile.yaml``) to define the buil

Once the Deployment is up and running on BentoCloud, you can access it via the exposed URL.

.. image:: ../../_static/img/use-cases/custom-models/xgboost/bentocloud-ui.png
.. image:: ../../_static/img/examples/xgboost/bentocloud-ui.png

.. note::

Expand Down
Loading