efficientformer / README.md
Flor's picture
card: update from fastforks 1cbf1671
3eeccd4 verified
|
Raw History Blame Contribute Delete
7.24 kB
metadata
library_name: fastforks
pipeline_tag: image-classification
license: apache-2.0
tags:
  - classification
  - image-classification
  - cuda
  - pytorch
  - fastforks
  - fastforks-card

EfficientFormer (fastforks)

EfficientFormer (Li et al. 2022, Snap Research): a hybrid classifier, pooling blocks on feature maps followed by transformer blocks on tokens.

This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: https://github.com/kleinicke/fastforks. Kernels for the kernels backend: https://huggingface.co/fastforks/kernels. Original code: https://github.com/huggingface/pytorch-image-models at 0df212b369a5.

Author weight repos: https://huggingface.co/timm/efficientformer_l1.snap_dist_in1k, https://huggingface.co/timm/efficientformer_l3.snap_dist_in1k, https://huggingface.co/timm/efficientformer_l7.snap_dist_in1k.

Task: classification. Tier: experimental. Outputs: logits. Backends: portable.

Input: one RGB image. Output: ImageNet-1k class logits.

Variants

Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in card.toml.

variant weights (author link) SHA-256 weights licence commercial use
efficientformer_l1.snap_dist_in1k@1 efficientformer_l1.snap_dist_in1k.safetensors dab9ad0e328f Apache-2.0 yes
efficientformer_l3.snap_dist_in1k@1 efficientformer_l3.snap_dist_in1k.safetensors ab0c5bfd7c18 Apache-2.0 yes
efficientformer_l7.snap_dist_in1k@1 efficientformer_l7.snap_dist_in1k.safetensors c497103536ff Apache-2.0 yes

Licence

Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0.

Training data: ImageNet-1k (ILSVRC 2012 classification).

Licence evidence: https://huggingface.co/timm/efficientformer_l1.snap_dist_in1k/blob/8738a58190800aaf5995f453b05f643df453a565/README.md

Input size

fixed 224x224: the input is resized (short side 235) and centre-cropped to it Tested up to (portable, fp16, RTX 5060 Ti 16 GB): efficientformer_l1.snap_dist_in1k 224x224 (0.1 GiB peak allocated, 0.1 reserved); efficientformer_l3.snap_dist_in1k 224x224 (0.2 GiB peak allocated, 0.2 reserved); efficientformer_l7.snap_dist_in1k 224x224 (0.3 GiB peak allocated, 0.3 reserved)

Speed and memory

Classification, synthetic

model input time (ms): original fp32 original portable kernels kernels speed-up: vs original vs portable peak memory (MiB, allocated / reserved): original portable kernels
efficientformer_l1.snap_dist_in1k 224x224 4.87 6.40 3.72 – – – 104 / 124 93 / 104 –
efficientformer_l3.snap_dist_in1k 224x224 8.39 11.0 6.37 – – – 214 / 236 161 / 216 –
efficientformer_l7.snap_dist_in1k 224x224 12.3 15.9 9.65 – – – 505 / 522 300 / 324 –

Startup and first call

model load (s): original portable kernels first call (s): original portable kernels
efficientformer_l1.snap_dist_in1k 0.22 1.71 – 0.22 0.07 –
efficientformer_l3.snap_dist_in1k 0.37 1.86 – 0.03 0.08 –
efficientformer_l7.snap_dist_in1k 0.93 2.27 – 0.03 0.07 –

torch.compile and TensorRT

model input time: portable compile TensorRT fp16 kernels preparation: compile (cold first call) ONNX + engine build peak MiB (alloc / reserved): portable compile kernels TensorRT (engine + torch)
efficientformer_l1.snap_dist_in1k 224x224 3.72 ms 1.69 ms 0.335 ms – 9.10 s 35.4 s 93 / 104 125 / 144 – 128 / 142
efficientformer_l3.snap_dist_in1k 224x224 6.37 ms 2.57 ms 0.750 ms – 11.8 s 39.4 s 161 / 216 193 / 216 – 227 / 286
efficientformer_l7.snap_dist_in1k 224x224 9.65 ms 3.69 ms 1.40 ms – 14.4 s 40.0 s 300 / 324 332 / 364 – 460 / 490

Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).

Hardware, protocol and caveats: benchmarks (RTX 5060 Ti 16 GB, sm_120). Original = the original code named above at the precision of portable (fp16, or (fp32) where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's.

Accuracy

On public datasets

fastforks: the model's own resize / crop on the GPU; original: the library's pretrained loader and its PIL eval transform. Original = the original code named under Details, same checkpoint and protocol.

variant dataset original fp32 original fp16 portable note
efficientformer_l1.snap_dist_in1k ImageNet-1k val, 5000 random images, top-1 / top-5 % 81.14 / 95.22 81.16 / 95.24 81.14 / 95.12
efficientformer_l3.snap_dist_in1k ImageNet-1k val, 5000 random images, top-1 / top-5 % 83.12 / 96.32 83.14 / 96.32 83.16 / 96.32
efficientformer_l7.snap_dist_in1k ImageNet-1k val, 5000 random images, top-1 / top-5 % 84.44 / 96.68 84.44 / 96.66 84.38 / 96.68

Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 7ba7307f, 2026-11-11.

Parity with the original code

Every variant is checked against reference outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 1.3e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.0046 and p99 <= 0.019 (absolute error of the output logits).

Usage

from fastforks import classification

model = classification.load("efficientformer_l1.snap_dist_in1k")  # mode="auto": the preferred backend from recorded measurements
result = model("photo.jpg")
result.top(5)  # top-5 classes
result.backend  # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')

Install with pip install fastforks (see https://github.com/kleinicke/fastforks). Other variants: efficientformer_l1.snap_dist_in1k, efficientformer_l3.snap_dist_in1k, efficientformer_l7.snap_dist_in1k.

Kernels backend

No kernels backend: not built yet: pooling blocks with Conv-BN MLPs and LayerNorm transformer blocks with learned attention bias tables need a dedicated kernels runner.