Models · Image restoration

Swin2SR

Swin2SR (Conde et al., ECCVW 2022): SwinIR with Swin Transformer V2 blocks: x4 / x2 upscalers for clean (bicubic) images and a x4 model for real-world photos. Apache-2.0 code and weights.

experimental Fork of mv-lab/swin2sr@6f25d76 · backends: portable, kernels

Checkpoint

Paper 2022 Added in 0.2.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 745 ms 512x512, fp16
vs the faster original 3.9× original fp16: 2922 ms
Peak memory 1,459 MiB original: 1,488 MiB
Accuracy vs original fp32 −0.01 kernels psnr, DIV2K validation (every 2nd: 50 images) (30.89 original)

Use it

pip install fastforks

Lean install with only what this model needs: pip install fastforks-core

from fastforks import restoration

model = restoration.load("swin2sr-x4")  # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.image
result.backend  # what ran: mode, device, dtype, kernels
fastforks bench swin2sr-x4

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.

Input: synthetic, 512x512 (the task’s standard size)

BackenddtypeTime per call (ms)vs original fp16Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32fp32not measured ––––
Original fp16.half() on 1 modules, fp16 inputs; upstream main_test_swin2sr.py, float32, no tilefp16 2922–1,488 MiB/2,160 MiB0.33.02
Portable fp32fp32not measured ––––
Portablefp16 9323.1×1,463 MiB/2,276 MiB0.71.15
Kernelsfp16 7453.9×1,459 MiB/1,736 MiB0.60.87
Portable + torch.compile 4965.9×1,308 MiB/1,556 MiB46 (build)–
TensorRT fp16fp16 5565.3×5,154 MiBenginenot comparable113 (build)–

Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-14 to 2026-11-15. 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-15Originalfp3212965 7,727 MiB process–512x512
Portablefp169410 4,580 MiB processmatches512x512
Portablefp329608 8,391 MiB processmatches512x512
Kernelsfp16not implemented–512x512

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

Commercial use allowed

Code
Apache-2.0 LICENSE
Weights
Apache-2.0 source
Training data

Our reading of the licences, not legal advice.

Weights

Swin2SR_ClassicalSR_X4_64.pth 69.4 MB· hosted on GitHub

fastforks downloads and checks these files on first use (fastforks download swin2sr-x4).

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.

DIV2K validation (every 2nd: 50 images)

bicubic x4 LR -> HR, PSNR / SSIM (Y)

Rundtypepsnr ↑ssim ↑Δ psnr vs fp32 originalimagesms / image
Original fp32fp3230.890.8420 reference 50 –
Original fp16not measured
Portable fp32fp3230.890.8420 ±0.00 50 –
Portablefp1630.890.8420 ±0.00 50 –
Kernelsfp1630.880.8420 −0.01 50 –

DIV2K validation HR images and the official bicubic LR images (x4 or x2, the model's scale), one pass without tiles; PSNR and SSIM (Gaussian 11 x 11, sigma 1.5) on the Y channel (BT.601) of the output rounded to uint8, `scale` px border cropped, averaged over the images. Real-ESRGAN is trained for real-world degradations, not bicubic, so its PSNR is low: the numbers compare our modes with the original, not with PSNR-oriented upscalers. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-14; portable fp32, portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks f104019b, 2026-11-14.

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| <= 1.4e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 and p99 <= 0.25 (absolute error of the output image).

CheckToleranceMeasured
CPU fp32, max |diff|≤ 0.000014 not recorded
GPU default dtypes, mean |diff|≤ 0.02 0.00055
GPU default dtypes, p99 |diff|≤ 0.25 0.00205

Recorded for swin2sr-x4 on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-14, with these kernels: cudnn_hacc

Details

Swin2SR (Conde et al., ECCVW 2022): SwinIR with Swin Transformer V2 layers (scaled cosine attention, continuous log-spaced position bias, residual post-norm) in residual groups between a conv stem and an upsampler. `swin2sr-x2` / `swin2sr-x4` are the classical (bicubic, PSNR-trained) DIV2K + Flickr2K models, `swin2sr-x4-real` the real-world x4 PSNR model (BSRGAN degradations).

Input / output
Input: one RGB image. Output: the restored (upscaled) image, model.scale x the input size, RGB in [0, 1].
What the numbers mean, and which models need the camera focal length

tile= runs large images in overlapping tiles (as ComfyUI).

Input size
any H x W >= 32, padded to a multiple of 32; tested up to 1024x2048 (10.9 GiB allocated)
Outputs
image
CUDA kernels
  • cudnn_haccconvolutions with fp16 accumulation (cuDNN)
Apple (MPS)
fp32, fp16

Limitations

  • Kernels peak allocated is equal to portable, but the cuDNN workspace next to the large conv maps fragments the allocator: peak reserved is ~80 MiB above portable.
Full reference, generated from the repository

Swin2SR (Conde et al., ECCVW 2022): SwinIR with Swin Transformer V2 blocks: x4 / x2 upscalers for clean (bicubic) images and a x4 model for real-world photos. Apache-2.0 code and weights.

Commercial use: yes.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
swin2sr-x4synthetic (512x512)original
portable
kernels
portable + torch.compile
TensorRT fp16
2922
932
745
496
556
1488 / 2160
1463 / 2276
1459 / 1736
1308 / 1556
5410 / 5470
swin2sr-x2synthetic (512x512)original
portable
kernels
portable + torch.compile
TensorRT fp16
2565
909
721
482
547
1488 / 1578
1459 / 1554
1459 / 1636
1308 / 1516
4941 / 4997
swin2sr-x4-realsynthetic (512x512)original
portable
kernels
portable + torch.compile
TensorRT fp16
2527
958
751
508
562
2321 / 2660
2354 / 2774
1459 / 1734
1308 / 1556
5409 / 5468
Details
  • Original code: https://github.com/mv-lab/swin2sr at 6f25d7689813
  • Code licence: Apache-2.0 (permissive); files: LICENSE
  • Weights licence: Apache-2.0
  • Licence evidence: https://github.com/mv-lab/swin2sr/blob/6f25d7689813f7dd12c5a212b638066fa71bc9e6/LICENSE ; https://github.com/mv-lab/swin2sr/releases/tag/v0.0.1
  • Training data: DIV2K (NTIRE 2017 super-resolution, 1000 2K images), Flickr2K (2650 2K Flickr images, EDSR) (README, Results: trained mainly on DIV2K and Flickr2K, setup as SwinIR (classical SR: bicubic-downsampled HR images).)
  • Kernel libraries: cudnn_hacc
  • Variants: swin2sr-x4, swin2sr-x2, swin2sr-x4-real
  • Outputs: image
  • Input size: any H x W >= 32, padded to a multiple of 32
  • Tested up to (portable, fp16, RTX 5060 Ti 16 GB): swin2sr-x4 1024x2048 (10.9 GiB peak allocated, 13.7 reserved); swin2sr-x2 1024x2048 (10.9 GiB peak allocated, 13.3 reserved); swin2sr-x4-real 1024x2048 (13.1 GiB peak allocated, 15.2 reserved)
  • swin2sr-x4 512x512, first call: portable + torch.compile 46 s (cold Inductor cache), TensorRT fp16 113 s (ONNX + engine).
  • swin2sr-x2 512x512, first call: portable + torch.compile 44 s (cold Inductor cache), TensorRT fp16 112 s (ONNX + engine).
  • swin2sr-x4-real 512x512, first call: portable + torch.compile 42 s (cold Inductor cache), TensorRT fp16 128 s (ONNX + engine).
  • swin2sr-x4 original 512x512: .half() on 1 modules, fp16 inputs; upstream main_test_swin2sr.py, float32, no tile
  • swin2sr-x2 original 512x512: .half() on 1 modules, fp16 inputs; upstream main_test_swin2sr.py, float32, no tile
  • swin2sr-x4-real original 512x512: .half() on 1 modules, fp16 inputs; upstream main_test_swin2sr.py, float32, no tile
  • swin2sr-x4 load / first call: original 1.63 s / 3.583 s, portable 0.48 s / 1.16 s, kernels 0.57 s / 1.023 s
  • swin2sr-x2 load / first call: original 1.81 s / 4.125 s, portable 0.49 s / 1.154 s, kernels 0.62 s / 0.863 s
  • swin2sr-x4-real load / first call: original 1.89 s / 3.754 s, portable 0.47 s / 1.179 s, kernels 0.57 s / 0.882 s
  • Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5

Measured

DIV2K validation HR images and the official bicubic LR images (x4 or x2, the model's scale), one pass without tiles; PSNR and SSIM (Gaussian 11 x 11, sigma 1.5) on the Y channel (BT.601) of the output rounded to uint8, scale px border cropped, averaged over the images. Real-ESRGAN is trained for real-world degradations, not bicubic, so its PSNR is low: the numbers compare our modes with the original, not with PSNR-oriented upscalers. Original = the original code named under Details, same checkpoint and protocol.

variantdatasetoriginal fp32portableportable fp32kernelsnote
swin2sr-x4DIV2K validation (every 2nd: 50 images), bicubic x4 LR -> HR, PSNR / SSIM (Y)30.89 / 0.842030.89 / 0.842030.89 / 0.842030.88 / 0.8420
swin2sr-x2DIV2K validation (every 4th: 25 images), bicubic x2 LR -> HR, PSNR / SSIM (Y)36.43 / 0.942336.43 / 0.942336.43 / 0.942336.43 / 0.9423
swin2sr-x4-realDIV2K validation (every 2nd: 50 images), bicubic x4 LR -> HR, PSNR / SSIM (Y)29.04 / 0.802129.04 / 0.802129.04 / 0.802129.05 / 0.8021

Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks f104019b, 2026-11-14.

Parity

CPU, float32: max |diff| <= 1.4e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 and p99 <= 0.25 (absolute error of the output image).

variantkernels error vs original, mean / p99GPU, torchkernels used
swin2sr-x40.00055 / 0.00205RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400
swin2sr-x20.00063 / 0.00232RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400
swin2sr-x4-real0.00037 / 0.00138RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400

Limitations

  • Kernels peak allocated is equal to portable, but the cuDNN workspace next to the large conv maps fragments the allocator: peak reserved is ~80 MiB above portable.

Example output

No example rendered for this checkpoint yet.