Skip to content

Commit 3ec6acb

Browse files
authored
Merge pull request #65 from DarthAffe/sdcppUpdate
Updated sd.cpp
2 parents 06b97ba + 66568ff commit 3ec6acb

File tree

7 files changed

+36
-28
lines changed

7 files changed

+36
-28
lines changed

Header/stable-diffusion.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ enum sample_method_t {
4848
LCM_SAMPLE_METHOD,
4949
DDIM_TRAILING_SAMPLE_METHOD,
5050
TCD_SAMPLE_METHOD,
51-
5251
SAMPLE_METHOD_COUNT
5352
};
5453

5554
enum scheduler_t {
56-
5755
DISCRETE_SCHEDULER,
5856
KARRAS_SCHEDULER,
5957
EXPONENTIAL_SCHEDULER,
@@ -73,6 +71,7 @@ enum prediction_t {
7371
EDM_V_PRED,
7472
SD3_FLOW_PRED,
7573
FLUX_FLOW_PRED,
74+
FLUX2_FLOW_PRED,
7675
PREDICTION_COUNT
7776
};
7877

@@ -158,8 +157,8 @@ typedef struct {
158157
const char* clip_g_path;
159158
const char* clip_vision_path;
160159
const char* t5xxl_path;
161-
const char* qwen2vl_path;
162-
const char* qwen2vl_vision_path;
160+
const char* llm_path;
161+
const char* llm_vision_path;
163162
const char* diffusion_model_path;
164163
const char* high_noise_diffusion_model_path;
165164
const char* vae_path;
@@ -284,11 +283,11 @@ typedef struct sd_ctx_t sd_ctx_t;
284283

285284
typedef void (*sd_log_cb_t)(enum sd_log_level_t level, const char* text, void* data);
286285
typedef void (*sd_progress_cb_t)(int step, int steps, float time, void* data);
287-
typedef void (*sd_preview_cb_t)(int step, int frame_count, sd_image_t* frames, bool is_noisy);
286+
typedef void (*sd_preview_cb_t)(int step, int frame_count, sd_image_t* frames, bool is_noisy, void* data);
288287

289288
SD_API void sd_set_log_callback(sd_log_cb_t sd_log_cb, void* data);
290289
SD_API void sd_set_progress_callback(sd_progress_cb_t cb, void* data);
291-
SD_API void sd_set_preview_callback(sd_preview_cb_t cb, enum preview_t mode, int interval, bool denoised, bool noisy);
290+
SD_API void sd_set_preview_callback(sd_preview_cb_t cb, enum preview_t mode, int interval, bool denoised, bool noisy, void* data);
292291
SD_API int32_t get_num_physical_cores();
293292
SD_API const char* sd_get_system_info();
294293

@@ -314,7 +313,6 @@ SD_API char* sd_ctx_params_to_str(const sd_ctx_params_t* sd_ctx_params);
314313

315314
SD_API sd_ctx_t* new_sd_ctx(const sd_ctx_params_t* sd_ctx_params);
316315
SD_API void free_sd_ctx(sd_ctx_t* sd_ctx);
317-
318316

319317
SD_API void sd_sample_params_init(sd_sample_params_t* sample_params);
320318
SD_API char* sd_sample_params_to_str(const sd_sample_params_t* sample_params);
@@ -360,4 +358,4 @@ SD_API bool preprocess_canny(sd_image_t image,
360358
}
361359
#endif
362360

363-
#endif // __STABLE_DIFFUSION_H__
361+
#endif // __STABLE_DIFFUSION_H__

StableDiffusion.NET/Enums/Prediction.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ public enum Prediction
77
V,
88
EDM_V,
99
SD3Flow,
10-
FluxFlow
10+
FluxFlow,
11+
Flux2Flow
1112
}

StableDiffusion.NET/Models/Parameter/DiffusionModelParameter.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using JetBrains.Annotations;
1+
using System;
2+
using JetBrains.Annotations;
23

34
namespace StableDiffusion.NET;
45

@@ -139,9 +140,13 @@ public sealed class DiffusionModelParameter
139140
/// </summary>
140141
public string T5xxlPath { get; set; } = string.Empty;
141142

142-
public string Qwen2VLPath { get; set; } = string.Empty;
143+
[Obsolete("Use LLMPath instead")]
144+
public string Qwen2VLPath { get => LLMPath; set => LLMPath = value; }
145+
public string LLMPath { get; set; } = string.Empty;
143146

144-
public string Qwen2VLVisionPath { get; set; } = string.Empty;
147+
[Obsolete("Use LLMVisionPath instead")]
148+
public string Qwen2VLVisionPath { get => LLMVisionPath; set => LLMVisionPath = value; }
149+
public string LLMVisionPath { get; set; } = string.Empty;
145150

146151
public string ClipVisionPath { get; set; } = string.Empty;
147152
public string HighNoiseDiffusionModelPath { get; set; } = string.Empty;

StableDiffusion.NET/Models/Parameter/Extensions/DiffusionModelBuilderExtension.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,20 @@ public static DiffusionModelParameter WithT5xxlPath(this DiffusionModelParameter
236236
return parameter;
237237
}
238238

239-
public static DiffusionModelParameter WithQwen2VLPath(this DiffusionModelParameter parameter, string qwen2VLPath)
239+
[Obsolete("Use WithLLMPath instead")]
240+
public static DiffusionModelParameter WithQwen2VLPath(this DiffusionModelParameter parameter, string qwen2VLPath) => parameter.WithLLMPath(qwen2VLPath);
241+
public static DiffusionModelParameter WithLLMPath(this DiffusionModelParameter parameter, string llmPath)
240242
{
241-
parameter.Qwen2VLPath = qwen2VLPath;
243+
parameter.LLMPath = llmPath;
242244

243245
return parameter;
244246
}
245247

246-
public static DiffusionModelParameter WithQwen2VLVisionPath(this DiffusionModelParameter parameter, string qwen2VLVisionPath)
248+
[Obsolete("Use WithLLMVisionPath instead")]
249+
public static DiffusionModelParameter WithQwen2VLVisionPath(this DiffusionModelParameter parameter, string qwen2VLVisionPath) => parameter.WithLLMVisionPath(qwen2VLVisionPath);
250+
public static DiffusionModelParameter WithLLMVisionPath(this DiffusionModelParameter parameter, string llmVisionPath)
247251
{
248-
parameter.Qwen2VLVisionPath = qwen2VLVisionPath;
252+
parameter.LLMVisionPath = llmVisionPath;
249253

250254
return parameter;
251255
}

StableDiffusion.NET/Native/Marshaller/DiffusionModelParameterMarshaller.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public static Native.Types.sd_ctx_params_t ConvertToUnmanaged(DiffusionModelPara
1414
clip_g_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.ClipGPath),
1515
clip_vision_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.ClipVisionPath),
1616
t5xxl_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.T5xxlPath),
17-
qwen2vl_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.Qwen2VLPath),
18-
qwen2vl_vision_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.Qwen2VLVisionPath),
17+
llm_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.LLMPath),
18+
llm_vision_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.LLMVisionPath),
1919
diffusion_model_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.DiffusionModelPath),
2020
high_noise_diffusion_model_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.HighNoiseDiffusionModelPath),
2121
vae_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.VaePath),
@@ -56,8 +56,8 @@ public static DiffusionModelParameter ConvertToManaged(Native.Types.sd_ctx_param
5656
ClipGPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.clip_g_path) ?? string.Empty,
5757
ClipVisionPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.clip_vision_path) ?? string.Empty,
5858
T5xxlPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.t5xxl_path) ?? string.Empty,
59-
Qwen2VLPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.qwen2vl_path) ?? string.Empty,
60-
Qwen2VLVisionPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.qwen2vl_vision_path) ?? string.Empty,
59+
LLMPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.llm_path) ?? string.Empty,
60+
LLMVisionPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.llm_vision_path) ?? string.Empty,
6161
DiffusionModelPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.diffusion_model_path) ?? string.Empty,
6262
HighNoiseDiffusionModelPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.high_noise_diffusion_model_path) ?? string.Empty,
6363
VaePath = AnsiStringMarshaller.ConvertToManaged(unmanaged.vae_path) ?? string.Empty,
@@ -96,8 +96,8 @@ public static void Free(Native.Types.sd_ctx_params_t unmanaged)
9696
AnsiStringMarshaller.Free(unmanaged.clip_l_path);
9797
AnsiStringMarshaller.Free(unmanaged.clip_g_path);
9898
AnsiStringMarshaller.Free(unmanaged.t5xxl_path);
99-
AnsiStringMarshaller.Free(unmanaged.qwen2vl_path);
100-
AnsiStringMarshaller.Free(unmanaged.qwen2vl_vision_path);
99+
AnsiStringMarshaller.Free(unmanaged.llm_path);
100+
AnsiStringMarshaller.Free(unmanaged.llm_vision_path);
101101
AnsiStringMarshaller.Free(unmanaged.diffusion_model_path);
102102
AnsiStringMarshaller.Free(unmanaged.vae_path);
103103
AnsiStringMarshaller.Free(unmanaged.taesd_path);

StableDiffusion.NET/Native/Native.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ internal struct sd_ctx_params_t
6060
public byte* clip_g_path;
6161
public byte* clip_vision_path;
6262
public byte* t5xxl_path;
63-
public byte* qwen2vl_path;
64-
public byte* qwen2vl_vision_path;
63+
public byte* llm_path;
64+
public byte* llm_vision_path;
6565
public byte* diffusion_model_path;
6666
public byte* high_noise_diffusion_model_path;
6767
public byte* vae_path;
@@ -207,7 +207,7 @@ internal struct upscaler_ctx_t;
207207

208208
internal delegate void sd_log_cb_t(sd_log_level_t level, [MarshalAs(UnmanagedType.LPStr)] string text, void* data);
209209
internal delegate void sd_progress_cb_t(int step, int steps, float time, void* data);
210-
internal delegate void sd_preview_cb_t(int step, int frame_count, sd_image_t* frames, bool is_noisy);
210+
internal delegate void sd_preview_cb_t(int step, int frame_count, sd_image_t* frames, bool is_noisy, void* data);
211211

212212
#endregion
213213

@@ -220,7 +220,7 @@ internal struct upscaler_ctx_t;
220220
internal static partial void sd_set_progress_callback(sd_progress_cb_t cb, void* data);
221221

222222
[LibraryImport(LIB_NAME, EntryPoint = "sd_set_preview_callback")]
223-
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);
223+
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);
224224

225225
[LibraryImport(LIB_NAME, EntryPoint = "get_num_physical_cores")]
226226
internal static partial int32_t get_num_physical_cores();

StableDiffusion.NET/StableDiffusionCpp.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static void EnablePreview(Preview mode, int interval, bool denoised, bool
4545
else if (_previewCallback == null)
4646
_previewCallback = OnPreview;
4747

48-
Native.sd_set_preview_callback(_previewCallback, mode, interval, denoised, noisy);
48+
Native.sd_set_preview_callback(_previewCallback, mode, interval, denoised, noisy, null);
4949
}
5050

5151
public static void Convert(string modelPath, string vaePath, Quantization quantization, string outputPath, string tensorTypeRules = "")
@@ -104,7 +104,7 @@ private static void OnNativeProgress(int step, int steps, float time, void* data
104104
catch { /**/ }
105105
}
106106

107-
private static void OnPreview(int step, int frameCount, Native.Types.sd_image_t* frames, bool isNoisy)
107+
private static void OnPreview(int step, int frameCount, Native.Types.sd_image_t* frames, bool isNoisy, void* data)
108108
{
109109
try
110110
{

0 commit comments

Comments
 (0)