Skip to content

Commit 6570136

Browse files
committed
trigger VAE tiling by image area instead of dimensions
I've tested with GGML_VULKAN_MEMORY_DEBUG all resolutions with the same 768x768 area (even extremes like 64x9216), and many below that: all consistently allocate 6656 bytes per image pixel. As tiling is primarily useful to avoid excessive memory usage, it seems reasonable to enable VAE tiling based on area rather than maximum image side. However, as there is currently no user interface option to change it back to a lower value, it's best to maintain the default behavior for now.
1 parent a82b1d9 commit 6570136

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

otherarch/sdcpp/sdtype_adapter.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,17 +475,24 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
475475
}
476476

477477
int tiled_vae_threshold;
478+
bool dotile;
478479
if (cfg_tiled_vae_threshold == 0) {
480+
// Legacy behavior: limit by image dimensions
479481
tiled_vae_threshold = 768;
482+
dotile = (sd_params->width>tiled_vae_threshold || sd_params->height>tiled_vae_threshold);
480483
} else {
481484
if (cfg_tiled_vae_threshold > 0) {
482485
tiled_vae_threshold = cfg_tiled_vae_threshold;
483486
} else {
484487
tiled_vae_threshold = 8192; // effectively avoids tiling
485488
}
489+
// when explicitely set, limit by image area
490+
// on the Vulkan backend, typically limited at 4G for a single allocation,
491+
// the memory used for the VAE buffer is 6656 bytes per image pixel; a
492+
// 768x768 square image (and all resolutions with the same area) stays a
493+
// bit below that limit, at 3.66G.
494+
dotile = (sd_params->width*sd_params->height > tiled_vae_threshold*tiled_vae_threshold);
486495
}
487-
488-
bool dotile = (sd_params->width>tiled_vae_threshold || sd_params->height>tiled_vae_threshold);
489496
set_sd_vae_tiling(sd_ctx,dotile); //changes vae tiling, prevents memory related crash/oom
490497

491498
if (sd_params->clip_skip <= 0) {

0 commit comments

Comments
 (0)