Skip to content

Commit

Permalink
Add community version controlnet performance testing (#557)
Browse files Browse the repository at this point in the history
## Performance Comparison
> NVIDIA GeForce RTX 3090 

- model: sd_xl_base_1.0.safetensors
- batch size: 1
- image size: 1024x1024
- steps: 20


Timings for 20 steps at 1024x1024
| e2e                    | Basic  | Lora   | ControlNet |
| ---------------------- | ------ | ------ | ---------- |
| PyTorch                | 5.57 s | 5.62 s | 7.95 s     |
| OneDiff                | 3.16 s | 3.16 s | 5.45 s     |
| Percentage improvement | 43%    | 44%    | 31%        |



Image throughput for 20 steps at 1024x1024
| it/s                   | Basic    | Lora     | ControlNet |
| ---------------------- | -------- | -------- | ---------- |
| PyTorch                | 4.04it/s | 3.99it/s | 2.87it/s   |
| OneDiff                | 7.61it/s | 7.51it/s | 4.40it/s   |
| Percentage improvement | 88%      | 88%      | 53%        |


- onediff: d387e7e (origin/main, origin/HEAD, main) 
- oneflow: version: 0.9.1.dev20240120+cu121 git_commit: 287b806
  • Loading branch information
ccssu authored Jan 23, 2024
1 parent 528f593 commit f481e6c
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 18 deletions.
Binary file added imgs/comfy_community_version_speed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions imgs/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
categories:
- Basic
- Lora
- ControlNets

optimization_scores:
- 0.3
- 0.3
- 0.35

display_scores_on_bars: true # Whether to display scores on bars
use_default_scores_on_bars: true # Whether to use default optimization_scores on bars
custom_scores_on_bars:
- 0.3
- 0.3
- 0.3
# scores_format_on_bars: '{score:.2f}' # Format of the displayed scores on bars
scores_format_on_bars: '{score:.0%}'

colormap: coolwarm
colormap_range:
- 0.2
- 0.5
- 0.8

bar_width: 0.6
rotation_angle: 45
label_fontsize: 10
line_color: '#d2b48c'
line_style: '--'
line_width: 0.5
line_alpha: 0.7

figure:
figsize:
width: 8
height: 6
dpi: 300

plot_title: 'Optimization Scores for Different Categories'
x_label: ''
y_label: 'Optimization Score'

output_filename: 'config.png'
115 changes: 115 additions & 0 deletions imgs/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import matplotlib as mpl
import matplotlib.pyplot as plt
import yaml
import argparse


def parse_args():
parser = argparse.ArgumentParser(description="Plot optimization scores")
parser.add_argument(
"--config", type=str, default="config.yaml", help="Path to the config file"
)
return parser.parse_args()


# Load settings from the YAML file
args = parse_args()
with open(args.config, "r") as file:
config = yaml.safe_load(file)

categories = config["categories"]
optimization_scores = config["optimization_scores"]

# Use default scores on bars if configured to do so
if config.get("use_default_scores_on_bars", False):
optimization_scores_on_bars = config.get("optimization_scores", [0.3, 0.3, 0.35])
else:
optimization_scores_on_bars = config.get("custom_scores_on_bars", [])


# Set up a colormap for gradient color
colormap_range = config.get("colormap_range", [0.2, 0.5, 0.8])
# colors = plt.cm.get_cmap(config['colormap'])(colormap_range)
colors = mpl.colormaps.get_cmap(config["colormap"])(colormap_range)


# Set figure size and resolution
fig, ax = plt.subplots(
figsize=(
config["figure"]["figsize"]["width"],
config["figure"]["figsize"]["height"],
),
dpi=config["figure"]["dpi"],
)

# Customize bar width and use gradient colors
bars = ax.bar(
categories,
optimization_scores,
width=config["bar_width"],
color=colors,
edgecolor="None",
)

# Add Optimization Scores on top of the bars
if config.get("display_scores_on_bars", False):
for bar, score in zip(bars, optimization_scores_on_bars):
ax.text(
bar.get_x() + bar.get_width() / 2,
bar.get_height() + 0.01,
config.get("scores_format_on_bars", "{score:.2f}").format(score=score),
ha="center",
va="bottom",
fontsize=config["label_fontsize"],
)
# ax.text(bar.get_x() + bar.get_width() / 2, bar.get_height() + 0.01, f'{score:.2f}', ha='center', va='bottom', fontsize=config['label_fontsize'])

# Adjust font size for ticks
ax.set_xticks(ax.get_xticks())
ax.set_xticklabels(
categories,
fontsize=config["label_fontsize"],
rotation=config["rotation_angle"],
ha="right",
)
ax.tick_params(
axis="x", which="both", direction="in"
) # Set x-axis ticks direction to 'in'

ax.set_yticks(ax.get_yticks())
ax.set_yticklabels(
[f"{tick:.2f}" for tick in ax.get_yticks()], fontsize=config["label_fontsize"]
)
ax.tick_params(
axis="y", which="both", direction="in"
) # Set y-axis ticks direction to 'in'

# Remove right and top spines
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)

# Set the color of dashed lines for right and top frame
ax.spines["right"].set_linestyle(config["line_style"])
ax.spines["top"].set_linestyle(config["line_style"])
ax.spines["right"].set_edgecolor(config["line_color"])
ax.spines["top"].set_edgecolor(config["line_color"])

# Add dashed grid lines for both x-axis and y-axis ticks
ax.grid(
axis="both",
linestyle=config["line_style"],
linewidth=config["line_width"],
color=config["line_color"],
alpha=config["line_alpha"],
)

# Set labels and title
ax.set_xlabel(config["x_label"], fontsize=config["label_fontsize"])
ax.set_ylabel(config["y_label"], fontsize=config["label_fontsize"])
ax.set_title(config["plot_title"], fontsize=config["label_fontsize"])

# Save the plot with higher quality
plt.savefig(config["output_filename"], dpi=config["figure"]["dpi"], bbox_inches="tight")

# Show the plot
plt.show()
59 changes: 41 additions & 18 deletions onediff_comfy_nodes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,52 @@
<img src="../imgs/onediff_logo.png" height="100">
</p>

Performance of Community Edition
---

Updated on DEC 7, 2023. Device: RTX 3090
Performance of Community Edition

| SDXL1.0-base (1024x1024) | torch(Baseline) | onediff(Optimized) | Percentage improvement |
| -------------------------------------------------------------- | --------------- | ------------------ | ---------------------- |
| [Stable Diffusion workflow(UNet)](workflows/model-speedup.png) | 4.08it/s | 6.70it/s | 64.2 % |
| [LoRA workflow](workflows/model-speedup-lora.png) | 4.05it/s | 6.69it/s | 65.1 % |
Updated on January 23, 2024. Device: RTX 3090


<div align="center">

**SDXL End2End Time** , Image Size 1024x1024 , Batch Size 1 , steps 20

<a href="https://github.com/siliconflow/onediff/tree/main" target="_blank">
<img width="100%" src="../imgs/comfy_community_version_speed.png"></a>
</div>


<details>
<summary> Figure Notes </summary>

- Workflow Download Links
- [SDXL 1.0 (Base)](https://github.com/siliconflow/onediff/releases/download/0.12.0/basic_base.png)
- [SDXL 1.0 (OneDiff)](https://github.com/siliconflow/onediff/releases/download/0.12.0/basic_onediff.png)
- [LoRA (Base)](https://github.com/siliconflow/onediff/releases/download/0.12.0/lora_base.png)
- [LoRA (OneDiff)](https://github.com/siliconflow/onediff/releases/download/0.12.0/lora_onediff.png)
- [ControlNet (Base)](https://github.com/siliconflow/onediff/releases/download/0.12.0/controlnet_base.png)
- [ControlNet (OneDiff)](https://github.com/siliconflow/onediff/releases/download/0.12.0/controlnet_onediff.png)


</details>

## Documentation

- [Installation Guide](#installation-guide)
- [Setup Community Edition](#setup-community-edition)
- [Setup Enterprise Edition](#setup-enterprise-edition)
- [Basical Nodes Usage](#basical-nodes-usage)
- [OneDiff LoadCheckpoint ](#load-checkpoint---onediff)
- [Quantization](#quantization)
- [OneDiff Community Examples](#onediff-community-examples)
- [LoRA](#lora)
- [ControlNet](#controlnet)
- [SVD](#svd)
- [DeepCache](#deepcache)
- [Contact](#contact)
- [OneDiff ComfyUI Nodes](#onediff-comfyui-nodes)
- [Documentation](#documentation)
- [Installation Guide](#installation-guide)
- [Setup Community Edition](#setup-community-edition)
- [Setup Enterprise Edition](#setup-enterprise-edition)
- [Basical Nodes Usage](#basical-nodes-usage)
- [Load Checkpoint - OneDiff](#load-checkpoint---onediff)
- [Quantization](#quantization)
- [OneDiff Community Examples](#onediff-community-examples)
- [LoRA](#lora)
- [ControlNet](#controlnet)
- [SVD](#svd)
- [DeepCache](#deepcache)
- [Contact](#contact)


### Installation Guide
Expand Down

0 comments on commit f481e6c

Please sign in to comment.