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 08f1a59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 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,12 @@ def _process_req(self, image, prompt, **kwargs):
"negative_prompt": kwargs.get("negative_prompt", None),
"guidance_scale": kwargs.get("guidance_scale", 7),
}
if "guidance_scale" not in kwargs:
default_guidance_scale = os.getenv("DEFAULT_GUIDANCE_SCALE")
if default_guidance_scale is not None:
kwargs["guidance_scale"] = float(default_guidance_scale)
prior_args["guidance_scale"] = float(default_guidance_scale)
# Else, don't specify anything, leave the default behaviour
image_emb, zero_image_emb = self.prior(prompt, **prior_args).to_tuple()
images = self.ldm(
prompt,
Expand Down
5 changes: 5 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,11 @@ def _process_req(self, inputs, **kwargs):
kwargs["num_inference_steps"] = 20
# Else, don't specify anything, leave the default behaviour

if "guidance_scale" not in kwargs:
default_guidance_scale = os.getenv("DEFAULT_GUIDANCE_SCALE")
if default_guidance_scale is not None:
kwargs["guidance_scale"] = float(default_guidance_scale)
# Else, don't specify anything, leave the default behaviour
if "seed" in kwargs:
seed = int(kwargs["seed"])
generator = torch.Generator().manual_seed(seed)
Expand Down

0 comments on commit 08f1a59

Please sign in to comment.