diff --git a/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py b/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py index bada59080c7b..e02391b7a402 100644 --- a/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py +++ b/src/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_controlnet.py @@ -103,13 +103,11 @@ # Copied from diffusers.pipelines.kandinsky2_2.pipeline_kandinsky2_2.downscale_height_and_width def downscale_height_and_width(height, width, scale_factor=8): - new_height = height // scale_factor**2 - if height % scale_factor**2 != 0: - new_height += 1 - new_width = width // scale_factor**2 - if width % scale_factor**2 != 0: - new_width += 1 - return new_height * scale_factor, new_width * scale_factor + # Optimize by avoiding repeated exponentiation and using integer division with ceil in a single step + sf2 = scale_factor * scale_factor + new_height = -(-height // sf2) * scale_factor # Equivalent to math.ceil(height/sf2)*scale_factor + new_width = -(-width // sf2) * scale_factor + return new_height, new_width class KandinskyV22ControlnetPipeline(DiffusionPipeline):