diff --git a/expose.h b/expose.h index 02b5be913..5c67570e2 100644 --- a/expose.h +++ b/expose.h @@ -169,8 +169,8 @@ struct sd_load_model_inputs const char * vae_filename = nullptr; const char * lora_filename = nullptr; const float lora_multiplier = 1.0f; - const int side_limit = 0; - const int square_limit = 0; + const int img_hard_limit = 0; + const int img_soft_limit = 0; const bool quiet = false; const int debugmode = 0; }; diff --git a/koboldcpp.py b/koboldcpp.py index c80d68aa7..79369699b 100644 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -279,8 +279,8 @@ class sd_load_model_inputs(ctypes.Structure): ("vae_filename", ctypes.c_char_p), ("lora_filename", ctypes.c_char_p), ("lora_multiplier", ctypes.c_float), - ("side_limit", ctypes.c_int), - ("square_limit", ctypes.c_int), + ("img_hard_limit", ctypes.c_int), + ("img_soft_limit", ctypes.c_int), ("quiet", ctypes.c_bool), ("debugmode", ctypes.c_int)] @@ -1547,8 +1547,8 @@ def sd_load_model(model_filename,vae_filename,lora_filename,t5xxl_filename,clipl inputs.t5xxl_filename = t5xxl_filename.encode("UTF-8") inputs.clipl_filename = clipl_filename.encode("UTF-8") inputs.clipg_filename = clipg_filename.encode("UTF-8") - inputs.side_limit = args.sdclamped - inputs.square_limit = args.sdrestrictsquare + inputs.img_hard_limit = args.sdclamped + inputs.img_soft_limit = args.sdclampedsoft inputs = set_backend_props(inputs) ret = handle.sd_load_model(inputs) return ret @@ -4291,7 +4291,7 @@ def show_gui(): sd_vaeauto_var = ctk.IntVar(value=0) sd_notile_var = ctk.IntVar(value=0) sd_clamped_var = ctk.StringVar(value="0") - sd_restrict_square_var = ctk.StringVar(value="0") + sd_clamped_soft_var = ctk.StringVar(value="0") sd_threads_var = ctk.StringVar(value=str(default_threads)) sd_quant_var = ctk.IntVar(value=0) @@ -4992,8 +4992,8 @@ def show_gui(): images_tab = tabcontent["Image Gen"] 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.") - 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).") - 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.") + 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).") + 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) 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.") sd_model_var.trace("w", gui_changed_modelfile) 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 show_gui(): args.sdthreads = (0 if sd_threads_var.get()=="" else int(sd_threads_var.get())) args.sdclamped = (0 if int(sd_clamped_var.get())<=0 else int(sd_clamped_var.get())) - args.sdrestrictsquare = (0 if int(sd_restrict_square_var.get())<=0 else int(sd_restrict_square_var.get())) + args.sdclampedsoft = (0 if int(sd_clamped_soft_var.get())<=0 else int(sd_clamped_soft_var.get())) args.sdnotile = (True if sd_notile_var.get()==1 else False) if sd_vaeauto_var.get()==1: args.sdvaeauto = True @@ -5464,7 +5464,7 @@ def show_gui(): sd_model_var.set(dict["sdmodel"] if ("sdmodel" in dict and dict["sdmodel"]) else "") sd_clamped_var.set(int(dict["sdclamped"]) if ("sdclamped" in dict and dict["sdclamped"]) else 0) - sd_restrict_square_var.set(int(dict["sdrestrictsquare"]) if ("sdrestrictsquare" in dict and dict["sdrestrictsquare"]) else 0) + sd_clamped_soft_var.set(int(dict["sdclampedsoft"]) if ("sdclampedsoft" in dict and dict["sdclampedsoft"]) else 0) sd_threads_var.set(str(dict["sdthreads"]) if ("sdthreads" in dict and dict["sdthreads"]) else str(default_threads)) sd_quant_var.set(1 if ("sdquant" in dict and dict["sdquant"]) else 0) sd_vae_var.set(dict["sdvae"] if ("sdvae" in dict and dict["sdvae"]) else "") @@ -7230,8 +7230,8 @@ if __name__ == '__main__': sdparsergroup = parser.add_argument_group('Image Generation Commands') sdparsergroup.add_argument("--sdmodel", metavar=('[filename]'), help="Specify an image generation safetensors or gguf model to enable image generation.", default="") 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) - 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) - 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) + 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) + 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) 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="") 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="") sdparsergroup.add_argument("--sdclipg", metavar=('[filename]'), help="Specify a Clip-G safetensors model for use in SD3. Leave blank if prebaked or unused.", default="") diff --git a/otherarch/sdcpp/sdtype_adapter.cpp b/otherarch/sdcpp/sdtype_adapter.cpp index 6c42de575..2bf44babf 100644 --- a/otherarch/sdcpp/sdtype_adapter.cpp +++ b/otherarch/sdcpp/sdtype_adapter.cpp @@ -135,8 +135,8 @@ bool sdtype_load_model(const sd_load_model_inputs inputs) { std::string clipl_filename = inputs.clipl_filename; std::string clipg_filename = inputs.clipg_filename; notiling = inputs.notile; - cfg_side_limit = inputs.side_limit; - cfg_square_limit = inputs.square_limit; + cfg_side_limit = inputs.img_hard_limit; + cfg_square_limit = inputs.img_soft_limit; printf("\nImageGen Init - Load Model: %s\n",inputs.model_filename); if(lorafilename!="") @@ -320,9 +320,9 @@ static inline int roundup_64(int n) { } //scale dimensions to ensure width and height stay within limits -//side_limit = sdclamped, hard size limit per side, no side can exceed this +//img_hard_limit = sdclamped, hard size limit per side, no side can exceed this //square limit = total NxN resolution based limit to also apply -static void sd_fix_resolution(int &width, int &height, int side_limit, int square_limit) { +static void sd_fix_resolution(int &width, int &height, int img_hard_limit, int img_soft_limit) { // sanitize the original values 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 // requested ratio, since the user can choose those values directly long_side = rounddown_64(long_side); short_side = rounddown_64(short_side); - side_limit = rounddown_64(side_limit); + img_hard_limit = rounddown_64(img_hard_limit); //enforce sdclamp side limit - if (long_side > side_limit) { - short_side = static_cast(short_side * side_limit / static_cast(long_side)); - long_side = side_limit; + if (long_side > img_hard_limit) { + short_side = static_cast(short_side * img_hard_limit / static_cast(long_side)); + long_side = img_hard_limit; if (short_side <= 64) { short_side = 64; } else { @@ -355,7 +355,7 @@ static void sd_fix_resolution(int &width, int &height, int side_limit, int squar } //enforce sd_restrict_square area limit - int area_limit = square_limit * square_limit; + int area_limit = img_soft_limit * img_soft_limit; if (long_side * short_side > area_limit) { float scale = std::sqrt(static_cast(area_limit) / (long_side * short_side)); int new_short = static_cast(short_side * scale); @@ -453,23 +453,23 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs) // cannot exceed (832x832) for sd1/sd2 or (1024x1024) for sdxl/sd3/flux, to prevent crashing the server const int hard_megapixel_res_limit = (loadedsdver==SDVersion::VERSION_SD1 || loadedsdver==SDVersion::VERSION_SD2)?832:1024; - int side_limit = default_res_limit; + int img_hard_limit = default_res_limit; if (cfg_side_limit > 0) { - side_limit = std::max(std::min(cfg_side_limit, default_res_limit), 64); + img_hard_limit = std::max(std::min(cfg_side_limit, default_res_limit), 64); } - int square_limit = default_res_limit; + int img_soft_limit = default_res_limit; if (cfg_square_limit > 0) { - square_limit = std::max(std::min(cfg_square_limit, default_res_limit), 64); + img_soft_limit = std::max(std::min(cfg_square_limit, default_res_limit), 64); } if (cfg_square_limit > 0 && sddebugmode == 1) { - square_limit = std::min(hard_megapixel_res_limit * 2, square_limit); //double the limit for debugmode if cfg_square_limit is set + img_soft_limit = std::min(hard_megapixel_res_limit * 2, img_soft_limit); //double the limit for debugmode if cfg_square_limit is set } else { - square_limit = std::min(hard_megapixel_res_limit, square_limit); + img_soft_limit = std::min(hard_megapixel_res_limit, img_soft_limit); } - sd_fix_resolution(sd_params->width, sd_params->height, side_limit, square_limit); + sd_fix_resolution(sd_params->width, sd_params->height, img_hard_limit, img_soft_limit); if (inputs.width != sd_params->width || inputs.height != sd_params->height) { printf("\nKCPP SD: Requested dimensions %dx%d changed to %dx%d\n", inputs.width, inputs.height, sd_params->width, sd_params->height); }