AniRestore: CUDA/Triton-Accelerated Anime Cover-Art Restoration
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.
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.