AiModelResultDiffusionExtensions

Helpers & Utilities · AiDotNet.Diffusion.Extensions

Model-specific inference extensions on AiModelResult for the diffusion family (DDPM, LDM, Stable Diffusion, DiT, etc.). Part of #1836.

How It Works

See AiModelResultRadianceFieldExtensions for the full design rationale — extension methods live in the same assembly as AiModelResult so they access internal Model without exposing it, keeping IP-protection intact while giving callers discoverable domain APIs.

Methods

Method Summary
Task<Tensor<T>> GenerateAsync(AiModelResult<T, TInput, TOutput> result, int[] shape, int numInferenceSteps, int? seed, IProgress<double> progress, CancellationToken cancellationToken) Async diffusion sampling — dispatches the atomic Generate call onto the thread pool so the caller isn’t blocked.
Tensor<T> DecodeFromLatent(AiModelResult<T, TInput, TOutput> result, Tensor<T> latent) Decodes a latent tensor back into image pixels via the VAE decoder of a latent-diffusion model.
Tensor<T> EncodeToLatent(AiModelResult<T, TInput, TOutput> result, Tensor<T> image, bool sampleMode) Encodes an image tensor into the latent space of a latent-diffusion model (LDM / Stable Diffusion).
Tensor<T> Generate(AiModelResult<T, TInput, TOutput> result, int[] shape, int numInferenceSteps, int? seed) Generates new samples by iteratively denoising from random noise.
Tensor<T> PredictNoise(AiModelResult<T, TInput, TOutput> result, Tensor<T> noisySample, int timestep) Predicts the noise present in a partially-noised sample at a given timestep.
Tensor<T>[] GenerateBatch(AiModelResult<T, TInput, TOutput> result, int[] shape, int batchCount, int numInferenceSteps, int[] seeds) Batched Generate: generates batchCount independent samples.