From cbc2ac12dd44ccd8df41206941d8cc2b79dfa4af Mon Sep 17 00:00:00 2001 From: sigma Date: Mon, 13 Apr 2026 00:04:20 +0000 Subject: [PATCH] autocast --- app.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app.py b/app.py index 24f84fb..8ebcea2 100644 --- a/app.py +++ b/app.py @@ -531,18 +531,20 @@ def infer( print(f"Rewritten Prompt: {prompt}") - # Generate the image - image = pipe( - image=pil_images if len(pil_images) > 0 else None, - prompt=prompt, - height=height, - width=width, - negative_prompt=negative_prompt, - num_inference_steps=num_inference_steps, - generator=generator, - true_cfg_scale=true_guidance_scale, - num_images_per_prompt=num_images_per_prompt, - ).images + # Enable Autocast for better results. + with torch.autocast(device_type="cuda", dtype=torch.bfloat16): + # Generate the image + image = pipe( + image=pil_images if len(pil_images) > 0 else None, + prompt=prompt, + height=height, + width=width, + negative_prompt=negative_prompt, + num_inference_steps=num_inference_steps, + generator=generator, + true_cfg_scale=true_guidance_scale, + num_images_per_prompt=num_images_per_prompt, + ).images _maintain_session_state( primary_buffers=image,