efficientformerv2 / README.md
Flor's picture
card: update from fastforks 1cbf1671
5b77504 verified
|
Raw History Blame Contribute Delete
8.23 kB
---
library_name: "fastforks"
pipeline_tag: "image-classification"
license: "apache-2.0"
tags:
- "classification"
- "image-classification"
- "cuda"
- "pytorch"
- "fastforks"
- "fastforks-card"
---
# EfficientFormerV2 (fastforks)
EfficientFormerV2 (Li et al. 2022, Snap Research): a mobile hybrid classifier, convolutional stages with attention in the last two.
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/efficientformerv2_l.snap_dist_in1k>, <https://huggingface.co/timm/efficientformerv2_s0.snap_dist_in1k>, <https://huggingface.co/timm/efficientformerv2_s1.snap_dist_in1k>, <https://huggingface.co/timm/efficientformerv2_s2.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`](https://github.com/kleinicke/fastforks/blob/main/src/fastforks/classification/models/efficientformerv2/card.toml).
| variant | weights (author link) | SHA-256 | weights licence | commercial use |
|---|---|---|---|---|
| `efficientformerv2_l.snap_dist_in1k@1` | [efficientformerv2_l.snap_dist_in1k.safetensors](https://huggingface.co/timm/efficientformerv2_l.snap_dist_in1k/resolve/092a1c107ec0fdc2207a470f81c696022f17a42e/model.safetensors) | `a92de90055b1` | Apache-2.0 | yes |
| `efficientformerv2_s0.snap_dist_in1k@1` | [efficientformerv2_s0.snap_dist_in1k.safetensors](https://huggingface.co/timm/efficientformerv2_s0.snap_dist_in1k/resolve/aa226e91a076e760bc7957e5990f19f6ae322c5f/model.safetensors) | `ad4ce93472a2` | Apache-2.0 | yes |
| `efficientformerv2_s1.snap_dist_in1k@1` | [efficientformerv2_s1.snap_dist_in1k.safetensors](https://huggingface.co/timm/efficientformerv2_s1.snap_dist_in1k/resolve/0c1fc60a0e89b6309d9de451cdacc11ac0a8b987/model.safetensors) | `3ef67aa25321` | Apache-2.0 | yes |
| `efficientformerv2_s2.snap_dist_in1k@1` | [efficientformerv2_s2.snap_dist_in1k.safetensors](https://huggingface.co/timm/efficientformerv2_s2.snap_dist_in1k/resolve/1c56a76355000c79568559d34ba3fa24416b5107/model.safetensors) | `c46c28768173` | 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/efficientformerv2_s0.snap_dist_in1k/blob/aa226e91a076e760bc7957e5990f19f6ae322c5f/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): `efficientformerv2_l.snap_dist_in1k` 224x224 (0.1 GiB peak allocated, 0.1 reserved); `efficientformerv2_s0.snap_dist_in1k` 224x224 (0.0 GiB peak allocated, 0.1 reserved); `efficientformerv2_s1.snap_dist_in1k` 224x224 (0.0 GiB peak allocated, 0.1 reserved); `efficientformerv2_s2.snap_dist_in1k` 224x224 (0.1 GiB peak allocated, 0.1 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 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| `efficientformerv2_l.snap_dist_in1k` | 224x224 | 19.9 | 29.0 | 17.1 | – | – | – | 186 / 198 | 93 / 144 | – |
| `efficientformerv2_s0.snap_dist_in1k` | 224x224 | 8.16 | 11.8 | 7.62 | – | – | – | 55 / 64 | 44 / 64 | – |
| `efficientformerv2_s1.snap_dist_in1k` | 224x224 | 10.1 | 14.9 | 8.91 | – | – | – | 70 / 80 | 50 / 88 | – |
| `efficientformerv2_s2.snap_dist_in1k` | 224x224 | 15.2 | 21.8 | 13.9 | – | – | – | 108 / 116 | 64 / 104 | – |
### Startup and first call
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
| --- | --- | --- | --- | --- | --- | --- |
| `efficientformerv2_l.snap_dist_in1k` | 0.32 | 2.74 | – | 0.73 | 0.43 | – |
| `efficientformerv2_s0.snap_dist_in1k` | 0.17 | 1.88 | – | 1.76 | 0.50 | – |
| `efficientformerv2_s1.snap_dist_in1k` | 0.19 | 1.96 | – | 0.59 | 0.43 | – |
| `efficientformerv2_s2.snap_dist_in1k` | 0.24 | 2.68 | – | 0.86 | 0.44 | – |
### 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) |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| `efficientformerv2_l.snap_dist_in1k` | 224x224 | 17.1 ms | 7.32 ms | 1.20 ms | – | 20.7 s | 45.1 s | 93 / 144 | 125 / 184 | – | 161 / 214 |
| `efficientformerv2_s0.snap_dist_in1k` | 224x224 | 7.62 ms | 3.34 ms | 0.550 ms | – | 11.3 s | 36.3 s | 44 / 64 | 76 / 104 | – | 78 / 100 |
| `efficientformerv2_s1.snap_dist_in1k` | 224x224 | 8.91 ms | 3.91 ms | 0.632 ms | – | 12.7 s | 41.2 s | 50 / 88 | 82 / 108 | – | 86 / 126 |
| `efficientformerv2_s2.snap_dist_in1k` | 224x224 | 13.9 ms | 5.55 ms | 0.919 ms | – | 16.4 s | 38.9 s | 64 / 104 | 96 / 124 | – | 100 / 142 |
Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).
Hardware, protocol and caveats: [benchmarks](https://github.com/kleinicke/fastforks/blob/main/docs/benchmarks.md) (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 |
|---|---|---|---|---|---|
| `efficientformerv2_s0.snap_dist_in1k` | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 77.04 / 92.94 | 77.00 / 92.76 | 77.34 / 92.82 | |
| `efficientformerv2_s1.snap_dist_in1k` | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 80.80 / 95.00 | 81.02 / 94.88 | 80.88 / 95.00 | |
| `efficientformerv2_s2.snap_dist_in1k` | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 83.22 / 96.28 | 83.10 / 96.34 | 83.18 / 96.30 | |
| `efficientformerv2_l.snap_dist_in1k` | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 83.88 / 96.58 | 83.96 / 96.58 | 84.02 / 96.50 | |
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| <= 4.7e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.12 and p99 <= 0.42 (absolute error of the output `logits`).
## Usage
```python
from fastforks import classification
model = classification.load("efficientformerv2_l.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: `efficientformerv2_l.snap_dist_in1k`, `efficientformerv2_s0.snap_dist_in1k`, `efficientformerv2_s1.snap_dist_in1k`, `efficientformerv2_s2.snap_dist_in1k`.
## Kernels backend
No kernels backend: not built yet: Conv-BN blocks with depthwise 3x3, feature-map attention with learned bias tables and strided depthwise convolutions need a dedicated kernels runner.
<!-- staged from fastforks 1cbf1671 (2026-11-15) -->