ControlNetXSModel<T>

Models & Types · AiDotNet.Diffusion.Control

ControlNet-XS model — lightweight control network with minimal parameters.

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

For Beginners

ControlNet-XS is ControlNet but much smaller and faster:

Key differences from ControlNet:

  • 50-100x fewer parameters than standard ControlNet
  • Faster inference with minimal quality loss
  • Simpler architecture: thin control encoder
  • Works with SD 1.5 and SDXL

Use ControlNet-XS when you need:

  • Spatial control with minimal compute overhead
  • Edge/depth/pose-guided generation
  • Mobile or edge deployment scenarios

How It Works

ControlNet-XS is a significantly smaller variant of ControlNet that achieves comparable control quality with only ~1% of the original ControlNet parameters. It uses a streamlined encoder that directly injects control signals into the base model.

Technical specifications:

  • Control encoder: lightweight copy with ~1% of base model parameters
  • Compatible: SD 1.5, SD 2.x, SDXL
  • Conditions: depth, canny edges, segmentation, pose
  • Injection: direct feature addition (no zero convolutions)

Reference: Zavadski et al., “ControlNet-XS”, 2024

Example

// Create ControlNet-XS for ultra-lightweight spatial control
var options = new DiffusionModelOptions<float>
{
    LatentChannels = 4,
    DefaultInferenceSteps = 20
};
            
// Generate with minimal compute overhead
var depthMap = Tensor<float>.CreateRandom(new[] { 1, 1, 512, 512 });
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 ControlNetXSModel<float>(options: options))
    .Build(trainX, trainY);
var prediction = result.Predict(depthMap);

Constructors

Constructor Summary
ControlNetXSModel(NeuralNetworkArchitecture<T> architecture, DiffusionModelOptions<T> options, INoiseScheduler<T> scheduler, UNetNoisePredictor<T> unet, UNetNoisePredictor<T> controlEncoder, StandardVAE<T> vae, IConditioningModule<T> conditioner, int? seed)

Properties

Property Summary
IConditioningModule<T> Conditioner { get; }
INoisePredictor<T> NoisePredictor { get; }
IVAEModel<T> VAE { get; }
UNetNoisePredictor<T> ControlEncoder { get; } Gets the lightweight control encoder.
int LatentChannels { get; }

Methods

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

Fields

Field Summary
int DefaultHeight
int DefaultWidth