Models · Semantic segmentation
SegFormer
NVIDIA's SegFormer: a transformer for ADE20K scene segmentation (sizes B0 and B5), plus two community fine-tunes: clothes parsing (B2, 18 classes) and face parsing (B5, 19 classes). Non-commercial weights.
stable Fork of huggingface/transformers@c4c4605 · backends: portable, kernels
- Paper SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers NeurIPS 2021 · first released 31 May 2021
- Authors’ code NVlabs/SegFormer (PyTorch), not the code forked here: The authors' code needs mmsegmentation; the transformers port is self-contained.
resize 2048x512
Paper 2021 Added in 0.1.0 Evaluated with 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install "fastforks-core[transformers]"
from fastforks import segmentation
model = segmentation.load("segformer-b0-ade20k") # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.logits
result.backend # what ran: mode, device, dtype, kernels The weights are non-commercial: fastforks downloads them only with FASTFORKS_NONCOMMERCIAL=1 set.
fastforks bench segformer-b0-ade20k Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.
Speed and memory
Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.
| Backend | dtype | Time per call (ms) | vs original fp32 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 17.3 | – | 1,583 MiB/1,638 MiB | – | – |
| Original fp16torch.autocast(fp16) around the forward | fp16 | 17.4 | 0.99× | 1,590 MiB/1,766 MiB | – | – |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 11.4 | 1.5× | 339 MiB/376 MiB | 2.5 | 0.08 |
| Kernels | fp16 | 3.49 | 4.9× | 105 MiB/178 MiB | 4.3 | 0.00 |
| Portable + torch.compile | 9.27 | 1.9× | 336 MiB/356 MiB | 12 (build) | – | |
| TensorRT fp16 | fp16 | 5.51 | 3.1× | 792 MiBenginenot comparable | 61 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-03 to 2026-11-16. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two
times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.
Other devices
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14 | Original | fp32 | 147 | 4,085 MiB process | matches | 1024x2048 |
| Portable | fp16 | 113 | 1,521 MiB process | matches | 1024x2048 | |
| Portable | fp32 | 106 | 1,523 MiB process | matches | 1024x2048 | |
| Kernels | fp16 | not implemented | – | 1024x2048 | ||
| NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 14.8 | 312 MiB/336 MiB | – | 1024x2048 |
| Kernels | fp16 | 3.91 | 89 MiB/178 MiB | – | 1024x2048 | |
| NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 7.25 | 312 MiB/336 MiB | – | 1024x2048 |
| Kernels | fp16 | 1.76 | 89 MiB/178 MiB | – | 1024x2048 | |
| NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 9.78 | 312 MiB/336 MiB | – | 1024x2048 |
| Kernels | fp16 | 3.79 | 89 MiB/178 MiB | – | 1024x2048 | |
| NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-08 | Portable | fp16 | 8.68 | 312 MiB/336 MiB | – | 1024x2048 |
| Kernels | fp16 | 3.43 | 89 MiB/178 MiB | – | 1024x2048 | |
| NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08 | Portable | fp16 | 3.18 | 336 MiB/356 MiB | – | 1024x2048 |
| Kernels | fp16 | 1.24 | 137 MiB/218 MiB | – | 1024x2048 | |
CUDA memory is torch’s peak allocated / reserved; Apple has no such counter, so the Mac rows show the process footprint (weights, Python and torch included). “Output vs reference” compares the device’s output with the stored golden output under the card’s tolerance; – = not checked on that device. Kernels “not implemented” = no kernels for this model on that backend yet: it runs portable there.
Licence and weights
Non-commercial only
- Code
- Apache-2.0
- Weights
- LicenseRef-NVIDIA-Source-Code-License-NC source
- Training data
-
- ImageNet-1k (ILSVRC 2012 classification) noncommercial, non-commercial
- ADE20K (SceneParsing, 150 classes) noncommercial, non-commercial
- weights: LicenseRef-NVIDIA-Source-Code-License-NC
Our reading of the licences, not legal advice.
Weights
segformer-b0-ade20k.config.json 6.9 KB· hosted on Hugging Facesegformer-b0-ade20k.safetensors 15.0 MB· hosted on Hugging Facefastforks downloads and checks these files on first use (fastforks download segformer-b0-ade20k). Non-commercial weights need FASTFORKS_NONCOMMERCIAL=1.
Accuracy
The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.
ADE20K val
every 4th image, mIoU / aAcc %
| Run | dtype | mIoU % ↑ | aAcc % ↑ | Δ mIoU % vs fp32 original | images | ms / image |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 34.68 | 76.41 | reference | 500 | 12.4 |
| Original fp16 | fp16 | 34.68 | 76.41 | ±0.00 | 500 | 14.8 |
| Portable fp32 | not measured | |||||
| Portable | fp16 | 34.67 | 76.41 | −0.01 | 500 | 6.37 |
| Kernels | fp16 | 34.67 | 76.41 | −0.01 | 500 | 4.14 |
Each image at its own size, argmax of the logits. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-06; portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06.
Closeness to the original
Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. 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).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.002 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.02 | 0.00916 |
| GPU default dtypes, p99 |diff| | ≤ 0.1 | 0.03086 |
Recorded for segformer-b0-ade20k on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13, with these kernels: cudnn_haccfvm_convfvm_extrafvm_mbfvm_r3seg_up
Details
SegFormer (Xie et al. 2021): hierarchical Mix Transformer encoder (overlapping patch embeddings, reduced-key attention, Mix-FFN) and an all-MLP decoder.
- Input / output
- Input: one RGB image. Output: per-pixel class labels (logits with
logits=True). - Input size
- any H x W >= 1, resized or padded inside the model; tested up to 3000x4000 (3,888 MiB allocated)
- Outputs
logits- Checkpoint
resize=["mmseg",2048,512]- CUDA kernels
cudnn_haccconvolutions with fp16 accumulation (cuDNN)fvm_convfused convolutions for image classifiersfvm_extrafused transformer row operations (rotary split, SwiGLU with LayerNorm)fvm_mbfused MBConv blocks (MobileNet and EfficientNet families)fvm_r3further fused classifier blocksseg_upfused resize and argmax of segmentation scores
- Apple (MPS)
- fp32, fp16
Full reference, generated from the repository
NVIDIA's SegFormer: a transformer for ADE20K scene segmentation (sizes B0 and B5), plus two community fine-tunes: clothes parsing (B2, 18 classes) and face parsing (B5, 19 classes). Non-commercial weights.
Commercial use: segformer-b0-ade20k, segformer-b5-ade20k, segformer-b2-clothes: no (weights: LicenseRef-NVIDIA-Source-Code-License-NC); segformer-b5-face-parsing: no (weights: LicenseRef-noncommercial).
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
segformer-b0-ade20k (resize 2048x512) | synthetic (1024x2048) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 17.2 17.4 11.4 3.49 9.27 5.51 | 1583 / 1638 1590 / 1766 339 / 376 105 / 178 336 / 356 1480 / 1522 |
segformer-b5-ade20k (resize 2048x640) | synthetic (1024x2048) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 132 72.0 38.7 25.4 31.4 22.8 | 2529 / 2538 2531 / 2620 546 / 590 294 / 432 543 / 630 2069 / 2110 |
segformer-b2-clothes (resize 512x512) | synthetic (512x512) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 18.9 14.1 8.13 3.61 4.38 2.68 | 829 / 902 425 / 488 156 / 168 133 / 170 182 / 228 312 / 328 |
segformer-b5-face-parsing (resize 512x512) | synthetic (512x512) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 38.8 34.2 21.9 9.21 14.1 6.33 | 1163 / 1284 647 / 758 278 / 292 257 / 294 305 / 352 538 / 552 |
Details
- Original code: https://github.com/huggingface/transformers at
c4c4605f9618 - Code licence: Apache-2.0 (permissive); files:
- Weights licence: LicenseRef-NVIDIA-Source-Code-License-NC
segformer-b5-face-parsing: LicenseRef-noncommercial
- Licence evidence: https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512/blob/489d5cd81a0b59fab9b7ea758d3548ebe99677da/README.md
- Training data: ImageNet-1k (ILSVRC 2012 classification), ADE20K (SceneParsing, 150 classes)
segformer-b2-clothes: ImageNet-1k (ILSVRC 2012 classification), ATR human parsing dataset (18 clothes / body-part classes; SegFormer-B2 clothes: Hugging Face mirror mattmdjaga/human_parsing_dataset)segformer-b5-face-parsing: ImageNet-1k (ILSVRC 2012 classification), CelebAMask-HQ (30 000 CelebA-HQ faces, 19 face-part masks)
- Kernel libraries:
cudnn_hacc,fvm_conv,fvm_extra,fvm_mb,fvm_r3,seg_up - Variants:
segformer-b0-ade20k,segformer-b5-ade20k,segformer-b2-clothes,segformer-b5-face-parsing - Outputs: logits; label_set:
ade20k-150 - 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-ade20k3000x4000 (3.8 GiB peak allocated, 4.0 reserved);segformer-b5-ade20k3000x4000 (4.0 GiB peak allocated, 4.3 reserved);segformer-b2-clothes3000x4000 (0.6 GiB peak allocated, 0.7 reserved);segformer-b5-face-parsing3000x4000 (0.7 GiB peak allocated, 0.9 reserved) segformer-b0-ade20k1024x2048, first call: portable + torch.compile 12 s (cold Inductor cache), TensorRT fp16 61 s (ONNX + engine).segformer-b5-ade20k1024x2048, first call: portable + torch.compile 34 s (cold Inductor cache), TensorRT fp16 84 s (ONNX + engine).segformer-b2-clothes512x512, first call: portable + torch.compile 18 s (cold Inductor cache), TensorRT fp16 63 s (ONNX + engine).segformer-b5-face-parsing512x512, first call: portable + torch.compile 35 s (cold Inductor cache), TensorRT fp16 85 s (ONNX + engine).segformer-b0-ade20koriginal 1024x2048: torch.autocast(fp16) around the forwardsegformer-b5-ade20koriginal 1024x2048: torch.autocast(fp16) around the forwardsegformer-b2-clothesoriginal (fp32) 512x512: transformers SegformerForSemanticSegmentation, logits upsampled bilinear + argmax, float32; pinned transformers checkpointsegformer-b2-clothesoriginal 512x512: transformers SegformerForSemanticSegmentation, logits upsampled bilinear + argmax, .half(); pinned transformers checkpointsegformer-b5-face-parsingoriginal (fp32) 512x512: transformers SegformerForSemanticSegmentation, logits upsampled bilinear + argmax, float32; pinned transformers checkpointsegformer-b5-face-parsingoriginal 512x512: transformers SegformerForSemanticSegmentation, logits upsampled bilinear + argmax, .half(); pinned transformers checkpointsegformer-b0-ade20kload / first call: original 4.83 s / 2.232 s (512x512), portable 2.55 s / 0.082 s, kernels 2.92 s / 0.009 ssegformer-b5-ade20kload / first call: original 1.24 s / 0.501 s (512x512), portable 3.09 s / 0.077 s, kernels 3.43 s / 0.032 ssegformer-b2-clothesload / first call: portable 3.72 s / 0.245 s (512x512), kernels 3.65 s / 0.062 s (512x512)segformer-b5-face-parsingload / first call: portable 4.16 s / 0.228 s (512x512), kernels 4.87 s / 0.093 s (512x512)- Protocol,
segformer-b0-ade20k,segformer-b5-ade20k: first call, 3 warm-up, peak reset, median of 3 rounds x median of 5 (tools/speed_check.py), synthetic CUDA input (bench_inputs); peak = max over the first call and the timed calls - Protocol,
segformer-b2-clothes,segformer-b5-face-parsing: first call, 3 warm-up, peak reset, median of 3 rounds x median of 5
Measured
Each image at its own size, argmax of the logits. Original = the original code named under Details, same checkpoint and protocol.
| variant | dataset | original fp32 | original fp16 | portable | kernels | note |
|---|---|---|---|---|---|---|
segformer-b0-ade20k | ADE20K val, every 4th image, mIoU / aAcc % | 34.68 / 76.41 | 34.68 / 76.41 | 34.67 / 76.41 | 34.67 / 76.41 | |
segformer-b5-ade20k | ADE20K val, every 4th image, mIoU / aAcc % | 48.28 / 82.75 | 48.28 / 82.75 | 48.28 / 82.75 | 48.28 / 82.75 |
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06.
Parity
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).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
segformer-b0-ade20k | 0.00916 / 0.03086 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120, seg_up@3e44e71200cd:sm_120 |
segformer-b5-ade20k | 0.01145 / 0.03991 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120, seg_up@3e44e71200cd:sm_120 |
segformer-b2-clothes | 0.00924 / 0.0351 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120, seg_up@3e44e71200cd:sm_120 |
segformer-b5-face-parsing | 0.01211 / 0.04755 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120, seg_up@3e44e71200cd:sm_120 |
Example output
One fixed input through this checkpoint, the same for every model of the task (portable · float16 · NVIDIA GeForce RTX 5060 Ti).
- table 52%
- plate 30%
- tray 16%
- glass 2.1%
- countertop 0.4%
- wall <0.1%
Input: A cup of coffee, Rachel Michetti (CC0).