GRAG: Continuous Image Editing Control for DiT Models

11月10日 Published inImage Tools

DiT-based image editors often force a binary choice: apply the edit or leave it. There is no fader for intensity. If you want a slightly redder rose rather than "stop-sign red," you are out of luck. Group Relative Attention Guidance (GRAG) changes that.

GRAG is a training-free, plug-and-play method for models built on the Diffusion-in-Transformer (DiT) architecture. It adds a dial to a process that previously only had an on-off switch.

How It Works

The mechanism is direct. Instead of altering model weights, GRAG reweights the difference between token attention and a shared attention bias. This intervention produces a continuous spectrum of editing strength. The math remains behind the scenes; the user simply gets a slider that works.

The result? If you prompt for a "redder rose," you can dial in the exact shade. If you want a "crochet bird," you get a smooth gradient from the original photo to a full yarn texture. When swapping "flowers" for "a surfboard," you control exactly how dominant the surfboard becomes in the frame.

Integration

GRAG integrates into existing DiT pipelines without retraining or fine-tuning. It has been validated with Qwen-Image-Edit and supports both single-image edits and batch processing via the PIE benchmark format.

Installation

Clone the repository and set up a clean environment:

git clone https://github.com/little-misfit/GRAG-Image-Editing.git
cd GRAG-Image-Editing/Qwen-Edit-GRAG
conda create -n grag python=3.10 -y
conda activate grag
pip install -r requirements.txt

Usage

The grag parameter is your primary control. Values between 0.8 and 1.7 typically yield the best results, and you can adjust the strength in increments as fine as 0.01.

  • Single Image: sh inference.sh
  • Batch Processing: sh PIE_test.sh
  • Gradio UI: python app.py

All outputs are saved automatically to the results/ directory.

Conclusion

There is no catch. This is a lightweight wrapper that preserves your existing workflow while adding the nuance of traditional slider-based tools to DiT models. For anyone tired of all-or-nothing image edits, GRAG is a subtle but effective upgrade.