Skip to content
module

EfficientFormer

13 members
lucid.models.vision.efficientformer

EfficientFormer — Li et al., 2022.

Image Classification
Paper

Li, Yanyu, et al. "EfficientFormer: Vision Transformers at MobileNet Speed." Advances in Neural Information Processing Systems, vol. 35, 2022.

Overview

EfficientFormer is a mobile-grade vision backbone designed so that its end-to-end on-device latency, rather than its FLOP count, matches the latency of MobileNet on the same hardware while retaining transformer-level accuracy. The authors profile real iOS / NPU latency and identify three transformer operators that are unexpectedly slow: the reshape between spatial and token layouts, GeLU compared to ReLU, and LayerNorm compared to BatchNorm. EfficientFormer is the result of a latency-aware architecture search that designs around these costs.

The backbone is a four-stage pyramid. Stages 1-3 use pooling mixer blocks — a MetaFormer-style token mixer that replaces the quadratic self-attention with a parameter-free 3×33 \times 3 average pooling — and operate entirely in the 4-D (B,C,H,W)(B, C, H, W) layout so no expensive reshape is needed. Each pooling block computes

x←x+γ1⊙(AvgPool3×3(x)−x),x←x+γ2⊙MLP(x),x \leftarrow x + \gamma_1 \odot \bigl(\mathrm{AvgPool}_{3 \times 3}(x) - x\bigr), \qquad x \leftarrow x + \gamma_2 \odot \mathrm{MLP}(x),

with γ1,γ2\gamma_1, \gamma_2 initialised to 10−510^{-5} — the layer scale trick from CaiT. Stage 4 is the only stage that pays the cost of a reshape and runs standard multi-head self-attention with relative position bias on the now-tiny token grid. The resulting design (variants L1 / L3 / L7) matches ResNet-50 / DeiT-S accuracy at MobileNetV2-class latency on an iPhone 12 NPU.

Classes

Functions

Weights