SwinIR
SwinIR (Liang et al., ICCVW 2021): a Swin Transformer upscaler: x4 / x2 for clean (bicubic) images and x4 for real-world photos (medium and large). Apache-2.0 code and weights.
experimental Fork of JingyunLiang/SwinIR@6545850 · backends: portable, kernels
- Paper SwinIR: Image Restoration Using Swin Transformer ICCVW 2021 · first released 23 Aug 2021
Paper 2021 Added in 0.2.0 Evaluated with 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install fastforks-core
from fastforks import restoration
model = restoration.load("swinir-m-x4") # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.image
result.backend # what ran: mode, device, dtype, kernels fastforks bench swinir-m-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)
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | not measured | – | – | – | – |
| Original fp16.half() on 1 modules, fp16 inputs; upstream main_test_swinir.py, float32, no tile | fp16 | 3497 | – | 1,500 MiB/2,058 MiB | 1.6 | 2.86 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 767 | 4.6× | 1,499 MiB/2,054 MiB | 0.6 | 0.77 |
| Kernels | fp16 | 576 | 6.1× | 1,354 MiB/1,456 MiB | 0.7 | 0.64 |
| Portable + torch.compile | 795 | 4.4× | 1,684 MiB/1,796 MiB | 62 (build) | – | |
| TensorRT fp16 | fp16 | 727 | 4.8× | 5,270 MiBenginenot comparable | 104 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-13 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
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14 | Original | fp32 | 8782 | 7,699 MiB process | – | 512x512 |
| Portable | fp16 | 5893 | 5,060 MiB process | matches | 512x512 | |
| Portable | fp32 | 6506 | 8,392 MiB process | matches | 512x512 | |
| Kernels | fp16 | not 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
-
- DIV2K (NTIRE 2017 super-resolution, 1000 2K images) research-only, non-commercial
- Flickr2K (2650 2K Flickr images, EDSR) not stated
Our reading of the licences, not legal advice.
Weights
001_classicalSR_DF2K_s64w8_SwinIR-M_x4.pth 67.9 MB· hosted on GitHubfastforks downloads and checks these files on first use (fastforks download swinir-m-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)
| Run | dtype | psnr ↑ | ssim ↑ | Δ psnr vs fp32 original | images | ms / image |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 30.90 | 0.8423 | reference | 50 | – |
| Original fp16 | not measured | |||||
| Portable fp32 | fp32 | 30.90 | 0.8423 | ±0.00 | 50 | – |
| Portable | fp16 | 30.90 | 0.8423 | ±0.00 | 50 | – |
| Kernels | fp16 | 30.89 | 0.8422 | −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-13; portable fp32, portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 45a5c91f, 2026-11-13.
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).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.000014 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.02 | 0.00052 |
| GPU default dtypes, p99 |diff| | ≤ 0.25 | 0.00192 |
Recorded for swinir-m-x4 on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13, with these kernels: cudnn_hacc
Details
SwinIR (Liang et al., ICCVW 2021): image restoration with residual groups of Swin Transformer layers (8 x 8 window attention, shifted every second layer) between a conv stem and an upsampler. `swinir-m-x4` / `swinir-m-x2` are the classical (bicubic, PSNR-trained) DF2K models, `swinir-m-x4-real` and `swinir-l-x4-real` the real-world x4 GAN models (BSRGAN degradations; L = 9 groups, 240 channels).
- Input / output
- Input: one RGB image. Output: the restored (upscaled) image,
model.scalex 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 1024x1024 (11.0 GiB allocated)
- Outputs
image- CUDA kernels
cudnn_haccconvolutions with fp16 accumulation (cuDNN)
- Apple (MPS)
- fp32, fp16
Full reference, generated from the repository
SwinIR (Liang et al., ICCVW 2021): a Swin Transformer upscaler: x4 / x2 for clean (bicubic) images and x4 for real-world photos (medium and large). Apache-2.0 code and weights.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
swinir-m-x4 | synthetic (512x512) | original portable kernels portable + torch.compile TensorRT fp16 | 3497 767 576 795 727 | 1500 / 2058 1499 / 2054 1354 / 1456 1684 / 1796 5525 / 5604 |
swinir-m-x2 | synthetic (512x512) | original portable kernels portable + torch.compile TensorRT fp16 | 3252 739 553 781 719 | 1500 / 1818 1353 / 1454 1353 / 1454 1683 / 1796 5088 / 5144 |
swinir-m-x4-real | synthetic (512x512) | original portable kernels portable + torch.compile TensorRT fp16 | 2462 1242 584 807 733 | 2321 / 2978 2387 / 3034 1353 / 1814 1683 / 1796 5427 / 5506 |
swinir-l-x4-real | synthetic (512x512) | original portable kernels portable + torch.compile TensorRT fp16 | 3709 2099 1036 1426 1118 | 2357 / 2746 2425 / 2672 1806 / 1934 2153 / 2876 9182 / 9282 |
Details
- Original code: https://github.com/JingyunLiang/SwinIR at
6545850fbf8d - Code licence: Apache-2.0 (permissive); files:
LICENSE - Weights licence: Apache-2.0
- Licence evidence: https://github.com/JingyunLiang/SwinIR/blob/6545850fbf8df298df73d81f3e8cba638787c8bd/LICENSE ; https://github.com/JingyunLiang/SwinIR/releases/tag/v0.0
- Training data: DIV2K (NTIRE 2017 super-resolution, 1000 2K images), Flickr2K (2650 2K Flickr images, EDSR) (README, Training and testing: classical SR on DF2K (DIV2K + Flickr2K) HR images, bicubic-downsampled.)
swinir-m-x4-real: DIV2K (NTIRE 2017 super-resolution, 1000 2K images), Flickr2K (2650 2K Flickr images, EDSR), OutdoorSceneTraining (OST, SFTGAN) (README, Training and testing: real-world SR, SwinIR-M on DIV2K + Flickr2K + OST HR images with BSRGAN degradations.)swinir-l-x4-real: DIV2K (NTIRE 2017 super-resolution, 1000 2K images), Flickr2K (2650 2K Flickr images, EDSR), OutdoorSceneTraining (OST, SFTGAN), Waterloo Exploration Database (4744 natural images), Flickr-Faces-HQ (FFHQ, 70k face images), Manga109 (109 Japanese manga volumes), SCUT-CTW1500 (curved scene text) (README, Training and testing: real-world SR, SwinIR-L on DIV2K + Flickr2K + OST + WED + FFHQ (first 2000) + Manga109 + SCUT-CTW1500 (first 100) with BSRGAN degradations.)
- Kernel libraries:
cudnn_hacc - Variants:
swinir-m-x4,swinir-m-x2,swinir-m-x4-real,swinir-l-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):
swinir-m-x41024x1024 (11.0 GiB peak allocated, 14.4 reserved);swinir-m-x21024x1024 (11.0 GiB peak allocated, 12.3 reserved);swinir-m-x4-real512x512 (3.1 GiB peak allocated, 5.6 reserved);swinir-l-x4-real512x512 (4.0 GiB peak allocated, 5.8 reserved) swinir-m-x4512x512, first call: portable + torch.compile 62 s (cold Inductor cache), TensorRT fp16 104 s (ONNX + engine).swinir-m-x2512x512, first call: portable + torch.compile 60 s (cold Inductor cache), TensorRT fp16 102 s (ONNX + engine).swinir-m-x4-real512x512, first call: portable + torch.compile 60 s (cold Inductor cache), TensorRT fp16 109 s (ONNX + engine).swinir-l-x4-real512x512, first call: portable + torch.compile 68 s (cold Inductor cache), TensorRT fp16 193 s (ONNX + engine).swinir-m-x4original 512x512: .half() on 1 modules, fp16 inputs; upstream main_test_swinir.py, float32, no tileswinir-m-x2original 512x512: .half() on 1 modules, fp16 inputs; upstream main_test_swinir.py, float32, no tileswinir-m-x4-realoriginal 512x512: .half() on 1 modules, fp16 inputs; upstream main_test_swinir.py, float32, no tileswinir-l-x4-realoriginal 512x512: .half() on 1 modules, fp16 inputs; upstream main_test_swinir.py, float32, no tileswinir-m-x4load / first call: original 2.07 s / 3.272 s, portable 0.44 s / 1.36 s, kernels 1.28 s / 0.646 sswinir-m-x2load / first call: original 2.95 s / 4.489 s, portable 0.67 s / 0.848 s, kernels 0.43 s / 0.629 sswinir-m-x4-realload / first call: original 2.06 s / 3.326 s, portable 0.4 s / 1.386 s, kernels 1.31 s / 0.697 sswinir-l-x4-realload / first call: original 2.15 s / 5.945 s, portable 0.7 s / 2.188 s, kernels 1.46 s / 1.103 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.
| variant | dataset | original fp32 | portable | portable fp32 | kernels | note |
|---|---|---|---|---|---|---|
swinir-m-x4 | DIV2K validation (every 2nd: 50 images), bicubic x4 LR -> HR, PSNR / SSIM (Y) | 30.90 / 0.8423 | 30.90 / 0.8423 | 30.90 / 0.8423 | 30.89 / 0.8422 | |
swinir-m-x2 | DIV2K validation (100 images), bicubic x2 LR -> HR, PSNR / SSIM (Y) | 36.86 / 0.9507 | 36.86 / 0.9507 | |||
swinir-m-x4-real | DIV2K validation (every 2nd: 50 images), bicubic x4 LR -> HR, PSNR / SSIM (Y) | 26.71 / 0.7516 | 26.71 / 0.7516 | 26.71 / 0.7516 | 26.71 / 0.7515 | |
swinir-l-x4-real | DIV2K validation (every 2nd: 50 images), bicubic x4 LR -> HR, PSNR / SSIM (Y) | 27.04 / 0.7628 | 27.04 / 0.7628 | 27.04 / 0.7628 | 27.05 / 0.7628 |
Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 45a5c91f, 2026-11-13; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 3bf0bac7 / 45a5c91f, 2026-11-13 to 2026-11-18; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 45a5c91f, 2026-11-13.
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).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
swinir-m-x4 | 0.00052 / 0.00192 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
swinir-m-x2 | 0.00039 / 0.00139 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
swinir-m-x4-real | 0.00126 / 0.00498 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
swinir-l-x4-real | 0.00082 / 0.0039 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
Example output
No example rendered for this checkpoint yet.