Skip to content

Commit dc990a7

Browse files
committed
set vae tile size via env var
1 parent 389cd04 commit dc990a7

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
@@ -1298,14 +1298,27 @@ class StableDiffusionGGML {
12981298
ggml_tensor* encode_first_stage(ggml_context* work_ctx, ggml_tensor* x, bool decode_video = false) {
12991299
int64_t t0 = ggml_time_ms();
13001300
ggml_tensor* result = NULL;
1301+
int tile_size = 32;
1302+
// TODO: arg instead of env?
1303+
const char* SD_TILE_SIZE = getenv("SD_TILE_SIZE");
1304+
if (SD_TILE_SIZE != nullptr) {
1305+
std::string sd_tile_size_str = SD_TILE_SIZE;
1306+
try {
1307+
tile_size = std::stoi(sd_tile_size_str);
1308+
} catch (const std::invalid_argument&) {
1309+
LOG_WARN("Invalid");
1310+
} catch (const std::out_of_range&) {
1311+
LOG_WARN("OOR");
1312+
}
1313+
}
13011314
if (!use_tiny_autoencoder) {
13021315
process_vae_input_tensor(x);
13031316
if (vae_tiling && !decode_video) {
13041317
// split latent in 32x32 tiles and compute in several steps
13051318
auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) {
13061319
first_stage_model->compute(n_threads, in, true, &out, NULL);
13071320
};
1308-
sd_tiling(x, result, 8, 32, 0.5f, on_tiling, false);
1321+
sd_tiling(x, result, 8, tile_size, 0.5f, on_tiling, false);
13091322
} else {
13101323
first_stage_model->compute(n_threads, x, false, &result, work_ctx);
13111324
}
@@ -1428,7 +1441,19 @@ class StableDiffusionGGML {
14281441
C,
14291442
x->ne[3]);
14301443
}
1431-
1444+
int tile_size = 32;
1445+
// TODO: arg instead of env?
1446+
const char* SD_TILE_SIZE = getenv("SD_TILE_SIZE");
1447+
if (SD_TILE_SIZE != nullptr) {
1448+
std::string sd_tile_size_str = SD_TILE_SIZE;
1449+
try {
1450+
tile_size = std::stoi(sd_tile_size_str);
1451+
} catch (const std::invalid_argument&) {
1452+
LOG_WARN("Invalid");
1453+
} catch (const std::out_of_range&) {
1454+
LOG_WARN("OOR");
1455+
}
1456+
}
14321457
int64_t t0 = ggml_time_ms();
14331458
if (!use_tiny_autoencoder) {
14341459
process_latent_out(x);
@@ -1438,7 +1463,7 @@ class StableDiffusionGGML {
14381463
auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) {
14391464
first_stage_model->compute(n_threads, in, true, &out, NULL);
14401465
};
1441-
sd_tiling(x, result, 8, 32, 0.5f, on_tiling, true);
1466+
sd_tiling(x, result, 8, tile_size, 0.5f, on_tiling, true);
14421467
} else {
14431468
first_stage_model->compute(n_threads, x, true, &result, work_ctx);
14441469
}

0 commit comments

Comments
 (0)