Multimodal & Image Generation
Generative & Agentic AI · Customize & Ship · Advanced · 22 min
Understand how models read images (vision-language models), how diffusion models create images by removing noise step by step, and how to use Claude vision, Amazon Nova Canvas and Stability models on Bedrock safely.
A photo slowly dissolves into TV static, one sprinkle of noise at a time. A diffusion model learns to run that film backwards: from pure static, it removes a little noise per step until a picture appears, steered by your words.
The idea in everyday words
Think of a sculptor and a block of marble. The block (random noise) already contains every possible statue. The sculptor (the diffusion model) chips away a little at a time, and the customer's description ('a cat sitting on a chair') tells them which statue to reveal. A vision model is the opposite job: an art critic who looks at the finished statue and describes it in words.
What multimodal means
A modality is a kind of data: text, images, audio, video. A multimodal model works with more than one. In practice there are three jobs:
| Job | Input → output | Typical model | On AWS |
|---|---|---|---|
| Understand | image (+ text) → text | Vision-language model (VLM) | Claude or Amazon Nova models on Bedrock |
| Generate | text (+ image) → image | Diffusion model | Amazon Nova Canvas, Stability AI models on Bedrock |
| Search | image or text → vector | Multimodal embedding model | Amazon Titan Multimodal Embeddings |
How a vision-language model reads an image: the image is cut into small square patches (like tiles). A vision encoder turns each patch into a vector, and those vectors are fed to the language model next to the text tokens. So to the LLM, an image is just "more tokens". That is why bigger images cost more tokens: resize them to what the task needs.
Calling Claude with an image through the Bedrock Converse API:
import boto3
br = boto3.client("bedrock-runtime")
with open("receipt.png", "rb") as f:
img = f.read()
resp = br.converse(
modelId="A_VISION_CAPABLE_MODEL_ID", # pick one in the Bedrock console
messages=[{"role": "user", "content": [
{"image": {"format": "png", "source": {"bytes": img}}},
{"text": "What is the total on this receipt? Reply with the number only."},
]}],
)
print(resp["output"]["message"]["content"][0]["text"])
Use cases: reading receipts and forms, describing product photos, answering questions about charts, checking a screenshot for UI bugs.
Diffusion: learning to remove noise
Forward process (only used for training): take a real image and add a little random noise, again and again, for many steps, until it is pure static. At every step we know exactly which noise we added.
Training: show the network a noisy image and the step number, and ask it to predict the noise that was added. Reward it for guessing right. After millions of images it gets very good at saying "this part is noise, this part is picture".
Reverse process (generation): start from fresh random noise. At each step the network predicts the noise, and a scheduler removes part of it. After 20 to 50 steps, an image appears that never existed before.
The network is usually a U-Net: it shrinks the image down to capture the big picture, then grows it back up, with skip connections that carry fine details across. Newer models also use transformer backbones. Latent diffusion (Stable Diffusion) does all of this on a small compressed version of the image (a latent), made by an autoencoder, which makes it far cheaper; a decoder turns the final latent into pixels.
A toy version with whole numbers instead of real noise:
clean = [0, 9, 9, 0] # a tiny 1D "image"
noise = [3, -4, -2, 4]
noisy = [max(0, min(9, c + n)) for c, n in zip(clean, noise)]
print("forward (add noise):", noisy)
x = noisy
for step in range(1, 4):
# pretend the model predicted the clean image; move at most 2 units per step
x = [v + max(-2, min(2, c - v)) for v, c in zip(x, clean)]
print("reverse step", step, x)
Key idea: generation is many small corrections, not one big guess. That is why more steps usually look better but take longer.
Text conditioning and the guidance scale
How does the prompt steer the picture? A text encoder (for example CLIP or T5) turns your prompt into vectors. Inside the U-Net, cross-attention layers let each part of the image look at those vectors, so the noise prediction depends on the words.
Classifier-free guidance (CFG) makes the prompt matter more. At each step the model predicts the noise twice, once with the prompt and once without, and pushes further in the direction the prompt points:
noise = uncond + scale × (cond − uncond)
| Guidance scale | Effect |
|---|---|
| Low (about 1 to 4) | Creative, varied, may ignore parts of the prompt |
| Medium (about 5 to 9) | Usual sweet spot |
| High (12+) | Follows the prompt very literally; colours can look burnt, less variety |
Other knobs you will meet:
- Negative prompt: things to steer away from ("blurry, text, extra fingers").
- Seed: the starting noise. Same seed + same settings = the same image, which is great for reproducible tests.
- Steps: more steps, more detail, more time.
- Image strength (image-to-image): how much of an input image to keep.
Editing: inpainting, outpainting and variations
Because diffusion starts from noise, you can choose where the noise goes:
- Inpainting: add noise only inside a mask (say, the sofa in a living-room photo) and regenerate just that area with a prompt ("a green velvet sofa"). The rest of the photo stays untouched.
- Outpainting: extend the canvas (make a portrait photo wider) and generate the new border so it blends with the original.
- Image variation / image-to-image: start from a partly noised version of an existing image, so the result keeps its layout but changes style.
- Background removal and colour-guided generation (give a palette of brand colours).
- Control methods (ControlNet-style conditioning on edges, depth or pose) keep the composition fixed while changing the content.
Key idea: masks decide where the model is allowed to change pixels, prompts decide what goes there.
Go deeper (engineer level)
The forward process has a closed form. A noise schedule picks a small variance β_t for each step t. With ᾱ_t = the product of (1 − β_s) up to t, a noisy sample is x_t = √ᾱ_t · x_0 + √(1 − ᾱ_t) · ε with ε random Gaussian noise. So training never loops through steps: pick a random t, make x_t in one line, and train the network ε_θ(x_t, t, text) to predict ε with a mean-squared-error loss. Some models predict x_0 or a "velocity" instead; the idea is the same. Linear vs cosine schedules change how much signal survives at middle steps, which affects quality.
Samplers trade steps for quality. DDPM-style ancestral sampling adds fresh noise each step and needs many steps. DDIM and ODE solvers (DPM-Solver and friends) are deterministic given the seed and get good images in 20 to 50 steps. Distilled models go down to a handful of steps. This is why seeds are reproducible only with the same model version, sampler and settings.
Classifier-free guidance maths. During training the text is dropped for a fraction of examples, so one network learns both ε(x, t, text) and ε(x, t, ∅). At sampling time ε = ε_uncond + s · (ε_cond − ε_uncond). s = 1 is plain conditioning; larger s extrapolates past it. Cost: two predictions per step (usually batched together), so CFG roughly doubles compute. Too high a scale pushes values out of the normal range: oversaturated, burnt images.
Latent space makes it affordable. Stable Diffusion 1.x encodes a 512 × 512 × 3 image into a 64 × 64 × 4 latent, about 48 times fewer numbers, runs diffusion there, then decodes once.
Known failure modes: text inside images, hands and counting, prompt words that bleed into the wrong object, and memorised training images. Moderate outputs, and evaluate with human review plus automatic scores (prompt-image similarity, aesthetic or safety classifiers).
Step by step
- Training data:
Take a clean 8×8 heart: 9s inside the heart, 0s outside.
- Forward step 1:
Add a small random noise to each pixel, e.g. +3 or -2, clipped to 0..9. The heart is still visible.
- Forward steps 2-4:
Keep adding noise. By step 4 it is pure static: every pixel random. The model was trained to predict the noise at each of these steps.
- Generate:
Now start from brand-new static. Prompt 'heart', guidance strong. The model predicts what the clean image should be (here we let it know the heart).
- Reverse steps:
Each step moves every pixel at most 3 units toward that prediction: a pixel at 2 that should be 9 goes 2 → 5 → 8 → 9. Pixels already right stay put.
- Compare:
With weak guidance (1 unit per step) the same image needs 9 steps. With no prompt, the model has no target and the pixels just blur into grey: conditioning is what gives the picture its meaning.
Code example
# Toy diffusion on a 5x5 "plus" with whole numbers (0 = dark, 9 = bright).
PLUS = [[0, 0, 9, 0, 0],
[0, 0, 9, 0, 0],
[9, 9, 9, 9, 9],
[0, 0, 9, 0, 0],
[0, 0, 9, 0, 0]]
seed = 7
def rand(lo, hi): # tiny deterministic random number generator
global seed
seed = (seed * 16807) % 2147483647
return lo + seed % (hi - lo + 1)
def show(title, g):
print(title)
for row in g:
print(" " + " ".join(str(v) for v in row))
# Generation starts from pure random noise.
x = [[rand(0, 9) for _ in range(5)] for _ in range(5)]
show("step 0 (pure noise)", x)
def denoise_step(x, predicted, max_step):
return [[v + max(-max_step, min(max_step, p - v)) for v, p in zip(r, pr)]
for r, pr in zip(x, predicted)]
step = 0
while x != PLUS:
step += 1
x = denoise_step(x, PLUS, 3) # strong guidance: big confident moves
show("step " + str(step), x)
# Classifier-free guidance on one number: push past the unconditional guess.
uncond, cond = 2, 5
for scale in [1, 3, 7]:
print("guidance", scale, "->", uncond + scale * (cond - uncond))Complexity
- Time: O(S · R · C) for S denoising steps over an R × C grid
- Space: O(R · C) for the new grid each step
Interview tips
Explain diffusion in three sentences: forward noising for training, the network predicts noise, reverse denoising from random noise at generation time.
What does the guidance scale do, and what goes wrong when it is too high or too low?
Why latent diffusion? Working in a compressed latent space is far cheaper than in pixel space.
How would you build 'search our product photos by text' on AWS? Titan Multimodal Embeddings, OpenSearch Serverless vector index, embed the query text, k-NN search.
How do you make an image-generation feature safe? Prompt and output filtering, moderation of uploads, watermarking, no real people or brands, human review.
Challenge: Integer denoising on a pixel grid
Simulate the reverse (denoising) process of a diffusion model on a small grid of whole numbers.
Write denoise(noisy, predicted, max_step, max_steps):
noisy: the current grid (list of rows of ints).predicted: the clean grid the model predicts (same shape).- In one step, every pixel moves toward its predicted value by at most
max_step(never overshooting). - Repeat while the grid is not yet equal to
predictedand fewer thanmax_stepssteps were taken.
Return {"grid": <final grid>, "steps": <steps taken>}. Do not modify noisy (one test checks it is unchanged after your call).
denoise([[0, 9, 4]], [[9, 0, 4]], 3, 2)
# step 1: [[3, 6, 4]] step 2: [[6, 3, 4]] budget used up
# {"grid": [[6, 3, 4]], "steps": 2}
Solve it in the browser with tests, hints and an AI coach.
Practice problems
- Image Smoother (a 3×3 grid filter, like one blur step) (Easy)
- Flood Fill (editing a masked region of an image) (Easy)
- Hugging Face diffusion models class (hands-on notebooks) (Medium)
- Amazon Nova user guide (Nova Canvas image generation) (Medium)
More in Customize & Ship
- Fine-Tuning & LoRA
- Making Models Smaller & Faster
- LLM Inference & Serving at Scale
- Evaluation & Guardrails
- LLMOps: Shipping GenAI on the Cloud
Previous: LLM Inference & Serving at Scale · Next: Evaluation & Guardrails