RepLKNet
A foundational deep learning convolutional architecture and PyTorch framework introducing very large convolutional kernels (up to $31 \times 31$) coupled with structural re-parameterization. Developed by Xiaohan Ding, Xiangyu Zhang, Yizhuang Zhou, Jungong Han, Guiguang Ding, and Jian Sun across Tsinghua University and Megvii Research (CVPR 2022), RepLKNet revolutionized modern computer vision by proving that pure CNNs can achieve the massive Effective Receptive Field (ERF), high shape bias, and benchmark performance of Vision Transformers while retaining convolutional speed, hardware efficiency, and linear scaling.
PyTorch Repository: DingXiaoH/RepLKNet-pytorch — Apache-2.0
Official MegEngine Repository: megvii-research/RepLKNet
Foundational Paper: Ding X, Zhang X, Zhou Y, Han J, Ding G, Sun J. Scaling Up Your Kernels to 31x31: Revisiting Large Kernel Design in CNNs. IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR 2022): 11975–11985. DOI: 10.1109/CVPR52688.2022.01167; arXiv:2203.06717
Companion Literature Review: [[Scaling Up Your Kernels to 31x31: Revisiting Large Kernel Design in CNNs]]
Evolutionary Successor: AILab-CVC/UniRepLKNet (CVPR 2024 / TPAMI 2025)
Direct Computational Pathology Descendants: [[CellQuant-Net]] / [[CellPrior-Net: Prior-Guided Nuclei Detection and Classification for H&E Whole-Slide Images]], LKCell
Why Large Kernels Matter in Computational Pathology
For nearly a decade following VGGNet (2014), deep learning doctrine mandated stacking small $3 \times 3$ convolutional filters to reduce parameters and deepen networks. When Vision Transformers (ViTs) emerged and outperformed standard CNNs, the performance gap was widely attributed to multi-head self-attention.
However, in computational pathology and gigapixel Whole-Slide Image (WSI) analysis, deploying Vision Transformers introduces severe operational friction:
The Quadratic Compute Bottleneck: Self-attention computes pairwise token interactions with $\mathcal{O}(N^2)$ memory and compute complexity, demanding enormous GPU VRAM and causing whole-slide inference to take 15 to 45 minutes per slide (e.g., CellViT).
Loss of Inductive Biases: ViTs lack shift-invariance and translation equivariance out of the box, requiring massive pretraining datasets (hundreds of millions of patches) to learn basic spatial relationships that CNNs possess inherently.
Small-Kernel Receptive Field Saturation: Traditional CNNs with $3 \times 3$ kernels (e.g., ResNet, UNet) have a strictly localized Effective Receptive Field (ERF) that does not expand sufficiently with depth, failing to capture millimeter-scale glandular morphology, invasive tumor margins, and tumor-stroma spatial context.
RepLKNet resolved this dilemma by demonstrating that the primary competitive advantage of Transformers is their large Effective Receptive Field, and that CNNs can acquire an equally vast receptive field simply by scaling depthwise kernels to $31 \times 31$. In computational pathology, this insight powers modern, ultra-fast architectures like UniRepLKNet-N in [[CellQuant-Net]] and LKCell, which match ViT accuracy while cutting inference latency by $2\times$ to $3\times$.
Core Architectural Innovations
1. The Five Design Guidelines for Large-Kernel CNNs
Large Depthwise Convolutions are Computationally Cheap: Standard dense convolutions scale with $\mathcal{O}(C_{\text{in}} C_{\text{out}} K^2)$, making a $31 \times 31$ kernel impossible ($106.8\times$ heavier than $3 \times 3$). But depthwise (DW) convolution isolates spatial operations channel-by-channel ($\mathcal{O}(C \cdot K^2)$), while $1 \times 1$ pointwise convs handle channel mixing. Because $1 \times 1$ convs consume $>90%$ of network FLOPs, increasing kernel size to $31 \times 31$ in DW layers incurs minimal overall overhead.
Structural Re-parameterization Overcomes Optimization Bottlenecks: Directly training large kernels with SGD or Adam suffers from vanishing gradients and optimization stagnation. RepLKNet introduces a parallel small-kernel branch ($5 \times 5$ DW conv) during training. At test time, the $5 \times 5$ kernel is zero-padded and algebraically merged into the $31 \times 31$ kernel, giving the optimization stability of small kernels with zero inference latency.
Small Kernels Preserve High-Frequency Texture: While large kernels capture macro-architectural context and broad shapes, the parallel $5 \times 5$ branch ensures that fine cytologic details (nuclear chromatin clumping, nucleoli, membrane contours) are explicitly learned and preserved.
Effective Receptive Field (ERF) Mimics Transformers: While theoretical receptive field scales with depth, the effective receptive field decays like a Gaussian from the center. RepLKNet produces an ultra-wide, uniformly distributed ERF that spans the entire visual token field, directly mirroring the global attention maps of ViTs.
High Shape Bias: Standard CNNs suffer from severe texture bias, making them fragile to domain and stain shifts. RepLKNet shifts CNN representation fundamentally toward shape bias, approaching human visual perception and explaining its high robustness in downstream transfer tasks.
2. Custom CUDA Implicit GEMM Engine
Standard deep learning frameworks (PyTorch cuDNN) rely on direct convolution or im2col algorithms optimized exclusively for $3 \times 3$ to $7 \times 7$ kernels. On large kernels ($K \ge 13$), cuDNN experiences catastrophic memory bandwidth bottlenecks.
RepLKNet provides a custom CUDA extension based on CUTLASS and Implicit GEMM (DepthWiseConv2dImplicitGEMM):
Eliminates the materialization of large intermediate im2col matrices.
Computes depthwise operations directly as tiled matrix multiplications in GPU SRAM/registers.
Achieves 82% of theoretical hardware FLOPS on NVIDIA Tesla V100/A100 GPUs, unlocking true real-time execution.
Model Zoo & Specifications
RepLKNet-31B
$224 \times 224$
83.5%
79M
15.3G
Base edge / fast classification
RepLKNet-31B
$384 \times 384$
84.8%
79M
45.1G
High-resolution semantic segmentation
RepLKNet-31B (22K)
$384 \times 384$
86.0%
79M
45.1G
Pretrained pan-domain feature extractor
RepLKNet-31L (22K)
$384 \times 384$
86.6%
172M
96.0G
Heavy foundation backbone
RepLKNet-XL (MegData-73M)
$320 \times 320$
87.8%
335M
128.7G
Extreme capacity dense segmentation
Kernel Sizes per Stage: Typically $[31, 29, 27, 13]$ across stages 1 through 4, providing progressive receptive fields.
Structural Re-parameterization: $5 \times 5$ DW conv parallel to large DW conv in every RepLK Block.
Installation & Code Integration
1. Installation
2. PyTorch Definition & Weight Reparameterization
Lineage and Impact on Digital Pathology
[[CellPrior-Net: Prior-Guided Nuclei Detection and Classification for H&E Whole-Slide Images]] / [[CellQuant-Net]]: Adopts the compact UniRepLKNet-N (the lightweight variant in the RepLKNet family) as its visual feature encoder. By leveraging large depthwise kernels with physical hematoxylin DoG prior guidance, CP-Net matches CellViT panoptic quality while achieving $2\times$ to $3\times$ speedups on gigapixel slides (2.16 min on $20\times$, 2.77 min on $40\times$).
Comparison with [[HoVer-NeXt]]: HoVer-NeXt uses modern ConvNeXt-V2 backbones ($7 \times 7$ kernels) with masked autoencoding pretraining. RepLKNet pushes the spatial kernel envelope up to $31 \times 31$, maximizing the effective receptive field without requiring self-attention heads.
Comparison with [[HistoPLUS: Towards Comprehensive Cellular Characterisation of H&E Slides]]: HistoPLUS utilizes a distilled ViT (H0-mini, 86M) within CellViT. RepLKNet demonstrates that pure convolutional architectures can match or exceed ViT representation quality on dense cellular classification with substantially lower VRAM consumption and zero quadratic scaling.
Related Notes
Foundational Paper Clipping: [[Scaling Up Your Kernels to 31x31: Revisiting Large Kernel Design in CNNs]]
Direct Descendant Pipelines: [[CellQuant-Net]], [[CellPrior-Net: Prior-Guided Nuclei Detection and Classification for H&E Whole-Slide Images]]
Modern Cellular Segmentation Backbones: [[HoVer-NeXt]], [[HistoPLUS: Towards Comprehensive Cellular Characterisation of H&E Slides]], [[NuClick]]
Ecosystem: [[Digital Pathology Software]], [[Digital Pathology]], [[Image Analysis]]
Last updated