Zero-Sum Attention as a Shift-Cancelling Adapter for Synthetic-to-Real Transfer

Models trained on rendered images, such as game-engine driving scenes or CAD object renders, fail on real photographs. Part of the reason is that a renderer's "look" is global. Its illumination model, texture smoothness and colour response mark every patch of every synthetic image in roughly the same way. Vision Transformers mix information between image patches with an attention step whose weights come from Softmax, a normalisation that makes every weight positive and makes each patch's weights sum to one. The attention output is therefore always a weighted average of patch features. A weighted average of vectors that all carry the same offset still carries that offset in full. However cleverly Softmax picks which patches to attend to, it passes the renderer's shared signature through untouched.

We propose a small change that is easy to test. In the attention layers of a pretrained Vision Transformer, we subtract a learned fraction of a uniform average from the Softmax weights, so that each patch's weights can sum to zero. Zero-sum weights are necessarily signed: some are negative. They cancel any component shared by all patches exactly, while attention can still select patches as before. The adapter adds one scalar per head, about 144 parameters for a 12-layer, 12-head model. The research question is whether the synthetic-to-real gap in a Transformer's internal features really is dominated by such shared components. If it is, zero-sum attention should close that part of the gap. If it is not, the method should visibly fail. We design the experiments so that both outcomes are informative.

Core Claim

Write the attention output for patch $i$ as $o_i = \sum_j w_{ij} v_j$, where $v_j$ is the value vector (the feature each patch contributes) of patch $j$ and $w_{ij}$ are attention weights. Suppose a domain shift adds the same vector $c$ to every value, so $v_j = u_j + c$. Then

$$o_i = \sum_j w_{ij} u_j + \Big(\sum_j w_{ij}\Big) c .$$

With Softmax, $\sum_j w_{ij} = 1$, and the full shift $c$ reaches the output. We use

$$w_{ij} = p_{ij} - \lambda_h \frac{1}{N},$$

where $p_{ij}$ is the pretrained Softmax weight, $N$ is the number of patches, and $\lambda_h \in [0,1]$ is a learned scalar for head $h$. The rows then sum to $1-\lambda_h$, so head $h$ passes only a fraction $1-\lambda_h$ of any shared shift. We also test a windowed variant, which replaces the global average $1/N$ with an average over a local window. It targets shifts shared within a region, such as a material's rendered texture, but it cancels them only approximately.

The claim is specific. The benefit of signed attention in sim-to-real transfer should come from the zero-sum property. Negativity alone should not produce it. We further predict that heads which learn a large $\lambda_h$ are the heads whose features carry the most domain information in their patch-mean. Keeping $\lambda_h$ per head matters because some heads, such as those carrying scene-level context the classifier needs, should keep their average while others discard it.

Relation to Prior Work

The signed-attention literature supplies the mechanism but never tests it under domain shift. ZeroS removes the zero-order Taylor term of Softmax so that weights sum to zero, a correction for what it calls a $1/N$ "averaging tax". It does this inside a linear-attention architecture trained from scratch, evaluated on MAD, WikiText-103 and ImageNet. We reuse its zero-sum idea in a different form: as a partial, per-head correction retrofitted onto a pretrained quadratic-attention model. Our motivation is also different. ZeroS aims at sharper contrast. We aim at invariance to shared shifts.

Several papers show that attention stays stable without Softmax's convexity and that negative weights suppress corruption. SimA replaces Softmax with $\ell_1$ normalisation. CoDA uses a tanh-and-sigmoid dual-affinity gate. IRNeXt uses tanh attention to cancel haze and noise. PolaFormer keeps the interactions between negative query and key features that non-negative linear kernels discard. These methods produce signed weights, but their rows need not sum to zero, so they do not cancel a shared offset. That makes them the right ablation for isolating whether the gain comes from zero-sum or from sign. Coeff-Tuning is the closest parameter-efficient relative. It learns a signed $H \times H$ matrix that mixes attention maps across heads, and it was evaluated on VTAB-1k and SDXL but never on unsupervised adaptation. The theory in Superiority of Multi-Head Attention constrains our argument: multi-head Softmax can already subtract by differencing heads. We therefore have to show that the explicit zero-sum form does better than head mixing, rather than assume it.

On the adaptation side, the relevant papers motivate the problem. Each changes only which patches Softmax attention emphasises. CDTrans argues that source-target cross-attention filters noise by giving mismatched pairs small positive weights. TVT multiplies attention by patch transferability scores from a domain discriminator. Uni-UVPT adapts a frozen Swin-B to Cityscapes with prompt adapters built on Softmax cross-attention. By the argument above, none of these can remove a shift that every patch shares. Our adapter is complementary and can be added to any of them.

Research Program

The work has three parts, and the first decides whether the other two are worth running.

The first part is a diagnostic study with no training. We take ImageNet-1K DeiT-B features, the backbone CDTrans uses, on VisDA-C synthetic and real images. At every layer and head, we split each image's value vectors into their patch-mean and the residual after subtracting that mean. We then train linear probes to classify domain from each part and measure the domain gap (maximum mean discrepancy) carried by each. The hypothesis predicts that the patch-mean carries most of the domain information while the residual carries most of the class information.

We state the failure case in advance. If a domain probe on mean-removed values is nearly as accurate as one on raw values, the shared-shift account is wrong for this benchmark, and we will report that rather than proceed to leaderboard claims. We repeat the analysis with windowed means to see whether regional shifts add to the global one.

The second part is the adapter itself. We insert the $\lambda_h$ correction into every attention layer and initialise $\lambda_h = 0$, so the model starts exactly as the pretrained network. We then train under two regimes. The first is a deliberately simple self-training recipe on unlabeled target data: source cross-entropy plus target entropy minimisation and diversity terms of the kind SHOT uses. The second adds the adapter to CDTrans's full pipeline. For segmentation, we add the adapter to the frozen Swin-B used by Uni-UVPT, working in its source-free setting.

The third part is mechanistic verification. We correlate the learned $\lambda_h$ with each head's patch-mean domain-probe accuracy from the first part. We check whether the domain probe's accuracy on output features drops after adaptation. We also test whether real-image accuracy survives artificial global colour or illumination shifts applied at test time, a controlled case where the invariance should hold exactly.

Baselines

The do-nothing reference is the source-only DeiT-B trained on synthetic VisDA-C renders and tested on real images, run by us under the same training schedule. The only historical anchor in the file is much older: VisDA reports AlexNet collapsing from 99% on synthetic data to 28% on real COCO, and 21.4 mIoU source-only for GTA5 to Cityscapes. We also report the plain self-training recipe without the adapter. The difference between these two runs is the adapter's contribution in isolation.

The strongest existing competitor for classification is CDTrans, which reports 88.4% on VisDA-2017 with an ImageNet-1K DeiT backbone (CDTrans). It is the strongest because it is the best Transformer result in the file under the same pretraining. TVT's 86.7% (TVT) relies on ImageNet-21K pretraining, and CDTrans reports TVT at 83.9% under its own comparison. We rerun CDTrans from its released configuration with and without our adapter, on identical data, epochs and seeds, and with the same hyperparameter search budget for both arms. A convincing result has two parts. The simple self-training recipe with the adapter should come close to CDTrans while using one branch instead of three. Adding the adapter to CDTrans should improve it by more than the spread across seeds.

For source-free segmentation the reference is Uni-UVPT at 56.9% mIoU on GTA5 to Cityscapes (Uni-UVPT). We add the adapter to its frozen backbone without changing anything else. The file reports no SYNTHIA-to-Cityscapes result for Uni-UVPT, so we rerun it there ourselves.

Three ablations isolate the key ingredient. Fixed global value-centering sets $\lambda_h = 1$ in every head; it tests whether learning per-head fractions matters. Signed but not zero-sum attention uses SimA-style $\ell_1$ normalisation and tanh-gated attention in the CoDA and IRNeXt style, fine-tuned under the same recipe; it tests whether sign alone helps. Coeff-Tuning's signed head mixing, trained under the same adaptation losses, tests explicit zero-sum against subtraction built from heads.

Why not just…?

Why not just centre the values, or add instance normalisation across patches? Global value-centering is exactly our method with every $\lambda_h = 1$, so it is a real threat. If it matches the learned version, the honest conclusion is that a one-line centering step is enough. That conclusion would still be new for sim-to-real Transformers and would be worth reporting. We expect learned $\lambda_h$ to win because some heads carry scene-level context in their mean, and the diagnostic study shows directly which heads do. The fixed-centering ablation settles the question.

Why not just fine-tune with LoRA or prompts? These methods change the query, key and value projections or add tokens, but every head's weights still sum to one. Coeff-Tuning argues that such methods stay inside the convex hull of the attention maps. However, a LoRA change to the value projection can, in principle, learn to map a shared shift to near zero if that shift occupies a consistent direction in feature space. So LoRA is a genuine competitor. We run LoRA at matched and at much larger parameter counts. Our prediction is that it helps less on test-time global shifts, where the shift direction varies from image to image and a single learned projection cannot anticipate it, while zero-sum cancellation needs no knowledge of the direction.

Why not just rely on multi-head subtraction or TVT-style transferability weighting? Multi-head Softmax can in principle difference heads, as Superiority of Multi-Head Attention proves. The Coeff-Tuning ablation gives that capability its best explicit form. Transferability weighting as in TVT only rescales positive weights, so by the core equation it cannot remove a shift every patch shares. It is still strong in practice, so it stays in the comparison.

Why not just use larger pretraining or style augmentation? Larger pretraining raises every method's numbers, and CDTrans reports that its gains over SHOT persist under matched backbones. We control for this by holding pretraining fixed. Style augmentation randomises the shift during source training, whereas our adapter removes the shift inside the network. We combine the two to test whether they are complementary or redundant.

Decisive Experiments

The first decisive check is the VisDA-C diagnostic. The programme continues only if the patch-mean holds most of the domain-probe accuracy. The second is the three-way comparison on VisDA-C and GTA5 to Cityscapes between zero-sum, signed-but-not-zero-sum and fixed centering. The hypothesis predicts that only the zero-sum variants help, and that learned $\lambda_h$ beats fixed centering. The third is the correlation between learned $\lambda_h$ and per-head patch-mean domain information.

As a specificity control, we run the same adapter on Office-Home pairs whose domains differ less in rendering style. CDTrans reports 80.5% average accuracy on Office-Home and TVT reports 83.6%. There the gains should shrink. If they are just as large, the benefit is generic regularisation rather than cancellation of shared shifts, and we will say so. Finally, the test-time global colour and illumination shift experiment checks the exact invariance the equation predicts: accuracy should degrade less as $\lambda_h$ approaches 1.