TrainingEfficientLCM<T>

Models & Types · AiDotNet.Diffusion.FastGeneration

Training-Efficient Latent Consistency Model for resource-constrained LCM distillation.

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

For Beginners

Training LCM requires expensive GPU compute — typically 32 A100 hours. This variant uses LoRA (lightweight adapters) and other efficiency tricks to reduce that to about 3 A100 hours, making it feasible for researchers and hobbyists to create their own fast-generation models from any Stable Diffusion checkpoint.

How It Works

Reduces the computational cost of LCM distillation by using LoRA-based fine-tuning instead of full model training, memory-efficient gradient checkpointing, and a simplified consistency loss. Achieves comparable quality to full LCM with 10x less training compute.

Reference: Based on LCM-LoRA (Luo et al., 2023) with additional training optimizations

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 TrainingEfficientLCM<float>(options: options))
    .Build(trainX, trainY);
var generated = result.Predict(noise);

Constructors

Constructor Summary
TrainingEfficientLCM(NeuralNetworkArchitecture<T> architecture, DiffusionModelOptions<T> options, INoiseScheduler<T> scheduler, UNetNoisePredictor<T> predictor, StandardVAE<T> vae, IConditioningModule<T> conditioner, int loraRank, int? seed) Initializes a new Training-Efficient LCM.

Properties

Property Summary
IConditioningModule<T> Conditioner { get; }
INoisePredictor<T> NoisePredictor { get; }
IVAEModel<T> VAE { get; }
int LatentChannels { get; }
int LoRArank { get; } Gets the LoRA rank used for efficient fine-tuning.

Methods

Method Summary
ModelMetadata<T> GetModelMetadata()