skip to content

Search

← From Noise to Image

Part II — The Diffusion Revolution (2015–2022)

Personalization and LoRA

Textual inversion, DreamBooth, and low-rank adaptation applied to diffusion — the fine-tuning economy.

2022–2023 14 min read 3 papers

It is August 2022. Stable Diffusion has just made high-quality text-to-image generation something anyone can run on a personal GPU, but the model only knows what was in its training set. It can draw “a dog” in any style requested; it cannot draw your dog. Within three weeks, two research groups publish opposite answers to the same question: how do you teach a pretrained diffusion model one new, specific thing from only a handful of photographs?

Where We Were

By mid-2022 the pieces this book’s latent diffusion chapter covers were in place: a frozen text encoder produces a conditioning vector from a prompt, and a U-Net trained with the DDPM loss denoises a latent while attending to that conditioning through cross-attention. CLIP-style contrastive text-image pretraining gives the text encoder its shared vocabulary of visual concepts, and classifier-free guidance sharpens how strongly the output follows the prompt. All of this machinery generates classes of things — dogs, mugs, sunsets in a particular painter’s style — because those classes, described in natural language, were well represented across the model’s training data.

What none of it could do was reproduce one specific instance of a class that the model had never seen: a particular corgi, a particular person’s face, a specific ceramic mug from a specific studio. Asking for “a photo of my dog” produces a generic dog, because the text encoder has no token or embedding that refers to that one animal. The obvious fix — fine-tune the entire model on a few photos of the subject — runs into a problem familiar from other fine-tuning settings: with only three to five images and a model containing hundreds of millions of parameters, naive full fine-tuning overfits quickly, and it also tends to erode the model’s general vocabulary, a failure mode later work would name language drift — after a few hundred steps of retraining on photos of one dog, prompting for “a dog running” might start producing only that specific dog even when the prompt describes an unrelated scene.

Two questions therefore separated: could a new concept be taught without touching the network’s weights at all, working instead within the vocabulary the frozen model already understood? And if the weights had to move, could the update be shaped so that the model’s general knowledge survived alongside the new, narrow fact it was being asked to memorize?

Two opposite answers, three weeks apart The pieces were all in place by August 2022. Textual Inversion and DreamBooth then took the same question in opposite directions. Grey monospace text is what each stage still could not do, or the trade-off it settled on. 2021-06 LoRA published low-rank adapters for language models not yet applied to diffusion 2021-12 Latent Diffusion cross-attention text conditioning arrives the layer LoRA will target 2022-08 SD public release high quality generation, same weights for everyone cannot draw your dog yet 2022-08-02 Textual Inversion one new embedding vector, model stays frozen cheap, lower fidelity 2022-08-25 DreamBooth fine-tunes the full model, a prior preservation loss expensive, high fidelity a precondition, not yet personalization touch nothing, accept limited fidelity touch everything, pay for full fidelity
Every ingredient personalization needed was in place by August 2022. Two teams then took the same three-to-five-photo problem in opposite directions, three weeks apart. PNG ↓

The Breakthrough

Textual Inversion (Gal et al., 2022) answered the first question by refusing to touch the model at all. Every weight in the U-Net and the text encoder stays frozen. What changes is the input: the method introduces a new pseudo-word, written S∗S_*, and searches for a single embedding vector that this pseudo-word should map to, so that prompts containing S∗S_* reproduce the target concept. Because S∗S_* lives in exactly the same embedding space the text encoder already uses for every other word, it can be dropped into ordinary prompts — “a photo of S∗S_* wearing a hat” — and the frozen model composes it with the rest of its existing vocabulary. The paper trains this one vector on three to five images per concept, optimizing for roughly 5,000 steps on two V100 GPUs, a run the paper reports takes about two hours. The result is small by construction: the entire “fine-tune” is one new vector, nothing else in the model moves.

DreamBooth (Ruiz et al., 2022), submitted three weeks later out of Google Research and Boston University, took the opposite route: fine-tune the model’s weights directly, subject and all. A handful of photos — again three to five — are paired with a prompt containing a rare token the vocabulary rarely uses (selected so it carries little prior meaning of its own) plus the subject’s class noun, such as “a [V] dog.” Full fine-tuning on so few images would ordinarily overfit or drift, so DreamBooth adds a second loss term computed simultaneously: samples generated by the frozen model for the plain class prompt “a dog,” used as a regularization target so the fine-tuned model keeps producing generic dogs when asked for one, instead of collapsing every dog into the one subject it just learned. The rare token itself is not chosen at random from the whole vocabulary — the paper samples from a range of the T5-XXL tokenizer’s tokens corresponding to three or fewer Unicode characters with no spaces, then decodes that token back into text, on the reasoning that a token which rarely appears on its own carries little pre-existing meaning for the model to fight against. Training runs for roughly a thousand iterations and — for Stable Diffusion specifically — about five minutes on a single NVIDIA A100. Measured against Textual Inversion on subject fidelity, DreamBooth’s reported DINO similarity score is 0.668 versus 0.569, and in a human preference study, evaluators favored DreamBooth’s subject fidelity 68% of the time against 22% for Textual Inversion.

Touch nothing, or touch everything The same three to five photos, run down two opposite paths to personalization. Subject photos three to five images the same input for both paths TEXTUAL INVERSION DREAMBOOTH Entire model frozen U-Net and text encoder untouched throughout Optimize one embedding ~5,000 steps, 2x V100 about two hours Cheap, portable DINO similarity 0.569 kilobytes on disk Fine-tune full network U-Net and text encoder both move Class prior preservation frozen model's own class samples guard against drift Expensive, high fidelity DINO similarity 0.668 full model copy per subject Human raters preferred DreamBooth's subject fidelity 68% of the time against 22% for Textual Inversion.
The same handful of photos, run down two opposite paths. Human raters preferred DreamBooth's fidelity 68 percent of the time against 22 percent for Textual Inversion. PNG ↓

The two papers had traced the extremes of a spectrum: touch almost nothing and accept limited fidelity, or touch everything and pay for a full fine-tune per subject. LoRA (Hu et al., 2021) — designed a year earlier for large language models and covered in full in this book’s sister volume’s PEFT and LoRA chapter — offered a middle path once the diffusion community adapted it to the U-Net. Rather than optimizing a single embedding or retraining the whole network, LoRA freezes every original weight matrix and inserts a small, additive low-rank update next to a chosen subset of them, training only that update. Applied to diffusion, the natural target is the cross-attention layers that connect the U-Net to the text conditioning covered in the latent-diffusion chapter — the query, key, and value projections that let text tokens steer image denoising are exactly where a subject or a style needs to leave its mark. Because the update merges back into the frozen weight after training, it costs nothing at inference and, being low-rank, costs very little to store: Hugging Face’s diffusers integration of the method reported adapter files as small as a few megabytes, roughly a thousand times smaller than the U-Net they modify — Replicate’s own February 2023 comparison of the two workflows found LoRA training on Stable Diffusion completing in about eight minutes and producing files around 5 MB, against roughly twenty minutes and several gigabytes for a full DreamBooth run.

Three artifact sizes, several orders of magnitude apart What one personalized subject costs to store, by method. Bar length is illustrative, not to a linear scale; the gap between kilobytes and gigabytes cannot be drawn to scale on one page. DreamBooth ~20 min training, single GPU several GB LoRA ~8 min training, single GPU ~5 MB Textual Inversion ~2 hours training, 2x V100 kilobytes The practical effect: personalizing a model collapsed from a full retraining problem into downloading a small file.
LoRA lands where DreamBooth's fidelity meets Textual Inversion's footprint, not literally between the two on either axis, which is what turned personalization into a file you download rather than a model you retrain. PNG ↓

The Mathematics

Textual Inversion’s objective looks exactly like the ordinary diffusion training loss this book’s diffusion foundations chapter derives, with one crucial restriction on what is allowed to change:

v∗=arg⁡min⁡v  Ez,y,ϵ,t[∥ϵ−ϵθ ⁣(zt,t,cθ(y))∥22]v_* = \arg\min_v \; \mathbb{E}_{z, y, \epsilon, t} \left[ \left\| \epsilon - \epsilon_\theta\!\left(z_t, t, c_\theta(y)\right) \right\|_2^2 \right]
SymbolMeaning
v∗v_*The learned embedding for the pseudo-word S∗S_*, the only trainable quantity
zzLatent code of a training image, from the frozen autoencoder
yyA text prompt containing the placeholder S∗S_*
ϵ\epsilonNoise added during the forward diffusion process
ϵθ\epsilon_\thetaThe frozen U-Net’s noise-prediction network
cθ(y)c_\theta(y)Conditioning vector produced by the frozen text encoder from yy
ttDiffusion timestep

DreamBooth optimizes the same kind of noise-prediction loss but over the full network, and adds a second term evaluated on the frozen model’s own outputs to hold the wider class steady:

Ex,c,ϵ,ϵ′,t,t′[wt∥x^θ ⁣(αtx+σtϵ, c)−x∥22+λ wt′∥x^θ ⁣(αt′xpr+σt′ϵ′, cpr)−xpr∥22]\mathbb{E}_{x, c, \epsilon, \epsilon', t, t'} \Big[ w_t \left\| \hat{x}_\theta\!\left(\alpha_t x + \sigma_t \epsilon,\, c\right) - x \right\|_2^2 + \lambda \, w_{t'} \left\| \hat{x}_\theta\!\left(\alpha_{t'} x_{\mathrm{pr}} + \sigma_{t'} \epsilon',\, c_{\mathrm{pr}}\right) - x_{\mathrm{pr}} \right\|_2^2 \Big]
SymbolMeaning
xxA ground-truth subject photo
ccText embedding of a subject prompt containing the rare-token identifier
xprx_{\mathrm{pr}}A class sample generated by the frozen model before fine-tuning
cprc_{\mathrm{pr}}Text embedding of the plain class prompt
ϵ,ϵ′\epsilon, \epsilon'Independent noise draws for the subject and class terms
αt,σt\alpha_t, \sigma_tNoise-schedule coefficients at timestep tt
t,t′t, t'Independently sampled timesteps for the two terms
wt,wt′w_t, w_{t'}Loss weighting at each timestep
λ\lambdaStrength of the prior-preservation term

LoRA’s own decomposition — freezing a weight matrix W0W_0 and adding a trained low-rank update ΔW=αrBA\Delta W = \frac{\alpha}{r}BA — is derived in full in the PEFT and LoRA chapter; this chapter only needs to say where that update lands inside a diffusion U-Net. Cross-attention conditions image generation on text through three projections — query, key, and value — and LoRA-for-diffusion attaches its own low-rank pair to each:

WQ′=WQ+αrBQAQ,WK′=WK+αrBKAK,WV′=WV+αrBVAVW_Q' = W_Q + \frac{\alpha}{r} B_Q A_Q, \qquad W_K' = W_K + \frac{\alpha}{r} B_K A_K, \qquad W_V' = W_V + \frac{\alpha}{r} B_V A_V
SymbolMeaning
WQ,WK,WVW_Q, W_K, W_VThe frozen cross-attention query, key, and value projection matrices
WQ′,WK′,WV′W_Q', W_K', W_V'The projections used at inference, after the trained low-rank update is merged in
BQ,AQB_Q, A_Q / BK,AKB_K, A_K / BV,AVB_V, A_VThe low-rank factor pair trained for each projection; shape, rank, and initialization are covered in the PEFT and LoRA chapter
α,r\alpha, rThe LoRA scaling constant and rank, defined once in the PEFT and LoRA chapter

What It Enabled

MethodYearWhat movesTypical training timeTypical artifact size
Full DreamBooth fine-tune2022Entire U-Net and text encoder~20 minutes (SD, single GPU)Several gigabytes
Textual Inversion2022One embedding vector~2 hours (2×V100)Kilobytes
LoRA-for-diffusionadapted 2023Low-rank update to targeted weight matrices~8 minutes (SD, single GPU)Around 5 MB

The practical effect was to collapse “personalize a diffusion model” from a full-model retraining problem into something closer to downloading a small file. Because a LoRA adapter is additive and mergeable, the same frozen Stable Diffusion checkpoint can host any number of subject- or style-specific adapters, swapped in at load time rather than baked into separate multi-gigabyte checkpoints — the same serving pattern this book’s sister volume describes for inference engines multiplexing many fine-tuned variants against one base model. That portability is what let LoRA sharing become a community activity rather than a lab-scale exercise: by the time SDXL shipped in July 2023, LoRA had become the default way the open-source Stable Diffusion community distributed both character and style fine-tunes, alongside the spatial and reference-image conditioning methods this book covers next in control and the training-free approaches covered in editing. The same low-rank pattern carried forward into the rectified-flow transformer backbones this book covers in flow matching and transformer backbones, where FLUX and SD3-era models are fine-tuned with LoRA rather than full retraining as a matter of course.

Personalization and control solve related but distinct problems worth keeping separate: Textual Inversion, DreamBooth, and LoRA answer “how do I teach the model a new subject or style,” while ControlNet-style conditioning, covered next, answers “how do I specify the exact pose, depth, or layout of a generation.” A production pipeline built after 2023 routinely combines both — a LoRA for the client’s product, layered with spatial conditioning for the exact shot composition.

The rank rr of the low-rank update is the knob that trades cost against expressiveness, and the diffusion community treated it as a tunable rather than a constant: a low-rank adapter trained only on cross-attention captures a style or a simple subject cheaply, while a higher-rank adapter, or one extended to the U-Net’s convolutional layers and the text encoder as well, approaches DreamBooth-level subject fidelity at a proportionally larger — though still comparatively small — file size. Community LoRA-sharing platforms that emerged around Stable Diffusion formalized this as a spectrum of adapter types rather than one fixed recipe: style LoRAs trained on an artist’s body of work, character LoRAs trained on a specific fictional or real subject, and concept LoRAs trained on an object, pose, or clothing item, all using the identical W′=W0+αrBAW' = W_0 + \frac{\alpha}{r}BA mechanism with different training data and different rank choices.

Key Papers

PaperAuthorsYearLinkWhy it matters
An Image is Worth One Word: Personalizing Text-to-Image Generation using Textual InversionGal et al.2022arXiv:2208.01618Personalizes by learning one new embedding vector; frozen model, smallest possible footprint
DreamBooth: Fine Tuning Text-to-Image Diffusion Models for Subject-Driven GenerationRuiz et al.2022arXiv:2208.12242Full-weight fine-tuning with class prior preservation; highest subject fidelity, highest cost
LoRA: Low-Rank Adaptation of Large Language ModelsHu et al.2021arXiv:2106.09685Low-rank additive update, later attached to diffusion cross-attention; DreamBooth-level fidelity at a fraction of the cost

PM Lens

Papers referenced