PnP Inversion: Boosting Diffusion-based Editing with 3 Lines of Code

Xuan Ju, Ailing Zeng, Yuxuan Bian, Shaoteng Liu, Qiang Xu

TL;DR

PnP Inversion is a simple yet powerful technique that significantly improves diffusion-based image editing by disentangling the source (preservation) and target (editing) diffusion branches. By adding just three lines of code to existing pipelines, it achieves state-of-the-art content preservation and edit fidelity with nearly a 10x speedup compared to optimization-based methods.

The Challenge of Image Editing

Text-guided diffusion models are incredible at generating images, but editing real images remains tricky. The standard workflow involves "inversion": taking a real image and finding the initial noise (latent vector) that would generate it. Once you have this noise, you can run the diffusion process again with a new prompt (e.g., changing "a cat" to "a dog").

However, standard inversion techniques like DDIM inversion are imperfect. They introduce "drift" or perturbations, especially when using classifier-free guidance. This leads to two main problems:

  1. Poor Preservation: The background or unedited parts of the image change unintentionally.
  2. Low Edit Fidelity: The model struggles to actually perform the requested change because it's too constrained by the "corrected" noise.

Prior state-of-the-art methods, such as Null-text Inversion, try to fix this by running a time-consuming optimization process to find a single "perfect" latent that works for both the original image and the edited version. The authors of this paper argue that this "unified" approach is fundamentally flawed.

The Solution: Disentangled Inversion

The core contribution of this paper is the idea of disentanglement. Instead of trying to find one latent vector to rule them all, the authors propose treating the source branch (which reconstructs the original image) and the target branch (which performs the edit) separately.

The "PnP" (Plug-and-Play) Inversion works as follows:

  1. Source Branch Correction: During the forward diffusion process, the algorithm calculates the difference between the "ideal" DDIM path and the actual path taken. It then directly adds this difference back into the source branch at every step. This ensures the source branch perfectly preserves the original image's structure.
  2. Target Branch Freedom: The target branch is left untouched. By not forcing the "corrected" latents onto the target branch, the diffusion model is free to use its full generative power to fulfill the editing prompt.
  3. The "3 Lines of Code": The implementation is incredibly lightweight. It simply involves computing the error in the source branch and adding it back, which can be integrated into existing editing frameworks (like Prompt-to-Prompt or MasaCtrl) with minimal effort.

Key Insights

  • Separation of Responsibilities: The source branch's job is preservation, while the target branch's job is fidelity. Trying to force one latent to do both creates a conflict that degrades quality.
  • Optimization is Overkill: You don't need minutes of GPU-heavy optimization if you simply correct the drift in the source branch mathematically.
  • The Guidance Scale Sweet Spot: The authors found that an inverse guidance scale of 2.5 and a forward scale of 7.5 provides the best balance between keeping the original structure and achieving a high-quality edit.

PIE-Bench Dataset

To rigorously test their method, the authors introduced PIE-Bench (Prompt-based Image Editing Benchmark).

  • Scale: 700 images across diverse scenes.
  • Diversity: 10 editing categories, including object replacement, adding/deleting objects, changing pose, color, material, background, and style.
  • Annotations: Each entry includes source/target prompts, specific editing instructions, and hand-annotated editing masks to precisely measure background preservation.

Key Results

PnP Inversion consistently outperforms existing methods across multiple metrics and editing frameworks.

  • Speed: It achieves nearly an order of magnitude speedup. For example, it takes ~28 seconds per image compared to ~148 seconds for Null-text Inversion.
  • Quantitative Gains: On PIE-Bench, it improved structure preservation by up to 83.2% (measured by Structure Distance) and edit fidelity by up to 8.8% compared to baseline inversion methods.
  • Qualitative Improvements: PnP Inversion results in much cleaner edits where the background remains identical to the source, and the edited subject looks more natural without bleeding artifacts.
Visual comparison showing how PnP Inversion improves background preservation and structure across different editing methods.

Limitations and Future Work

While PnP Inversion boosts existing methods, it is still bound by the underlying diffusion model's capabilities. If the base model (like Stable Diffusion v1.4) cannot understand a complex prompt or perform a specific pose change, PnP Inversion cannot magically fix that.

The authors suggest several future directions:

  1. Extending the "disentangled inversion" logic to video editing.
  2. Developing more comprehensive evaluation systems for image editing.
  3. Improving success rates for highly complex scenes where current diffusion models still struggle.

Summary updated

BibTeX
@inproceedings{ju2024pnp,
  author = {Xuan Ju and Ailing Zeng and Yuxuan Bian and Shaoteng Liu and Qiang Xu},
  title = {{PnP Inversion: Boosting Diffusion-based Editing with 3 Lines of Code}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=FoMZ4ljhVw},
}
Figure