Ionite
1 year ago
committed by
GitHub
21 changed files with 637 additions and 111 deletions
@ -0,0 +1,15 @@
|
||||
using StabilityMatrix.Core.Models; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Models; |
||||
|
||||
public interface IParametersLoadableState |
||||
{ |
||||
void LoadStateFromParameters(GenerationParameters parameters); |
||||
|
||||
GenerationParameters SaveStateToParameters(GenerationParameters parameters); |
||||
|
||||
public GenerationParameters SaveStateToParameters() |
||||
{ |
||||
return SaveStateToParameters(new GenerationParameters()); |
||||
} |
||||
} |
@ -0,0 +1,70 @@
|
||||
using System.Collections.Immutable; |
||||
using System.Diagnostics.CodeAnalysis; |
||||
using StabilityMatrix.Core.Models.Api.Comfy; |
||||
|
||||
namespace StabilityMatrix.Core.Helper; |
||||
|
||||
public static class GenerationParametersConverter |
||||
{ |
||||
private static readonly ImmutableDictionary< |
||||
string, |
||||
ComfySamplerScheduler |
||||
> ParamsToSamplerSchedulers = new Dictionary<string, ComfySamplerScheduler> |
||||
{ |
||||
["DPM++ 2M Karras"] = (ComfySampler.Dpmpp2M, ComfyScheduler.Karras), |
||||
["DPM++ SDE Karras"] = (ComfySampler.DpmppSde, ComfyScheduler.Karras), |
||||
["DPM++ 2M SDE Exponential"] = (ComfySampler.Dpmpp2MSde, ComfyScheduler.Exponential), |
||||
["DPM++ 2M SDE Karras"] = (ComfySampler.Dpmpp2MSde, ComfyScheduler.Karras), |
||||
["Euler a"] = (ComfySampler.EulerAncestral, ComfyScheduler.Normal), |
||||
["Euler"] = (ComfySampler.Euler, ComfyScheduler.Normal), |
||||
["LMS"] = (ComfySampler.LMS, ComfyScheduler.Normal), |
||||
["Heun"] = (ComfySampler.Heun, ComfyScheduler.Normal), |
||||
["DPM2"] = (ComfySampler.Dpm2, ComfyScheduler.Normal), |
||||
["DPM2 Karras"] = (ComfySampler.Dpm2, ComfyScheduler.Karras), |
||||
["DPM2 a"] = (ComfySampler.Dpm2Ancestral, ComfyScheduler.Normal), |
||||
["DPM2 a Karras"] = (ComfySampler.Dpm2Ancestral, ComfyScheduler.Karras), |
||||
["DPM++ 2S a"] = (ComfySampler.Dpmpp2SAncestral, ComfyScheduler.Normal), |
||||
["DPM++ 2S a Karras"] = (ComfySampler.Dpmpp2SAncestral, ComfyScheduler.Karras), |
||||
["DPM++ 2M"] = (ComfySampler.Dpmpp2M, ComfyScheduler.Normal), |
||||
["DPM++ SDE"] = (ComfySampler.DpmppSde, ComfyScheduler.Normal), |
||||
["DPM++ 2M SDE"] = (ComfySampler.Dpmpp2MSde, ComfyScheduler.Normal), |
||||
["DPM++ 3M SDE"] = (ComfySampler.Dpmpp3MSde, ComfyScheduler.Normal), |
||||
["DPM++ 3M SDE Karras"] = (ComfySampler.Dpmpp3MSde, ComfyScheduler.Karras), |
||||
["DPM++ 3M SDE Exponential"] = (ComfySampler.Dpmpp3MSde, ComfyScheduler.Exponential), |
||||
["DPM fast"] = (ComfySampler.DpmFast, ComfyScheduler.Normal), |
||||
["DPM adaptive"] = (ComfySampler.DpmAdaptive, ComfyScheduler.Normal), |
||||
["LMS Karras"] = (ComfySampler.LMS, ComfyScheduler.Karras), |
||||
["DDIM"] = (ComfySampler.DDIM, ComfyScheduler.Normal), |
||||
["UniPC"] = (ComfySampler.UniPC, ComfyScheduler.Normal), |
||||
}.ToImmutableDictionary(); |
||||
|
||||
private static readonly ImmutableDictionary< |
||||
ComfySamplerScheduler, |
||||
string |
||||
> SamplerSchedulersToParams = ParamsToSamplerSchedulers.ToImmutableDictionary( |
||||
x => x.Value, |
||||
x => x.Key |
||||
); |
||||
|
||||
/// <summary> |
||||
/// Converts a parameters-type string to a <see cref="ComfySamplerScheduler"/>. |
||||
/// </summary> |
||||
public static bool TryGetSamplerScheduler( |
||||
string parameters, |
||||
out ComfySamplerScheduler samplerScheduler |
||||
) |
||||
{ |
||||
return ParamsToSamplerSchedulers.TryGetValue(parameters, out samplerScheduler); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Converts a <see cref="ComfySamplerScheduler"/> to a parameters-type string. |
||||
/// </summary> |
||||
public static bool TryGetParameters( |
||||
ComfySamplerScheduler samplerScheduler, |
||||
[NotNullWhen(true)] out string? parameters |
||||
) |
||||
{ |
||||
return SamplerSchedulersToParams.TryGetValue(samplerScheduler, out parameters); |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
namespace StabilityMatrix.Core.Models.Api.Comfy; |
||||
|
||||
/// <summary> |
||||
/// Pair of <see cref="ComfySampler"/> and <see cref="ComfyScheduler"/> |
||||
/// </summary> |
||||
public readonly record struct ComfySamplerScheduler(ComfySampler Sampler, ComfyScheduler Scheduler) |
||||
{ |
||||
/// <inheritdoc /> |
||||
public bool Equals(ComfySamplerScheduler other) |
||||
{ |
||||
return Sampler.Equals(other.Sampler) && Scheduler.Equals(other.Scheduler); |
||||
} |
||||
|
||||
/// <inheritdoc /> |
||||
public override int GetHashCode() |
||||
{ |
||||
return HashCode.Combine(Sampler, Scheduler); |
||||
} |
||||
|
||||
// Implicit conversion from (ComfySampler, ComfyScheduler) |
||||
public static implicit operator ComfySamplerScheduler((ComfySampler, ComfyScheduler) tuple) |
||||
{ |
||||
return new ComfySamplerScheduler(tuple.Item1, tuple.Item2); |
||||
} |
||||
} |
Loading…
Reference in new issue