Skip to content

Commit 6df4d4c

Browse files
committed
sanitize max image size, reduce vae vram usage
1 parent 34595c5 commit 6df4d4c

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/main.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ int main(int argc, char** argv)
244244
return -1;
245245
}
246246

247+
if (width > 2048 || height > 2048)
248+
{
249+
fprintf(stderr, "width and height must be <= 2048 but got %d and %d\n", width, height);
250+
return -1;
251+
}
252+
247253
float guidance_scale;
248254
float scheduler_shift;
249255
if (model.find(PATHSTR("z-image-turbo")) != path_t::npos)
@@ -303,6 +309,9 @@ int main(int argc, char** argv)
303309
opt.use_bf16_storage = gpuid >= 0;
304310
// opt.use_mapped_model_loading = true;
305311

312+
// disable winograd for reducing vae vram usage
313+
opt.use_winograd_convolution = false;
314+
306315
// estimate transformer and vae memory usage
307316
const uint32_t heap_budget = gpuid >= 0 ? ncnn::get_gpu_device(gpuid)->get_heap_budget() : 0;
308317

@@ -317,7 +326,7 @@ int main(int argc, char** argv)
317326
int vae_tile_width = 0;
318327
int vae_tile_height = 0;
319328
{
320-
int max_tile_area = (int)((float)heap_budget / 5700 * 1024 * 1024);
329+
int max_tile_area = (int)((float)heap_budget / 6000 * 1024 * 1024);
321330
ZImage::get_optimal_tile_size(width, height, max_tile_area, &vae_tile_width, &vae_tile_height);
322331

323332
NCNN_LOGE("vae_tile_size = %d x %d", vae_tile_width, vae_tile_height);

0 commit comments

Comments
 (0)