Skip to content

Commit 496e5f2

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 5919014 commit 496e5f2

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
@@ -483,17 +483,24 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
483483
}
484484

485485
int tiled_vae_threshold;
486+
bool dotile;
486487
if (cfg_tiled_vae_threshold == 0) {
488+
// Legacy behavior: limit by image dimensions
487489
tiled_vae_threshold = 768;
490+
dotile = (sd_params->width>tiled_vae_threshold || sd_params->height>tiled_vae_threshold);
488491
} else {
489492
if (cfg_tiled_vae_threshold > 0) {
490493
tiled_vae_threshold = cfg_tiled_vae_threshold;
491494
} else {
492495
tiled_vae_threshold = 8192; // effectively avoids tiling
493496
}
497+
// when explicitely set, limit by image area
498+
// on the Vulkan backend, typically limited at 4G for a single allocation,
499+
// the memory used for the VAE buffer is 6656 bytes per image pixel; a
500+
// 768x768 square image (and all resolutions with the same area) stays a
501+
// bit below that limit, at 3.66G.
502+
dotile = (sd_params->width*sd_params->height > tiled_vae_threshold*tiled_vae_threshold);
494503
}
495-
496-
bool dotile = (sd_params->width>tiled_vae_threshold || sd_params->height>tiled_vae_threshold);
497504
set_sd_vae_tiling(sd_ctx,dotile); //changes vae tiling, prevents memory related crash/oom
498505

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

0 commit comments

Comments
 (0)