mirror of
https://github.com/DarthAffe/StableDiffusion.NET.git
synced 2026-02-05 03:15:17 +00:00
Compare commits
No commits in common. "master" and "4.6.0" have entirely different histories.
@ -60,7 +60,6 @@ enum scheduler_t {
|
|||||||
SGM_UNIFORM_SCHEDULER,
|
SGM_UNIFORM_SCHEDULER,
|
||||||
SIMPLE_SCHEDULER,
|
SIMPLE_SCHEDULER,
|
||||||
SMOOTHSTEP_SCHEDULER,
|
SMOOTHSTEP_SCHEDULER,
|
||||||
KL_OPTIMAL_SCHEDULER,
|
|
||||||
LCM_SCHEDULER,
|
LCM_SCHEDULER,
|
||||||
SCHEDULER_COUNT
|
SCHEDULER_COUNT
|
||||||
};
|
};
|
||||||
@ -169,6 +168,7 @@ typedef struct {
|
|||||||
const char* vae_path;
|
const char* vae_path;
|
||||||
const char* taesd_path;
|
const char* taesd_path;
|
||||||
const char* control_net_path;
|
const char* control_net_path;
|
||||||
|
const char* lora_model_dir;
|
||||||
const sd_embedding_t* embeddings;
|
const sd_embedding_t* embeddings;
|
||||||
uint32_t embedding_count;
|
uint32_t embedding_count;
|
||||||
const char* photo_maker_path;
|
const char* photo_maker_path;
|
||||||
@ -182,7 +182,6 @@ typedef struct {
|
|||||||
enum prediction_t prediction;
|
enum prediction_t prediction;
|
||||||
enum lora_apply_mode_t lora_apply_mode;
|
enum lora_apply_mode_t lora_apply_mode;
|
||||||
bool offload_params_to_cpu;
|
bool offload_params_to_cpu;
|
||||||
bool enable_mmap;
|
|
||||||
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;
|
||||||
@ -190,13 +189,10 @@ typedef struct {
|
|||||||
bool tae_preview_only;
|
bool tae_preview_only;
|
||||||
bool diffusion_conv_direct;
|
bool diffusion_conv_direct;
|
||||||
bool vae_conv_direct;
|
bool vae_conv_direct;
|
||||||
bool circular_x;
|
|
||||||
bool circular_y;
|
|
||||||
bool force_sdxl_vae_conv_scale;
|
bool force_sdxl_vae_conv_scale;
|
||||||
bool chroma_use_dit_mask;
|
bool chroma_use_dit_mask;
|
||||||
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;
|
|
||||||
float flow_shift;
|
float flow_shift;
|
||||||
} sd_ctx_params_t;
|
} sd_ctx_params_t;
|
||||||
|
|
||||||
@ -240,34 +236,12 @@ typedef struct {
|
|||||||
float style_strength;
|
float style_strength;
|
||||||
} sd_pm_params_t; // photo maker
|
} sd_pm_params_t; // photo maker
|
||||||
|
|
||||||
enum sd_cache_mode_t {
|
|
||||||
SD_CACHE_DISABLED = 0,
|
|
||||||
SD_CACHE_EASYCACHE,
|
|
||||||
SD_CACHE_UCACHE,
|
|
||||||
SD_CACHE_DBCACHE,
|
|
||||||
SD_CACHE_TAYLORSEER,
|
|
||||||
SD_CACHE_CACHE_DIT,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
enum sd_cache_mode_t mode;
|
bool enabled;
|
||||||
float reuse_threshold;
|
float reuse_threshold;
|
||||||
float start_percent;
|
float start_percent;
|
||||||
float end_percent;
|
float end_percent;
|
||||||
float error_decay_rate;
|
} sd_easycache_params_t;
|
||||||
bool use_relative_threshold;
|
|
||||||
bool reset_error_on_compute;
|
|
||||||
int Fn_compute_blocks;
|
|
||||||
int Bn_compute_blocks;
|
|
||||||
float residual_diff_threshold;
|
|
||||||
int max_warmup_steps;
|
|
||||||
int max_cached_steps;
|
|
||||||
int max_continuous_cached_steps;
|
|
||||||
int taylorseer_n_derivatives;
|
|
||||||
int taylorseer_skip_interval;
|
|
||||||
const char* scm_mask;
|
|
||||||
bool scm_policy_dynamic;
|
|
||||||
} sd_cache_params_t;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool is_high_noise;
|
bool is_high_noise;
|
||||||
@ -297,7 +271,7 @@ typedef struct {
|
|||||||
float control_strength;
|
float control_strength;
|
||||||
sd_pm_params_t pm_params;
|
sd_pm_params_t pm_params;
|
||||||
sd_tiling_params_t vae_tiling_params;
|
sd_tiling_params_t vae_tiling_params;
|
||||||
sd_cache_params_t cache;
|
sd_easycache_params_t easycache;
|
||||||
} sd_img_gen_params_t;
|
} sd_img_gen_params_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -319,8 +293,7 @@ typedef struct {
|
|||||||
int64_t seed;
|
int64_t seed;
|
||||||
int video_frames;
|
int video_frames;
|
||||||
float vace_strength;
|
float vace_strength;
|
||||||
sd_tiling_params_t vae_tiling_params;
|
sd_easycache_params_t easycache;
|
||||||
sd_cache_params_t cache;
|
|
||||||
} sd_vid_gen_params_t;
|
} sd_vid_gen_params_t;
|
||||||
|
|
||||||
typedef struct sd_ctx_t sd_ctx_t;
|
typedef struct sd_ctx_t sd_ctx_t;
|
||||||
@ -350,7 +323,7 @@ SD_API enum preview_t str_to_preview(const char* str);
|
|||||||
SD_API const char* sd_lora_apply_mode_name(enum lora_apply_mode_t mode);
|
SD_API const char* sd_lora_apply_mode_name(enum lora_apply_mode_t mode);
|
||||||
SD_API enum lora_apply_mode_t str_to_lora_apply_mode(const char* str);
|
SD_API enum lora_apply_mode_t str_to_lora_apply_mode(const char* str);
|
||||||
|
|
||||||
SD_API void sd_cache_params_init(sd_cache_params_t* cache_params);
|
SD_API void sd_easycache_params_init(sd_easycache_params_t* easycache_params);
|
||||||
|
|
||||||
SD_API void sd_ctx_params_init(sd_ctx_params_t* sd_ctx_params);
|
SD_API void sd_ctx_params_init(sd_ctx_params_t* sd_ctx_params);
|
||||||
SD_API char* sd_ctx_params_to_str(const sd_ctx_params_t* sd_ctx_params);
|
SD_API char* sd_ctx_params_to_str(const sd_ctx_params_t* sd_ctx_params);
|
||||||
@ -362,7 +335,7 @@ SD_API void sd_sample_params_init(sd_sample_params_t* sample_params);
|
|||||||
SD_API char* sd_sample_params_to_str(const sd_sample_params_t* sample_params);
|
SD_API char* sd_sample_params_to_str(const sd_sample_params_t* sample_params);
|
||||||
|
|
||||||
SD_API enum sample_method_t sd_get_default_sample_method(const sd_ctx_t* sd_ctx);
|
SD_API enum sample_method_t sd_get_default_sample_method(const sd_ctx_t* sd_ctx);
|
||||||
SD_API enum scheduler_t sd_get_default_scheduler(const sd_ctx_t* sd_ctx, enum sample_method_t sample_method);
|
SD_API enum scheduler_t sd_get_default_scheduler(const sd_ctx_t* sd_ctx);
|
||||||
|
|
||||||
SD_API void sd_img_gen_params_init(sd_img_gen_params_t* sd_img_gen_params);
|
SD_API void sd_img_gen_params_init(sd_img_gen_params_t* sd_img_gen_params);
|
||||||
SD_API char* sd_img_gen_params_to_str(const sd_img_gen_params_t* sd_img_gen_params);
|
SD_API char* sd_img_gen_params_to_str(const sd_img_gen_params_t* sd_img_gen_params);
|
||||||
@ -390,8 +363,7 @@ SD_API bool convert(const char* input_path,
|
|||||||
const char* vae_path,
|
const char* vae_path,
|
||||||
const char* output_path,
|
const char* output_path,
|
||||||
enum sd_type_t output_type,
|
enum sd_type_t output_type,
|
||||||
const char* tensor_type_rules,
|
const char* tensor_type_rules);
|
||||||
bool convert_name);
|
|
||||||
|
|
||||||
SD_API bool preprocess_canny(sd_image_t image,
|
SD_API bool preprocess_canny(sd_image_t image,
|
||||||
float high_threshold,
|
float high_threshold,
|
||||||
|
|||||||
@ -1,11 +0,0 @@
|
|||||||
namespace StableDiffusion.NET;
|
|
||||||
|
|
||||||
public enum CacheMode
|
|
||||||
{
|
|
||||||
Disabled = 0,
|
|
||||||
EasyCache,
|
|
||||||
UCache,
|
|
||||||
DBCache,
|
|
||||||
Taylorseer,
|
|
||||||
CacheDit,
|
|
||||||
}
|
|
||||||
@ -10,7 +10,6 @@ public enum Scheduler
|
|||||||
SGM_Uniform,
|
SGM_Uniform,
|
||||||
Simple,
|
Simple,
|
||||||
Smoothstep,
|
Smoothstep,
|
||||||
KlOptimal,
|
|
||||||
LCM,
|
LCM,
|
||||||
Default
|
Default
|
||||||
}
|
}
|
||||||
@ -20,7 +20,9 @@ public static class ParameterExtension
|
|||||||
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(parameter.ThreadCount, nameof(DiffusionModelParameter.ThreadCount));
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(parameter.ThreadCount, nameof(DiffusionModelParameter.ThreadCount));
|
||||||
ArgumentNullException.ThrowIfNull(parameter.VaePath, nameof(DiffusionModelParameter.VaePath));
|
ArgumentNullException.ThrowIfNull(parameter.VaePath, nameof(DiffusionModelParameter.VaePath));
|
||||||
ArgumentNullException.ThrowIfNull(parameter.TaesdPath, nameof(DiffusionModelParameter.TaesdPath));
|
ArgumentNullException.ThrowIfNull(parameter.TaesdPath, nameof(DiffusionModelParameter.TaesdPath));
|
||||||
|
ArgumentNullException.ThrowIfNull(parameter.LoraModelDirectory, nameof(DiffusionModelParameter.LoraModelDirectory));
|
||||||
ArgumentNullException.ThrowIfNull(parameter.ControlNetPath, nameof(DiffusionModelParameter.ControlNetPath));
|
ArgumentNullException.ThrowIfNull(parameter.ControlNetPath, nameof(DiffusionModelParameter.ControlNetPath));
|
||||||
|
ArgumentNullException.ThrowIfNull(parameter.EmbeddingsDirectory, nameof(DiffusionModelParameter.EmbeddingsDirectory));
|
||||||
ArgumentNullException.ThrowIfNull(parameter.StackedIdEmbeddingsDirectory, nameof(DiffusionModelParameter.StackedIdEmbeddingsDirectory));
|
ArgumentNullException.ThrowIfNull(parameter.StackedIdEmbeddingsDirectory, nameof(DiffusionModelParameter.StackedIdEmbeddingsDirectory));
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(parameter.VaePath) && !string.IsNullOrWhiteSpace(parameter.TaesdPath)) throw new ArgumentException("VAE and TAESD are mutually exclusive.");
|
if (!string.IsNullOrWhiteSpace(parameter.VaePath) && !string.IsNullOrWhiteSpace(parameter.TaesdPath)) throw new ArgumentException("VAE and TAESD are mutually exclusive.");
|
||||||
@ -91,6 +93,7 @@ public static class ParameterExtension
|
|||||||
|
|
||||||
ArgumentOutOfRangeException.ThrowIfNegative(parameter.ImgCfg);
|
ArgumentOutOfRangeException.ThrowIfNegative(parameter.ImgCfg);
|
||||||
ArgumentOutOfRangeException.ThrowIfNegative(parameter.DistilledGuidance);
|
ArgumentOutOfRangeException.ThrowIfNegative(parameter.DistilledGuidance);
|
||||||
|
ArgumentOutOfRangeException.ThrowIfNegative(parameter.MinCfg);
|
||||||
ArgumentOutOfRangeException.ThrowIfNegative(parameter.TxtCfg);
|
ArgumentOutOfRangeException.ThrowIfNegative(parameter.TxtCfg);
|
||||||
|
|
||||||
parameter.Slg.Validate();
|
parameter.Slg.Validate();
|
||||||
|
|||||||
@ -1,27 +0,0 @@
|
|||||||
using JetBrains.Annotations;
|
|
||||||
|
|
||||||
namespace StableDiffusion.NET;
|
|
||||||
|
|
||||||
[PublicAPI]
|
|
||||||
public sealed class CacheParameter
|
|
||||||
{
|
|
||||||
public CacheMode Mode { get; set; } = CacheMode.Disabled;
|
|
||||||
public float ReuseThreshold { get; set; } = 1.0f;
|
|
||||||
public float StartPercent { get; set; } = 0.15f;
|
|
||||||
public float EndPercent { get; set; } = 0.95f;
|
|
||||||
public float ErrorDecayRate { get; set; } = 1.0f;
|
|
||||||
public bool UseRelativeThreshold { get; set; } = true;
|
|
||||||
public bool ResetErrorOnCompute { get; set; } = true;
|
|
||||||
public int FnComputeBlocks { get; set; } = 8;
|
|
||||||
public int BnComputeBlocks { get; set; } = 0;
|
|
||||||
public float ResidualDiffThreshold { get; set; } = 0.08f;
|
|
||||||
public int MaxWarmupSteps { get; set; } = 8;
|
|
||||||
public int MaxCachedSteps { get; set; } = -1;
|
|
||||||
public int MaxContinuousCachedSteps { get; set; } = -1;
|
|
||||||
public int TaylorseerNDerivatives { get; set; } = 1;
|
|
||||||
public int TaylorseerSkipInterval { get; set; } = 1;
|
|
||||||
public string? ScmMask { get; set; } = null;
|
|
||||||
public bool ScmPolicyDynamic { get; set; } = true;
|
|
||||||
|
|
||||||
internal CacheParameter() { }
|
|
||||||
}
|
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
namespace StableDiffusion.NET;
|
namespace StableDiffusion.NET;
|
||||||
@ -16,6 +17,17 @@ public sealed class DiffusionModelParameter
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string TaesdPath { get; set; } = string.Empty;
|
public string TaesdPath { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// lora model directory
|
||||||
|
/// </summary>
|
||||||
|
public string LoraModelDirectory { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// path to embeddings
|
||||||
|
/// </summary>
|
||||||
|
[Obsolete("Use Embeddings instead")]
|
||||||
|
public string EmbeddingsDirectory { get; set; } = string.Empty;
|
||||||
|
|
||||||
public List<Embedding> Embeddings { get; } = [];
|
public List<Embedding> Embeddings { get; } = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -27,7 +39,7 @@ public sealed class DiffusionModelParameter
|
|||||||
/// number of threads to use during computation (default: -1)
|
/// number of threads to use during computation (default: -1)
|
||||||
/// If threads = -1, then threads will be set to the number of CPU physical cores
|
/// If threads = -1, then threads will be set to the number of CPU physical cores
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int ThreadCount { get; set; } = -1;
|
public int ThreadCount { get; set; } = 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -43,8 +55,6 @@ public sealed class DiffusionModelParameter
|
|||||||
|
|
||||||
public bool OffloadParamsToCPU { get; set; } = false;
|
public bool OffloadParamsToCPU { get; set; } = false;
|
||||||
|
|
||||||
public bool EnableMmap { get; set; } = false;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// keep clip in cpu (for low vram)
|
/// keep clip in cpu (for low vram)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -81,9 +91,6 @@ public sealed class DiffusionModelParameter
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool VaeConvDirect { get; set; } = false;
|
public bool VaeConvDirect { get; set; } = false;
|
||||||
|
|
||||||
public bool CircularX { get; set; } = false;
|
|
||||||
public bool CircularY { get; set; } = false;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// RNG (default: Standard)
|
/// RNG (default: Standard)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -101,7 +108,7 @@ 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 float FlowShift { get; set; } = 0;
|
||||||
|
|
||||||
public bool ForceSdxlVaeConvScale { get; set; } = false;
|
public bool ForceSdxlVaeConvScale { get; set; } = false;
|
||||||
|
|
||||||
@ -137,8 +144,12 @@ public sealed class DiffusionModelParameter
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string T5xxlPath { get; set; } = string.Empty;
|
public string T5xxlPath { 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 LLMPath { 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 LLMVisionPath { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string ClipVisionPath { get; set; } = string.Empty;
|
public string ClipVisionPath { get; set; } = string.Empty;
|
||||||
@ -148,7 +159,5 @@ public sealed class DiffusionModelParameter
|
|||||||
public bool ChromaEnableT5Map { get; set; } = false;
|
public bool ChromaEnableT5Map { get; set; } = false;
|
||||||
public int ChromaT5MaskPad { get; set; } = 1;
|
public int ChromaT5MaskPad { get; set; } = 1;
|
||||||
|
|
||||||
public bool QwenImageZeroCondT { get; set; } = false;
|
|
||||||
|
|
||||||
public static DiffusionModelParameter Create() => new();
|
public static DiffusionModelParameter Create() => new();
|
||||||
}
|
}
|
||||||
11
StableDiffusion.NET/Models/Parameter/EasyCache.cs
Normal file
11
StableDiffusion.NET/Models/Parameter/EasyCache.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace StableDiffusion.NET;
|
||||||
|
|
||||||
|
public sealed class EasyCache
|
||||||
|
{
|
||||||
|
public bool IsEnabled { get; set; }
|
||||||
|
public float ReuseThreshold { get; set; }
|
||||||
|
public float StartPercent { get; set; }
|
||||||
|
public float EndPercent { get; set; }
|
||||||
|
|
||||||
|
internal EasyCache() { }
|
||||||
|
}
|
||||||
@ -28,6 +28,25 @@ public static class DiffusionModelBuilderExtension
|
|||||||
return parameter;
|
return parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DiffusionModelParameter WithLoraSupport(this DiffusionModelParameter parameter, string loraModelDirectory)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(loraModelDirectory);
|
||||||
|
|
||||||
|
parameter.LoraModelDirectory = loraModelDirectory;
|
||||||
|
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Obsolete("Use WithEmbedding instead")]
|
||||||
|
public static DiffusionModelParameter WithEmbeddingSupport(this DiffusionModelParameter parameter, string embeddingsDirectory)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(embeddingsDirectory);
|
||||||
|
|
||||||
|
parameter.EmbeddingsDirectory = embeddingsDirectory;
|
||||||
|
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
|
||||||
public static DiffusionModelParameter WithEmbedding(this DiffusionModelParameter parameter, Embedding embedding)
|
public static DiffusionModelParameter WithEmbedding(this DiffusionModelParameter parameter, Embedding embedding)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(embedding);
|
ArgumentNullException.ThrowIfNull(embedding);
|
||||||
@ -227,6 +246,8 @@ public static class DiffusionModelBuilderExtension
|
|||||||
return parameter;
|
return parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[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)
|
public static DiffusionModelParameter WithLLMPath(this DiffusionModelParameter parameter, string llmPath)
|
||||||
{
|
{
|
||||||
parameter.LLMPath = llmPath;
|
parameter.LLMPath = llmPath;
|
||||||
@ -234,6 +255,8 @@ public static class DiffusionModelBuilderExtension
|
|||||||
return parameter;
|
return parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[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)
|
public static DiffusionModelParameter WithLLMVisionPath(this DiffusionModelParameter parameter, string llmVisionPath)
|
||||||
{
|
{
|
||||||
parameter.LLMVisionPath = llmVisionPath;
|
parameter.LLMVisionPath = llmVisionPath;
|
||||||
|
|||||||
@ -99,6 +99,13 @@ public static class ImageGenerationParameterExtension
|
|||||||
return parameter;
|
return parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ImageGenerationParameter WithMinCfg(this ImageGenerationParameter parameter, float minCfg)
|
||||||
|
{
|
||||||
|
parameter.SampleParameter.Guidance.MinCfg = minCfg;
|
||||||
|
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
|
||||||
public static ImageGenerationParameter WithGuidance(this ImageGenerationParameter parameter, float guidance)
|
public static ImageGenerationParameter WithGuidance(this ImageGenerationParameter parameter, float guidance)
|
||||||
{
|
{
|
||||||
parameter.SampleParameter.Guidance.DistilledGuidance = guidance;
|
parameter.SampleParameter.Guidance.DistilledGuidance = guidance;
|
||||||
|
|||||||
@ -85,6 +85,13 @@ public static class VideoGenerationParameterExtension
|
|||||||
return parameter;
|
return parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static VideoGenerationParameter WithMinCfg(this VideoGenerationParameter parameter, float minCfg)
|
||||||
|
{
|
||||||
|
parameter.SampleParameter.Guidance.MinCfg = minCfg;
|
||||||
|
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
|
||||||
public static VideoGenerationParameter WithGuidance(this VideoGenerationParameter parameter, float guidance)
|
public static VideoGenerationParameter WithGuidance(this VideoGenerationParameter parameter, float guidance)
|
||||||
{
|
{
|
||||||
parameter.SampleParameter.Guidance.DistilledGuidance = guidance;
|
parameter.SampleParameter.Guidance.DistilledGuidance = guidance;
|
||||||
@ -189,6 +196,13 @@ public static class VideoGenerationParameterExtension
|
|||||||
return parameter;
|
return parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static VideoGenerationParameter WithHighNoiseMinCfg(this VideoGenerationParameter parameter, float minCfg)
|
||||||
|
{
|
||||||
|
parameter.HighNoiseSampleParameter.Guidance.MinCfg = minCfg;
|
||||||
|
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
|
||||||
public static VideoGenerationParameter WithHighNoiseGuidance(this VideoGenerationParameter parameter, float guidance)
|
public static VideoGenerationParameter WithHighNoiseGuidance(this VideoGenerationParameter parameter, float guidance)
|
||||||
{
|
{
|
||||||
parameter.HighNoiseSampleParameter.Guidance.DistilledGuidance = guidance;
|
parameter.HighNoiseSampleParameter.Guidance.DistilledGuidance = guidance;
|
||||||
|
|||||||
@ -3,7 +3,8 @@
|
|||||||
public sealed class GuidanceParameter
|
public sealed class GuidanceParameter
|
||||||
{
|
{
|
||||||
public float TxtCfg { get; set; } = 7.0f;
|
public float TxtCfg { get; set; } = 7.0f;
|
||||||
public float ImgCfg { get; set; } = float.PositiveInfinity;
|
public float ImgCfg { get; set; } = 7.0f;
|
||||||
|
public float MinCfg { get; set; } = 1.0f;
|
||||||
public float DistilledGuidance { get; set; } = 3.5f;
|
public float DistilledGuidance { get; set; } = 3.5f;
|
||||||
|
|
||||||
public SlgParameter Slg { get; } = new();
|
public SlgParameter Slg { get; } = new();
|
||||||
|
|||||||
@ -45,9 +45,9 @@ public sealed class ImageGenerationParameter
|
|||||||
public SampleParameter SampleParameter { get; internal init; } = new();
|
public SampleParameter SampleParameter { get; internal init; } = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// strength for noising/unnoising (default: 0.75)
|
/// strength for noising/unnoising (default: 0.7)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float Strength { get; set; } = 0.75f;
|
public float Strength { get; set; } = 0.7f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// RNG seed. use -1 for a random seed (default: -1)
|
/// RNG seed. use -1 for a random seed (default: -1)
|
||||||
@ -58,9 +58,9 @@ public sealed class ImageGenerationParameter
|
|||||||
|
|
||||||
public PhotoMakerParameter PhotoMaker { get; } = new();
|
public PhotoMakerParameter PhotoMaker { get; } = new();
|
||||||
|
|
||||||
public TilingParameter VaeTiling { get; internal init; } = new();
|
public TilingParameter VaeTiling { get; } = new();
|
||||||
|
|
||||||
public CacheParameter Cache { get; internal init; } = new();
|
public EasyCache EasyCache { get; } = new();
|
||||||
|
|
||||||
public List<Lora> Loras { get; } = [];
|
public List<Lora> Loras { get; } = [];
|
||||||
|
|
||||||
|
|||||||
@ -10,14 +10,14 @@ public sealed class SampleParameter
|
|||||||
public Scheduler Scheduler { get; set; } = Scheduler.Default;
|
public Scheduler Scheduler { get; set; } = Scheduler.Default;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// sampling method (default: Default)
|
/// sampling method (default: Euler_A)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Sampler SampleMethod { get; set; } = Sampler.Default;
|
public Sampler SampleMethod { get; set; } = Sampler.Euler_A;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// number of sample steps (default: 20)
|
/// number of sample steps (default: 25)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int SampleSteps { get; set; } = 20;
|
public int SampleSteps { get; set; } = 25;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// eta in DDIM, only for DDIM and TCD (default: 0)
|
/// eta in DDIM, only for DDIM and TCD (default: 0)
|
||||||
|
|||||||
@ -3,9 +3,9 @@
|
|||||||
public sealed class SlgParameter
|
public sealed class SlgParameter
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Layers to skip for SLG steps
|
/// Layers to skip for SLG steps: (default: [7,8,9])
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int[] Layers { get; set; } = [];
|
public int[] Layers { get; set; } = [7, 8, 9];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// SLG enabling point: (default: 0.01)
|
/// SLG enabling point: (default: 0.01)
|
||||||
|
|||||||
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
public sealed class TilingParameter
|
public sealed class TilingParameter
|
||||||
{
|
{
|
||||||
public bool IsEnabled { get; set; } = false;
|
public bool IsEnabled { get; set; }
|
||||||
|
|
||||||
public int TileSizeX { get; set; } = 0;
|
public int TileSizeX { get; set; }
|
||||||
public int TileSizeY { get; set; } = 0;
|
public int TileSizeY { get; set; }
|
||||||
public float TargetOverlap { get; set; } = 0.5f;
|
public float TargetOverlap { get; set; }
|
||||||
public float RelSizeX { get; set; } = 0;
|
public float RelSizeX { get; set; }
|
||||||
public float RelSizeY { get; set; } = 0;
|
public float RelSizeY { get; set; }
|
||||||
|
|
||||||
internal TilingParameter() { }
|
internal TilingParameter() { }
|
||||||
}
|
}
|
||||||
@ -21,27 +21,25 @@ public sealed class VideoGenerationParameter
|
|||||||
|
|
||||||
public IImage[]? ControlFrames { get; set; }
|
public IImage[]? ControlFrames { get; set; }
|
||||||
|
|
||||||
public int Width { get; set; } = 512;
|
public int Width { get; set; }
|
||||||
|
|
||||||
public int Height { get; set; } = 512;
|
public int Height { get; set; }
|
||||||
|
|
||||||
public SampleParameter SampleParameter { get; internal init; } = new();
|
public SampleParameter SampleParameter { get; internal init; } = new();
|
||||||
|
|
||||||
public SampleParameter HighNoiseSampleParameter { get; internal init; } = new() { SampleSteps = -1 };
|
public SampleParameter HighNoiseSampleParameter { get; internal init; } = new();
|
||||||
|
|
||||||
public float MoeBoundry { get; set; } = 0.875f;
|
public float MoeBoundry { get; set; }
|
||||||
|
|
||||||
public float Strength { get; set; } = 0.75f;
|
public float Strength { get; set; }
|
||||||
|
|
||||||
public long Seed { get; set; } = -1;
|
public long Seed { get; set; }
|
||||||
|
|
||||||
public int FrameCount { get; set; } = 6;
|
public int FrameCount { get; set; }
|
||||||
|
|
||||||
public float VaceStrength { get; set; } = 1.0f;
|
public float VaceStrength { get; set; }
|
||||||
|
|
||||||
public TilingParameter VaeTiling { get; internal init; } = new();
|
public EasyCache EasyCache { get; } = new();
|
||||||
|
|
||||||
public CacheParameter Cache { get; internal init; } = new();
|
|
||||||
|
|
||||||
public List<Lora> Loras { get; } = [];
|
public List<Lora> Loras { get; } = [];
|
||||||
|
|
||||||
|
|||||||
@ -1,89 +0,0 @@
|
|||||||
// ReSharper disable MemberCanBeMadeStatic.Global
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Runtime.InteropServices.Marshalling;
|
|
||||||
|
|
||||||
namespace StableDiffusion.NET;
|
|
||||||
|
|
||||||
[CustomMarshaller(typeof(CacheParameter), MarshalMode.ManagedToUnmanagedIn, typeof(CacheParameterMarshallerIn))]
|
|
||||||
[CustomMarshaller(typeof(CacheParameter), MarshalMode.ManagedToUnmanagedOut, typeof(CacheParameterMarshaller))]
|
|
||||||
[CustomMarshaller(typeof(CacheParameter), MarshalMode.ManagedToUnmanagedRef, typeof(CacheParameterMarshallerRef))]
|
|
||||||
internal static unsafe class CacheParameterMarshaller
|
|
||||||
{
|
|
||||||
public static CacheParameter ConvertToManaged(Native.Types.sd_cache_params_t unmanaged)
|
|
||||||
{
|
|
||||||
CacheParameter parameter = new()
|
|
||||||
{
|
|
||||||
Mode = unmanaged.mode,
|
|
||||||
ReuseThreshold = unmanaged.reuse_threshold,
|
|
||||||
StartPercent = unmanaged.start_percent,
|
|
||||||
EndPercent = unmanaged.end_percent,
|
|
||||||
ErrorDecayRate = unmanaged.error_decay_rate,
|
|
||||||
UseRelativeThreshold = unmanaged.use_relative_threshold == 1,
|
|
||||||
ResetErrorOnCompute = unmanaged.reset_error_on_compute == 1,
|
|
||||||
FnComputeBlocks = unmanaged.Fn_compute_blocks,
|
|
||||||
BnComputeBlocks = unmanaged.Bn_compute_blocks,
|
|
||||||
ResidualDiffThreshold = unmanaged.residual_diff_threshold,
|
|
||||||
MaxWarmupSteps = unmanaged.max_warmup_steps,
|
|
||||||
MaxCachedSteps = unmanaged.max_cached_steps,
|
|
||||||
MaxContinuousCachedSteps = unmanaged.max_continuous_cached_steps,
|
|
||||||
TaylorseerNDerivatives = unmanaged.taylorseer_n_derivatives,
|
|
||||||
TaylorseerSkipInterval = unmanaged.taylorseer_skip_interval,
|
|
||||||
ScmMask = AnsiStringMarshaller.ConvertToManaged(unmanaged.scm_mask),
|
|
||||||
ScmPolicyDynamic = unmanaged.scm_policy_dynamic == 1
|
|
||||||
};
|
|
||||||
|
|
||||||
return parameter;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal ref struct CacheParameterMarshallerIn
|
|
||||||
{
|
|
||||||
private Native.Types.sd_cache_params_t _cacheParams;
|
|
||||||
|
|
||||||
public void FromManaged(CacheParameter managed)
|
|
||||||
{
|
|
||||||
|
|
||||||
_cacheParams = new Native.Types.sd_cache_params_t
|
|
||||||
{
|
|
||||||
mode = managed.Mode,
|
|
||||||
reuse_threshold = managed.ReuseThreshold,
|
|
||||||
start_percent = managed.StartPercent,
|
|
||||||
end_percent = managed.EndPercent,
|
|
||||||
error_decay_rate = managed.ErrorDecayRate,
|
|
||||||
use_relative_threshold = (sbyte)(managed.UseRelativeThreshold ? 1 : 0),
|
|
||||||
reset_error_on_compute = (sbyte)(managed.ResetErrorOnCompute ? 1 : 0),
|
|
||||||
Fn_compute_blocks = managed.FnComputeBlocks,
|
|
||||||
Bn_compute_blocks = managed.BnComputeBlocks,
|
|
||||||
residual_diff_threshold = managed.ResidualDiffThreshold,
|
|
||||||
max_warmup_steps = managed.MaxWarmupSteps,
|
|
||||||
max_cached_steps = managed.MaxCachedSteps,
|
|
||||||
max_continuous_cached_steps = managed.MaxContinuousCachedSteps,
|
|
||||||
taylorseer_n_derivatives = managed.TaylorseerNDerivatives,
|
|
||||||
taylorseer_skip_interval = managed.TaylorseerSkipInterval,
|
|
||||||
scm_mask = AnsiStringMarshaller.ConvertToUnmanaged(managed.ScmMask),
|
|
||||||
scm_policy_dynamic = (sbyte)(managed.ScmPolicyDynamic ? 1 : 0)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public Native.Types.sd_cache_params_t ToUnmanaged() => _cacheParams;
|
|
||||||
|
|
||||||
public void Free()
|
|
||||||
{
|
|
||||||
AnsiStringMarshaller.Free(_cacheParams.scm_mask);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal ref struct CacheParameterMarshallerRef()
|
|
||||||
{
|
|
||||||
private CacheParameterMarshallerIn _inMarshaller = new();
|
|
||||||
private CacheParameter? _parameter;
|
|
||||||
|
|
||||||
public void FromManaged(CacheParameter managed) => _inMarshaller.FromManaged(managed);
|
|
||||||
public Native.Types.sd_cache_params_t ToUnmanaged() => _inMarshaller.ToUnmanaged();
|
|
||||||
|
|
||||||
public void FromUnmanaged(Native.Types.sd_cache_params_t unmanaged) => _parameter = ConvertToManaged(unmanaged);
|
|
||||||
public CacheParameter ToManaged() => _parameter ?? throw new NullReferenceException($"{nameof(FromUnmanaged)} needs to be called before ToManaged.");
|
|
||||||
|
|
||||||
public void Free() => _inMarshaller.Free();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.InteropServices.Marshalling;
|
using System.Runtime.InteropServices.Marshalling;
|
||||||
|
|
||||||
namespace StableDiffusion.NET;
|
namespace StableDiffusion.NET;
|
||||||
@ -24,6 +26,7 @@ internal static unsafe class DiffusionModelParameterMarshaller
|
|||||||
VaePath = AnsiStringMarshaller.ConvertToManaged(unmanaged.vae_path) ?? string.Empty,
|
VaePath = AnsiStringMarshaller.ConvertToManaged(unmanaged.vae_path) ?? string.Empty,
|
||||||
TaesdPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.taesd_path) ?? string.Empty,
|
TaesdPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.taesd_path) ?? string.Empty,
|
||||||
ControlNetPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.control_net_path) ?? string.Empty,
|
ControlNetPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.control_net_path) ?? string.Empty,
|
||||||
|
LoraModelDirectory = AnsiStringMarshaller.ConvertToManaged(unmanaged.lora_model_dir) ?? string.Empty,
|
||||||
StackedIdEmbeddingsDirectory = AnsiStringMarshaller.ConvertToManaged(unmanaged.photo_maker_path) ?? string.Empty,
|
StackedIdEmbeddingsDirectory = AnsiStringMarshaller.ConvertToManaged(unmanaged.photo_maker_path) ?? string.Empty,
|
||||||
TensorTypeRules = AnsiStringMarshaller.ConvertToManaged(unmanaged.tensor_type_rules) ?? string.Empty,
|
TensorTypeRules = AnsiStringMarshaller.ConvertToManaged(unmanaged.tensor_type_rules) ?? string.Empty,
|
||||||
VaeDecodeOnly = unmanaged.vae_decode_only == 1,
|
VaeDecodeOnly = unmanaged.vae_decode_only == 1,
|
||||||
@ -35,7 +38,6 @@ internal static unsafe class DiffusionModelParameterMarshaller
|
|||||||
Prediction = unmanaged.prediction,
|
Prediction = unmanaged.prediction,
|
||||||
LoraApplyMode = unmanaged.lora_apply_mode,
|
LoraApplyMode = unmanaged.lora_apply_mode,
|
||||||
OffloadParamsToCPU = unmanaged.offload_params_to_cpu == 1,
|
OffloadParamsToCPU = unmanaged.offload_params_to_cpu == 1,
|
||||||
EnableMmap = unmanaged.enable_mmap == 1,
|
|
||||||
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,
|
||||||
@ -43,13 +45,10 @@ internal static unsafe class DiffusionModelParameterMarshaller
|
|||||||
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,
|
||||||
CircularX = unmanaged.circular_x == 1,
|
|
||||||
CircularY = unmanaged.circular_y == 1,
|
|
||||||
ForceSdxlVaeConvScale = unmanaged.force_sdxl_vae_conv_scale == 1,
|
ForceSdxlVaeConvScale = unmanaged.force_sdxl_vae_conv_scale == 1,
|
||||||
ChromaUseDitMap = unmanaged.chroma_use_dit_mask == 1,
|
ChromaUseDitMap = unmanaged.chroma_use_dit_mask == 1,
|
||||||
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,
|
|
||||||
FlowShift = unmanaged.flow_shift
|
FlowShift = unmanaged.flow_shift
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -76,11 +75,39 @@ internal static unsafe class DiffusionModelParameterMarshaller
|
|||||||
|
|
||||||
public void FromManaged(DiffusionModelParameter managed)
|
public void FromManaged(DiffusionModelParameter managed)
|
||||||
{
|
{
|
||||||
_embeddings = (Native.Types.sd_embedding_t*)NativeMemory.Alloc((nuint)managed.Embeddings.Count, (nuint)Marshal.SizeOf<Native.Types.sd_embedding_t>());
|
//_embeddings = (Native.Types.sd_embedding_t*)NativeMemory.Alloc((nuint)managed.Embeddings.Count, (nuint)Marshal.SizeOf<Native.Types.sd_embedding_t>());
|
||||||
|
|
||||||
for (int i = 0; i < managed.Embeddings.Count; i++)
|
//for (int i = 0; i < managed.Embeddings.Count; i++)
|
||||||
|
//{
|
||||||
|
// Embedding embedding = managed.Embeddings[i];
|
||||||
|
|
||||||
|
// _embeddings[i] = new Native.Types.sd_embedding_t
|
||||||
|
// {
|
||||||
|
// name = AnsiStringMarshaller.ConvertToUnmanaged(embedding.Name),
|
||||||
|
// path = AnsiStringMarshaller.ConvertToUnmanaged(embedding.Path),
|
||||||
|
// };
|
||||||
|
//}
|
||||||
|
|
||||||
|
//HACK DarthAffe 25.12.2025 Workaround to support EmbeddingsDir till the next major release
|
||||||
|
List<Embedding> embeddings = [];
|
||||||
{
|
{
|
||||||
Embedding embedding = managed.Embeddings[i];
|
embeddings.AddRange(managed.Embeddings);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(managed.EmbeddingsDirectory) && Directory.Exists(managed.EmbeddingsDirectory))
|
||||||
|
{
|
||||||
|
foreach (string file in Directory.GetFiles(managed.EmbeddingsDirectory))
|
||||||
|
embeddings.Add(new Embedding(Path.GetFileNameWithoutExtension(file), file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { /**/ }
|
||||||
|
|
||||||
|
_embeddings = (Native.Types.sd_embedding_t*)NativeMemory.Alloc((nuint)embeddings.Count, (nuint)Marshal.SizeOf<Native.Types.sd_embedding_t>());
|
||||||
|
|
||||||
|
for (int i = 0; i < embeddings.Count; i++)
|
||||||
|
{
|
||||||
|
Embedding embedding = embeddings[i];
|
||||||
|
|
||||||
_embeddings[i] = new Native.Types.sd_embedding_t
|
_embeddings[i] = new Native.Types.sd_embedding_t
|
||||||
{
|
{
|
||||||
@ -88,6 +115,7 @@ internal static unsafe class DiffusionModelParameterMarshaller
|
|||||||
path = AnsiStringMarshaller.ConvertToUnmanaged(embedding.Path),
|
path = AnsiStringMarshaller.ConvertToUnmanaged(embedding.Path),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_ctxParams = new Native.Types.sd_ctx_params_t
|
_ctxParams = new Native.Types.sd_ctx_params_t
|
||||||
{
|
{
|
||||||
@ -103,8 +131,9 @@ internal static unsafe class DiffusionModelParameterMarshaller
|
|||||||
vae_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.VaePath),
|
vae_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.VaePath),
|
||||||
taesd_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.TaesdPath),
|
taesd_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.TaesdPath),
|
||||||
control_net_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.ControlNetPath),
|
control_net_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.ControlNetPath),
|
||||||
|
lora_model_dir = AnsiStringMarshaller.ConvertToUnmanaged(managed.LoraModelDirectory),
|
||||||
embeddings = _embeddings,
|
embeddings = _embeddings,
|
||||||
embedding_count = (uint)managed.Embeddings.Count,
|
embedding_count = (uint)embeddings.Count,
|
||||||
photo_maker_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.StackedIdEmbeddingsDirectory),
|
photo_maker_path = AnsiStringMarshaller.ConvertToUnmanaged(managed.StackedIdEmbeddingsDirectory),
|
||||||
tensor_type_rules = AnsiStringMarshaller.ConvertToUnmanaged(managed.TensorTypeRules),
|
tensor_type_rules = AnsiStringMarshaller.ConvertToUnmanaged(managed.TensorTypeRules),
|
||||||
vae_decode_only = (sbyte)(managed.VaeDecodeOnly ? 1 : 0),
|
vae_decode_only = (sbyte)(managed.VaeDecodeOnly ? 1 : 0),
|
||||||
@ -116,7 +145,6 @@ internal static unsafe class DiffusionModelParameterMarshaller
|
|||||||
prediction = managed.Prediction,
|
prediction = managed.Prediction,
|
||||||
lora_apply_mode = managed.LoraApplyMode,
|
lora_apply_mode = managed.LoraApplyMode,
|
||||||
offload_params_to_cpu = (sbyte)(managed.OffloadParamsToCPU ? 1 : 0),
|
offload_params_to_cpu = (sbyte)(managed.OffloadParamsToCPU ? 1 : 0),
|
||||||
enable_mmap = (sbyte)(managed.EnableMmap ? 1 : 0),
|
|
||||||
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),
|
||||||
@ -124,13 +152,10 @@ internal static unsafe class DiffusionModelParameterMarshaller
|
|||||||
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),
|
||||||
circular_x = (sbyte)(managed.CircularX ? 1 : 0),
|
|
||||||
circular_y = (sbyte)(managed.CircularY ? 1 : 0),
|
|
||||||
force_sdxl_vae_conv_scale = (sbyte)(managed.ForceSdxlVaeConvScale ? 1 : 0),
|
force_sdxl_vae_conv_scale = (sbyte)(managed.ForceSdxlVaeConvScale ? 1 : 0),
|
||||||
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),
|
|
||||||
flow_shift = managed.FlowShift
|
flow_shift = managed.FlowShift
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -139,6 +164,7 @@ internal static unsafe class DiffusionModelParameterMarshaller
|
|||||||
|
|
||||||
public void Free()
|
public void Free()
|
||||||
{
|
{
|
||||||
|
|
||||||
AnsiStringMarshaller.Free(_ctxParams.model_path);
|
AnsiStringMarshaller.Free(_ctxParams.model_path);
|
||||||
AnsiStringMarshaller.Free(_ctxParams.clip_l_path);
|
AnsiStringMarshaller.Free(_ctxParams.clip_l_path);
|
||||||
AnsiStringMarshaller.Free(_ctxParams.clip_g_path);
|
AnsiStringMarshaller.Free(_ctxParams.clip_g_path);
|
||||||
@ -149,6 +175,7 @@ internal static unsafe class DiffusionModelParameterMarshaller
|
|||||||
AnsiStringMarshaller.Free(_ctxParams.vae_path);
|
AnsiStringMarshaller.Free(_ctxParams.vae_path);
|
||||||
AnsiStringMarshaller.Free(_ctxParams.taesd_path);
|
AnsiStringMarshaller.Free(_ctxParams.taesd_path);
|
||||||
AnsiStringMarshaller.Free(_ctxParams.control_net_path);
|
AnsiStringMarshaller.Free(_ctxParams.control_net_path);
|
||||||
|
AnsiStringMarshaller.Free(_ctxParams.lora_model_dir);
|
||||||
AnsiStringMarshaller.Free(_ctxParams.photo_maker_path);
|
AnsiStringMarshaller.Free(_ctxParams.photo_maker_path);
|
||||||
AnsiStringMarshaller.Free(_ctxParams.tensor_type_rules);
|
AnsiStringMarshaller.Free(_ctxParams.tensor_type_rules);
|
||||||
|
|
||||||
|
|||||||
@ -38,8 +38,22 @@ internal static unsafe class ImageGenerationParameterMarshaller
|
|||||||
IdEmbedPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.pm_params.id_embed_path) ?? string.Empty,
|
IdEmbedPath = AnsiStringMarshaller.ConvertToManaged(unmanaged.pm_params.id_embed_path) ?? string.Empty,
|
||||||
StyleStrength = unmanaged.pm_params.style_strength,
|
StyleStrength = unmanaged.pm_params.style_strength,
|
||||||
},
|
},
|
||||||
VaeTiling = TilingParameterMarshaller.ConvertToManaged(unmanaged.vae_tiling_params),
|
VaeTiling =
|
||||||
Cache = CacheParameterMarshaller.ConvertToManaged(unmanaged.cache)
|
{
|
||||||
|
IsEnabled = unmanaged.vae_tiling_params.enabled == 1,
|
||||||
|
TileSizeX = unmanaged.vae_tiling_params.tile_size_x,
|
||||||
|
TileSizeY = unmanaged.vae_tiling_params.tile_size_y,
|
||||||
|
TargetOverlap = unmanaged.vae_tiling_params.target_overlap,
|
||||||
|
RelSizeX = unmanaged.vae_tiling_params.rel_size_x,
|
||||||
|
RelSizeY = unmanaged.vae_tiling_params.rel_size_y
|
||||||
|
},
|
||||||
|
EasyCache =
|
||||||
|
{
|
||||||
|
IsEnabled = unmanaged.easycache.enabled == 1,
|
||||||
|
ReuseThreshold = unmanaged.easycache.reuse_threshold,
|
||||||
|
StartPercent = unmanaged.easycache.start_percent,
|
||||||
|
EndPercent = unmanaged.easycache.end_percent
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int i = 0; i < unmanaged.lora_count; i++)
|
for (int i = 0; i < unmanaged.lora_count; i++)
|
||||||
@ -59,8 +73,6 @@ internal static unsafe class ImageGenerationParameterMarshaller
|
|||||||
internal ref struct ImageGenerationParameterMarshallerIn
|
internal ref struct ImageGenerationParameterMarshallerIn
|
||||||
{
|
{
|
||||||
private SampleParameterMarshaller.SampleParameterMarshallerIn _sampleParameterMarshaller = new();
|
private SampleParameterMarshaller.SampleParameterMarshallerIn _sampleParameterMarshaller = new();
|
||||||
private TilingParameterMarshaller.TilingParameterMarshallerIn _tilingParameterMarshaller = new();
|
|
||||||
private CacheParameterMarshaller.CacheParameterMarshallerIn _cacheParameterMarshaller = new();
|
|
||||||
private Native.Types.sd_img_gen_params_t _imgGenParams;
|
private Native.Types.sd_img_gen_params_t _imgGenParams;
|
||||||
|
|
||||||
private Native.Types.sd_image_t _initImage;
|
private Native.Types.sd_image_t _initImage;
|
||||||
@ -75,8 +87,6 @@ internal static unsafe class ImageGenerationParameterMarshaller
|
|||||||
public void FromManaged(ImageGenerationParameter managed)
|
public void FromManaged(ImageGenerationParameter managed)
|
||||||
{
|
{
|
||||||
_sampleParameterMarshaller.FromManaged(managed.SampleParameter);
|
_sampleParameterMarshaller.FromManaged(managed.SampleParameter);
|
||||||
_tilingParameterMarshaller.FromManaged(managed.VaeTiling);
|
|
||||||
_cacheParameterMarshaller.FromManaged(managed.Cache);
|
|
||||||
|
|
||||||
_initImage = managed.InitImage?.ToSdImage() ?? new Native.Types.sd_image_t();
|
_initImage = managed.InitImage?.ToSdImage() ?? new Native.Types.sd_image_t();
|
||||||
_controlNetImage = managed.ControlNet.Image?.ToSdImage() ?? new Native.Types.sd_image_t();
|
_controlNetImage = managed.ControlNet.Image?.ToSdImage() ?? new Native.Types.sd_image_t();
|
||||||
@ -119,6 +129,24 @@ internal static unsafe class ImageGenerationParameterMarshaller
|
|||||||
style_strength = managed.PhotoMaker.StyleStrength
|
style_strength = managed.PhotoMaker.StyleStrength
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Native.Types.sd_tiling_params_t tilingParams = new()
|
||||||
|
{
|
||||||
|
enabled = (sbyte)(managed.VaeTiling.IsEnabled ? 1 : 0),
|
||||||
|
tile_size_x = managed.VaeTiling.TileSizeX,
|
||||||
|
tile_size_y = managed.VaeTiling.TileSizeY,
|
||||||
|
target_overlap = managed.VaeTiling.TargetOverlap,
|
||||||
|
rel_size_x = managed.VaeTiling.RelSizeX,
|
||||||
|
rel_size_y = managed.VaeTiling.RelSizeY
|
||||||
|
};
|
||||||
|
|
||||||
|
Native.Types.sd_easycache_params_t easyCache = new()
|
||||||
|
{
|
||||||
|
enabled = (sbyte)(managed.EasyCache.IsEnabled ? 1 : 0),
|
||||||
|
reuse_threshold = managed.EasyCache.ReuseThreshold,
|
||||||
|
start_percent = managed.EasyCache.StartPercent,
|
||||||
|
end_percent = managed.EasyCache.EndPercent,
|
||||||
|
};
|
||||||
|
|
||||||
_imgGenParams = new Native.Types.sd_img_gen_params_t
|
_imgGenParams = new Native.Types.sd_img_gen_params_t
|
||||||
{
|
{
|
||||||
prompt = AnsiStringMarshaller.ConvertToUnmanaged(managed.Prompt),
|
prompt = AnsiStringMarshaller.ConvertToUnmanaged(managed.Prompt),
|
||||||
@ -138,10 +166,10 @@ internal static unsafe class ImageGenerationParameterMarshaller
|
|||||||
control_image = _controlNetImage,
|
control_image = _controlNetImage,
|
||||||
control_strength = managed.ControlNet.Strength,
|
control_strength = managed.ControlNet.Strength,
|
||||||
pm_params = photoMakerParams,
|
pm_params = photoMakerParams,
|
||||||
vae_tiling_params = _tilingParameterMarshaller.ToUnmanaged(),
|
vae_tiling_params = tilingParams,
|
||||||
cache = _cacheParameterMarshaller.ToUnmanaged(),
|
easycache = easyCache,
|
||||||
loras = _loras,
|
loras = _loras,
|
||||||
lora_count = (uint)managed.Loras.Count,
|
lora_count = (uint)managed.Loras.Count
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,8 +192,6 @@ internal static unsafe class ImageGenerationParameterMarshaller
|
|||||||
ImageHelper.Free(_pmIdImages, _imgGenParams.pm_params.id_images_count);
|
ImageHelper.Free(_pmIdImages, _imgGenParams.pm_params.id_images_count);
|
||||||
|
|
||||||
_sampleParameterMarshaller.Free();
|
_sampleParameterMarshaller.Free();
|
||||||
_tilingParameterMarshaller.Free();
|
|
||||||
_cacheParameterMarshaller.Free();
|
|
||||||
|
|
||||||
for (int i = 0; i < _imgGenParams.lora_count; i++)
|
for (int i = 0; i < _imgGenParams.lora_count; i++)
|
||||||
AnsiStringMarshaller.Free(_imgGenParams.loras[i].path);
|
AnsiStringMarshaller.Free(_imgGenParams.loras[i].path);
|
||||||
|
|||||||
@ -19,6 +19,7 @@ internal static unsafe class SampleParameterMarshaller
|
|||||||
{
|
{
|
||||||
TxtCfg = unmanaged.guidance.txt_cfg,
|
TxtCfg = unmanaged.guidance.txt_cfg,
|
||||||
ImgCfg = unmanaged.guidance.img_cfg,
|
ImgCfg = unmanaged.guidance.img_cfg,
|
||||||
|
MinCfg = unmanaged.guidance.min_cfg,
|
||||||
DistilledGuidance = unmanaged.guidance.distilled_guidance,
|
DistilledGuidance = unmanaged.guidance.distilled_guidance,
|
||||||
Slg =
|
Slg =
|
||||||
{
|
{
|
||||||
@ -73,6 +74,7 @@ internal static unsafe class SampleParameterMarshaller
|
|||||||
{
|
{
|
||||||
txt_cfg = managed.Guidance.TxtCfg,
|
txt_cfg = managed.Guidance.TxtCfg,
|
||||||
img_cfg = managed.Guidance.ImgCfg,
|
img_cfg = managed.Guidance.ImgCfg,
|
||||||
|
min_cfg = managed.Guidance.MinCfg,
|
||||||
distilled_guidance = managed.Guidance.DistilledGuidance,
|
distilled_guidance = managed.Guidance.DistilledGuidance,
|
||||||
slg = slg
|
slg = slg
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,63 +0,0 @@
|
|||||||
// ReSharper disable MemberCanBeMadeStatic.Global
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Runtime.InteropServices.Marshalling;
|
|
||||||
|
|
||||||
namespace StableDiffusion.NET;
|
|
||||||
|
|
||||||
[CustomMarshaller(typeof(TilingParameter), MarshalMode.ManagedToUnmanagedIn, typeof(TilingParameterMarshallerIn))]
|
|
||||||
[CustomMarshaller(typeof(TilingParameter), MarshalMode.ManagedToUnmanagedOut, typeof(TilingParameterMarshaller))]
|
|
||||||
[CustomMarshaller(typeof(TilingParameter), MarshalMode.ManagedToUnmanagedRef, typeof(TilingParameterMarshallerRef))]
|
|
||||||
internal static unsafe class TilingParameterMarshaller
|
|
||||||
{
|
|
||||||
public static TilingParameter ConvertToManaged(Native.Types.sd_tiling_params_t unmanaged)
|
|
||||||
{
|
|
||||||
TilingParameter parameter = new()
|
|
||||||
{
|
|
||||||
IsEnabled = unmanaged.enabled == 1,
|
|
||||||
TileSizeX = unmanaged.tile_size_x,
|
|
||||||
TileSizeY = unmanaged.tile_size_y,
|
|
||||||
TargetOverlap = unmanaged.target_overlap,
|
|
||||||
RelSizeX = unmanaged.rel_size_x,
|
|
||||||
RelSizeY = unmanaged.rel_size_y
|
|
||||||
};
|
|
||||||
|
|
||||||
return parameter;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal ref struct TilingParameterMarshallerIn
|
|
||||||
{
|
|
||||||
private Native.Types.sd_tiling_params_t _tilingParams;
|
|
||||||
|
|
||||||
public void FromManaged(TilingParameter managed)
|
|
||||||
{
|
|
||||||
_tilingParams = new Native.Types.sd_tiling_params_t
|
|
||||||
{
|
|
||||||
enabled = (sbyte)(managed.IsEnabled ? 1 : 0),
|
|
||||||
tile_size_x = managed.TileSizeX,
|
|
||||||
tile_size_y = managed.TileSizeY,
|
|
||||||
target_overlap = managed.TargetOverlap,
|
|
||||||
rel_size_x = managed.RelSizeX,
|
|
||||||
rel_size_y = managed.RelSizeY
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public Native.Types.sd_tiling_params_t ToUnmanaged() => _tilingParams;
|
|
||||||
|
|
||||||
public void Free() { }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal ref struct TilingParameterMarshallerRef()
|
|
||||||
{
|
|
||||||
private TilingParameterMarshallerIn _inMarshaller = new();
|
|
||||||
private TilingParameter? _parameter;
|
|
||||||
|
|
||||||
public void FromManaged(TilingParameter managed) => _inMarshaller.FromManaged(managed);
|
|
||||||
public Native.Types.sd_tiling_params_t ToUnmanaged() => _inMarshaller.ToUnmanaged();
|
|
||||||
|
|
||||||
public void FromUnmanaged(Native.Types.sd_tiling_params_t unmanaged) => _parameter = ConvertToManaged(unmanaged);
|
|
||||||
public TilingParameter ToManaged() => _parameter ?? throw new NullReferenceException($"{nameof(FromUnmanaged)} needs to be called before ToManaged.");
|
|
||||||
|
|
||||||
public void Free() => _inMarshaller.Free();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -29,8 +29,13 @@ internal static unsafe class VideoGenerationParameterMarshaller
|
|||||||
Seed = unmanaged.seed,
|
Seed = unmanaged.seed,
|
||||||
FrameCount = unmanaged.video_frames,
|
FrameCount = unmanaged.video_frames,
|
||||||
VaceStrength = unmanaged.vace_strength,
|
VaceStrength = unmanaged.vace_strength,
|
||||||
VaeTiling = TilingParameterMarshaller.ConvertToManaged(unmanaged.vae_tiling_params),
|
EasyCache =
|
||||||
Cache = CacheParameterMarshaller.ConvertToManaged(unmanaged.cache),
|
{
|
||||||
|
IsEnabled = unmanaged.easycache.enabled == 1,
|
||||||
|
ReuseThreshold = unmanaged.easycache.reuse_threshold,
|
||||||
|
StartPercent = unmanaged.easycache.start_percent,
|
||||||
|
EndPercent = unmanaged.easycache.end_percent
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int i = 0; i < unmanaged.lora_count; i++)
|
for (int i = 0; i < unmanaged.lora_count; i++)
|
||||||
@ -50,9 +55,7 @@ internal static unsafe class VideoGenerationParameterMarshaller
|
|||||||
internal ref struct VideoGenerationParameterMarshallerIn
|
internal ref struct VideoGenerationParameterMarshallerIn
|
||||||
{
|
{
|
||||||
private SampleParameterMarshaller.SampleParameterMarshallerIn _sampleParameterMarshaller = new();
|
private SampleParameterMarshaller.SampleParameterMarshallerIn _sampleParameterMarshaller = new();
|
||||||
private TilingParameterMarshaller.TilingParameterMarshallerIn _tilingParameterMarshaller = new();
|
|
||||||
private SampleParameterMarshaller.SampleParameterMarshallerIn _highNoiseSampleParameterMarshaller = new();
|
private SampleParameterMarshaller.SampleParameterMarshallerIn _highNoiseSampleParameterMarshaller = new();
|
||||||
private CacheParameterMarshaller.CacheParameterMarshallerIn _cacheParameterMarshaller = new();
|
|
||||||
private Native.Types.sd_vid_gen_params_t _vidGenParams;
|
private Native.Types.sd_vid_gen_params_t _vidGenParams;
|
||||||
|
|
||||||
private Native.Types.sd_image_t _initImage;
|
private Native.Types.sd_image_t _initImage;
|
||||||
@ -65,9 +68,7 @@ internal static unsafe class VideoGenerationParameterMarshaller
|
|||||||
public void FromManaged(VideoGenerationParameter managed)
|
public void FromManaged(VideoGenerationParameter managed)
|
||||||
{
|
{
|
||||||
_sampleParameterMarshaller.FromManaged(managed.SampleParameter);
|
_sampleParameterMarshaller.FromManaged(managed.SampleParameter);
|
||||||
_tilingParameterMarshaller.FromManaged(managed.VaeTiling);
|
|
||||||
_highNoiseSampleParameterMarshaller.FromManaged(managed.HighNoiseSampleParameter);
|
_highNoiseSampleParameterMarshaller.FromManaged(managed.HighNoiseSampleParameter);
|
||||||
_cacheParameterMarshaller.FromManaged(managed.Cache);
|
|
||||||
|
|
||||||
_initImage = managed.InitImage?.ToSdImage() ?? new Native.Types.sd_image_t();
|
_initImage = managed.InitImage?.ToSdImage() ?? new Native.Types.sd_image_t();
|
||||||
_endImage = managed.EndImage?.ToSdImage() ?? new Native.Types.sd_image_t();
|
_endImage = managed.EndImage?.ToSdImage() ?? new Native.Types.sd_image_t();
|
||||||
@ -85,6 +86,14 @@ internal static unsafe class VideoGenerationParameterMarshaller
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Native.Types.sd_easycache_params_t easyCache = new()
|
||||||
|
{
|
||||||
|
enabled = (sbyte)(managed.EasyCache.IsEnabled ? 1 : 0),
|
||||||
|
reuse_threshold = managed.EasyCache.ReuseThreshold,
|
||||||
|
start_percent = managed.EasyCache.StartPercent,
|
||||||
|
end_percent = managed.EasyCache.EndPercent,
|
||||||
|
};
|
||||||
|
|
||||||
_vidGenParams = new Native.Types.sd_vid_gen_params_t
|
_vidGenParams = new Native.Types.sd_vid_gen_params_t
|
||||||
{
|
{
|
||||||
prompt = AnsiStringMarshaller.ConvertToUnmanaged(managed.Prompt),
|
prompt = AnsiStringMarshaller.ConvertToUnmanaged(managed.Prompt),
|
||||||
@ -103,8 +112,7 @@ internal static unsafe class VideoGenerationParameterMarshaller
|
|||||||
seed = managed.Seed,
|
seed = managed.Seed,
|
||||||
video_frames = managed.FrameCount,
|
video_frames = managed.FrameCount,
|
||||||
vace_strength = managed.VaceStrength,
|
vace_strength = managed.VaceStrength,
|
||||||
vae_tiling_params = _tilingParameterMarshaller.ToUnmanaged(),
|
easycache = easyCache,
|
||||||
cache = _cacheParameterMarshaller.ToUnmanaged(),
|
|
||||||
loras = _loras,
|
loras = _loras,
|
||||||
lora_count = (uint)managed.Loras.Count
|
lora_count = (uint)managed.Loras.Count
|
||||||
};
|
};
|
||||||
@ -124,9 +132,7 @@ internal static unsafe class VideoGenerationParameterMarshaller
|
|||||||
ImageHelper.Free(_controlFrames, _vidGenParams.control_frames_size);
|
ImageHelper.Free(_controlFrames, _vidGenParams.control_frames_size);
|
||||||
|
|
||||||
_sampleParameterMarshaller.Free();
|
_sampleParameterMarshaller.Free();
|
||||||
_tilingParameterMarshaller.Free();
|
|
||||||
_highNoiseSampleParameterMarshaller.Free();
|
_highNoiseSampleParameterMarshaller.Free();
|
||||||
_cacheParameterMarshaller.Free();
|
|
||||||
|
|
||||||
for (int i = 0; i < _vidGenParams.lora_count; i++)
|
for (int i = 0; i < _vidGenParams.lora_count; i++)
|
||||||
AnsiStringMarshaller.Free(_vidGenParams.loras[i].path);
|
AnsiStringMarshaller.Free(_vidGenParams.loras[i].path);
|
||||||
|
|||||||
@ -15,8 +15,6 @@ using rng_type_t = RngType;
|
|||||||
using sample_method_t = Sampler;
|
using sample_method_t = Sampler;
|
||||||
using scheduler_t = Scheduler;
|
using scheduler_t = Scheduler;
|
||||||
using prediction_t = Prediction;
|
using prediction_t = Prediction;
|
||||||
using sd_cache_mode_t = CacheMode;
|
|
||||||
using sd_cache_params_t = CacheParameter;
|
|
||||||
using sd_ctx_params_t = DiffusionModelParameter;
|
using sd_ctx_params_t = DiffusionModelParameter;
|
||||||
using sd_ctx_t = Native.Types.sd_ctx_t;
|
using sd_ctx_t = Native.Types.sd_ctx_t;
|
||||||
using sd_image_t = Native.Types.sd_image_t;
|
using sd_image_t = Native.Types.sd_image_t;
|
||||||
@ -27,6 +25,7 @@ using sd_type_t = Quantization;
|
|||||||
using sd_vid_gen_params_t = VideoGenerationParameter;
|
using sd_vid_gen_params_t = VideoGenerationParameter;
|
||||||
using lora_apply_mode_t = LoraApplyMode;
|
using lora_apply_mode_t = LoraApplyMode;
|
||||||
using preview_t = Preview;
|
using preview_t = Preview;
|
||||||
|
using sd_easycache_params_t = Native.Types.sd_easycache_params_t;
|
||||||
using size_t = nuint;
|
using size_t = nuint;
|
||||||
using uint32_t = uint;
|
using uint32_t = uint;
|
||||||
using uint8_t = byte;
|
using uint8_t = byte;
|
||||||
@ -75,6 +74,7 @@ internal unsafe partial class Native
|
|||||||
public byte* vae_path;
|
public byte* vae_path;
|
||||||
public byte* taesd_path;
|
public byte* taesd_path;
|
||||||
public byte* control_net_path;
|
public byte* control_net_path;
|
||||||
|
public byte* lora_model_dir;
|
||||||
public sd_embedding_t* embeddings;
|
public sd_embedding_t* embeddings;
|
||||||
public uint32_t embedding_count;
|
public uint32_t embedding_count;
|
||||||
public byte* photo_maker_path;
|
public byte* photo_maker_path;
|
||||||
@ -88,7 +88,6 @@ internal unsafe partial class Native
|
|||||||
public prediction_t prediction;
|
public prediction_t prediction;
|
||||||
public lora_apply_mode_t lora_apply_mode;
|
public lora_apply_mode_t lora_apply_mode;
|
||||||
public sbyte offload_params_to_cpu;
|
public sbyte offload_params_to_cpu;
|
||||||
public sbyte enable_mmap;
|
|
||||||
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;
|
||||||
@ -96,13 +95,10 @@ internal unsafe partial class Native
|
|||||||
public sbyte tae_preview_only;
|
public sbyte tae_preview_only;
|
||||||
public sbyte diffusion_conv_direct;
|
public sbyte diffusion_conv_direct;
|
||||||
public sbyte vae_conv_direct;
|
public sbyte vae_conv_direct;
|
||||||
public sbyte circular_x;
|
|
||||||
public sbyte circular_y;
|
|
||||||
public sbyte force_sdxl_vae_conv_scale;
|
public sbyte force_sdxl_vae_conv_scale;
|
||||||
public sbyte chroma_use_dit_mask;
|
public sbyte chroma_use_dit_mask;
|
||||||
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 float flow_shift;
|
public float flow_shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,6 +126,7 @@ internal unsafe partial class Native
|
|||||||
{
|
{
|
||||||
public float txt_cfg;
|
public float txt_cfg;
|
||||||
public float img_cfg;
|
public float img_cfg;
|
||||||
|
public float min_cfg;
|
||||||
public float distilled_guidance;
|
public float distilled_guidance;
|
||||||
public sd_slg_params_t slg;
|
public sd_slg_params_t slg;
|
||||||
}
|
}
|
||||||
@ -157,25 +154,12 @@ internal unsafe partial class Native
|
|||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
internal struct sd_cache_params_t
|
internal struct sd_easycache_params_t
|
||||||
{
|
{
|
||||||
public sd_cache_mode_t mode;
|
public sbyte enabled;
|
||||||
public float reuse_threshold;
|
public float reuse_threshold;
|
||||||
public float start_percent;
|
public float start_percent;
|
||||||
public float end_percent;
|
public float end_percent;
|
||||||
public float error_decay_rate;
|
|
||||||
public sbyte use_relative_threshold;
|
|
||||||
public sbyte reset_error_on_compute;
|
|
||||||
public int Fn_compute_blocks;
|
|
||||||
public int Bn_compute_blocks;
|
|
||||||
public float residual_diff_threshold;
|
|
||||||
public int max_warmup_steps;
|
|
||||||
public int max_cached_steps;
|
|
||||||
public int max_continuous_cached_steps;
|
|
||||||
public int taylorseer_n_derivatives;
|
|
||||||
public int taylorseer_skip_interval;
|
|
||||||
public byte* scm_mask;
|
|
||||||
public sbyte scm_policy_dynamic;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
@ -210,7 +194,7 @@ internal unsafe partial class Native
|
|||||||
public float control_strength;
|
public float control_strength;
|
||||||
public sd_pm_params_t pm_params;
|
public sd_pm_params_t pm_params;
|
||||||
public sd_tiling_params_t vae_tiling_params;
|
public sd_tiling_params_t vae_tiling_params;
|
||||||
public sd_cache_params_t cache;
|
public sd_easycache_params_t easycache;
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
@ -234,8 +218,7 @@ internal unsafe partial class Native
|
|||||||
public int64_t seed;
|
public int64_t seed;
|
||||||
public int video_frames;
|
public int video_frames;
|
||||||
public float vace_strength;
|
public float vace_strength;
|
||||||
public sd_tiling_params_t vae_tiling_params;
|
public sd_easycache_params_t easycache;
|
||||||
public sd_cache_params_t cache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal struct sd_ctx_t;
|
internal struct sd_ctx_t;
|
||||||
@ -319,8 +302,8 @@ internal unsafe partial class Native
|
|||||||
[LibraryImport(LIB_NAME, EntryPoint = "str_to_lora_apply_mode")]
|
[LibraryImport(LIB_NAME, EntryPoint = "str_to_lora_apply_mode")]
|
||||||
internal static partial lora_apply_mode_t str_to_lora_apply_mode([MarshalAs(UnmanagedType.LPStr)] string str);
|
internal static partial lora_apply_mode_t str_to_lora_apply_mode([MarshalAs(UnmanagedType.LPStr)] string str);
|
||||||
|
|
||||||
[LibraryImport(LIB_NAME, EntryPoint = "sd_cache_params_init")]
|
[LibraryImport(LIB_NAME, EntryPoint = "sd_easycache_params_init")]
|
||||||
internal static partial void sd_cache_params_init([MarshalUsing(typeof(CacheParameterMarshaller))] ref sd_cache_params_t cache_params);
|
internal static partial void sd_easycache_params_init(ref sd_easycache_params_t easycache_params);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
@ -360,7 +343,7 @@ internal unsafe partial class Native
|
|||||||
internal static partial sample_method_t sd_get_default_sample_method(sd_ctx_t* sd_ctx);
|
internal static partial sample_method_t sd_get_default_sample_method(sd_ctx_t* sd_ctx);
|
||||||
|
|
||||||
[LibraryImport(LIB_NAME, EntryPoint = "sd_get_default_scheduler")]
|
[LibraryImport(LIB_NAME, EntryPoint = "sd_get_default_scheduler")]
|
||||||
internal static partial scheduler_t sd_get_default_scheduler(sd_ctx_t* sd_ctx, sample_method_t sample_method);
|
internal static partial scheduler_t sd_get_default_scheduler(sd_ctx_t* sd_ctx);
|
||||||
|
|
||||||
[LibraryImport(LIB_NAME, EntryPoint = "generate_image")]
|
[LibraryImport(LIB_NAME, EntryPoint = "generate_image")]
|
||||||
internal static partial sd_image_t* generate_image(sd_ctx_t* sd_ctx, [MarshalUsing(typeof(ImageGenerationParameterMarshaller))] in sd_img_gen_params_t sd_img_gen_params);
|
internal static partial sd_image_t* generate_image(sd_ctx_t* sd_ctx, [MarshalUsing(typeof(ImageGenerationParameterMarshaller))] in sd_img_gen_params_t sd_img_gen_params);
|
||||||
@ -402,8 +385,7 @@ internal unsafe partial class Native
|
|||||||
[MarshalAs(UnmanagedType.LPStr)] string vae_path,
|
[MarshalAs(UnmanagedType.LPStr)] string vae_path,
|
||||||
[MarshalAs(UnmanagedType.LPStr)] string output_path,
|
[MarshalAs(UnmanagedType.LPStr)] string output_path,
|
||||||
sd_type_t output_type,
|
sd_type_t output_type,
|
||||||
[MarshalAs(UnmanagedType.LPStr)] string tensor_type_rules,
|
[MarshalAs(UnmanagedType.LPStr)] string tensor_type_rules);
|
||||||
[MarshalAs(UnmanagedType.I1)] bool convert_name);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|||||||
@ -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 => "43a70e8";
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -51,14 +51,14 @@ public static unsafe class StableDiffusionCpp
|
|||||||
Native.sd_set_preview_callback(_previewCallback, mode, interval, denoised, noisy, null);
|
Native.sd_set_preview_callback(_previewCallback, mode, interval, denoised, noisy, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Convert(string modelPath, string vaePath, Quantization quantization, string outputPath, bool convertName = false, string tensorTypeRules = "")
|
public static void Convert(string modelPath, string vaePath, Quantization quantization, string outputPath, string tensorTypeRules = "")
|
||||||
{
|
{
|
||||||
ArgumentException.ThrowIfNullOrWhiteSpace(nameof(modelPath));
|
ArgumentException.ThrowIfNullOrWhiteSpace(nameof(modelPath));
|
||||||
ArgumentException.ThrowIfNullOrWhiteSpace(nameof(outputPath));
|
ArgumentException.ThrowIfNullOrWhiteSpace(nameof(outputPath));
|
||||||
ArgumentNullException.ThrowIfNull(vaePath);
|
ArgumentNullException.ThrowIfNull(vaePath);
|
||||||
if (!Enum.IsDefined(quantization)) throw new ArgumentOutOfRangeException(nameof(quantization));
|
if (!Enum.IsDefined(quantization)) throw new ArgumentOutOfRangeException(nameof(quantization));
|
||||||
|
|
||||||
Native.convert(modelPath, vaePath, outputPath, quantization, tensorTypeRules, convertName);
|
Native.convert(modelPath, vaePath, outputPath, quantization, tensorTypeRules);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetSystemInfo() => Native.sd_get_system_info();
|
public static string GetSystemInfo() => Native.sd_get_system_info();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user