ImageGPT
ImageGPT trains a plain GPT transformer on flattened pixel sequences, proving the language modelling recipe learns visual features with no 2D machinery.
Why Does This Exist?
Vision and language ran on separate machinery: convolutions here, transformers there, with endless debate about which bias vision truly needs. Settling it required the purest experiment, the exact language recipe with nothing visual added, to see how far sequence modelling alone reaches.
ImageGPT is that experiment. Flatten the image, cluster colours to codes, train GPT-2 architectures as-is. The models generated coherent images and, more importantly, learned features rivalling supervised pretraining on classification probes. The result licensed the transformer takeover of vision. The pixel-level predecessor is PixelCNN, and the scaled-up descendant is Parti.
Think of It Like This
A novelist asked to paint by numbers
A novelist who has never held a brush is handed paint-by-number canvases with numbered colours and told to fill them left to right, top to bottom, guessing each cell from the story so far. No sketching lessons, no colour theory, just sequence instinct.
Surprisingly the novelist produces recognisable scenes and develops opinions about composition, because narrative prediction transfers to visual prediction. The paintings stay small, the novelist works one cell at a time, but the lesson lands: the machinery matters less than the prediction game.
How It Actually Works
Preprocess crops to and k-means colours to clusters (-bit colour), turning each image into tokens. Train a decoder-only transformer, GPT-2 small through XL sizes, on next-token cross-entropy with a single learned position embedding per index. No 2D position grids, no convolution stems, no image-specific changes whatsoever:
After generative training, freeze the transformer and probe it: linear classifiers on middle-layer activations match supervised ResNet features on several benchmarks, showing the next-pixel game taught genuine visual understanding, not just texture statistics.
Worked example
One image is positions times a -way choice. At nats per position the image costs nats. The XL model's billion parameters process sequences of length with full attention, about a million pairwise interactions per layer, which is why experiments stayed at pixels: the sequence recipe works, but its compute bill scales with the square of resolution.
Code
Sequence shaping for the GPT treatment, the only vision code in the recipe.
def gpt_sequence(px: int = 32) -> tuple[int, int]: """Positions and vocabulary for ImageGPT preprocessing.""" positions = px * px # flattened raster order vocab = 512 # k-means colour clusters, 9 bit colour return positions, vocab
print(gpt_sequence()) # -> (1024, 512) positions and colour codesWatch Out For
Flattening away resolution and calling it general
Results at pixels do not transfer to megapixel generation. Full attention over positions is computationally hopeless, which is why practical descendants quantise patches first instead of pixels.
Read ImageGPT as a representation-learning result, not a generator blueprint. Scaling the recipe needs token compression, the VQ route.
Colour clustering artefacts mistaken for model failures
K-means colours band smooth gradients and shift hues slightly. Blame the model for banded skies and you will tune transformers to fix a preprocessing artifact.
Inspect reconstructions through the clustering alone first. Anything already broken there is data pipeline, not architecture.
The Quick Version
- ImageGPT trains unmodified GPT-2 transformers on flattened, colour-clustered pixels.
- images become positions over a -code vocabulary.
- Frozen features rival supervised pretraining on classification probes.
- Quadratic attention confines the pure recipe to tiny images.
- Colour banding comes from k-means preprocessing, not the transformer.