From f8360a48313553a5ae010c916dede0af2649e631 Mon Sep 17 00:00:00 2001 From: Cauldrath Date: Tue, 19 Dec 2023 18:35:09 -0500 Subject: [PATCH] Fix zero height buckets If max_size is too large relative to max_reso, it will calculate a height of zero for some buckets. This causes a crash later when it divides the width by the height. This change also simplifies some math and consolidates the redundant "size" variable into "width". --- library/model_util.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/library/model_util.py b/library/model_util.py index 00a3c049..858c86c3 100644 --- a/library/model_util.py +++ b/library/model_util.py @@ -1307,19 +1307,19 @@ def load_vae(vae_id, dtype): def make_bucket_resolutions(max_reso, min_size=256, max_size=1024, divisible=64): max_width, max_height = max_reso - max_area = (max_width // divisible) * (max_height // divisible) + max_area = max_width * max_height resos = set() - size = int(math.sqrt(max_area)) * divisible - resos.add((size, size)) + width = int(math.sqrt(max_area) // divisible) * divisible + resos.add((width, width)) - size = min_size - while size <= max_size: - width = size - height = min(max_size, (max_area // (width // divisible)) * divisible) - resos.add((width, height)) - resos.add((height, width)) + width = min_size + while width <= max_size: + height = min(max_size, int((max_area // width) // divisible) * divisible) + if height > 0: + resos.add((width, height)) + resos.add((height, width)) # # make additional resos # if width >= height and width - divisible >= min_size: @@ -1329,7 +1329,7 @@ def make_bucket_resolutions(max_reso, min_size=256, max_size=1024, divisible=64) # resos.add((width, height - divisible)) # resos.add((height - divisible, width)) - size += divisible + width += divisible resos = list(resos) resos.sort()