EfficientFormerConfig
ModelConfigEfficientFormerConfig(num_classes: int = 1000, in_channels: int = 3, depths: tuple[int, ...] = (3, 2, 6, 4), embed_dims: tuple[int, ...] = (48, 96, 224, 448), mlp_ratios: tuple[float, ...] = (4.0, 4.0, 4.0, 4.0), num_vit: int = 1, pool_size: int = 3, key_dim: int = 32, num_heads: int = 8, attn_ratio: float = 4.0, resolution: int = 7, drop_path_rate: float = 0.0, layer_scale_init: float = 1e-05)Configuration dataclass for every EfficientFormer variant.
EfficientFormerConfig is an immutable container that fully
specifies the architecture of an EfficientFormer (Li et al., 2022).
The model is a mobile-grade vision backbone whose on-device
latency, rather than its FLOP count, matches MobileNet on the same
hardware while retaining transformer-level accuracy.
Stages 1-3 use pooling mixer MetaFormer blocks (a parameter-free average pool replacing self-attention) and operate entirely in layout. Stage 4 is the only stage that pays the cost of a reshape and runs standard multi-head self-attention on the now-tiny token grid.
Parameters
num_classesint= 10001000 (ImageNet-1k).in_channelsint= 33 (RGB).depthstuple of int= (3, 2, 6, 4)(3, 2, 6, 4)
(EfficientFormer-L1).embed_dimstuple of int= (48, 96, 224, 448)(48, 96, 224, 448) (EfficientFormer-L1).mlp_ratiostuple of float= (4.0, 4.0, 4.0, 4.0)(4.0, 4.0, 4.0, 4.0).num_vitint= 11 (EfficientFormer-L1); L3 uses
4 and L7 uses 8.pool_sizeint= 33.key_dimint= 3232 (fixed across all paper variants).num_headsint= 88 (fixed across all paper variants).attn_ratiofloat= 4.0attn_ratio * key_dim. Defaults
to 4.0.resolutionint= 7resolution ** 2 entries per head. Defaults to 7
(a 7 x 7 grid at the default 224 input).drop_path_ratefloat= 0.00.0 for L1, 0.1
for L3, 0.2 for L7. Defaults to 0.0.layer_scale_initfloat= 1e-051e-5 (Li et al., 2022, appendix).Attributes
model_typeClassVar[str]"efficientformer" used by the model registry.Notes
The canonical variants registered as factory functions in
lucid.models.vision.efficientformer are:
============================ ================ =================== Variant depths embed_dims ============================ ================ =================== EfficientFormer-L1 (3, 2, 6, 4) (48, 96, 224, 448) EfficientFormer-L3 (4, 4, 12, 6) (64, 128, 320, 512) EfficientFormer-L7 (6, 6, 18, 8) (96, 192, 384, 768) ============================ ================ ===================
Reference: Yanyu Li et al., "EfficientFormer: Vision Transformers at MobileNet Speed", NeurIPS 2022, arXiv:2206.01191.
Examples
Build an EfficientFormer-L1 configuration with a 100-class head:
>>> from lucid.models.vision.efficientformer import EfficientFormerConfig
>>> cfg = EfficientFormerConfig(num_classes=100)
>>> cfg.depths, cfg.embed_dims, cfg.num_classes
((3, 2, 6, 4), (48, 96, 224, 448), 100)Used by 3
Constructors
1__init__
→None__init__(num_classes: int = 1000, in_channels: int = 3, depths: tuple[int, ...] = (3, 2, 6, 4), embed_dims: tuple[int, ...] = (48, 96, 224, 448), mlp_ratios: tuple[float, ...] = (4.0, 4.0, 4.0, 4.0), num_vit: int = 1, pool_size: int = 3, key_dim: int = 32, num_heads: int = 8, attn_ratio: float = 4.0, resolution: int = 7, drop_path_rate: float = 0.0, layer_scale_init: float = 1e-05)