-
Notifications
You must be signed in to change notification settings - Fork 4
Add graph loading benchmark #16
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
Open
jackalcooper
wants to merge
14
commits into
main
Choose a base branch
from
add-graph-sharing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b5adf24
check in demo
jackalcooper ffeefd1
refine readme
jackalcooper 01a595d
revert
jackalcooper ecd536f
update demo
jackalcooper a806f35
refine
jackalcooper 6b43399
update
jackalcooper fd8f509
add
jackalcooper bc2aac0
add
jackalcooper 79939fa
add
jackalcooper c862fa3
refine
jackalcooper f380c1f
refine
jackalcooper 4371bd1
fix
jackalcooper 561eea6
rm
jackalcooper 5ea08c5
refine
jackalcooper 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 hidden or 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,2 @@ | ||
| # Examples to run oneflow SD | ||
| This directory contains scripts for non-throughput performance benchmarks/tests, for instance the performance of cache or compilation. |
This file contains hidden or 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,4 @@ | ||
| set -e | ||
| export ONEFLOW_NNGRAPH_ENABLE_PROGRESS_BAR=1 | ||
| time python3 examples/graph-cache/infer.py --save | ||
| time python3 examples/graph-cache/infer.py --load |
This file contains hidden or 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,83 @@ | ||
| import os | ||
|
|
||
| import argparse | ||
| import oneflow as torch | ||
| from diffusers import OneFlowStableDiffusionPipeline | ||
|
|
||
|
|
||
| def parse_args(): | ||
| parser = argparse.ArgumentParser(description="Simple demo of image generation.") | ||
| parser.add_argument( | ||
| "--prompt", type=str, default="a photo of an astronaut riding a horse on mars" | ||
| ) | ||
| parser.add_argument("--cache", type=str, default="./oneflow-sd/graph_cache") | ||
| parser.add_argument("--model", type=str, default="./oneflow-sd/model") | ||
| parser.add_argument( | ||
| "--load", | ||
| default=False, | ||
| action="store_true", | ||
| help="If specified, load from cache", | ||
| ) | ||
| parser.add_argument( | ||
| "--save", | ||
| default=False, | ||
| action="store_true", | ||
| help="If specified, save to cache", | ||
| ) | ||
| args = parser.parse_args() | ||
| return args | ||
|
|
||
|
|
||
| args = parse_args() | ||
|
|
||
| model = "CompVis/stable-diffusion-v1-4" | ||
| if args.load: | ||
| # Note: restore the cache by setting the pretrain path to a cache path | ||
| model = args.model | ||
| print(f"will load pipe from: {args.cache}") | ||
| pipe = OneFlowStableDiffusionPipeline.from_pretrained( | ||
| model, | ||
| use_auth_token=True, | ||
| revision="fp16", | ||
| torch_dtype=torch.float16, | ||
| safety_checker=None, | ||
| ) | ||
|
|
||
| pipe = pipe.to("cuda") | ||
|
|
||
| output_dir = "oneflow-sd-output" | ||
| os.makedirs(output_dir, exist_ok=True) | ||
|
|
||
| pipe.set_unet_graphs_cache_size(10) | ||
| pipe.enable_graph_share_mem() | ||
| # Note: enable saving/loading graph-related cache, these APIs are tricky and might be changed | ||
| if args.save: | ||
| pipe.enable_save_graph() | ||
| if args.load: | ||
| pipe.load_graph(args.cache) | ||
|
|
||
|
|
||
| def do_infer(n): | ||
| with torch.autocast("cuda"): | ||
| for i in [2, 1, 0]: | ||
| for j in [2, 1, 0]: | ||
| width = 768 + 128 * i | ||
| height = 768 + 128 * j | ||
| prompt = args.prompt | ||
| images = pipe(prompt, width=width, height=height).images | ||
| for i, image in enumerate(images): | ||
| prompt = prompt.strip().replace("\n", " ") | ||
| dst = os.path.join( | ||
| output_dir, f"{prompt[:100]}-{n}-{width}-{height}.png" | ||
| ) | ||
| image.save(dst) | ||
|
|
||
|
|
||
| for n in range(2): | ||
| do_infer(n) | ||
| if args.save: | ||
| pipe.save_pretrained(args.model) | ||
| print(f"saving cache to: {args.cache}") | ||
| os.makedirs(args.cache, exist_ok=True) | ||
| # Note: save graph cache | ||
| pipe.save_graph(args.cache) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.