Skip to content

Commit 5bcc444

Browse files
authored
Merge branch 'main' into main
2 parents b298abe + f1b0fb1 commit 5bcc444

16 files changed

+755
-169
lines changed

.gitignore

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ __pycache__
22
*.egg-info
33
build
44
.DS_STORE
5-
comfyui*
6-
ComfyUI*
5+
comfyui/
6+
ComfyUI/
7+
cuda_temp
78

89
# VS Code settings
910
.vscode/
@@ -18,4 +19,4 @@ launch.json
1819
.env.test
1920
.env.production
2021

21-
nodes/web/static/*
22+
nodes/web/static/*

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This repo also includes a WebRTC server and UI that uses comfystream to support
1010
- [Docker Image](#docker-image)
1111
- [RunPod](#runpod)
1212
- [Tensordock](#tensordock)
13+
- [Other Cloud Providers](#other-cloud-providers)
1314
- [Download Models](#download-models)
1415
- [Install package](#install-package)
1516
- [Custom Nodes](#custom-nodes)
@@ -42,11 +43,15 @@ The RunPod template [livepeer-comfystream](https://runpod.io/console/deploy?temp
4243

4344
#### Tensordock
4445

45-
We also have a python script that can be used to spin up a ComfyStream instance on a [Tensordock server](https://tensordock.com/). Refer to [scripts/README.md](scripts/README.md) for instructions.
46+
We also have a python script that can be used to spin up a ComfyStream instance on a [Tensordock server](https://tensordock.com/). Refer to [scripts/README.md](./scripts/README.md#tensordock-auto-setup-fully-automated) for instructions.
47+
48+
#### Other Cloud Providers
49+
50+
We also provide an [Ansible playbook](https://docs.ansible.com/ansible/latest/installation_guide/index.html) for deploying ComfyStream on any cloud provider. Refer to [scripts/README.md](./scripts/README.md#cloud-agnostic-automated-setup-ansible-based-deployment) for instructions.
4651

4752
## Download Models
4853

49-
Refer to [src/comfystream/scripts/README.md](src/comfystream/scripts/README.md) for instructions to download commonly used models.
54+
Refer to [scripts/README.md](src/comfystream/scripts/README.md) for instructions to download commonly used models.
5055

5156
## Install package
5257

@@ -83,7 +88,7 @@ pip install git+https://github.com/yondonfu/comfystream.git
8388

8489
### Custom Nodes
8590

86-
comfystream uses a few auxiliary custom nodes to support running workflows.
91+
Comfystream uses a few auxiliary custom nodes to support running workflows.
8792

8893
**Note:** If you are using comfystream as a custom node in ComfyUI, you can skip the following steps.
8994

configs/nodes.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ nodes:
22
# Core TensorRT nodes
33
comfyui-tensorrt:
44
name: "ComfyUI TensorRT"
5-
url: "https://github.com/yondonfu/ComfyUI_TensorRT"
6-
branch: "quantization_with_controlnet_fixes"
5+
url: "https://github.com/eliteprox/ComfyUI_TensorRT.git"
6+
branch: "fix/onnxconverter-converter"
77
type: "tensorrt"
8+
dependencies:
9+
- "onnxruntime-gpu>=1.17.0"
10+
- "onnx>=1.17.0"
811

912
comfyui-depthanything-tensorrt:
1013
name: "ComfyUI DepthAnything TensorRT"
@@ -65,6 +68,4 @@ nodes:
6568
comfyui_controlnet_aux:
6669
name: "ComfyUI ControlNet Auxiliary"
6770
url: "https://github.com/Fannovel16/comfyui_controlnet_aux"
68-
type: "utility"
69-
dependencies:
70-
- "mediapipe==0.10.8"
71+
type: "utility"

docker/Dockerfile.base

+5-6
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@ COPY ./workflows/comfyui/* /workspace/ComfyUI/user/default/workflows
5252
RUN conda run -n comfystream --no-capture-output --cwd /workspace/ComfyUI pip install -r requirements.txt --root-user-action=ignore
5353

5454
# Install ComfyStream requirements
55-
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream pip install -r requirements.txt --root-user-action=ignore && \
56-
conda run -n comfystream --no-capture-output --cwd /workspace/comfystream pip install . --root-user-action=ignore && \
57-
ln -s /workspace/comfystream /workspace/ComfyUI/custom_nodes/comfystream && \
58-
conda run -n comfystream --no-capture-output --cwd /workspace/comfystream python install.py --workspace /workspace/ComfyUI && \
59-
conda run -n comfystream --no-capture-output pip install --upgrade tensorrt-cu12-bindings tensorrt-cu12-libs --root-user-action=ignore && \
60-
conda run -n comfystream --no-capture-output pip install mediapipe==0.10.8 --root-user-action=ignore
55+
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream pip install -r requirements.txt --root-user-action=ignore
56+
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream pip install . --root-user-action=ignore
57+
RUN ln -s /workspace/comfystream /workspace/ComfyUI/custom_nodes/comfystream
58+
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream python install.py --workspace /workspace/ComfyUI
59+
RUN conda run -n comfystream --no-capture-output pip install --upgrade tensorrt-cu12-bindings tensorrt-cu12-libs --root-user-action=ignore
6160

6261
# Configure no environment activation by default
6362
RUN conda config --set auto_activate_base false && \

install.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def download_and_extract_ui_files(version: str):
5353
output_dir = os.path.join(os.getcwd(), "nodes", "web")
5454
pathlib.Path(output_dir).mkdir(parents=True, exist_ok=True)
5555
base_url = urllib.parse.urljoin("https://github.com/yondonfu/comfystream/releases/download/", f"v{version}/static.tar.gz")
56+
fallback_url = "https://github.com/yondonfu/comfystream/releases/latest/download/static.tar.gz"
5657

5758
# Create a temporary directory instead of a temporary file
5859
with tempfile.TemporaryDirectory() as temp_dir:
@@ -63,13 +64,25 @@ def download_and_extract_ui_files(version: str):
6364
logger.info(f"Downloading {base_url}")
6465
try:
6566
urllib.request.urlretrieve(base_url, download_path)
66-
67-
# Extract contents
67+
except urllib.error.HTTPError as e:
68+
if e.code == 404:
69+
logger.warning(f"{base_url} not found, trying {fallback_url}")
70+
try:
71+
urllib.request.urlretrieve(fallback_url, download_path)
72+
except Exception as e:
73+
logger.error(f"Error downloading latest ui package: {e}")
74+
raise
75+
else:
76+
logger.error(f"Error downloading package: {e}")
77+
raise
78+
79+
# Extract contents
80+
try:
6881
logger.info(f"Extracting files to {output_dir}")
6982
with tarfile.open(download_path, 'r:gz') as tar:
7083
tar.extractall(path=output_dir)
7184
except Exception as e:
72-
logger.error(f"Error downloading or extracting files: {e}")
85+
logger.error(f"Error extracting files: {e}")
7386
raise
7487

7588
if __name__ == "__main__":
@@ -100,14 +113,14 @@ def download_and_extract_ui_files(version: str):
100113

101114
if workspace is None:
102115
logger.warning("No ComfyUI workspace found. Please specify a valid workspace path to fully install")
103-
104-
logger.info("Downloading and extracting UI files...")
105-
version = get_project_version(os.getcwd())
106-
download_and_extract_ui_files(version)
107116

108117
if workspace is not None:
109118
logger.info("Ensuring __init__.py files exist in ComfyUI directories...")
110119
ensure_init_files(workspace)
111120
logger.info("Installing custom node requirements...")
112121
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", "."])
122+
123+
logger.info("Downloading and extracting UI files...")
124+
version = get_project_version(os.getcwd())
125+
download_and_extract_ui_files(version)
113126
logger.info("Installation completed successfully.")

nodes/tensor_utils/prestartup_script.py

+19-16
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,29 @@ def wrapped_control_merge(self, control, control_prev, output_dtype):
2828
}
2929

3030
# Get result from original merge function
31-
result = original_control_merge(self, control, control_prev, output_dtype)
32-
33-
# Clone all output tensors
34-
result = {
35-
k: [t.clone() if t is not None else None for t in v]
36-
for k, v in result.items()
37-
}
38-
39-
# Mark CUDA graph step at end
40-
if torch.cuda.is_available() and hasattr(torch.compiler, 'cudagraph_mark_step_begin'):
41-
torch.compiler.cudagraph_mark_step_begin()
42-
torch.cuda.synchronize()
43-
44-
return result
45-
31+
try:
32+
result = original_control_merge(self, control, control_prev, output_dtype)
33+
34+
# Clone all output tensors
35+
result = {
36+
k: [t.clone() if t is not None else None for t in v]
37+
for k, v in result.items()
38+
}
39+
return result
40+
except Exception as e:
41+
print(f"Error: Failed to clone ControlNet during inference: {str(e)}")
42+
raise e
43+
finally:
44+
# Mark CUDA graph step at end
45+
if torch.cuda.is_available() and hasattr(torch.compiler, 'cudagraph_mark_step_begin'):
46+
torch.compiler.cudagraph_mark_step_begin()
47+
torch.cuda.synchronize()
48+
4649
# Apply the patch
4750
ControlBase.control_merge = wrapped_control_merge
4851
print("Successfully patched ControlNet for torch.compile() compatibility")
4952
except Exception as e:
5053
print(f"Warning: Failed to patch ControlNet: {str(e)}")
5154

5255
# Apply patch when module is imported
53-
patch_controlnet_for_stream()
56+
patch_controlnet_for_stream()

scripts/README.md

+81-17
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,112 @@
11
# ComfyUI Helper Scripts
22

3-
This directory contains various helper scripts designed to streamline working with ComfyStream:
3+
This directory contains helper scripts to simplify the deployment and management of **ComfyStream**:
44

5-
- `spinup_comfystream_tensordock.py`: Spins up a ComfyStream instance on a [Tensordock server](https://tensordock.com/), installs dependencies, and starts the server.
5+
- **Ansible Playbook (`ansible/plays/setup_comfystream.yml`)** – Deploys ComfyStream on any cloud provider.
6+
- **`spinup_comfystream_tensordock.py`** – Fully automates VM creation and ComfyStream setup on a [TensorDock server](https://tensordock.com/).
67

78
## Usage Instructions
89

9-
### Spinup TensorDock ComfyStream Instance
10+
### Ansible Playbook (Cloud-Agnostic Deployment)
1011

11-
1. **Create a Tensordock Account**: Register at [Tensordock](https://dashboard.tensordock.com/register), attach a credit card, and create an API key and token.
12-
2. **Set Up a Python Virtual Environment**:
13-
Create and activate a virtual environment using [Conda](https://docs.anaconda.com/miniconda/) and install the required dependencies:
12+
This repository includes an [Ansible playbook](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_intro.html) to deploy ComfyStream on any cloud provider. Follow the steps below:
13+
14+
1. **Create a VM**:
15+
Deploy a VM on a cloud provider such as [TensorDock](https://marketplace.tensordock.com/deploy?gpu=geforcertx4090-pcie-24gb&gpuCount=1&ramAmount=16&vcpuCount=4&storage=100&os=Ubuntu-22.04-LTS), AWS, Google Cloud, or Azure with the following minimum specifications:
16+
- **GPU**: 20GB VRAM
17+
- **RAM**: 16GB
18+
- **CPU**: 4 vCPUs
19+
- **Storage**: 100GB
20+
21+
> [!TIP]
22+
> You can use the `spinup_comfystream_tensordock.py --bare-vm` script to create a [compatible VM on TensorDock](https://marketplace.tensordock.com/deploy?gpu=geforcertx4090-pcie-24gb&gpuCount=1&ramAmount=16&vcpuCount=4&storage=100&os=Ubuntu-22.04-LTS)
23+
24+
2. **Open Required Ports**:
25+
Ensure the following ports are open **inbound and outbound** on the VM's firewall/security group:
26+
- **SSH (Port 22)** – Remote access
27+
- **HTTPS (Port 8189)** – ComfyStream access
28+
29+
3. **Install Ansible**:
30+
Follow the [official Ansible installation guide](https://docs.ansible.com/ansible/latest/installation_guide/index.html).
31+
32+
4. **Configure the Inventory File**:
33+
Add the VM’s public IP to `ansible/inventory.yml`.
34+
35+
5. **Change the ComfyUI Password:**
36+
Open the `ansible/plays/setup_comfystream.yaml` file and replace the `comfyui_password` value with your own secure password.
37+
38+
6. **Run the Playbook**:
39+
Execute:
1440

1541
```bash
16-
conda create -n comfystream python=3.8
17-
conda activate comfystream
18-
pip install -r requirements.txt
42+
ansible-playbook -i ansible/inventory.yaml ansible/plays/setup_comfystream.yaml
1943
```
2044

21-
3. **Check Available Options** *(Optional but Recommended)*:
22-
To see all available script options, run:
45+
> [!IMPORTANT]
46+
> When using a non-sudo user, add `--ask-become-pass` to provide the sudo password or use an Ansible vault for secure storage.
47+
48+
7. **Access the Server**:
49+
After the playbook completes, **ComfyStream** will start, and you can access **ComfyUI** at `https://<VM_IP>:<PORT_FOR_8189>`. Credentials are shown in the output and regenerated each time. To persist the password, set the `comfyui_password` variable when running the playbook:
50+
51+
```bash
52+
ansible-playbook -i ansible/inventory.yaml ansible/plays/setup_comfystream.yaml -e "comfyui_password=YourSecurePasswordHere"
53+
```
54+
55+
> [!IMPORTANT]
56+
> If you encounter a `toomanyrequests` error while pulling the Docker image, either wait a few minutes or provide your Docker credentials when running the playbook:
57+
>
58+
> ```bash
59+
> ansible-playbook -i ansible/inventory.yaml ansible/plays/setup_comfystream.yaml -e "docker_hub_username=your_dockerhub_username docker_hub_password=your_dockerhub_pat"
60+
> ```
61+
62+
> [!TIP]
63+
> The [ComfyStream Docker image](https://hub.docker.com/r/livepeer/comfystream/tags) is **~20GB**. To check download progress, SSH into the VM and run:
64+
>
65+
> ```bash
66+
> docker pull livepeer/comfystream:latest
67+
> ```
68+
69+
### TensorDock Spinup Script (Fully Automated)
70+
71+
The `spinup_comfystream_tensordock.py` script automates VM provisioning, setup, and server launch on [TensorDock](https://tensordock.com/). Follow the steps below:
72+
73+
1. **Create a TensorDock Account**: Sign up at [Tensordock](https://dashboard.tensordock.com/register), add a payment method, and generate API credentials.
74+
75+
2. **Set Up a Python Virtual Environment**:
76+
To prevent dependency conflicts, create and activate a virtual environment with [Conda](https://docs.anaconda.com/miniconda/) and install the required dependencies:
77+
78+
```bash
79+
conda create -n comfystream python=3.8
80+
conda activate comfystream
81+
pip install -r requirements.txt
82+
```
83+
84+
3. **View Available Script Options** *(Optional)*:
85+
To see all available options, run:
2386

2487
```bash
2588
python spinup_comfystream_tensordock.py --help
2689
```
2790

2891
4. **Run the Script**:
29-
Execute the following command to spin up a ComfyStream instance:
92+
Execute the following command to provision a VM and set up ComfyStream automatically:
3093

3194
```bash
3295
python spinup_comfystream_tensordock.py --api-key <API_KEY> --api-token <API_TOKEN>
3396
```
3497

3598
5. **Access the Server**:
36-
The script will set up the instance, install dependencies, and start the server. This process will take a few minutes. Once completed, you can access the ComfyStream server and UI using the provided URLs.
99+
Once the setup is complete, the script will display the URLs to access ComfyStream.
37100

38-
6. **Stop the Server**:
39-
To stop the server, run:
101+
6. **Stop & Delete the VM** *(When No Longer Needed)*:
102+
To stop and remove the instance, run:
40103

41104
```bash
42105
python spinup_comfystream_tensordock.py --delete <VM_ID>
43106
```
44107

45-
Replace `<VM_ID>` with the ID of the VM you want to delete. You can find the VM ID in the script logs or the [Tensordock dashboard](https://dashboard.tensordock.com/).
108+
Replace `<VM_ID>` with the VM ID found in the script logs or the [TensorDock dashboard](https://dashboard.tensordock.com/instances).
46109

47110
> [!WARNING]
48-
> If you see `max retries exceeded with url` errors, the VM was likely created but is inaccessible. Check the [TensorDock dashboard](https://dashboard.tensordock.com/instances), delete the VM, wait 2-3 minutes, then run the script again.
111+
> If you encounter `max retries exceeded with URL` errors, the VM might have been created but is inaccessible.
112+
> Check the [TensorDock dashboard](https://dashboard.tensordock.com/instances), delete the VM manually, wait **2-3 minutes**, then rerun the script.

scripts/ansible/inventory.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
all:
3+
hosts:
4+
comfystream_vm:
5+
ansible_host: 123.234.102.170 # Replace with your VM's IP address
6+
ansible_port: 22 # Replace with your VM's SSH port
7+
ansible_user: user # Replace with your SSH user
8+
ansible_ssh_private_key_file: ~/.ssh/private_key # Path to your SSH key

0 commit comments

Comments
 (0)