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
- Paper Masked-attention Mask Transformer for Universal Image Segmentation CVPR 2022 · first released 2 Dec 2021
- Authors’ code facebookresearch/Mask2Former (PyTorch), not the code forked here: The authors' code needs detectron2; the transformers port is self-contained.
Checkpoint mask2former-swinl-ade20k
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("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.
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 244 | 0.59× | 2,966 MiB/3,660 MiB | – | – |
| Original fp16torch.autocast(fp16) around the forward | fp16 | 145 | – | 3,572 MiB/3,878 MiB | – | – |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 103 | 1.4× | 1,164 MiB/1,400 MiB | 3.0 | 0.13 |
| Kernels | fp16 | 60.4 | 2.4× | 1,164 MiB/1,400 MiB | 3.2 | 0.07 |
| Portable + torch.compileInductor: Triton kernel does not compile (torch bug) | fails | – | – | – | – | |
| TensorRT fp16 | fp16 | 55.6 | 2.6× | 1,816 MiBenginenot comparable | 129 (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
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-12 | Original | fp32 | 933 | 7,342 MiB process | matches | 1024x2048 |
| Portable | fp16 | 964 | 4,503 MiB process | matches | 1024x2048 | |
| Portable | fp32 | 909 | 6,661 MiB process | matches | 1024x2048 | |
| Kernels | fp16 | not implemented | – | 1024x2048 | ||
| NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 124 | 1,131 MiB/1,358 MiB | – | 1024x2048 |
| Kernels | fp16 | 77.8 | 1,131 MiB/1,358 MiB | – | 1024x2048 | |
| NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 48.4 | 1,131 MiB/1,358 MiB | – | 1024x2048 |
| Kernels | fp16 | 32.8 | 1,131 MiB/1,358 MiB | – | 1024x2048 | |
| NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 94.5 | 1,131 MiB/1,358 MiB | – | 1024x2048 |
| Kernels | fp16 | 67.4 | 1,131 MiB/1,358 MiB | – | 1024x2048 | |
| NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 52.1 | 1,131 MiB/1,358 MiB | – | 1024x2048 |
| Kernels | fp16 | 35.3 | 1,131 MiB/1,358 MiB | – | 1024x2048 | |
| NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08 | Portable | fp16 | 24.9 | 1,155 MiB/1,338 MiB | – | 1024x2048 |
| Kernels | fp16 | 16.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
-
- ImageNet-21k / ImageNet-22k (full ImageNet, fall 2011 release) noncommercial, non-commercial
- ADE20K (SceneParsing, 150 classes) noncommercial, non-commercial
- 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 Facemask2former-swinl-ade20k.safetensors 866 MB· hosted on Hugging Facefastforks 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 %
| Run | dtype | mIoU % ↑ | aAcc % ↑ | Δ mIoU % vs fp32 original | images | ms / image |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 53.55 | 85.10 | reference | 500 | 163 |
| Original fp16 | fp16 | 53.63 | 85.10 | +0.08 | 500 | 96.6 |
| Portable fp32 | fp32 | 53.59 | 85.13 | +0.04 | 500 | 161 |
| Portable | fp16 | 53.68 | 85.12 | +0.13 | 500 | 70.1 |
| Kernels | fp16 | 53.68 | 85.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).
| Check | Tolerance | Measured |
|---|---|---|
| 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 OneFormerseg_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).
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
mask2former-swinl-ade20k | synthetic (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-ade20k3000x4000 (14.1 GiB peak allocated, 15.1 reserved) mask2former-swinl-ade20k1024x2048, first call: TensorRT fp16 129 s (ONNX + engine).mask2former-swinl-ade20koriginal 1024x2048: torch.autocast(fp16) around the forwardmask2former-swinl-ade20kload / 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.
| variant | dataset | original fp32 | original fp16 | portable | portable fp32 | kernels | note |
|---|---|---|---|---|---|---|---|
mask2former-swinl-ade20k | ADE20K val, every 4th image, mIoU / aAcc % | 53.55 / 85.10 | 53.63 / 85.10 | 53.68 / 85.12 | 53.59 / 85.13 | 53.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).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
mask2former-swinl-ade20k | 2e-05 / 0.00024 | RTX 5060 Ti, torch 2.14.1+cu130 | fvm_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).
- table 51%
- plate 29%
- barrel 15%
- floor 3.4%
- ball 1.1%
Input: A cup of coffee, Rachel Michetti (CC0).