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