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

Refine SVD diffusers example for graph save/load #836

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
Commits
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
30 changes: 26 additions & 4 deletions benchmarks/image_to_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--model", type=str, default=MODEL)
parser.add_argument("--save_graph", action="store_true")
parser.add_argument("--load_graph", action="store_true")
parser.add_argument("--variant", type=str, default=VARIANT)
parser.add_argument("--custom-pipeline", type=str, default=CUSTOM_PIPELINE)
parser.add_argument("--scheduler", type=str, default=SCHEDULER)
Expand Down Expand Up @@ -251,10 +253,22 @@ def get_kwarg_inputs():
return kwarg_inputs

if args.warmups > 0:
print("Begin warmup")
for _ in range(args.warmups):
pipe(**get_kwarg_inputs())
print("End warmup")
if args.load_graph:
print("Loading graphs to avoid compilation...")
start_t = time.time()
pipe.unet.load_graph("base_unet_compiled", run_warmup=True)
pipe.vae.decoder.load_graph("base_vae_compiled", run_warmup=True)
end_t = time.time()
print(f"Loading graph elapsed: {end_t - start_t} s")
print("Begin warmup")
for _ in range(args.warmups):
pipe(**get_kwarg_inputs())
print("End warmup")
else:
print("Begin warmup")
for _ in range(args.warmups):
pipe(**get_kwarg_inputs())
print("End warmup")

kwarg_inputs = get_kwarg_inputs()
iter_profiler = IterationProfiler()
Expand All @@ -280,6 +294,14 @@ def get_kwarg_inputs():
else:
print("Please set `--output-video` to save the output video")

if args.save_graph:
print("Saving graphs...")
start_t = time.time()
pipe.unet.save_graph("base_unet_compiled")
pipe.vae.decoder.save_graph("base_vae_compiled")
end_t = time.time()
print(f"save graphs elapsed: {end_t - start_t} s")


if __name__ == "__main__":
main()