Skip to content

Commit

Permalink
Diffusers, txt2img and img2img, make sure guidance scale defaults to …
Browse files Browse the repository at this point in the history
…0 when num steps <=4

Signed-off-by: Raphael Glon <[email protected]>
  • Loading branch information
oOraph committed Oct 25, 2024
1 parent 4a49933 commit 8410cc9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docker_images/diffusers/app/pipelines/image_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ def _process_req(self, image, prompt, **kwargs):
"negative_prompt": kwargs.get("negative_prompt", None),
"guidance_scale": kwargs.get("guidance_scale", 7),
}
if int(kwargs["num_inference_steps"]) <= 4 and 'guidance_scale' not in kwargs.keys():
kwargs["guidance_scale"] = 0
prior_args["guidance_scale"] = 0
image_emb, zero_image_emb = self.prior(prompt, **prior_args).to_tuple()
images = self.ldm(
prompt,
Expand Down
3 changes: 3 additions & 0 deletions docker_images/diffusers/app/pipelines/text_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ def _process_req(self, inputs, **kwargs):
kwargs["num_inference_steps"] = 20
# Else, don't specify anything, leave the default behaviour

if int(kwargs.get("num_inference_steps", 20)) <= 4 and 'guidance_scale' not in kwargs.keys():
kwargs["guidance_scale"] = 0

if "seed" in kwargs:
seed = int(kwargs["seed"])
generator = torch.Generator().manual_seed(seed)
Expand Down

0 comments on commit 8410cc9

Please sign in to comment.