Swin Transformer
Swin Transformer (Liu et al. 2021): a vision transformer with shifted-window attention.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
swin_base_patch4_window7_224.ms_in22k_ft_in1k | synthetic (224x224) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 15.0 19.1 10.8 2.15 4.19 1.48 | 389 / 416 538 / 550 213 / 394 246 / 300 243 / 270 202 (engine) |
Details
- Original code: https://github.com/huggingface/pytorch-image-models at
0df212b369a5 - Code licence: Apache-2.0 (permissive); files:
- Weights licence: MIT
- Licence evidence: https://huggingface.co/timm/swin_base_patch4_window7_224.ms_in22k_ft_in1k/blob/a6a1eb2321b4f556fa0fa243fb777d47679f13c9/README.md
- Training data: ImageNet-21k / ImageNet-22k (full ImageNet, fall 2011 release), ImageNet-1k (ILSVRC 2012 classification)
- Kernel libraries:
cudnn_hacc,fvm_conv,fvm_extra,fvm_mb,fvm_r3 - Variants:
swin_base_patch4_window7_224.ms_in22k_ft_in1k(default ofswin_base_patch4_window7_224) - Outputs: logits; label_set:
imagenet-1k - Input size: fixed 224x224: the input is resized (short side 248) and centre-cropped to it
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
swin_base_patch4_window7_224.ms_in22k_ft_in1k224x224 (0.2 GiB peak allocated, 0.3 reserved) swin_base_patch4_window7_224.ms_in22k_ft_in1k224x224, first call: portable + torch.compile 27 s (cold Inductor cache), TensorRT fp16 64 s (ONNX + engine).swin_base_patch4_window7_224.ms_in22k_ft_in1koriginal 224x224: torch.autocast(fp16) around the forwardswin_base_patch4_window7_224.ms_in22k_ft_in1kload / first call: original 2.71 s / 0.414 s, portable 0.94 s / 0.026 s, kernels 2.28 s / 0.087 s- Protocol, median of 5 after 3 warm-up, uint8 CUDA input (synthetic for bench_inputs sizes), card defaults; gc before each load; peak = max over the first call and the timed calls
Measured
fastforks: the model's own resize / crop on the GPU; original: the library's pretrained loader and its PIL eval transform. Original = the original code named under Details, same checkpoint and protocol.
| variant | dataset | original fp32 | original fp16 | portable | kernels | note |
|---|---|---|---|---|---|---|
swin_base_patch4_window7_224.ms_in22k_ft_in1k | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 86.28 / 97.82 | 86.30 / 97.82 | 86.24 / 97.86 | 86.24 / 97.86 |
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.08 (absolute error of the output logits).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
swin_base_patch4_window7_224.ms_in22k_ft_in1k | 0.00178 / 0.00688 | 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 |