Manuscript Offprint

arXiv:2609.35708

Mind the RefGAP: Correcting Reference Attention in Diffusion-Based Visual Editing

Yanan Wang, Shengcai Liao, Guangyi Liu, Xiaodan Liang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Reference-guided diffusion editors struggle to faithfully reproduce user-provided references. We identify a potential bottleneck in diffusion editors: many methods provide limited reference-attention allocation. For example, in LoomVideo, edit-region queries assign less than 1% of their attention mass to the reference. We introduce RefGAP, a training-free correction that determines logit-offset magnitudes online at each layer from the reference-attention mass measured during the forward pass. Positive offsets to reference logits strengthen reference usage by edit-region queries, while negative offsets for keep-region queries limit reference-induced changes outside the edit. Two global coefficients control the correction; they are selected once on validation data from four development diffusion editors and held fixed. Across seven diffusion-based image/video editors, RefGAP improves identity fidelity in head swapping and face swapping. RefGAP achieves a fidelity-preservation trade-off comparable to separately tuned constant edit-side biases, without per-approach strength sweeps. Additional experiments on virtual try-on and background replacement evaluate transfer beyond identity editing.

1 INTRODUCTION

Modern diffusion editors can condition on a user-provided reference image to edit a driving image or video, supporting tasks such as head swapping, face swapping, virtual try-on, and background replacement. Many recent systems adopt an in-context design (Jiang et al., 2025; Wu et al., 2025a;b; Black Forest Labs, 2025), in which reference tokens share the denoiser's attention sequence with the content being edited. Yet direct access to the reference does not guarantee fidelity.

Existing methods strengthen reference conditioning through task-specific training (Wang et al., 2025; Chen et al., 2024; Fang et al., 2024) or training-free manipulation of reference attention or features (Shin et al., 2025; Fan et al., 2024). However, inference-time interventions typically rely on fixed, empirically chosen coefficients that may require retuning across models or tasks. They do not explicitly couple reference-attention enhancement in edit regions with suppression in keep regions.

We partition each attention layer's keys into reference and rest tokens and compute the fraction ρ\rho of each query's attention mass assigned to the reference (fig. 2). Using an edit mask, we average ρ\rho separately over content queries in the edit and keep regions. The profiles reveal two patterns: some approaches exhibit substantially higher reference attention in edit versus keep regions within a localized layer band, typically in the network's second half; others assign little reference attention to edit queries across many layers, falling below 1% on LoomVideo (Wu et al., 2026). These patterns motivate selective layer intervention, while ρ\rho provides an online signal for correction strength.

Based on this measurement, we introduce RefGAP, a training-free correction named after the reference-attention gap it aims to bridge. Within a single forward pass, using statistics already produced by the attention computation, RefGAP reads the reference-attention masses in both regions and adds one scalar to every reference-key logit: a positive offset for edit-region queries, so they

*Emails:

{scliao@uaeu.ac.ae}

{yanan.wang, guangyi.liu, xiaodan.liang}@mbzuai.ac.ae, read the reference more, and a negative offset for keep-region queries, so the stronger reference signal does not pull the preserved content with it. The offset adapts to the measured reference-attention mass at each intervened layer and forward pass, reducing the need for model- or task-specific tuning.

We calibrate two global coefficients and establish a shared layer-selection rule on four development approaches (JoyAI-Video-Edit (Xiao et al., 2026), LoomVideo (Wu et al., 2026), FLUX.2-klein and FLUX.2-klein-base (Black Forest Labs, 2025)) using 40 head-swap validation clips. We freeze the coefficients, thresholds, and rule before applying them to three held-out approaches. Each approach requires one validation profiling run to determine its layer set under the fixed rule; this set is reused across tasks without tuning. Identity similarity improves on head-swap and face-swap tasks. Without task-specific retuning, virtual try-on fidelity improves across seven approaches, while background replacement yields mixed results, including a clear degradation on Qwen-Image-Edit (section 5).

To summarize, our contributions are:

• We measure reference-attention mass for edit and keep queries, revealing approach-dependent allocation patterns and limited reference attention in several approaches.

• We propose RefGAP, a training-free, two-sided attention correction that derives its per-layer strength online from the measured attention mass. RefGAP increases reference influence inside the edit while suppressing reference attention in the keep region.

• We demonstrate cross-approach and cross-task transfer using a single configuration calibrated once on 40 head-swap validation clips. Without retuning, it consistently boosts identity fidelity across seven approaches in head and face swapping (alongside an attribute-preservation trade-off), transfers to virtual try-on, and delineates transfer boundaries with mixed results on background replacement.

References (26)