Skip to main content
Back

UC Berkeley's InstructPix2Pix Rewrote Image Editing With Just a Text Command

A conditional diffusion model that edits images from plain-English instructions in a single forward pass, no masks or fine-tuning required.

Pro

  • InstructPix2Pix edits images from plain instructions in one forward pass, no masks or fine-tuning.
  • Released by UC Berkeley authors as a 0.9B parameter MIT-licensed checkpoint on Hugging Face.
  • Training data synthesized by chaining GPT-3 with Stable Diffusion to generate paired before-after examples.
  • Ships as StableDiffusionInstructPix2PixPipeline in diffusers, powering 100+ Hugging Face Spaces.
  • Strong at style transfer, object swaps, attribute edits; weak at spatial precision and multi-instance edits.
  • Paper established the synthetic-data recipe that most instruction editors still use today.

Editing an image with a diffusion model has traditionally meant wrestling with masks, inversion tricks, or per-image fine-tuning. InstructPix2Pix takes a different route: hand it a photo and a sentence like turn him into a cyborg and it returns the edited image in a few seconds, without touching a segmentation tool or retraining anything.

The model, from Tim Brooks, Aleksander Holynski, and Alexei Efros at UC Berkeley, is a conditional diffusion network built on top of Stable Diffusion. It has crossed 1.18k likes and 26k downloads on Hugging Face and remains one of the most reused instruction-editing checkpoints in the ecosystem, with 100+ Spaces built on top of it and multiple community fine-tunes.

Instructions instead of descriptions

Most text-to-image editors want a full description of what the output should look like. InstructPix2Pix wants a command. Given an image and an instruction for how to edit that image, the model performs the appropriate edit without requiring full descriptions for the input or output, and it works in a single forward pass with no per-example inversion or fine-tuning.

That distinction matters in practice. You do not need to describe the whole scene, mask the region you want changed, or run an optimization loop per image. You write what you want done, and the model figures out what to leave alone.

The training-data trick

The interesting part of the paper is how the authors got training data for a task where paired before/after images basically do not exist on the internet. They synthesized the dataset by chaining two large pretrained models together: GPT-3 for language, Stable Diffusion for images. Together they produced a large corpus of image editing examples.

The recipe, roughly:

  1. A small text dataset was labeled by hand, GPT-3 was fine-tuned on it, and that finetuned model then generated a large dataset of text triplets, using real image captions from LAION as the input caption.
  2. For each caption, GPT-3 produced a plausible editing instruction and a reasonable output caption describing the image after the edit, yielding an input/output caption pair.
  3. To generate the paired images, Stable Diffusion produced pictures for both captions. Prompt-to-Prompt kept the two structurally aligned so only the edited region differs.
  4. A conditional diffusion model was then trained on these synthetic (image, instruction, edited image) triples.

At inference time, the trained model generalizes to real photos and user-written instructions. Because it edits in a single forward pass with no per-example fine-tuning or inversion, a single edit takes seconds.

Using it from diffusers

The model ships as a StableDiffusionInstructPix2PixPipeline in the diffusers library and weighs in at roughly 0.9B parameters under an MIT license. A minimal working example:

import torch, PIL, requests
from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(
    "timbrooks/instruct-pix2pix",
    torch_dtype=torch.float16,
    safety_checker=None,
).to("cuda")
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
image = PIL.Image.open(requests.get(url, stream=True).raw).convert("RGB")
out = pipe("turn him into cyborg", image=image,
           num_inference_steps=10, image_guidance_scale=1).images[0]

Two knobs matter more than anything else: guidance_scale (how strongly to follow the text) and image_guidance_scale (how strongly to preserve the original). Lowering image guidance lets the model make bigger changes; raising it keeps the output closer to the source.

What it is good at

  • Global style transfers, such as making a photo look like a Van Gogh painting or a pencil sketch.
  • Object swaps at the semantic level: turning a cat into a dog, a summer scene into winter, or day into night.
  • Attribute changes such as adding sunglasses, changing hair color, or aging a face.
  • Contextual edits like adding fireworks in the sky or replacing the background.

With no mask and no inversion, throughput is high and the API surface is tiny: image plus text in, image out.

Where it struggles

Follow-up research has been blunt about the failure modes. The approach is prone to over-editing, which has motivated a large body of work exploring attention control, spatial conditioning, and improved inference strategies. Current models still struggle with multi-instance scenarios where several similar objects need distinct, independent modifications.

Practical limitations to watch for:

  • Precise spatial edits such as "move the cup two inches left" typically fail.
  • Counting and multi-object instructions like "change only the second person from the left" are unreliable.
  • Fine text rendering and small details often get mangled, a limitation inherited from the underlying Stable Diffusion backbone.
  • Identity preservation on faces is imperfect, and strong edits can drift the subject's features.

The template everyone copied

InstructPix2Pix set the template that most modern instruction-based editors now follow. As the field matured, the paradigm shifted toward instruction-driven models, and the synthetic-data pipeline pairing GPT-3 with Prompt-to-Prompt turned out to be the reusable idea. Subsequent systems like MagicBrush, MGIE, and instruction-tuned variants of newer diffusion backbones all borrow from the same playbook of generating paired edits with a language model plus a text-to-image model.

The original paper and code repository remain the cleanest reference point for anyone building an instruction-editing feature. If you need fast, mask-free semantic edits on arbitrary photos and can tolerate occasional over-editing, it is still a solid default. If you need pixel-precise control or identity preservation, treat it as the first stage of a pipeline and layer on newer controls such as ControlNet or IP-Adapter to constrain what changes.