SDXLModel<T>
Models & Types · AiDotNet.Diffusion.TextToImage
Stable Diffusion XL (SDXL) model for high-resolution image generation.
Inheritance: DiffusionModelBase<T> → LatentDiffusionModelBase<T> → SDXLModel<T>
For Beginners
SDXL is like Stable Diffusion 2.0 but significantly upgraded:
Key improvements over SD 1.5/2.0:
- 4x larger U-Net (2.6B vs 865M parameters)
- Dual text encoders (better prompt understanding)
- Native 1024x1024 resolution (vs 512x512)
- Optional refiner model for enhanced details
How SDXL works:
- Your prompt goes through TWO text encoders (CLIP + OpenCLIP)
- These embeddings guide a much larger U-Net during denoising
- The base model generates at 1024x1024
- (Optional) A refiner model enhances fine details
Example prompt flow: “A majestic dragon” -> [CLIP] + [OpenCLIP] -> Combined embedding -> Large U-Net denoises -> 1024x1024 image -> (Optional) Refiner -> Enhanced details
Use SDXL when you need:
- High resolution output
- Better text rendering in images
- More detailed and coherent images
- Following complex prompts accurately
How It Works
SDXL is Stability AI’s flagship text-to-image model, designed for high-quality 1024x1024 image generation with improved prompt understanding and visual fidelity compared to earlier Stable Diffusion versions.
Technical specifications:
- Base model: 2.6B parameter U-Net
- Text encoders: CLIP ViT-L/14 + OpenCLIP ViT-bigG/14
- Native resolution: 1024x1024
- Latent space: 4 channels, 8x spatial downsampling
- Guidance scale: 5.0-9.0 recommended (7.5 default)
- Scheduler: DDPM/DPM++/Euler with 20-50 steps
Architecture details:
- Micro-conditioning: Size and crop coordinates for multi-aspect training
- Dual text encoding: Concatenated CLIP + OpenCLIP embeddings
- Channel multipliers: [1, 2, 4, 4] (vs [1, 2, 4, 8] in SD 2.x)
- Cross-attention dimension: 2048 (vs 1024 in SD 1.x)
Example
// Create an SDXL model
var sdxl = new SDXLModel<float>();
// Generate a high-resolution image
var image = sdxl.GenerateFromText(
prompt: "A majestic dragon perched on a mountain peak at sunset, highly detailed",
negativePrompt: "blurry, low quality, distorted",
width: 1024,
height: 1024,
numInferenceSteps: 30,
guidanceScale: 7.5,
seed: 42);
// Generate with micro-conditioning for aspect ratio
var wideImage = sdxl.GenerateWithMicroCondition(
prompt: "Panoramic landscape with mountains and lake",
width: 1536,
height: 640,
originalWidth: 1536,
originalHeight: 640,
cropTop: 0,
cropLeft: 0);
// Use the refiner for enhanced details
if (sdxl.SupportsRefiner)
{
var refined = sdxl.RefineImage(image, "enhance details");
}
Constructors
| Constructor | Summary |
|---|---|
SDXLModel(NeuralNetworkArchitecture<T> architecture, DiffusionModelOptions<T> options, INoiseScheduler<T> scheduler, UNetNoisePredictor<T> unet, StandardVAE<T> vae, IConditioningModule<T> conditioner1, IConditioningModule<T> conditioner2, SDXLRefiner<T> refiner, bool useDualEncoder, int crossAttentionDim, int? seed) |
Initializes a new instance of SDXLModel with full customization support. |
Properties
| Property | Summary |
|---|---|
IConditioningModule<T> Conditioner { get; } |
|
IConditioningModule<T> SecondaryConditioner { get; } |
Gets the secondary text encoder if available. |
INoisePredictor<T> NoisePredictor { get; } |
|
IVAEModel<T> VAE { get; } |
|
SDXLRefiner<T> Refiner { get; } |
Gets the refiner model if available. |
bool SupportsRefiner { get; } |
Gets whether this model has a refiner available. |
bool UsesDualEncoder { get; } |
Gets whether this model uses dual text encoders. |
int CrossAttentionDim { get; } |
Gets the cross-attention dimension (2048 for SDXL). |
int LatentChannels { get; } |
Methods
| Method | Summary |
|---|---|
ModelMetadata<T> GetModelMetadata() |
|
Task<Tensor<T>> GenerateAsync(string prompt, string negativePrompt, int width, int height, int? originalWidth, int? originalHeight, int cropTop, int cropLeft, int numInferenceSteps, double? guidanceScale, int? seed, IProgress<int> progress, CancellationToken cancellationToken) |
Async wrapper around GenerateWithMicroCondition with cooperative cancellation between scheduler steps and per-step progress reporting. |
Tensor<T> GenerateWithMicroCondition(string prompt, string negativePrompt, int width, int height, int? originalWidth, int? originalHeight, int cropTop, int cropLeft, int numInferenceSteps, double? guidanceScale, int? seed) |
Generates an image with micro-conditioning for multi-aspect ratio support. |
Tensor<T> RefineImage(Tensor<T> image, string prompt, string negativePrompt, int numInferenceSteps, double denoiseStrength, int? seed) |
Refines an image using the SDXL refiner model. |
void InvalidateAllStageCompiledPlans() |
Drops every stage’s plan in lockstep. |
void InvalidateConditioner1CompiledPlans() |
Drops the conditioner1 stage’s compiled plan on the next generation. |
void InvalidateConditioner2CompiledPlans() |
Drops conditioner2’s plan only. |
void InvalidateUNetCompiledPlans() |
Drops UNet’s per-step plan only. |
void InvalidateVAECompiledPlans() |
Drops VAE-decoder’s plan only. |
Fields
| Field | Summary |
|---|---|
int DefaultHeight |
Default height for SDXL generation. |
int DefaultWidth |
Default width for SDXL generation. |