-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[feat: Benchmarking Workflow] add stuff for a benchmarking workflow #5839
Merged
Merged
Changes from 1 commit
Commits
Show all changes
118 commits
Select commit
Hold shift + click to select a range
4c185f0
add poc for benchmarking workflow.
sayakpaul 945ab17
import
sayakpaul b4debda
fix argument
sayakpaul 22966a1
fix: argument
sayakpaul 12424a3
fix: path
sayakpaul 122d5d9
fix
sayakpaul c20d254
fix
sayakpaul 43544ed
path
sayakpaul ada65b3
Merge branch 'main' into feat/ci-benchmarking
sayakpaul f59e315
Merge branch 'main' into feat/ci-benchmarking
sayakpaul 3c05e41
output csv files.
sayakpaul 24b68fd
workflow cleanup
sayakpaul 8e2088e
append token
sayakpaul 01584c7
add utility to push to hf dataset
sayakpaul 853035b
fix: kw arg
sayakpaul 46aaf96
better reporting
sayakpaul d626eef
fix: headers
sayakpaul ab12fe6
better formatting of the numbers.
sayakpaul 1bb531e
better type annotation
sayakpaul 2df4aba
fix: formatting
sayakpaul 939fe5c
moentarily disable check
sayakpaul 3a18e29
push results.
sayakpaul 71279b6
remove disable check
sayakpaul ea1e57e
Merge branch 'main' into feat/ci-benchmarking
sayakpaul 3c8cc38
introduce base classes.
sayakpaul 9683cd7
img2img class
sayakpaul 274b9e1
add inpainting pipeline
sayakpaul 2b5b8ae
intoduce base benchmark class.
sayakpaul 0b54a6a
Merge branch 'main' into feat/ci-benchmarking
sayakpaul 66b159a
add img2img and inpainting
sayakpaul 01addbd
feat: utility to compare changes
sayakpaul c30cab6
fix
sayakpaul 689b9f7
fix import
sayakpaul d046a25
add args
sayakpaul 71f6bd9
basepath
sayakpaul 295cf30
better exception handling
sayakpaul b5e2371
better path handling
sayakpaul e7aed9e
fix
sayakpaul 8eb8baf
fix
sayakpaul aac35c3
Merge branch 'main' into feat/ci-benchmarking
sayakpaul 3cb02f8
remove
sayakpaul 60c980c
ifx
sayakpaul 1e7db92
Merge branch 'main' into feat/ci-benchmarking
patrickvonplaten cd91b62
fix
sayakpaul 38b8708
Merge branch 'main' into feat/ci-benchmarking
sayakpaul aeefb55
Merge branch 'main' into feat/ci-benchmarking
sayakpaul 1782d5a
add: support for controlnet.
sayakpaul df5dead
image_url -> url
sayakpaul c6c545c
move images to huggingface hub
sayakpaul b358c87
correct urls.
sayakpaul 93b491b
root_ckpt
sayakpaul 131bfce
Merge branch 'main' into feat/ci-benchmarking
sayakpaul 13a86dc
Merge branch 'main' into feat/ci-benchmarking
sayakpaul 748f6dc
flush before benchmarking
sayakpaul 5d5d5fd
don't install accelerate from source
sayakpaul 4651082
add runner
sayakpaul 8e80579
simplify Diffusers Benchmarking step
sayakpaul d49ad65
change runner
sayakpaul 7c7846b
fix: subprocess call.
sayakpaul 5dbcbf5
filter percentage values
sayakpaul cb8572a
fix controlnet benchmark
sayakpaul 6dec96c
add t2i adapters.
sayakpaul 86d597f
fix filter columns
sayakpaul fa7bfe1
fix t2i adapter benchmark
sayakpaul 59df524
fix init.
sayakpaul 3cd0f59
fix
sayakpaul 8583db8
remove safetensors flag
sayakpaul 6b9bf4a
fix args print
sayakpaul 38160f1
fix
sayakpaul e6116b0
feat: run_command
sayakpaul d98fbe1
add adapter resolution mapping
sayakpaul c93278d
benchmark t2i adapter fix.
sayakpaul 924096f
fix adapter input
sayakpaul 628591d
fix
sayakpaul 0f4ae4e
convert to L.
sayakpaul de739fa
add flush() add appropriate places
sayakpaul cb9f9c6
better filtering
sayakpaul d7aee28
okay
sayakpaul 385ffbb
get env for torch
sayakpaul 611ae13
convert to float
sayakpaul b3a91d8
fix
sayakpaul e55913e
filter out nans.
sayakpaul dc3063a
better coment
sayakpaul 63aee79
sdxl
sayakpaul 9a9d5ea
sdxl for other benchmarks.
sayakpaul 3d66747
Merge branch 'main' into feat/ci-benchmarking
sayakpaul c8f6eef
fix: condition
sayakpaul 4a67437
fix: condition for inpainting
sayakpaul e94b895
Merge branch 'main' into feat/ci-benchmarking
sayakpaul eedf218
fix: mapping for resolution
sayakpaul e300038
fix
sayakpaul 60614f5
include kandinsky and wuerstchen
sayakpaul b394168
fix: Wuerstchen
sayakpaul 70f3556
Merge branch 'main' into feat/ci-benchmarking
sayakpaul b7eb3fb
Empty-Commit
sayakpaul 63a61bd
Merge branch 'main' into feat/ci-benchmarking
DN6 821726d
[Community] AnimateDiff + Controlnet Pipeline (#5928)
a-r-r-o-w 3dc2362
EulerDiscreteScheduler add `rescale_betas_zero_snr` (#6024)
Beinsezii 26a8c00
Revert "[Community] AnimateDiff + Controlnet Pipeline (#5928)"
sayakpaul 8db59d7
Revert "EulerDiscreteScheduler add `rescale_betas_zero_snr` (#6024)"
sayakpaul f76ba5b
Merge branch 'main' into feat/ci-benchmarking
sayakpaul 4e7fb4d
add SDXL turbo
sayakpaul e2df761
add lcm lora to the mix as well.
sayakpaul 2588853
fix
sayakpaul 81d56de
Merge branch 'main' into feat/ci-benchmarking
sayakpaul a7fd2c3
increase steps to 2 when running turbo i2i
sayakpaul 191ebf6
Merge branch 'main' into feat/ci-benchmarking
sayakpaul b878a29
debug
sayakpaul 1389d0e
debug
sayakpaul b2d35be
debug
sayakpaul d78609d
fix for good
sayakpaul b3897f8
fix and isolate better
sayakpaul 8289baa
fuse lora so that torch compile works with peft
sayakpaul dd54366
fix: LCMLoRA
sayakpaul d6966b4
Merge branch 'main' into feat/ci-benchmarking
sayakpaul 51acace
better identification for LCM
sayakpaul 65b97e8
Merge branch 'main' into feat/ci-benchmarking
sayakpaul 80e8311
change to cron job
sayakpaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Benchmarking tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- ci-* | ||
|
||
env: | ||
DIFFUSERS_IS_CI: yes | ||
HF_HOME: /mnt/cache | ||
OMP_NUM_THREADS: 8 | ||
MKL_NUM_THREADS: 8 | ||
PYTEST_TIMEOUT: 600 | ||
RUN_SLOW: yes | ||
PIPELINE_USAGE_CUTOFF: 50000 | ||
|
||
jobs: | ||
torch_pipelines_cuda_benchmark_tests: | ||
name: Torch Core Pipelines CUDA Benchmarking Tests | ||
sayakpaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
strategy: | ||
fail-fast: false | ||
max-parallel: 1 | ||
runs-on: docker-gpu | ||
container: | ||
image: diffusers/diffusers-pytorch-cuda | ||
options: --shm-size "16gb" --ipc host -v /mnt/hf_cache:/mnt/cache/ --gpus 0 | ||
steps: | ||
- name: Checkout diffusers | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 2 | ||
- name: NVIDIA-SMI | ||
run: | | ||
nvidia-smi | ||
- name: Install dependencies | ||
run: | | ||
apt-get update && apt-get install libsndfile1-dev libgl1 -y | ||
python -m pip install -e .[quality,test] | ||
python -m pip install git+https://github.com/huggingface/accelerate.git | ||
sayakpaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mkdir benchmark_outputs | ||
- name: Environment | ||
run: | | ||
python utils/print_env.py | ||
- name: Stable Diffusion Benchmarking Tests | ||
env: | ||
HUGGING_FACE_HUB_TOKEN: ${{ secrets.HUGGING_FACE_HUB_TOKEN }} | ||
run: | | ||
cd benchmarks && python benchmark_sd.py && \ | ||
python benchmark_sd.py --batch_size 4 && \ | ||
python benchmark_sd.py --run_compile && \ | ||
python benchmark_sd.py --batch_size 4 --run_compile | ||
|
||
sayakpaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- name: Test suite reports artifacts | ||
if: ${{ always() }} | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: benchmark_test_reports | ||
path: benchmark_outputs | ||
sayakpaul marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import argparse | ||
import os | ||
import torch | ||
from diffusers import DiffusionPipeline | ||
from .benchmark_utils import benchmark_fn, bytes_to_giga_bytes, BenchmarkInfo, generate_markdown_table | ||
|
||
CKPT = "CompVis/stable-diffusion-v1-4" | ||
sayakpaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PROMPT = "ghibli style, a fantasy landscape with castles" | ||
BASE_PATH = "benchmark_outputs" | ||
|
||
|
||
def load_pipeline(run_compile=False, with_tensorrt=False): | ||
pipe = DiffusionPipeline.from_pretrained( | ||
CKPT, torch_dtype=torch.float16, use_safetensors=True | ||
) | ||
pipe = pipe.to("cuda") | ||
|
||
if run_compile: | ||
pipe.unet.to(memory_format=torch.channels_last) | ||
print("Run torch compile") | ||
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True) | ||
|
||
pipe.set_progress_bar_config(disable=True) | ||
return pipe | ||
|
||
|
||
def run_inference(pipe, args): | ||
_ = pipe( | ||
prompt=PROMPT, | ||
num_inference_steps=args.num_inference_steps, | ||
num_images_per_prompt=args.batch_size, | ||
) | ||
|
||
def main(args): | ||
pipeline = load_pipeline( | ||
run_compile=args.run_compile, with_tensorrt=args.with_tensorrt | ||
) | ||
|
||
time = benchmark_fn(run_inference, pipeline, args) # in seconds. | ||
memory = bytes_to_giga_bytes(torch.cuda.max_memory_allocated()) # in GBs. | ||
benchmark_info = BenchmarkInfo(time=time, memory=memory) | ||
|
||
markdown_report = "" | ||
markdown_report = generate_markdown_table(pipeline_name=CKPT, args=args, benchmark_info=benchmark_info, markdown_report=markdown_report) | ||
return markdown_report | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--batch_size", type=int, default=1) | ||
parser.add_argument("--num_inference_steps", type=int, default=50) | ||
parser.add_argument("--run_compile", action="store_true") | ||
args = parser.parse_args() | ||
markdown_report = main(args) | ||
|
||
name = CKPT + f"-batch_sze@{args.batch_size}-num_inference_steps@{args.num_inference_steps}--run_compile@{args.run_compile}" | ||
filepath = os.path.join(BASE_PATH, name) | ||
with open(filepath, "w") as f: | ||
f.write(markdown_report) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import gc | ||
import torch | ||
import torch.utils.benchmark as benchmark | ||
from dataclasses import dataclass | ||
import argparse | ||
|
||
@dataclass | ||
class BenchmarkInfo: | ||
time: float | ||
memory: float | ||
|
||
|
||
def flush(): | ||
gc.collect() | ||
torch.cuda.empty_cache() | ||
|
||
def bytes_to_giga_bytes(bytes): | ||
return bytes / 1024 / 1024 / 1024 | ||
|
||
|
||
# Adapted from | ||
# https://pytorch.org/tutorials/intermediate/scaled_dot_product_attention_tutorial.html | ||
def benchmark_fn(f, *args, **kwargs): | ||
t0 = benchmark.Timer( | ||
stmt="f(*args, **kwargs)", globals={"args": args, "kwargs": kwargs, "f": f} | ||
) | ||
return f"{(t0.blocked_autorange().mean):.3f}" | ||
|
||
def generate_markdown_table(pipeline_name: str, args: argparse.Namespace, benchmark_info: BenchmarkInfo) -> str: | ||
headers = ["**Parameter**", "**Value**"] | ||
data = [ | ||
["Batch Size", args.batch_size], | ||
["Number of Inference Steps", args.num_inference_steps], | ||
["Run Compile", args.run_compile], | ||
["Time (seconds)", benchmark_info.time], | ||
["Memory (GBs)", benchmark_info.memory] | ||
] | ||
|
||
# Formatting the table. | ||
markdown_table = f"## {pipeline_name}\n\n" | ||
markdown_table += "| " + " | ".join(headers) + " |\n" | ||
markdown_table += "|-" + "-|-".join(['' for _ in headers]) + "-|\n" | ||
for row in data: | ||
markdown_table += "| " + " | ".join(str(item) for item in row) + " |\n" | ||
|
||
return markdown_table |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should ideally be done weekly or bi-weekly and only on
main
. For testing, I am running it on PRs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think bi-weekly (twice a month?) Works here. Or even monthly is a good cadence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. Will keep it to bi-weekly. Will incorporate that change once we're one with how we want to report the benchmarks and the pipelines we want to benchmark.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should change this to a cron job
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this will be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to cron job.