in benchmark/muse_perf.py [0:0]
def sd_turbo_benchmark(batch_size, timesteps, use_xformers):
model = "stabilityai/sd-turbo"
dtype = torch.float16
pipe = AutoPipelineForText2Image.from_pretrained(model, torch_dtype=torch.float16, variant="fp16", safety_checker=None)
pipe.to("cuda")
if use_xformers:
pipe.enable_xformers_memory_efficient_attention()
def benchmark_fn():
pipe(
prompt,
num_images_per_prompt=batch_size,
num_inference_steps=timesteps,
)
pipe(prompt, num_images_per_prompt=batch_size, num_inference_steps=2)
def fn():
return Timer(
stmt="benchmark_fn()",
globals={"benchmark_fn": benchmark_fn},
num_threads=num_threads,
label=f"batch_size: {batch_size}, dtype: {dtype}, timesteps {timesteps}, use_xformers: {use_xformers}",
description=model,
).blocked_autorange(min_run_time=1)
return measure_max_memory_allocated(fn)