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

Checkpoint

resize 2048x512

Paper 2021 Added in 0.1.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 3.49 ms 1024x2048, fp16
vs the faster original 4.9× original fp32: 17.3 ms
Peak memory 105 MiB original: 1,583 MiB
Accuracy vs original fp32 −0.01 kernels mIoU %, ADE20K val (34.68 original)

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.

BackenddtypeTime per call (ms)vs original fp32Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32fp32 17.3–1,583 MiB/1,638 MiB––
Original fp16torch.autocast(fp16) around the forwardfp16 17.40.99×1,590 MiB/1,766 MiB––
Portable fp32fp32not measured ––––
Portablefp16 11.41.5×339 MiB/376 MiB2.50.08
Kernelsfp16 3.494.9×105 MiB/178 MiB4.30.00
Portable + torch.compile 9.271.9×336 MiB/356 MiB12 (build)–
TensorRT fp16fp16 5.513.1×792 MiBenginenot comparable61 (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

DeviceBackenddtypems / callPeak memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14Originalfp32147 4,085 MiB processmatches1024x2048
Portablefp16113 1,521 MiB processmatches1024x2048
Portablefp32106 1,523 MiB processmatches1024x2048
Kernelsfp16not implemented–1024x2048
NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp1614.8 312 MiB/336 MiB–1024x2048
Kernelsfp163.91 89 MiB/178 MiB–1024x2048
NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp167.25 312 MiB/336 MiB–1024x2048
Kernelsfp161.76 89 MiB/178 MiB–1024x2048
NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp169.78 312 MiB/336 MiB–1024x2048
Kernelsfp163.79 89 MiB/178 MiB–1024x2048
NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-08Portablefp168.68 312 MiB/336 MiB–1024x2048
Kernelsfp163.43 89 MiB/178 MiB–1024x2048
NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08Portablefp163.18 336 MiB/356 MiB–1024x2048
Kernelsfp161.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
  • 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 Face
segformer-b0-ade20k.safetensors 15.0 MB· hosted on Hugging Face

fastforks 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 %

RundtypemIoU % ↑aAcc % ↑Δ mIoU % vs fp32 originalimagesms / image
Original fp32fp3234.6876.41 reference 500 12.4
Original fp16fp1634.6876.41 ±0.00 500 14.8
Portable fp32not measured
Portablefp1634.6776.41 −0.01 500 6.37
Kernelsfp1634.6776.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).

CheckToleranceMeasured
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 classifiers
  • fvm_extrafused transformer row operations (rotary split, SwiGLU with LayerNorm)
  • fvm_mbfused MBConv blocks (MobileNet and EfficientNet families)
  • fvm_r3further fused classifier blocks
  • seg_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).

variantinputbackendtime (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-ade20k 3000x4000 (3.8 GiB peak allocated, 4.0 reserved); segformer-b5-ade20k 3000x4000 (4.0 GiB peak allocated, 4.3 reserved); segformer-b2-clothes 3000x4000 (0.6 GiB peak allocated, 0.7 reserved); segformer-b5-face-parsing 3000x4000 (0.7 GiB peak allocated, 0.9 reserved)
  • segformer-b0-ade20k 1024x2048, first call: portable + torch.compile 12 s (cold Inductor cache), TensorRT fp16 61 s (ONNX + engine).
  • segformer-b5-ade20k 1024x2048, first call: portable + torch.compile 34 s (cold Inductor cache), TensorRT fp16 84 s (ONNX + engine).
  • segformer-b2-clothes 512x512, first call: portable + torch.compile 18 s (cold Inductor cache), TensorRT fp16 63 s (ONNX + engine).
  • segformer-b5-face-parsing 512x512, first call: portable + torch.compile 35 s (cold Inductor cache), TensorRT fp16 85 s (ONNX + engine).
  • segformer-b0-ade20k original 1024x2048: torch.autocast(fp16) around the forward
  • segformer-b5-ade20k original 1024x2048: torch.autocast(fp16) around the forward
  • segformer-b2-clothes original (fp32) 512x512: transformers SegformerForSemanticSegmentation, logits upsampled bilinear + argmax, float32; pinned transformers checkpoint
  • segformer-b2-clothes original 512x512: transformers SegformerForSemanticSegmentation, logits upsampled bilinear + argmax, .half(); pinned transformers checkpoint
  • segformer-b5-face-parsing original (fp32) 512x512: transformers SegformerForSemanticSegmentation, logits upsampled bilinear + argmax, float32; pinned transformers checkpoint
  • segformer-b5-face-parsing original 512x512: transformers SegformerForSemanticSegmentation, logits upsampled bilinear + argmax, .half(); pinned transformers checkpoint
  • segformer-b0-ade20k load / first call: original 4.83 s / 2.232 s (512x512), portable 2.55 s / 0.082 s, kernels 2.92 s / 0.009 s
  • segformer-b5-ade20k load / first call: original 1.24 s / 0.501 s (512x512), portable 3.09 s / 0.077 s, kernels 3.43 s / 0.032 s
  • segformer-b2-clothes load / first call: portable 3.72 s / 0.245 s (512x512), kernels 3.65 s / 0.062 s (512x512)
  • segformer-b5-face-parsing load / 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.

variantdatasetoriginal fp32original fp16portablekernelsnote
segformer-b0-ade20kADE20K val, every 4th image, mIoU / aAcc %34.68 / 76.4134.68 / 76.4134.67 / 76.4134.67 / 76.41
segformer-b5-ade20kADE20K val, every 4th image, mIoU / aAcc %48.28 / 82.7548.28 / 82.7548.28 / 82.7548.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).

variantkernels error vs original, mean / p99GPU, torchkernels used
segformer-b0-ade20k0.00916 / 0.03086RTX 5060 Ti, torch 2.14.1+cu130cudnn_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-ade20k0.01145 / 0.03991RTX 5060 Ti, torch 2.14.1+cu130cudnn_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-clothes0.00924 / 0.0351RTX 5060 Ti, torch 2.14.1+cu130cudnn_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-parsing0.01211 / 0.04755RTX 5060 Ti, torch 2.14.1+cu130cudnn_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).

Input
Output
  • table 52%
  • plate 30%
  • tray 16%
  • glass 2.1%
  • countertop 0.4%
  • wall <0.1%
A cup of coffee, input
Input · 100%

Input: A cup of coffee, Rachel Michetti (CC0).