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 <oOraph@users.noreply.github.com>
  • Loading branch information
oOraph committed Oct 25, 2024
1 parent 4a49933 commit 18a07ce
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
8 changes: 5 additions & 3 deletions docker_images/diffusers/app/lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ def _load_textual_embeddings(self, adapter, model_data):
if self._is_pivotal_tuning_lora(model_data):
embedding_path = self._hub_repo_file(
repo_id=adapter,
filename="embeddings.safetensors"
if self._is_safetensors_pivotal(model_data)
else "embeddings.pti",
filename=(
"embeddings.safetensors"
if self._is_safetensors_pivotal(model_data)
else "embeddings.pti"
),
repo_type="model",
)

Expand Down
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:
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:
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 18a07ce

Please sign in to comment.