diff --git a/stable-diffusion.cpp b/stable-diffusion.cpp index 074290d84..1add767b0 100644 --- a/stable-diffusion.cpp +++ b/stable-diffusion.cpp @@ -2076,8 +2076,9 @@ class StableDiffusionGGML { ggml_tensor* vae_encode(ggml_context* work_ctx, ggml_tensor* x, bool encode_video = false) { int64_t t0 = ggml_time_ms(); ggml_tensor* result = nullptr; - int W = x->ne[0] / get_vae_scale_factor(); - int H = x->ne[1] / get_vae_scale_factor(); + const int vae_scale_factor = get_vae_scale_factor(); + int W = x->ne[0] / vae_scale_factor; + int H = x->ne[1] / vae_scale_factor; int C = get_latent_channel(); if (vae_tiling_params.enabled && !encode_video) { // TODO wan2.2 vae support? @@ -2113,7 +2114,7 @@ class StableDiffusionGGML { auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) { first_stage_model->compute(n_threads, in, false, &out, work_ctx); }; - sd_tiling_non_square(x, result, 8, tile_size_x, tile_size_y, tile_overlap, on_tiling); + sd_tiling_non_square(x, result, vae_scale_factor, tile_size_x, tile_size_y, tile_overlap, on_tiling); } else { first_stage_model->compute(n_threads, x, false, &result, work_ctx); } @@ -2124,7 +2125,7 @@ class StableDiffusionGGML { auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) { tae_first_stage->compute(n_threads, in, false, &out, nullptr); }; - sd_tiling(x, result, 8, 64, 0.5f, on_tiling); + sd_tiling(x, result, vae_scale_factor, 64, 0.5f, on_tiling); } else { tae_first_stage->compute(n_threads, x, false, &result, work_ctx); } @@ -2200,8 +2201,9 @@ class StableDiffusionGGML { } ggml_tensor* decode_first_stage(ggml_context* work_ctx, ggml_tensor* x, bool decode_video = false) { - int64_t W = x->ne[0] * get_vae_scale_factor(); - int64_t H = x->ne[1] * get_vae_scale_factor(); + const int vae_scale_factor = get_vae_scale_factor(); + int64_t W = x->ne[0] * vae_scale_factor; + int64_t H = x->ne[1] * vae_scale_factor; int64_t C = 3; ggml_tensor* result = nullptr; if (decode_video) { @@ -2241,7 +2243,7 @@ class StableDiffusionGGML { auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) { first_stage_model->compute(n_threads, in, true, &out, nullptr); }; - sd_tiling_non_square(x, result, 8, tile_size_x, tile_size_y, tile_overlap, on_tiling); + sd_tiling_non_square(x, result, vae_scale_factor, tile_size_x, tile_size_y, tile_overlap, on_tiling); } else { first_stage_model->compute(n_threads, x, true, &result, work_ctx); } @@ -2253,7 +2255,7 @@ class StableDiffusionGGML { auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) { tae_first_stage->compute(n_threads, in, true, &out); }; - sd_tiling(x, result, 8, 64, 0.5f, on_tiling); + sd_tiling(x, result, vae_scale_factor, 64, 0.5f, on_tiling); } else { tae_first_stage->compute(n_threads, x, true, &result); }