Skip to content

Commit 21881a8

Browse files
committed
rename restrict square to sdclampedsoft
1 parent 175c990 commit 21881a8

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

expose.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ struct sd_load_model_inputs
169169
const char * vae_filename = nullptr;
170170
const char * lora_filename = nullptr;
171171
const float lora_multiplier = 1.0f;
172-
const int side_limit = 0;
173-
const int square_limit = 0;
172+
const int img_hard_limit = 0;
173+
const int img_soft_limit = 0;
174174
const bool quiet = false;
175175
const int debugmode = 0;
176176
};

koboldcpp.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ class sd_load_model_inputs(ctypes.Structure):
279279
("vae_filename", ctypes.c_char_p),
280280
("lora_filename", ctypes.c_char_p),
281281
("lora_multiplier", ctypes.c_float),
282-
("side_limit", ctypes.c_int),
283-
("square_limit", ctypes.c_int),
282+
("img_hard_limit", ctypes.c_int),
283+
("img_soft_limit", ctypes.c_int),
284284
("quiet", ctypes.c_bool),
285285
("debugmode", ctypes.c_int)]
286286

@@ -1547,8 +1547,8 @@ def sd_load_model(model_filename,vae_filename,lora_filename,t5xxl_filename,clipl
15471547
inputs.t5xxl_filename = t5xxl_filename.encode("UTF-8")
15481548
inputs.clipl_filename = clipl_filename.encode("UTF-8")
15491549
inputs.clipg_filename = clipg_filename.encode("UTF-8")
1550-
inputs.side_limit = args.sdclamped
1551-
inputs.square_limit = args.sdrestrictsquare
1550+
inputs.img_hard_limit = args.sdclamped
1551+
inputs.img_soft_limit = args.sdclampedsoft
15521552
inputs = set_backend_props(inputs)
15531553
ret = handle.sd_load_model(inputs)
15541554
return ret
@@ -4291,7 +4291,7 @@ def hide_tooltip(event):
42914291
sd_vaeauto_var = ctk.IntVar(value=0)
42924292
sd_notile_var = ctk.IntVar(value=0)
42934293
sd_clamped_var = ctk.StringVar(value="0")
4294-
sd_restrict_square_var = ctk.StringVar(value="0")
4294+
sd_clamped_soft_var = ctk.StringVar(value="0")
42954295
sd_threads_var = ctk.StringVar(value=str(default_threads))
42964296
sd_quant_var = ctk.IntVar(value=0)
42974297

@@ -4992,8 +4992,8 @@ def togglehorde(a,b,c):
49924992

49934993
images_tab = tabcontent["Image Gen"]
49944994
makefileentry(images_tab, "Image Gen. Model (safetensors/gguf):", "Select Image Gen Model File", sd_model_var, 1, width=280, singlecol=True, filetypes=[("*.safetensors *.gguf","*.safetensors *.gguf")], tooltiptxt="Select a .safetensors or .gguf Image Generation model file on disk to be loaded.")
4995-
makelabelentry(images_tab, "Clamped Mode (Limit Resolution):", sd_clamped_var, 4, 50, padx=290,singleline=True,tooltip="Limit generation steps and resolution settings for shared use.\nSet to 0 to disable, otherwise value is the size limit (min 512px).")
4996-
makelabelentry(images_tab, "Restrict Square Size:", sd_restrict_square_var, 6, 50, padx=290,singleline=True,tooltip="Square image size restriction, to protect the server against memory crashes.\nAllows width-height tradeoffs, eg. 640 allows 640x640 and 512x768\nLeave at 0 for the default value: 832 for SD1.5/SD2, 1024 otherwise.")
4995+
makelabelentry(images_tab, "Clamp Resolution Limit (Hard):", sd_clamped_var, 4, 50, padx=190,singleline=True,tooltip="Limit generation steps and output image size for shared use.\nSet to 0 to disable, otherwise value is clamped to the max size limit (min 512px).")
4996+
makelabelentry(images_tab, "(Soft):", sd_clamped_soft_var, 4, 50, padx=290,singleline=True,tooltip="Square image size restriction, to protect the server against memory crashes.\nAllows width-height tradeoffs, eg. 640 allows 640x640 and 512x768\nLeave at 0 for the default value: 832 for SD1.5/SD2, 1024 otherwise.",labelpadx=250)
49974997
makelabelentry(images_tab, "Image Threads:" , sd_threads_var, 8, 50,padx=290,singleline=True,tooltip="How many threads to use during image generation.\nIf left blank, uses same value as threads.")
49984998
sd_model_var.trace("w", gui_changed_modelfile)
49994999
makecheckbox(images_tab, "Compress Weights (Saves Memory)", sd_quant_var, 10,tooltiptxt="Quantizes the SD model weights to save memory. May degrade quality.")
@@ -5252,7 +5252,7 @@ def export_vars():
52525252

52535253
args.sdthreads = (0 if sd_threads_var.get()=="" else int(sd_threads_var.get()))
52545254
args.sdclamped = (0 if int(sd_clamped_var.get())<=0 else int(sd_clamped_var.get()))
5255-
args.sdrestrictsquare = (0 if int(sd_restrict_square_var.get())<=0 else int(sd_restrict_square_var.get()))
5255+
args.sdclampedsoft = (0 if int(sd_clamped_soft_var.get())<=0 else int(sd_clamped_soft_var.get()))
52565256
args.sdnotile = (True if sd_notile_var.get()==1 else False)
52575257
if sd_vaeauto_var.get()==1:
52585258
args.sdvaeauto = True
@@ -5464,7 +5464,7 @@ def import_vars(dict):
54645464

54655465
sd_model_var.set(dict["sdmodel"] if ("sdmodel" in dict and dict["sdmodel"]) else "")
54665466
sd_clamped_var.set(int(dict["sdclamped"]) if ("sdclamped" in dict and dict["sdclamped"]) else 0)
5467-
sd_restrict_square_var.set(int(dict["sdrestrictsquare"]) if ("sdrestrictsquare" in dict and dict["sdrestrictsquare"]) else 0)
5467+
sd_clamped_soft_var.set(int(dict["sdclampedsoft"]) if ("sdclampedsoft" in dict and dict["sdclampedsoft"]) else 0)
54685468
sd_threads_var.set(str(dict["sdthreads"]) if ("sdthreads" in dict and dict["sdthreads"]) else str(default_threads))
54695469
sd_quant_var.set(1 if ("sdquant" in dict and dict["sdquant"]) else 0)
54705470
sd_vae_var.set(dict["sdvae"] if ("sdvae" in dict and dict["sdvae"]) else "")
@@ -7230,8 +7230,8 @@ def range_checker(arg: str):
72307230
sdparsergroup = parser.add_argument_group('Image Generation Commands')
72317231
sdparsergroup.add_argument("--sdmodel", metavar=('[filename]'), help="Specify an image generation safetensors or gguf model to enable image generation.", default="")
72327232
sdparsergroup.add_argument("--sdthreads", metavar=('[threads]'), help="Use a different number of threads for image generation if specified. Otherwise, has the same value as --threads.", type=int, default=0)
7233-
sdparsergroup.add_argument("--sdclamped", metavar=('[maxres]'), help="If specified, limit generation steps and resolution settings for shared use. Accepts an extra optional parameter that indicates maximum resolution (eg. 768 clamps to 768x768, min 512px, disabled if 0).", nargs='?', const=512, type=int, default=0)
7234-
sdparsergroup.add_argument("--sdrestrictsquare", metavar=('[maxres]'), help="If specified, restrict square image sides to this value, in pixels, to avoid server crashes related to excessive memory usage. Similar to --sdclamped, but allows trade-offs between width and height (e.g. 640 would allow 640x640, 512x768 and 768x512 images). If 0 or unspecified, use a model-specific safe value: 832 for SD1.5/SD2, 1024 otherwise. Total resolution cannot exceed 1MP.", type=int, default=0)
7233+
sdparsergroup.add_argument("--sdclamped", metavar=('[maxres]'), help="If specified, limit generation steps and image size for shared use. Accepts an extra optional parameter that indicates maximum resolution (eg. 768 clamps to 768x768, min 512px, disabled if 0).", nargs='?', const=512, type=int, default=0)
7234+
sdparsergroup.add_argument("--sdclampedsoft", metavar=('[maxres]'), help="If specified, limit max image size to curb memory usage. Similar to --sdclamped, but less strict, allows trade-offs between width and height (e.g. 640 would allow 640x640, 512x768 and 768x512 images). Total resolution cannot exceed 1MP.", type=int, default=0)
72357235
sdparsergroup.add_argument("--sdt5xxl", metavar=('[filename]'), help="Specify a T5-XXL safetensors model for use in SD3 or Flux. Leave blank if prebaked or unused.", default="")
72367236
sdparsergroup.add_argument("--sdclipl", metavar=('[filename]'), help="Specify a Clip-L safetensors model for use in SD3 or Flux. Leave blank if prebaked or unused.", default="")
72377237
sdparsergroup.add_argument("--sdclipg", metavar=('[filename]'), help="Specify a Clip-G safetensors model for use in SD3. Leave blank if prebaked or unused.", default="")

otherarch/sdcpp/sdtype_adapter.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ bool sdtype_load_model(const sd_load_model_inputs inputs) {
135135
std::string clipl_filename = inputs.clipl_filename;
136136
std::string clipg_filename = inputs.clipg_filename;
137137
notiling = inputs.notile;
138-
cfg_side_limit = inputs.side_limit;
139-
cfg_square_limit = inputs.square_limit;
138+
cfg_side_limit = inputs.img_hard_limit;
139+
cfg_square_limit = inputs.img_soft_limit;
140140
printf("\nImageGen Init - Load Model: %s\n",inputs.model_filename);
141141

142142
if(lorafilename!="")
@@ -320,9 +320,9 @@ static inline int roundup_64(int n) {
320320
}
321321

322322
//scale dimensions to ensure width and height stay within limits
323-
//side_limit = sdclamped, hard size limit per side, no side can exceed this
323+
//img_hard_limit = sdclamped, hard size limit per side, no side can exceed this
324324
//square limit = total NxN resolution based limit to also apply
325-
static void sd_fix_resolution(int &width, int &height, int side_limit, int square_limit) {
325+
static void sd_fix_resolution(int &width, int &height, int img_hard_limit, int img_soft_limit) {
326326

327327
// sanitize the original values
328328
width = std::max(std::min(width, 8192), 64);
@@ -337,12 +337,12 @@ static void sd_fix_resolution(int &width, int &height, int side_limit, int squar
337337
// requested ratio, since the user can choose those values directly
338338
long_side = rounddown_64(long_side);
339339
short_side = rounddown_64(short_side);
340-
side_limit = rounddown_64(side_limit);
340+
img_hard_limit = rounddown_64(img_hard_limit);
341341

342342
//enforce sdclamp side limit
343-
if (long_side > side_limit) {
344-
short_side = static_cast<int>(short_side * side_limit / static_cast<float>(long_side));
345-
long_side = side_limit;
343+
if (long_side > img_hard_limit) {
344+
short_side = static_cast<int>(short_side * img_hard_limit / static_cast<float>(long_side));
345+
long_side = img_hard_limit;
346346
if (short_side <= 64) {
347347
short_side = 64;
348348
} else {
@@ -355,7 +355,7 @@ static void sd_fix_resolution(int &width, int &height, int side_limit, int squar
355355
}
356356

357357
//enforce sd_restrict_square area limit
358-
int area_limit = square_limit * square_limit;
358+
int area_limit = img_soft_limit * img_soft_limit;
359359
if (long_side * short_side > area_limit) {
360360
float scale = std::sqrt(static_cast<float>(area_limit) / (long_side * short_side));
361361
int new_short = static_cast<int>(short_side * scale);
@@ -453,23 +453,23 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
453453
// cannot exceed (832x832) for sd1/sd2 or (1024x1024) for sdxl/sd3/flux, to prevent crashing the server
454454
const int hard_megapixel_res_limit = (loadedsdver==SDVersion::VERSION_SD1 || loadedsdver==SDVersion::VERSION_SD2)?832:1024;
455455

456-
int side_limit = default_res_limit;
456+
int img_hard_limit = default_res_limit;
457457
if (cfg_side_limit > 0) {
458-
side_limit = std::max(std::min(cfg_side_limit, default_res_limit), 64);
458+
img_hard_limit = std::max(std::min(cfg_side_limit, default_res_limit), 64);
459459
}
460460

461-
int square_limit = default_res_limit;
461+
int img_soft_limit = default_res_limit;
462462
if (cfg_square_limit > 0) {
463-
square_limit = std::max(std::min(cfg_square_limit, default_res_limit), 64);
463+
img_soft_limit = std::max(std::min(cfg_square_limit, default_res_limit), 64);
464464
}
465465

466466
if (cfg_square_limit > 0 && sddebugmode == 1) {
467-
square_limit = std::min(hard_megapixel_res_limit * 2, square_limit); //double the limit for debugmode if cfg_square_limit is set
467+
img_soft_limit = std::min(hard_megapixel_res_limit * 2, img_soft_limit); //double the limit for debugmode if cfg_square_limit is set
468468
} else {
469-
square_limit = std::min(hard_megapixel_res_limit, square_limit);
469+
img_soft_limit = std::min(hard_megapixel_res_limit, img_soft_limit);
470470
}
471471

472-
sd_fix_resolution(sd_params->width, sd_params->height, side_limit, square_limit);
472+
sd_fix_resolution(sd_params->width, sd_params->height, img_hard_limit, img_soft_limit);
473473
if (inputs.width != sd_params->width || inputs.height != sd_params->height) {
474474
printf("\nKCPP SD: Requested dimensions %dx%d changed to %dx%d\n", inputs.width, inputs.height, sd_params->width, sd_params->height);
475475
}

0 commit comments

Comments
 (0)