Skip to content

Commit e959d46

Browse files
authored
chore: add perf mode to example (#319)
* chore: add perf mode to example * chore: add perf mode to example
1 parent d525c77 commit e959d46

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

examples/parallelism/run_qwen_image_cp.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,17 @@
8989

9090
def run_pipe():
9191
# do_true_cfg = true_cfg_scale > 1 and has_neg_prompt
92-
image = pipe(
92+
output = pipe(
9393
prompt=prompt + positive_magic["en"],
9494
negative_prompt=negative_prompt,
9595
width=1024 if args.width is None else args.width,
9696
height=1024 if args.height is None else args.height,
9797
num_inference_steps=50 if args.steps is None else args.steps,
9898
true_cfg_scale=4.0,
9999
generator=torch.Generator(device="cpu").manual_seed(42),
100-
).images[0]
101-
100+
output_type="latent" if args.perf else "pil",
101+
)
102+
image = output.images[0] if not args.perf else None
102103
return image
103104

104105

@@ -119,7 +120,8 @@ def run_pipe():
119120
time_cost = end - start
120121
save_path = f"qwen-image.{strify(args, pipe)}.png"
121122
print(f"Time cost: {time_cost:.2f}s")
122-
print(f"Saving image to {save_path}")
123-
image.save(save_path)
123+
if not args.perf:
124+
print(f"Saving image to {save_path}")
125+
image.save(save_path)
124126

125127
maybe_destroy_distributed()

examples/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def get_args(
6666
default=None,
6767
choices=[None, "flash", "_native_cudnn"],
6868
)
69+
parser.add_argument("--perf", action="store_true", default=False)
6970
return parser.parse_args() if parse else parser
7071

7172

0 commit comments

Comments
 (0)