Skip to content

Commit c25ee33

Browse files
committed
set vae tile size via env var
1 parent 6b82b95 commit c25ee33

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
@@ -1292,14 +1292,27 @@ class StableDiffusionGGML {
12921292
ggml_tensor* encode_first_stage(ggml_context* work_ctx, ggml_tensor* x, bool decode_video = false) {
12931293
int64_t t0 = ggml_time_ms();
12941294
ggml_tensor* result = NULL;
1295+
int tile_size = 32;
1296+
// TODO: arg instead of env?
1297+
const char* SD_TILE_SIZE = getenv("SD_TILE_SIZE");
1298+
if (SD_TILE_SIZE != nullptr) {
1299+
std::string sd_tile_size_str = SD_TILE_SIZE;
1300+
try {
1301+
tile_size = std::stoi(sd_tile_size_str);
1302+
} catch (const std::invalid_argument&) {
1303+
LOG_WARN("Invalid");
1304+
} catch (const std::out_of_range&) {
1305+
LOG_WARN("OOR");
1306+
}
1307+
}
12951308
if (!use_tiny_autoencoder) {
12961309
process_vae_input_tensor(x);
12971310
if (vae_tiling && !decode_video) {
12981311
// split latent in 32x32 tiles and compute in several steps
12991312
auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) {
13001313
first_stage_model->compute(n_threads, in, true, &out, NULL);
13011314
};
1302-
sd_tiling(x, result, 8, 32, 0.5f, on_tiling, false);
1315+
sd_tiling(x, result, 8, tile_size, 0.5f, on_tiling, false);
13031316
} else {
13041317
first_stage_model->compute(n_threads, x, false, &result, work_ctx);
13051318
}
@@ -1422,7 +1435,19 @@ class StableDiffusionGGML {
14221435
C,
14231436
x->ne[3]);
14241437
}
1425-
1438+
int tile_size = 32;
1439+
// TODO: arg instead of env?
1440+
const char* SD_TILE_SIZE = getenv("SD_TILE_SIZE");
1441+
if (SD_TILE_SIZE != nullptr) {
1442+
std::string sd_tile_size_str = SD_TILE_SIZE;
1443+
try {
1444+
tile_size = std::stoi(sd_tile_size_str);
1445+
} catch (const std::invalid_argument&) {
1446+
LOG_WARN("Invalid");
1447+
} catch (const std::out_of_range&) {
1448+
LOG_WARN("OOR");
1449+
}
1450+
}
14261451
int64_t t0 = ggml_time_ms();
14271452
if (!use_tiny_autoencoder) {
14281453
process_latent_out(x);
@@ -1432,7 +1457,7 @@ class StableDiffusionGGML {
14321457
auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) {
14331458
first_stage_model->compute(n_threads, in, true, &out, NULL);
14341459
};
1435-
sd_tiling(x, result, 8, 32, 0.5f, on_tiling, true);
1460+
sd_tiling(x, result, 8, tile_size, 0.5f, on_tiling, true);
14361461
} else {
14371462
first_stage_model->compute(n_threads, x, true, &result, work_ctx);
14381463
}

0 commit comments

Comments
 (0)