Skip to content

Commit 3e3e1ab

Browse files
committed
add backend support for changing the VAE tiling threshold
1 parent f6d2d1c commit 3e3e1ab

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

expose.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct sd_load_model_inputs
162162
const int threads = 0;
163163
const int quant = 0;
164164
const bool taesd = false;
165-
const bool notile = false;
165+
const int tiled_vae_threshold = 0;
166166
const char * t5xxl_filename = nullptr;
167167
const char * clipl_filename = nullptr;
168168
const char * clipg_filename = nullptr;

koboldcpp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class sd_load_model_inputs(ctypes.Structure):
267267
("threads", ctypes.c_int),
268268
("quant", ctypes.c_int),
269269
("taesd", ctypes.c_bool),
270-
("notile", ctypes.c_bool),
270+
("tiled_vae_threshold", ctypes.c_int),
271271
("t5xxl_filename", ctypes.c_char_p),
272272
("clipl_filename", ctypes.c_char_p),
273273
("clipg_filename", ctypes.c_char_p),
@@ -1534,7 +1534,7 @@ def sd_load_model(model_filename,vae_filename,lora_filename,t5xxl_filename,clipl
15341534
inputs.threads = thds
15351535
inputs.quant = quant
15361536
inputs.taesd = True if args.sdvaeauto else False
1537-
inputs.notile = True if args.sdnotile else False
1537+
inputs.tiled_vae_threshold = -1 if args.sdnotile else 0
15381538
inputs.vae_filename = vae_filename.encode("UTF-8")
15391539
inputs.lora_filename = lora_filename.encode("UTF-8")
15401540
inputs.lora_multiplier = args.sdloramult

otherarch/sdcpp/sdtype_adapter.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static uint8_t * input_image_buffer = NULL;
118118
static uint8_t * input_mask_buffer = NULL;
119119

120120
static std::string sdplatformenv, sddeviceenv, sdvulkandeviceenv;
121-
static bool notiling = false;
121+
static int cfg_tiled_vae_threshold = 0;
122122
static int cfg_square_limit = 0;
123123
static int cfg_side_limit = 0;
124124
static bool sd_is_quiet = false;
@@ -134,7 +134,7 @@ bool sdtype_load_model(const sd_load_model_inputs inputs) {
134134
std::string t5xxl_filename = inputs.t5xxl_filename;
135135
std::string clipl_filename = inputs.clipl_filename;
136136
std::string clipg_filename = inputs.clipg_filename;
137-
notiling = inputs.notile;
137+
cfg_tiled_vae_threshold = inputs.tiled_vae_threshold;
138138
cfg_side_limit = inputs.side_limit;
139139
cfg_square_limit = inputs.square_limit;
140140
printf("\nImageGen Init - Load Model: %s\n",inputs.model_filename);
@@ -474,7 +474,18 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
474474
printf("\nKCPP SD: Requested dimensions %dx%d changed to %dx%d\n", inputs.width, inputs.height, sd_params->width, sd_params->height);
475475
}
476476

477-
bool dotile = (sd_params->width>768 || sd_params->height>768) && !notiling;
477+
int tiled_vae_threshold;
478+
if (cfg_tiled_vae_threshold == 0) {
479+
tiled_vae_threshold = 768;
480+
} else {
481+
if (cfg_tiled_vae_threshold > 0) {
482+
tiled_vae_threshold = cfg_tiled_vae_threshold;
483+
} else {
484+
tiled_vae_threshold = 8192; // effectively avoids tiling
485+
}
486+
}
487+
488+
bool dotile = (sd_params->width>tiled_vae_threshold || sd_params->height>tiled_vae_threshold);
478489
set_sd_vae_tiling(sd_ctx,dotile); //changes vae tiling, prevents memory related crash/oom
479490

480491
if (sd_params->clip_skip <= 0) {

0 commit comments

Comments
 (0)