SPAN
SPAN (Wan et al., NTIRE 2024 efficient SR winner): a small, fast x4 / x2 upscaler for clean (bicubic) images, convolutions with parameter-free attention. Apache-2.0 code and weights.
experimental Fork of hongyuanyu/SPAN@c77a591 · backends: portable, kernels
- Paper Swift Parameter-free Attention Network for Efficient Super-Resolution CVPRW 2024 · first released 21 Nov 2023
Paper 2023 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("span-x4") # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.image
result.backend # what ran: mode, device, dtype, kernels fastforks bench span-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 SPAN eval mode, float32, net(lq) clamped | fp16 | 26.9 | – | 611 MiB/648 MiB | 0.5 | 0.74 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 24.2 | 1.1× | 607 MiB/662 MiB | 0.1 | 0.26 |
| Kernels | fp16 | 14.6 | 1.8× | 487 MiB/522 MiB | 1.1 | 0.05 |
| Portable + torch.compile | 13.2 | 2.0× | 204 MiB/222 MiB | 5 (build) | – | |
| TensorRT fp16 | fp16 | 8.28 | 3.3× | 264 MiBenginenot comparable | 10 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-13. 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 | 117 | 2,388 MiB process | – | 512x512 |
| Portable | fp16 | 89.0 | 1,296 MiB process | matches | 512x512 | |
| Portable | fp32 | 103 | 2,321 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
spanx4_ch48.pth 18.0 MB· inside a 1.3 GB archive· hosted on Google Drivefastforks downloads and checks these files on first use (fastforks download span-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 (100 images)
bicubic x4 LR -> HR, PSNR / SSIM (Y)
| Run | dtype | psnr ↑ | ssim ↑ | Δ psnr vs fp32 original | images | ms / image |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 30.47 | 0.8382 | reference | 100 | – |
| Original fp16 | not measured | |||||
| Portable fp32 | fp32 | 30.47 | 0.8382 | ±0.00 | 100 | – |
| Portable | fp16 | 30.47 | 0.8382 | ±0.00 | 100 | – |
| Kernels | fp16 | 30.47 | 0.8382 | ±0.00 | 100 | – |
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| <= 1e-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.00001 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.02 | 0.00074 |
| GPU default dtypes, p99 |diff| | ≤ 0.25 | 0.00305 |
Recorded for span-x4 on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13, with these kernels: cudnn_hacc
Details
SPAN (Wan et al., CVPRW 2024; NTIRE 2024 efficient super-resolution winner): a small bicubic super-resolution network (about 0.4 M parameters at inference) of six parameter-free attention blocks (re-parameterised 3 x 3 convs, attention = sigmoid(features) - 0.5) and a pixel-shuffle upsampler, trained for PSNR. `span-x4` and `span-x2` are the 48-channel release models.
- 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 >= 4, resized or padded inside the model; tested up to 1988x2880 (12.9 GiB allocated)
- Outputs
image- CUDA kernels
cudnn_haccconvolutions with fp16 accumulation (cuDNN)
- Apple (MPS)
- fp32, fp16
Full reference, generated from the repository
SPAN (Wan et al., NTIRE 2024 efficient SR winner): a small, fast x4 / x2 upscaler for clean (bicubic) images, convolutions with parameter-free attention. Apache-2.0 code and weights.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
span-x4 | synthetic (512x512) | original portable kernels portable + torch.compile TensorRT fp16 | 26.9 24.2 14.6 13.2 8.28 | 611 / 648 607 / 662 487 / 522 204 / 222 319 / 346 |
span-x2 | synthetic (512x512) | original portable kernels portable + torch.compile TensorRT fp16 | 24.6 23.5 14.9 13.2 7.98 | 611 / 648 607 / 662 487 / 522 204 / 222 243 / 266 |
Details
- Original code: https://github.com/hongyuanyu/SPAN at
c77a5917759f - Code licence: Apache-2.0 (permissive); files:
LICENSE - Weights licence: Apache-2.0
- Licence evidence: https://github.com/hongyuanyu/SPAN/blob/c77a5917759f09e66fbc7124220c5afc5ee221e5/LICENSE.txt ; https://github.com/hongyuanyu/SPAN/blob/c77a5917759f09e66fbc7124220c5afc5ee221e5/README.md
- Training data: DIV2K (NTIRE 2017 super-resolution, 1000 2K images), Flickr2K (2650 2K Flickr images, EDSR) (Paper Sec. 4.1: DF2K (DIV2K + Flickr2K) HR images, bicubic-downsampled.)
- Kernel libraries:
cudnn_hacc - Variants:
span-x4,span-x2 - Outputs: image
- Input size: any H x W >= 4, resized or padded inside the model
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
span-x41988x2880 (12.9 GiB peak allocated, 14.0 reserved);span-x21988x2880 (12.9 GiB peak allocated, 14.0 reserved) span-x4512x512, first call: portable + torch.compile 5 s (cold Inductor cache), TensorRT fp16 10 s (ONNX + engine).span-x2512x512, first call: portable + torch.compile 7 s (cold Inductor cache), TensorRT fp16 10 s (ONNX + engine).span-x4original 512x512: .half() on 1 modules, fp16 inputs; upstream SPAN eval mode, float32, net(lq) clampedspan-x2original 512x512: .half() on 1 modules, fp16 inputs; upstream SPAN eval mode, float32, net(lq) clampedspan-x4load / first call: original 0.45 s / 0.585 s, portable 0.1 s / 0.264 s, kernels 1.11 s / 0.048 sspan-x2load / first call: original 0.23 s / 0.322 s, portable 0.1 s / 0.258 s, kernels 2.88 s / 0.102 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 |
|---|---|---|---|---|---|---|
span-x4 | DIV2K validation (100 images), bicubic x4 LR -> HR, PSNR / SSIM (Y) | 30.47 / 0.8382 | 30.47 / 0.8382 | 30.47 / 0.8382 | 30.47 / 0.8382 | |
span-x2 | DIV2K validation (100 images), bicubic x2 LR -> HR, PSNR / SSIM (Y) | 36.20 / 0.9460 | 36.20 / 0.9460 | 36.20 / 0.9460 | 36.20 / 0.9460 |
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 45a5c91f, 2026-11-13.
Parity
CPU, float32: max |diff| <= 1e-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 |
|---|---|---|---|
span-x4 | 0.00074 / 0.00305 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
span-x2 | 0.00207 / 0.0225 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
Example output
No example rendered for this checkpoint yet.