Book Deep Read · Generative AI System Design Interview · Ch 8

High-Resolution Image Synthesis: the hard part is not painting finer — it is not painting at full size

Generative AI System Design Interview · Ch 8 · Ali Aminian, Hao Sheng & Alex Xu · 2024

中文 →

What is this chapter about?

You type "a cabin below a snowy mountain, dusk" into your phone, and a few seconds later out comes something you would use as a wallpaper. This chapter is about the machinery behind that. It answers one very concrete engineering question: how do you get a machine to paint a large, sharp picture without burning through all your compute?

Start with something odd

The most effective way to teach a machine to paint turns out to be teaching it to ruin a painting first. Take a real photo, sprinkle a little static onto it, do that a thousand times, and you end up with a screen of pure snow. That ruining step is so simple it needs no learning at all — you just follow a fixed recipe. Then you train a network to do exactly one thing: look at a speckled picture and point out which parts are the speckles. Point them out, subtract them, and the picture gets a little cleaner.

Why going backwards works better

Because it turns one hard job into a thousand easy ones. Asking a machine to paint a whole face from nothing in a single shot is hard — the older approach from the previous chapter, where two networks fight each other, often collapses mid-training. But asking it to "clean up a slightly fuzzy picture a little" is far easier, and you have unlimited practice material: grab any photo, sprinkle your own static on it, and the correct answer is exactly the static you just sprinkled. Nobody has to label anything.

So painting becomes this: start from a screen of pure snow, let the network wipe once, wipe again, wipe again — and after a few dozen wipes, a picture develops out of the noise.

The real obstacle: switch to a smaller sheet of paper

Here is the catch. A 512-by-512 picture has a few hundred thousand dots in it, and each wipe has to push every one of those dots through the network — dozens to hundreds of times. Do all that at full size and your graphics card falls over.

The key move in this chapter is to switch sheets of paper. You separately train a pair of helpers — a compressor and a restorer. The compressor squeezes a photo down to a palm-sized sketch holding roughly one-fiftieth of the information; the restorer blows the sketch back up to full size. Then all those wipes happen on the little sketch, and you restore it just once at the end. The cost per step drops by an order of magnitude, and that is what made "a picture from a home graphics card" possible at all.

The price is real: the squeeze is lossy, and the finest strokes get wiped out — which is exactly why small text, fingers and dense grids come out mangled so often in these pictures.

How many wipes is a dial you can turn

Wipe more and the detail is steadier but it takes longer; wipe less and it is fast but the composition occasionally falls apart. So in a product this is a dial with a published price: fewer wipes for a quick preview, more wipes for the final take. That beats "swap in a bigger model" by a mile — it needs no retraining and you can turn it live.

Remember this one line

Run "paint a picture" backwards into "wipe off the static step by step", and one hard job becomes a thousand easy ones; then move all that wiping onto a small sketch sheet, and the compute finally comes down. How many wipes is the dial you get to turn.

Want the mechanisms, notation and diagrams? → Switch to the deep read