mirror of
https://github.com/DarthAffe/StableDiffusion.NET.git
synced 2025-12-13 05:48:40 +00:00
36 lines
919 B
C#
36 lines
919 B
C#
using System;
|
|
using JetBrains.Annotations;
|
|
|
|
namespace StableDiffusion.NET;
|
|
|
|
[PublicAPI]
|
|
public static class QuantizedModelBuilderExtension
|
|
{
|
|
public static T WithoutMultithreading<T>(this T builder)
|
|
where T : IQuantizedModelBuilder
|
|
{
|
|
builder.Parameter.ThreadCount = 1;
|
|
|
|
return builder;
|
|
}
|
|
|
|
public static T WithMultithreading<T>(this T builder, int threadCount = 0)
|
|
where T : IQuantizedModelBuilder
|
|
{
|
|
ArgumentOutOfRangeException.ThrowIfLessThan(threadCount, 0, nameof(threadCount));
|
|
|
|
if (threadCount == 0) threadCount = Environment.ProcessorCount;
|
|
|
|
builder.Parameter.ThreadCount = threadCount;
|
|
|
|
return builder;
|
|
}
|
|
|
|
public static T WithQuantization<T>(this T builder, Quantization quantization)
|
|
where T : IQuantizedModelBuilder
|
|
{
|
|
builder.Parameter.Quantization = quantization;
|
|
|
|
return builder;
|
|
}
|
|
} |