mirror of
https://github.com/DarthAffe/StableDiffusion.NET.git
synced 2026-03-24 02:08:49 +00:00
Updated sd.cpp to 5792c66
This commit is contained in:
parent
9fd65e14ae
commit
e8349b8962
@ -48,6 +48,8 @@ enum sample_method_t {
|
|||||||
LCM_SAMPLE_METHOD,
|
LCM_SAMPLE_METHOD,
|
||||||
DDIM_TRAILING_SAMPLE_METHOD,
|
DDIM_TRAILING_SAMPLE_METHOD,
|
||||||
TCD_SAMPLE_METHOD,
|
TCD_SAMPLE_METHOD,
|
||||||
|
RES_MULTISTEP_SAMPLE_METHOD,
|
||||||
|
RES_2S_SAMPLE_METHOD,
|
||||||
SAMPLE_METHOD_COUNT
|
SAMPLE_METHOD_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,6 +64,7 @@ enum scheduler_t {
|
|||||||
SMOOTHSTEP_SCHEDULER,
|
SMOOTHSTEP_SCHEDULER,
|
||||||
KL_OPTIMAL_SCHEDULER,
|
KL_OPTIMAL_SCHEDULER,
|
||||||
LCM_SCHEDULER,
|
LCM_SCHEDULER,
|
||||||
|
BONG_TANGENT_SCHEDULER,
|
||||||
SCHEDULER_COUNT
|
SCHEDULER_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -186,6 +189,7 @@ typedef struct {
|
|||||||
bool keep_clip_on_cpu;
|
bool keep_clip_on_cpu;
|
||||||
bool keep_control_net_on_cpu;
|
bool keep_control_net_on_cpu;
|
||||||
bool keep_vae_on_cpu;
|
bool keep_vae_on_cpu;
|
||||||
|
bool flash_attn;
|
||||||
bool diffusion_flash_attn;
|
bool diffusion_flash_attn;
|
||||||
bool tae_preview_only;
|
bool tae_preview_only;
|
||||||
bool diffusion_conv_direct;
|
bool diffusion_conv_direct;
|
||||||
@ -197,7 +201,7 @@ typedef struct {
|
|||||||
bool chroma_use_t5_mask;
|
bool chroma_use_t5_mask;
|
||||||
int chroma_t5_mask_pad;
|
int chroma_t5_mask_pad;
|
||||||
bool qwen_image_zero_cond_t;
|
bool qwen_image_zero_cond_t;
|
||||||
float flow_shift;
|
|
||||||
} sd_ctx_params_t;
|
} sd_ctx_params_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -231,6 +235,7 @@ typedef struct {
|
|||||||
int shifted_timestep;
|
int shifted_timestep;
|
||||||
float* custom_sigmas;
|
float* custom_sigmas;
|
||||||
int custom_sigmas_count;
|
int custom_sigmas_count;
|
||||||
|
float flow_shift;
|
||||||
} sd_sample_params_t;
|
} sd_sample_params_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@ -14,5 +14,7 @@ public enum Sampler
|
|||||||
LCM,
|
LCM,
|
||||||
DDIM_Trailing,
|
DDIM_Trailing,
|
||||||
TCD,
|
TCD,
|
||||||
|
ResMultistep,
|
||||||
|
Res2S,
|
||||||
Default
|
Default
|
||||||
}
|
}
|
||||||
@ -12,5 +12,6 @@ public enum Scheduler
|
|||||||
Smoothstep,
|
Smoothstep,
|
||||||
KlOptimal,
|
KlOptimal,
|
||||||
LCM,
|
LCM,
|
||||||
|
BongTangent,
|
||||||
Default
|
Default
|
||||||
}
|
}
|
||||||
@ -60,12 +60,14 @@ public sealed class DiffusionModelParameter
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool KeepVaeOnCPU { get; set; } = false;
|
public bool KeepVaeOnCPU { get; set; } = false;
|
||||||
|
|
||||||
|
public bool FlashAttention { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// use flash attention in the diffusion model (for low vram)
|
/// use flash attention in the diffusion model (for low vram)
|
||||||
/// Might lower quality, since it implies converting k and v to f16.
|
/// Might lower quality, since it implies converting k and v to f16.
|
||||||
/// This might crash if it is not supported by the backend.
|
/// This might crash if it is not supported by the backend.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool FlashAttention { get; set; } = false;
|
public bool DiffusionFlashAttention { get; set; } = false;
|
||||||
|
|
||||||
public bool TaePreviewOnly { get; set; } = false;
|
public bool TaePreviewOnly { get; set; } = false;
|
||||||
|
|
||||||
@ -101,8 +103,6 @@ public sealed class DiffusionModelParameter
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Quantization Quantization { get; set; } = Quantization.Unspecified;
|
public Quantization Quantization { get; set; } = Quantization.Unspecified;
|
||||||
|
|
||||||
public float FlowShift { get; set; } = float.PositiveInfinity;
|
|
||||||
|
|
||||||
public bool ForceSdxlVaeConvScale { get; set; } = false;
|
public bool ForceSdxlVaeConvScale { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -120,6 +120,13 @@ public static class DiffusionModelBuilderExtension
|
|||||||
return parameter;
|
return parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DiffusionModelParameter WithDiffusionFlashAttention(this DiffusionModelParameter parameter, bool flashAttention = true)
|
||||||
|
{
|
||||||
|
parameter.DiffusionFlashAttention = flashAttention;
|
||||||
|
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
|
||||||
public static DiffusionModelParameter WithDiffusionConvDirect(this DiffusionModelParameter parameter, bool diffusionConvDirect = true)
|
public static DiffusionModelParameter WithDiffusionConvDirect(this DiffusionModelParameter parameter, bool diffusionConvDirect = true)
|
||||||
{
|
{
|
||||||
parameter.DiffusionConvDirect = diffusionConvDirect;
|
parameter.DiffusionConvDirect = diffusionConvDirect;
|
||||||
@ -159,13 +166,6 @@ public static class DiffusionModelBuilderExtension
|
|||||||
return parameter;
|
return parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DiffusionModelParameter WithFlowShift(this DiffusionModelParameter parameter, float flowShift)
|
|
||||||
{
|
|
||||||
parameter.FlowShift = flowShift;
|
|
||||||
|
|
||||||
return parameter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DiffusionModelParameter WithForcedSdxlVaeConvScale(this DiffusionModelParameter parameter, bool forcedScale = true)
|
public static DiffusionModelParameter WithForcedSdxlVaeConvScale(this DiffusionModelParameter parameter, bool forcedScale = true)
|
||||||
{
|
{
|
||||||
parameter.ForceSdxlVaeConvScale = forcedScale;
|
parameter.ForceSdxlVaeConvScale = forcedScale;
|
||||||
|
|||||||
@ -175,6 +175,13 @@ public static class ImageGenerationParameterExtension
|
|||||||
return parameter;
|
return parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ImageGenerationParameter WithFlowShift(this ImageGenerationParameter parameter, float flowShift)
|
||||||
|
{
|
||||||
|
parameter.SampleParameter.FlowShift = flowShift;
|
||||||
|
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public static ImageGenerationParameter WithStrength(this ImageGenerationParameter parameter, float strength)
|
public static ImageGenerationParameter WithStrength(this ImageGenerationParameter parameter, float strength)
|
||||||
|
|||||||
@ -161,6 +161,13 @@ public static class VideoGenerationParameterExtension
|
|||||||
return parameter;
|
return parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static VideoGenerationParameter WithFlowShift(this VideoGenerationParameter parameter, float flowShift)
|
||||||
|
{
|
||||||
|
parameter.SampleParameter.FlowShift = flowShift;
|
||||||
|
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region HighNoiseSampleParameter
|
#region HighNoiseSampleParameter
|
||||||
|
|||||||
@ -28,5 +28,7 @@ public sealed class SampleParameter
|
|||||||
|
|
||||||
public float[] CustomSigmas { get; set; } = [];
|
public float[] CustomSigmas { get; set; } = [];
|
||||||
|
|
||||||
|
public float FlowShift { get; set; } = float.PositiveInfinity;
|
||||||
|
|
||||||
internal SampleParameter() { }
|
internal SampleParameter() { }
|
||||||
}
|
}
|
||||||
@ -39,7 +39,8 @@ internal static unsafe class DiffusionModelParameterMarshaller
|
|||||||
KeepClipOnCPU = unmanaged.keep_clip_on_cpu == 1,
|
KeepClipOnCPU = unmanaged.keep_clip_on_cpu == 1,
|
||||||
KeepControlNetOnCPU = unmanaged.keep_control_net_on_cpu == 1,
|
KeepControlNetOnCPU = unmanaged.keep_control_net_on_cpu == 1,
|
||||||
KeepVaeOnCPU = unmanaged.keep_vae_on_cpu == 1,
|
KeepVaeOnCPU = unmanaged.keep_vae_on_cpu == 1,
|
||||||
FlashAttention = unmanaged.diffusion_flash_attn == 1,
|
DiffusionFlashAttention = unmanaged.diffusion_flash_attn == 1,
|
||||||
|
FlashAttention = unmanaged.flash_attn == 1,
|
||||||
TaePreviewOnly = unmanaged.tae_preview_only == 1,
|
TaePreviewOnly = unmanaged.tae_preview_only == 1,
|
||||||
DiffusionConvDirect = unmanaged.diffusion_conv_direct == 1,
|
DiffusionConvDirect = unmanaged.diffusion_conv_direct == 1,
|
||||||
VaeConvDirect = unmanaged.vae_conv_direct == 1,
|
VaeConvDirect = unmanaged.vae_conv_direct == 1,
|
||||||
@ -50,7 +51,6 @@ internal static unsafe class DiffusionModelParameterMarshaller
|
|||||||
ChromaEnableT5Map = unmanaged.chroma_use_t5_mask == 1,
|
ChromaEnableT5Map = unmanaged.chroma_use_t5_mask == 1,
|
||||||
ChromaT5MaskPad = unmanaged.chroma_t5_mask_pad,
|
ChromaT5MaskPad = unmanaged.chroma_t5_mask_pad,
|
||||||
QwenImageZeroCondT = unmanaged.qwen_image_zero_cond_t == 1,
|
QwenImageZeroCondT = unmanaged.qwen_image_zero_cond_t == 1,
|
||||||
FlowShift = unmanaged.flow_shift
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int i = 0; i < unmanaged.embedding_count; i++)
|
for (int i = 0; i < unmanaged.embedding_count; i++)
|
||||||
@ -120,7 +120,8 @@ internal static unsafe class DiffusionModelParameterMarshaller
|
|||||||
keep_clip_on_cpu = (sbyte)(managed.KeepClipOnCPU ? 1 : 0),
|
keep_clip_on_cpu = (sbyte)(managed.KeepClipOnCPU ? 1 : 0),
|
||||||
keep_control_net_on_cpu = (sbyte)(managed.KeepControlNetOnCPU ? 1 : 0),
|
keep_control_net_on_cpu = (sbyte)(managed.KeepControlNetOnCPU ? 1 : 0),
|
||||||
keep_vae_on_cpu = (sbyte)(managed.KeepVaeOnCPU ? 1 : 0),
|
keep_vae_on_cpu = (sbyte)(managed.KeepVaeOnCPU ? 1 : 0),
|
||||||
diffusion_flash_attn = (sbyte)(managed.FlashAttention ? 1 : 0),
|
diffusion_flash_attn = (sbyte)(managed.DiffusionFlashAttention ? 1 : 0),
|
||||||
|
flash_attn = (sbyte)(managed.FlashAttention ? 1 : 0),
|
||||||
tae_preview_only = (sbyte)(managed.TaePreviewOnly ? 1 : 0),
|
tae_preview_only = (sbyte)(managed.TaePreviewOnly ? 1 : 0),
|
||||||
diffusion_conv_direct = (sbyte)(managed.DiffusionConvDirect ? 1 : 0),
|
diffusion_conv_direct = (sbyte)(managed.DiffusionConvDirect ? 1 : 0),
|
||||||
vae_conv_direct = (sbyte)(managed.VaeConvDirect ? 1 : 0),
|
vae_conv_direct = (sbyte)(managed.VaeConvDirect ? 1 : 0),
|
||||||
@ -130,8 +131,7 @@ internal static unsafe class DiffusionModelParameterMarshaller
|
|||||||
chroma_use_dit_mask = (sbyte)(managed.ChromaUseDitMap ? 1 : 0),
|
chroma_use_dit_mask = (sbyte)(managed.ChromaUseDitMap ? 1 : 0),
|
||||||
chroma_use_t5_mask = (sbyte)(managed.ChromaEnableT5Map ? 1 : 0),
|
chroma_use_t5_mask = (sbyte)(managed.ChromaEnableT5Map ? 1 : 0),
|
||||||
chroma_t5_mask_pad = managed.ChromaT5MaskPad,
|
chroma_t5_mask_pad = managed.ChromaT5MaskPad,
|
||||||
qwen_image_zero_cond_t = (sbyte)(managed.QwenImageZeroCondT ? 1 : 0),
|
qwen_image_zero_cond_t = (sbyte)(managed.QwenImageZeroCondT ? 1 : 0)
|
||||||
flow_shift = managed.FlowShift
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,8 @@ internal static unsafe class SampleParameterMarshaller
|
|||||||
SampleSteps = unmanaged.sample_steps,
|
SampleSteps = unmanaged.sample_steps,
|
||||||
Eta = unmanaged.eta,
|
Eta = unmanaged.eta,
|
||||||
ShiftedTimestep = unmanaged.shifted_timestep,
|
ShiftedTimestep = unmanaged.shifted_timestep,
|
||||||
CustomSigmas = new float[unmanaged.custom_sigmas_count]
|
CustomSigmas = new float[unmanaged.custom_sigmas_count],
|
||||||
|
FlowShift = unmanaged.flow_shift
|
||||||
};
|
};
|
||||||
|
|
||||||
if (unmanaged.guidance.slg.layers != null)
|
if (unmanaged.guidance.slg.layers != null)
|
||||||
@ -86,7 +87,8 @@ internal static unsafe class SampleParameterMarshaller
|
|||||||
eta = managed.Eta,
|
eta = managed.Eta,
|
||||||
shifted_timestep = managed.ShiftedTimestep,
|
shifted_timestep = managed.ShiftedTimestep,
|
||||||
custom_sigmas = _customSigmas,
|
custom_sigmas = _customSigmas,
|
||||||
custom_sigmas_count = managed.CustomSigmas.Length
|
custom_sigmas_count = managed.CustomSigmas.Length,
|
||||||
|
flow_shift = managed.FlowShift
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -92,6 +92,7 @@ internal unsafe partial class Native
|
|||||||
public sbyte keep_clip_on_cpu;
|
public sbyte keep_clip_on_cpu;
|
||||||
public sbyte keep_control_net_on_cpu;
|
public sbyte keep_control_net_on_cpu;
|
||||||
public sbyte keep_vae_on_cpu;
|
public sbyte keep_vae_on_cpu;
|
||||||
|
public sbyte flash_attn;
|
||||||
public sbyte diffusion_flash_attn;
|
public sbyte diffusion_flash_attn;
|
||||||
public sbyte tae_preview_only;
|
public sbyte tae_preview_only;
|
||||||
public sbyte diffusion_conv_direct;
|
public sbyte diffusion_conv_direct;
|
||||||
@ -103,7 +104,6 @@ internal unsafe partial class Native
|
|||||||
public sbyte chroma_use_t5_mask;
|
public sbyte chroma_use_t5_mask;
|
||||||
public int chroma_t5_mask_pad;
|
public int chroma_t5_mask_pad;
|
||||||
public sbyte qwen_image_zero_cond_t;
|
public sbyte qwen_image_zero_cond_t;
|
||||||
public float flow_shift;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
@ -145,6 +145,7 @@ internal unsafe partial class Native
|
|||||||
public int shifted_timestep;
|
public int shifted_timestep;
|
||||||
public float* custom_sigmas;
|
public float* custom_sigmas;
|
||||||
public int custom_sigmas_count;
|
public int custom_sigmas_count;
|
||||||
|
public float flow_shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
|||||||
@ -16,7 +16,7 @@ public static unsafe class StableDiffusionCpp
|
|||||||
private static Native.sd_preview_cb_t? _previewCallback;
|
private static Native.sd_preview_cb_t? _previewCallback;
|
||||||
// ReSharper restore NotAccessedField.Local
|
// ReSharper restore NotAccessedField.Local
|
||||||
|
|
||||||
public static string ExpectedSDCommit => "b87fe13";
|
public static string ExpectedSDCommit => "5792c66";
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user