Papers › Rethinking and Improving Relative Position Encoding for Vision Transformer
Rethinking and Improving Relative Position Encoding for Vision Transformer
Kan Wu, Houwen Peng, Minghao Chen, Jianlong Fu, Hongyang Chao
Relative position encoding (RPE) is important for transformer to capture sequence ordering of input tokens. General efficacy has been proven in natural language processing. However, in computer vision, its efficacy is not well studied and even remains controversial, e.g., whether relative position encoding can work equally well as absolute position? In order to clarify this, we first review existing relative position encoding methods and analyze their pros and cons when applied in vision transformers. We then propose new relative position encoding methods dedicated to 2D images, called image RPE (iRPE). Our methods consider directional relative distance modeling as well as the interactions between queries and relative position embeddings in self-attention mechanism. The proposed iRPE methods are simple and lightweight. They can be easily plugged into transformer blocks. Experiments demonstrate that solely due to the proposed encoding methods, DeiT and DETR obtain up to 1.5% (top-1 Acc) and 1.3% (mAP) stable improvements over their original versions on ImageNet and COCO respectively, without tuning any extra hyperparameters such as learning rate and weight decay. Our ablation and analysis also yield interesting findings, some of which run counter to previous understanding. Code and models are open-sourced at https://github.com/microsoft/Cream/tree/main/iRPE.
In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.
For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2107.14222")
Code
Syntology Ran 7 of 9 code samples harvested from 1 repository linked to this paper; 2 have no recorded run. Of those that ran: 4 ran · our draft was wrong; 3 ran · fixture could not drive it.
By repository: official repository: 9 samples from 1 repository, 7 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.
Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.
Code Syntology ran Syntology
9 samples harvested; 7 ran; 0 honoured the contract we drafted; 2 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.
Licence: 0 of the 9 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.
Harvested from microsoft/Cream. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.
Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.
Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.
affb9ad6b732b9e4 · report
434e634a4741440f · report
37c3e0e9c4bac792 · report
cd9ab56e1ede5e05 · report
f1ae97ecf9f3f3e1 · report
8a9e6d9d71d3c2f8 · report
5632af974aa9bde4 · report
c6d5f9784d683be8 · report
5bc74c794e5f05ef · report
Tasks
1 archive task tag without a task page not shown.
Results from the paper archive 2025-07-28
| Task | Dataset | Model | Metric | Value | Rank at snapshot | Leaderboard | Report |
|---|---|---|---|---|---|---|---|
| Image Classification | ImageNet | DeiT-B with iRPE-K | GFLOPs | 35.368 | #542 of 1060 | Archive leaderboard | report |
| Image Classification | ImageNet | DeiT-B with iRPE-K | Number of params | 87M | #542 of 1060 | Archive leaderboard | report |
| Image Classification | ImageNet | DeiT-B with iRPE-K | Top 1 Accuracy | 82.4% | #542 of 1060 | Archive leaderboard | report |
| Image Classification | ImageNet | DeiT-S with iRPE-QKV | GFLOPs | 9.770 | #642 of 1060 | Archive leaderboard | report |
| Image Classification | ImageNet | DeiT-S with iRPE-QKV | Top 1 Accuracy | 81.4% | #642 of 1060 | Archive leaderboard | report |
| Image Classification | ImageNet | DeiT-S with iRPE-QK | GFLOPs | 9.412 | #660 of 1060 | Archive leaderboard | report |
| Image Classification | ImageNet | DeiT-S with iRPE-QK | Top 1 Accuracy | 81.1% | #660 of 1060 | Archive leaderboard | report |
| Image Classification | ImageNet | DeiT-S with iRPE-K | GFLOPs | 9.318 | #675 of 1060 | Archive leaderboard | report |
| Image Classification | ImageNet | DeiT-S with iRPE-K | Number of params | 22M | #675 of 1060 | Archive leaderboard | report |
| Image Classification | ImageNet | DeiT-S with iRPE-K | Top 1 Accuracy | 80.9% | #675 of 1060 | Archive leaderboard | report |
| Image Classification | ImageNet | DeiT-Ti with iRPE-K | GFLOPs | 2.568 | #985 of 1060 | Archive leaderboard | report |
| Image Classification | ImageNet | DeiT-Ti with iRPE-K | Number of params | 6M | #985 of 1060 | Archive leaderboard | report |
| Image Classification | ImageNet | DeiT-Ti with iRPE-K | Top 1 Accuracy | 73.7% | #985 of 1060 | Archive leaderboard | report |
| Object Detection | COCO minival | DETR-ResNet50 with iRPE-K (300 epochs) | box AP | 42.3 | #157 of 220 | Archive leaderboard | report |
| Object Detection | COCO minival | DETR-ResNet50 with iRPE-K (150 epochs) | box AP | 40.8 | #175 of 220 | Archive leaderboard | report |
Ranks are positions in the archive's leaderboards as they stood at the 2025-07-28 snapshot. Results published since then are not among these rows, so a rank here is not a current standing.
Methods
Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections