LatentConsistencyModel<T>

Models & Types · AiDotNet.Diffusion.FastGeneration

Latent Consistency Model (LCM) for fast few-step image generation.

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

For Beginners

LCM makes Stable Diffusion much faster:

How LCM works:

  1. Starts with a pre-trained SD model (1.5, 2.1, or SDXL)
  2. Uses consistency distillation to learn a shortcut through the denoising process
  3. The distilled model can skip most denoising steps (2-8 instead of 20-50)
  4. LCM-LoRA allows applying this speedup to ANY fine-tuned model

Key characteristics:

  • 2-8 step generation (vs 20-50 for standard SD)
  • Based on consistency distillation (not adversarial training)
  • Lower guidance scales needed (1.0-2.0 vs 7.5)
  • LCM-LoRA variant: lightweight adapter compatible with any SD fine-tune
  • Compatible with SD 1.5, SD 2.1, and SDXL base models

Advantages:

  • 5-10x faster than standard SD
  • LCM-LoRA is composable with other LoRAs
  • Maintains good quality at 4 steps
  • Open-source and widely available

Limitations:

  • Slightly lower diversity than full-step models
  • Very low step counts (1-2) may show artifacts
  • Lower guidance scales may reduce prompt adherence

How It Works

Latent Consistency Models (LCM) distill pre-trained latent diffusion models into fast inference models that can generate high-quality images in 2-8 steps. LCM uses consistency distillation in latent space to learn a one-step mapping.

Technical specifications:

  • Architecture: Consistency-distilled latent diffusion model
  • Base: SD 1.5/2.1/SDXL U-Net with consistency training
  • Distillation: Latent Consistency Distillation (LCD)
  • Optimal steps: 4 (good quality/speed tradeoff)
  • Guidance scale: 1.0-2.0 (lower than standard SD)
  • Scheduler: LCM scheduler with skipping timesteps
  • LCM-LoRA: ~67M adapter parameters for any SD fine-tune

Reference: Luo et al., “Latent Consistency Models: Synthesizing High-Resolution Images with Few-Step Inference”, 2023

Example

// Create LCM for fast generation
var lcm = new LatentConsistencyModel<float>();
            
// Generate in just 4 steps
var image = lcm.GenerateFromText(
    prompt: "A beautiful landscape painting",
    width: 512,
    height: 512,
    numInferenceSteps: 4,
    guidanceScale: 1.5,
    seed: 42);

Constructors

Constructor Summary
LatentConsistencyModel(NeuralNetworkArchitecture<T> architecture, DiffusionModelOptions<T> options, INoiseScheduler<T> scheduler, UNetNoisePredictor<T> unet, StandardVAE<T> vae, IConditioningModule<T> conditioner, string baseModel, int? seed) Initializes a new instance of LatentConsistencyModel with full customization support.

Properties

Property Summary
IConditioningModule<T> Conditioner { get; }
INoisePredictor<T> NoisePredictor { get; }
IVAEModel<T> VAE { get; }
int LatentChannels { get; }
string BaseModel { get; } Counts the flat-API parameter surface (predictor + VAE).

Methods

Method Summary
ModelMetadata<T> GetModelMetadata()
Tensor<T> GenerateFromText(string prompt, string negativePrompt, int width, int height, int numInferenceSteps, double? guidanceScale, int? seed)
Tensor<T> ImageToImage(Tensor<T> inputImage, string prompt, string negativePrompt, double strength, int numInferenceSteps, double? guidanceScale, int? seed)

Fields

Field Summary
int DefaultHeight Default image height for LCM (matches SD 1.5).
int DefaultWidth Default image width for LCM (matches SD 1.5).