diff --git a/StableDiffusion.NET/ModelParameter.cs b/StableDiffusion.NET/ModelParameter.cs index 22ee931..cfd013f 100644 --- a/StableDiffusion.NET/ModelParameter.cs +++ b/StableDiffusion.NET/ModelParameter.cs @@ -13,7 +13,10 @@ public class ModelParameter public string VaePath { get; set; } = string.Empty; public string ControlNetPath { get; set; } = string.Empty; public string EmbeddingsDirectory { get; set; } = string.Empty; + public string StackedIdEmbeddingsDirectory { get; set; } = string.Empty; public bool KeepControlNetOnCPU { get; set; } = false; + public bool KeepClipOnCPU { get; set; } = false; + public bool KeepVaeOnCPU { get; set; } = false; //TODO DarthAffe 01.01.2024: K-Quants doesn't seem to work so far public Quantization Quantization { get; set; } = Quantization.F16; diff --git a/StableDiffusion.NET/Native.cs b/StableDiffusion.NET/Native.cs index 56438c4..d95ecff 100644 --- a/StableDiffusion.NET/Native.cs +++ b/StableDiffusion.NET/Native.cs @@ -55,6 +55,7 @@ internal unsafe partial class Native [MarshalAs(UnmanagedType.LPStr)] string control_net_path_c_str, [MarshalAs(UnmanagedType.LPStr)] string lora_model_dir, [MarshalAs(UnmanagedType.LPStr)] string embed_dir_c_str, + [MarshalAs(UnmanagedType.LPStr)] string stacked_id_embed_dir_c_str, [MarshalAs(UnmanagedType.I1)] bool vae_decode_only, [MarshalAs(UnmanagedType.I1)] bool vae_tiling, [MarshalAs(UnmanagedType.I1)] bool free_params_immediately, @@ -62,7 +63,9 @@ internal unsafe partial class Native sd_type_t wtype, rng_type_t rng_type, schedule_t s, - [MarshalAs(UnmanagedType.I1)] bool keep_control_net_cpu); + [MarshalAs(UnmanagedType.I1)] bool keep_clip_on_cpu, + [MarshalAs(UnmanagedType.I1)] bool keep_control_net_cpu, + [MarshalAs(UnmanagedType.I1)] bool keep_vae_on_cpu); [LibraryImport(LIB_NAME, EntryPoint = "free_sd_ctx")] internal static partial void free_sd_ctx(sd_ctx_t* sd_ctx); @@ -80,7 +83,10 @@ internal unsafe partial class Native long seed, int batch_count, sd_image_t* control_cond, - float control_strength); + float control_strength, + float style_strength, + [MarshalAs(UnmanagedType.I1)] bool normalize_input, + [MarshalAs(UnmanagedType.LPStr)] string input_id_images_path); [LibraryImport(LIB_NAME, EntryPoint = "img2img")] internal static partial sd_image_t* img2img(sd_ctx_t* sd_ctx, diff --git a/StableDiffusion.NET/StableDiffusionModel.cs b/StableDiffusion.NET/StableDiffusionModel.cs index bf45786..8f51ce9 100644 --- a/StableDiffusion.NET/StableDiffusionModel.cs +++ b/StableDiffusion.NET/StableDiffusionModel.cs @@ -56,6 +56,7 @@ public sealed unsafe class StableDiffusionModel : IDisposable _parameter.ControlNetPath, _parameter.LoraModelDir, _parameter.EmbeddingsDirectory, + _parameter.StackedIdEmbeddingsDirectory, _parameter.VaeDecodeOnly, _parameter.VaeTiling, false, @@ -63,7 +64,9 @@ public sealed unsafe class StableDiffusionModel : IDisposable _parameter.Quantization, _parameter.RngType, _parameter.Schedule, - _parameter.KeepControlNetOnCPU); + _parameter.KeepClipOnCPU, + _parameter.KeepControlNetOnCPU, + _parameter.KeepVaeOnCPU); if (_ctx == null) throw new NullReferenceException("Failed to initialize Stable Diffusion"); if (_upscalerParameter != null) @@ -114,7 +117,10 @@ public sealed unsafe class StableDiffusionModel : IDisposable parameter.Seed, 1, &controlNetImage, - parameter.ControlNet.Strength); + parameter.ControlNet.Strength, + parameter.PhotoMaker.StyleRatio, + parameter.PhotoMaker.NormalizeInput, + parameter.PhotoMaker.InputIdImageDirectory); Marshal.FreeHGlobal((nint)controlNetImage.data); } @@ -140,7 +146,10 @@ public sealed unsafe class StableDiffusionModel : IDisposable parameter.Seed, 1, &controlNetImage, - parameter.ControlNet.Strength); + parameter.ControlNet.Strength, + parameter.PhotoMaker.StyleRatio, + parameter.PhotoMaker.NormalizeInput, + parameter.PhotoMaker.InputIdImageDirectory); } } } @@ -158,7 +167,10 @@ public sealed unsafe class StableDiffusionModel : IDisposable parameter.Seed, 1, null, - 0); + 0, + parameter.PhotoMaker.StyleRatio, + parameter.PhotoMaker.NormalizeInput, + parameter.PhotoMaker.InputIdImageDirectory); } return new StableDiffusionImage(result); diff --git a/StableDiffusion.NET/StableDiffusionParameter.cs b/StableDiffusion.NET/StableDiffusionParameter.cs index 74bdc7f..eeb1680 100644 --- a/StableDiffusion.NET/StableDiffusionParameter.cs +++ b/StableDiffusion.NET/StableDiffusionParameter.cs @@ -15,6 +15,7 @@ public sealed class StableDiffusionParameter public int ClipSkip { get; set; } = -1; public StableDiffusionControlNetParameter ControlNet { get; } = new(); + public PhotoMakerParameter PhotoMaker { get; } = new(); #endregion } @@ -31,4 +32,11 @@ public sealed class StableDiffusionControlNetParameter public float CannyWeak { get; set; } = 0.8f; public float CannyStrong { get; set; } = 1.0f; public bool CannyInverse { get; set; } = false; +} + +public sealed class PhotoMakerParameter +{ + public string InputIdImageDirectory { get; set; } = string.Empty; + public float StyleRatio { get; set; } = 20f; + public bool NormalizeInput { get; set; } = false; } \ No newline at end of file diff --git a/build.bat b/build.bat index a52a27c..4883f20 100644 --- a/build.bat +++ b/build.bat @@ -4,7 +4,7 @@ if not exist stable-diffusion.cpp ( cd stable-diffusion.cpp git fetch -git checkout 1ce9470f27d480c6aa5d43c0af5b60db99454252 +git checkout a469688e30122d3b6c1faa5b36ffc3261e6deb82 git submodule init git submodule update