Models · Semantic segmentation

Mask2Former

Mask2Former with a Swin-L backbone for ADE20K scene segmentation. Non-commercial weights.

stable Fork of huggingface/transformers@c4c4605 · backends: portable, kernels

Checkpoint mask2former-swinl-ade20k

Paper 2021 Added in 0.1.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 60.4 ms 1024x2048, fp16
vs the faster original 2.4× original fp16: 145 ms
Peak memory 1,164 MiB original: 3,572 MiB
Accuracy vs original fp32 +0.13 kernels mIoU %, ADE20K val (53.55 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("mask2former-swinl-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 mask2former-swinl-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 fp16Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32fp32 2440.59×2,966 MiB/3,660 MiB––
Original fp16torch.autocast(fp16) around the forwardfp16 145–3,572 MiB/3,878 MiB––
Portable fp32fp32not measured ––––
Portablefp16 1031.4×1,164 MiB/1,400 MiB3.00.13
Kernelsfp16 60.42.4×1,164 MiB/1,400 MiB3.20.07
Portable + torch.compileInductor: Triton kernel does not compile (torch bug)fails––––
TensorRT fp16fp16 55.62.6×1,816 MiBenginenot comparable129 (build)–

Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-03 to 2026-11-04. 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. 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-12Originalfp32933 7,342 MiB processmatches1024x2048
Portablefp16964 4,503 MiB processmatches1024x2048
Portablefp32909 6,661 MiB processmatches1024x2048
Kernelsfp16not implemented–1024x2048
NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp16124 1,131 MiB/1,358 MiB–1024x2048
Kernelsfp1677.8 1,131 MiB/1,358 MiB–1024x2048
NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp1648.4 1,131 MiB/1,358 MiB–1024x2048
Kernelsfp1632.8 1,131 MiB/1,358 MiB–1024x2048
NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp1694.5 1,131 MiB/1,358 MiB–1024x2048
Kernelsfp1667.4 1,131 MiB/1,358 MiB–1024x2048
NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp1652.1 1,131 MiB/1,358 MiB–1024x2048
Kernelsfp1635.3 1,131 MiB/1,358 MiB–1024x2048
NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08Portablefp1624.9 1,155 MiB/1,338 MiB–1024x2048
Kernelsfp1616.9 1,155 MiB/1,398 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
CC-BY-NC-4.0 source
Training data
  • weights: CC-BY-NC-4.0

Our reading of the licences, not legal advice.

Weights

mask2former-swinl-ade20k.config.json 82.5 KB· hosted on Hugging Face
mask2former-swinl-ade20k.safetensors 866 MB· hosted on Hugging Face

fastforks downloads and checks these files on first use (fastforks download mask2former-swinl-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 fp32fp3253.5585.10 reference 500 163
Original fp16fp1653.6385.10 +0.08 500 96.6
Portable fp32fp3253.5985.13 +0.04 500 161
Portablefp1653.6885.12 +0.13 500 70.1
Kernelsfp1653.6885.10 +0.13 500 44.2

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 fp32: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 44640884, 2026-11-17; 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.001 and p99 <= 0.01 (absolute error of the output logits).

CheckToleranceMeasured
CPU fp32, max |diff|≤ 0.002 not recorded
GPU default dtypes, mean |diff|≤ 0.001 0.00002
GPU default dtypes, p99 |diff|≤ 0.01 0.00024

Recorded for mask2former-swinl-ade20k on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-04, with these kernels: fvm_segseg_up

Details

Mask2Former (Cheng et al. 2022): Swin backbone, multi-scale deformable attention pixel decoder and a masked-attention transformer decoder; semantic logits from mask classification.

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 (14.1 GiB allocated)
Outputs
logits
CUDA kernels
  • fvm_segfused kernels for Mask2Former and OneFormer
  • seg_upfused resize and argmax of segmentation scores
Apple (MPS)
fp32, fp16
Full reference, generated from the repository

Mask2Former with a Swin-L backbone for ADE20K scene segmentation. Non-commercial weights.

Commercial use: no (weights: CC-BY-NC-4.0).

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
mask2former-swinl-ade20ksynthetic (1024x2048)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
244
145
103
60.4
fails: Inductor: Triton kernel does not compile (torch bug)
55.6
2966 / 3660
3572 / 3878
1164 / 1400
1164 / 1400
–
3051 / 3090
Details
  • Original code: https://github.com/huggingface/transformers at c4c4605f9618
  • Code licence: Apache-2.0 (permissive); files:
  • Weights licence: CC-BY-NC-4.0
  • Licence evidence: https://github.com/facebookresearch/Mask2Former/blob/9b0651c6c1d5b3af2e6da0589b719c514ec0d69a/MODEL_ZOO.md#license
  • Training data: ImageNet-21k / ImageNet-22k (full ImageNet, fall 2011 release), ADE20K (SceneParsing, 150 classes)
  • Kernel libraries: fvm_seg, seg_up
  • Variants: mask2former-swinl-ade20k
  • 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): mask2former-swinl-ade20k 3000x4000 (14.1 GiB peak allocated, 15.1 reserved)
  • mask2former-swinl-ade20k 1024x2048, first call: TensorRT fp16 129 s (ONNX + engine).
  • mask2former-swinl-ade20k original 1024x2048: torch.autocast(fp16) around the forward
  • mask2former-swinl-ade20k load / first call: original 4.86 s / 0.763 s (512x512), portable 3.03 s / 0.127 s, kernels 3.17† s / 0.069† s
  • † measured in the speed sweep after the portable load (or an earlier size) in the same process: file cache and kernels are warm, so the time is lower than a fresh start.
  • Protocol, 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

Measured

Each image at its own size, argmax of the logits. Original = the original code named under Details, same checkpoint and protocol.

variantdatasetoriginal fp32original fp16portableportable fp32kernelsnote
mask2former-swinl-ade20kADE20K val, every 4th image, mIoU / aAcc %53.55 / 85.1053.63 / 85.1053.68 / 85.1253.59 / 85.1353.68 / 85.10

Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 44640884, 2026-11-17; kernels: 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.001 and p99 <= 0.01 (absolute error of the output logits).

variantkernels error vs original, mean / p99GPU, torchkernels used
mask2former-swinl-ade20k2e-05 / 0.00024RTX 5060 Ti, torch 2.14.1+cu130fvm_seg@739693dff3b4:sm_120, seg_up@3e44e71200cd:sm_120

Example output

One fixed input through this checkpoint, the same for every model of the task (kernels · float16 · NVIDIA GeForce RTX 5060 Ti).

Input
Output
  • table 51%
  • plate 29%
  • barrel 15%
  • floor 3.4%
  • ball 1.1%
A cup of coffee, input
Input · 100%

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