Skip to content

Commit 16d60ac

Browse files
authored
Merge pull request #35 from DarthAffe/SD3_5
SD3.5
2 parents d25eb97 + 5ed63e5 commit 16d60ac

File tree

7 files changed

+50
-5
lines changed

7 files changed

+50
-5
lines changed

Examples/ImageCreationUI/ImageCreationUI.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="HPPH.System.Drawing" Version="1.0.0" />
14-
<PackageReference Include="StableDiffusion.NET.Backend.Cpu" Version="3.0.0" />
15-
<PackageReference Include="StableDiffusion.NET.Backend.Cuda" Version="3.0.0" />
16-
<PackageReference Include="StableDiffusion.NET.Backend.Rocm" Version="3.0.0" />
14+
<PackageReference Include="StableDiffusion.NET.Backend.Cpu" Version="3.2.0" />
15+
<PackageReference Include="StableDiffusion.NET.Backend.Cuda" Version="3.2.0" />
16+
<PackageReference Include="StableDiffusion.NET.Backend.Rocm" Version="3.2.0" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

StableDiffusion.NET/Models/Builder/ModelBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace StableDiffusion.NET;
66
public static class ModelBuilder
77
{
88
public static StableDiffusionModelBuilder StableDiffusion(string modelPath) => new(modelPath);
9+
public static StableDiffusion3_5ModelBuilder StableDiffusion3_5(string modelPath, string clipLPath, string clipGPath, string t5xxlPath) => new(modelPath, clipLPath, clipGPath, t5xxlPath);
910
public static FluxModelBuilder Flux(string diffusionModelPath, string clipLPath, string t5xxlPath, string vaePath) => new(diffusionModelPath, clipLPath, t5xxlPath, vaePath);
1011
public static ESRGANModelBuilder ESRGAN(string modelPath) => new(modelPath);
1112
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using JetBrains.Annotations;
2+
3+
namespace StableDiffusion.NET;
4+
5+
[PublicAPI]
6+
public sealed class StableDiffusion3_5ModelBuilder : IDiffusionModelBuilder, IQuantizedModelBuilder
7+
{
8+
#region Properties & Fields
9+
10+
public DiffusionModelParameter Parameter { get; }
11+
IDiffusionModelParameter IDiffusionModelBuilder.Parameter => Parameter;
12+
IQuantizedModelParameter IQuantizedModelBuilder.Parameter => Parameter;
13+
14+
#endregion
15+
16+
#region Constructors
17+
18+
public StableDiffusion3_5ModelBuilder(string modelPath, string clipLPath, string clipGPath, string t5xxlPath)
19+
{
20+
Parameter = new DiffusionModelParameter
21+
{
22+
DiffusionModelType = DiffusionModelType.StableDiffusion,
23+
ModelPath = modelPath,
24+
ClipLPath = clipLPath,
25+
ClipGPath = clipGPath,
26+
T5xxlPath = t5xxlPath,
27+
};
28+
}
29+
30+
#endregion
31+
32+
#region Methods
33+
34+
public DiffusionModel Build() => new(Parameter);
35+
36+
#endregion
37+
}

StableDiffusion.NET/Models/DiffusionModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ private void Initialize()
4141
{
4242
_ctx = Native.new_sd_ctx(ModelParameter.ModelPath,
4343
ModelParameter.ClipLPath,
44+
ModelParameter.ClipGPath,
4445
ModelParameter.T5xxlPath,
4546
ModelParameter.DiffusionModelPath,
4647
ModelParameter.VaePath,

StableDiffusion.NET/Models/Parameter/DiffusionModelParameter.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ public sealed class DiffusionModelParameter : IDiffusionModelParameter, IQuantiz
2424

2525
public Quantization Quantization { get; set; } = Quantization.Unspecified;
2626

27-
// Stable Diffusion only
27+
// SD <= 3 only
2828
public string ModelPath { get; set; } = string.Empty;
2929
public string StackedIdEmbeddingsDirectory { get; set; } = string.Empty;
3030

31-
// Flux only
31+
// Flux & SD3.5 only
3232
public string DiffusionModelPath { get; set; } = string.Empty;
3333
public string ClipLPath { get; set; } = string.Empty;
3434
public string T5xxlPath { get; set; } = string.Empty;
35+
36+
37+
// SD3.5 only
38+
public string ClipGPath { get; set; } = string.Empty;
3539
}

StableDiffusion.NET/Models/Parameter/DiffusionParameter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public sealed class DiffusionParameter
99

1010
public static DiffusionParameter SD1Default => new() { Width = 512, Height = 512, CfgScale = 7.5f, Guidance = 1f, SampleSteps = 25, SampleMethod = Sampler.Euler_A };
1111
public static DiffusionParameter SDXLDefault => new() { Width = 1024, Height = 1024, CfgScale = 7f, Guidance = 1f, SampleSteps = 30, SampleMethod = Sampler.Euler_A };
12+
public static DiffusionParameter SD3_5Default => new() { Width = 1024, Height = 1024, CfgScale = 4.5f, Guidance = 1f, SampleSteps = 20, SampleMethod = Sampler.Euler };
1213
public static DiffusionParameter FluxDefault => new() { Width = 1024, Height = 1024, CfgScale = 1, Guidance = 3.5f, SampleSteps = 20, SampleMethod = Sampler.Euler };
1314

1415
public string NegativePrompt { get; set; } = string.Empty;

StableDiffusion.NET/Native/Native.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ internal struct sd_image_t
5151
[LibraryImport(LIB_NAME, EntryPoint = "new_sd_ctx")]
5252
internal static partial sd_ctx_t* new_sd_ctx([MarshalAs(UnmanagedType.LPStr)] string model_path,
5353
[MarshalAs(UnmanagedType.LPStr)] string clip_l_path,
54+
[MarshalAs(UnmanagedType.LPStr)] string clip_g_path,
5455
[MarshalAs(UnmanagedType.LPStr)] string t5xxl_path,
5556
[MarshalAs(UnmanagedType.LPStr)] string diffusion_model_path,
5657
[MarshalAs(UnmanagedType.LPStr)] string vae_path,

0 commit comments

Comments
 (0)