Skip to content

Commit 59c912a

Browse files
committed
Keep explicitly small VAE tiles from growing on the seam fix and the retry
1 parent ee5829c commit 59c912a

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎src/core/backend_fit.cpp‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,10 @@ namespace sd::backend_fit {
512512
} else if (tiling_params.rel_size_x > 0.f && tiling_params.rel_size_x <= 1.f &&
513513
tiling_params.rel_size_y > 0.f && tiling_params.rel_size_y <= 1.f &&
514514
std::max(tiling_params.rel_size_x, tiling_params.rel_size_y) > min_rel_size) {
515-
tiling_params.rel_size_x = std::max(tiling_params.rel_size_x * 0.5f, min_rel_size);
516-
tiling_params.rel_size_y = std::max(tiling_params.rel_size_y * 0.5f, min_rel_size);
515+
// An axis already below the floor keeps its size: clamping it up would grow the tile that just failed.
516+
auto shrink = [&](float rel) { return rel > min_rel_size ? std::max(rel * 0.5f, min_rel_size) : rel; };
517+
tiling_params.rel_size_x = shrink(tiling_params.rel_size_x);
518+
tiling_params.rel_size_y = shrink(tiling_params.rel_size_y);
517519
if (tiling_params.target_overlap <= 0.f) {
518520
tiling_params.target_overlap = 0.5f;
519521
}

‎src/runtime/tiling.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ int sd_tiling_seam_safe_tile_size(int small_dim, int tile_size, float tile_overl
6262
// sd_tiling_calc_tiles lets the real overlap fall well below the target for some sizes. The worst case is a
6363
// tile a little over half of the axis (e.g. round(dim / 2)): it falls back to two tiles overlapping by
6464
// 2 * tile_size - small_dim, which is 0 or 1 latent, so the cross-fade has nothing to blend over and the tile
65-
// edge shows as a line. Pick the nearest tile size (smaller first, so memory use never grows unless nothing
66-
// smaller works) whose tiles overlap by at least half the target and never by less than 2 latents.
65+
// edge shows as a line. Pick the nearest tile size (smaller first; a larger one only up to twice the request,
66+
// so an explicitly small tile cannot balloon) whose tiles overlap by at least half the target and by 2+ latents.
6767
const int min_tile_size = 4;
6868
if (tile_overlap_factor <= 0.f || tile_size >= small_dim) {
6969
return tile_size;
@@ -81,7 +81,7 @@ int sd_tiling_seam_safe_tile_size(int small_dim, int tile_size, float tile_overl
8181
return size;
8282
}
8383
}
84-
for (int size = tile_size + 1; size < small_dim; ++size) {
84+
for (int size = tile_size + 1; size < small_dim && size <= 2 * tile_size; ++size) {
8585
if (overlaps_enough(size)) {
8686
return size;
8787
}

0 commit comments

Comments
 (0)