A text-to-image diffusion process, starting with a white noise image and remove noise gradually to achieve a target image.
positive and negative prompts
|
CLIP/T5 generates positive & negative embeddings
|
VAE encodes a white-noise image to latent space
|
U-Net, the denoiser predicts 'known' noise (what noise patches to remove), based on prompt and noisy image, in latent space.
Conceptually (noisy image) - (known noise) -> (cleaner image).
|
CFG blends known noises (positive and negative).
Conceptually (blended noise) = (negative noise) + w*(positive noise - negative noise), in latent space.
The weight w is a constant strength of positive noise.
|
Sampler removes a fraction of the blended nosie.
Conceptually (cleaner image) = (noisy image) - (blended noise), in latent space, with a scaling factor from scheduler.
Scheduler has a sequence of timesteps and scaling factors.
|
loop back to U-Net for next timestep
|
complete t loops
|
VAE decodes output image from latent space
CLIP/T5 : text encoder, text->embedding
VAE : Variational Autoencoder, image<->latent
U-Net : Denoiser, predicts what noises to remove
CFG : Classifier-Free Guidance, noises blending
Sampler : Noise subtraction
LORA Low Rank Adaption
The original model is essentially y = Wx.
Now freeze model weights W, but add a small extra, y = Wx + aBAx
Matrix multiplication BAx, shrinks x to r dimensions, and retores back to original dimensions. Alpha "a" is a small scaling factor.
A has shape (r, in_dim)
B has shape (out_dim, r)
Why? similar to Autoencoder, it compresses the extra updates so can only change in r important features.
These r features are supposed (not guaranteed) to capture the most significant updates (e.g portrait aesthetic) to enhance the original image.
LoRa is usually attached to U-Net desnoiser and other layers, to implement required styles.
ControlNet
ControlNet takes a copy of the U-Net denoiser's encoder and middle blocks.
It resizes and encodes a “control map” (pose skeleton, canny edge map, depth map, etc.), and merge it with noise latents encoded from an extra dataset, as guidance signals.
It then further trains the copy of denoiser blocks using the guidance signals.
At run time, The residuals of the blocks are injected back into the original blocks's outputs.
The residuals steer the original desnoiser blocks to respect structure. E.g. Canny edges, object skeletons.