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

add onediff_comfy_nodes/benchmarks #956

Merged
merged 44 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f570e4d
add onediff_comfy_nodes/benchmarks
ccssu Jun 17, 2024
06dbe7e
refine
ccssu Jun 17, 2024
6d02e69
Merge branch 'main' into add_onediff_comfy_nodes_benchmarks
ccssu Jun 17, 2024
19be5ca
Add prompt styler (#960)
ccssu Jun 17, 2024
9bf63f9
refine
ccssu Jun 18, 2024
2636684
add testcase
ccssu Jun 18, 2024
9e50404
test join ci
ccssu Jun 19, 2024
fed1b5b
add_pulid_comfyui_support (#965)
ccssu Jun 19, 2024
69018c9
refine
ccssu Jun 19, 2024
6b4bf21
Merge branch 'main' into add_onediff_comfy_nodes_benchmarks
ccssu Jun 19, 2024
f461c87
fix lora switching
ccssu Jun 19, 2024
2b945ef
refine
ccssu Jun 19, 2024
d896faf
Merge branch 'main' into add_onediff_comfy_nodes_benchmarks
ccssu Jun 20, 2024
fe95960
Delete redundant codes
ccssu Jun 20, 2024
cfb1bbd
add warning
ccssu Jun 20, 2024
83deb80
support oneflow unet cache
ccssu Jun 20, 2024
26158ac
print VRAM used
ccssu Jun 20, 2024
5ec229d
refine
ccssu Jun 21, 2024
c0e9c75
Refactoring code
ccssu Jun 21, 2024
24152e5
refine
ccssu Jun 21, 2024
df38af2
add ipa test case
ccssu Jun 21, 2024
dc71785
Merge branch 'main' into add_onediff_comfy_nodes_benchmarks
ccssu Jun 21, 2024
9eae93f
Merge branch 'main' into add_onediff_comfy_nodes_benchmarks
ccssu Jun 22, 2024
605ed5d
add instantid test
ccssu Jun 22, 2024
6822c25
refine
ccssu Jun 22, 2024
e2d3734
disable instantid test
ccssu Jun 22, 2024
70bf215
refine
ccssu Jun 23, 2024
5891abf
debug ci failed
ccssu Jun 23, 2024
d6c67a2
debug ci
ccssu Jun 23, 2024
8555f12
debug ci
ccssu Jun 23, 2024
d429f97
debug ci
ccssu Jun 23, 2024
83cb5af
debug ci
ccssu Jun 23, 2024
f7d903a
debug ci
ccssu Jun 23, 2024
8ef31a1
debug ci
ccssu Jun 23, 2024
ffda595
refine
ccssu Jun 24, 2024
4baf73b
Merge branch 'main' into add_onediff_comfy_nodes_benchmarks
ccssu Jun 24, 2024
86bf061
refine
ccssu Jun 24, 2024
903123a
refine
ccssu Jun 24, 2024
53b4132
Merge branch 'main' into add_onediff_comfy_nodes_benchmarks
ccssu Jun 24, 2024
85e7fe9
Improve structure
ccssu Jun 25, 2024
79156b6
merge main
ccssu Jun 25, 2024
d64cf8c
format
ccssu Jun 25, 2024
5031b6e
fix ci error
ccssu Jun 25, 2024
f3dbf43
Merge branch 'main' into add_onediff_comfy_nodes_benchmarks
ccssu Jun 25, 2024
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
18 changes: 12 additions & 6 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ jobs:
- name: Start ComfyUI Web Service
if: matrix.test-suite == 'comfy'
run: |
docker exec -w /app/ComfyUI -d ${{ env.CONTAINER_NAME }} sh -c "python3 /app/ComfyUI/main.py --port 8188 --extra-model-paths-config /src/onediff/tests/comfyui/extra_model_paths.yaml > /app/ComfyUI/onediff_comfyui.log 2>&1"
docker exec -w /app/ComfyUI -d ${{ env.CONTAINER_NAME }} sh -c "python3 /app/ComfyUI/main.py --gpu-only --disable-cuda-malloc --port 8188 --extra-model-paths-config /src/onediff/tests/comfyui/extra_model_paths.yaml > /app/ComfyUI/onediff_comfyui.log 2>&1"
sleep 30
# print to check if comfy is launched successfully
- run: docker exec ${{ env.CONTAINER_NAME }} ps aux
Expand All @@ -299,12 +299,18 @@ jobs:
}
}

run_comfy_test "workflows/sdxl-unet-speedup-graph-saver.json" 200
run_comfy_test "workflows/sdxl-control-lora-speedup.json" 200
run_comfy_test "/share_nfs/hf_models/comfyui_resources/workflows/ipadapter_advanced.json" 200
run_comfy_test "/share_nfs/hf_models/comfyui_resources/workflows/deep-cache.json" 600
run_comfy_test "/share_nfs/hf_models/comfyui_resources/workflows/deep-cache-with-lora.json" 800
# run_comfy_test "workflows/sdxl-unet-speedup-graph-saver.json" 200
# run_comfy_test "workflows/sdxl-control-lora-speedup.json" 200
# run_comfy_test "/share_nfs/hf_models/comfyui_resources/workflows/ipadapter_advanced.json" 200
# run_comfy_test "/share_nfs/hf_models/comfyui_resources/workflows/deep-cache.json" 600
# run_comfy_test "/share_nfs/hf_models/comfyui_resources/workflows/deep-cache-with-lora.json" 800
ccssu marked this conversation as resolved.
Show resolved Hide resolved
# run_comfy_test "workflows/text-to-video-speedup.json" 5000
docker exec -w /src/onediff/onediff_comfy_nodes/benchmarks ${{ env.CONTAINER_NAME }} bash scripts/install_env.sh /app/ComfyUI
docker exec -w /src/onediff/onediff_comfy_nodes/benchmarks ${{ env.CONTAINER_NAME }} bash scripts/run_oneflow_case.sh || {
echo "Test fails! print the ComfyUI logs..."
docker exec onediff-test cat /app/ComfyUI/onediff_comfyui.log
false
}

- name: Show ComfyUI Log
if: matrix.test-suite == 'comfy'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,4 @@ unet_graphs

# onediff_sd_webui_extensions
onediff_sd_webui_extensions/compiled_caches/
onediff_comfy_nodes/benchmarks/results/
9 changes: 9 additions & 0 deletions onediff_comfy_nodes/_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import torch
import folder_paths

__all__ = [
Expand All @@ -8,6 +9,14 @@
"is_disable_oneflow_backend",
]

# https://huggingface.co/blog/sd3#performance-optimizations-for-sd3
torch.set_float32_matmul_precision("high")
torch._inductor.config.conv_1x1_as_mm = True
torch._inductor.config.coordinate_descent_tuning = True
torch._inductor.config.epilogue_fusion = False
torch._inductor.config.coordinate_descent_check_all_directions = True
ccssu marked this conversation as resolved.
Show resolved Hide resolved


# https://github.com/comfyanonymous/ComfyUI/blob/master/folder_paths.py#L9
os.environ["COMFYUI_ROOT"] = folder_paths.base_path
_default_backend = os.environ.get("ONEDIFF_COMFY_NODES_DEFAULT_BACKEND", "oneflow")
Expand Down
59 changes: 25 additions & 34 deletions onediff_comfy_nodes/_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def speedup(
model,
inplace: bool = False,
custom_booster: Optional[BoosterScheduler] = None,
booster_settings: Optional[BoosterSettings] = None,
*args,
**kwargs
) -> Tuple:
Expand All @@ -60,15 +61,15 @@ def speedup(
Returns:
Tuple: Tuple containing the optimized model.
"""
if not hasattr(self, "booster_settings"):
if booster_settings is None and not hasattr(self, "booster_settings"):
self.booster_settings = BoosterSettings(tmp_cache_key=str(uuid.uuid4()))

if custom_booster:
booster = custom_booster
booster.inplace = inplace
else:
booster = BoosterScheduler(BasicBoosterExecutor(), inplace=inplace)
booster.settings = self.booster_settings
booster.settings = self.booster_settings if booster_settings is None else booster_settings
return (booster(model, *args, **kwargs),)


Expand All @@ -93,6 +94,9 @@ def INPUT_TYPES(s):

RETURN_TYPES = ("VAE",)

def speedup(self, vae, inplace=False, custom_booster: BoosterScheduler = None):
return super().speedup(vae, inplace, custom_booster)


class ControlnetSpeedup:
@classmethod
Expand Down Expand Up @@ -193,7 +197,7 @@ def onediff_load_controlnet(self, control_net_name, custom_booster=None):
return (controlnet,)


class OneDiffCheckpointLoaderSimple(CheckpointLoaderSimple):
class OneDiffCheckpointLoaderSimple(CheckpointLoaderSimple, SpeedupMixin):
@classmethod
def INPUT_TYPES(s):
return {
Expand All @@ -207,40 +211,27 @@ def INPUT_TYPES(s):
CATEGORY = "OneDiff/Loaders"
FUNCTION = "onediff_load_checkpoint"

@staticmethod
def _load_checkpoint(
ckpt_name, vae_speedup="disable", custom_booster: BoosterScheduler = None
):
"""Loads a checkpoint, applying speedup techniques."""

ckpt_path = folder_paths.get_full_path("checkpoints", ckpt_name)
out = comfy.sd.load_checkpoint_guess_config(
ckpt_path,
output_vae=True,
output_clip=True,
embedding_directory=folder_paths.get_folder_paths("embeddings"),
)

# Unpack outputs
modelpatcher, clip, vae = out[:3]
def __init__(self) -> None:
super().__init__()
self.unet_booster_settings = BoosterSettings(tmp_cache_key=str(uuid.uuid4()))
self.vae_booster_settings = BoosterSettings(tmp_cache_key=str(uuid.uuid4()))

# Apply custom booster if provided, otherwise use a basic one
custom_booster = custom_booster or BoosterScheduler(BasicBoosterExecutor())
modelpatcher = custom_booster(modelpatcher, ckpt_name=ckpt_name)
@torch.inference_mode()
def onediff_load_checkpoint(
self, ckpt_name, vae_speedup="disable", custom_booster: BoosterScheduler = None,
):
modelpatcher, clip, vae = self.load_checkpoint(ckpt_name)
modelpatcher = self.speedup(
modelpatcher, inplace=True, custom_booster=custom_booster, booster_settings=self.unet_booster_settings
)[0]

# Apply VAE speedup if enabled
if vae_speedup == "enable":
vae = BoosterScheduler(BasicBoosterExecutor())(vae, ckpt_name=ckpt_name)
vae = self.speedup(vae, inplace=True, custom_booster=custom_booster,booster_settings = self.vae_booster_settings)[0]

# Set weight inplace update
modelpatcher.weight_inplace_update = True

return modelpatcher, clip, vae

@torch.inference_mode()
def onediff_load_checkpoint(
self, ckpt_name, vae_speedup="disable", custom_booster: BoosterScheduler = None,
):
out = self._load_checkpoint(ckpt_name, vae_speedup, custom_booster)
# Return the loaded checkpoint (modelpatcher, clip, vae)
return out
return (
modelpatcher,
clip,
vae,
)
17 changes: 17 additions & 0 deletions onediff_comfy_nodes/benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Overview
This benchmarks the production environment stability by testing:
- ✅ Memory prediction time
- ✅ First AUTOTUNE duration
- ✅ Startup time with warmup
- [x] TODO Join CI
- [ ] https://github.com/Fannovel16/comfyui_controlnet_aux 耗时测试
- [ ] SSIM 验证准确度

## “disable auto tune”
https://discuss.pytorch.org/t/how-to-use-auto-tune-with-pytorch/64669


- [ ] lora 切换测试
- [ ] load checkpoint 切换测试
- [ ] 文档节点整理
- [ ] AnimateDiff 支持
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
{
"3": {
"inputs": {
"seed": 1,
"steps": 30,
"cfg": 6.5,
"sampler_name": "ddpm",
"scheduler": "karras",
"denoise": 1,
"model": [
"14",
0
],
"positive": [
"6",
0
],
"negative": [
"7",
0
],
"latent_image": [
"5",
0
]
},
"class_type": "KSampler",
"_meta": {
"title": "KSampler"
}
},
"4": {
"inputs": {
"ckpt_name": "sd15/020.realisticVisionV51_v51VAE.safetensors"
},
"class_type": "CheckpointLoaderSimple",
"_meta": {
"title": "Load Checkpoint"
}
},
"5": {
"inputs": {
"width": 512,
"height": 512,
"batch_size": 1
},
"class_type": "EmptyLatentImage",
"_meta": {
"title": "Empty Latent Image"
}
},
"6": {
"inputs": {
"text": "in a peaceful spring morning a woman wearing a white shirt is sitting in a park on a bench\n\nhigh quality, detailed, diffuse light",
"clip": [
"4",
1
]
},
"class_type": "CLIPTextEncode",
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"7": {
"inputs": {
"text": "blurry, noisy, messy, lowres, jpeg, artifacts, ill, distorted, malformed",
"clip": [
"4",
1
]
},
"class_type": "CLIPTextEncode",
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"8": {
"inputs": {
"samples": [
"3",
0
],
"vae": [
"4",
2
]
},
"class_type": "VAEDecode",
"_meta": {
"title": "VAE Decode"
}
},
"9": {
"inputs": {
"filename_prefix": "IPAdapter",
"images": [
"8",
0
]
},
"class_type": "SaveImage",
"_meta": {
"title": "Save Image"
}
},
"12": {
"inputs": {
"image": "input_image_vermeer.png",
"upload": "image"
},
"class_type": "LoadImage",
"_meta": {
"title": "Load Image"
}
},
"14": {
"inputs": {
"weight": 0.8,
"weight_type": "linear",
"combine_embeds": "concat",
"start_at": 0,
"end_at": 1,
"embeds_scaling": "V only",
"model": [
"4",
0
],
"ipadapter": [
"15",
0
],
"image": [
"17",
0
],
"clip_vision": [
"16",
0
]
},
"class_type": "IPAdapterAdvanced",
"_meta": {
"title": "IPAdapter Advanced"
}
},
"15": {
"inputs": {
"ipadapter_file": "ip-adapter-plus_sd15.safetensors"
},
"class_type": "IPAdapterModelLoader",
"_meta": {
"title": "IPAdapter Model Loader"
}
},
"16": {
"inputs": {
"clip_name": "SD1.5/pytorch_model.bin"
},
"class_type": "CLIPVisionLoader",
"_meta": {
"title": "Load CLIP Vision"
}
},
"17": {
"inputs": {
"interpolation": "LANCZOS",
"crop_position": "top",
"sharpening": 0.15,
"image": [
"12",
0
]
},
"class_type": "PrepImageForClipVision",
"_meta": {
"title": "Prep Image For ClipVision"
}
}
}
Loading