Skip to content

Commit 680140d

Browse files
committed
add env var to change tile overlap
1 parent ff6127c commit 680140d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

stable-diffusion.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,18 @@ class StableDiffusionGGML {
14891489
LOG_WARN("OOR");
14901490
}
14911491
}
1492+
float tile_overlap = 0.5f;
1493+
const char* SD_TILE_OVERLAP = getenv("SD_TILE_OVERLAP");
1494+
if (SD_TILE_OVERLAP != nullptr) {
1495+
std::string sd_tile_overlap_str = SD_TILE_OVERLAP;
1496+
try {
1497+
tile_overlap = std::stof(sd_tile_overlap_str);
1498+
} catch (const std::invalid_argument&) {
1499+
LOG_WARN("Invalid");
1500+
} catch (const std::out_of_range&) {
1501+
LOG_WARN("OOR");
1502+
}
1503+
}
14921504
if(!decode){
14931505
// TODO: also use and arg for this one?
14941506
// to keep the compute buffer size consistent
@@ -1505,11 +1517,14 @@ class StableDiffusionGGML {
15051517
if (SD_TILE_SIZE != nullptr) {
15061518
LOG_INFO("VAE Tile size: %dx%d", tile_size_x, tile_size_y);
15071519
}
1520+
if (SD_TILE_OVERLAP != nullptr) {
1521+
LOG_INFO("VAE Tile overlap: %.2f", tile_overlap);
1522+
}
15081523
// split latent in 32x32 tiles and compute in several steps
15091524
auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) {
15101525
first_stage_model->compute(n_threads, in, decode, &out);
15111526
};
1512-
sd_tiling_non_square(x, result, 8, tile_size_x, tile_size_y, 0.5f, on_tiling);
1527+
sd_tiling_non_square(x, result, 8, tile_size_x, tile_size_y, tile_overlap, on_tiling);
15131528
} else {
15141529
first_stage_model->compute(n_threads, x, decode, &result);
15151530
}

0 commit comments

Comments
 (0)