TCDModel<T>

Models & Types · AiDotNet.Diffusion.FastGeneration

Trajectory Consistency Distillation (TCD) model for high-quality few-step generation.

Inheritance: DiffusionModelBase<T> → LatentDiffusionModelBase<T> → TCDModel<T>

For Beginners

TCD improves upon LCM by being smarter about how it trains. While LCM focuses on individual steps, TCD considers the entire journey from noise to image. Adding a tiny bit of random noise during generation also helps — like how a slight shake of the camera can sometimes produce a more natural photo.

How It Works

TCD extends LCM by using a trajectory-aware loss that considers the entire denoising path, not just individual timestep consistency. Combined with a stochastic noise injection strategy during inference, TCD produces higher-quality images than LCM at the same step count, especially at 2-4 steps.

Reference: Zheng et al., “Trajectory Consistency Distillation”, 2024

Example

var options = new DiffusionModelOptions<float> { LatentChannels = 4, DefaultInferenceSteps = 4 };
var noise = Tensor<float>.CreateRandom(new[] { 1, 4, 64, 64 });
var trainX = Tensor<float>.CreateRandom(4, 8);
var trainY = Tensor<float>.CreateRandom(4, 2);
var result = new AiModelBuilder<float, Tensor<float>, Tensor<float>>()
    .ConfigureModel(new TCDModel<float>(options: options))
    .Build(trainX, trainY);
var generated = result.Predict(noise);

Constructors

Constructor Summary
TCDModel(NeuralNetworkArchitecture<T> architecture, DiffusionModelOptions<T> options, INoiseScheduler<T> scheduler, UNetNoisePredictor<T> predictor, StandardVAE<T> vae, IConditioningModule<T> conditioner, int? seed) Initializes a new TCD model.

Properties

Property Summary
IConditioningModule<T> Conditioner { get; }
INoisePredictor<T> NoisePredictor { get; }
IVAEModel<T> VAE { get; }
int LatentChannels { get; }

Methods

Method Summary
ModelMetadata<T> GetModelMetadata()