DeclareViT: Decoupling Early Classification from Feature Refinement with Exit Query for Efficient ViTs
Organizations: Technische Universität Darmstadt · Leibniz Universität Hannover · Technische Universität München · Technische Universität Ilmenau ·
Abstract
Vision Transformers achieve remarkable recognition performance but incur substantial computational cost during inference, limiting their use in latency- and compute-constrained deployment scenarios. Early-exit inference offers a promising solution by allowing easy samples to terminate at intermediate layers. However, existing approaches typically couple early classification with the shared backbone, requiring intermediate representations to support both early classification and subsequent feature refinement. Under joint training, the corresponding optimization objectives jointly update shared backbone parameters, which can lead to conflicting gradient directions. Motivated by this observation, we introduce DeclareViT, a framework that decouples early classification from feature refinement. Each exit uses a dedicated query to read intermediate features through one-way cross-attention without modifying the backbone token stream. The query branches are optimized for early classification while the backbone and final classifier remain frozen. Across ViT, DeiT, and Swin on CIFAR-100, ImageNet-1K, and Food-101, DeclareViT consistently establishes a state-of-the-art accuracy-efficiency trade-off: It achieves 1.58 times to 2.57 times multiply-accumulate (MAC)-based speed-up with only a 0.39-1.91 percentage-point accuracy drop. Wall-clock measurements on CPU and GPU further demonstrate practical inference acceleration. Code is available at https://github.com/TUDa-HWAI/DeclareViT.
Figures & tables
| Method | Acc. (%) | GPU | CPU | |||
|---|---|---|---|---|---|---|
| Wall-clock time | Wall-clock time | |||||
| ViT | ||||||
| SDN | ||||||
| BYOT | ||||||
| ViT-EE | ||||||
| LGViT | ||||||
| Exit Head | Per-Exit Accuracy (%) | Acc. (%) | #Params. | ||||||
|---|---|---|---|---|---|---|---|---|---|
| @2 | @4 | @6 | @8 | @10 | Final | ||||
| [ cls ] + Linear | |||||||||
| [ cls ] + MLP | |||||||||
| Transformer Encoder | |||||||||
| Patch Tokens + CNN | |||||||||
| Ours | |||||||||
| (a) Components | ||
|---|---|---|
| Variant | Acc. (%) | |
| w/o FFN | ||
| Pooling readout | ||
| Token injection | ||
| Ours | ||
| (b) Query accumulation | ||
Appendix figures & tables22 assets
Supplementary material from the paper’s appendix.
Appendix
| Dataset | Classes | Local training | Selection/calibration | Final evaluation |
|---|---|---|---|---|
| CIFAR-100 | 100 | 45,000 | 5,000 | 10,000 (test) |
| ImageNet-1K | 1,000 | 1,153,050 | 128,117 | 50,000 (validation) |
| Food-101 | 101 | 68,175 | 7,575 | 25,250 (test) |
| Setting | ViT | DeiT | Swin |
|---|---|---|---|
| Backbone depth | 12 | 12 | by stage |
| Backbone width | 768 | 768 | by stage |
| Exit blocks | |||
| Query width | 768 | 768 | 384 |
| Reader memory | Patches + [ cls ] | Patches + [ cls ] + distillation token | Spatial tokens |
| Query updates | Every block up to its exit | Every block up to its exit | Once at its exit block |
| (a) Shared settings | |
|---|---|
| Optimizer / weight decay | AdamW / |
| Epochs per executed stage | 100 |
| Global batch size | 1,024 (256 per GPU) |
| Schedule | Cosine decay with 10 epochs of linear warmup |
| Minimum learning rate | |
| Precision | BF16 mixed precision |
| Method | CIFAR-100 | ImageNet-1K | Food-101 | ||||||
|---|---|---|---|---|---|---|---|---|---|
| ViT | |||||||||
| SDN | 91.43 0.23 ( ) | 87.09 0.57 ( ) | 79.53 0.84 ( ) | 80.70 0.14 ( ) | 74.31 0.31 ( ) | 66.09 0.39 ( ) | 90.92 0.15 ( ) | 88.42 0.23 ( ) | 82.75 0.21 ( ) |
| BYOT | 89.61 0.30 ( ) | 84.21 0.81 ( ) | 76.50 1.11 ( ) | 80.09 0.10 ( ) | 77.11 0.27 ( ) | 71.36 0.68 ( ) | 90.20 0.18 ( ) | 86.39 0.89 ( ) | 80.52 1.62 ( ) |
| ViT-EE | 88.79 0.68 ( ) | 81.08 1.46 ( ) | 75.33 1.42 ( ) | 77.44 0.25 ( ) | 69.08 0.51 ( ) | 63.62 0.67 ( ) | 89.43 0.57 ( ) | 82.93 1.18 ( ) | 77.97 1.52 ( ) |
| LGViT | 91.02 0.03 ( ) | 83.85 0.35 ( ) | 74.83 0.47 ( ) | 75.61 1.36 ( ) | 61.89 2.33 ( ) | 51.93 2.71 ( ) | 90.05 0.25 ( ) | 85.59 0.58 ( ) | 79.67 0.99 ( ) |
| Method | CIFAR-100 | ImageNet-1K | Food-101 | |||
|---|---|---|---|---|---|---|
| Acc. (%) | Acc. (%) | Acc. (%) | ||||
| ViT | ||||||
| ViT | ||||||
| SDN | ||||||
| BYOT | ||||||
| ViT-EE | ||||||
| Backbone only | + DeclareViT, target | + DeclareViT, target | |||||||
| Backbone | #Params | Acc. (%) | GMAC | Acc. (%) | GMAC | Acc. (%) | GMAC | ||
| ViT-B | 86.6M | 81.77 | 17.56 | 81.77 | 12.21 | 79.90 | 9.05 | ||
| DeiT-B | 87.3M | 83.38 | 17.66 | 82.74 | 12.32 | 78.75 | 9.11 | ||
| Swin-B | 87.8M | 83.59 | 15.43 | 83.35 | 10.88 | 80.57 | 8.13 | ||
| DeiT-S | 22.4M | 81.21 | 4.62 | 80.43 | 3.21 | 76.89 | 2.38 | ||
| EfficientFormerV2-L | 26.3M | 83.36 | 2.55 | 80.97 | 1.76 | 73.66 | 1.29 | ||
| Dataset | Method | Acc. (%) | GPU | CPU | |||
|---|---|---|---|---|---|---|---|
| Wall-clock time | Wall-clock time | ||||||
| CIFAR-100 | ViT | ||||||
| Ours | |||||||
| ImageNet-1K | ViT | ||||||
| Ours | |||||||
| Food-101 | ViT | ||||||
| Method | Acc. (%) | ||||||
|---|---|---|---|---|---|---|---|
| ViT | 81.77 | 1.00 | 1.00 (7.66) | 1.00 (6.91) | 1.00 (6.26) | 1.00 (5.93) | 1.00 (5.78) |
| SDN | 79.20 | 1.63 | 1.55 (4.95) | 1.57 (4.40) | 1.58 (3.95) | 1.59 (3.73) | 1.60 (3.62) |
| BYOT | 79.53 | 1.64 | 1.55 (4.94) | 1.57 (4.39) | 1.59 (3.94) | 1.59 (3.72) | 1.60 (3.61) |
| ViT-EE | 78.56 | 1.36 | 1.31 (5.85) | 1.32 (5.21) | 1.33 (4.69) | 1.34 (4.44) | 1.34 (4.30) |
| LGViT | 79.21 | 1.36 | 1.18 (6.50) | 1.17 (5.90) | 1.16 (5.37) | 1.16 (5.11) | 1.16 (4.97) |
| COSEE | 79.38 | 1.66 | 1.58 (4.87) | 1.60 (4.32) | 1.61 (3.88) | 1.62 (3.67) | 1.62 (3.56) |
| (a) Knowledge distillation | ||
|---|---|---|
| Variant | Acc. | |
| w/o KD | ||
| w/ KD (ours) | ||
| target | target | |||||
|---|---|---|---|---|---|---|
| Configuration | #Params (extra) | Final-path GMAC (overhead) | Acc. (%) | Acc. (%) | ||
| ViT-B/16 | 86.6M (–) | 17.56 (–) | 81.77 (full depth, ) | |||
| DeclareViT ( , FFN ratio 4) | 107.0M (+20.4M) | 19.96 (+13.6%) | 81.77 | 79.90 | ||
| DeclareViT-Lite ( , FFN ratio 2) | 93.5M (+7.0M) | 18.74 (+6.7%) | 81.59 | 78.63 | ||
| Method | Implementation | ViT / DeiT blocks | Swin blocks |
|---|---|---|---|
| SDN | Adapted linear-readout baseline | ||
| BYOT | Self-distillation adaptation | ||
| ViT-EE | Transformer-exit adaptation | ||
| COSEE | Visual adaptation of published objectives | ||
| LGViT | Native reimplementation | ||
| DMPO | Adapted released implementation; DeiT/Swin extensions |
| Path | Block | Backbone | Readers | Readouts | Total |
|---|---|---|---|---|---|
| Exit 1 | 2 | 3.0235 | 0.4796 | 0.0055 | 3.5086 |
| Exit 2 | 4 | 5.9314 | 0.9562 | 0.0110 | 6.8986 |
| Exit 3 | 6 | 8.8393 | 1.4299 | 0.0165 | 10.2857 |
| Exit 4 | 8 | 11.7472 | 1.9006 | 0.0219 | 13.6698 |
| Exit 5 | 10 | 14.6552 | 2.3684 | 0.0274 | 17.0510 |
| Dynamic final | 12 | 17.5631 | 2.3684 | 0.0282 | 19.9596 |
Efficient ViTs
Efficient Vision Transformers reduce the compute, memory, energy, or latency needed to process images and video while retaining useful accuracy.
See all 264 papers