Models · Image restoration

HAT

HAT (Chen et al., CVPR 2023): a x4 upscaler mixing window attention, channel attention and overlapping cross-attention: two models for clean (bicubic) images (large and small) and a GAN model for real-world photos. Apache-2.0 code and weights.

experimental Fork of XPixelGroup/HAT@1638a9a · backends: portable, kernels

Checkpoint

Paper 2022 Added in 0.2.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 1427 ms 512x512, fp16
vs the faster original 2.1× original fp16: 3038 ms
Peak memory 2,298 MiB original: 5,318 MiB
Accuracy vs original fp32 ±0.00 kernels psnr, DIV2K validation (every 4th: 25 images) (31.01 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("hat-x4")  # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.image
result.backend  # what ran: mode, device, dtype, kernels
fastforks bench hat-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 hat_model.py test, float32, no tilefp16 3038–5,318 MiB/6,106 MiB1.93.43
Portable fp32fp32not measured ––––
Portablefp16 15961.9×2,426 MiB/2,590 MiB0.51.81
Kernelsfp16 14272.1×2,298 MiB/2,470 MiB0.81.54
Portable + torch.compile 11852.6×1,811 MiB/2,750 MiB53 (build)–
TensorRTTensorRT engine build failedfails––––

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

DeviceBackenddtypems / callPeak memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14Originalfp32out of memory–512x512
Portablefp16out of memory–512x512
Portablefp32out of memory–512x512
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

HAT_SRx4_ImageNet-pretrain.pth 85.1 MB· hosted on Google Drive

fastforks downloads and checks these files on first use (fastforks download hat-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 4th: 25 images)

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

Rundtypepsnr ↑ssim ↑Δ psnr vs fp32 originalimagesms / image
Original fp32fp3231.010.8498 reference 25 –
Original fp16not measured
Portable fp32fp3231.010.8498 ±0.00 25 –
Portablefp1631.010.8498 ±0.00 25 –
Kernelsfp1631.010.8498 ±0.00 25 –

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 f33b2772, 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| <= 3e-06 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.00083 and p99 <= 0.0031 (absolute error of the output image).

CheckToleranceMeasured
CPU fp32, max |diff|≤ 0.000003 not recorded
GPU default dtypes, mean |diff|≤ 0.00083 0.00055
GPU default dtypes, p99 |diff|≤ 0.0031 0.00204

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

Details

HAT (Chen et al., CVPR 2023): image super-resolution with residual groups of hybrid attention blocks (16 x 16 window attention plus a channel-attention conv branch) and an overlapping cross-attention block per group. `hat-x4` is the classical x4 model pretrained on ImageNet and fine-tuned on DF2K, `hat-s-x4` the small one (144 channels), `real-hat-gan-x4` the real-world x4 GAN model (Real-ESRGAN 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 1024x1024 (9,628 MiB allocated)
Outputs
image
CUDA kernels
  • cudnn_haccconvolutions with fp16 accumulation (cuDNN)
Apple (MPS)
fp32, fp16
Full reference, generated from the repository

HAT (Chen et al., CVPR 2023): a x4 upscaler mixing window attention, channel attention and overlapping cross-attention: two models for clean (bicubic) images (large and small) and a GAN model for real-world photos. Apache-2.0 code and weights.

Commercial use: yes.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
hat-x4synthetic (512x512)original
portable
kernels
portable + torch.compile
TensorRT fp16
3038
1596
1427
1185
fails: TensorRT engine build failed
5318 / 6106
2426 / 2590
2298 / 2470
1811 / 2750
–
hat-s-x4synthetic (512x512)original
portable
kernels
portable + torch.compile
TensorRT fp16
2402
1072
956
750
fails: TensorRT engine build failed
5018 / 5644
1984 / 2148
1856 / 1888
2352 / 3068
–
real-hat-gan-x4synthetic (512x512)original
portable
kernels
portable + torch.compile
TensorRT fp16
3038
1597
1427
1185
fails: TensorRT engine build failed
5318 / 6106
2426 / 2610
2298 / 2470
1811 / 2750
–
Details
  • Original code: https://github.com/XPixelGroup/HAT at 1638a9a82258
  • Code licence: Apache-2.0 (permissive); files: LICENSE
  • Weights licence: Apache-2.0
  • Licence evidence: https://github.com/XPixelGroup/HAT/blob/1638a9a822581657811867bf670717f8371fc3e5/LICENSE ; https://github.com/XPixelGroup/HAT/blob/1638a9a822581657811867bf670717f8371fc3e5/README.md (pretrained models: https://drive.google.com/drive/folders/1HpmReFfoUqUbnAOQ7rvOeNU3uf_m69w0)
  • Training data: ImageNet-1k (ILSVRC 2012 classification), DIV2K (NTIRE 2017 super-resolution, 1000 2K images), Flickr2K (2650 2K Flickr images, EDSR) (options/train/train_HAT_SRx4_ImageNet_from_scratch.yml then train_HAT_SRx4_finetune_from_ImageNet_pretrain.yml: pretrained on ImageNet, fine-tuned on DF2K (DIV2K + Flickr2K), bicubic-downsampled.)
    • hat-s-x4: DIV2K (NTIRE 2017 super-resolution, 1000 2K images), Flickr2K (2650 2K Flickr images, EDSR) (options/train/train_HAT-S_SRx4_finetune_from_SRx2.yml: DF2K (DIV2K + Flickr2K), bicubic-downsampled, fine-tuned from the x2 model.)
    • real-hat-gan-x4: DIV2K (NTIRE 2017 super-resolution, 1000 2K images), Flickr2K (2650 2K Flickr images, EDSR), OutdoorSceneTraining (OST, SFTGAN) (options/train/train_Real_HAT_SRx4_mse_model.yml then train_Real_HAT_GAN_SRx4_finetune_from_mse_model.yml: DF2K + OST with Real-ESRGAN degradations (README: the released model without USM-sharpened ground truth).)
  • Kernel libraries: cudnn_hacc
  • Variants: hat-x4, hat-s-x4, real-hat-gan-x4
  • 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): hat-x4 1024x1024 (9.4 GiB peak allocated, 14.7 reserved); hat-s-x4 1024x1024 (7.5 GiB peak allocated, 11.1 reserved); real-hat-gan-x4 1024x1024 (9.4 GiB peak allocated, 14.7 reserved)
  • hat-x4 512x512, first call: portable + torch.compile 53 s (cold Inductor cache).
  • hat-s-x4 512x512, first call: portable + torch.compile 42 s (cold Inductor cache).
  • real-hat-gan-x4 512x512, first call: portable + torch.compile 54 s (cold Inductor cache).
  • hat-x4 original 512x512: .half() on 1 modules, fp16 inputs; upstream hat_model.py test, float32, no tile
  • hat-s-x4 original 512x512: .half() on 1 modules, fp16 inputs; upstream hat_model.py test, float32, no tile
  • real-hat-gan-x4 original 512x512: .half() on 1 modules, fp16 inputs; upstream hat_model.py test, float32, no tile
  • hat-x4 load / first call: original 1.75 s / 5.422 s, portable 0.47 s / 1.809 s, kernels 1.36 s / 1.569 s
  • hat-s-x4 load / first call: original 3.14 s / 4.407 s, portable 0.35 s / 1.268 s, kernels 1.58 s / 1.068 s
  • real-hat-gan-x4 load / first call: original 1.96 s / 5.412 s, portable 1.24 s / 1.769 s, kernels 1.49 s / 1.562 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
hat-x4DIV2K validation (every 4th: 25 images), bicubic x4 LR -> HR, PSNR / SSIM (Y)31.01 / 0.849831.01 / 0.849831.01 / 0.849831.01 / 0.8498
hat-s-x4DIV2K validation (every 4th: 25 images), bicubic x4 LR -> HR, PSNR / SSIM (Y)30.91 / 0.847630.91 / 0.847630.91 / 0.847630.90 / 0.8476
real-hat-gan-x4DIV2K validation (every 4th: 25 images), bicubic x4 LR -> HR, PSNR / SSIM (Y)27.13 / 0.763327.13 / 0.763327.13 / 0.763327.13 / 0.7632

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

Parity

CPU, float32: max |diff| <= 3e-06 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.00083 and p99 <= 0.0031 (absolute error of the output image).

variantkernels error vs original, mean / p99GPU, torchkernels used
hat-x40.00055 / 0.00204RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400
hat-s-x40.0005 / 0.00182RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400
real-hat-gan-x40.00045 / 0.00158RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400

Example output

No example rendered for this checkpoint yet.