SegFormer (fastforks)
SegFormer (Xie et al. 2021): hierarchical Mix Transformer encoder (overlapping patch embeddings, reduced-key attention, Mix-FFN) and an all-MLP decoder.
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/transformers at c4c4605f9618.
Author weight repos: https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512, https://huggingface.co/nvidia/segformer-b5-finetuned-ade-640-640.
Task: segmentation. Tier: stable. Outputs: logits. Backends: portable, kernels.
Input: one RGB image. Output: per-pixel 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 |
|---|---|---|---|---|
segformer-b0-ade20k@1 |
segformer-b0-ade20k.config.json segformer-b0-ade20k.safetensors |
209caa9091e46ae39addd01d |
LicenseRef-NVIDIA-Source-Code-License-NC | no |
segformer-b5-ade20k@1 |
segformer-b5-ade20k.config.json segformer-b5-ade20k.bin |
083fbb6bc7cea3dbf2d7a991 |
LicenseRef-NVIDIA-Source-Code-License-NC | no |
Licence
Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0. Files: .
Training data: ImageNet-1k (ILSVRC 2012 classification), ADE20K (SceneParsing, 150 classes).
Licence evidence: https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512/blob/489d5cd81a0b59fab9b7ea758d3548ebe99677da/README.md
Input size
any H x W >= 1, resized or padded inside the model
Tested up to (portable, fp16, RTX 5060 Ti 16 GB): segformer-b0-ade20k 3000x4000 (3.8 GiB peak allocated, 4.0 reserved); segformer-b5-ade20k 3000x4000 (4.0 GiB peak allocated, 4.3 reserved)
Speed and memory
Segmentation, synthetic, 1024x2048
| model | time (ms): original fp32 | original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels |
|---|---|---|---|---|---|---|---|---|---|
segformer-b0-ade20k (resize 2048x512) |
17.25 | 17.41 | 11.383 | 3.479 | 5.0x | 3.3x | 1590 / 1766 | 339 / 376 | 148 / 238 |
segformer-b5-ade20k (resize 2048x640) |
131.51 | 72.01 | 38.652 | 25.347 | 2.8x | 1.5x | 2531 / 2620 | 546 / 590 | 407 / 534 |
Startup and first call
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
|---|---|---|---|---|---|---|
segformer-b0-ade20k (resize 2048x512) |
4.83 (512x512) | 2.55 | 2.92 | 2.23 (512x512) | 0.08 | 0.01 |
segformer-b5-ade20k (resize 2048x640) |
1.24 (512x512) | 3.09 | 3.43 | 0.50 (512x512) | 0.08 | 0.03 |
torch.compile and TensorRT
| model | input | portable ms | compile ms | compile s (cold) | TensorRT fp16 ms | ONNX + build s | kernels ms | peak MiB (alloc / reserved): portable | compile | TensorRT (device) |
|---|---|---|---|---|---|---|---|---|---|---|
segformer-b0-ade20k (resize 2048x512) |
1024x2048 | 11.383 | 11.4 | 0.3 | 5.5 | 61 | 3.479 | 339 / 376 | 336 / 356 | 792 |
Fixed-size speed and peak memory, all models
| model | mode | 640x480 | 1280x720 | 1920x1080 | 12 MP 4000x3000 |
|---|---|---|---|---|---|
segformer-b0-ade20k (resize 2048x512) |
portable | 7.5 ms / 237 / 290 | 11.9 ms / 454 / 518 | 18.5 ms / 798 / 864 | 74.7 ms / 3888 / 4048 |
segformer-b0-ade20k (resize 2048x512) |
kernels | 7.3 ms / 237 / 290 | 11.6 ms / 454 / 518 | 18.2 ms / 798 / 864 | 74.5 ms / 3888 / 4048 |
segformer-b5-ade20k (resize 2048x640) |
portable | 28.3 ms / 469 / 668 | 36.7 ms / 707 / 958 | 43.4 ms / 1050 / 1304 | 96.1 ms / 4063 / 4380 |
segformer-b5-ade20k (resize 2048x640) |
kernels | 26.6 ms / 470 / 668 | 33.7 ms / 708 / 958 | 40.4 ms / 1051 / 1304 | 94.4 ms / 4064 / 4380 |
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 authors' code 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
Parity with the original code
Every variant is checked against golden outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 and p99 <= 0.1 (absolute error of the output logits).
Usage
from fastforks import segmentation
# non-commercial weights: run with FASTFORKS_NONCOMMERCIAL=1 in the environment
model = segmentation.load("segformer-b0-ade20k") # mode="auto": the preferred backend from recorded measurements
result = model("photo.jpg")
result.labels # [H, W] per-pixel class index
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: segformer-b0-ade20k, segformer-b5-ade20k.
Kernels backend
segmentation.load("segformer-b0-ade20k", mode="kernels") runs our CUDA kernels (cudnn_hacc, fvm_conv, fvm_extra, fvm_mb, fvm_r3, seg_up). It needs a prebuilt kernel for your GPU architecture (downloaded from https://huggingface.co/fastforks/kernels on first use) and a recent NVIDIA driver; if there is none it raises BackendUnavailableError with the reason and never falls back silently. mode="auto" picks kernels when it can run and logs the choice.