Skip to content

Commit 2cedfbd

Browse files
committed
Diffusers, txt2img (and img2img when supported), make sure guidance scale defaults to 0 when num steps <=4
Signed-off-by: Raphael Glon <[email protected]>
1 parent 5dd8409 commit 2cedfbd

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/huggingface_inference_toolkit/diffusers_utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ def __call__(
6565
logger.warning("Sending num_images_per_prompt > 1 to pipeline is not supported. Using default value 1.")
6666

6767
if "num_inference_steps" not in kwargs:
68-
kwargs["num_inference_steps"] = int(os.environ.get("DEFAULT_NUM_INFERENCE_STEPS", 50))
68+
default_num_steps = os.environ.get("DEFAULT_NUM_INFERENCE_STEPS")
69+
if default_num_steps:
70+
kwargs["num_inference_steps"] = int(default_num_steps)
71+
72+
if "guidance_scale" not in kwargs:
73+
guidance_scale = os.environ.get("DEFAULT_GUIDANCE_SCALE")
74+
if guidance_scale is not None:
75+
kwargs["guidance_scale"] = float(guidance_scale)
6976

7077
if "target_size" in kwargs:
7178
kwargs["height"] = kwargs["target_size"].pop("height", None)

0 commit comments

Comments
 (0)