Models · Image restoration

CodeFormer

CodeFormer (Zhou et al., S-Lab NTU, NeurIPS 2022): restores a degraded face (an aligned 512 x 512 crop) by predicting codes of a learned face codebook; fidelity w trades quality against faithfulness. Non-commercial code and weights (S-Lab License 1.0).

experimental Fork of sczhou/CodeFormer@b33cc7d · backends: portable, kernels

Checkpoint codeformer

Paper 2022 Added in 0.2.0

Kernels, RTX 5060 Ti 16 GB 40.4 ms 512x512, fp16
vs the faster original 2.1× original fp32: 85.7 ms
Peak memory 432 MiB original: 959 MiB
Accuracy vs original fp32 – no test-set run

Use it

pip install fastforks

Lean install with only what this model needs: pip install "fastforks-core[nc]"

from fastforks import restoration

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

The weights are non-commercial: fastforks downloads them only with FASTFORKS_NONCOMMERCIAL=1 set.

fastforks bench codeformer

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 (own default)upstream inference_codeformer.py on the aligned face, float32, w 0.5fp32 85.7–959 MiB/1,090 MiB1.20.41
Portable fp32fp32not measured ––––
Portablefp16 48.61.8×512 MiB/638 MiB0.70.23
Kernelsfp16 40.42.1×432 MiB/496 MiB0.70.23
Portable + torch.compile 30.82.8×407 MiB/458 MiB34 (build)–
TensorRT fp16fp16 16.35.3×372 MiBenginenot comparable65 (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

DeviceBackenddtypems / callPeak memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-17Originalfp32274 3,182 MiB process–512x512
Portablefp16196 1,866 MiB processmatches512x512
Portablefp32260 3,064 MiB processmatches512x512
Kernelsfp16not implemented–512x512
Kernelsfp32not 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

Non-commercial only

Code
LicenseRef-noncommercial LICENSE
Weights
LicenseRef-noncommercial source
Training data
  • code: LicenseRef-noncommercial (noncommercial)
  • weights: LicenseRef-noncommercial

Our reading of the licences, not legal advice.

Weights

codeformer.pth 377 MB· hosted on GitHub

fastforks downloads and checks these files on first use (fastforks download codeformer). Non-commercial weights need FASTFORKS_NONCOMMERCIAL=1.

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.

Accuracy not measured for codeformer.

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| <= 0.002 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.002 not recorded
GPU default dtypes, mean |diff|≤ 0.02 0.0017
GPU default dtypes, p99 |diff|≤ 0.25 0.01817

Recorded for codeformer on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-15, with these kernels: cudnn_hacccutlass_convigev

Details

CodeFormer (Zhou et al., NeurIPS 2022): blind face restoration with a learned codebook: a VQGAN encoder, a transformer that predicts the code of each of the 16 x 16 latent positions, and the VQGAN decoder with controllable feature fusion from the encoder (fidelity w). Input: an aligned 512 x 512 face crop (FFHQ alignment); detecting, aligning and pasting the face back are not part of the model.

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 >= 512, padded to a multiple of 32; tested up to 512x512 (519 MiB allocated)
Options
  • fidelity=0.50.0 to 1.0· changes the output
Outputs
image
CUDA kernels
  • igevIGEV stereo: convolution epilogues, correlation lookups, GRU gates
  • cutlass_convCUTLASS convolutions with the recurrent update (GRU) fused in
  • cudnn_haccconvolutions with fp16 accumulation (cuDNN)
Apple (MPS)
fp32, fp16

Limitations

  • No accuracy measurement: blind face restoration is scored on CelebA-Test / LFW / WebPhoto (FID, NIQE, identity distance), which are not part of the evaluation data here; tiers are compared by output parity and speed only.
Full reference, generated from the repository

CodeFormer (Zhou et al., S-Lab NTU, NeurIPS 2022): restores a degraded face (an aligned 512 x 512 crop) by predicting codes of a learned face codebook; fidelity w trades quality against faithfulness. Non-commercial code and weights (S-Lab License 1.0).

Commercial use: no (code: LicenseRef-noncommercial (noncommercial); weights: LicenseRef-noncommercial).

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
codeformersynthetic (512x512)original
portable
kernels
portable + torch.compile
TensorRT fp16
85.7
48.6
40.4
30.8
16.3
959 / 1090
512 / 638
432 / 496
407 / 458
593 / 642
Details

Parity

CPU, float32: max |diff| <= 0.002 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
codeformer0.0017 / 0.01817RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, cutlass_conv@988138e042cb:sm_120, igev@f075827d68c6:sm_120

Limitations

  • No accuracy measurement: blind face restoration is scored on CelebA-Test / LFW / WebPhoto (FID, NIQE, identity distance), which are not part of the evaluation data here; tiers are compared by output parity and speed only.

Example output

No example rendered for this checkpoint yet.