KV-Edit: Training-Free Image Editing for Precise Background Preservation

Tianrui Zhu, Shiyi Zhang, Jiawei Shao, Yansong Tang

TL;DR

This paper introduces KV-Edit, a novel training-free image editing method that leverages KV cache in Diffusion Transformer (DiT) models to achieve precise background preservation. By caching and reusing background information, KV-Edit effectively decouples foreground editing from background manipulation, leading to more realistic and consistent edits without requiring additional training.

What Problem Does This Paper Address?

The core challenge in AI-powered image editing is maintaining background consistency while accurately reflecting user-specified edits. Existing methods often struggle with a trade-off: either they preserve the background too rigidly, leading to unnatural edits, or they allow too much background modification, resulting in a loss of the original scene's integrity. This is particularly problematic for tasks like object removal, where residual information from the original object can interfere with the desired outcome. Current approaches often rely on complex mechanisms, extensive hyperparameter tuning, or computationally expensive training, limiting their practical applicability.

Methods

KV-Edit tackles this problem by introducing a training-free approach that utilizes the KV cache mechanism within Diffusion Transformers (DiTs). Here's a breakdown of their key techniques:

  • KV Cache for Background Preservation: The core innovation is the use of KV cache, a technique common in Large Language Models (LLMs), for image editing. During the inversion process (converting an image to noise), KV cache stores the key and value pairs of background tokens at each attention layer and timestep.
  • Attention Decoupling: In the denoising phase, KV-Edit selectively reconstructs only the foreground regions. The attention mechanism is modified so that queries come only from foreground tokens, while keys and values incorporate both foreground and cached background information. This effectively allows foreground edits to be applied without altering the background.
  • Mask-Guided Editing: A mask is used to explicitly separate foreground and background regions, guiding the attention mechanism.
  • Enhancement Techniques (Optional):
    • Mask-guided inversion and reinitialization: To address challenges in object removal, they introduce strategies to disrupt residual information in surrounding tokens and reinitialize parts of the image.
  • Inversion-free approach: To reduce memory consumption, they propose an inversion-free method that computes the KV cache immediately after one step, allowing for O(1) space complexity.

Datasets

The paper evaluates its method on the PIE-Bench dataset, which contains 620 images with corresponding masks and text prompts. They specifically focus on tasks involving object removal, addition, and change, excluding style transfer tasks.

Key Insights and Ideas

  • KV Cache is a powerful tool for image editing: The paper demonstrates that a technique primarily used for LLM efficiency can be effectively adapted for precise image editing, particularly for background preservation.
  • Background tokens are "deterministic": The authors argue that background information is inherently stable and can be preserved rather than regenerated, which is the key to their method's success.
  • DiTs are well-suited for this approach: The attention-based architecture of DiTs allows for the decoupling of foreground and background processing, which is crucial for KV-Edit.
  • Object removal is a significant challenge: The paper highlights that residual information from the original object can persist and interfere with editing, necessitating specific enhancement strategies.
  • Training-free is practical: The ability to achieve state-of-the-art results without additional training makes KV-Edit highly accessible and efficient.

Key Results

  • Superior Background Preservation: KV-Edit significantly outperforms existing methods in metrics related to masked region preservation, often achieving scores far superior to baselines with PSNR below 30.
  • Competitive Image Quality: While prioritizing background preservation, KV-Edit still achieves competitive image quality, often ranking third-best among evaluated methods.
  • Optimal Text Alignment (with enhancements): With the reinitialization strategy, KV-Edit achieves optimal text alignment scores, particularly for object removal tasks.
  • User Study Validation: A user study showed that participants preferred KV-Edit over four popular baselines, with background preservation being a key factor in their satisfaction.
  • Memory Efficiency: The inversion-free implementation reduces memory complexity from O(N) to O(1), making it suitable for personal computers.

Limitations and Future Work

  • Content Retention Artifacts (Inversion-Free): The paper notes that the inversion-free method may occasionally result in content retention artifacts, though they leave a more detailed discussion for supplementary materials.
  • Mask Size Impact: For very large masks, the enhancement strategies (no-skip, reinitialization, attention mask) might lead to some discontinuities in generated images, suggesting they are optional and scenario-dependent.
  • Broader Applications: The authors express hope that their straightforward yet effective mechanism could inspire broader applications, such as video editing and multi-concept personalization.

Summary updated

BibTeX
@inproceedings{zhu2025kv,
  author = {Tianrui Zhu and Shiyi Zhang and Jiawei Shao and Yansong Tang},
  title = {{KV-Edit: Training-Free Image Editing for Precise Background Preservation}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2025},
}
Figure