Skip to content

Commit 70bf429

Browse files
ccssudoombeaker
andauthored
Add Onediff ComfyUI nodes (#397)
diffusers 中主要修改: - .github/workflows/examples.yml - .gitignore - tests/comfy-docker-compose.yml --------- Co-authored-by: Yao Chi <later@usopp.net>
1 parent 659f194 commit 70bf429

33 files changed

+1720
-24
lines changed

.github/workflows/examples.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ env:
1111
REGION_ID: cn-beijing
1212
ACR_ORG: registry.cn-beijing.aliyuncs.com/oneflow
1313
COMFYUI_SRC_DIR: ComfyUI
14-
COMFYUI_SPEEDUP_DIR: comfyui-speedup
1514
SDXL_BASE: /share_nfs/hf_models/sd_xl_base_1.0.safetensors
1615
UNET_INT8: /share_nfs/hf_models/unet_int8
1716
SELENIUM_CONTAINER_NAME: selenium-test
@@ -54,13 +53,6 @@ jobs:
5453
with:
5554
repository: comfyanonymous/ComfyUI
5655
path: ${{ env.COMFYUI_SRC_DIR }}
57-
- name: Checkout ConfyUI Speedup Nodes
58-
uses: actions/checkout@v2
59-
if: matrix.test-suite == 'comfy'
60-
with:
61-
repository: ${{ secrets.ONEFLOW_PRIV_ORG }}/comfyui-speedup
62-
token: ${{ secrets.ONEFLOW_PRIV_GH_TOKEN }}
63-
path: ${{ env.COMFYUI_SPEEDUP_DIR }}
6456

6557
- run: |
6658
docker rm -f ${{ env.CONTAINER_NAME }} || true
@@ -79,7 +71,6 @@ jobs:
7971
ACR_ORG: ${{ env.ACR_ORG }}
8072
MATRIX_IMAGE: ${{ matrix.image }}
8173
COMFYUI_SRC_DIR: ${{ env.COMFYUI_SRC_DIR }}
82-
COMFYUI_SPEEDUP_DIR: ${{ env.COMFYUI_SPEEDUP_DIR }}
8374
SDXL_BASE: ${{ env.SDXL_BASE }}
8475
UNET_INT8: ${{ env.UNET_INT8 }}
8576
SELENIUM_IMAGE: ${{ env.SELENIUM_IMAGE }}
@@ -93,8 +84,6 @@ jobs:
9384
CONTAINER_NAME: ${{ env.CONTAINER_NAME }}
9485
ACR_ORG: ${{ env.ACR_ORG }}
9586
MATRIX_IMAGE: ${{ matrix.image }}
96-
COMFYUI_SRC_DIR: ${{ env.COMFYUI_SRC_DIR }}
97-
COMFYUI_SPEEDUP_DIR: ${{ env.COMFYUI_SPEEDUP_DIR }}
9887
SDXL_BASE: ${{ env.SDXL_BASE }}
9988
UNET_INT8: ${{ env.UNET_INT8 }}
10089

@@ -143,7 +132,6 @@ jobs:
143132
ACR_ORG: ${{ env.ACR_ORG }}
144133
MATRIX_IMAGE: ${{ matrix.image }}
145134
COMFYUI_SRC_DIR: ${{ env.COMFYUI_SRC_DIR }}
146-
COMFYUI_SPEEDUP_DIR: ${{ env.COMFYUI_SPEEDUP_DIR }}
147135
SDXL_BASE: ${{ env.SDXL_BASE }}
148136
UNET_INT8: ${{ env.UNET_INT8 }}
149137
SELENIUM_IMAGE: ${{ env.SELENIUM_IMAGE }}
@@ -157,7 +145,5 @@ jobs:
157145
CONTAINER_NAME: ${{ env.CONTAINER_NAME }}
158146
ACR_ORG: ${{ env.ACR_ORG }}
159147
MATRIX_IMAGE: ${{ matrix.image }}
160-
COMFYUI_SRC_DIR: ${{ env.COMFYUI_SRC_DIR }}
161-
COMFYUI_SPEEDUP_DIR: ${{ env.COMFYUI_SPEEDUP_DIR }}
162148
SDXL_BASE: ${{ env.SDXL_BASE }}
163149
UNET_INT8: ${{ env.UNET_INT8 }}

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,6 @@ log
174174
unet_graphs
175175
*.json
176176

177-
ComfyUI/
178-
comfyui-speedup/
177+
# onediff_comfy_nodes
178+
*.pt
179+
*.graph

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ Updated on Nov 6, 2023.
3636

3737
## Business inquiry on OneDiff Enterprise Edition
3838

39-
If you need **LoRA**, [**ComfyUI**](https://github.com/Oneflow-Inc/onediff/wiki/Run-ComfyUI-with-OneDiff), **quant** support or any other more advanced features, please send an email to caishenghang@oneflow.org . Tell us about your **use case, deployment scale and requirements**!
39+
If you need **unrestricted multiple resolution**, **quantization** support or any other more advanced features, please send an email to caishenghang@oneflow.org . Tell us about your **use case, deployment scale and requirements**!
40+
4041
|   | OneDiff Community | OneDiff Enterprise|
4142
| -------------------- | ------------------- | ----------- |
4243
| diffusers | Yes | Yes |
@@ -45,7 +46,7 @@ If you need **LoRA**, [**ComfyUI**](https://github.com/Oneflow-Inc/onediff/wiki/
4546
| LCM | Limited | Yes |
4647
| Multiple Resolutions | Limited | Yes |
4748
| Technical Support | Community | Yes |
48-
| ComfyUI |   | Yes |
49+
| ComfyUI | Community | Yes |
4950
| Quantization |   | Yes |
5051
| Source Code Access |   | Yes |
5152

onediff_comfy_nodes/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__pycache__/
2+
*.py[cod]
3+
temp/
4+
*.png
5+
*.pt
6+
*.graph

onediff_comfy_nodes/README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# OneDiff ComfyUI Nodes
2+
3+
- [Installation Guide](#installation-guide)
4+
- [Nodes Usage](#nodes-usage)
5+
- [Model Acceleration](#model-acceleration)
6+
- [Model Speedup](#model-speedup)
7+
- [Model Graph Saver](#model-graph-saver)
8+
- [Model Graph Loader](#model-graph-loader)
9+
- [Quantization](#quantization)
10+
- [VAE Acceleration](#vae-acceleration)
11+
- [Image Distinction Scanner](#image-distinction-scanner)
12+
13+
14+
## Installation Guide
15+
16+
1. Install and set up [ComfyUI](https://github.com/comfyanonymous/ComfyUI)
17+
18+
19+
2. Install PyTorch and OneFlow
20+
21+
Install PyTorch:
22+
23+
```bash
24+
pip install torch torchvision torchaudio
25+
```
26+
27+
Install OneFlow Community(CUDA 11.x)
28+
29+
```bash
30+
pip install --pre oneflow -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/community/cu118
31+
```
32+
33+
Install OneFlow Community(CUDA 12.x)
34+
35+
```bash
36+
pip install --pre oneflow -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/community/cu121
37+
```
38+
39+
3. Intall onediff
40+
41+
```bash
42+
https://github.com/Oneflow-Inc/onediff.git
43+
cd onediff && pip install -e .
44+
```
45+
46+
5. Install onediff_comfy_nodes for ComfyUI
47+
48+
```bash
49+
cd onediff
50+
cp -r onediff_comfy_nodes path/to/ComfyUI/custom_nodes/
51+
```
52+
53+
6. (Optional) Advanced features
54+
55+
If you need **unrestricted multiple resolution**, **quantization** support or any other more advanced features, please send an email to caishenghang@oneflow.org . Tell us about your **use case, deployment scale and requirements**!
56+
57+
58+
59+
60+
## Nodes Usage
61+
62+
**Note** All the images in this section can be loaded directly into ComfyUI.
63+
64+
### Model Acceleration
65+
66+
#### Model Speedup
67+
68+
The "Model Speedup" node takes a model as input and outputs an optimized model.
69+
70+
If the `static_mode` is `enabled` (which is the default), it will take some time to compile before the first inference.
71+
72+
If `static_model` is `disabled`, there is no need for additional compilation time before the first inference, but the inference speed will be slower compared to `enabled`, albeit slightly.
73+
74+
![](workflows/model-speedup.png)
75+
76+
#### Model Graph Saver
77+
78+
The optimized model from the "Model Speedup" node can be saved to "graph" by the "Model Graph Saver" node, allowing it to be used in other scenarios without the need for recompilation.
79+
80+
![](workflows/model-graph-saver.png)
81+
82+
You can set different file name prefixes for different types of models.
83+
84+
#### Model Graph Loader
85+
86+
The "Model Graph Loader" node is used to load graph files from the disk, thus saving the time required for the initial compilation.
87+
88+
![](workflows/model-graph-loader.png)
89+
90+
### Quantization
91+
92+
The "UNet Loader Int8" node is used to load quantized models. Quantized models need to be used in conjunction with the "Model Speedup" node.
93+
94+
![](workflows/int8-speedup.png)
95+
96+
The compilation result of the quantized model can also be saved as a graph and loaded when needed.
97+
98+
99+
![quantized model saver](workflows/int8-graph-saver.png)
100+
101+
![quantized model loader](workflows/int8-graph-loader.png)
102+
103+
104+
### VAE Acceleration
105+
106+
The VAE nodes used for accelerating, saving, and loading VAE graphs operate in a manner very similar to the usage of Model nodes.
107+
108+
Omitting specific details here, the following workflow can be loaded and tested.
109+
110+
**VAE Speedup and Graph Saver**
111+
112+
![](workflows/vae-graph-saver.png)
113+
114+
**VAE Speedup and Graph Loader**
115+
116+
![](workflows/vae-graph-loader.png)
117+
118+
### Image Distinction Scanner
119+
120+
The "Image Distinction Scanner" node is used to compare the differences between two images and visualize the resulting variances.
121+
122+
![](workflows/image-distinction-scanner.png)
123+
124+

onediff_comfy_nodes/__init__.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""OneFlow ComfyUI Speedup Module"""
2+
from ._config import _USE_UNET_INT8
3+
from ._nodes import (
4+
ModelSpeedup,
5+
ModelGraphLoader,
6+
ModelGraphSaver,
7+
VaeSpeedup,
8+
VaeGraphLoader,
9+
VaeGraphSaver,
10+
)
11+
from ._compare_node import CompareModel, ShowImageDiff
12+
13+
14+
NODE_CLASS_MAPPINGS = {
15+
"ModelSpeedup": ModelSpeedup,
16+
"CompareModel": CompareModel,
17+
"ShowImageDiff": ShowImageDiff,
18+
"ModelGraphLoader": ModelGraphLoader,
19+
"ModelGraphSaver": ModelGraphSaver,
20+
"VaeSpeedup": VaeSpeedup,
21+
"VaeGraphSaver": VaeGraphSaver,
22+
"VaeGraphLoader": VaeGraphLoader,
23+
}
24+
25+
NODE_DISPLAY_NAME_MAPPINGS = {
26+
"ModelSpeedup": "Model Speedup",
27+
"CompareModel": "Model Weight Comparator",
28+
"ShowImageDiff": "Image Distinction Scanner",
29+
"ModelGraphLoader": "Model Graph Loader",
30+
"ModelGraphSaver": "Model Graph Saver",
31+
"VaeSpeedup": "VAE Speedup",
32+
"VaeGraphLoader": "VAE Graph Loader",
33+
"VaeGraphSaver": "VAE Graph Saver",
34+
}
35+
36+
if _USE_UNET_INT8:
37+
from ._nodes import UNETLoaderInt8
38+
39+
NODE_CLASS_MAPPINGS.update({"UNETLoaderInt8": UNETLoaderInt8})
40+
NODE_DISPLAY_NAME_MAPPINGS.update({"UNETLoaderInt8": "UNET Loader Int8"})

0 commit comments

Comments
 (0)