TensorStack.StableDiffusionCpp
0.15.0
Prefix Reserved
dotnet add package TensorStack.StableDiffusionCpp --version 0.15.0
NuGet\Install-Package TensorStack.StableDiffusionCpp -Version 0.15.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TensorStack.StableDiffusionCpp" Version="0.15.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TensorStack.StableDiffusionCpp" Version="0.15.0" />
<PackageReference Include="TensorStack.StableDiffusionCpp" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TensorStack.StableDiffusionCpp --version 0.15.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TensorStack.StableDiffusionCpp, 0.15.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TensorStack.StableDiffusionCpp@0.15.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TensorStack.StableDiffusionCpp&version=0.15.0
#tool nuget:?package=TensorStack.StableDiffusionCpp&version=0.15.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
TensorStack.StableDiffusionCpp
Basic .NET Wrapper API for stable-diffusion.cpp
Nuget Package
Image Example
Generate an image using Krea2 Turbo
using (var backend = new StableDiffusionBackend(VendorType.Nvidia))
{
await backend.InitializeAsync();
using (var pipeline = new StableDiffusionPipeline(backend))
{
var device = pipeline.Devices.FirstOrDefault(x => x.Type == DeviceType.GPU);
await pipeline.LoadAsync(new StableDiffusionOptions
{
Backend = device.Backend,
ParamsBackend = "*=cpu",
LlmPath = "Qwen3VL-4B-Instruct-Q8_0.gguf",
VaePath = "diffusion_pytorch_model.safetensors",
DiffusionModelPath = "Krea-2-Turbo-Q8_0.gguf",
});
var defaultOptions = pipeline.DefaultImageOptions;
var options = defaultOptions with
{
Prompt = "cute cat",
Width = 1024,
Height = 1024,
Seed = 420,
SampleParameters = defaultOptions.SampleParameters with
{
TxtCfg = 1,
SampleSteps = 8,
SampleMethod = SamplerType.Euler,
}
};
var result = await pipeline.GenerateImageAsync(options);
await result.SaveAsync("OutputImage.png");
}
}
Video Example
Generate a video using MiniMax-H3
using (var backend = new StableDiffusionBackend(VendorType.Nvidia))
{
await backend.InitializeAsync();
using (var pipeline = new StableDiffusionPipeline(backend))
{
var device = pipeline.Devices.FirstOrDefault(x => x.Type == DeviceType.GPU);
await pipeline.LoadAsync(new StableDiffusionOptions
{
Backend = device.Backend,
ParamsBackend = "*=cpu",
LlmPath = "qwen3vl_32b_minimax_h3-Q4_K_M.gguf",
VaePath = "minimax_h3_video_vae_fp16.safetensors",
AudioVaePath = "minimax_h3_audio_vae_fp32.safetensors",
DiffusionModelPath = "minimax_h3_fl2va_pruned-Q8_0.gguf",
});
var defaultOptions = pipeline.DefaultVideoOptions;
var options = defaultOptions with
{
Prompt = "cute cat",
Width = 864,
Height = 480,
Fps = 24,
Seed = 420,
VideoFrames = 56,
SampleParameters = defaultOptions.SampleParameters with
{
TxtCfg = 1,
SampleSteps = 20,
SampleMethod = SamplerType.Euler,
}
};
var videoSequence = await pipeline.GenerateVideoAsync(options);
await videoSequence.SaveAsync("OutputVideo.mp4");
}
}
Upscale Example
Upscale Images, Videos or Inline with generations
// Upscale Image
using (var backend = new StableDiffusionBackend(VendorType.Nvidia))
{
await backend.InitializeAsync();
using (var pipeline = new StableDiffusionPipeline(backend))
{
var device = pipeline.Devices.FirstOrDefault(x => x.Type == DeviceType.GPU);
await pipeline.LoadAsync(new UpscaleOptions
{
Backend = device.Backend,
ModelPath = "2xPSNR.gguf"
});
var inputImage = new ImageInput("InputImage.png");
var resultImage = await pipeline.UpscaleImageAsync(inputImage);
await resultImage.SaveAsync("OutputImage.png");
}
}
// Upscale Video Frames
using (var backend = new StableDiffusionBackend(VendorType.Nvidia))
{
await backend.InitializeAsync();
using (var pipeline = new StableDiffusionPipeline(backend))
{
var device = pipeline.Devices.FirstOrDefault(x => x.Type == DeviceType.GPU);
await pipeline.LoadAsync(new UpscaleOptions
{
Backend = device.Backend,
ModelPath = "2xPSNR.gguf"
});
var inputVideo = new VideoInput("InputVideo.mp4");
var videoFrames = await pipeline.UpscaleFramesAsync(inputVideo.Frames);
var resultVideo = new VideoSequence(videoFrames, inputVideo.FrameRate, inputVideo.Audio);
await resultVideo.SaveAsync("OutputFrames.mp4");
}
}
// Upscale Video
using (var backend = new StableDiffusionBackend(VendorType.Nvidia))
{
await backend.InitializeAsync();
using (var pipeline = new StableDiffusionPipeline(backend))
{
var device = pipeline.Devices.FirstOrDefault(x => x.Type == DeviceType.GPU);
await pipeline.LoadAsync(new UpscaleOptions
{
Backend = device.Backend,
ScaleFactor = 2,
VaePath = "seedvr2_ema_vae_fp16.safetensors",
DiffusionModelPath = "seedvr2_3b_fp16.safetensors"
});
var options = new UpscaleVideoOptions
{
Seed = 42,
TemporalChunkSize = 1
};
var inputVideo = new VideoInput("InputVideo.mp4");
var resultVideo = await pipeline.UpscaleVideoAsync(inputVideo, options);
await resultVideo.SaveAsync("OutputVideo.mp4");
}
}
// Inline StableDiffusion + Upscale
using (var backend = new StableDiffusionBackend(VendorType.Nvidia))
{
await backend.InitializeAsync();
using (var pipeline = new StableDiffusionPipeline(backend))
{
var device = pipeline.Devices.FirstOrDefault(x => x.Type == DeviceType.GPU);
var stableDiffusionOptions = new StableDiffusionOptions
{
Backend = device.Backend,
ParamsBackend = "*=cpu",
LlmPath = "Qwen3VL-4B-Instruct-Q8_0.gguf",
VaePath = "diffusion_pytorch_model.safetensors",
DiffusionModelPath = "Krea-2-Turbo-Q8_0.gguf",
};
var upscaleOptions = new UpscaleOptions
{
Backend = device.Backend,
ModelPath = "2xPSNR.gguf"
};
await pipeline.LoadAsync(stableDiffusionOptions, upscaleOptions);
var defaultOptions = pipeline.DefaultImageOptions;
var options = defaultOptions with
{
Prompt = "cute cat",
Width = 1024,
Height = 1024,
Seed = 420,
SampleParameters = defaultOptions.SampleParameters with
{
TxtCfg = 1,
SampleSteps = 8,
SampleMethod = SamplerType.Euler,
}
};
var result = await pipeline.GenerateImageAsync(options);
await result.SaveAsync("OutputImage.png");
}
}
StableDiffusion.cpp Backends
The StableDiffusionBackend class to manage StableDiffusion.cpp backend environments. You can initialize a backend using built-in vendor configurations or provide a custom configuration to control its version, installation directory, and requirements.
Basic Documentation
// Create a backend using built-in vendor defaults.
var backend = new StableDiffusionBackend(VendorType.Nvidia);
// Initialize the environment.
// Attempts to load an existing environment, update it if loading
// fails, or create a new environment if necessary.
bool initialized = await backend.InitializeAsync();
// Load the environment directly.
bool loaded = await backend.LoadAsync();
// Perform a specific setup operation.
bool updated = await backend.SetupAsync(BackendStatus.Update);
// Delete the backend environment.
bool deleted = await backend.DeleteAsync();
// Check whether the backend environment exists.
bool exists = backend.Exists();
// ============================================================
// Backend Setup Operations
// ============================================================
// Create - Create a new environment.
// Load - Load operation status.
// Update - Update an existing environment.
// Rebuild - Rebuild the environment.
// Reinstall - Reinstall the environment.
bool success = await backend.SetupAsync(BackendStatus.Create);
// ============================================================
// Custom Configuration
// ============================================================
// Name - Backend name
// Version - StableDiffusionCpp version
// Directory - Backend directory
// Requirements - List of download requirements.
// Define a custom backend configuration.
var customConfiguration = new BackendConfig
{
Name = "vulkan",
Version = "1106",
Directory = "StableDiffusionCpp",
Requirements =
[
"https://github.com/leejet/stable-diffusion.cpp/releases/download/master-1106-532d2c1/sd-master-532d2c1-bin-win-vulkan-x64.zip"
]
};
// Create a backend using the custom configuration.
var customBackend = new StableDiffusionBackend(customConfiguration);
// ============================================================
// Built-in Configuration Customization
// ============================================================
// Retrieve a built-in vendor configuration.
BackendConfig configuration = StableDiffusionBackend.GetConfig(VendorType.Nvidia);
// Create a modified copy of the configuration.
// BackendConfig is a record, so the original remains unchanged.
var modifiedConfiguration = configuration with
{
Name = "vulkan-test",
Directory = "My Location"
};
// Create a backend using the modified configuration.
var modifiedBackend = new StableDiffusionBackend(modifiedConfiguration);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows10.0.17763 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0-windows10.0.17763
- Microsoft.Extensions.Logging (>= 11.0.0)
- TensorStack.Media (>= 0.15.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.15.0 | 47 | 11/18/2026 |
| 0.14.14 | 76 | 11/17/2026 |
| 0.14.13 | 90 | 11/16/2026 |
| 0.14.12 | 95 | 11/15/2026 |
| 0.14.11 | 86 | 11/15/2026 |
| 0.14.10 | 95 | 11/14/2026 |
| 0.14.9 | 94 | 11/13/2026 |
| 0.14.8 | 88 | 11/10/2026 |
| 0.14.7 | 93 | 11/8/2026 |
| 0.14.6 | 86 | 11/5/2026 |
| 0.14.5 | 110 | 11/1/2026 |
| 0.14.4 | 166 | 10/29/2026 |
| 0.14.3 | 103 | 10/28/2026 |
| 0.14.2 | 136 | 10/20/2026 |
| 0.14.1 | 115 | 10/16/2026 |
| 0.13.13 | 107 | 10/11/2026 |
| 0.13.12 | 101 | 10/10/2026 |
| 0.13.10 | 125 | 10/6/2026 |
| 0.13.9 | 104 | 10/5/2026 |
| 0.13.8 | 115 | 10/4/2026 |
Loading failed