Paper · 2021-06-17 · cs.CV, cs.LG
XCiT: Cross-Covariance Image Transformers
XCiT replaces token-to-token self-attention with cross-covariance attention (XCA), which attends across feature channels. Its l2-normalised query-key channel map makes cost linear in token count. Blocks add a depth-wise local patch interaction and an FFN. Author-reported: 86.0% ImageNet-1k top-1 (L24, 8x8 patches, 384px, distilled); 48.5 COCO box AP (M24/8).
Vision Transformer (ViT) backbonesLinear attentionSelf-attentionEfficient vision backbonesvision-transformerself-attentionlinear-complexityimage-classificationobject-detectionsemantic-segmentationself-supervised-learning
arXivPDFCodeMarkdown20 min read
AI-compiled by claude-haiku-5-5 on 2026-10-24, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.
In plain words
A transformer for images looks at every small patch of the picture against every other patch. That works very well, but the work grows very fast as the picture gets bigger, so high-resolution images become slow and memory-hungry.
XCiT changes what the attention compares. Instead of asking which patches relate to which, it asks which feature channels relate to which, looking across all the patches at once. The table it builds has a fixed size, so it does not get bigger when the image has more patches. The network adds two small steps: a light convolution so that neighbouring patches can exchange information directly, and the usual per-patch feed-forward step. The authors' point is that this keeps the accuracy of a transformer, scales to large images more like a convolutional network, and copes better when the test image size differs from the training size.
TL;DR
XCiT is a vision transformer whose core operation, cross-covariance attention,
computes attention between feature channels instead of between image patches. Its
cost is linear in the number of patches, so high-resolution inputs stay affordable
§1, §3.2. The authors describe the aim as combining transformer accuracy with the
scalability of convolutional networks §1. They report accuracy on par with DeiT
and CaiT in comparable settings, and better dense-prediction results than ResNet and
several transformer backbones §1. Before implementing, read Paper vs code: the
equation's softmax axis and temperature form differ from the released code, and the
FPN adapter and several training details are only in the code.
Problem
Token self-attention compares all N tokens with each other. Its time cost is O(N²d) and its memory cost is O(hN² + Nd) for h heads §3.2, Complexity analysis. For a w×h image the paper writes this as O(w²h²) §1. This makes the method expensive for high-resolution images and dense tasks such as detection and segmentation §1.
Existing remedies are approximate attention and pyramidal designs. The authors argue that they either lose accuracy or stay too costly for very large images §1. Learned position embeddings must also be interpolated when the input resolution changes §3.3, Handling images of varying resolution.
Method
XCiT is a columnar network: it keeps the same spatial resolution (token count) across all layers §3.3. Each XCiT layer has three residual sub-blocks in this order: cross-covariance attention (XCA), local patch interaction (LPI) and a feed-forward network (FFN). Each sub-block is preceded by LayerNorm fig. 1 §3.3. Classification adds class-attention layers on top §3.3.
- Token self-attention, the baseline. Tokens X (N × d) are projected to queries, keys and values. Attention is a softmax over Q Kᵀ / √d_k, then a weighted sum of V §3.1.
- Cross-covariance instead of Gram matrix. The token-side matrix Q Kᵀ is N × N. The paper uses the d × d matrix Kᵀ Q instead, which can be computed in time linear in N §3.1. The motivation is the known relation between the Gram and covariance matrices of X §3.1.
- Unit-normalise channels. Each channel (column of length N) of Q and K is scaled to unit ℓ2 norm over the tokens. Every entry of the d × d matrix then lies in [−1, 1] §3.2. The authors report that this norm control strongly stabilises training, especially with variable token counts §3.2.
- Temperature. A learnable temperature τ scales the products before the
softmax, so the distribution can be sharper or flatter. The paper's equation
divides by τ §3.2 eq. 1. The code multiplies by a per-head parameter
initialised to 1 (see
Paper vs code). - Softmax and output. Attention weights come from the softmax of the cross-covariance. Each output feature is a convex combination of the value features in its group §3.2 eq. 1.
- Heads. Channels are split into h groups, each with its own Q, K and V projections. Attention is block-diagonal across groups. This reduces the aggregation cost by a factor h and the authors found it easier to optimise and better in accuracy §3.2. Total cost is O(N d² / h) time and O(d² / h + N d) memory §3.2.
- Local patch interaction (LPI). Tokens are reshaped onto their 2-D grid. Two depth-wise 3 × 3 convolutions with Batch Normalization and GELU in between are applied, then the tokens are reshaped back. This adds explicit communication between neighbouring patches, which XCA alone does not provide §3.3.
- Feed-forward network. A point-wise MLP with one hidden layer of 4d units §3.3.
- Patch embedding. The default patch size is 16 × 16. The paper also uses 8 × 8 patches, which it notes can improve performance §3.3. The embedding is a convolutional projection, as in LeViT, rather than a linear projection §3.3 tab. 4.
- Positional encoding. A 2-D sinusoidal encoding is generated in a 64-d intermediate space and then linearly projected to d. It is added to the tokens and needs no interpolation when the image size changes §3.3 app. B.1.
- Class attention for classification. Two layers (default in the code) let a CLS token read the patch tokens, one head at a time, in the CaiT style §3.3 xcit.py. The count of these layers is not stated in the paper.
- LayerScale. Each residual branch is scaled by a learnable per-channel value, initialised to a model-specific ε §4.1 app. B.3 tab. B.1.
- Head. The CLS token after the final LayerNorm feeds a linear classifier xcit.py.
The core operation, in the paper's notation eq. 1:
\text{XC-Attention}(Q, K, V) = V\,\mathcal{A}_{\text{XC}}(K, Q), \qquad \mathcal{A}_{\text{XC}}(K, Q) = \text{Softmax}\left(\hat{K}^\top \hat{Q} / \tau\right) eq. 1
Here Q̂ and K̂ are the channel-normalised queries and keys from step 3. The orientation of the softmax is ambiguous in the notation. The pseudocode below follows the released code, which is the reading consistent with the text's "convex combination" wording.
# Cross-covariance attention (XCA), one block [eq. 1] [alg. 1]
# Input: tokens (B, N, d)
# Output: tokens (B, N, d)
def xca(tokens, num_heads, temperature):
# Project every token to queries, keys and values [§3.2]
queries = linear_q(tokens) # (B, N, d)
keys = linear_k(tokens) # (B, N, d)
values = linear_v(tokens) # (B, N, d)
# Split the channels into heads, d / h channels each [§3.2]
queries = split_heads(queries, num_heads) # (B, h, N, d/h)
keys = split_heads(keys, num_heads) # (B, h, N, d/h)
values = split_heads(values, num_heads) # (B, h, N, d/h)
# Scale each channel to unit length over the N tokens [§3.2]
# [code: xcit.py#L247-L248]
queries = l2_normalize(queries, axis=tokens)
keys = l2_normalize(keys, axis=tokens)
# Per-head d/h x d/h cross-covariance, times a learned temperature
# [§3.2] [code: xcit.py#L250]
scores = transpose(queries) @ keys * temperature # (B, h, d/h, d/h)
# Softmax over key channels, separately for each query channel
# [§3.2] [code: xcit.py#L251]
weights = softmax(scores, axis=key_channels)
# Each output channel is a convex mix of its head's value channels
# [§3.2]
mixed = values @ transpose(weights) # (B, h, N, d/h)
return merge_heads(mixed) # (B, N, d)# One XCiT block: XCA, then LPI, then FFN [fig. 1] [§3.3]
# Input: tokens (B, N, d); patch grid height and width
# Output: tokens (B, N, d)
def xcit_block(tokens, grid_height, grid_width):
# Cross-covariance attention on the normalised tokens, with
# LayerScale [§3.3] [§4.1] [code: xcit.py#L288-L291]
tokens = tokens + layerscale_attn * xca(layer_norm(tokens))
# Depth-wise local patch interaction on the 2-D grid [§3.3]
tokens = tokens + layerscale_lpi * lpi(
layer_norm(tokens), grid_height, grid_width
)
# Point-wise feed-forward network, 4d hidden units [§3.3]
tokens = tokens + layerscale_ffn * ffn(layer_norm(tokens))
return tokensHyperparameters
Model configurations tab. 1. Depth, width d, heads h and parameter counts for the seven models in the paper. Top-1 is ImageNet-1k validation accuracy. "dist." means trained with hard distillation from a convolutional teacher §4.1. "↑" means fine-tuned and tested at 384 × 384 tab. 1 caption.
| Model | Depth | d | heads h | #params | GFLOPs @224/16 | GFLOPs @384/8 | top-1 @224/16 | top-1 @224/16 dist. | top-1 @384/8 dist. ↑ |
|---|---|---|---|---|---|---|---|---|---|
| XCiT-N12 | 12 | 128 | 4 | 3M | 0.5 | 6.4 | 69.9 | 72.2 | 77.8 |
| XCiT-T12 | 12 | 192 | 4 | 7M | 1.2 | 14.3 | 77.1 | 78.6 | 82.4 |
| XCiT-T24 | 24 | 192 | 4 | 12M | 2.3 | 27.3 | 79.4 | 80.4 | 83.7 |
| XCiT-S12 | 12 | 384 | 8 | 26M | 4.8 | 55.6 | 82.0 | 83.3 | 85.1 |
| XCiT-S24 | 24 | 384 | 8 | 48M | 9.1 | 106.0 | 82.6 | 83.9 | 85.6 |
| XCiT-M24 | 24 | 512 | 8 | 84M | 16.2 | 188.0 | 82.7 | 84.3 | 85.8 |
| XCiT-L24 | 24 | 768 | 16 | 189M | 36.1 | 417.9 | 82.9 | 84.9 | 86.0 |
Stochastic depth and LayerScale ε tab. B.1 app. B.3. Per model, for patch sizes 8 and 16 unless stated. The paper calls the rate "drop rate" and ε the LayerScale initial value.
| Model | Patch size | Stochastic depth d_r | LayerScale ε |
|---|---|---|---|
| XCiT-N12 | 8 & 16 | 0.0 | 1.0 |
| XCiT-T12 | 8 & 16 | 0.0 | 1.0 |
| XCiT-T24 | 8 & 16 | 0.05 | 1e-5 |
| XCiT-S12 | 8 & 16 | 0.05 | 1.0 |
| XCiT-S24 | 8 & 16 | 0.1 | 1e-5 |
| XCiT-M24 | 8 & 16 | 0.15 | 1e-5 |
| XCiT-L24 | 16 | 0.25 | 1e-5 |
| XCiT-L24 | 8 | 0.3 | 1e-5 |
ImageNet-1k classification training §4.1.
- Stated: 400 epochs; AdamW optimiser; cosine learning-rate decay; the DeiT training recipe; LayerScale; stochastic depth adjusted per model (values above); images cropped with ratio 1.0 for evaluation, following CaiT §4.1.
- Not stated in the paper: batch size, base learning rate, weight decay, warm-up, label smoothing, mixup/cutmix and augmentation strengths (they are said to follow the DeiT recipe, which this paper does not restate).
- Defaults in the released training script are listed in
Paper vs code; they are not the paper's stated values.
Object detection and instance segmentation §4.2 app. B.2.
- Mask R-CNN with FPN on COCO, 36 epochs (3× schedule) after ImageNet-1k pre-training.
- AdamW, learning rate 1e-4, weight decay 0.05, batch size 16.
- Multi-scale training and augmentation following DETR §4.2.
- Features are taken from layers [4, 6, 8, 12] for 12-layer models and [8, 12, 16, 24] for 24-layer models, and rescaled to strides 4, 8, 16 and 32 app. B.2.
Semantic segmentation (ADE20k) §4.3.
- Semantic FPN for 80k iterations and UperNet for 160k iterations.
- AdamW, learning rate 6e-5, weight decay 0.01, batch size 16, single-scale testing.
- Same FPN feature extraction as detection §4.3.
Self-supervised learning (DINO) tab. 3.
- 300 epochs, ImageNet-1k. Crop ratio 0.875 for consistency with DINO, except the last row, which uses 1.0 (80.7% → 80.9%) tab. 3 caption.
Results
Author-reported. Setup: ImageNet-1k (1.28M training, 50k validation, 1000 classes) §4.1; COCO (118k training, 5k validation, 80 classes) §4.2; ADE20k (20k training, 5k validation, 150 classes) §4.3. Memory and throughput were measured at batch size 64 on one V100-32GB fig. 2 tab. D.5. Models are trained on ImageNet-1k only unless stated.
ImageNet-1k and ImageNet-V2 top-1, supervised tab. 2. Columns: parameters, GFLOPs, test resolution, ImageNet-1k validation and ImageNet-V2. "dist." = distilled. "↑" = fine-tuned at 384 and tested at 384.
| Model | #params | FLOPs | Res. | ImNet | V2 |
|---|---|---|---|---|---|
| EfficientNet-B5 RA | 30M | 9.9B | 456 | 83.7 | – |
| RegNetY-4GF | 21M | 4.0B | 224 | 80.0 | 72.4 |
| DeiT-S dist. | 22M | 4.6B | 224 | 81.2 | 68.5 |
| Swin-T | 29M | 4.5B | 224 | 81.3 | – |
| CaiT-XS24 dist. ↑ | 26M | 19.3B | 384 | 84.1 | 74.1 |
| XCiT-S12/16 dist. | 26M | 4.8B | 224 | 83.3 | 72.5 |
| XCiT-S12/16 dist. ↑ | 26M | 14.3B | 384 | 84.7 | 74.1 |
| XCiT-S12/8 dist. ↑ | 26M | 55.6B | 384 | 85.1 | 74.8 |
| EfficientNet-B7 RA | 66M | 37.0B | 600 | 84.7 | – |
| NFNet-F0 | 72M | 12.4B | 256 | 83.6 | 72.6 |
| RegNetY-8GF | 39M | 8.0B | 224 | 81.7 | 72.4 |
| TNT-B | 66M | 14.1B | 224 | 82.8 | – |
| Swin-S | 50M | 8.7B | 224 | 83.0 | – |
| CaiT-S24 dist. ↑ | 47M | 32.2B | 384 | 85.1 | 75.4 |
| XCiT-S24/16 dist. | 48M | 9.1B | 224 | 83.9 | 73.3 |
| XCiT-S24/16 dist. ↑ | 48M | 26.9B | 384 | 85.1 | 74.6 |
| XCiT-S24/8 dist. ↑ | 48M | 105.9B | 384 | 85.6 | 75.7 |
| Fix-EfficientNet-B8 | 87M | 89.5B | 800 | 85.7 | 75.9 |
| RegNetY-16GF | 84M | 16.0B | 224 | 82.9 | 72.4 |
| Swin-B ↑ | 88M | 47.0B | 384 | 84.2 | – |
| DeiT-B dist. ↑ | 87M | 55.5B | 384 | 85.2 | 75.2 |
| CaiT-S48 dist. ↑ | 89M | 63.8B | 384 | 85.3 | 76.2 |
| XCiT-M24/16 dist. | 84M | 16.2B | 224 | 84.3 | 73.6 |
| XCiT-M24/16 dist. ↑ | 84M | 47.7B | 384 | 85.4 | 75.1 |
| XCiT-M24/8 dist. ↑ | 84M | 187.9B | 384 | 85.8 | 76.1 |
| NFNet-F2 | 194M | 62.6B | 352 | 85.1 | 74.3 |
| NFNet-F3 | 255M | 114.8B | 416 | 85.7 | 75.2 |
| CaiT-M24 dist. ↑ | 186M | 116.1B | 384 | 85.8 | 76.1 |
| XCiT-L24/16 dist. | 189M | 36.1B | 224 | 84.9 | 74.6 |
| XCiT-L24/16 dist. ↑ | 189M | 106.0B | 384 | 85.8 | 75.8 |
| XCiT-L24/8 dist. ↑ | 189M | 417.8B | 384 | 86.0 | 76.6 |
Self-supervised ImageNet-1k with DINO tab. 3. Linear and k-NN accuracy.
| SSL method | Model | #params | FLOPs | Linear | k-NN |
|---|---|---|---|---|---|
| MoBY | Swin-T | 29M | 4.5B | 75.0 | – |
| DINO | ResNet-50 | 23M | 4.1B | 74.5 | 65.6 |
| DINO | ViT-S/16 | 22M | 4.6B | 76.1 | 72.8 |
| DINO | ViT-S/8 | 22M | 22.4B | 79.2 | 77.2 |
| DINO | XCiT-S12/16 | 26M | 4.9B | 77.8 | 76.0 |
| DINO | XCiT-S12/8 | 26M | 18.9B | 79.2 | 77.1 |
| DINO | ViT-B/16 | 87M | 17.5B | 78.2 | 76.1 |
| DINO | ViT-B/8 | 87M | 78.2B | 80.1 | 77.4 |
| DINO | XCiT-M24/16 | 84M | 16.2B | 78.8 | 76.4 |
| DINO | XCiT-M24/8 | 84M | 64.0B | 80.3 | 77.9 |
| DINO | XCiT-M24/8 ↑384 | 84M | 188.0B | 80.9 | – |
Ablations on XCiT-S12 with ImageNet-1k top-1 tab. 4.
| Model | Ablation | ImNet top-1 |
|---|---|---|
| XCiT-S12/16 | Baseline | 82.0 |
| XCiT-S12/8 | Baseline | 83.4 |
| XCiT-S12/16 | Linear patch projection | 81.1 |
| XCiT-S12/8 | Linear patch projection | 83.1 |
| XCiT-S12/16 | Without LPI | 80.8 |
| XCiT-S12/16 | Without XCA layer | 75.9 |
| XCiT-S12/16 | Without ℓ2 normalisation | failed |
| XCiT-S12/16 | Without learned temperature τ | 81.8 |
The "Without XCA layer" row removes the XCA layer and reports a 6.1-point drop §4.1 analysis. The authors also state that the convolutional patch projection and LPI speed up training §4.1 analysis.
COCO object detection and instance segmentation, Mask R-CNN with FPN, 3× schedule tab. 5. Box AP (AP^b) and mask AP (AP^m) on mini-val. Backbones are pre-trained on ImageNet-1k. Numbers for Swin are taken from the Swin authors' code §4.2.
| Backbone | #params | AP^b | AP^b 50 | AP^b 75 | AP^m | AP^m 50 | AP^m 75 |
|---|---|---|---|---|---|---|---|
| ResNet18 | 31.2M | 36.9 | 57.1 | 40.0 | 33.6 | 53.9 | 35.7 |
| PVT-Tiny | 32.9M | 39.8 | 62.2 | 43.0 | 37.4 | 59.3 | 39.9 |
| ViL-Tiny | 26.9M | 41.2 | 64.0 | 44.7 | 37.9 | 59.8 | 40.6 |
| XCiT-T12/16 | 26.1M | 42.7 | 64.3 | 46.4 | 38.5 | 61.2 | 41.1 |
| XCiT-T12/8 | 25.8M | 44.5 | 66.4 | 48.8 | 40.3 | 63.5 | 43.2 |
| ResNet50 | 44.2M | 41.0 | 61.7 | 44.9 | 37.1 | 58.4 | 40.1 |
| PVT-Small | 44.1M | 43.0 | 65.3 | 46.9 | 39.9 | 62.5 | 42.8 |
| ViL-Small | 45.0M | 43.4 | 64.9 | 47.0 | 39.6 | 62.1 | 42.4 |
| Swin-T | 47.8M | 46.0 | 68.1 | 50.3 | 41.6 | 65.1 | 44.9 |
| XCiT-S12/16 | 44.3M | 45.3 | 67.0 | 49.5 | 40.8 | 64.0 | 43.8 |
| XCiT-S12/8 | 43.1M | 47.0 | 68.9 | 51.7 | 42.3 | 66.0 | 45.4 |
| ResNet101 | 63.2M | 42.8 | 63.2 | 47.1 | 38.5 | 60.1 | 41.3 |
| ResNeXt101-32 | 62.8M | 44.0 | 64.4 | 48.0 | 39.2 | 61.4 | 41.9 |
| PVT-Medium | 63.9M | 44.2 | 66.0 | 48.2 | 40.5 | 63.1 | 43.5 |
| ViL-Medium | 60.1M | 44.6 | 66.3 | 48.5 | 40.7 | 63.8 | 43.7 |
| Swin-S | 69.1M | 48.5 | 70.2 | 53.5 | 43.3 | 67.3 | 46.6 |
| XCiT-S24/16 | 65.8M | 46.5 | 68.0 | 50.9 | 41.8 | 65.2 | 45.0 |
| XCiT-S24/8 | 64.5M | 48.1 | 69.5 | 53.0 | 43.0 | 66.5 | 46.1 |
| ResNeXt101-64 | 101.9M | 44.4 | 64.9 | 48.8 | 39.7 | 61.9 | 42.6 |
| PVT-Large | 81.0M | 44.5 | 66.0 | 48.3 | 40.7 | 63.4 | 43.7 |
| ViL-Large | 76.1M | 45.7 | 67.2 | 49.9 | 41.3 | 64.4 | 44.5 |
| XCiT-M24/16 | 101.1M | 46.7 | 68.2 | 51.1 | 42.0 | 65.6 | 44.9 |
| XCiT-M24/8 | 98.9M | 48.5 | 70.3 | 53.4 | 43.7 | 67.5 | 46.9 |
ADE20k semantic segmentation, single-scale mIoU tab. 6. Left block: Semantic FPN. Right block: UperNet. Params are the segmentation model's parameter count as listed in the paper. The paper notes that it excludes comparisons with models pre-trained on larger datasets tab. 6 caption.
| Backbone | FPN #params | FPN mIoU | UperNet #params | UperNet mIoU |
|---|---|---|---|---|
| ResNet18 | 15.5M | 32.9 | – | – |
| PVT-Tiny | 17.0M | 35.7 | – | – |
| XCiT-T12/16 | 8.4M | 38.1 | 33.7M | 41.5 |
| XCiT-T12/8 | 8.4M | 39.9 | 33.7M | 43.5 |
| ResNet50 | 28.5M | 36.7 | 66.5M | 42.0 |
| PVT-Small | 28.2M | 39.8 | – | – |
| Swin-T | – | – | 59.9M | 44.5 |
| XCiT-S12/16 | 30.4M | 43.9 | 52.4M | 45.9 |
| XCiT-S12/8 | 30.4M | 44.2 | 52.3M | 46.6 |
| ResNet101 | 47.5M | 38.8 | 85.5M | 43.8 |
| ResNeXt101-32 | 47.1M | 39.7 | – | – |
| PVT-Medium | 48.0M | 41.6 | – | – |
| Swin-S | – | – | 81.0M | 47.6 |
| XCiT-S24/16 | 51.8M | 44.6 | 73.8M | 46.9 |
| XCiT-S24/8 | 51.8M | 47.1 | 73.8M | 48.1 |
| ResNeXt101-64 | 86.4M | 40.2 | – | – |
| PVT-Large | 65.1M | 42.1 | – | – |
| Swin-B | – | – | 121.0M | 48.1 |
| XCiT-M24/16 | 90.8M | 45.9 | 109.0M | 47.6 |
| XCiT-M24/8 | 90.8M | 46.9 | 108.9M | 48.4 |
The PVT-Tiny FPN parameter count is printed as "35.7M" for mIoU in the source; the value above is the number as written there.
Transfer learning after ImageNet-1k pre-training, top-1 tab. D.2. Models fine-tuned on each dataset.
| Architecture | CIFAR-10 | CIFAR-100 | Flowers-102 | Cars | iNat-2018 | iNat-2019 |
|---|---|---|---|---|---|---|
| EfficientNet-B7 | 98.9 | 91.7 | 98.8 | 94.7 | – | – |
| ViT-B/16 | 98.1 | 87.1 | 89.5 | – | – | – |
| ViT-L/16 | 97.9 | 86.4 | 89.7 | – | – | – |
| DeiT-B/16 dist. | 99.1 | 91.3 | 98.8 | 92.9 | 73.7 | 78.4 |
| XCiT-S24/16 dist. | 99.1 | 91.2 | 97.4 | 92.8 | 68.8 | 76.1 |
| XCiT-M24/16 dist. | 99.1 | 91.4 | 98.2 | 93.4 | 72.6 | 78.1 |
| XCiT-L24/16 dist. | 99.1 | 91.3 | 98.3 | 93.7 | 75.6 | 79.3 |
More model sizes, with 16 and 8 patches at several test resolutions tab. D.1. The source labels the head-count column "#Blocks". For 16 × 16 patches the columns are GFLOPs at 224, top-1 at 224, top-1 at 224 with distillation, and top-1 at 384 (fine-tuned, distilled). The same four values for 8 × 8 patches follow the GFLOPs column.
| Model | Depth | d | #heads | #params | P16 GFLOPs | P16 @224 | P16 @224 dist. | P16 @384 ↑ | P8 GFLOPs | P8 @224 | P8 @224 dist. | P8 @384 ↑ |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| XCiT-N12 | 12 | 128 | 4 | 3M | 0.5 | 69.9 | 72.2 | 75.4 | 2.1 | 73.8 | 76.3 | 77.8 |
| XCiT-T12 | 12 | 192 | 4 | 7M | 1.2 | 77.1 | 78.6 | 80.9 | 4.8 | 79.7 | 81.2 | 82.4 |
| XCiT-T24 | 24 | 192 | 4 | 12M | 2.3 | 79.4 | 80.4 | 82.6 | 9.2 | 81.9 | 82.6 | 83.7 |
| XCiT-S12 | 12 | 384 | 8 | 26M | 4.8 | 82.0 | 83.3 | 84.7 | 18.9 | 83.4 | 84.2 | 85.1 |
| XCiT-S24 | 24 | 384 | 8 | 48M | 9.1 | 82.6 | 83.9 | 85.1 | 36.0 | 83.9 | 84.9 | 85.6 |
| XCiT-M24 | 24 | 512 | 8 | 84M | 16.2 | 82.7 | 84.3 | 85.4 | 63.9 | 83.7 | 85.1 | 85.8 |
| XCiT-L24 | 24 | 768 | 16 | 189M | 36.1 | 82.9 | 84.9 | 85.8 | 142.2 | 84.4 | 85.4 | 86.0 |
Inference memory and throughput at batch size 64 on V100-32GB tab. D.5. Each cell shows images per second, then peak memory in MB fig. 2. OOM means out of memory.
| Model | #params | ImNet top-1 | 224² im/s | 224² MB | 384² im/s | 384² MB | 512² im/s | 512² MB | 1024² im/s | 1024² MB |
|---|---|---|---|---|---|---|---|---|---|---|
| ResNet-50 | 25M | 79.0 | 1171 | 772 | 434 | 2078 | 245 | 3618 | 61 | 14178 |
| DeiT-S | 22M | 79.9 | 974 | 433 | 263 | 1580 | 116 | 4020 | N/A | OOM |
| CaiT-S12 | 26M | 80.8 | 671 | 577 | 108 | 2581 | 38 | 7117 | N/A | OOM |
| PVT-Small | 25M | 79.8 | 777 | 1266 | 256 | 3142 | 134 | 5354 | N/A | OOM |
| Swin-T | 29M | 81.3 | 704 | 1386 | 220 | 3890 | 120 | 6873 | 29 | 26915 |
| XCiT-S12/16 | 26M | 82.0 | 781 | 731 | 266 | 1372 | 151 | 2128 | 37 | 7312 |
Image retrieval (appendix) tab. D.4 app. D.3. Models pre-trained on ImageNet-1k only, using the CLS token, VLAD or ASMK aggregation over patch features. The best Holidays mAP in the table is 92.3 (XCiT-S12/8, ASMK, k=65536). On ROxford5k, the best medium score is 42.0 (XCiT-S12/8, ASMK, k=65536) and the best hard score is 15.0 (XCiT-S12/16, ASMK, k=65536). These are author-reported, and the table's default resolution is 768 tab. D.4 caption. The paper says the method is slightly below a ResNet-50 baseline on ROxford and better on Holidays app. D.3.
Robustness to test resolution fig. 3. XCiT-S12 keeps more accuracy than DeiT-S when the test resolution differs from the 224 training resolution, and benefits more from the test-time resolution increase effect (FixRes). The paper describes these curves in words and gives no table of values.
Paper vs code
Compared against the official repository facebookresearch/xcit at
code_commit 82f5291f412604970c39a912586e008ec009cdca xcit.py.
The paper's sections and tables are cited as in the arXiv version.
- Temperature form. Paper: the cross-covariance is divided by τ §3.2 eq. 1. Code: a per-head parameter initialised to 1 multiplies the scores [code: xcit.py#L230] xcit.py. Appendix Algorithm 1 also multiplies app. C alg. 1. The two forms are reparametrisations of each other; use the code's form.
- Softmax orientation. Paper: Softmax(K̂ᵀQ̂/τ) with output V·A eq. 1. Read literally with row-wise softmax, the weights for each output channel do not sum to one, which contradicts the paper's own "convex combination" wording §3.2. Code: attention is Q̂ᵀK̂ per head with softmax over key channels for each query channel, and output channel i mixes value channels j xcit.py. Appendix Algorithm 1: attention is K̂ᵀQ̂ with softmax over the query channel index app. C alg. 1, so the output channel index is the key channel. The two orientations are different functions. The released code is what produced the published checkpoints, so follow it.
- Positional encoding constants. Paper: sinusoidal, 2-D, 64-d intermediate, then projected app. B.1. Code matches this (32 dims per coordinate, 2π scale, temperature 10000, eps 1e-6) xcit.py. The base temperature 10000, scale and eps are not stated in the paper.
- FPN adapter for detection and segmentation. Paper: upsampling is a single transposed convolution, kernel 2, stride 2 app. B.2. Code, for 16 × 16 patch models, uses two stride-2 transposed convolutions with SyncBatchNorm and GELU in between to reach stride 4 xcit.py. The stride-8 level uses one transposed convolution xcit.py. For 8 × 8 patch models the code uses one transposed convolution for stride 4, an identity for stride 8, and max pooling for strides 16 and 32 [code: detection/backbone/xcit.py#L377-L390]. The segmentation backbone has a similar structure xcit.py.
- Local patch interaction order. Paper: "Batch Normalization and GELU in between", with no order given §3.3. Code: conv → GELU → BatchNorm → conv xcit.py.
- Patch embedding. Paper: convolutional projection "as in LeViT" §3.3. Code: four 3 × 3 stride-2 conv + BatchNorm blocks with GELU between for 16 × 16 patches, three for 8 × 8, and no activation after the last block xcit.py.
- Stochastic depth. Paper: per-model values tab. B.1. Code: one rate for every XCA block, the same in each layer xcit.py. Class-attention blocks are built without a drop-path rate, so they get none xcit.py.
- Token normalisation flag. The paper does not describe it. The code's
tokens_normis False for the nano models and True for the others [code: xcit.py#L415, L424, L433] xcit.py. - Training recipe. Paper: DeiT recipe, AdamW, cosine decay, 400 epochs §4.1.
Code defaults: batch size 64 per process, learning rate 5e-4 scaled linearly by
batch × processes / 512 main.py, weight decay 0.05
main.py, warm-up 5 epochs main.py, label smoothing 0.1
main.py, mixup 0.8 and cutmix 1.0 main.py,
repeated augmentation on by default main.py, and a teacher model
regnety_160for distillation, with distillation off by default [code: main.py#L135] main.py. The paper names no teacher model in the text. The README example trains XCiT-S12/16 with batch 128 on 8 GPUs and drop path 0.05 README.md, which the linear rule above turns into a learning rate of 1e-3. This is a derived value, not a paper value. - Evaluation crop. Paper: crop ratio 1.0 §4.1. README: "By default we use the
--full_cropflag" README.md. In the script,--full_cropis an opt-in flag with no default main.py. Pass it explicitly. - Detection schedule. Paper: AdamW, lr 1e-4, weight decay 0.05, 36 epochs, batch 16 §4.2. Code matches, and adds step decay at epochs 27 and 33 [code: detection/configs/xcit/mask_rcnn_xcit_small_12_p16_3x_coco.py#L87-L92], no weight decay on normalisation layers same file, L87-L90, and a per-model drop path (0.05 for S12) same file, L24. The paper does not state these.
- Segmentation schedule. Paper: AdamW, lr 6e-5, weight decay 0.01, batch 16, 80k or 160k iterations §4.3. Code matches, and adds a linear warm-up of 1500 iterations, warm-up ratio 1e-6, and polynomial decay with power 1.0 [code: semantic_segmentation/configs/xcit/upernet/upernet_xcit_small_12_p16_160k_ade20k.py#L27-L36], plus drop path 0.05 for the small model same file, L17. The paper does not state these.
- Object detection comparisons. Swin numbers come from the Swin authors' code §4.2 footnote, not from a re-run by the XCiT authors.
- Class-attention count. The code default is 2 xcit.py. The paper does not give the number.
No discrepancies found for the XCA steps that the released code and the paper both state: ℓ2 normalisation over tokens, block-diagonal heads, linear complexity in N, and the block order XCA → LPI → FFN xcit.py xcit.py.
Pitfalls
- Softmax orientation is the main risk. The paper's equation is ambiguous and
the appendix pseudocode differs from the released code (see
Paper vs code). An implementation that follows the equation literally, with row-wise softmax, will not match the released checkpoints. Use the code's orientation and check one layer's attention output against it. - Temperature. The paper gives no initial value for τ. The code initialises a
multiplicative per-head parameter to 1 xcit.py. Weight decay on this
parameter is not specified; the XCA module's
no_weight_decayliststemperaturexcit.py. - ℓ2 normalisation epsilon. Not stated in the paper. The code calls PyTorch's
normalizewith default arguments xcit.py. Without normalisation the authors report failure for S12/16 tab. 4. They also say convergence without it was possible with hyperparameter tweaks §4.1, so the normalisation is a stability choice, not a hard requirement. - Cost is linear in tokens, not free. Doubling the token count doubles the attention cost, but the FFN and LPI are also linear in tokens. 8 × 8 patches quadruple the token count of 16 × 16 at the same resolution, so 384-pixel 8 × 8 models cost many more GFLOPs. Compare S12/8 at 384 (55.6 GFLOPs) with S12/16 at 224 (4.8 GFLOPs) tab. 1.
- Block-diagonal heads. Each head's cross-covariance is d/h × d/h, so the number of heads sets the size of the attention map. The paper's Table 1 gives the head counts per model tab. 1.
- Resolution changes. The XCA softmax always runs over the same number of channels, so the attention map keeps its shape at any resolution §3.3. The positional encoding is computed on the fly for the current grid [code: xcit.py#L35-L55]. Neither needs interpolation.
- SyncBatchNorm. The code uses
nn.SyncBatchNormin the patch embedding, LPI and FPN layers xcit.py xcit.py. Single-process training needs a regular BatchNorm instead. The paper does not discuss this. - Class-attention blocks. Their normalisation behaviour depends on
tokens_norm: when it is False only the CLS token is normalised after the attention [code: xcit.py#L208-L211]. The paper does not mention this. - Stochastic depth schedule. The paper gives per-model rates, not a per-layer schedule. The code uses one flat rate across XCA blocks and none in class-attention blocks xcit.py xcit.py.
- ImageNet hyperparameters. The paper names only the recipe. Batch size, base learning rate, weight decay, warm-up and augmentation strengths are not stated. The code defaults are the values to check before reproducing any number.
- Distillation. The teacher is not named in the paper. Distilled numbers in tab. 1 and tab. 2 depend on a convolutional teacher that the paper does not identify.
- Comparisons across papers. The COCO results are at 3× schedule after ImageNet-1k pre-training. The paper notes that larger results come from larger pre-training datasets or longer schedules and are not directly comparable §4.2.
- Figure and table numbers. These were derived by counting captions in the arXiv v2 LaTeX source, not checked against the compiled PDF. The appendix uses section letters (for example, Table B.1). The README cites Table B.1 and Figure 3, which agree with this count.
Lineage
- Builds on: token self-attention [Vaswani et al., 2017, cited in §3.1]; ViT (Dosovitskiy et al., 2020) for the columnar patch transformer §3.3; DeiT (Touvron et al., 2020) for the training recipe and hard distillation §4.1; CaiT (Touvron et al., arXiv:2103.17239) for class-attention layers and LayerScale §3.3 §4.1; LeViT (Graham et al., 2021) for the convolutional patch projection §3.3; Group Normalization for the idea of grouped channels §3.2; DINO (/papers/2104.14294) for the self-supervised setup §4.1 tab. 3.
- Compared against: ResNet, ResNeXt, EfficientNet, RegNet and NFNet for classification tab. 2; DeiT, CaiT and Swin (/papers/2103.14030) for classification and detection tab. 2 tab. 5; PVT, ViL and Swin for detection and segmentation tab. 5 tab. 6; Linformer, efficient attention and axial attention for approximate self-attention app. A.2 tab. A.1.
- Superseded by: not stated in this wiki.
Source and license
Adapted from “XCiT: Cross-Covariance Image Transformers” by Alaaeldin El-Nouby, Hugo Touvron, Mathilde Caron, Piotr Bojanowski, Matthijs Douze, Armand Joulin, Ivan Laptev, Natalia Neverova, Gabriel Synnaeve, Jakob Verbeek, Hervé Jegou (arXiv:2106.09681), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/facebookresearch/xcit at commit 82f5291f4126 (Apache-2.0). Any quoted code is shown under that license.