Skip to content

Commit 495cc9e

Browse files
committed
set vae tile size via env var
1 parent 9c00ed6 commit 495cc9e

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
@@ -1284,14 +1284,27 @@ class StableDiffusionGGML {
12841284
ggml_tensor* encode_first_stage(ggml_context* work_ctx, ggml_tensor* x, bool decode_video = false) {
12851285
int64_t t0 = ggml_time_ms();
12861286
ggml_tensor* result = NULL;
1287+
int tile_size = 32;
1288+
// TODO: arg instead of env?
1289+
const char* SD_TILE_SIZE = getenv("SD_TILE_SIZE");
1290+
if (SD_TILE_SIZE != nullptr) {
1291+
std::string sd_tile_size_str = SD_TILE_SIZE;
1292+
try {
1293+
tile_size = std::stoi(sd_tile_size_str);
1294+
} catch (const std::invalid_argument&) {
1295+
LOG_WARN("Invalid");
1296+
} catch (const std::out_of_range&) {
1297+
LOG_WARN("OOR");
1298+
}
1299+
}
12871300
if (!use_tiny_autoencoder) {
12881301
process_vae_input_tensor(x);
12891302
if (vae_tiling && !decode_video) {
12901303
// split latent in 32x32 tiles and compute in several steps
12911304
auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) {
12921305
first_stage_model->compute(n_threads, in, true, &out, NULL);
12931306
};
1294-
sd_tiling(x, result, 8, 32, 0.5f, on_tiling, false);
1307+
sd_tiling(x, result, 8, tile_size, 0.5f, on_tiling, false);
12951308
} else {
12961309
first_stage_model->compute(n_threads, x, false, &result, work_ctx);
12971310
}
@@ -1414,7 +1427,19 @@ class StableDiffusionGGML {
14141427
C,
14151428
x->ne[3]);
14161429
}
1417-
1430+
int tile_size = 32;
1431+
// TODO: arg instead of env?
1432+
const char* SD_TILE_SIZE = getenv("SD_TILE_SIZE");
1433+
if (SD_TILE_SIZE != nullptr) {
1434+
std::string sd_tile_size_str = SD_TILE_SIZE;
1435+
try {
1436+
tile_size = std::stoi(sd_tile_size_str);
1437+
} catch (const std::invalid_argument&) {
1438+
LOG_WARN("Invalid");
1439+
} catch (const std::out_of_range&) {
1440+
LOG_WARN("OOR");
1441+
}
1442+
}
14181443
int64_t t0 = ggml_time_ms();
14191444
if (!use_tiny_autoencoder) {
14201445
process_latent_out(x);
@@ -1424,7 +1449,7 @@ class StableDiffusionGGML {
14241449
auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) {
14251450
first_stage_model->compute(n_threads, in, true, &out, NULL);
14261451
};
1427-
sd_tiling(x, result, 8, 32, 0.5f, on_tiling, true);
1452+
sd_tiling(x, result, 8, tile_size, 0.5f, on_tiling, true);
14281453
} else {
14291454
first_stage_model->compute(n_threads, x, true, &result, work_ctx);
14301455
}

0 commit comments

Comments
 (0)