From 1dcbe72e2bff94e94f59a7a37ad5e09d04da808b Mon Sep 17 00:00:00 2001 From: DarthAffe Date: Sun, 30 Nov 2025 17:45:49 +0100 Subject: [PATCH] Updated sd.cpp --- StableDiffusion.NET/Enums/Prediction.cs | 3 ++- .../Models/Parameter/DiffusionModelParameter.cs | 11 ++++++++--- .../Extensions/DiffusionModelBuilderExtension.cs | 12 ++++++++---- .../Marshaller/DiffusionModelParameterMarshaller.cs | 12 ++++++------ StableDiffusion.NET/Native/Native.cs | 8 ++++---- StableDiffusion.NET/StableDiffusionCpp.cs | 4 ++-- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/StableDiffusion.NET/Enums/Prediction.cs b/StableDiffusion.NET/Enums/Prediction.cs index 07e916b..f753030 100644 --- a/StableDiffusion.NET/Enums/Prediction.cs +++ b/StableDiffusion.NET/Enums/Prediction.cs @@ -7,5 +7,6 @@ public enum Prediction V, EDM_V, SD3Flow, - FluxFlow + FluxFlow, + Flux2Flow } diff --git a/StableDiffusion.NET/Models/Parameter/DiffusionModelParameter.cs b/StableDiffusion.NET/Models/Parameter/DiffusionModelParameter.cs index 114513f..dc3a7d4 100644 --- a/StableDiffusion.NET/Models/Parameter/DiffusionModelParameter.cs +++ b/StableDiffusion.NET/Models/Parameter/DiffusionModelParameter.cs @@ -1,4 +1,5 @@ -using JetBrains.Annotations; +using System; +using JetBrains.Annotations; namespace StableDiffusion.NET; @@ -139,9 +140,13 @@ public sealed class DiffusionModelParameter /// public string T5xxlPath { get; set; } = string.Empty; - public string Qwen2VLPath { get; set; } = string.Empty; + [Obsolete("Use LLMPath instead")] + public string Qwen2VLPath { get => LLMPath; set => LLMPath = value; } + public string LLMPath { get; set; } = string.Empty; - public string Qwen2VLVisionPath { get; set; } = string.Empty; + [Obsolete("Use LLMVisionPath instead")] + public string Qwen2VLVisionPath { get => LLMVisionPath; set => LLMVisionPath = value; } + public string LLMVisionPath { get; set; } = string.Empty; public string ClipVisionPath { get; set; } = string.Empty; public string HighNoiseDiffusionModelPath { get; set; } = string.Empty; diff --git a/StableDiffusion.NET/Models/Parameter/Extensions/DiffusionModelBuilderExtension.cs b/StableDiffusion.NET/Models/Parameter/Extensions/DiffusionModelBuilderExtension.cs index 6f9ec7f..6e398c1 100644 --- a/StableDiffusion.NET/Models/Parameter/Extensions/DiffusionModelBuilderExtension.cs +++ b/StableDiffusion.NET/Models/Parameter/Extensions/DiffusionModelBuilderExtension.cs @@ -236,16 +236,20 @@ public static class DiffusionModelBuilderExtension return parameter; } - public static DiffusionModelParameter WithQwen2VLPath(this DiffusionModelParameter parameter, string qwen2VLPath) + [Obsolete("Use WithLLMPath instead")] + public static DiffusionModelParameter WithQwen2VLPath(this DiffusionModelParameter parameter, string qwen2VLPath) => parameter.WithLLMPath(qwen2VLPath); + public static DiffusionModelParameter WithLLMPath(this DiffusionModelParameter parameter, string llmPath) { - parameter.Qwen2VLPath = qwen2VLPath; + parameter.LLMPath = llmPath; return parameter; } - public static DiffusionModelParameter WithQwen2VLVisionPath(this DiffusionModelParameter parameter, string qwen2VLVisionPath) + [Obsolete("Use WithLLMVisionPath instead")] + public static DiffusionModelParameter WithQwen2VLVisionPath(this DiffusionModelParameter parameter, string qwen2VLVisionPath) => parameter.WithLLMVisionPath(qwen2VLVisionPath); + public static DiffusionModelParameter WithLLMVisionPath(this DiffusionModelParameter parameter, string llmVisionPath) { - parameter.Qwen2VLVisionPath = qwen2VLVisionPath; + parameter.LLMVisionPath = llmVisionPath; return parameter; } diff --git a/StableDiffusion.NET/Native/Marshaller/DiffusionModelParameterMarshaller.cs b/StableDiffusion.NET/Native/Marshaller/DiffusionModelParameterMarshaller.cs index f6fabc7..e8ff8b8 100644 --- a/StableDiffusion.NET/Native/Marshaller/DiffusionModelParameterMarshaller.cs +++ b/StableDiffusion.NET/Native/Marshaller/DiffusionModelParameterMarshaller.cs @@ -14,8 +14,8 @@ internal static unsafe class DiffusionModelParameterMarshaller clip_g_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.ClipGPath), clip_vision_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.ClipVisionPath), t5xxl_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.T5xxlPath), - qwen2vl_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.Qwen2VLPath), - qwen2vl_vision_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.Qwen2VLVisionPath), + llm_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.LLMPath), + llm_vision_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.LLMVisionPath), diffusion_model_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.DiffusionModelPath), high_noise_diffusion_model_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.HighNoiseDiffusionModelPath), vae_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.VaePath), @@ -56,8 +56,8 @@ internal static unsafe class DiffusionModelParameterMarshaller ClipGPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.clip_g_path) ?? string.Empty, ClipVisionPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.clip_vision_path) ?? string.Empty, T5xxlPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.t5xxl_path) ?? string.Empty, - Qwen2VLPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.qwen2vl_path) ?? string.Empty, - Qwen2VLVisionPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.qwen2vl_vision_path) ?? string.Empty, + LLMPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.llm_path) ?? string.Empty, + LLMVisionPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.llm_vision_path) ?? string.Empty, DiffusionModelPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.diffusion_model_path) ?? string.Empty, HighNoiseDiffusionModelPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.high_noise_diffusion_model_path) ?? string.Empty, VaePath = AnsiStringMarshaller.ConvertToManaged(unmanaged.vae_path) ?? string.Empty, @@ -96,8 +96,8 @@ internal static unsafe class DiffusionModelParameterMarshaller AnsiStringMarshaller.Free(unmanaged.clip_l_path); AnsiStringMarshaller.Free(unmanaged.clip_g_path); AnsiStringMarshaller.Free(unmanaged.t5xxl_path); - AnsiStringMarshaller.Free(unmanaged.qwen2vl_path); - AnsiStringMarshaller.Free(unmanaged.qwen2vl_vision_path); + AnsiStringMarshaller.Free(unmanaged.llm_path); + AnsiStringMarshaller.Free(unmanaged.llm_vision_path); AnsiStringMarshaller.Free(unmanaged.diffusion_model_path); AnsiStringMarshaller.Free(unmanaged.vae_path); AnsiStringMarshaller.Free(unmanaged.taesd_path); diff --git a/StableDiffusion.NET/Native/Native.cs b/StableDiffusion.NET/Native/Native.cs index 6e3ec63..16ef550 100644 --- a/StableDiffusion.NET/Native/Native.cs +++ b/StableDiffusion.NET/Native/Native.cs @@ -60,8 +60,8 @@ internal unsafe partial class Native public byte* clip_g_path; public byte* clip_vision_path; public byte* t5xxl_path; - public byte* qwen2vl_path; - public byte* qwen2vl_vision_path; + public byte* llm_path; + public byte* llm_vision_path; public byte* diffusion_model_path; public byte* high_noise_diffusion_model_path; public byte* vae_path; @@ -207,7 +207,7 @@ internal unsafe partial class Native internal delegate void sd_log_cb_t(sd_log_level_t level, [MarshalAs(UnmanagedType.LPStr)] string text, void* data); internal delegate void sd_progress_cb_t(int step, int steps, float time, void* data); - internal delegate void sd_preview_cb_t(int step, int frame_count, sd_image_t* frames, bool is_noisy); + internal delegate void sd_preview_cb_t(int step, int frame_count, sd_image_t* frames, bool is_noisy, void* data); #endregion @@ -220,7 +220,7 @@ internal unsafe partial class Native internal static partial void sd_set_progress_callback(sd_progress_cb_t cb, void* data); [LibraryImport(LIB_NAME, EntryPoint = "sd_set_preview_callback")] - internal static partial void sd_set_preview_callback(sd_preview_cb_t? cb, preview_t mode, int interval, [MarshalAs(UnmanagedType.I1)] bool denoised, [MarshalAs(UnmanagedType.I1)] bool noisy); + internal static partial void sd_set_preview_callback(sd_preview_cb_t? cb, preview_t mode, int interval, [MarshalAs(UnmanagedType.I1)] bool denoised, [MarshalAs(UnmanagedType.I1)] bool noisy, void* data); [LibraryImport(LIB_NAME, EntryPoint = "get_num_physical_cores")] internal static partial int32_t get_num_physical_cores(); diff --git a/StableDiffusion.NET/StableDiffusionCpp.cs b/StableDiffusion.NET/StableDiffusionCpp.cs index 48081fd..13e4c0a 100644 --- a/StableDiffusion.NET/StableDiffusionCpp.cs +++ b/StableDiffusion.NET/StableDiffusionCpp.cs @@ -45,7 +45,7 @@ public static unsafe class StableDiffusionCpp else if (_previewCallback == null) _previewCallback = OnPreview; - Native.sd_set_preview_callback(_previewCallback, mode, interval, denoised, noisy); + Native.sd_set_preview_callback(_previewCallback, mode, interval, denoised, noisy, null); } public static void Convert(string modelPath, string vaePath, Quantization quantization, string outputPath, string tensorTypeRules = "") @@ -104,7 +104,7 @@ public static unsafe class StableDiffusionCpp catch { /**/ } } - private static void OnPreview(int step, int frameCount, Native.Types.sd_image_t* frames, bool isNoisy) + private static void OnPreview(int step, int frameCount, Native.Types.sd_image_t* frames, bool isNoisy, void* data) { try {