Skip to content

Commit

Permalink
Updated stablediffussion.cpp to a469688
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthAffe committed Mar 12, 2024
1 parent 64fd986 commit 631c8ca
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
3 changes: 3 additions & 0 deletions StableDiffusion.NET/ModelParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions StableDiffusion.NET/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,17 @@ internal struct sd_image_t
[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,
int n_threads,
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);
Expand All @@ -80,7 +83,10 @@ internal struct sd_image_t
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,
Expand Down
20 changes: 16 additions & 4 deletions StableDiffusion.NET/StableDiffusionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ private void Initialize()
_parameter.ControlNetPath,
_parameter.LoraModelDir,
_parameter.EmbeddingsDirectory,
_parameter.StackedIdEmbeddingsDirectory,
_parameter.VaeDecodeOnly,
_parameter.VaeTiling,
false,
_parameter.ThreadCount,
_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)
Expand Down Expand Up @@ -114,7 +117,10 @@ public StableDiffusionImage TextToImage(string prompt, StableDiffusionParameter
parameter.Seed,
1,
&controlNetImage,
parameter.ControlNet.Strength);
parameter.ControlNet.Strength,
parameter.PhotoMaker.StyleRatio,
parameter.PhotoMaker.NormalizeInput,
parameter.PhotoMaker.InputIdImageDirectory);

Marshal.FreeHGlobal((nint)controlNetImage.data);
}
Expand All @@ -140,7 +146,10 @@ public StableDiffusionImage TextToImage(string prompt, StableDiffusionParameter
parameter.Seed,
1,
&controlNetImage,
parameter.ControlNet.Strength);
parameter.ControlNet.Strength,
parameter.PhotoMaker.StyleRatio,
parameter.PhotoMaker.NormalizeInput,
parameter.PhotoMaker.InputIdImageDirectory);
}
}
}
Expand All @@ -158,7 +167,10 @@ public StableDiffusionImage TextToImage(string prompt, StableDiffusionParameter
parameter.Seed,
1,
null,
0);
0,
parameter.PhotoMaker.StyleRatio,
parameter.PhotoMaker.NormalizeInput,
parameter.PhotoMaker.InputIdImageDirectory);
}

return new StableDiffusionImage(result);
Expand Down
8 changes: 8 additions & 0 deletions StableDiffusion.NET/StableDiffusionParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 631c8ca

Please sign in to comment.