SDXL (Stable Diffusion XL) is a Stable Diffusion model variant for text-to-image generation. It is a practical step up from Stable Diffusion 1.5: it produces notably higher-quality images and follows prompts better, while needing only slightly more VRAM. That makes it useful when image quality matters but consumer GPU limits still matter too. section 9.1
The easiest way to run SDXL from Python is through Hugging Face Diffusers. Load the pretrained SDXL base model into a DiffusionPipeline, move it to CUDA, then call the pipeline with a prompt, negative prompt, dimensions, guidance scale, and seeded generator. Diffusers hides most of the machinery, leaving a small configuration surface to tweak. section 3.4 section 3.4.2
Listing 3.1 Using the same configuration in Diffusers as last chapter
from diffusers import DiffusionPipeline
import torch
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", #A
torch_dtype=torch.float16,
use_safetensors=True, variant="fp16")
pipe.to("cuda") #B
prng = torch.Generator("cuda").manual_seed(1433094685) #C
prompt = "A scene from a scifi movie, a sandworm with a mouth, teeth” #D
negative_prompt = "black and white, eyes"
width = 680
height = 520
cfg_scale = 13
pipe( #E
prompt=prompt,
negative_prompt=negative_prompt,
width=width,
height=height,
guidance_scale=cfg_scale,
generator=prng
).images[0]This minimal pipeline shows the working knobs: model identifier, GPU and fp16 setup, reproducible seed, positive and negative prompts, image size, and guidance scale. section 3.4
For repeatable image work, treat SDXL as a generator inside a small program rather than a button you press fifty times:
- Keep each image request as configuration: prompt, width, height, and other settings can vary per panel. section 3.5
- Loop over configurations and save candidates into separate folders, making later selection much less chaotic. section 3.5
- Use a notebook to separate editable configuration cells from generation cells, then rerun after changing prompts or settings. section 3.5
- Swap the model identifier to use Stable Diffusion 1.5 if SDXL exceeds local GPU capacity; the surrounding pipeline code can remain the same. section 3.4.2
Generating a graphic-novel page
Split a scene into five illustrated panels, assign each panel its own prompt and dimensions, and generate ten candidates per panel. After the batch finishes, choose favorites and assemble them with text in a page-layout tool. This is the sort of job where a few loops beat manually repeating generations until your mouse asks for workers’ compensation. section 3.2 section 3.5
SDXL is not magic paint with perfect hands. It may favor an illustrative look even when a prompt requests a crisp photo, and generated hands can still have implausible finger counts. Trying other SDXL checkpoints and iterating may improve results; composition can also avoid making hands prominent when realism is important. For style-focused image creation, SDXL remains a strong starting point, while Flux is presented as stronger for generally high-quality prompt-matched images. section 9.1.2 section 9.3
