Skip to content

armgit / kokon

Public Imported from GitHub
0

Edit photos by describing the change, on your own GPU. A free, open-source alternative to Nano Banana and ChatGPT image editing: photos stay on your computer, no daily limit. One installer for Windows, Mac and Linux sets up the best open model (Qwen-Image 2.1). MCP server for AI agents.

fix: 8 GB cards keep 1.5 GiB of VRAM out of sd-server's budget

Gabriele Lozuponeaae7461d114d
diff --git a/crates/qls-core/src/catalog.rs b/crates/qls-core/src/catalog.rs
index 8bd9a17..1288293 100644
--- a/crates/qls-core/src/catalog.rs
+++ b/crates/qls-core/src/catalog.rs
@@ -583,6 +583,11 @@ pub struct Preset {
pub diffusion: Download,
pub text_encoder: Download,
pub text_encoder_placement: TextEncoderPlacement,
+ /// Free VRAM sd-server leaves out of its budget (`--max-vram -N`). CUDA loads a kernel's code
+ /// on first use, outside that budget: on an emulated 8 GB card 1 GiB left too little and the
+ /// first job after every start crashed ("shared object initialization failed"); 1.5 GiB ran
+ /// clean with the prompt enhancer still fully on the GPU (2026-10-19).
+ pub vram_reserve_gib: f32,
/// Measured on real hardware of this class (otherwise only derived).
pub verified: bool,
pub summary: &'static str,
@@ -604,6 +609,7 @@ pub const PRESETS: &[Preset] = &[
diffusion: TURBO_Q4_K,
text_encoder: TEXT_ENCODER_Q4_K_M,
text_encoder_placement: TextEncoderPlacement::Ram,
+ vram_reserve_gib: 1.5,
verified: false,
summary: "4-bit model; text encoder in system RAM; images of about 1 megapixel",
},
@@ -616,6 +622,7 @@ pub const PRESETS: &[Preset] = &[
diffusion: TURBO_Q4_K,
text_encoder: TEXT_ENCODER_Q4_K_M,
text_encoder_placement: TextEncoderPlacement::Ram,
+ vram_reserve_gib: 1.0,
verified: true,
summary: "4-bit model; text encoder in system RAM; smaller working sizes",
},
@@ -628,6 +635,7 @@ pub const PRESETS: &[Preset] = &[
diffusion: TURBO_Q4_K,
text_encoder: TEXT_ENCODER_Q4_K_M,
text_encoder_placement: TextEncoderPlacement::Ram,
+ vram_reserve_gib: 1.0,
verified: true,
summary: "4-bit model; text encoder in system RAM; native 2K for Quality",
},
@@ -640,6 +648,7 @@ pub const PRESETS: &[Preset] = &[
diffusion: TURBO_Q4_K,
text_encoder: TEXT_ENCODER_Q4_K_M,
text_encoder_placement: TextEncoderPlacement::Ram,
+ vram_reserve_gib: 1.0,
verified: false,
summary: "4-bit model; text encoder in system RAM; larger edits fit",
},
@@ -652,6 +661,7 @@ pub const PRESETS: &[Preset] = &[
diffusion: TURBO_Q4_K,
text_encoder: TEXT_ENCODER_Q8_0,
text_encoder_placement: TextEncoderPlacement::Ram,
+ vram_reserve_gib: 1.0,
verified: false,
summary: "4-bit model and 8-bit text encoder",
},
diff --git a/crates/qls-core/src/config.rs b/crates/qls-core/src/config.rs
index 93e68ff..6f73c76 100644
--- a/crates/qls-core/src/config.rs
+++ b/crates/qls-core/src/config.rs
@@ -21,7 +21,8 @@ pub const DEFAULT_SERVICE_PORT: u16 = 39151;
/// and ESRGAN tile sizes reset to automatic.
/// Schema 9 (2026-10-16, #14): profiles record their model and source; model paths edited by
/// hand on the official profile move to a profile of the user's own files.
-const SCHEMA_VERSION: u32 = 9;
+/// Schema 10 (2026-10-19): the 8 GB preset's VRAM reserve 1 -> 1.5 GiB (unless set by hand).
+const SCHEMA_VERSION: u32 = 10;
/// `upscaler_model` value for a plain Lanczos resize (no model).
pub const LANCZOS: &str = "lanczos";
/// Upscalers offered in Settings: (file stem, label). Superscale-SP is a setup download, MoSR is
@@ -506,6 +507,9 @@ impl AppConfig {
}
c.keep_hand_edited_paths();
}
+ if c.schema_version < 10 && c.hardware_preset == "8gb" && c.vram_reserve_gib == 1.0 {
+ c.vram_reserve_gib = c.preset().vram_reserve_gib;
+ }
// The official weights are always available as a profile, built for the
// configured folder and preset; the active one stays as it is.
c.normalize();
@@ -694,6 +698,7 @@ impl AppConfig {
pub fn apply_preset(&mut self, preset: &crate::catalog::Preset) {
self.hardware_preset = preset.id.into();
self.text_encoder_placement = preset.text_encoder_placement;
+ self.vram_reserve_gib = preset.vram_reserve_gib;
self.normalize();
}
@@ -1118,6 +1123,25 @@ mod tests {
assert_eq!(old.profile().recommended_settings.area_quality, 2048 * 2048);
}
+ #[test]
+ fn eight_gb_preset_reserves_more_vram() {
+ let dir = tempfile::tempdir().unwrap();
+ let path = dir.path().join("config.json");
+ let load = |json: &str| {
+ std::fs::write(&path, json).unwrap();
+ AppConfig::load_from(&path).vram_reserve_gib
+ };
+ assert_eq!(load(r#"{"schemaVersion": 9, "hardwarePreset": "8gb", "vramReserveGib": 1.0}"#), 1.5);
+ assert_eq!(load(r#"{"schemaVersion": 9, "hardwarePreset": "8gb", "vramReserveGib": 2.0}"#), 2.0, "set by hand");
+ assert_eq!(load(r#"{"schemaVersion": 9, "hardwarePreset": "16gb", "vramReserveGib": 1.0}"#), 1.0);
+ assert_eq!(load(r#"{"schemaVersion": 10, "hardwarePreset": "8gb", "vramReserveGib": 1.0}"#), 1.0, "chosen after the migration");
+ let mut c = AppConfig::default();
+ c.apply_preset(crate::catalog::preset("8gb").unwrap());
+ assert_eq!(c.vram_reserve_gib, 1.5);
+ c.apply_preset(crate::catalog::preset("12gb").unwrap());
+ assert_eq!(c.vram_reserve_gib, 1.0);
+ }
+
#[test]
fn roundtrip_and_partial_files() {
let dir = tempfile::tempdir().unwrap();