Skip to content

Commit 5054cf4

Browse files
committed
set vae tile size via env var
1 parent 957f009 commit 5054cf4

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

stable-diffusion.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,14 +1304,27 @@ class StableDiffusionGGML {
13041304
ggml_tensor* encode_first_stage(ggml_context* work_ctx, ggml_tensor* x, bool decode_video = false) {
13051305
int64_t t0 = ggml_time_ms();
13061306
ggml_tensor* result = NULL;
1307+
int tile_size = 32;
1308+
// TODO: arg instead of env?
1309+
const char* SD_TILE_SIZE = getenv("SD_TILE_SIZE");
1310+
if (SD_TILE_SIZE != nullptr) {
1311+
std::string sd_tile_size_str = SD_TILE_SIZE;
1312+
try {
1313+
tile_size = std::stoi(sd_tile_size_str);
1314+
} catch (const std::invalid_argument&) {
1315+
LOG_WARN("Invalid");
1316+
} catch (const std::out_of_range&) {
1317+
LOG_WARN("OOR");
1318+
}
1319+
}
13071320
if (!use_tiny_autoencoder) {
13081321
process_vae_input_tensor(x);
13091322
if (vae_tiling && !decode_video) {
13101323
// split latent in 32x32 tiles and compute in several steps
13111324
auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) {
13121325
first_stage_model->compute(n_threads, in, true, &out, NULL);
13131326
};
1314-
sd_tiling(x, result, 8, 32, 0.5f, on_tiling, false);
1327+
sd_tiling(x, result, 8, tile_size, 0.5f, on_tiling, false);
13151328
} else {
13161329
first_stage_model->compute(n_threads, x, false, &result, work_ctx);
13171330
}
@@ -1434,7 +1447,19 @@ class StableDiffusionGGML {
14341447
C,
14351448
x->ne[3]);
14361449
}
1437-
1450+
int tile_size = 32;
1451+
// TODO: arg instead of env?
1452+
const char* SD_TILE_SIZE = getenv("SD_TILE_SIZE");
1453+
if (SD_TILE_SIZE != nullptr) {
1454+
std::string sd_tile_size_str = SD_TILE_SIZE;
1455+
try {
1456+
tile_size = std::stoi(sd_tile_size_str);
1457+
} catch (const std::invalid_argument&) {
1458+
LOG_WARN("Invalid");
1459+
} catch (const std::out_of_range&) {
1460+
LOG_WARN("OOR");
1461+
}
1462+
}
14381463
int64_t t0 = ggml_time_ms();
14391464
if (!use_tiny_autoencoder) {
14401465
process_latent_out(x);
@@ -1444,7 +1469,7 @@ class StableDiffusionGGML {
14441469
auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) {
14451470
first_stage_model->compute(n_threads, in, true, &out, NULL);
14461471
};
1447-
sd_tiling(x, result, 8, 32, 0.5f, on_tiling, true);
1472+
sd_tiling(x, result, 8, tile_size, 0.5f, on_tiling, true);
14481473
} else {
14491474
first_stage_model->compute(n_threads, x, true, &result, work_ctx);
14501475
}

0 commit comments

Comments
 (0)