SD3InpaintingModel<T>

Models & Types · AiDotNet.Diffusion.ImageEditing

Stable Diffusion 3 inpainting model using MMDiT architecture for mask-guided generation.

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

For Beginners

This is Stable Diffusion 3’s inpainting mode. SD3 uses a modern transformer architecture (instead of U-Net) and three text encoders for better prompt understanding. It produces high-quality inpainting results with excellent text following.

How It Works

Adapts the SD3 MMDiT (Multimodal Diffusion Transformer) architecture for inpainting. Uses 16-channel latent space with the MMDiT-X noise predictor for high-quality mask-conditioned generation with improved text understanding via triple text encoders.

Technical specifications (SD3 Medium):

  • Architecture: MMDiT-X (Multimodal Diffusion Transformer with cross-attention)
  • Hidden size: 1536, 24 joint attention layers, 24 heads
  • Text encoders: CLIP-L (768-dim) + CLIP-G (1280-dim) + T5-XXL (4096-dim)
  • Latent space: 16 channels with rectified flow training
  • Prediction type: v-prediction (velocity)
  • Resolution: Up to 1024x1024 (aspect-ratio buckets)

Reference: Esser et al., “Scaling Rectified Flow Transformers for High-Resolution Image Synthesis”, ICML 2024

Example

var options = new DiffusionModelOptions<float> { LatentChannels = 16, DefaultInferenceSteps = 28 };
var maskedInput = Tensor<float>.CreateRandom(new[] { 1, 16, 128, 128 });
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 SD3InpaintingModel<float>(options: options))
    .Build(trainX, trainY);
var inpainted = result.Predict(maskedInput);

Constructors

Constructor Summary
SD3InpaintingModel(NeuralNetworkArchitecture<T> architecture, DiffusionModelOptions<T> options, INoiseScheduler<T> scheduler, MMDiTXNoisePredictor<T> predictor, StandardVAE<T> vae, IConditioningModule<T> conditioner, int? seed)

Properties

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

Methods

Method Summary
ModelMetadata<T> GetModelMetadata()