FocalNet (fastforks)
FocalNet (Yang et al. 2022): a hierarchical classifier that replaces self-attention by focal modulation (stacked depthwise convolutions with gated aggregation).
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/focalnet_base_lrf.ms_in1k, https://huggingface.co/timm/focalnet_base_srf.ms_in1k, https://huggingface.co/timm/focalnet_small_lrf.ms_in1k, https://huggingface.co/timm/focalnet_small_srf.ms_in1k, https://huggingface.co/timm/focalnet_tiny_lrf.ms_in1k, https://huggingface.co/timm/focalnet_tiny_srf.ms_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 |
|---|---|---|---|---|
focalnet_base_lrf.ms_in1k@1 |
focalnet_base_lrf.ms_in1k.safetensors | e1c36016eaef |
MIT | yes |
focalnet_base_srf.ms_in1k@1 |
focalnet_base_srf.ms_in1k.safetensors | 05a7ff7cda7e |
MIT | yes |
focalnet_small_lrf.ms_in1k@1 |
focalnet_small_lrf.ms_in1k.safetensors | c7d963802b47 |
MIT | yes |
focalnet_small_srf.ms_in1k@1 |
focalnet_small_srf.ms_in1k.safetensors | 2590faabe2cd |
MIT | yes |
focalnet_tiny_lrf.ms_in1k@1 |
focalnet_tiny_lrf.ms_in1k.safetensors | f5f73a0b0430 |
MIT | yes |
focalnet_tiny_srf.ms_in1k@1 |
focalnet_tiny_srf.ms_in1k.safetensors | fc5ae22ca975 |
MIT | 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/focalnet_tiny_srf.ms_in1k/blob/de75c3a73e9ed84fee554a7138d4bac119751645/README.md
Input size
fixed 224x224: the input is resized (short side 248) and centre-cropped to it
Tested up to (portable, fp16, RTX 5060 Ti 16 GB): focalnet_base_lrf.ms_in1k 224x224 (0.2 GiB peak allocated, 0.2 reserved); focalnet_base_srf.ms_in1k 224x224 (0.2 GiB peak allocated, 0.2 reserved); focalnet_small_lrf.ms_in1k 224x224 (0.1 GiB peak allocated, 0.1 reserved); focalnet_small_srf.ms_in1k 224x224 (0.1 GiB peak allocated, 0.1 reserved); focalnet_tiny_lrf.ms_in1k 224x224 (0.1 GiB peak allocated, 0.1 reserved); focalnet_tiny_srf.ms_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 |
|---|---|---|---|---|---|---|---|---|---|---|
focalnet_base_lrf.ms_in1k |
224x224 | 18.0 | 22.1 | 15.5 | β | β | β | 546 / 560 | 212 / 234 | β |
focalnet_base_srf.ms_in1k |
224x224 | 17.1 | 20.0 | 14.2 | β | β | β | 542 / 558 | 211 / 234 | β |
focalnet_small_lrf.ms_in1k |
224x224 | 16.8 | 22.0 | 15.8 | β | β | β | 323 / 338 | 136 / 152 | β |
focalnet_small_srf.ms_in1k |
224x224 | 15.9 | 20.1 | 14.0 | β | β | β | 320 / 336 | 136 / 152 | β |
focalnet_tiny_lrf.ms_in1k |
224x224 | 8.92 | 11.4 | 8.07 | β | β | β | 199 / 208 | 95 / 118 | β |
focalnet_tiny_srf.ms_in1k |
224x224 | 8.39 | 10.4 | 7.36 | β | β | β | 197 / 206 | 95 / 118 | β |
Startup and first call
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
|---|---|---|---|---|---|---|
focalnet_base_lrf.ms_in1k |
0.91 | 1.89 | β | 0.03 | 0.62 | β |
focalnet_base_srf.ms_in1k |
0.89 | 1.92 | β | 0.05 | 0.49 | β |
focalnet_small_lrf.ms_in1k |
0.54 | 1.86 | β | 0.03 | 0.69 | β |
focalnet_small_srf.ms_in1k |
0.54 | 1.73 | β | 0.02 | 0.49 | β |
focalnet_tiny_lrf.ms_in1k |
0.36 | 2.56 | β | 0.15 | 0.77 | β |
focalnet_tiny_srf.ms_in1k |
0.40 | 1.49 | β | 0.45 | 0.49 | β |
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) |
|---|---|---|---|---|---|---|---|---|---|---|---|
focalnet_base_lrf.ms_in1k |
224x224 | 15.5 ms | 7.47 ms | 2.08 ms | β | 19.7 s | 63.9 s | 212 / 234 | 235 / 274 | β | 404 / 432 |
focalnet_base_srf.ms_in1k |
224x224 | 14.2 ms | 6.94 ms | 1.74 ms | β | 17.8 s | 63.8 s | 211 / 234 | 234 / 272 | β | 401 / 430 |
focalnet_small_lrf.ms_in1k |
224x224 | 15.8 ms | 7.28 ms | 1.70 ms | β | 19.5 s | 62.5 s | 136 / 152 | 162 / 192 | β | 265 / 286 |
focalnet_small_srf.ms_in1k |
224x224 | 14.0 ms | 6.90 ms | 1.49 ms | β | 17.8 s | 65.3 s | 136 / 152 | 161 / 190 | β | 234 / 256 |
focalnet_tiny_lrf.ms_in1k |
224x224 | 8.07 ms | 3.94 ms | 0.952 ms | β | 13.3 s | 49.9 s | 95 / 118 | 120 / 138 | β | 158 / 186 |
focalnet_tiny_srf.ms_in1k |
224x224 | 7.36 ms | 3.72 ms | 0.864 ms | β | 12.9 s | 52.0 s | 95 / 118 | 120 / 136 | β | 159 / 188 |
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 |
|---|---|---|---|---|---|
focalnet_tiny_srf.ms_in1k |
ImageNet-1k val, 5000 random images, top-1 / top-5 % | 82.86 / 96.28 | 82.88 / 96.30 | 82.90 / 96.28 | |
focalnet_small_srf.ms_in1k |
ImageNet-1k val, 5000 random images, top-1 / top-5 % | 84.34 / 96.84 | 84.30 / 96.84 | 84.44 / 96.76 | |
focalnet_base_srf.ms_in1k |
ImageNet-1k val, 5000 random images, top-1 / top-5 % | 84.20 / 96.86 | 84.18 / 96.86 | 84.16 / 96.84 | |
focalnet_tiny_lrf.ms_in1k |
ImageNet-1k val, 5000 random images, top-1 / top-5 % | 82.88 / 96.12 | 82.86 / 96.10 | 82.86 / 96.20 | |
focalnet_small_lrf.ms_in1k |
ImageNet-1k val, 5000 random images, top-1 / top-5 % | 84.36 / 96.80 | 84.34 / 96.80 | 84.32 / 96.80 | |
focalnet_base_lrf.ms_in1k |
ImageNet-1k val, 5000 random images, top-1 / top-5 % | 84.64 / 96.64 | 84.64 / 96.64 | 84.56 / 96.56 |
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| <= 2.9e-06 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.0027 and p99 <= 0.0098 (absolute error of the output logits).
Usage
from fastforks import classification
model = classification.load("focalnet_base_lrf.ms_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: focalnet_base_lrf.ms_in1k, focalnet_base_srf.ms_in1k, focalnet_small_lrf.ms_in1k, focalnet_small_srf.ms_in1k, focalnet_tiny_lrf.ms_in1k, focalnet_tiny_srf.ms_in1k.
Kernels backend
No kernels backend: not implemented: LayerNorm blocks with depthwise convolutions and gated sums: needs its own runner.