AniRestore: CUDA/Triton-Accelerated Anime Cover-Art Restoration

Deep Learning GPU Kernels CUDA/Triton Model Optimization PyTorch
Architecture
AniRestore restoration pipeline architecture diagram
Restoration Demo
Before and after 4x anime cover-art restoration
View on GitHub

AniRestore takes a pretrained Real-ESRGAN checkpoint (RealESRGAN_x4plus_anime_6B) for 4x anime cover-art super-resolution and asks the question a "wrap a pretrained model" demo usually skips: where does the GPU time actually go, and can a targeted kernel change move the needle? The RRDBNet architecture is vendored directly (rather than pip install basicsr, whose setup.py is broken on current Python) so every layer is editable.

torch.profiler on a Tesla T4 found the convolutions dominate (65.9% of GPU time, already on cuDNN's tuned Winograd kernel — not a sane target), but bias-add and LeakyReLU each ran as separate elementwise kernels after nearly every conv, costing 11.83% of GPU time combined. A custom Triton kernel (fused_bias_act.py) fuses those two ops into one read of the conv output and one write of the activated result, gated behind a flag so the stock and fused paths run with identical weights for direct comparison.

19 correctness tests (kernel-level shape/batch/non-contiguous cases, model-level PSNR/SSIM parity) gate every kernel change — several are bit-exact (PSNR = inf). The first wall-clock benchmark showed no improvement despite the GPU-compute win, so CUDA graph capture was tried (the standard fix), which made things worse; the real culprit was that separately-invoked benchmark processes were too noisy to trust (~10% baseline drift with zero code changes). An interleaved, single-process, paired comparison (benchmark_compare.py) fixed that.

Tesla T4, 256×256, batch 1, 100 interleaved paired rounds: stock PyTorch 215.34ms/frame vs. Triton fused kernel 211.94ms/frame — a real, statistically significant -1.58% latency reduction (t = -10.18), fully explained by the 53% GPU-compute-time cut to the targeted op. CUDA graphs regressed both configurations (likely non-graph-safe cuDNN algorithms), so they're implemented and tested but intentionally not shipped.
Built with
Python PyTorch Triton CUDA torch.profiler Real-ESRGAN (RRDBNet) Gradio pytest

Shares its cover-art dataset with AniOntology — the same MyAnimeList anime IDs and cover URLs, so both projects stay pointed at the exact same set of anime.